continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From batkin...@apache.org
Subject svn commit: r1659076 - in /continuum/trunk/continuum-buildagent/continuum-buildagent-core: ./ src/test/java/org/apache/continuum/buildagent/manager/ src/test/java/org/apache/continuum/buildagent/taskqueue/execution/
Date Wed, 11 Feb 2015 21:27:03 GMT
Author: batkinson
Date: Wed Feb 11 21:27:03 2015
New Revision: 1659076

URL: http://svn.apache.org/r1659076
Log:
Migrated buildagent-core tests from jmock to mockito.

Modified:
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/pom.xml
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/manager/BuildAgentPurgeManagerTest.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/manager/BuildAgentReleaseManagerTest.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutorTest.java

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/pom.xml?rev=1659076&r1=1659075&r2=1659076&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/pom.xml (original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/pom.xml Wed Feb 11 21:27:03
2015
@@ -146,33 +146,6 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.jmock</groupId>
-      <artifactId>jmock-junit3</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.jmock</groupId>
-      <artifactId>jmock</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>jmock</groupId>
-      <artifactId>jmock</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <!-- dependency of jmock3 -->
-    <dependency>
-      <groupId>cglib</groupId>
-      <artifactId>cglib-nodep</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <!-- dependency of jmock3 -->
-    <dependency>
-      <groupId>org.objenesis</groupId>
-      <artifactId>objenesis</artifactId>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
       <groupId>org.apache.maven.wagon</groupId>
       <artifactId>wagon-file</artifactId>
       <scope>test</scope>

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/manager/BuildAgentPurgeManagerTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/manager/BuildAgentPurgeManagerTest.java?rev=1659076&r1=1659075&r2=1659076&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/manager/BuildAgentPurgeManagerTest.java
(original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/manager/BuildAgentPurgeManagerTest.java
Wed Feb 11 21:27:03 2015
@@ -22,10 +22,6 @@ package org.apache.continuum.buildagent.
 import org.apache.commons.io.FileUtils;
 import org.apache.continuum.buildagent.configuration.BuildAgentConfigurationService;
 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit3.JUnit3Mockery;
-import org.jmock.lib.legacy.ClassImposteriser;
 
 import java.io.File;
 import java.io.IOException;
@@ -34,6 +30,8 @@ import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 
+import static org.mockito.Mockito.*;
+
 /**
  * For CONTINUUM-2658 tests, Support purging of working and release directories of build
agents on a schedule
  */
@@ -54,8 +52,6 @@ public class BuildAgentPurgeManagerTest
 
     private static final String DIRECTORY_TYPE_WORKING = "working";
 
-    private Mockery context;
-
     private BuildAgentConfigurationService buildAgentConfigurationService;
 
     private DefaultBuildAgentPurgeManager purgeManager;
@@ -67,16 +63,15 @@ public class BuildAgentPurgeManagerTest
     {
         super.setUp();
 
-        context = new JUnit3Mockery();
-        context.setImposteriser( ClassImposteriser.INSTANCE );
-
         purgeManager = (DefaultBuildAgentPurgeManager) lookup( BuildAgentPurgeManager.class
);
 
-        buildAgentConfigurationService = context.mock( BuildAgentConfigurationService.class
);
+        buildAgentConfigurationService = mock( BuildAgentConfigurationService.class );
 
         purgeManager.setBuildAgentConfigurationService( buildAgentConfigurationService );
 
         createTestDirectoriesAndFiles();
+
+        when( buildAgentConfigurationService.getWorkingDirectory() ).thenReturn( tempDir
);
     }
 
     protected void tearDown()
@@ -91,17 +86,6 @@ public class BuildAgentPurgeManagerTest
     public void testCleanAllPurge()
         throws Exception
     {
-        context.checking( new Expectations()
-        {
-            {
-                one( buildAgentConfigurationService ).getWorkingDirectory();
-                will( returnValue( tempDir ) );
-
-                one( buildAgentConfigurationService ).getWorkingDirectory();
-                will( returnValue( tempDir ) );
-            }
-        } );
-
         //confirm current content of directory
         //2 random files
         assertEquals( RELEASES_COUNT + WORKING_COUNT + 2, tempDir.list().length );
@@ -122,17 +106,6 @@ public class BuildAgentPurgeManagerTest
     public void testRetentionOnlyPurge()
         throws Exception
     {
-        context.checking( new Expectations()
-        {
-            {
-                one( buildAgentConfigurationService ).getWorkingDirectory();
-                will( returnValue( tempDir ) );
-
-                one( buildAgentConfigurationService ).getWorkingDirectory();
-                will( returnValue( tempDir ) );
-            }
-        } );
-
         //confirm current content of directory
         //2 random files
         assertEquals( RELEASES_COUNT + WORKING_COUNT + 2, tempDir.list().length );
@@ -141,8 +114,6 @@ public class BuildAgentPurgeManagerTest
 
         List<String> fileNames = Arrays.asList( tempDir.list() );
 
-        File[] files = tempDir.listFiles();
-
         //confirm current content of directory
         //2 working directories left
         assertEquals( RELEASES_COUNT + 2 + 2, fileNames.size() );
@@ -159,17 +130,6 @@ public class BuildAgentPurgeManagerTest
     public void testDaysOldOnlyPurge()
         throws Exception
     {
-        context.checking( new Expectations()
-        {
-            {
-                one( buildAgentConfigurationService ).getWorkingDirectory();
-                will( returnValue( tempDir ) );
-
-                one( buildAgentConfigurationService ).getWorkingDirectory();
-                will( returnValue( tempDir ) );
-            }
-        } );
-
         //confirm current content of directory
         //2 random files
         assertEquals( RELEASES_COUNT + WORKING_COUNT + 2, tempDir.list().length );
@@ -195,17 +155,6 @@ public class BuildAgentPurgeManagerTest
     public void testRetentionAndDaysOldOnlyPurge()
         throws Exception
     {
-        context.checking( new Expectations()
-        {
-            {
-                one( buildAgentConfigurationService ).getWorkingDirectory();
-                will( returnValue( tempDir ) );
-
-                one( buildAgentConfigurationService ).getWorkingDirectory();
-                will( returnValue( tempDir ) );
-            }
-        } );
-
         //confirm current content of directory
         //2 random files
         assertEquals( RELEASES_COUNT + WORKING_COUNT + 2, tempDir.list().length );

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/manager/BuildAgentReleaseManagerTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/manager/BuildAgentReleaseManagerTest.java?rev=1659076&r1=1659075&r2=1659076&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/manager/BuildAgentReleaseManagerTest.java
(original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/manager/BuildAgentReleaseManagerTest.java
Wed Feb 11 21:27:03 2015
@@ -24,10 +24,6 @@ import org.apache.continuum.buildagent.m
 import org.apache.continuum.buildagent.utils.ContinuumBuildAgentUtil;
 import org.apache.maven.continuum.release.ContinuumReleaseException;
 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit3.JUnit3Mockery;
-import org.jmock.lib.legacy.ClassImposteriser;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -36,6 +32,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
+import static org.mockito.Mockito.*;
+
 /**
  * For the CONTINUUM-2391 tests, checking of the local repository details is in ContinuumReleaseManagerStub.
An
  * exception is thrown if the set local repository in the repository map is incorrect.
@@ -43,8 +41,6 @@ import java.util.Properties;
 public class BuildAgentReleaseManagerTest
     extends PlexusInSpringTestCase
 {
-    private Mockery context;
-
     private BuildAgentConfigurationService buildAgentConfigurationService;
 
     private DefaultBuildAgentReleaseManager releaseManager;
@@ -54,14 +50,17 @@ public class BuildAgentReleaseManagerTes
     {
         super.setUp();
 
-        context = new JUnit3Mockery();
-        context.setImposteriser( ClassImposteriser.INSTANCE );
-
         releaseManager = (DefaultBuildAgentReleaseManager) lookup( BuildAgentReleaseManager.class
);
 
-        buildAgentConfigurationService = context.mock( BuildAgentConfigurationService.class
);
+        buildAgentConfigurationService = mock( BuildAgentConfigurationService.class );
 
         releaseManager.setBuildAgentConfigurationService( buildAgentConfigurationService
);
+
+        final List<LocalRepository> localRepos = createLocalRepositories();
+        final File workingDir = new File( getBasedir(), "target/test-classes/working-dir"
);
+
+        when( buildAgentConfigurationService.getLocalRepositories() ).thenReturn( localRepos
);
+        when( buildAgentConfigurationService.getWorkingDirectory( 1 ) ).thenReturn( workingDir
);
     }
 
     protected void tearDown()
@@ -76,23 +75,7 @@ public class BuildAgentReleaseManagerTes
     public void testLocalRepositoryInReleasePrepare()
         throws Exception
     {
-        final List<LocalRepository> localRepos = createLocalRepositories();
-        final File workingDir = new File( getBasedir(), "target/test-classes/working-dir"
);
-
-        context.checking( new Expectations()
-        {
-            {
-                one( buildAgentConfigurationService ).getLocalRepositories();
-                will( returnValue( localRepos ) );
-
-                one( buildAgentConfigurationService ).getWorkingDirectory( 1 );
-                will( returnValue( workingDir ) );
-
-                one( buildAgentConfigurationService ).getAvailableInstallations();
-                will( returnValue( null ) );
-            }
-        } );
-
+        when( buildAgentConfigurationService.getAvailableInstallations() ).thenReturn( null
);
         try
         {
             releaseManager.releasePrepare( createProjectMap(), createProperties(), createReleaseVersionMap(),
@@ -108,25 +91,8 @@ public class BuildAgentReleaseManagerTes
     public void testLocalRepositoryNameMismatchedCaseInReleasePrepare()
         throws Exception
     {
-        final List<LocalRepository> localRepos = createLocalRepositories();
-        final File workingDir = new File( getBasedir(), "target/test-classes/working-dir"
);
-
-        context.checking( new Expectations()
-        {
-            {
-                one( buildAgentConfigurationService ).getLocalRepositories();
-                will( returnValue( localRepos ) );
-
-                one( buildAgentConfigurationService ).getWorkingDirectory( 1 );
-                will( returnValue( workingDir ) );
-
-                one( buildAgentConfigurationService ).getAvailableInstallations();
-                will( returnValue( null ) );
-            }
-        } );
-
+        when( buildAgentConfigurationService.getAvailableInstallations() ).thenReturn( null
);
         Map<String, Object> map = createProjectMap();
-
         try
         {
             releaseManager.releasePrepare( map, createProperties(), createReleaseVersionMap(),
createDevVersionMap(),
@@ -143,23 +109,8 @@ public class BuildAgentReleaseManagerTes
     public void testLocalRepositoryInReleasePerform()
         throws Exception
     {
-        final List<LocalRepository> localRepos = createLocalRepositories();
-        final File workingDir = new File( getBasedir(), "target/test-classes/working-dir"
);
-
-        context.checking( new Expectations()
-        {
-            {
-                one( buildAgentConfigurationService ).getLocalRepositories();
-                will( returnValue( localRepos ) );
-
-                one( buildAgentConfigurationService ).getWorkingDirectory();
-                will( returnValue( workingDir ) );
-            }
-        } );
-
         Map repository = createRepositoryMap();
         repository.put( ContinuumBuildAgentUtil.KEY_LOCAL_REPOSITORY_NAME, "DEFAULT" );
-
         try
         {
             releaseManager.releasePerform( "1", "clean deploy", "", true, repository, "user"
);
@@ -174,20 +125,6 @@ public class BuildAgentReleaseManagerTes
     public void testLocalRepositoryNameMismatchedCaseInReleasePerform()
         throws Exception
     {
-        final List<LocalRepository> localRepos = createLocalRepositories();
-        final File workingDir = new File( getBasedir(), "target/test-classes/working-dir"
);
-
-        context.checking( new Expectations()
-        {
-            {
-                one( buildAgentConfigurationService ).getLocalRepositories();
-                will( returnValue( localRepos ) );
-
-                one( buildAgentConfigurationService ).getWorkingDirectory();
-                will( returnValue( workingDir ) );
-            }
-        } );
-
         try
         {
             releaseManager.releasePerform( "1", "clean deploy", "", true, createRepositoryMap(),
"user" );
@@ -203,24 +140,9 @@ public class BuildAgentReleaseManagerTes
     public void testLocalRepositoryInReleasePerformFromScm()
         throws Exception
     {
-        final List<LocalRepository> localRepos = createLocalRepositories();
-        final File workingDir = new File( getBasedir(), "target/test-classes/working-dir"
);
-
-        context.checking( new Expectations()
-        {
-            {
-                one( buildAgentConfigurationService ).getLocalRepositories();
-                will( returnValue( localRepos ) );
-
-                one( buildAgentConfigurationService ).getWorkingDirectory();
-                will( returnValue( workingDir ) );
-            }
-        } );
-
         Map repository = new HashMap();
         repository.put( ContinuumBuildAgentUtil.KEY_USERNAME, "user" );
         repository.put( ContinuumBuildAgentUtil.KEY_LOCAL_REPOSITORY_NAME, "default" );
-
         try
         {
             releaseManager.releasePerformFromScm( "clean deploy", "", true, repository,

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutorTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutorTest.java?rev=1659076&r1=1659075&r2=1659076&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutorTest.java
(original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/test/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutorTest.java
Wed Feb 11 21:27:03 2015
@@ -30,16 +30,13 @@ import org.apache.continuum.buildagent.m
 import org.apache.continuum.buildagent.utils.ContinuumBuildAgentUtil;
 import org.apache.continuum.taskqueue.BuildProjectTask;
 import org.apache.continuum.utils.build.BuildTrigger;
+import org.apache.maven.continuum.ContinuumException;
 import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.scm.ScmResult;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
 import org.codehaus.plexus.taskqueue.execution.TaskExecutor;
-import org.jmock.Expectations;
-import org.jmock.Mockery;
-import org.jmock.integration.junit3.JUnit3Mockery;
-import org.jmock.lib.legacy.ClassImposteriser;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -48,11 +45,11 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import static org.mockito.Mockito.*;
+
 public class BuildProjectTaskExecutorTest
     extends PlexusInSpringTestCase
 {
-    private Mockery context;
-
     private BuildContextManager buildContextManager;
 
     private BuildAgentBuildExecutorManager buildAgentBuildExecutorManager;
@@ -61,99 +58,76 @@ public class BuildProjectTaskExecutorTes
 
     private BuildAgentManager buildAgentManager;
 
-    protected void setUp()
-        throws Exception
-    {
-        super.setUp();
+    private BuildProjectTaskExecutor buildProjectExecutor;
 
-        context = new JUnit3Mockery();
-        context.setImposteriser( ClassImposteriser.INSTANCE );
+    private BuildContext buildContext;
 
-        buildContextManager = context.mock( BuildContextManager.class );
+    private List<LocalRepository> localRepos;
 
-        buildAgentBuildExecutorManager = context.mock( BuildAgentBuildExecutorManager.class
);
+    private Map<String, String> masterBuildEnvironments;
 
-        buildAgentConfigurationService = context.mock( BuildAgentConfigurationService.class
);
+    private List<Installation> slaveBuildEnvironments = new ArrayList<Installation>();
 
-        buildAgentManager = context.mock( BuildAgentManager.class );
-    }
+    private ContinuumAgentBuildExecutor executor;
 
-    // CONTINUUM-2391
-    // Note: The checking of the local repo set in the context is in ContinuumActionStub.
If the
-    // local repo path is incorrect, an exception will be thrown by the action stub.
-    public void testBuildProjectLocalRepository()
+    private File workingDir;
+
+    private MavenProject project;
+
+    private File outputFile;
+
+    protected void setUp()
         throws Exception
     {
-        BuildProjectTaskExecutor buildProjectExecutor = (BuildProjectTaskExecutor) lookup(
TaskExecutor.class,
-                                                                                        
  "build-agent" );
+        super.setUp();
 
-        buildProjectExecutor.setBuildAgentBuildExecutorManager( buildAgentBuildExecutorManager
);
+        buildContextManager = mock( BuildContextManager.class );
+        buildAgentBuildExecutorManager = mock( BuildAgentBuildExecutorManager.class );
+        buildAgentConfigurationService = mock( BuildAgentConfigurationService.class );
+        buildAgentManager = mock( BuildAgentManager.class );
+        executor = mock( ContinuumAgentBuildExecutor.class );
 
+        buildProjectExecutor = (BuildProjectTaskExecutor) lookup( TaskExecutor.class, "build-agent"
);
+        buildProjectExecutor.setBuildAgentBuildExecutorManager( buildAgentBuildExecutorManager
);
         buildProjectExecutor.setBuildAgentConfigurationService( buildAgentConfigurationService
);
-
         buildProjectExecutor.setBuildContextManager( buildContextManager );
-
         buildProjectExecutor.setBuildAgentManager( buildAgentManager );
 
-        final BuildContext buildContext = createBuildContext();
-
-        final List<LocalRepository> localRepos = new ArrayList<LocalRepository>();
+        buildContext = createBuildContext();
 
+        localRepos = new ArrayList<LocalRepository>();
         LocalRepository localRepo = createLocalRepository( "temp", "/tmp/.m2/repository",
"default" );
         localRepos.add( localRepo );
-
         localRepo = createLocalRepository( "default", "/home/user/.m2/repository", "default"
);
         localRepos.add( localRepo );
 
-        final Map<String, String> masterBuildEnvironments = new HashMap<String,
String>();
+        masterBuildEnvironments = new HashMap<String, String>();
         masterBuildEnvironments.put( "M2_HOME", "/tmp/apache-maven-2.2.1" );
 
-        final List<Installation> slaveBuildEnvironments = new ArrayList<Installation>();
-
-        final ContinuumAgentBuildExecutor executor = context.mock( ContinuumAgentBuildExecutor.class
);
-        final File workingDir = new File( "/tmp/data/working-directory/project-test" );
-        final MavenProject project = new MavenProject();
-        final File outputFile = new File( "/tmp/data/build-output-directory/output.txt" );
-
-        context.checking( new Expectations()
-        {
-            {
-                one( buildContextManager ).getBuildContext( 1 );
-                will( returnValue( buildContext ) );
-
-                one( buildAgentManager ).getEnvironments( 1, "maven2" );
-                will( returnValue( masterBuildEnvironments ) );
-
-                one( buildAgentConfigurationService ).getAvailableInstallations();
-                will( returnValue( slaveBuildEnvironments ) );
-
-                one( buildAgentConfigurationService ).getLocalRepositories();
-                will( returnValue( localRepos ) );
-
-                one( buildAgentManager ).shouldBuild( with( any( Map.class ) ) );
-                will( returnValue( true ) );
-
-                one( buildAgentBuildExecutorManager ).getBuildExecutor(
-                    ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR );
-                will( returnValue( executor ) );
+        slaveBuildEnvironments = new ArrayList<Installation>();
 
-                one( buildAgentConfigurationService ).getWorkingDirectory( 1 );
-                will( returnValue( workingDir ) );
-
-                one( executor ).getMavenProject( with( any( File.class ) ), with( any( BuildDefinition.class
) ) );
-                will( returnValue( project ) );
-
-                one( buildAgentManager ).startProjectBuild( 1 );
-
-                one( buildAgentConfigurationService ).getBuildOutputFile( 1 );
-                will( returnValue( outputFile ) );
-
-                one( buildAgentManager ).returnBuildResult( with( any( Map.class ) ) );
-
-                one( buildContextManager ).removeBuildContext( 1 );
-            }
-        } );
+        workingDir = new File( "/tmp/data/working-directory/project-test" );
+        project = new MavenProject();
+        outputFile = new File( "/tmp/data/build-output-directory/output.txt" );
+
+        when( buildContextManager.getBuildContext( 1 ) ).thenReturn( buildContext );
+        when( buildAgentManager.getEnvironments( 1, "maven2" ) ).thenReturn( masterBuildEnvironments
);
+        when( buildAgentConfigurationService.getAvailableInstallations() ).thenReturn( slaveBuildEnvironments
);
+        when( buildAgentConfigurationService.getLocalRepositories() ).thenReturn( localRepos
);
+        when( buildAgentManager.shouldBuild( anyMap() ) ).thenReturn( true );
+        when( buildAgentBuildExecutorManager.getBuildExecutor(
+            ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR ) ).thenReturn( executor
);
+        when( buildAgentConfigurationService.getWorkingDirectory( 1 ) ).thenReturn( workingDir
);
+        when( executor.getMavenProject( any( File.class ), any( BuildDefinition.class ) )
).thenReturn( project );
+        when( buildAgentConfigurationService.getBuildOutputFile( 1 ) ).thenReturn( outputFile
);
+    }
 
+    // CONTINUUM-2391
+    // Note: The checking of the local repo set in the context is in ContinuumActionStub.
If the
+    // local repo path is incorrect, an exception will be thrown by the action stub.
+    public void testBuildProjectLocalRepository()
+        throws Exception
+    {
         try
         {
             buildProjectExecutor.executeTask( createBuildProjectTask() );
@@ -162,87 +136,18 @@ public class BuildProjectTaskExecutorTes
         {
             fail( "An exception should not have been thrown!" );
         }
+
+        assertBuilt();
     }
 
     public void testBuildProjectWithConfiguredInstallationsFromBuildAgent()
         throws Exception
     {
-        BuildProjectTaskExecutor buildProjectExecutor = (BuildProjectTaskExecutor) lookup(
TaskExecutor.class,
-                                                                                        
  "build-agent" );
-
-        buildProjectExecutor.setBuildAgentBuildExecutorManager( buildAgentBuildExecutorManager
);
-
-        buildProjectExecutor.setBuildAgentConfigurationService( buildAgentConfigurationService
);
-
-        buildProjectExecutor.setBuildContextManager( buildContextManager );
-
-        buildProjectExecutor.setBuildAgentManager( buildAgentManager );
-
-        final BuildContext buildContext = createBuildContext();
-
-        final List<LocalRepository> localRepos = new ArrayList<LocalRepository>();
-
-        LocalRepository localRepo = createLocalRepository( "temp", "/tmp/.m2/repository",
"default" );
-        localRepos.add( localRepo );
-
-        localRepo = createLocalRepository( "default", "/home/user/.m2/repository", "default"
);
-        localRepos.add( localRepo );
-
-        final Map<String, String> masterBuildEnvironments = new HashMap<String,
String>();
-        masterBuildEnvironments.put( "M2_HOME", "/tmp/apache-maven-2.2.1" );
-
-        final List<Installation> slaveBuildEnvironments = new ArrayList<Installation>();
-
         Installation slaveBuildEnvironment = createInstallation( "M2_HOME", "/home/user/apache-maven-2.2.1"
);
         slaveBuildEnvironments.add( slaveBuildEnvironment );
-
         slaveBuildEnvironment = createInstallation( "EXTRA_VAR", "/home/user/extra" );
         slaveBuildEnvironments.add( slaveBuildEnvironment );
 
-        final ContinuumAgentBuildExecutor executor = context.mock( ContinuumAgentBuildExecutor.class
);
-        final File workingDir = new File( "/tmp/data/working-directory/project-test" );
-        final MavenProject project = new MavenProject();
-        final File outputFile = new File( "/tmp/data/build-output-directory/output.txt" );
-
-        context.checking( new Expectations()
-        {
-            {
-                one( buildContextManager ).getBuildContext( 1 );
-                will( returnValue( buildContext ) );
-
-                one( buildAgentManager ).getEnvironments( 1, "maven2" );
-                will( returnValue( masterBuildEnvironments ) );
-
-                one( buildAgentConfigurationService ).getAvailableInstallations();
-                will( returnValue( slaveBuildEnvironments ) );
-
-                one( buildAgentConfigurationService ).getLocalRepositories();
-                will( returnValue( localRepos ) );
-
-                one( buildAgentManager ).shouldBuild( with( any( Map.class ) ) );
-                will( returnValue( true ) );
-
-                one( buildAgentBuildExecutorManager ).getBuildExecutor(
-                    ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR );
-                will( returnValue( executor ) );
-
-                one( buildAgentConfigurationService ).getWorkingDirectory( 1 );
-                will( returnValue( workingDir ) );
-
-                one( executor ).getMavenProject( with( any( File.class ) ), with( any( BuildDefinition.class
) ) );
-                will( returnValue( project ) );
-
-                one( buildAgentManager ).startProjectBuild( 1 );
-
-                one( buildAgentConfigurationService ).getBuildOutputFile( 1 );
-                will( returnValue( outputFile ) );
-
-                one( buildAgentManager ).returnBuildResult( with( any( Map.class ) ) );
-
-                one( buildContextManager ).removeBuildContext( 1 );
-            }
-        } );
-
         try
         {
             buildProjectExecutor.executeTask( createBuildProjectTask() );
@@ -260,81 +165,13 @@ public class BuildProjectTaskExecutorTes
         {
             fail( "An exception should not have been thrown!" );
         }
+
+        assertBuilt();
     }
 
     public void testBuildProjectWithNoConfiguredInstallationsFromBuildAgent()
         throws Exception
     {
-        BuildProjectTaskExecutor buildProjectExecutor = (BuildProjectTaskExecutor) lookup(
TaskExecutor.class,
-                                                                                        
  "build-agent" );
-
-        buildProjectExecutor.setBuildAgentBuildExecutorManager( buildAgentBuildExecutorManager
);
-
-        buildProjectExecutor.setBuildAgentConfigurationService( buildAgentConfigurationService
);
-
-        buildProjectExecutor.setBuildContextManager( buildContextManager );
-
-        buildProjectExecutor.setBuildAgentManager( buildAgentManager );
-
-        final BuildContext buildContext = createBuildContext();
-
-        final List<LocalRepository> localRepos = new ArrayList<LocalRepository>();
-
-        LocalRepository localRepo = createLocalRepository( "temp", "/tmp/.m2/repository",
"default" );
-        localRepos.add( localRepo );
-
-        localRepo = createLocalRepository( "default", "/home/user/.m2/repository", "default"
);
-        localRepos.add( localRepo );
-
-        final Map<String, String> masterBuildEnvironments = new HashMap<String,
String>();
-        masterBuildEnvironments.put( "M2_HOME", "/tmp/apache-maven-2.2.1" );
-
-        final List<Installation> slaveBuildEnvironments = new ArrayList<Installation>();
-
-        final ContinuumAgentBuildExecutor executor = context.mock( ContinuumAgentBuildExecutor.class
);
-        final File workingDir = new File( "/tmp/data/working-directory/project-test" );
-        final MavenProject project = new MavenProject();
-        final File outputFile = new File( "/tmp/data/build-output-directory/output.txt" );
-
-        context.checking( new Expectations()
-        {
-            {
-                one( buildContextManager ).getBuildContext( 1 );
-                will( returnValue( buildContext ) );
-
-                one( buildAgentManager ).getEnvironments( 1, "maven2" );
-                will( returnValue( masterBuildEnvironments ) );
-
-                one( buildAgentConfigurationService ).getAvailableInstallations();
-                will( returnValue( slaveBuildEnvironments ) );
-
-                one( buildAgentConfigurationService ).getLocalRepositories();
-                will( returnValue( localRepos ) );
-
-                one( buildAgentManager ).shouldBuild( with( any( Map.class ) ) );
-                will( returnValue( true ) );
-
-                one( buildAgentBuildExecutorManager ).getBuildExecutor(
-                    ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR );
-                will( returnValue( executor ) );
-
-                one( buildAgentConfigurationService ).getWorkingDirectory( 1 );
-                will( returnValue( workingDir ) );
-
-                one( executor ).getMavenProject( with( any( File.class ) ), with( any( BuildDefinition.class
) ) );
-                will( returnValue( project ) );
-
-                one( buildAgentManager ).startProjectBuild( 1 );
-
-                one( buildAgentConfigurationService ).getBuildOutputFile( 1 );
-                will( returnValue( outputFile ) );
-
-                one( buildAgentManager ).returnBuildResult( with( any( Map.class ) ) );
-
-                one( buildContextManager ).removeBuildContext( 1 );
-            }
-        } );
-
         try
         {
             buildProjectExecutor.executeTask( createBuildProjectTask() );
@@ -349,6 +186,16 @@ public class BuildProjectTaskExecutorTes
         {
             fail( "An exception should not have been thrown!" );
         }
+
+        assertBuilt();
+    }
+
+    private void assertBuilt()
+        throws ContinuumException
+    {
+        verify( buildAgentManager ).startProjectBuild( 1 );
+        verify( buildAgentManager ).returnBuildResult( anyMap() );
+        verify( buildContextManager ).removeBuildContext( 1 );
     }
 
     private BuildProjectTask createBuildProjectTask()



Mime
View raw message