public Long getActualRevision(FreeStyleBuild b, String url) throws Exception { SVNRevisionState revisionState = b.getAction(SVNRevisionState.class); if (revisionState == null) { throw new Exception("No revision found!"); } return revisionState.revisions.get(url); } /**
@LocalData @Test public void testNonDescendantRelativePath() throws Exception { FreeStyleBuild build = project.scheduleBuild2(0).get(10, TimeUnit.MINUTES); // leave time for interactive debugging rule.assertBuildStatus(Result.UNSTABLE, build); TestResult theOverallTestResult = build.getAction(TestResultAction.class).getResult(); CaseResult theFailedTestCase = theOverallTestResult.getFailedTests().get(0); String relativePath = theFailedTestCase.getRelativePathFrom(theOverallTestResult); System.out.println("relative path seems to be: " + relativePath); assertNotNull("relative path exists", relativePath); assertFalse("relative path doesn't start with a slash", relativePath.startsWith("/")); // Now ask for the relative path from the child to the parent -- we should get an absolute path String relativePath2 = theOverallTestResult.getRelativePathFrom(theFailedTestCase); System.out.println("relative path2 seems to be: " + relativePath2); // I know that in a HudsonTestCase we don't have a meaningful root url, so I expect an empty string here. // If somehow we start being able to produce a root url, then I'll also tolerate a url that starts with that. boolean pathIsEmptyOrNull = relativePath2 == null || relativePath2.isEmpty(); boolean pathStartsWithRootUrl = !pathIsEmptyOrNull && relativePath2.startsWith(rule.jenkins.getRootUrl()); assertTrue("relative path is empty OR begins with the app root", pathIsEmptyOrNull || pathStartsWithRootUrl ); } }
@Test public void getUpstreamRunIfAvailable() throws Exception { FreeStyleBuild build = buildWithConduit(getFetchDiffResponse(), null, null, true); FreeStyleBuild upstream = buildWithConduit(getFetchDiffResponse(), null, null, true); assertNull(PhabricatorBuildWrapper.getUpstreamRun(build)); List<Cause> causes = build.getAction(CauseAction.class).getCauses(); ArrayList<Cause> newCauses = new ArrayList<Cause>(causes); newCauses.add((new Cause.UpstreamCause(upstream))); build.replaceAction(new CauseAction(newCauses)); assertEquals(upstream, PhabricatorBuildWrapper.getUpstreamRun(build)); }
public String buildAndCheck(FreeStyleProject p, String name, Action... actions) throws Exception { FreeStyleBuild b = j.assertBuildStatusSuccess(p.scheduleBuild2(0, null, actions).get()); // for (String line : b.getLog(Integer.MAX_VALUE)) { // System.err.println(">> " + line); // } if (!b.getWorkspace().child(name).exists()) { Set<String> children = new TreeSet<>(); for (FilePath child : b.getWorkspace().list()) { children.add(child.getName()); } fail("Could not find " + name + " among " + children); } assertNotNull(b.getAction(MercurialTagAction.class)); @SuppressWarnings("deprecation") String log = b.getLog(); return log; }
@Bug(10706) @Test public void testGetBranchFromTag() throws Exception { initRepoWithTag(); FreeStyleProject p = j.createFreeStyleProject(); p.setScm(new MercurialSCM(hgInstallation(), repo.getPath(), MercurialSCM.RevisionType.TAG, "release", null, null, null, false, null)); FreeStyleBuild b = j.buildAndAssertSuccess(p); MercurialTagAction action = b.getAction(MercurialTagAction.class); assertNotNull(action); assertEquals("stable", action.getBranch()); assertEquals("stable", b.getEnvironment().get("MERCURIAL_REVISION_BRANCH")); }
/** * Verifies that the error message and stacktrace from a failed junit test actually render properly. */ @Issue("JENKINS-4257") @Test public void testFreestyleErrorMsgAndStacktraceRender() throws Exception { FreeStyleBuild b = configureTestBuild("render-test"); TestResult tr = b.getAction(TestResultAction.class).getResult(); assertEquals(3,tr.getFailedTests().size()); CaseResult cr = tr.getFailedTests().get(1); assertEquals("org.twia.vendor.VendorManagerTest",cr.getClassName()); assertEquals("testGetRevokedClaimsForAdjustingFirm",cr.getName()); assertNotNull("Error details should not be null", cr.getErrorDetails()); assertNotNull("Error stacktrace should not be null", cr.getErrorStackTrace()); String testUrl = cr.getRelativePathFrom(tr); HtmlPage page = rule.createWebClient().goTo("job/render-test/1/testReport/" + testUrl); HtmlElement errorMsg = (HtmlElement) page.getByXPath("//h3[text()='Error Message']/following-sibling::*").get(0); assertEquals(cr.annotate(cr.getErrorDetails()).replaceAll("<", "<"), errorMsg.getTextContent()); HtmlElement errorStackTrace = (HtmlElement) page.getByXPath("//h3[text()='Stacktrace']/following-sibling::*").get(0); // Have to do some annoying replacing here to get the same text Jelly produces in the end. assertEquals(cr.annotate(cr.getErrorStackTrace()).replaceAll("<", "<").replace("\r\n", "\n"), errorStackTrace.getTextContent()); }
@Bug(10706) @Test public void testGetNoBranchFromBranch() throws Exception { initRepoWithTag(); FreeStyleProject p = j.createFreeStyleProject(); p.setScm(new MercurialSCM(hgInstallation(), repo.getPath(), MercurialSCM.RevisionType.BRANCH, "default", null, null, null, false, null)); FreeStyleBuild b = j.buildAndAssertSuccess(p); MercurialTagAction action = b.getAction(MercurialTagAction.class); assertNotNull(action); assertEquals(null, action.getBranch()); assertEquals(null, b.getEnvironment().get("MERCURIAL_REVISION_BRANCH")); }
private void assertTestResults(FreeStyleBuild build) { TestResultAction testResultAction = build.getAction(TestResultAction.class); assertNotNull("no TestResultAction", testResultAction); TestResult result = testResultAction.getResult(); assertNotNull("no TestResult", result); assertEquals("should have 1 failing test", 1, testResultAction.getFailCount()); assertEquals("should have 1 failing test", 1, result.getFailCount()); assertEquals("should have 132 total tests", 132, testResultAction.getTotalCount()); assertEquals("should have 132 total tests", 132, result.getTotalCount()); }
@LocalData @Test public void testFailureLinks() throws Exception { FreeStyleBuild build = project.scheduleBuild2(0).get(10, TimeUnit.SECONDS); rule.assertBuildStatus(Result.UNSTABLE, build); TestResult theOverallTestResult = build.getAction(TestResultAction.class).getResult(); CaseResult theFailedTestCase = theOverallTestResult.getFailedTests().get(0); String relativePath = theFailedTestCase.getRelativePathFrom(theOverallTestResult); System.out.println("relative path seems to be: " + relativePath); WebClient wc = rule.createWebClient(); String testReportPageUrl = project.getLastBuild().getUrl() + "/testReport"; HtmlPage testReportPage = wc.goTo( testReportPageUrl ); Page packagePage = testReportPage.getAnchorByText("tacoshack.meals").click(); rule.assertGoodStatus(packagePage); // I expect this to work; just checking that my use of the APIs is correct. // Now we're on that page. We should be able to find a link to the failed test in there. HtmlAnchor anchor = testReportPage.getAnchorByText("tacoshack.meals.NachosTest.testBeanDip"); String href = anchor.getHrefAttribute(); System.out.println("link is : " + href); Page failureFromLink = anchor.click(); rule.assertGoodStatus(failureFromLink); // Now check the >>> link -- this is harder, because we can't do the javascript click handler properly // The summary page is just tack on /summary to the url for the test }
/** * Tests that the builds from the FreeStyleProject can be loaded. */ @Test @LocalData public void testFreeStyleBuild() { Item item = j.jenkins.getItem("freestyleJob"); assertThat("Item is not a FreeStyleProject", item, instanceOf(FreeStyleProject.class)); FreeStyleProject proj = (FreeStyleProject)item; RunList<FreeStyleBuild> builds = proj.getBuilds(); assertNotNull(builds); assertFalse("The build list should not be empty", builds.isEmpty()); FreeStyleBuild freeStyleBuild = proj.getFirstBuild(); assertNotNull(freeStyleBuild.getAction(RetriggerAction.class)); GerritManualCause cause = freeStyleBuild.getCause(GerritManualCause.class); assertNotNull(cause); BadgeAction action = freeStyleBuild.getAction(BadgeAction.class); assertNotNull(action); GerritTriggeredEvent event = action.getEvent(); assertNotNull(event); GerritEventType eventType = event.getEventType(); assertSame(eventType.getEventRepresentative(), PatchsetCreated.class); }
@LocalData("All") @Test public void setDescription() throws Exception { FreeStyleBuild build = project.scheduleBuild2(0).get(10, TimeUnit.SECONDS); CaseResult caseResult = build.getAction(TestResultAction.class).getFailedTests().get(0); String url = build.getUrl() + "/testReport/" + caseResult.getRelativePathFrom(caseResult.getTestResult()); testSetDescription(url, caseResult); ClassResult classResult = caseResult.getParent(); url = build.getUrl() + "/testReport/" + classResult.getParent().getSafeName() + "/" + classResult.getSafeName(); testSetDescription(url, classResult); PackageResult packageResult = classResult.getParent(); url = build.getUrl() + "/testReport/" + classResult.getParent().getSafeName(); testSetDescription(url, packageResult); }
@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()); }
private void assertTestResults(FreeStyleBuild build) { TestResultAction testResultAction = build.getAction(TestResultAction.class); assertNotNull("no TestResultAction", testResultAction); TestResult result = testResultAction.getResult(); assertNotNull("no TestResult", result); assertEquals("should have 1 failing test", 1, testResultAction.getFailCount()); assertEquals("should have 1 failing test", 1, result.getFailCount()); assertEquals("should have 132 total tests", 132, testResultAction.getTotalCount()); assertEquals("should have 132 total tests", 132, result.getTotalCount()); for (SuiteResult suite : result.getSuites()) { assertNull("No nodeId should be present on the SuiteResult", suite.getNodeId()); } }
public void testIssue20090516() throws Exception { FreeStyleBuild b = configureTestBuild(null); TestResult tr = b.getAction(TestResultAction.class).getResult(); assertEquals(3,tr.getFailedTests().size()); CaseResult cr = tr.getFailedTests().get(0);
rule.assertBuildStatus(Result.SUCCESS, build7); TestResult tr = build4.getAction(TestResultAction.class).getResult(); assertEquals(2,tr.getFailedTests().size()); TestResult tr5 = project.getBuildByNumber(5).getAction(TestResultAction.class).getResult(); assertEquals(1,tr5.getFailedTests().size()); deepPackage = tr5.byPackage("org.jvnet.hudson.examples.small.deep");
r.assertBuildStatus(Result.SUCCESS,b); final SubversionTagAction action = b.getAction(SubversionTagAction.class); r.executeOnServer(() -> { assertFalse("Shouldn't be accessible to anonymous user",b.hasPermission(action.getPermission()));
public void testTrivialRecorder() throws Exception { FreeStyleProject project = createFreeStyleProject("trivialtest"); TrivialTestResultRecorder recorder = new TrivialTestResultRecorder(); project.getPublishersList().add(recorder); project.getBuildersList().add(new TouchBuilder()); FreeStyleBuild build = project.scheduleBuild2(0).get(5, TimeUnit.MINUTES); /* leave room for debugging*/ assertBuildStatus(Result.SUCCESS, build); TrivialTestResultAction action = build.getAction(TrivialTestResultAction.class); assertNotNull("we should have an action", action); assertNotNull("parent action should have an owner", action.run); Object resultObject = action.getResult(); assertNotNull("we should have a result"); assertTrue("result should be an TestResult", resultObject instanceof TestResult); TestResult result = (TestResult) resultObject; Run<?,?> ownerBuild = result.getRun(); assertNotNull("we should have an owner", ownerBuild); assertNotNull("we should have a list of test actions", result.getTestActions()); // Validate that there are test results where I expect them to be: HudsonTestCase.WebClient wc = new HudsonTestCase.WebClient(); HtmlPage projectPage = wc.getPage(project); assertGoodStatus(projectPage); HtmlPage testReportPage = wc.getPage(project, "/lastBuild/testReport/"); assertGoodStatus(testReportPage); } }