src/test/java/org/jenkinsci/plugins/pretestedintegrationmercurial/MercurialIT.java
public void testRejectedCommitFailure() throws Exception {
		
		//initialise remote
		setup();
		File remote = createTempDirectory();
		hg(remote,"init");
		File foo = new File(remote,"foo");
		FileUtils.touch(foo);
		hg(remote,"add","foo");

		File bar = new File(remote,"bar");
		FileUtils.touch(bar);
		hg(remote,"add","bar");
		hg(remote,"commit","-m","Initial import");
		
		//setup and configure 2 jobs for different branches with pretested integration
		FreeStyleProject alice = createJob(remote.getAbsolutePath(),"alice","alice","default");
		FreeStyleProject bob = createJob(remote.getAbsolutePath(),"bob","bob","default");
				
		//work on one branch
		hg(remote,"branch","alice");
		FileUtils.writeStringToFile(foo, "hello, world!");
		hg(remote,"commit","-m","Added foo");
		String aliceRevision = hg(remote,"tip","--template","{node}").toString();
		
		//work on the other
		hg(remote,"branch","bob");
		FileUtils.writeStringToFile(bar, "hello, world!");
		hg(remote,"commit","-m","Added bar");
		String bobRevision = hg(remote,"tip","--template","{node}").toString();
		//For some reason bobs build fails
		TestBuilder failBuilder = new TestBuilder() {

			@Override
			public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
					BuildListener listener) throws InterruptedException,
					IOException {
				build.setResult(Result.FAILURE);
				return false;
			}
		};
		bob.getBuildersList().add(failBuilder);
		//trigger jenkins build
		Future<FreeStyleBuild> aliceBuild = alice.scheduleBuild2(0);
		Future<FreeStyleBuild> bobBuild = bob.scheduleBuild2(0);
		
		//We only need to wait for bobs build as alices is bound to complete first
		aliceBuild.get();
		bobBuild.get();
		
		//the jobs should now be present in the integration branch merged in the same order as comitted.
		ByteArrayOutputStream revisions = hg(remote,"log","--branch","default","--template","{desc}\n","-r",":");
		String[] revArr = revisions.toString().split("\n");
		//The first element is the initial commit
		assertTrue(revArr[1].startsWith("Merge of revision " + aliceRevision));
		//Only alices commit is integrated
		assertTrue(revArr.length == 2);
		
		//alice works on
		hg(remote,"update","alice");
		hg(remote,"merge","default");
		hg(remote,"commit","-m","Synched with default");
		String aliceRevision2 = hg(remote,"tip","--template","{node}").toString();
		alice.scheduleBuild2(0).get();
		FileUtils.writeStringToFile(foo, "hello, world from foo");
		hg(remote,"commit","-m","Added sender in bar");
		String aliceRevision3 =  hg(remote,"tip","--template","{node}").toString();
		alice.scheduleBuild2(0).get();
		
		bob.getBuildersList().remove(failBuilder);
		hg(remote,"update","bob");
		FileUtils.writeStringToFile(bar, "hello, world from bar");
		hg(remote,"commit","-m","Added sender in bar");
		String bobRevision2 = hg(remote,"tip","--template","{node}").toString();
		bob.scheduleBuild2(0).get();
		
		//this time around the merge should succeed
		
		revisions = hg(remote,"log","--branch","default","--template","{desc}\n","-r",":");
		revArr = revisions.toString().split("\n");
		
		assertTrue(revArr[2].startsWith("Merge of revision " + aliceRevision2));
		assertTrue(revArr[3].startsWith("Merge of revision " + aliceRevision3));
		assertTrue(revArr[4].startsWith("Merge of revision " + bobRevision2));
		assertTrue(revArr.length == 5);
	}
/**
	 * Test that a rejected commit does not ruin the integration branch
	 */
Test that a rejected commit does not ruin the integration branch
Test that a rejected commit does not ruin the integration branch
public void testRejectedCommitFailure() throws Exception {
		setup();
		File remote = createTempDirectory();
		hg(remote,"init");
		File foo = new File(remote,"foo");
		FileUtils.touch(foo);
		hg(remote,"add","foo");
		File bar = new File(remote,"bar");
		FileUtils.touch(bar);
		hg(remote,"add","bar");
		hg(remote,"commit","-m","Initial import");
		FreeStyleProject alice = createJob(remote.getAbsolutePath(),"alice","alice","default");
		FreeStyleProject bob = createJob(remote.getAbsolutePath(),"bob","bob","default");
		hg(remote,"branch","alice");
		FileUtils.writeStringToFile(foo, "hello, world!");
		hg(remote,"commit","-m","Added foo");
		String aliceRevision = hg(remote,"tip","--template","{node}").toString();
		hg(remote,"branch","bob");
		FileUtils.writeStringToFile(bar, "hello, world!");
		hg(remote,"commit","-m","Added bar");
		String bobRevision = hg(remote,"tip","--template","{node}").toString();
		TestBuilder failBuilder = new TestBuilder() {
			@Override
			public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
					BuildListener listener) throws InterruptedException,
					IOException {
				build.setResult(Result.FAILURE);
				return false;
			}
		};
		bob.getBuildersList().add(failBuilder);
		Future<FreeStyleBuild> aliceBuild = alice.scheduleBuild2(0);
		Future<FreeStyleBuild> bobBuild = bob.scheduleBuild2(0);
		aliceBuild.get();
		bobBuild.get();
		ByteArrayOutputStream revisions = hg(remote,"log","--branch","default","--template","{desc}\n","-r",":");
		String[] revArr = revisions.toString().split("\n");
		assertTrue(revArr[1].startsWith("Merge of revision " + aliceRevision));
		assertTrue(revArr.length == 2);
		hg(remote,"update","alice");
		hg(remote,"merge","default");
		hg(remote,"commit","-m","Synched with default");
		String aliceRevision2 = hg(remote,"tip","--template","{node}").toString();
		alice.scheduleBuild2(0).get();
		FileUtils.writeStringToFile(foo, "hello, world from foo");
		hg(remote,"commit","-m","Added sender in bar");
		String aliceRevision3 =  hg(remote,"tip","--template","{node}").toString();
		alice.scheduleBuild2(0).get();
		bob.getBuildersList().remove(failBuilder);
		hg(remote,"update","bob");
		FileUtils.writeStringToFile(bar, "hello, world from bar");
		hg(remote,"commit","-m","Added sender in bar");
		String bobRevision2 = hg(remote,"tip","--template","{node}").toString();
		bob.scheduleBuild2(0).get();
		revisions = hg(remote,"log","--branch","default","--template","{desc}\n","-r",":");
		revArr = revisions.toString().split("\n");
		assertTrue(revArr[2].startsWith("Merge of revision " + aliceRevision2));
		assertTrue(revArr[3].startsWith("Merge of revision " + aliceRevision3));
		assertTrue(revArr[4].startsWith("Merge of revision " + bobRevision2));
		assertTrue(revArr.length == 5);
	}
public void testRejectedCommitFailure ( ) throws Exception { setup ( ) ; File remote = createTempDirectory ( ) ; hg ( remote , "init" ) ; File foo = new File ( remote , "foo" ) ; FileUtils . touch ( foo ) ; hg ( remote , "add" , "foo" ) ; File bar = new File ( remote , "bar" ) ; FileUtils . touch ( bar ) ; hg ( remote , "add" , "bar" ) ; hg ( remote , "commit" , "-m" , "Initial import" ) ; FreeStyleProject alice = createJob ( remote . getAbsolutePath ( ) , "alice" , "alice" , "default" ) ; FreeStyleProject bob = createJob ( remote . getAbsolutePath ( ) , "bob" , "bob" , "default" ) ; hg ( remote , "branch" , "alice" ) ; FileUtils . writeStringToFile ( foo , "hello, world!" ) ; hg ( remote , "commit" , "-m" , "Added foo" ) ; String aliceRevision = hg ( remote , "tip" , "--template" , "{node}" ) . toString ( ) ; hg ( remote , "branch" , "bob" ) ; FileUtils . writeStringToFile ( bar , "hello, world!" ) ; hg ( remote , "commit" , "-m" , "Added bar" ) ; String bobRevision = hg ( remote , "tip" , "--template" , "{node}" ) . toString ( ) ; TestBuilder failBuilder = new TestBuilder ( ) { @ Override public boolean perform ( AbstractBuild < ? , ? > build , Launcher launcher , BuildListener listener ) throws InterruptedException , IOException { build . setResult ( Result . FAILURE ) ; return false ; } } ; bob . getBuildersList ( ) . add ( failBuilder ) ; Future < FreeStyleBuild > aliceBuild = alice . scheduleBuild2 ( 0 ) ; Future < FreeStyleBuild > bobBuild = bob . scheduleBuild2 ( 0 ) ; aliceBuild . get ( ) ; bobBuild . get ( ) ; ByteArrayOutputStream revisions = hg ( remote , "log" , "--branch" , "default" , "--template" , "{desc}\n" , "-r" , ":" ) ; String [ ] revArr = revisions . toString ( ) . split ( "\n" ) ; assertTrue ( revArr [ 1 ] . startsWith ( "Merge of revision " + aliceRevision ) ) ; assertTrue ( revArr . length == 2 ) ; hg ( remote , "update" , "alice" ) ; hg ( remote , "merge" , "default" ) ; hg ( remote , "commit" , "-m" , "Synched with default" ) ; String aliceRevision2 = hg ( remote , "tip" , "--template" , "{node}" ) . toString ( ) ; alice . scheduleBuild2 ( 0 ) . get ( ) ; FileUtils . writeStringToFile ( foo , "hello, world from foo" ) ; hg ( remote , "commit" , "-m" , "Added sender in bar" ) ; String aliceRevision3 = hg ( remote , "tip" , "--template" , "{node}" ) . toString ( ) ; alice . scheduleBuild2 ( 0 ) . get ( ) ; bob . getBuildersList ( ) . remove ( failBuilder ) ; hg ( remote , "update" , "bob" ) ; FileUtils . writeStringToFile ( bar , "hello, world from bar" ) ; hg ( remote , "commit" , "-m" , "Added sender in bar" ) ; String bobRevision2 = hg ( remote , "tip" , "--template" , "{node}" ) . toString ( ) ; bob . scheduleBuild2 ( 0 ) . get ( ) ; revisions = hg ( remote , "log" , "--branch" , "default" , "--template" , "{desc}\n" , "-r" , ":" ) ; revArr = revisions . toString ( ) . split ( "\n" ) ; assertTrue ( revArr [ 2 ] . startsWith ( "Merge of revision " + aliceRevision2 ) ) ; assertTrue ( revArr [ 3 ] . startsWith ( "Merge of revision " + aliceRevision3 ) ) ; assertTrue ( revArr [ 4 ] . startsWith ( "Merge of revision " + bobRevision2 ) ) ; assertTrue ( revArr . length == 5 ) ; }
Test that a rejected commit does not ruin the integration branch
Test that a rejected commit does not ruin the integration branch
//initialise remote //setup and configure 2 jobs for different branches with pretested integration //work on one branch //work on the other //For some reason bobs build fails //trigger jenkins build //We only need to wait for bobs build as alices is bound to complete first //the jobs should now be present in the integration branch merged in the same order as comitted. //The first element is the initial commit //Only alices commit is integrated //alice works on //this time around the merge should succeed