/** This test unit is for testing a commit hook using the UUID */ @Bug(399165) @Test public void testPrebuiltCommitTrigger() throws Exception { hudson.setCrumbIssuer(null); // First create repository with 1 file and commit information SVNCommitInfo info = createSVNRepository(); assertNull(info.getErrorMessage()); assertEquals("Failed to create 1 revision.", 1, info.getNewRevision()); // Create freestyle project with SVN SCM. FreeStyleProject project = createFreeStyleProject(); project.setScm(new SubversionSCM("file:///tmp/399165")); SCMTrigger trigger = new SCMTrigger("0 */6 * * *"); project.addTrigger(trigger); trigger.start(project, true); // Execute build (This is critical for fixing eclipse bug: 399165) assertBuildStatusSuccess(project.scheduleBuild2(0)); // Commit a file again. info = createSecondCommit(); assertNull(info.getErrorMessage()); assertEquals("Failed to create second commit.", 2, info.getNewRevision()); // Create post-commit hook WebClient wc = new WebClient(); WebRequestSettings wr = new WebRequestSettings( new URL( getURL() + "subversion/" + repository.getRepositoryUUID(false) + "/notifyCommit"), HttpMethod.POST); wr.setRequestBody("A dirB/file2.txt"); wr.setAdditionalHeader("Content-Type", "text/plain;charset=UTF-8"); wr.setAdditionalHeader("X-Hudson-Subversion-Revision", "2"); WebConnection conn = wc.getWebConnection(); System.out.println(wr); WebResponse resp = conn.getResponse(wr); assertTrue(isGoodHttpStatus(resp.getStatusCode())); waitUntilNoActivity(); FreeStyleBuild b = project.getLastBuild(); assertNotNull(b); assertBuildStatus(Result.SUCCESS, b); assertEquals("Failed to execute a buid.", 2, b.getNumber()); }
/** * Creates a {@link FreeStyleProject} with a gerrit-trigger configured. * * @param base the test case that is doing the current testing. * @param name the name of the new job. * @return the project. * @throws Exception if so. */ public static FreeStyleProject createGerritTriggeredJob(HudsonTestCase base, String name) throws Exception { FreeStyleProject p = base.hudson.createProject(FreeStyleProject.class, name); List<GerritProject> projects = new LinkedList<GerritProject>(); projects.add( new GerritProject( CompareType.ANT, "**", Collections.singletonList(new Branch(CompareType.ANT, "**", false)), null)); p.addTrigger( new GerritTrigger( projects, null, null, null, null, null, null, null, null, null, null, null, false, true, false, null, null, null, null, null, null, null, null, false, false, null)); base.submit(base.createWebClient().getPage(p, "configure").getFormByName("config")); return p; }
@Test public void testPostCommitTrigger() throws Exception { // Disable crumbs because HTMLUnit refuses to mix request bodies with // request parameters hudson.setCrumbIssuer(null); FreeStyleProject p = createFreeStyleProject(); String url = "https://tsethudsonsvn.googlecode.com/svn/trunk"; SCMTrigger trigger = new SCMTrigger("0 */6 * * *"); p.setScm(new SubversionSCM(url)); p.addTrigger(trigger); trigger.start(p, true); String repoUUID = "b703df53-fdd9-0691-3d8c-58db40123d9f"; WebClient wc = new WebClient(); WebRequestSettings wr = new WebRequestSettings( new URL(getURL() + "subversion/" + repoUUID + "/notifyCommit"), HttpMethod.POST); wr.setRequestBody("A trunk/testcommit.txt"); wr.setAdditionalHeader("Content-Type", "text/plain;charset=UTF-8"); wr.setAdditionalHeader("X-Hudson-Subversion-Revision", "16"); WebConnection conn = wc.getWebConnection(); WebResponse resp = conn.getResponse(wr); assertTrue(isGoodHttpStatus(resp.getStatusCode())); waitUntilNoActivity(); FreeStyleBuild b = p.getLastBuild(); assertNotNull(b); assertBuildStatus(Result.SUCCESS, b); SVNRevisionState revisionState = b.getAction(SVNRevisionState.class); assertNotNull("Failed to find revision", revisionState); assertNotNull("Failed to find revision", revisionState.revisions.get(url)); assertEquals(16, revisionState.revisions.get(url).longValue()); }
/** * Creates a {@link FreeStyleProject} with a gerrit-trigger dynamically configured. * * @param base the test case that is doing the current testing. * @param name the name of the new job. * @return the project. * @throws Exception if so. */ public static FreeStyleProject createGerritDynamicTriggeredJob(HudsonTestCase base, String name) throws Exception { FreeStyleProject p = base.hudson.createProject(FreeStyleProject.class, name); List<GerritProject> projects = new LinkedList<GerritProject>(); File file = File.createTempFile("dynamic", "txt"); FileWriter fw = new FileWriter(file); fw.write("p=project\n"); fw.write("b=branch"); fw.close(); List<PluginGerritEvent> list = new LinkedList<PluginGerritEvent>(); URI uri = file.toURI(); String filepath = uri.toURL().toString(); GerritTrigger trigger = new GerritTrigger( projects, null, null, null, null, null, null, null, null, null, null, null, false, true, false, null, null, null, null, null, null, null, list, true, false, filepath); p.addTrigger(trigger); base.submit(base.createWebClient().getPage(p, "configure").getFormByName("config")); return p; }