-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated to use current version of Horreum 0.15.x
- Loading branch information
Showing
15 changed files
with
580 additions
and
328 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
src/main/java/jenkins/plugins/horreum/auth/KeycloakAuthentication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 17 additions & 16 deletions
33
src/test/java/jenkins/plugins/horreum/HorreumExpectStepTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 9 additions & 7 deletions
16
src/test/java/jenkins/plugins/horreum/HorreumExpectTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 24 additions & 39 deletions
63
src/test/java/jenkins/plugins/horreum/HorreumPluginTestBase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,37 @@ | ||
package jenkins.plugins.horreum; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import java.util.logging.Logger; | ||
|
||
import io.hyperfoil.tools.horreum.api.data.Test; | ||
import jenkins.plugins.horreum.junit.HorreumTestClientExtension; | ||
import jenkins.plugins.horreum.junit.HorreumTestExtension; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.extension.AfterAllCallback; | ||
import org.junit.jupiter.api.extension.BeforeAllCallback; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.cloudbees.plugins.credentials.Credentials; | ||
import com.cloudbees.plugins.credentials.CredentialsScope; | ||
import com.cloudbees.plugins.credentials.SystemCredentialsProvider; | ||
import com.cloudbees.plugins.credentials.domains.Domain; | ||
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
|
||
import io.hyperfoil.tools.HorreumTestClientExtension; | ||
import io.hyperfoil.tools.HorreumTestExtension; | ||
import static jenkins.plugins.horreum.junit.HorreumTestClientExtension.getHorreumClient; | ||
|
||
@ExtendWith(HorreumTestClientExtension.class) | ||
public class HorreumPluginTestBase { | ||
public static final String HORREUM_UPLOAD_CREDENTIALS = "horreum-creds"; | ||
private static final Logger LOGGER = Logger.getLogger(HorreumPluginTestBase.class.getName()); | ||
|
||
@RegisterExtension | ||
public JenkinsExtension j = new JenkinsExtension(); | ||
private Map<Domain, List<Credentials>> credentials; | ||
|
||
void registerBasicCredential(String id, String username, String password) { | ||
credentials.get(Domain.global()).add( | ||
new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, | ||
id, "", username, password)); | ||
SystemCredentialsProvider.getInstance().setDomainCredentialsMap(credentials); | ||
Test createTest(String name, String owner) { | ||
Test test = new Test(); | ||
test.name = name; | ||
test.owner = owner; | ||
return getHorreumClient().testService.add(test); | ||
} | ||
|
||
@BeforeEach | ||
public void init() { | ||
credentials = new HashMap<>(); | ||
credentials.put(Domain.global(), new ArrayList<Credentials>()); | ||
this.registerBasicCredential(HORREUM_UPLOAD_CREDENTIALS, "user", "secret"); | ||
@BeforeAll | ||
public static void before() throws Exception { | ||
HorreumTestExtension.beforeAll(); | ||
} | ||
|
||
HorreumGlobalConfig globalConfig = HorreumGlobalConfig.get(); | ||
if (globalConfig != null) { | ||
globalConfig.setKeycloakRealm("horreum"); | ||
globalConfig.setClientId("horreum-ui"); | ||
globalConfig.setKeycloakBaseUrl(HorreumTestExtension.HORREUM_KEYCLOAK_BASE_URL); | ||
globalConfig.setBaseUrl(HorreumTestExtension.HORREUM_BASE_URL); | ||
} else { | ||
System.out.println("Can not find Horreum Global Config"); | ||
} | ||
@AfterAll | ||
public static void after() throws Exception { | ||
// HorreumTestExtension.afterAll(); | ||
} | ||
} |
90 changes: 47 additions & 43 deletions
90
src/test/java/jenkins/plugins/horreum/HorreumUploadStepTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,88 @@ | ||
package jenkins.plugins.horreum; | ||
|
||
import static io.hyperfoil.tools.HorreumTestClientExtension.dummyTest; | ||
import static io.hyperfoil.tools.HorreumTestClientExtension.horreumClient; | ||
import static jenkins.plugins.horreum.junit.HorreumTestExtension.*; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static jenkins.plugins.horreum.junit.HorreumTestClientExtension.getHorreumClient; | ||
|
||
import java.net.URL; | ||
import java.util.Map; | ||
|
||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import hudson.FilePath; | ||
import io.hyperfoil.tools.horreum.api.services.RunService; | ||
import org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowJob; | ||
import org.jenkinsci.plugins.workflow.job.WorkflowRun; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import io.hyperfoil.tools.horreum.api.RunService; | ||
import org.junit.jupiter.api.TestInfo; | ||
|
||
public class HorreumUploadStepTest extends HorreumPluginTestBase { | ||
@Test | ||
public void testUpload() throws Exception { | ||
URL jsonResource = Thread.currentThread().getContextClassLoader().getResource("data/config-quickstart.jvm.json"); | ||
WorkflowJob proj = j.jenkins.createProject(WorkflowJob.class, "Horreum-Upload-Pipeline"); | ||
WorkflowJob proj = j.jenkins.createProject(WorkflowJob.class, "Horreum-Upload-Pipeline-testUpload"); | ||
io.hyperfoil.tools.horreum.api.data.Test dummyTest = createTest("upload-single", "dev-team"); | ||
proj.setDefinition(new CpsFlowDefinition( | ||
"node {\n" + | ||
"def id = horreumUpload(\n" + | ||
"credentials: '" + HorreumPluginTestBase.HORREUM_UPLOAD_CREDENTIALS + "',\n" + | ||
"test: '" + dummyTest.name + "',\n" + | ||
"owner: '" + dummyTest.owner + "',\n" + | ||
"access: 'PUBLIC',\n" + | ||
"start: '$.build-timestamp',\n" + | ||
"stop: '$.build-timestamp',\n" + | ||
"jsonFile: '" + jsonResource.getPath() + "',\n" + | ||
"addBuildInfo: true\n" + | ||
")\n" + | ||
"println(id)\n" + | ||
"}\n", | ||
true)); | ||
"node {\n" + | ||
"def id = horreumUpload(\n" + | ||
"credentials: '" + HORREUM_UPLOAD_CREDENTIALS + "',\n" + | ||
"test: '" + dummyTest.name + "',\n" + | ||
"owner: '" + dummyTest.owner + "',\n" + | ||
"access: 'PUBLIC',\n" + | ||
"start: '$.build-timestamp',\n" + | ||
"stop: '$.build-timestamp',\n" + | ||
"jsonFile: '" + jsonResource.getPath() + "',\n" + | ||
"addBuildInfo: true\n" + | ||
")\n" + | ||
"println(id)\n" + | ||
"}\n", | ||
true)); | ||
|
||
WorkflowRun run = proj.scheduleBuild2(0).get(); | ||
|
||
j.assertBuildStatusSuccess(run); | ||
|
||
RunService.RunsSummary summary = horreumClient.runService.listTestRuns(dummyTest.id, false, null, null, "", null); | ||
RunService.RunsSummary summary = getHorreumClient().runService.listTestRuns(dummyTest.id, false, null, null, "", null); | ||
assertEquals(1, summary.total); | ||
assertEquals(1, summary.runs.size()); | ||
} | ||
|
||
@Test | ||
public void testUploadMultiple() throws Exception { | ||
public void testUploadMultiple(TestInfo info) throws Exception { | ||
URL jsonResource1 = Thread.currentThread().getContextClassLoader().getResource("data/config-quickstart.jvm.json"); | ||
URL jsonResource2 = Thread.currentThread().getContextClassLoader().getResource("data/another-file.json"); | ||
WorkflowJob proj = j.jenkins.createProject(WorkflowJob.class, "Horreum-Upload-Pipeline"); | ||
assertNotNull(j); | ||
assertNotNull(j.jenkins); | ||
WorkflowJob proj = j.jenkins.createProject(WorkflowJob.class, "Horreum-Upload-Pipeline-testUploadMultiple"); | ||
FilePath folder = j.jenkins.getWorkspaceFor(proj).child("run"); | ||
folder.child("config-quickstart.jvm.json").copyFrom(jsonResource1); | ||
folder.child("another-file.json").copyFrom(jsonResource2); | ||
io.hyperfoil.tools.horreum.api.data.Test dummyTest = createTest(info.getTestClass() + "-upload-multiple", "dev-team"); | ||
proj.setDefinition(new CpsFlowDefinition( | ||
"node {\n" + | ||
"def id = horreumUpload(\n" + | ||
"credentials: '" + HorreumPluginTestBase.HORREUM_UPLOAD_CREDENTIALS + "',\n" + | ||
"test: '" + dummyTest.name + "',\n" + | ||
"owner: '" + dummyTest.owner + "',\n" + | ||
"access: 'PUBLIC',\n" + | ||
"start: '1970-01-01T00:00:00.00Z',\n" + | ||
"stop: '1970-01-01T00:00:01.00Z',\n" + | ||
"files: '**/*.json',\n"+ | ||
"addBuildInfo: true\n" + | ||
")\n" + | ||
"println(id)\n" + | ||
"}\n", | ||
true)); | ||
"node {\n" + | ||
"def id = horreumUpload(\n" + | ||
"credentials: '" + HORREUM_UPLOAD_CREDENTIALS + "',\n" + | ||
"test: '" + dummyTest.name + "',\n" + | ||
"owner: '" + dummyTest.owner + "',\n" + | ||
"access: 'PUBLIC',\n" + | ||
"start: '1970-01-01T00:00:00.00Z',\n" + | ||
"stop: '1970-01-01T00:00:01.00Z',\n" + | ||
"files: '**/*.json',\n"+ | ||
"addBuildInfo: true\n" + | ||
")\n" + | ||
"println(id)\n" + | ||
"}\n", | ||
true)); | ||
WorkflowRun run = proj.scheduleBuild2(0).get(); | ||
j.assertBuildStatusSuccess(run); | ||
RunService.RunsSummary summary = horreumClient.runService.listTestRuns(dummyTest.id, false, null, null, "", null); | ||
RunService.RunsSummary summary = getHorreumClient().runService.listTestRuns(dummyTest.id, false, null, null, "", null); | ||
assertEquals(1, summary.total); | ||
assertEquals(1, summary.runs.size()); | ||
Object runObject = horreumClient.runService.getRun(summary.runs.get(0).id,summary.runs.get(0).token); | ||
RunService.RunExtended runObject = getHorreumClient().runService.getRun(summary.runs.get(0).id,summary.runs.get(0).token); | ||
assertNotNull(runObject); | ||
assertTrue(runObject instanceof Map,"run should return a map"); | ||
Object data = ((Map)runObject).get("data"); | ||
assertInstanceOf(RunService.RunExtended.class, runObject,"run should return a RunService.RunExtended"); | ||
Object data = runObject.data; | ||
assertNotNull(data); | ||
assertTrue(data instanceof Map,"data should be a map"); | ||
assertEquals(2,((Map<?, ?>) data).size(),"data should have an entry for each file"); | ||
assertInstanceOf(ObjectNode.class, data,"data should be a ObjectNode"); | ||
assertEquals(2,((ObjectNode) data).size(),"data should have an entry for each file"); | ||
} | ||
} |
Oops, something went wrong.