Modified: continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java?rev=764863&r1=764862&r2=764863&view=diff ============================================================================== --- continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java (original) +++ continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/continuum/buildmanager/ParallelBuildsManagerTest.java Tue Apr 14 16:28:12 2009 @@ -28,10 +28,10 @@ import org.apache.continuum.buildqueue.BuildQueueService; import org.apache.continuum.dao.BuildDefinitionDao; -import org.apache.continuum.taskqueue.OverallBuildQueue; -import org.apache.continuum.taskqueueexecutor.ParallelBuildsThreadedTaskQueueExecutor; import org.apache.continuum.taskqueue.BuildProjectTask; import org.apache.continuum.taskqueue.CheckOutTask; +import org.apache.continuum.taskqueue.OverallBuildQueue; +import org.apache.continuum.taskqueueexecutor.ParallelBuildsThreadedTaskQueueExecutor; import org.apache.maven.continuum.configuration.ConfigurationService; import org.apache.maven.continuum.model.project.BuildDefinition; import org.apache.maven.continuum.model.project.BuildQueue; @@ -48,7 +48,7 @@ /** * ParallelBuildsManagerTest - * + * * @author Maria Odea Ching */ public class ParallelBuildsManagerTest @@ -59,17 +59,13 @@ private Mockery context; private BuildDefinitionDao buildDefinitionDao; - - private TaskQueue prepareBuildQueue; - + private ConfigurationService configurationService; - - private BuildQueueService buildQueueService; - + private OverallBuildQueue overallBuildQueue; - + private TaskQueue buildQueue; - + private TaskQueue checkoutQueue; @Override @@ -86,21 +82,21 @@ buildDefinitionDao = context.mock( BuildDefinitionDao.class ); buildsManager.setBuildDefinitionDao( buildDefinitionDao ); - - prepareBuildQueue = context.mock( TaskQueue.class, "prepare-build-queue" ); - + + TaskQueue prepareBuildQueue = context.mock( TaskQueue.class, "prepare-build-queue" ); + buildsManager.setPrepareBuildQueue( prepareBuildQueue ); - + configurationService = context.mock( ConfigurationService.class ); - + buildsManager.setConfigurationService( configurationService ); - - buildQueueService = context.mock( BuildQueueService.class ); - - buildsManager.setBuildQueueService( buildQueueService ); + + BuildQueueService buildQueueService = context.mock( BuildQueueService.class ); + + buildsManager.setBuildQueueService( buildQueueService ); buildQueue = context.mock( TaskQueue.class, "build-queue" ); - + checkoutQueue = context.mock( TaskQueue.class, "checkout-queue" ); } @@ -146,21 +142,21 @@ return schedule; } - + public void setupMockOverallBuildQueues() throws Exception - { + { Map overallBuildQueues = Collections.synchronizedMap( new HashMap() ); - overallBuildQueue = context.mock( OverallBuildQueue.class ); - for ( int i = 1; i <=5; i++ ) - { - overallBuildQueues.put( new Integer( i ), overallBuildQueue ); + overallBuildQueue = context.mock( OverallBuildQueue.class ); + for ( int i = 1; i <= 5; i++ ) + { + overallBuildQueues.put( i, overallBuildQueue ); } - + buildsManager.setOverallBuildQueues( overallBuildQueues ); } - + // build project recordings private void recordStartOfBuildProjectSequence() throws TaskQueueException @@ -168,50 +164,47 @@ context.checking( new Expectations() { { - exactly(5).of( overallBuildQueue ).isInBuildQueue( with( any(int.class) ) ); + exactly( 5 ).of( overallBuildQueue ).isInBuildQueue( with( any( int.class ) ) ); will( returnValue( false ) ); - + one( configurationService ).getNumberOfBuildsInParallel(); will( returnValue( 2 ) ); - - exactly(2).of( overallBuildQueue ).getBuildQueue(); + + exactly( 2 ).of( overallBuildQueue ).getBuildQueue(); will( returnValue( buildQueue ) ); - } - } ); + }} ); } - + private void recordBuildProjectBuildQueuesAreEmpty() throws TaskQueueException { // shouldn't only the build queues attached to the schedule be checked? recordStartOfBuildProjectSequence(); - - final List tasks = new ArrayList(); + + final List tasks = new ArrayList(); context.checking( new Expectations() { { - exactly(3).of( buildQueue ).getQueueSnapshot(); + exactly( 3 ).of( buildQueue ).getQueueSnapshot(); will( returnValue( tasks ) ); - - one( overallBuildQueue).getName(); + + one( overallBuildQueue ).getName(); will( returnValue( "BUILD_QUEUE_2" ) ); - } - } ); - + }} ); + recordAddToBuildQueue(); } - + private void recordAddToBuildQueue() throws TaskQueueException { context.checking( new Expectations() { { - one( overallBuildQueue).addToBuildQueue( with( any( Task.class ) ) ); - } - } ); + one( overallBuildQueue ).addToBuildQueue( with( any( Task.class ) ) ); + }} ); } - + // checkout project recordings private void recordStartOfCheckoutProjectSequence() throws TaskQueueException @@ -219,39 +212,37 @@ context.checking( new Expectations() { { - exactly(5).of(overallBuildQueue).isInCheckoutQueue( with( any( int.class ) ) ); - will( returnValue( false ) ); - + exactly( 5 ).of( overallBuildQueue ).isInCheckoutQueue( with( any( int.class ) ) ); + will( returnValue( false ) ); + one( configurationService ).getNumberOfBuildsInParallel(); will( returnValue( 2 ) ); - - exactly(2).of( overallBuildQueue ).getCheckoutQueue(); + + exactly( 2 ).of( overallBuildQueue ).getCheckoutQueue(); will( returnValue( checkoutQueue ) ); - } - } ); - + }} ); + } - + private void recordCheckoutProjectBuildQueuesAreEmpty() throws TaskQueueException { recordStartOfCheckoutProjectSequence(); - - final List tasks = new ArrayList(); + + final List tasks = new ArrayList(); context.checking( new Expectations() { { - exactly(3).of( checkoutQueue ).getQueueSnapshot(); + exactly( 3 ).of( checkoutQueue ).getQueueSnapshot(); will( returnValue( tasks ) ); - - one( overallBuildQueue).getName(); + + one( overallBuildQueue ).getName(); will( returnValue( "BUILD_QUEUE_2" ) ); - } - } ); - + }} ); + recordAddToCheckoutQueue(); } - + private void recordAddToCheckoutQueue() throws TaskQueueException { @@ -259,22 +250,21 @@ { { one( overallBuildQueue ).addToCheckoutQueue( with( any( Task.class ) ) ); - } - } ); + }} ); } // start of test cases.. - + public void testContainer() throws Exception { buildsManager.setContainer( getContainer() ); - + buildsManager.isProjectInAnyCurrentBuild( 1 ); - + assertTrue( true ); } - + public void testBuildProjectNoProjectQueuedInAnyOverallBuildQueues() throws Exception { @@ -285,12 +275,12 @@ buildDef.setSchedule( getSchedule( 1, 1, 2 ) ); recordBuildProjectBuildQueuesAreEmpty(); - + buildsManager.buildProject( 1, buildDef, "continuum-project-test-1", 1, null ); - + context.assertIsSatisfied(); } - + public void testBuildProjectProjectsAreAlreadyQueuedInOverallBuildQueues() throws Exception { @@ -301,110 +291,108 @@ buildDef.setSchedule( getSchedule( 1, 1, 2 ) ); recordBuildProjectBuildQueuesAreEmpty(); - + buildsManager.buildProject( 1, buildDef, "continuum-project-test-1", 1, null ); context.assertIsSatisfied(); - + //queue second project - 1st queue is not empty, 2nd queue is empty recordStartOfBuildProjectSequence(); - + // the first build queue already has a task queued final List tasks = new ArrayList(); final List tasksOfFirstBuildQueue = new ArrayList(); - tasksOfFirstBuildQueue.add( new BuildProjectTask( 2, 1, 1, "continuum-project-test-2", buildDef.getDescription(), null ) ); + tasksOfFirstBuildQueue.add( + new BuildProjectTask( 2, 1, 1, "continuum-project-test-2", buildDef.getDescription(), null ) ); context.checking( new Expectations() { { - exactly(2).of( buildQueue ).getQueueSnapshot(); + exactly( 2 ).of( buildQueue ).getQueueSnapshot(); will( returnValue( tasksOfFirstBuildQueue ) ); - + // the second build queue has no tasks queued, so it should return 0 - exactly(2).of(buildQueue).getQueueSnapshot(); + exactly( 2 ).of( buildQueue ).getQueueSnapshot(); will( returnValue( tasks ) ); - - one( overallBuildQueue).getName(); + + one( overallBuildQueue ).getName(); will( returnValue( "BUILD_QUEUE_3" ) ); - } - } ); - + }} ); + recordAddToBuildQueue(); - + buildsManager.buildProject( 2, buildDef, "continuum-project-test-2", 1, null ); context.assertIsSatisfied(); - + // queue third project - both queues have 1 task queued each recordStartOfBuildProjectSequence(); - + // both queues have 1 task each context.checking( new Expectations() { { - exactly(3).of( buildQueue ).getQueueSnapshot(); + exactly( 3 ).of( buildQueue ).getQueueSnapshot(); will( returnValue( tasksOfFirstBuildQueue ) ); - - one( overallBuildQueue).getName(); + + one( overallBuildQueue ).getName(); will( returnValue( "BUILD_QUEUE_2" ) ); - } - } ); - + }} ); + recordAddToBuildQueue(); - + buildsManager.buildProject( 3, buildDef, "continuum-project-test-3", 1, null ); context.assertIsSatisfied(); } - + public void testRemoveProjectFromBuildQueue() throws Exception { setupMockOverallBuildQueues(); - + context.checking( new Expectations() { { - one(overallBuildQueue).isInBuildQueue( 1 ); + one( overallBuildQueue ).isInBuildQueue( 1 ); will( returnValue( true ) ); - - one(overallBuildQueue).removeProjectFromBuildQueue( 1 ); - } - } ); - + + one( overallBuildQueue ).removeProjectFromBuildQueue( 1 ); + }} ); + buildsManager.removeProjectFromBuildQueue( 1 ); context.assertIsSatisfied(); } - + public void testRemoveProjectsFromBuildQueue() throws Exception { setupMockOverallBuildQueues(); - int[] projectIds = new int[] { 1, 2, 3 }; - + int[] projectIds = new int[]{1, 2, 3}; + context.checking( new Expectations() { { - exactly(3).of(overallBuildQueue).isInBuildQueue( with( any( int.class ) ) ); - will( returnValue( true ) ); - - exactly(3).of(overallBuildQueue).removeProjectFromBuildQueue( with( any( int.class ) ) ); - } - } ); - + exactly( 3 ).of( overallBuildQueue ).isInBuildQueue( with( any( int.class ) ) ); + will( returnValue( true ) ); + + exactly( 3 ).of( overallBuildQueue ).removeProjectFromBuildQueue( with( any( int.class ) ) ); + }} ); + buildsManager.removeProjectsFromBuildQueue( projectIds ); context.assertIsSatisfied(); } - + public void testCheckoutProjectSingle() throws Exception { setupMockOverallBuildQueues(); - + BuildDefinition buildDef = new BuildDefinition(); buildDef.setId( 1 ); buildDef.setSchedule( getSchedule( 1, 1, 2 ) ); - + recordCheckoutProjectBuildQueuesAreEmpty(); - - buildsManager.checkoutProject( 1, "continuum-project-test-1", new File( getBasedir(), "/target/test-working-dir/1" ), - "dummy", "dummypass", buildDef ); + + buildsManager.checkoutProject( 1, "continuum-project-test-1", + new File( getBasedir(), "/target/test-working-dir/1" ), "dummy", "dummypass", + buildDef ); context.assertIsSatisfied(); } @@ -412,65 +400,67 @@ throws Exception { setupMockOverallBuildQueues(); - + BuildDefinition buildDef = new BuildDefinition(); buildDef.setId( 1 ); buildDef.setSchedule( getSchedule( 1, 1, 2 ) ); - + recordCheckoutProjectBuildQueuesAreEmpty(); - - buildsManager.checkoutProject( 1, "continuum-project-test-1", new File( getBasedir(), "/target/test-working-dir/1" ), - "dummy", "dummypass", buildDef ); + + buildsManager.checkoutProject( 1, "continuum-project-test-1", + new File( getBasedir(), "/target/test-working-dir/1" ), "dummy", "dummypass", + buildDef ); context.assertIsSatisfied(); - + // queue second project - 1st queue has 1 task while 2nd queue is empty; project should be queued in // 2nd queue recordStartOfCheckoutProjectSequence(); - + final List tasks = new ArrayList(); - + final List tasksInFirstCheckoutQueue = new ArrayList(); - tasksInFirstCheckoutQueue.add( new CheckOutTask( 1, new File( getBasedir(), "/target/test-working-dir/1" ), - "continuum-project-test-1", "dummy", "dummypass" ) ); - + tasksInFirstCheckoutQueue.add( + new CheckOutTask( 1, new File( getBasedir(), "/target/test-working-dir/1" ), "continuum-project-test-1", + "dummy", "dummypass" ) ); + context.checking( new Expectations() { { - exactly(2).of( checkoutQueue ).getQueueSnapshot(); + exactly( 2 ).of( checkoutQueue ).getQueueSnapshot(); will( returnValue( tasksInFirstCheckoutQueue ) ); - - exactly(2).of( checkoutQueue ).getQueueSnapshot(); + + exactly( 2 ).of( checkoutQueue ).getQueueSnapshot(); will( returnValue( tasks ) ); - - one( overallBuildQueue).getName(); + + one( overallBuildQueue ).getName(); will( returnValue( "BUILD_QUEUE_3" ) ); - } - } ); - + }} ); + recordAddToCheckoutQueue(); - - buildsManager.checkoutProject( 2, "continuum-project-test-2", new File( getBasedir(), "/target/test-working-dir/1" ), - "dummy", "dummypass", buildDef ); - context.assertIsSatisfied(); - + + buildsManager.checkoutProject( 2, "continuum-project-test-2", + new File( getBasedir(), "/target/test-working-dir/1" ), "dummy", "dummypass", + buildDef ); + context.assertIsSatisfied(); + // queue third project - both queues have 1 task queued each; third project should be queued in 1st queue recordStartOfCheckoutProjectSequence(); - + context.checking( new Expectations() { { - exactly(3).of( checkoutQueue ).getQueueSnapshot(); + exactly( 3 ).of( checkoutQueue ).getQueueSnapshot(); will( returnValue( tasksInFirstCheckoutQueue ) ); - - one( overallBuildQueue).getName(); + + one( overallBuildQueue ).getName(); will( returnValue( "BUILD_QUEUE_2" ) ); - } - } ); - + }} ); + recordAddToCheckoutQueue(); - - buildsManager.checkoutProject( 3, "continuum-project-test-3", new File( getBasedir(), "/target/test-working-dir/1" ), - "dummy", "dummypass", buildDef ); + + buildsManager.checkoutProject( 3, "continuum-project-test-3", + new File( getBasedir(), "/target/test-working-dir/1" ), "dummy", "dummypass", + buildDef ); context.assertIsSatisfied(); } @@ -478,75 +468,71 @@ throws Exception { setupMockOverallBuildQueues(); - + context.checking( new Expectations() { { - one(overallBuildQueue).isInCheckoutQueue( 1 ); + one( overallBuildQueue ).isInCheckoutQueue( 1 ); will( returnValue( true ) ); - - one(overallBuildQueue).removeProjectFromCheckoutQueue( 1 ); - } - } ); - + + one( overallBuildQueue ).removeProjectFromCheckoutQueue( 1 ); + }} ); + buildsManager.removeProjectFromCheckoutQueue( 1 ); context.assertIsSatisfied(); } - + public void testRemoveProjectsFromCheckoutQueue() throws Exception { - setupMockOverallBuildQueues(); - + setupMockOverallBuildQueues(); + context.checking( new Expectations() { { - exactly(3).of(overallBuildQueue).isInCheckoutQueue( with( any( int.class ) ) ); + exactly( 3 ).of( overallBuildQueue ).isInCheckoutQueue( with( any( int.class ) ) ); will( returnValue( true ) ); - - exactly(3).of(overallBuildQueue).removeProjectFromCheckoutQueue( with( any( int.class ) ) ); - } - } ); - - int[] projectIds = new int[] { 1, 2, 3 }; - + + exactly( 3 ).of( overallBuildQueue ).removeProjectFromCheckoutQueue( with( any( int.class ) ) ); + }} ); + + int[] projectIds = new int[]{1, 2, 3}; + buildsManager.removeProjectsFromCheckoutQueue( projectIds ); context.assertIsSatisfied(); } - + public void testRemoveProjectFromCheckoutQueueProjectNotFound() throws Exception { setupMockOverallBuildQueues(); - + // shouldn't only the project's build queues be checked instead of all the overall build queues? context.checking( new Expectations() { { - exactly(5).of(overallBuildQueue).isInCheckoutQueue( 1 ); + exactly( 5 ).of( overallBuildQueue ).isInCheckoutQueue( 1 ); will( returnValue( false ) ); - } - } ); - + }} ); + buildsManager.removeProjectFromCheckoutQueue( 1 ); context.assertIsSatisfied(); } - + public void testRemoveDefaultOverallBuildQueue() throws Exception { setupMockOverallBuildQueues(); - + try { context.checking( new Expectations() { { - one(overallBuildQueue).getName(); + one( overallBuildQueue ).getName(); will( returnValue( ConfigurationService.DEFAULT_BUILD_QUEUE_NAME ) ); - } - } ); - + }} ); + buildsManager.removeOverallBuildQueue( 1 ); context.assertIsSatisfied(); fail( "An exception should have been thrown." ); @@ -556,151 +542,154 @@ assertEquals( "Cannot remove default build queue.", e.getMessage() ); } } - + public void testRemoveOverallBuildQueueNoTasksCurrentlyExecuting() throws Exception { // queued tasks (both checkout & build tasks) must be transferred to the other queues! setupMockOverallBuildQueues(); - + final BuildDefinition buildDef = new BuildDefinition(); buildDef.setId( 1 ); buildDef.setSchedule( getSchedule( 1, 1, 2 ) ); - + final TaskQueueExecutor buildQueueExecutor = context.mock( TaskQueueExecutor.class, "build-queue-executor" ); final TaskQueueExecutor checkoutQueueExecutor = context.mock( TaskQueueExecutor.class, "checkout-queue-executor" ); - + final List buildTasks = new ArrayList(); - buildTasks.add( new BuildProjectTask( 2, 1, 1, "continuum-project-test-2", "BUILD_DEF", null ) ); - + buildTasks.add( new BuildProjectTask( 2, 1, 1, "continuum-project-test-2", "BUILD_DEF", null ) ); + final List checkoutTasks = new ArrayList(); - checkoutTasks.add( new CheckOutTask( 2, new File( getBasedir(), "/target/test-working-dir/1" ), "continuum-project-test-2", - "dummy", "dummypass" ) ); - - final ParallelBuildsThreadedTaskQueueExecutor buildTaskQueueExecutor = context.mock( ParallelBuildsThreadedTaskQueueExecutor.class, "parallel-build-task-executor" ); - final ParallelBuildsThreadedTaskQueueExecutor checkoutTaskQueueExecutor = context.mock( ParallelBuildsThreadedTaskQueueExecutor.class, "parallel-checkout-task-executor" ); - - final List tasks = new ArrayList(); - + checkoutTasks.add( + new CheckOutTask( 2, new File( getBasedir(), "/target/test-working-dir/1" ), "continuum-project-test-2", + "dummy", "dummypass" ) ); + + final ParallelBuildsThreadedTaskQueueExecutor buildTaskQueueExecutor = + context.mock( ParallelBuildsThreadedTaskQueueExecutor.class, "parallel-build-task-executor" ); + final ParallelBuildsThreadedTaskQueueExecutor checkoutTaskQueueExecutor = + context.mock( ParallelBuildsThreadedTaskQueueExecutor.class, "parallel-checkout-task-executor" ); + + final List tasks = new ArrayList(); + context.checking( new Expectations() { { one( overallBuildQueue ).getName(); will( returnValue( "BUILD_QUEUE_5" ) ); - - // check if there is any build task currently being executed + + // check if there is any build task currently being executed one( overallBuildQueue ).getBuildTaskQueueExecutor(); - will( returnValue( buildQueueExecutor ) ); + will( returnValue( buildQueueExecutor ) ); one( buildQueueExecutor ).getCurrentTask(); - will ( returnValue( null ) ); + will( returnValue( null ) ); //will( returnValue( buildTask ) ); - - // check if there is any checkout task currently being executed + + // check if there is any checkout task currently being executed one( overallBuildQueue ).getCheckoutTaskQueueExecutor(); - will( returnValue( checkoutQueueExecutor ) ); + will( returnValue( checkoutQueueExecutor ) ); one( checkoutQueueExecutor ).getCurrentTask(); - will ( returnValue( null ) ); + will( returnValue( null ) ); //will( returnValue( checkoutTask ) ); - - // get all queued build tasks & remove them - one(overallBuildQueue).getProjectsInBuildQueue(); + + // get all queued build tasks & remove them + one( overallBuildQueue ).getProjectsInBuildQueue(); will( returnValue( buildTasks ) ); - one(overallBuildQueue).getBuildQueue(); + one( overallBuildQueue ).getBuildQueue(); will( returnValue( buildQueue ) ); - one(buildQueue).removeAll( buildTasks ); - - // get all queued checkout tasks & remove them - one(overallBuildQueue).getProjectsInCheckoutQueue(); - will( returnValue( checkoutTasks ) ); - one(overallBuildQueue).getCheckoutQueue(); + one( buildQueue ).removeAll( buildTasks ); + + // get all queued checkout tasks & remove them + one( overallBuildQueue ).getProjectsInCheckoutQueue(); + will( returnValue( checkoutTasks ) ); + one( overallBuildQueue ).getCheckoutQueue(); will( returnValue( checkoutQueue ) ); - one(checkoutQueue).removeAll( checkoutTasks ); - - // stop the build & checkout task queue executors - one(overallBuildQueue).getBuildTaskQueueExecutor(); + one( checkoutQueue ).removeAll( checkoutTasks ); + + // stop the build & checkout task queue executors + one( overallBuildQueue ).getBuildTaskQueueExecutor(); will( returnValue( buildTaskQueueExecutor ) ); - one(overallBuildQueue).getCheckoutTaskQueueExecutor(); + one( overallBuildQueue ).getCheckoutTaskQueueExecutor(); will( returnValue( checkoutTaskQueueExecutor ) ); - + one( buildTaskQueueExecutor ).stop(); one( checkoutTaskQueueExecutor ).stop(); - + // TODO: test scenario when there are no longer build queues configured aside from the one removed? // - the behaviour should be that the default build queue will be used! - - // re-queue projects in the build queue of the deleted overall build queue + + // re-queue projects in the build queue of the deleted overall build queue one( buildDefinitionDao ).getBuildDefinition( 1 ); will( returnValue( buildDef ) ); - + // queue to other build queue - exactly(4).of( overallBuildQueue ).isInBuildQueue( with( any(int.class) ) ); + exactly( 4 ).of( overallBuildQueue ).isInBuildQueue( with( any( int.class ) ) ); will( returnValue( false ) ); - + one( configurationService ).getNumberOfBuildsInParallel(); - will( returnValue( 2 ) ); - - exactly(2).of( overallBuildQueue ).getBuildQueue(); + will( returnValue( 2 ) ); + + exactly( 2 ).of( overallBuildQueue ).getBuildQueue(); will( returnValue( buildQueue ) ); - - exactly(3).of( buildQueue ).getQueueSnapshot(); + + exactly( 3 ).of( buildQueue ).getQueueSnapshot(); will( returnValue( tasks ) ); - - one( overallBuildQueue).getName(); + + one( overallBuildQueue ).getName(); will( returnValue( "BUILD_QUEUE_2" ) ); - + recordAddToBuildQueue(); - - // re-queue projects in the checkout queue of the deleted overall build queue + + // re-queue projects in the checkout queue of the deleted overall build queue one( buildDefinitionDao ).getDefaultBuildDefinition( 2 ); will( returnValue( buildDef ) ); - + // queue to other checkout queues - exactly(4).of(overallBuildQueue).isInCheckoutQueue( with( any( int.class ) ) ); - will( returnValue( false ) ); - + exactly( 4 ).of( overallBuildQueue ).isInCheckoutQueue( with( any( int.class ) ) ); + will( returnValue( false ) ); + one( configurationService ).getNumberOfBuildsInParallel(); will( returnValue( 2 ) ); - - exactly(2).of( overallBuildQueue ).getCheckoutQueue(); + + exactly( 2 ).of( overallBuildQueue ).getCheckoutQueue(); will( returnValue( checkoutQueue ) ); - - exactly(3).of( checkoutQueue ).getQueueSnapshot(); + + exactly( 3 ).of( checkoutQueue ).getQueueSnapshot(); will( returnValue( tasks ) ); - - one( overallBuildQueue).getName(); + + one( overallBuildQueue ).getName(); will( returnValue( "BUILD_QUEUE_2" ) ); - + recordAddToCheckoutQueue(); - } - } ); - + }} ); + buildsManager.removeOverallBuildQueue( 5 ); context.assertIsSatisfied(); Map overallBuildQueues = buildsManager.getOverallBuildQueues(); assertNull( overallBuildQueues.get( 5 ) ); } - + public void testRemoveOverallBuildQueueTasksCurrentlyExecuting() throws Exception { setupMockOverallBuildQueues(); - + final BuildDefinition buildDef = new BuildDefinition(); buildDef.setId( 1 ); buildDef.setSchedule( getSchedule( 1, 1, 2 ) ); - + final TaskQueueExecutor buildQueueExecutor = context.mock( TaskQueueExecutor.class, "build-queue-executor" ); final Task buildTask = new BuildProjectTask( 1, 1, 1, "continuum-project-test-1", "BUILD_DEF", null ); final List buildTasks = new ArrayList(); - buildTasks.add( new BuildProjectTask( 2, 1, 1, "continuum-project-test-2", "BUILD_DEF", null ) ); - + buildTasks.add( new BuildProjectTask( 2, 1, 1, "continuum-project-test-2", "BUILD_DEF", null ) ); + final List checkoutTasks = new ArrayList(); - checkoutTasks.add( new CheckOutTask( 2, new File( getBasedir(), "/target/test-working-dir/1" ), "continuum-project-test-2", - "dummy", "dummypass" ) ); - + checkoutTasks.add( + new CheckOutTask( 2, new File( getBasedir(), "/target/test-working-dir/1" ), "continuum-project-test-2", + "dummy", "dummypass" ) ); + try { context.checking( new Expectations() @@ -708,15 +697,14 @@ { one( overallBuildQueue ).getName(); will( returnValue( "BUILD_QUEUE_5" ) ); - - // check if there is any build task currently being executed + + // check if there is any build task currently being executed one( overallBuildQueue ).getBuildTaskQueueExecutor(); - will( returnValue( buildQueueExecutor ) ); - one( buildQueueExecutor ).getCurrentTask(); - will( returnValue( buildTask ) ); - } - } ); - + will( returnValue( buildQueueExecutor ) ); + one( buildQueueExecutor ).getCurrentTask(); + will( returnValue( buildTask ) ); + }} ); + buildsManager.removeOverallBuildQueue( 5 ); context.assertIsSatisfied(); fail( "An exception should have been thrown." ); @@ -726,68 +714,66 @@ assertEquals( "Cannot remove build queue. A task is currently executing.", e.getMessage() ); } } - + public void testNoBuildQueuesConfigured() throws Exception { - overallBuildQueue = context.mock( OverallBuildQueue.class ); - + overallBuildQueue = context.mock( OverallBuildQueue.class ); + Map overallBuildQueues = Collections.synchronizedMap( new HashMap() ); overallBuildQueues.put( 1, overallBuildQueue ); - + buildsManager.setOverallBuildQueues( overallBuildQueues ); - + Schedule schedule = new Schedule(); schedule.setId( 1 ); schedule.setName( "DEFAULT_SCHEDULE" ); schedule.setCronExpression( "0 0 * * * ?" ); schedule.setDelay( 100 ); schedule.setMaxJobExecutionTime( 10000 ); - + BuildDefinition buildDef = new BuildDefinition(); buildDef.setId( 1 ); buildDef.setSchedule( schedule ); - - context.checking( new Expectations() + + context.checking( new Expectations() { { - one( overallBuildQueue ).isInBuildQueue( with( any(int.class) ) ); + one( overallBuildQueue ).isInBuildQueue( with( any( int.class ) ) ); will( returnValue( false ) ); - + one( configurationService ).getNumberOfBuildsInParallel(); - will( returnValue( 2 ) ); - - exactly(2).of( overallBuildQueue ).getName(); + will( returnValue( 2 ) ); + + exactly( 2 ).of( overallBuildQueue ).getName(); will( returnValue( ConfigurationService.DEFAULT_BUILD_QUEUE_NAME ) ); - - one(overallBuildQueue).addToBuildQueue( with( any( Task.class) ) ); - } - }); - + + one( overallBuildQueue ).addToBuildQueue( with( any( Task.class ) ) ); + }} ); + buildsManager.buildProject( 1, buildDef, "continuum-project-test-1", 1, null ); context.assertIsSatisfied(); } - + public void testGetProjectsInBuildQueue() throws Exception { setupMockOverallBuildQueues(); - + final List tasks = new ArrayList(); - tasks.add( new BuildProjectTask( 2, 1, 1, "continuum-project-test-2", "BUILD_DEF", null ) ); - - context.checking( new Expectations() + tasks.add( new BuildProjectTask( 2, 1, 1, "continuum-project-test-2", "BUILD_DEF", null ) ); + + context.checking( new Expectations() { { - exactly(5).of( overallBuildQueue ).getName(); + exactly( 5 ).of( overallBuildQueue ).getName(); will( returnValue( "BUILD_QUEUE" ) ); - - exactly(5).of( overallBuildQueue).getProjectsInBuildQueue(); + + exactly( 5 ).of( overallBuildQueue ).getProjectsInBuildQueue(); will( returnValue( tasks ) ); - } - }); - + }} ); + buildsManager.getProjectsInBuildQueues(); context.assertIsSatisfied(); } @@ -796,26 +782,26 @@ throws Exception { setupMockOverallBuildQueues(); - + final List tasks = new ArrayList(); - tasks.add( new CheckOutTask( 2, new File( getBasedir(), "/target/test-working-dir/1" ), "continuum-project-test-2", - "dummy", "dummypass" ) ); - - context.checking( new Expectations() + tasks.add( + new CheckOutTask( 2, new File( getBasedir(), "/target/test-working-dir/1" ), "continuum-project-test-2", + "dummy", "dummypass" ) ); + + context.checking( new Expectations() { { - exactly(5).of( overallBuildQueue ).getName(); + exactly( 5 ).of( overallBuildQueue ).getName(); will( returnValue( "BUILD_QUEUE" ) ); - - exactly(5).of( overallBuildQueue).getProjectsInCheckoutQueue(); + + exactly( 5 ).of( overallBuildQueue ).getProjectsInCheckoutQueue(); will( returnValue( tasks ) ); - } - }); - + }} ); + buildsManager.getProjectsInCheckoutQueues(); context.assertIsSatisfied(); } - + /* public void testNumOfAllowedParallelBuildsIsLessThanConfiguredBuildQueues() throws Exception Modified: continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/continuum/notification/mail/MockJavaMailSender.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/continuum/notification/mail/MockJavaMailSender.java?rev=764863&r1=764862&r2=764863&view=diff ============================================================================== --- continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/continuum/notification/mail/MockJavaMailSender.java (original) +++ continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/continuum/notification/mail/MockJavaMailSender.java Tue Apr 14 16:28:12 2009 @@ -30,22 +30,21 @@ /** * @author olamy - * @since 26 sept. 2008 * @version $Id$ + * @since 26 sept. 2008 */ public class MockJavaMailSender extends JavaMailSenderImpl implements JavaMailSender { + private final List receivedEmails = new ArrayList(); - List receivedEmails = new ArrayList(); - /** - * + * */ public MockJavaMailSender() { - + } @Override @@ -54,7 +53,7 @@ { receivedEmails.add( mimeMessage ); } - + public List getReceivedEmails() { return receivedEmails; Modified: continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/AddMaven2ProjectTest.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/AddMaven2ProjectTest.java?rev=764863&r1=764862&r2=764863&view=diff ============================================================================== --- continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/AddMaven2ProjectTest.java (original) +++ continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/AddMaven2ProjectTest.java Tue Apr 14 16:28:12 2009 @@ -37,7 +37,7 @@ public class AddMaven2ProjectTest extends AbstractContinuumTest { - protected Logger log = LoggerFactory.getLogger( getClass() ); + protected final Logger log = LoggerFactory.getLogger( getClass() ); protected BuildDefinitionTemplate bdt; Modified: continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java?rev=764863&r1=764862&r2=764863&view=diff ============================================================================== --- continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java (original) +++ continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java Tue Apr 14 16:28:12 2009 @@ -41,7 +41,6 @@ import org.apache.maven.continuum.model.project.ProjectGroup; import org.apache.maven.continuum.model.project.ProjectNotifier; import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult; -import org.apache.maven.continuum.utils.ContinuumUrlValidator; import org.jmock.Expectations; import org.jmock.Mockery; import org.jmock.integration.junit3.JUnit3Mockery; @@ -55,7 +54,7 @@ public class DefaultContinuumTest extends AbstractContinuumTest { - protected Logger log = LoggerFactory.getLogger( getClass() ); + private static final Logger log = LoggerFactory.getLogger( DefaultContinuumTest.class ); private Mockery context; @@ -95,18 +94,12 @@ assertTrue( rootPom.exists() ); - ContinuumUrlValidator validator = (ContinuumUrlValidator) lookup( ContinuumUrlValidator.class, "continuumUrl" ); - - String fileUrl = rootPom.toURL().toExternalForm(); - - //assertTrue( validator.validate( fileUrl ) ); - ContinuumProjectBuildingResult result = continuum.addMavenTwoProject( rootPom.toURI().toURL().toExternalForm(), -1, true, false, true, -1 ); assertNotNull( result ); - assertEquals( "result.warnings.size" + result.getWarnings(), 0, result.getWarnings().size() ); + assertEquals( "result.warnings.size" + result.getErrors(), 0, result.getErrors().size() ); assertEquals( "result.projects.size", 3, result.getProjects().size() ); Modified: continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/buildcontroller/BuildProjectTaskExecutorTest.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/buildcontroller/BuildProjectTaskExecutorTest.java?rev=764863&r1=764862&r2=764863&view=diff ============================================================================== --- continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/buildcontroller/BuildProjectTaskExecutorTest.java (original) +++ continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/buildcontroller/BuildProjectTaskExecutorTest.java Tue Apr 14 16:28:12 2009 @@ -19,6 +19,11 @@ * under the License. */ +import java.io.File; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + import org.apache.continuum.taskqueue.BuildProjectTask; import org.apache.maven.continuum.AbstractContinuumTest; import org.apache.maven.continuum.core.action.AbstractContinuumAction; @@ -35,11 +40,6 @@ import org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor; import org.codehaus.plexus.util.FileUtils; -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - /** * @author Kenney Westerhof */ @@ -187,7 +187,7 @@ System.err.println( "Waiting for task to start" ); - Task curTask = null; + Task curTask; // Sleep at most 10 seconds for the task to start for ( int i = 0; i < 1000; i++ ) @@ -225,7 +225,7 @@ projectGroup.addBuildDefinition( buildDefinition ); - Map pgContext = new HashMap(); + Map pgContext = new HashMap(); pgContext.put( AbstractContinuumAction.KEY_WORKING_DIRECTORY, project.getWorkingDirectory() ); @@ -269,7 +269,7 @@ assertEquals( "#Projectgroups", 1, result.getProjectGroups().size() ); - ProjectGroup pg = (ProjectGroup) result.getProjectGroups().get( 0 ); + ProjectGroup pg = result.getProjectGroups().get( 0 ); // If the next part fails, remove this code! Then result.getProjects // might be empty, and result.projectgroups[0].getProjects contains @@ -277,7 +277,7 @@ assertEquals( "#Projects in result", 1, result.getProjects().size() ); - Project p = (Project) result.getProjects().get( 0 ); + Project p = result.getProjects().get( 0 ); pg.addProject( p ); Modified: continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionServiceTest.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionServiceTest.java?rev=764863&r1=764862&r2=764863&view=diff ============================================================================== --- continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionServiceTest.java (original) +++ continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionServiceTest.java Tue Apr 14 16:28:12 2009 @@ -18,15 +18,15 @@ */ package org.apache.maven.continuum.builddefinition; +import java.util.List; + +import org.apache.continuum.dao.DaoUtils; import org.apache.log4j.Logger; import org.apache.maven.continuum.AbstractContinuumTest; import org.apache.maven.continuum.model.project.BuildDefinition; import org.apache.maven.continuum.model.project.BuildDefinitionTemplate; import org.apache.maven.continuum.model.project.Project; import org.apache.maven.continuum.model.project.ProjectGroup; -import org.apache.continuum.dao.DaoUtils; - -import java.util.List; /** * @author olamy @@ -36,14 +36,10 @@ public class DefaultBuildDefinitionServiceTest extends AbstractContinuumTest { - private Logger logger = Logger.getLogger( getClass() ); - - private ProjectGroup projectGroup; + private static final Logger logger = Logger.getLogger( DefaultBuildDefinitionServiceTest.class ); private Project project; - private BuildDefinition buildDefinition; - private BuildDefinitionTemplate buildDefinitionTemplate; protected void setUp() @@ -53,7 +49,7 @@ DaoUtils daoUtils = (DaoUtils) lookup( DaoUtils.class.getName() ); daoUtils.eraseDatabase(); - projectGroup = new ProjectGroup(); + ProjectGroup projectGroup = new ProjectGroup(); projectGroup.setName( "test" ); projectGroup = getProjectGroupDao().addProjectGroup( projectGroup ); @@ -64,7 +60,7 @@ projectGroup.addProject( project ); getProjectGroupDao().updateProjectGroup( projectGroup ); - buildDefinition = new BuildDefinition(); + BuildDefinition buildDefinition = new BuildDefinition(); buildDefinition.setTemplate( true ); buildDefinition.setArguments( "-N" ); buildDefinition.setGoals( "clean test-compile" ); @@ -125,13 +121,15 @@ public void testGetDefaultBuildDef() throws Exception { - BuildDefinition bd = (BuildDefinition) getBuildDefinitionService().getDefaultAntBuildDefinitionTemplate() - .getBuildDefinitions().get( 0 ); + BuildDefinition bd = + (BuildDefinition) getBuildDefinitionService().getDefaultAntBuildDefinitionTemplate().getBuildDefinitions().get( + 0 ); assertNotNull( bd ); assertEquals( "build.xml", bd.getBuildFile() ); - bd = (BuildDefinition) getBuildDefinitionService().getDefaultMavenTwoBuildDefinitionTemplate() - .getBuildDefinitions().get( 0 ); + bd = + (BuildDefinition) getBuildDefinitionService().getDefaultMavenTwoBuildDefinitionTemplate().getBuildDefinitions().get( + 0 ); BuildDefinitionService buildDefinitionService = (BuildDefinitionService) lookup( BuildDefinitionService.class ); assertEquals( 5, buildDefinitionService.getAllBuildDefinitionTemplate().size() ); @@ -153,8 +151,9 @@ assertEquals( "test", template.getName() ); List all = getBuildDefinitionService().getAllBuildDefinitions(); assertEquals( 5, all.size() ); - BuildDefinition bd = (BuildDefinition) getBuildDefinitionService().getDefaultMavenTwoBuildDefinitionTemplate() - .getBuildDefinitions().get( 0 ); + BuildDefinition bd = + (BuildDefinition) getBuildDefinitionService().getDefaultMavenTwoBuildDefinitionTemplate().getBuildDefinitions().get( + 0 ); template = getBuildDefinitionService().addBuildDefinitionInTemplate( template, bd, false ); assertEquals( 1, template.getBuildDefinitions().size() ); all = getBuildDefinitionService().getAllBuildDefinitions(); Modified: continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java?rev=764863&r1=764862&r2=764863&view=diff ============================================================================== --- continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java (original) +++ continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java Tue Apr 14 16:28:12 2009 @@ -42,30 +42,28 @@ private CreateProjectsFromMetadataAction action; - private Mock projectBuilderManagerMock, projectBuilder, mavenSettingsBuilderMock; - protected void setUp() throws Exception { action = new CreateProjectsFromMetadataAction(); action.enableLogging( new ConsoleLogger( Logger.LEVEL_DEBUG, "" ) ); - projectBuilderManagerMock = mock( ContinuumProjectBuilderManager.class ); - mavenSettingsBuilderMock = mock( MavenSettingsBuilder.class ); + Mock projectBuilderManagerMock = mock( ContinuumProjectBuilderManager.class ); + Mock mavenSettingsBuilderMock = mock( MavenSettingsBuilder.class ); action.setProjectBuilderManager( (ContinuumProjectBuilderManager) projectBuilderManagerMock.proxy() ); action.setMavenSettingsBuilder( (MavenSettingsBuilder) mavenSettingsBuilderMock.proxy() ); action.setUrlValidator( new ContinuumUrlValidator() ); - projectBuilder = mock( ContinuumProjectBuilder.class ); + Mock projectBuilder = mock( ContinuumProjectBuilder.class ); - projectBuilderManagerMock.expects( once() ).method( "getProjectBuilder" ) - .will( returnValue( projectBuilder.proxy() ) ); - projectBuilder.expects( once() ).method( "buildProjectsFromMetadata" ) - .will( returnValue( new ContinuumProjectBuildingResult() ) ); + projectBuilderManagerMock.expects( once() ).method( "getProjectBuilder" ).will( + returnValue( projectBuilder.proxy() ) ); + projectBuilder.expects( once() ).method( "buildProjectsFromMetadata" ).will( + returnValue( new ContinuumProjectBuildingResult() ) ); - projectBuilder.expects( once() ).method( "getDefaultBuildDefinitionTemplate" ) - .will( returnValue( getDefaultBuildDefinitionTemplate() ) ); + projectBuilder.expects( once() ).method( "getDefaultBuildDefinitionTemplate" ).will( + returnValue( getDefaultBuildDefinitionTemplate() ) ); mavenSettingsBuilderMock.expects( once() ).method( "buildSettings" ).will( returnValue( new Settings() ) ); - + } private BuildDefinitionTemplate getDefaultBuildDefinitionTemplate() @@ -87,7 +85,7 @@ bdt.addBuildDefinition( bd ); return bdt; } - + @SuppressWarnings("unchecked") public void testExecuteWithNonRecursiveMode() throws Exception @@ -96,34 +94,37 @@ context.put( CreateProjectsFromMetadataAction.KEY_URL, "http://svn.apache.org/repos/asf/maven/continuum/trunk/pom.xml" ); context.put( CreateProjectsFromMetadataAction.KEY_PROJECT_BUILDER_ID, "id" ); - context.put( CreateProjectsFromMetadataAction.KEY_LOAD_RECURSIVE_PROJECTS, new Boolean( true ) ); + context.put( CreateProjectsFromMetadataAction.KEY_LOAD_RECURSIVE_PROJECTS, true ); - action.execute( context ); - ContinuumProjectBuildingResult result = (ContinuumProjectBuildingResult) context - .get( CreateProjectsFromMetadataAction.KEY_PROJECT_BUILDING_RESULT ); - - assertFalse( "Should not have errors but had " + result.getErrorsAsString() + - " (this test requires internet access)", result.hasErrors() ); + ContinuumProjectBuildingResult result = + (ContinuumProjectBuildingResult) context.get( CreateProjectsFromMetadataAction.KEY_PROJECT_BUILDING_RESULT ) + ; + + assertFalse( + "Should not have errors but had " + result.getErrorsAsString() + " (this test requires internet access)", + result.hasErrors() ); } public void testExecuteWithRecursiveMode() throws Exception { - Map context = new HashMap(); + Map context = new HashMap(); context.put( CreateProjectsFromMetadataAction.KEY_URL, "http://svn.apache.org/repos/asf/maven/archiva/trunk/pom.xml" ); context.put( CreateProjectsFromMetadataAction.KEY_PROJECT_BUILDER_ID, "id" ); - context.put( CreateProjectsFromMetadataAction.KEY_LOAD_RECURSIVE_PROJECTS, new Boolean( false ) ); + context.put( CreateProjectsFromMetadataAction.KEY_LOAD_RECURSIVE_PROJECTS, false ); action.execute( context ); - ContinuumProjectBuildingResult result = (ContinuumProjectBuildingResult) context - .get( CreateProjectsFromMetadataAction.KEY_PROJECT_BUILDING_RESULT ); - - assertFalse( "Should not have errors but had " + result.getErrorsAsString() + - " (this test requires internet access)", result.hasErrors() ); + ContinuumProjectBuildingResult result = + (ContinuumProjectBuildingResult) context.get( CreateProjectsFromMetadataAction.KEY_PROJECT_BUILDING_RESULT ) + ; + + assertFalse( + "Should not have errors but had " + result.getErrorsAsString() + " (this test requires internet access)", + result.hasErrors() ); } } Modified: continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/execution/ContinuumBuildExecutorTest.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/execution/ContinuumBuildExecutorTest.java?rev=764863&r1=764862&r2=764863&view=diff ============================================================================== --- continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/execution/ContinuumBuildExecutorTest.java (original) +++ continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/execution/ContinuumBuildExecutorTest.java Tue Apr 14 16:28:12 2009 @@ -23,8 +23,6 @@ import java.util.HashMap; import java.util.Map; -import junit.framework.TestCase; - import org.apache.continuum.utils.shell.ExecutionResult; import org.apache.continuum.utils.shell.ShellCommandHelper; import org.apache.maven.continuum.configuration.ConfigurationService; @@ -36,12 +34,14 @@ import org.jmock.Expectations; import org.jmock.Mockery; +import junit.framework.TestCase; + public class ContinuumBuildExecutorTest extends TestCase { - protected AbstractBuildExecutor executor = new BuildExecutorStub(); + protected final AbstractBuildExecutor executor = new BuildExecutorStub(); - private Mockery context = new Mockery(); + private final Mockery context = new Mockery(); private String toSystemPath( String path ) { @@ -123,8 +123,8 @@ super( "stub", true ); } - protected String findExecutable( Project project, String executable, String defaultExecutable, - boolean resolveExecutable, File workingDirectory ) + protected String findExecutable( String executable, String defaultExecutable, boolean resolveExecutable, + File workingDirectory ) { return executable; } Modified: continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/execution/maven/m2/TestMavenBuilderHelper.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/execution/maven/m2/TestMavenBuilderHelper.java?rev=764863&r1=764862&r2=764863&view=diff ============================================================================== --- continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/execution/maven/m2/TestMavenBuilderHelper.java (original) +++ continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/execution/maven/m2/TestMavenBuilderHelper.java Tue Apr 14 16:28:12 2009 @@ -29,14 +29,13 @@ /** * @author olamy - * @since 6 juin 2008 * @version $Id$ + * @since 6 juin 2008 */ public class TestMavenBuilderHelper extends AbstractContinuumTest { - - private Logger log = LoggerFactory.getLogger( getClass() ); + private static final Logger log = LoggerFactory.getLogger( TestMavenBuilderHelper.class ); public void testgetMavenProject() throws Exception @@ -54,7 +53,7 @@ assertTrue( project.getDependencies().isEmpty() ); assertTrue( result.getErrors().isEmpty() ); } - + public void testgetMavenProjectMissingDeps() throws Exception { @@ -68,7 +67,5 @@ log.info( "errorAsString " + errorsAsString ); assertTrue( errorsAsString.contains( "ghd:non-exists:pom:2.6.267676-beta-754-alpha-95" ) ); log.info( "errors " + result.getErrors() ); - - } - + } } Modified: continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java?rev=764863&r1=764862&r2=764863&view=diff ============================================================================== --- continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java (original) +++ continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java Tue Apr 14 16:28:12 2009 @@ -19,6 +19,16 @@ * under the License. */ +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.mail.Address; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import javax.mail.internet.MimeMessage.RecipientType; + import org.apache.continuum.notification.mail.MockJavaMailSender; import org.apache.maven.continuum.AbstractContinuumTest; import org.apache.maven.continuum.model.project.BuildDefinition; @@ -34,15 +44,6 @@ import org.slf4j.LoggerFactory; import org.springframework.mail.javamail.JavaMailSender; -import javax.mail.Address; -import javax.mail.internet.InternetAddress; -import javax.mail.internet.MimeMessage; -import javax.mail.internet.MimeMessage.RecipientType; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - /** * @author Trygve Laugstøl * @version $Id$ @@ -194,7 +195,7 @@ List mails = mailSender.getReceivedEmails(); - MimeMessage mailMessage = (MimeMessage) mails.get( 0 ); + MimeMessage mailMessage = mails.get( 0 ); // ---------------------------------------------------------------------- // Modified: continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven/MavenOneContinuumProjectBuilderTest.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven/MavenOneContinuumProjectBuilderTest.java?rev=764863&r1=764862&r2=764863&view=diff ============================================================================== --- continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven/MavenOneContinuumProjectBuilderTest.java (original) +++ continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven/MavenOneContinuumProjectBuilderTest.java Tue Apr 14 16:28:12 2009 @@ -29,8 +29,6 @@ import org.apache.maven.continuum.project.builder.ContinuumProjectBuilder; import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult; -import java.util.Iterator; - /** * @author Trygve Laugstøl * @version $Id$ @@ -44,7 +42,6 @@ ContinuumProjectBuilder projectBuilder = (ContinuumProjectBuilder) lookup( ContinuumProjectBuilder.ROLE, MavenOneContinuumProjectBuilder.ID ); - BuildDefinition bd = new BuildDefinition(); bd.setDefaultForProject( true ); @@ -54,56 +51,52 @@ bd.setBuildFile( "project.xml" ); bd.setType( ContinuumBuildExecutorConstants.MAVEN_ONE_BUILD_EXECUTOR ); - + bd.setTemplate( true ); - + BuildDefinitionService service = (BuildDefinitionService) lookup( BuildDefinitionService.class ); - + BuildDefinitionTemplate bdt = new BuildDefinitionTemplate(); bdt.setName( "maven1" ); bd = service.addBuildDefinition( bd ); bdt = service.addBuildDefinitionTemplate( bdt ); bdt = service.addBuildDefinitionInTemplate( bdt, bd, false ); - - ContinuumProjectBuildingResult result = projectBuilder - .buildProjectsFromMetadata( getTestFile( "src/test/resources/projects/maven-1.pom.xml" ).toURL(), null, - null, false, bdt ); + ContinuumProjectBuildingResult result = projectBuilder.buildProjectsFromMetadata( + getTestFile( "src/test/resources/projects/maven-1.pom.xml" ).toURL(), null, null, false, bdt ); assertOnResult( result ); - + } - + public void testBuildingAProjectFromMetadataWithACompleteMaven1PomWithDefaultBuildDef() throws Exception { - ContinuumProjectBuilder projectBuilder = (ContinuumProjectBuilder) lookup( ContinuumProjectBuilder.ROLE, - MavenOneContinuumProjectBuilder.ID ); + ContinuumProjectBuilder projectBuilder = + (ContinuumProjectBuilder) lookup( ContinuumProjectBuilder.ROLE, MavenOneContinuumProjectBuilder.ID ); BuildDefinitionService service = (BuildDefinitionService) lookup( BuildDefinitionService.class ); - ContinuumProjectBuildingResult result = projectBuilder - .buildProjectsFromMetadata( getTestFile( "src/test/resources/projects/maven-1.pom.xml" ).toURL(), null, - null, false, service.getDefaultMavenOneBuildDefinitionTemplate() ); + ContinuumProjectBuildingResult result = projectBuilder.buildProjectsFromMetadata( + getTestFile( "src/test/resources/projects/maven-1.pom.xml" ).toURL(), null, null, false, + service.getDefaultMavenOneBuildDefinitionTemplate() ); assertOnResult( result ); - } - + } + protected void assertOnResult( ContinuumProjectBuildingResult result ) { - assertNotNull( result.getWarnings() ); + assertNotNull( result.getErrors() ); assertNotNull( result.getProjects() ); - for ( Iterator it = result.getWarnings().iterator(); it.hasNext(); ) + for ( String error : result.getErrors() ) { - String s = (String) it.next(); - - System.err.println( s ); + System.err.println( error ); } - assertEquals( "result.warning.length", 0, result.getWarnings().size() ); + assertEquals( "result.warning.length", 0, result.getErrors().size() ); assertEquals( "result.projects.length", 1, result.getProjects().size() ); Modified: continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilderTest.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilderTest.java?rev=764863&r1=764862&r2=764863&view=diff ============================================================================== --- continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilderTest.java (original) +++ continuum/branches/continuum-1.3.x/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilderTest.java Tue Apr 14 16:28:12 2009 @@ -19,6 +19,12 @@ * under the License. */ +import java.io.File; +import java.net.URL; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.apache.log4j.Logger; import org.apache.maven.continuum.AbstractContinuumTest; import org.apache.maven.continuum.builddefinition.BuildDefinitionService; @@ -33,12 +39,6 @@ import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult; import org.codehaus.plexus.util.StringUtils; -import java.io.File; -import java.net.URL; -import java.util.HashMap; -import java.util.Map; -import java.util.List; - /** * @author Trygve Laugstøl * @version $Id$ @@ -46,21 +46,7 @@ public class MavenTwoContinuumProjectBuilderTest extends AbstractContinuumTest { - - private Logger logger = Logger.getLogger( getClass() ); - - /* - protected String getConfigurationName( String subname ) - throws Exception - { - return super.getConfigurationName( subname ); - } - */ - - protected String getCustomConfigurationName() - { - return "plexus.xml"; - } + private static final Logger logger = Logger.getLogger( MavenTwoContinuumProjectBuilderTest.class ); public void testGetEmailAddressWhenTypeIsSetToEmail() throws Exception Modified: continuum/branches/continuum-1.3.x/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-api/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportService.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-api/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportService.java?rev=764863&r1=764862&r2=764863&view=diff ============================================================================== --- continuum/branches/continuum-1.3.x/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-api/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportService.java (original) +++ continuum/branches/continuum-1.3.x/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-api/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportService.java Tue Apr 14 16:28:12 2009 @@ -1,10 +1,10 @@ package org.apache.continuum.distributed.transport.slave; +import com.atlassian.xmlrpc.ServiceObject; + import java.util.List; import java.util.Map; -import com.atlassian.xmlrpc.ServiceObject; - /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file @@ -27,20 +27,26 @@ /** * SlaveBuildAgentTransportService */ -@ServiceObject( "SlaveBuildAgentTransportService" ) +@ServiceObject("SlaveBuildAgentTransportService") public interface SlaveBuildAgentTransportService { - public Boolean buildProjects( List projectsBuildContext ) throws Exception; - - public Map getBuildResult( int projectId ) throws Exception; - - public Integer getProjectCurrentlyBuilding() throws Exception; - - public List getAvailableInstallations() throws Exception; - - public Boolean ping() throws Exception; + public Boolean buildProjects( List> projectsBuildContext ) + throws Exception; + + public Map getBuildResult( int projectId ) + throws Exception; - public Boolean cancelBuild() throws Exception; + public Integer getProjectCurrentlyBuilding() + throws Exception; + + public List> getAvailableInstallations() + throws Exception; + + public Boolean ping() + throws Exception; + + public Boolean cancelBuild() + throws Exception; public String generateWorkingCopyContent( int projectId, String directory, String baseUrl, String imagesBaseUrl ) throws Exception; @@ -54,7 +60,8 @@ public List> processProject( int projectId, String pomFilename, boolean autoVersionSubmodules ) throws Exception; - public String releasePrepare( Map project, Map properties, Map releaseVersion, Map developmentVersion, Map environments ) + public String releasePrepare( Map project, Map properties, Map releaseVersion, Map developmentVersion, + Map environments ) throws Exception; public Map getReleaseResult( String releaseId ) @@ -69,11 +76,13 @@ public String getPreparedReleaseName( String releaseId ) throws Exception; - public Boolean releasePerform( String releaseId, String goals, String arguments, boolean useReleaseProfile, Map repository ) + public Boolean releasePerform( String releaseId, String goals, String arguments, boolean useReleaseProfile, + Map repository ) throws Exception; - public String releasePerformFromScm( String goals, String arguments, boolean useReleaseProfile, Map repository, String scmUrl, - String scmUsername, String scmPassword, String scmTag, String scmTagBase, Map environments ) + public String releasePerformFromScm( String goals, String arguments, boolean useReleaseProfile, Map repository, + String scmUrl, String scmUsername, String scmPassword, String scmTag, + String scmTagBase, Map environments ) throws Exception; public String releaseCleanup( String releaseId ) Modified: continuum/branches/continuum-1.3.x/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportClient.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportClient.java?rev=764863&r1=764862&r2=764863&view=diff ============================================================================== --- continuum/branches/continuum-1.3.x/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportClient.java (original) +++ continuum/branches/continuum-1.3.x/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-client/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportClient.java Tue Apr 14 16:28:12 2009 @@ -19,6 +19,11 @@ * under the License. */ +import com.atlassian.xmlrpc.AuthenticationInfo; +import com.atlassian.xmlrpc.Binder; +import com.atlassian.xmlrpc.BindingException; +import com.atlassian.xmlrpc.DefaultBinder; + import java.net.URL; import java.util.List; import java.util.Map; @@ -26,21 +31,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.atlassian.xmlrpc.AuthenticationInfo; -import com.atlassian.xmlrpc.Binder; -import com.atlassian.xmlrpc.BindingException; -import com.atlassian.xmlrpc.DefaultBinder; - /** * SlaveBuildAgentTransportClient */ public class SlaveBuildAgentTransportClient implements SlaveBuildAgentTransportService { - private Logger log = LoggerFactory.getLogger( this.getClass() ); - + private static final Logger log = LoggerFactory.getLogger( SlaveBuildAgentTransportClient.class ); + private SlaveBuildAgentTransportService slave; - + public SlaveBuildAgentTransportClient( URL serviceUrl ) throws Exception { @@ -52,23 +52,27 @@ { Binder binder = new DefaultBinder(); AuthenticationInfo authnInfo = new AuthenticationInfo( login, password ); - + try { slave = binder.bind( SlaveBuildAgentTransportService.class, serviceUrl, authnInfo ); } catch ( BindingException e ) { - log.error( "Can't bind service interface " + SlaveBuildAgentTransportService.class.getName() + " to " + serviceUrl.toExternalForm() + " using " + authnInfo.getUsername() + ", " + authnInfo.getPassword(), e ); - throw new Exception( "Can't bind service interface " + SlaveBuildAgentTransportService.class.getName() + " to " + serviceUrl.toExternalForm() + " using " + authnInfo.getUsername() + ", " + authnInfo.getPassword(), e); + log.error( "Can't bind service interface " + SlaveBuildAgentTransportService.class.getName() + " to " + + serviceUrl.toExternalForm() + " using " + authnInfo.getUsername() + ", " + authnInfo.getPassword(), e ); + throw new Exception( + "Can't bind service interface " + SlaveBuildAgentTransportService.class.getName() + " to " + + serviceUrl.toExternalForm() + " using " + authnInfo.getUsername() + ", " + authnInfo.getPassword(), + e ); } } - public Boolean buildProjects( List projectsBuildContext ) + public Boolean buildProjects( List> projectsBuildContext ) throws Exception { - Boolean result = null; - + Boolean result; + try { result = slave.buildProjects( projectsBuildContext ); @@ -79,15 +83,15 @@ log.error( "Failed to build projects.", e ); throw new Exception( "Failed to build projects.", e ); } - + return result; } - public List getAvailableInstallations() + public List> getAvailableInstallations() throws Exception { - List installations = null; - + List> installations; + try { installations = slave.getAvailableInstallations(); @@ -96,17 +100,17 @@ catch ( Exception e ) { log.error( "Failed to get available installations.", e ); - throw new Exception( "Failed to get available installations." , e ); + throw new Exception( "Failed to get available installations.", e ); } - + return installations; } public Map getBuildResult( int projectId ) throws Exception { - Map buildResult = null; - + Map buildResult; + try { buildResult = slave.getBuildResult( projectId ); @@ -117,15 +121,15 @@ log.error( "Failed to get build result for project " + projectId, e ); throw new Exception( "Failed to get build result for project " + projectId, e ); } - + return buildResult; } public Integer getProjectCurrentlyBuilding() throws Exception { - Integer projectId = null; - + Integer projectId; + try { projectId = slave.getProjectCurrentlyBuilding(); @@ -136,33 +140,33 @@ log.error( "Failed to get the currently building project", e ); throw new Exception( "Failed to get the currently building project", e ); } - + return projectId; } public Boolean ping() throws Exception { - Boolean result = null; - + Boolean result; + try { result = slave.ping(); - log.info( "Ping " + ( result.booleanValue() ? "ok" : "failed" ) ); + log.info( "Ping " + ( result ? "ok" : "failed" ) ); } catch ( Exception e ) { log.info( "Ping error" ); throw new Exception( "Ping error", e ); } - + return result; } public Boolean cancelBuild() throws Exception { - Boolean result = null; + Boolean result; try { @@ -181,7 +185,7 @@ public String generateWorkingCopyContent( int projectId, String directory, String baseUrl, String imagesBaseUrl ) throws Exception { - String result = null; + String result; try { @@ -200,7 +204,7 @@ public String getProjectFileContent( int projectId, String directory, String filename ) throws Exception { - String result = null; + String result; try { @@ -219,12 +223,12 @@ public Map getReleasePluginParameters( int projectId, String pomFilename ) throws Exception { - Map result = null; + Map result; try { result = slave.getReleasePluginParameters( projectId, pomFilename ); - log.info( "Retrieving release plugin parameters" ); + log.info( "Retrieving release plugin parameters" ); } catch ( Exception e ) { @@ -238,7 +242,7 @@ public List> processProject( int projectId, String pomFilename, boolean autoVersionSubmodules ) throws Exception { - List> result = null; + List> result; try { @@ -254,10 +258,11 @@ return result; } - public String releasePrepare( Map project, Map properties, Map releaseVersion, Map developmentVersion, Map environments ) + public String releasePrepare( Map project, Map properties, Map releaseVersion, Map developmentVersion, + Map environments ) throws Exception { - String releaseId = null; + String releaseId; try { @@ -276,7 +281,7 @@ public Map getReleaseResult( String releaseId ) throws Exception { - Map result = null; + Map result; try { @@ -295,7 +300,7 @@ public Map getListener( String releaseId ) throws Exception { - Map result = null; + Map result; try { @@ -314,7 +319,7 @@ public Boolean removeListener( String releaseId ) throws Exception { - Boolean result = null; + Boolean result; try { @@ -334,7 +339,7 @@ public String getPreparedReleaseName( String releaseId ) throws Exception { - String result = null; + String result; try { @@ -350,10 +355,11 @@ return result; } - public Boolean releasePerform( String releaseId, String goals, String arguments, boolean useReleaseProfile, Map repository ) + public Boolean releasePerform( String releaseId, String goals, String arguments, boolean useReleaseProfile, + Map repository ) throws Exception { - Boolean result = null; + Boolean result; try { @@ -370,16 +376,17 @@ return result; } - public String releasePerformFromScm( String goals, String arguments, boolean useReleaseProfile, Map repository, String scmUrl, - String scmUsername, String scmPassword, String scmTag, String scmTagBase, Map environments ) + public String releasePerformFromScm( String goals, String arguments, boolean useReleaseProfile, Map repository, + String scmUrl, String scmUsername, String scmPassword, String scmTag, + String scmTagBase, Map environments ) throws Exception { - String result = null; + String result; try { - result = slave.releasePerformFromScm( goals, arguments, useReleaseProfile, repository, scmUrl, scmUsername, scmPassword, scmTag, - scmTagBase, environments); + result = slave.releasePerformFromScm( goals, arguments, useReleaseProfile, repository, scmUrl, scmUsername, + scmPassword, scmTag, scmTagBase, environments ); log.info( "Performing release" ); } catch ( Exception e ) @@ -394,7 +401,7 @@ public String releaseCleanup( String releaseId ) throws Exception { - String result = null; + String result; try { @@ -413,7 +420,7 @@ public Boolean releaseRollback( String releaseId, int projectId ) throws Exception { - Boolean result = Boolean.FALSE; + Boolean result; try {