@Test public void testWithCredentialsIgnoresMissingConduit() throws Exception { FreeStyleBuild build = buildWithConduit(null, null, null); assertEquals(Result.SUCCESS, build.getResult()); assertLogContains("Unable to fetch differential", build); }
@Test public void testNoParametersBuild() throws Exception { addBuildStep(); FreeStyleBuild build = p.scheduleBuild2(0).get(); Result result = build.getResult(); assertSuccessfulBuild(result); }
@Test public void testNoParameterBuild() throws Exception { addBuildStep(); FreeStyleBuild build = p.scheduleBuild2(0).get(); Result result = build.getResult(); assertSuccessfulBuild(result); }
@Test public void testPostToHarbormaster() throws Exception { FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, new JSONObject()); assertEquals(Result.SUCCESS, build.getResult()); }
@Test public void testBuildValidWithoutHarbormaster() throws Exception { JSONObject commentResponse = new JSONObject(); FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), commentResponse, null, false); assertEquals(Result.SUCCESS, build.getResult()); }
@Test public void testNonDifferentialWithPHID() throws Exception { FreeStyleBuild build = buildWithCommit(new JSONObject()); assertEquals(Result.SUCCESS, build.getResult()); assertLogContains("Sending diffusion result", build); }
@Test public void testPassBuildOnSameCoverage() throws Exception { TestUtils.addCopyBuildStep(p, TestUtils.COBERTURA_XML, XmlCoverageProvider.class, "go-torch-coverage2.xml"); UberallsClient uberalls = TestUtils.getDefaultUberallsClient(); notifier = getDecreasedLineCoverageNotifier(0.0); when(uberalls.getCoverage(any(String.class))).thenReturn("{\n" + " \"sha\": \"deadbeef\",\n" + " \"lineCoverage\": 0.0,\n" + " \"packageCoverage\": 0,\n" + " \"classesCoverage\": 0,\n" + " \"methodCoverage\": 0,\n" + " \"conditionalCoverage\": 100,\n" + " \"linesCovered\": 100,\n" + " \"linesTested\": 100\n" + "}"); notifier.setUberallsClient(uberalls); FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, new JSONObject()); assertEquals(Result.SUCCESS, build.getResult()); }
@Test public void testPostCoverageWithoutPublisher() throws Exception { TestUtils.addCopyBuildStep(p, "src/coverage/" + TestUtils.COBERTURA_XML, XmlCoverageProvider.class, "go-torch-coverage.xml"); FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, new JSONObject()); assertEquals(Result.SUCCESS, build.getResult()); assertLogContains("Publishing coverage data to Harbormaster for 3 files", build); }
@Test public void testBuildInvalidConduit() throws Exception { TestUtils.addInvalidCredentials(); addBuildStep(); TestUtils.setDefaultBuildEnvironment(j); FreeStyleBuild build = p.scheduleBuild2(0).get(); assertEquals(Result.FAILURE, build.getResult()); }
@Test public void testPostCoverage() throws Exception { TestUtils.addCopyBuildStep(p, TestUtils.COBERTURA_XML, XmlCoverageProvider.class, "go-torch-coverage.xml"); FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, new JSONObject()); assertEquals(Result.SUCCESS, build.getResult()); assertLogContains("Publishing coverage data to Harbormaster for 3 files", build); }
@Test public void testPostCoverageWithoutPublisherWithEmptyReportPattern() throws Exception { String[] emptyPatterns = {null, ""}; for (String emptyPattern : emptyPatterns) { notifier = getTestNotifier(emptyPattern); TestUtils.addCopyBuildStep(p, "src/coverage/" + TestUtils.COBERTURA_XML, XmlCoverageProvider.class, "go-torch-coverage.xml"); FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, new JSONObject()); assertEquals(Result.SUCCESS, build.getResult()); assertLogContains("Publishing coverage data to Harbormaster for 3 files", build); } }
@Test public void testPostCoverageWithoutPublisherWithNoFilesMatchingReportPattern() throws Exception { notifier = getTestNotifier("*.html"); TestUtils.addCopyBuildStep(p, "src/coverage/" + TestUtils.COBERTURA_XML, XmlCoverageProvider.class, "go-torch-coverage.xml"); FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, new JSONObject()); assertEquals(Result.SUCCESS, build.getResult()); assertLogContains("No coverage results found", build); }
@Test public void testPostToHarbormasterValidLint() throws Exception { JSONObject json = new JSONObject(); LintResults result = new LintResults(); result.add(new LintResult("test", "testcode", "error", "to/path", 10, 3, "test description")); json.element("lint", result); FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, json); assertEquals(Result.SUCCESS, build.getResult()); }
@Test public void testPostUnitWithFailure() throws Exception { TestUtils.addCopyBuildStep(p, TestUtils.JUNIT_XML, JUnitTestProvider.class, "go-torch-junit-fail.xml"); p.getPublishersList().add(TestUtils.getDefaultXUnitPublisher()); FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, new JSONObject()); assertEquals(Result.UNSTABLE, build.getResult()); assertLogContains("Publishing unit results to Harbormaster for 8 tests", build); FakeConduit conduitTestClient = getConduitClient(); // There are two requests, first it fetches the diff info, secondly it posts the unit result to harbormaster assertEquals(2, conduitTestClient.getRequestBodies().size()); String actualUnitResultWithFailureRequestBody = conduitTestClient.getRequestBodies().get(1); assertConduitRequest(getUnitResultWithFailureRequest(), actualUnitResultWithFailureRequestBody); }
@Test public void testPostUnit() throws Exception { TestUtils.addCopyBuildStep(p, TestUtils.JUNIT_XML, JUnitTestProvider.class, "go-torch-junit.xml"); p.getPublishersList().add(TestUtils.getDefaultXUnitPublisher()); FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, new JSONObject()); assertEquals(Result.SUCCESS, build.getResult()); assertLogContains("Publishing unit results to Harbormaster for 35 tests", build); }
/** * Tests to trigger a build with a dynamic configuration. * @param branchSetting the dynamic branch setting with operator e.g. "^**" or "=branch" * * @throws Exception if so. */ private void testDynamicTriggeredBuild(String branchSetting) throws Exception { ((Config)gerritServer.getConfig()).setDynamicConfigRefreshInterval(1); FreeStyleProject project = DuplicatesUtil.createGerritDynamicTriggeredJob(j, "projectX", branchSetting); serverMock.waitForCommand(GERRIT_STREAM_EVENTS, 2000); waitForDynamicTimer(project, 8000); gerritServer.triggerEvent(Setup.createPatchsetCreated()); TestUtils.waitForBuilds(project, 1); FreeStyleBuild build = project.getLastCompletedBuild(); assertSame(Result.SUCCESS, build.getResult()); }
@Test public void skipApplyPatchDoesNotFailPatching() throws Exception { p = createProject(); wrapper = new PhabricatorBuildWrapper( false, false, false, false, false, true ); wrapper.getDescriptor().setArcPath("false"); p.getBuildWrappersList().add(wrapper); FreeStyleBuild build = p.scheduleBuild2(0).get(); Result result = build.getResult(); assertSuccessfulBuild(result); }
@Test public void testBuildValidSuccess() throws Exception { JSONObject commentResponse = new JSONObject(); FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), commentResponse, null, true); assertEquals(Result.SUCCESS, build.getResult()); PhabricatorPostbuildSummaryAction action = build.getAction(PhabricatorPostbuildSummaryAction.class); assertNotNull(action); assertEquals("sc@ndella.com", action.getAuthorEmail()); assertEquals("aiden", action.getAuthorName()); assertEquals("commit message", action.getCommitMessage()); assertNotNull(action.getIconPath()); }
/** * Tests that a new build can be triggered for the old FreeStyleProject. */ @Test @LocalData public void testNewTriggeredBuild() { server.waitForCommand(GERRIT_STREAM_EVENTS, 10000); Item item = j.jenkins.getItem("freestyleJob"); assertThat("Item is not a FreeStyleProject", item, instanceOf(FreeStyleProject.class)); FreeStyleProject project = (FreeStyleProject)item; int number = project.getLastBuild().getNumber() + 1; PluginImpl.getServer_(PluginImpl.DEFAULT_SERVER_NAME).triggerEvent(Setup.createPatchsetCreated()); TestUtils.waitForBuilds(project, number, 20000); //3 old builds + the new one. assertEquals(number, project.getLastCompletedBuild().getNumber()); assertSame(Result.SUCCESS, project.getLastCompletedBuild().getResult()); }
/** * Tests that a comment added triggers a build correctly. * * @throws Exception if so. */ @Test @LocalData public void testTriggerOnCommentAdded() throws Exception { gerritServer.getConfig().setCategories(Setup.createCodeReviewVerdictCategoryList()); FreeStyleProject project = DuplicatesUtil.createGerritTriggeredJobForCommentAdded(j, "projectX"); project.getBuildersList().add(new SleepBuilder(2000)); serverMock.waitForCommand(GERRIT_STREAM_EVENTS, 2000); CommentAdded firstEvent = Setup.createCommentAdded(); gerritServer.triggerEvent(firstEvent); TestUtils.waitForBuilds(project, 1); assertEquals(1, project.getLastCompletedBuild().getNumber()); assertSame(Result.SUCCESS, project.getLastCompletedBuild().getResult()); }