archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1541399 [2/4] - in /archiva/trunk: ./ archiva-modules/archiva-base/archiva-configuration/src/test/java/org/apache/archiva/configuration/ archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva...
Date Wed, 13 Nov 2013 06:31:25 GMT
Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java?rev=1541399&r1=1541398&r2=1541399&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java Wed Nov 13 06:31:24 2013
@@ -44,8 +44,8 @@ import org.apache.jackrabbit.webdav.DavE
 import org.apache.jackrabbit.webdav.DavResourceLocator;
 import org.apache.jackrabbit.webdav.DavServletRequest;
 import org.apache.jackrabbit.webdav.DavServletResponse;
-import org.easymock.MockControl;
-import org.easymock.classextension.MockClassControl;
+
+import org.easymock.IMocksControl;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -59,6 +59,8 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 
+import static org.easymock.EasyMock.*;
+
 /**
  * ArchivaDavResourceFactoryTest
  */
@@ -79,25 +81,25 @@ public class ArchivaDavResourceFactoryTe
 
     private OverridingArchivaDavResourceFactory resourceFactory;
 
-    private MockControl requestControl;
+    private IMocksControl requestControl;
 
     private DavServletRequest request;
 
-    private MockControl repoRequestControl;
+    private IMocksControl repoRequestControl;
 
     private RepositoryRequest repoRequest;
 
-    private MockControl responseControl;
+    private IMocksControl responseControl;
 
     private DavServletResponse response;
 
-    private MockControl archivaConfigurationControl;
+    private IMocksControl archivaConfigurationControl;
 
     private ArchivaConfiguration archivaConfiguration;
 
     private Configuration config;
 
-    private MockControl repoContentFactoryControl;
+    private IMocksControl repoContentFactoryControl;
 
     private RepositoryContentFactory repoFactory;
 
@@ -124,21 +126,23 @@ public class ArchivaDavResourceFactoryTe
     {
         super.setUp();
 
-        requestControl = MockControl.createControl( DavServletRequest.class );
-        request = (DavServletRequest) requestControl.getMock();
+        requestControl = createControl();
+        request = requestControl.createMock( DavServletRequest.class );
 
-        responseControl = MockControl.createControl( DavServletResponse.class );
-        response = (DavServletResponse) responseControl.getMock();
-        responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
+        responseControl = createControl();
+        response = responseControl.createMock( DavServletResponse.class );
+        //responseControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
 
-        archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
-        archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
+        archivaConfigurationControl = createControl();
+        archivaConfiguration = archivaConfigurationControl.createMock( ArchivaConfiguration.class );
 
         config = new Configuration();
-        archivaConfiguration.getConfiguration();
-        archivaConfigurationControl.setReturnValue( config, 5, 20 );
+        //archivaConfiguration.getConfiguration();
+        //archivaConfigurationControl.setReturnValue( config, 5, 20 );
+        expect( archivaConfiguration.getConfiguration() ).andReturn( config ).times( 5, 20 );
         archivaConfiguration.save( config );
-        archivaConfigurationControl.setVoidCallable( 1, 4 );
+        //archivaConfigurationControl.setVoidCallable( 1, 4 );
+        expectLastCall().times( 1, 4 );
         archivaConfigurationControl.replay();
 
         defaultManagedRepositoryAdmin.setArchivaConfiguration( archivaConfiguration );
@@ -167,11 +171,11 @@ public class ArchivaDavResourceFactoryTe
             defaultRepositoryGroupAdmin.addRepositoryGroup( repoGroupConfig, null );
         }
 
-        repoContentFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class );
-        repoFactory = (RepositoryContentFactory) repoContentFactoryControl.getMock();
+        repoContentFactoryControl = createControl();
+        repoFactory = repoContentFactoryControl.createMock( RepositoryContentFactory.class );
 
-        repoRequestControl = MockClassControl.createControl( RepositoryRequest.class );
-        repoRequest = (RepositoryRequest) repoRequestControl.getMock();
+        repoRequestControl = createControl();
+        repoRequest = repoRequestControl.createMock( RepositoryRequest.class );
 
         resourceFactory =
             new OverridingArchivaDavResourceFactory( applicationContext, plexusSisuBridge, archivaConfiguration );
@@ -224,33 +228,51 @@ public class ArchivaDavResourceFactoryTe
         try
         {
             archivaConfigurationControl.reset();
-            archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
-            requestControl.expectAndReturn( request.getMethod(), "GET", 2 );
-            requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 );
-            repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( RELEASES_REPO ),
-                                                       releasesRepo );
-            requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 );
-            requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
-
-            repoRequestControl.expectAndReturn(
-                repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
+            //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
+            expect( archivaConfiguration.getConfiguration() ).andReturn( config );
+            //requestControl.expectAndReturn( request.getMethod(), "GET", 2 );
+            expect( request.getMethod() ).andReturn( "GET" ).times( 2 );
+            //requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 );
+            expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
+            //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( RELEASES_REPO ),
+            //                                           releasesRepo );
+            expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
+            //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 );
+            expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
+            //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
+            expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
+
+            //repoRequestControl.expectAndReturn(
+            //    repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
+            //    false );
+            expect( repoRequest.isSupportFile(
+                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( true );
+            //repoRequestControl.expectAndReturn(
+            //    repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false );
+            expect(
+                repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
                 false );
-            repoRequestControl.expectAndReturn(
-                repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false );
-            repoRequestControl.expectAndReturn(
-                repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
-                null );
-            repoRequestControl.expectAndReturn(
-                repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
-                                          internalRepo ),
+            //repoRequestControl.expectAndReturn(
+            //    repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
+            //    null );
+            expect( repoRequest.toArtifactReference(
+                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
+            //repoRequestControl.expectAndReturn(
+            //    repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", internalRepo ),
+            //    new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
+            //              "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
+            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
+                                              internalRepo ) ).andReturn(
                 new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
                           "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
-            repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
-                                                       internalRepo );
-            repoRequestControl.expectAndReturn(
-                    repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
-                    false );
-
+            //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
+            //                                           internalRepo );
+            expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
+            //repoRequestControl.expectAndReturn(
+            //        repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
+            //        false );
+            expect( repoRequest.isArchetypeCatalog(
+                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
             archivaConfigurationControl.replay();
             requestControl.replay();
             repoContentFactoryControl.replay();
@@ -296,32 +318,51 @@ public class ArchivaDavResourceFactoryTe
         try
         {
             archivaConfigurationControl.reset();
-            archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
-            requestControl.expectAndReturn( request.getMethod(), "GET", 2 );
-            requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 );
-            repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
-                                                       internalRepo );
-            repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( RELEASES_REPO ),
-                                                       releasesRepo );
-            requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 );
-            requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
-            repoRequestControl.expectAndReturn(
-                repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
+            //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
+            expect( archivaConfiguration.getConfiguration() ).andReturn( config );
+            //requestControl.expectAndReturn( request.getMethod(), "GET", 2 );
+            expect( request.getMethod() ).andReturn( "GET" ).times( 2 );
+            //requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 );
+            expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
+            //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
+            //                                           internalRepo );
+            expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
+            //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( RELEASES_REPO ),
+            //                                           releasesRepo );
+            expect( repoFactory.getManagedRepositoryContent( RELEASES_REPO ) ).andReturn( releasesRepo );
+            //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 );
+            expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
+            //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
+            expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
+            //repoRequestControl.expectAndReturn(
+            //    repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
+            //    false );
+            expect( repoRequest.isSupportFile(
+                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
+            //repoRequestControl.expectAndReturn(
+            //    repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false );
+            expect(
+                repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
                 false );
-            repoRequestControl.expectAndReturn(
-                repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false );
-            repoRequestControl.expectAndReturn(
-                repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
-                null );
-            repoRequestControl.expectAndReturn(
-                repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
-                                          internalRepo ),
+            //repoRequestControl.expectAndReturn(
+            //    repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
+            //    null );
+            expect( repoRequest.toArtifactReference(
+                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null );
+            //repoRequestControl.expectAndReturn(
+            //    repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", internalRepo ),
+            //    new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
+            //              "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
+            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
+                                              internalRepo ) ).andReturn(
                 new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
                           "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
-            repoRequestControl.expectAndReturn(
-                    repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
-                    false );
 
+            //repoRequestControl.expectAndReturn(
+            //        repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
+            //        false );
+            expect( repoRequest.isArchetypeCatalog(
+                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false );
             archivaConfigurationControl.replay();
             requestControl.replay();
             repoContentFactoryControl.replay();
@@ -370,39 +411,58 @@ public class ArchivaDavResourceFactoryTe
         try
         {
             archivaConfigurationControl.reset();
-            archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
-            requestControl.expectAndReturn( request.getMethod(), "GET", 4 );
-            requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 );
-            repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
-                                                       internalRepo );
-            repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ),
-                                                       localMirrorRepo );
-            requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 4 );
-            requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 4 );
-            repoRequestControl.expectAndReturn(
-                repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false,
-                2 );
-            repoRequestControl.expectAndReturn(
-                repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false, 2 );
-            repoRequestControl.expectAndReturn(
-                repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
-                null, 2 );
-            repoRequestControl.expectAndReturn(
-                repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
-                                          internalRepo ),
+            //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
+            expect( archivaConfiguration.getConfiguration() ).andReturn( config );
+            //requestControl.expectAndReturn( request.getMethod(), "GET", 4 );
+            expect( request.getMethod() ).andReturn( "GET" ).times( 4 );
+            //requestControl.expectAndReturn( request.getPathInfo(), "org/apache/archiva", 0, 2 );
+            expect( request.getPathInfo() ).andReturn( "org/apache/archiva" ).times( 0, 2 );
+            //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
+            //                                           internalRepo );
+            expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
+            //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ),
+            //                                           localMirrorRepo );
+            expect( repoFactory.getManagedRepositoryContent( LOCAL_MIRROR_REPO ) ).andReturn( localMirrorRepo );
+            //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 4 );
+            expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 4 );
+            //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 4 );
+            expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 4 );
+            //repoRequestControl.expectAndReturn(
+            //    repoRequest.isSupportFile( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false,
+            //    2 );
+            expect( repoRequest.isSupportFile(
+                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
+            //repoRequestControl.expectAndReturn(
+            //    repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ), false, 2 );
+            expect(
+                repoRequest.isDefault( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn(
+                false ).times( 2 );
+            //repoRequestControl.expectAndReturn(
+            //    repoRequest.toArtifactReference( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
+            //    null, 2 );
+            expect( repoRequest.toArtifactReference(
+                "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( null ).times( 2 );
+            //repoRequestControl.expectAndReturn(
+            //repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
+            //                          internalRepo ),
+            //new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
+            //          "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
+            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
+                                              internalRepo ) ).andReturn(
                 new File( config.findManagedRepositoryById( INTERNAL_REPO ).getLocation(),
                           "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
-
-            repoRequestControl.expectAndReturn(
-                repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
-                                          localMirrorRepo ),
-                new File( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
-                          "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
-
-            repoRequestControl.expectAndReturn(
-                    repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
-                    false , 2);
-
+            //repoRequestControl.expectAndReturn(
+            //    repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar", localMirrorRepo ),
+            //    new File( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
+            //              "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
+            expect( repoRequest.toNativePath( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar",
+                                              localMirrorRepo ) )
+                .andReturn( new File( config.findManagedRepositoryById( LOCAL_MIRROR_REPO ).getLocation(),
+                                      "target/test-classes/internal/org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ).getPath() );
+            //repoRequestControl.expectAndReturn(
+            //    repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ),
+            //    false, 2 );
+            expect( repoRequest.isArchetypeCatalog( "org/apache/archiva/archiva/1.2-SNAPSHOT/archiva-1.2-SNAPSHOT.jar" ) ).andReturn( false ).times( 2 );
             archivaConfigurationControl.replay();
             requestControl.replay();
             repoContentFactoryControl.replay();
@@ -442,24 +502,32 @@ public class ArchivaDavResourceFactoryTe
         try
         {
             archivaConfigurationControl.reset();
-            archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
-            repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
-                                                       internalRepo );
-            requestControl.expectAndReturn( request.getMethod(), "GET", 3 );
-            requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 3 );
-            requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
-            requestControl.expectAndReturn( request.getRequestURI(),
-                                            "http://localhost:8080/archiva/repository/" + INTERNAL_REPO
-                                                + "/eclipse/jdtcore/maven-metadata.xml" );
+            //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
+            expect( archivaConfiguration.getConfiguration() ).andReturn( config );
+            //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
+            //                                           internalRepo );
+            expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
+            //requestControl.expectAndReturn( request.getMethod(), "GET", 3 );
+            expect( request.getMethod() ).andReturn( "GET" ).times( 3 );
+            //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 3 );
+            expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 3 );
+            //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
+            expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
+            //requestControl.expectAndReturn( request.getRequestURI(),
+            //                                "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" );
+            expect( request.getRequestURI() ).andReturn( "http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml" );
             response.setHeader( "Pragma", "no-cache" );
-            responseControl.setVoidCallable();
+            //responseControl.setVoidCallable();
+            expectLastCall();
 
             response.setHeader( "Cache-Control", "no-cache" );
-            responseControl.setVoidCallable();
+            //responseControl.setVoidCallable();
+            expectLastCall();
 
-            long date = 2039842134;
-            response.setDateHeader( "last-modified", date );
-            responseControl.setVoidCallable();
+            //long date = 2039842134;
+            response.setDateHeader( eq("Last-Modified"), anyLong() );
+            //responseControl.setVoidCallable();
+            expectLastCall();
 
             archivaConfigurationControl.replay();
             repoContentFactoryControl.replay();
@@ -497,12 +565,17 @@ public class ArchivaDavResourceFactoryTe
         try
         {
             archivaConfigurationControl.reset();
-            archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
-            repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
-                                                       internalRepo );
-            requestControl.expectAndReturn( request.getMethod(), "GET", 2 );
-            requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 );
-            requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
+            //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
+            expect( archivaConfiguration.getConfiguration() ).andReturn( config );
+            //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ),
+            //                                           internalRepo );
+            expect( repoFactory.getManagedRepositoryContent( INTERNAL_REPO ) ).andReturn( internalRepo );
+            //requestControl.expectAndReturn( request.getMethod(), "GET", 2 );
+            expect( request.getMethod() ).andReturn( "GET" ).times( 2 );
+            //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 );
+            expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
+            //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
+            expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
 
             archivaConfigurationControl.replay();
             repoContentFactoryControl.replay();
@@ -542,12 +615,17 @@ public class ArchivaDavResourceFactoryTe
         try
         {
             archivaConfigurationControl.reset();
-            archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
-            repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( LEGACY_REPO ),
-                                                       legacyRepo );
-            requestControl.expectAndReturn( request.getMethod(), "GET", 2 );
-            requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 );
-            requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
+            //archivaConfigurationControl.expectAndReturn( archivaConfiguration.getConfiguration(), config );
+            expect( archivaConfiguration.getConfiguration() ).andReturn( config );
+            //repoContentFactoryControl.expectAndReturn( repoFactory.getManagedRepositoryContent( LEGACY_REPO ),
+            //                                           legacyRepo );
+            expect( repoFactory.getManagedRepositoryContent( LEGACY_REPO ) ).andReturn( legacyRepo );
+            //requestControl.expectAndReturn( request.getMethod(), "GET", 2 );
+            expect( request.getMethod() ).andReturn( "GET" ).times( 2 );
+            //requestControl.expectAndReturn( request.getRemoteAddr(), "http://localhost:8080", 2 );
+            expect( request.getRemoteAddr() ).andReturn( "http://localhost:8080" ).times( 2 );
+            //requestControl.expectAndReturn( request.getDavSession(), new ArchivaDavSession(), 2 );
+            expect( request.getDavSession() ).andReturn( new ArchivaDavSession() ).times( 2 );
 
             archivaConfigurationControl.replay();
             repoContentFactoryControl.replay();

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletSecurityTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletSecurityTest.java?rev=1541399&r1=1541398&r2=1541399&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletSecurityTest.java (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/RepositoryServletSecurityTest.java Wed Nov 13 06:31:24 2013
@@ -29,25 +29,26 @@ import com.meterware.servletunit.Servlet
 import com.meterware.servletunit.ServletUnitClient;
 import junit.framework.TestCase;
 import net.sf.ehcache.CacheManager;
-import org.apache.archiva.redback.authentication.AuthenticationException;
-import org.apache.archiva.redback.users.User;
-import org.apache.archiva.repository.audit.TestAuditListener;
-import org.apache.archiva.security.common.ArchivaRoleConstants;
-import org.apache.commons.io.FileUtils;
-import org.apache.jackrabbit.webdav.DavSessionProvider;
 import org.apache.archiva.configuration.ArchivaConfiguration;
 import org.apache.archiva.configuration.Configuration;
 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
-import org.apache.archiva.security.ServletAuthenticator;
+import org.apache.archiva.redback.authentication.AuthenticationException;
 import org.apache.archiva.redback.authentication.AuthenticationResult;
 import org.apache.archiva.redback.authorization.UnauthorizedException;
+import org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator;
 import org.apache.archiva.redback.system.DefaultSecuritySession;
 import org.apache.archiva.redback.system.SecuritySession;
+import org.apache.archiva.redback.users.User;
 import org.apache.archiva.redback.users.memory.SimpleUser;
-import org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator;
-import org.apache.archiva.redback.integration.filter.authentication.basic.HttpBasicAuthentication;
-import org.easymock.MockControl;
-import org.easymock.classextension.MockClassControl;
+import org.apache.archiva.repository.audit.TestAuditListener;
+import org.apache.archiva.security.ServletAuthenticator;
+import org.apache.archiva.security.common.ArchivaRoleConstants;
+import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
+import org.apache.commons.io.FileUtils;
+import org.apache.jackrabbit.webdav.DavSessionProvider;
+import org.easymock.EasyMock;
+import static org.easymock.EasyMock.*;
+import org.easymock.IMocksControl;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -56,19 +57,17 @@ import org.springframework.context.Appli
 import org.springframework.test.context.ContextConfiguration;
 
 import javax.inject.Inject;
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.charset.Charset;
 
-import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
-
 /**
  * RepositoryServletSecurityTest Test the flow of the authentication and authorization checks. This does not necessarily
  * perform redback security checking.
- * 
- *
  */
 @RunWith( ArchivaSpringJUnit4ClassRunner.class )
 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
@@ -87,11 +86,11 @@ public class RepositoryServletSecurityTe
 
     private DavSessionProvider davSessionProvider;
 
-    private MockControl servletAuthControl;
+    private IMocksControl servletAuthControl;
 
     private ServletAuthenticator servletAuth;
 
-    private MockClassControl httpAuthControl;
+    private IMocksControl httpAuthControl;
 
     private HttpAuthenticator httpAuth;
 
@@ -106,7 +105,8 @@ public class RepositoryServletSecurityTe
     {
         super.setUp();
 
-        String appserverBase =  System.getProperty( "appserver.base", new File( "target/appserver-base" ).getAbsolutePath() );
+        String appserverBase =
+            System.getProperty( "appserver.base", new File( "target/appserver-base" ).getAbsolutePath() );
 
         File testConf = new File( "src/test/resources/repository-archiva.xml" );
         File testConfDest = new File( appserverBase, "conf/archiva.xml" );
@@ -117,9 +117,10 @@ public class RepositoryServletSecurityTe
         archivaConfiguration = applicationContext.getBean( ArchivaConfiguration.class );
         Configuration config = archivaConfiguration.getConfiguration();
 
-        if (!config.getManagedRepositoriesAsMap().containsKey( REPOID_INTERNAL ))
+        if ( !config.getManagedRepositoriesAsMap().containsKey( REPOID_INTERNAL ) )
         {
-            config.addManagedRepository( createManagedRepository( REPOID_INTERNAL, "Internal Test Repo", repoRootInternal ) );
+            config.addManagedRepository(
+                createManagedRepository( REPOID_INTERNAL, "Internal Test Repo", repoRootInternal ) );
         }
         saveConfiguration( archivaConfiguration );
 
@@ -131,14 +132,14 @@ public class RepositoryServletSecurityTe
         sr.registerServlet( "/repository/*", RepositoryServlet.class.getName() );
         sc = sr.newClient();
 
-        servletAuthControl = MockControl.createControl( ServletAuthenticator.class );
-        servletAuthControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
-        servletAuth = (ServletAuthenticator) servletAuthControl.getMock();
-
-        httpAuthControl =
-            MockClassControl.createControl( HttpBasicAuthentication.class, HttpBasicAuthentication.class.getMethods() );
-        httpAuthControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
-        httpAuth = (HttpAuthenticator) httpAuthControl.getMock();
+        servletAuthControl = EasyMock.createControl();// MockControl.createControl( ServletAuthenticator.class );
+        //servletAuthControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
+        servletAuth = servletAuthControl.createMock( ServletAuthenticator.class );
+
+        httpAuthControl = EasyMock.createControl();
+        //MockClassControl.createControl( HttpBasicAuthentication.class, HttpBasicAuthentication.class.getMethods() );
+        //httpAuthControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
+        httpAuth = httpAuthControl.createMock( HttpAuthenticator.class );
 
         davSessionProvider = new ArchivaDavSessionProvider( servletAuth, httpAuth );
     }
@@ -217,13 +218,19 @@ public class RepositoryServletSecurityTe
         servlet.setDavSessionProvider( davSessionProvider );
 
         AuthenticationResult result = new AuthenticationResult();
-        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
-        servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ),
-                                           new AuthenticationException( "Authentication error" ) );
+        //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
+        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
+                                                           anyObject( HttpServletResponse.class ) ) ).andReturn( result );
+        //servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ),
+        //                                   new AuthenticationException( "Authentication error" ) );
+        servletAuth.isAuthenticated( EasyMock.anyObject( HttpServletRequest.class ),
+                                     EasyMock.anyObject( AuthenticationResult.class ) );
+        EasyMock.expectLastCall().andThrow( new AuthenticationException( "Authentication error" ) );
 
         servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD );
-        servletAuthControl.setMatcher( MockControl.EQUALS_MATCHER );
-        servletAuthControl.setThrowable( new UnauthorizedException( "'guest' has no write access to repository" ) );
+        //servletAuthControl.setMatcher( MockControl.EQUALS_MATCHER );
+        //servletAuthControl.setThrowable( new UnauthorizedException( "'guest' has no write access to repository" ) );
+        EasyMock.expectLastCall().andThrow( new UnauthorizedException( "'guest' has no write access to repository" ) );
 
         httpAuthControl.replay();
         servletAuthControl.replay();
@@ -260,27 +267,41 @@ public class RepositoryServletSecurityTe
         servlet.setResourceFactory( archivaDavResourceFactory );
 
         AuthenticationResult result = new AuthenticationResult();
-        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
-        servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ),
-                                           new AuthenticationException( "Authentication error" ) );
-
-        servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD );
-        servletAuthControl.setMatcher( MockControl.EQUALS_MATCHER );
-        servletAuthControl.setReturnValue( true );
+        //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
+        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
+                                                           anyObject( HttpServletResponse.class ) ) ).andReturn( result );
+        //servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ),
+        //                                   new AuthenticationException( "Authentication error" ) );
+
+        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
+                                                      anyObject( AuthenticationResult.class ) ) ).andThrow(
+            new AuthenticationException( "Authentication error" ) );
+
+        //servletAuthControl.setMatcher( MockControl.EQUALS_MATCHER );
+        //servletAuthControl.setReturnValue( true );
+        EasyMock.expect(servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD )).andReturn( true );
 
         // ArchivaDavResourceFactory#isAuthorized()
         SecuritySession session = new DefaultSecuritySession();
-        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
-        httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session );
-        servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, result ),
-                                           new AuthenticationException( "Authentication error" ) );
+        //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
+        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
+                                                           anyObject( HttpServletResponse.class ) ) ).andReturn( result );
+        //httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session );
+        EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class ) ) ).andReturn( session );
+        //servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, result ),
+        //                                   new AuthenticationException( "Authentication error" ) );
+        EasyMock.expect(servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq(result) )).andThrow( new AuthenticationException( "Authentication error" ) );
 
-        httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), null );
+        //httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), null );
+        EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class ) ) ).andReturn( null );
 
         // check if guest has write access
-        servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD );
-        servletAuthControl.setMatcher( MockControl.EQUALS_MATCHER );
-        servletAuthControl.setReturnValue( true );
+        //servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD );
+        //servletAuthControl.setMatcher( MockControl.EQUALS_MATCHER );
+        //servletAuthControl.setReturnValue( true );
+        EasyMock.expect( servletAuth.isAuthorized( "guest", "internal",
+                                                   ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ) ).andReturn(
+            true );
 
         httpAuthControl.replay();
         servletAuthControl.replay();
@@ -316,20 +337,31 @@ public class RepositoryServletSecurityTe
         servlet.setResourceFactory( archivaDavResourceFactory );
 
         AuthenticationResult result = new AuthenticationResult();
-        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
-        servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true );
+        //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
+        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
+                                                           anyObject( HttpServletResponse.class ) ) ).andReturn( result );
+        //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true );
+        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
+                                                      anyObject( AuthenticationResult.class ) ) ).andReturn( true );
 
         // ArchivaDavResourceFactory#isAuthorized()
         SecuritySession session = new DefaultSecuritySession();
-        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
-        httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session );
-        httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), new SimpleUser() );
-        servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true );
-        servletAuthControl.expectAndThrow(
-                                           servletAuth.isAuthorized( null, session, "internal",
-                                                                     ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ),
-                                           new UnauthorizedException( "User not authorized" ) );
-
+        //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
+        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
+                                                           anyObject( HttpServletResponse.class ) ) ).andReturn( result );
+        //httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session );
+        EasyMock.expect( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ) ).andReturn( session );
+        //httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), new SimpleUser() );
+        EasyMock.expect( httpAuth.getSessionUser( ic.getRequest().getSession() ) ).andReturn( new SimpleUser() );
+        //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true );
+        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
+                                                      eq( result ) ) ).andReturn( true );
+        //servletAuthControl.expectAndThrow(
+        //                                   servletAuth.isAuthorized( null, session, "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ),
+        //                                   new UnauthorizedException( "User not authorized" ) );
+        EasyMock.expect( servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq(session), eq("internal"),
+                                                   eq(ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD) ) ).andThrow(
+            new UnauthorizedException( "User not authorized" ) );
         httpAuthControl.replay();
         servletAuthControl.replay();
 
@@ -368,22 +400,34 @@ public class RepositoryServletSecurityTe
         servlet.setResourceFactory( archivaDavResourceFactory );
 
         AuthenticationResult result = new AuthenticationResult();
-        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
-        servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true );
+        //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
+        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ),
+                                                           anyObject( HttpServletResponse.class) )).andReturn( result );
+        //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true );
+        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ),
+                                                      anyObject( AuthenticationResult.class ) ) ).andReturn( true );
 
         User user = new SimpleUser();
         user.setUsername( "admin" );
-        
+
         // ArchivaDavResourceFactory#isAuthorized()
         SecuritySession session = new DefaultSecuritySession();
-        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
-        httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session );
-        httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), user );
-        servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true );
-        servletAuthControl.expectAndReturn(
-                                            servletAuth.isAuthorized( null, session, "internal",
-                                                                      ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ),
-                                            true );
+        //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
+        EasyMock.expect( httpAuth.getAuthenticationResult(anyObject( HttpServletRequest.class ),
+                                                          anyObject( HttpServletResponse.class) ) ).andReturn( result );
+        //httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session );
+        EasyMock.expect( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ) ).andReturn( session );
+        //httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), user );
+        EasyMock.expect( httpAuth.getSessionUser( ic.getRequest().getSession() ) ).andReturn( user );
+        //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true );
+        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq(result) ) ).andReturn(
+            true );
+        //servletAuthControl.expectAndReturn(
+        //                                    servletAuth.isAuthorized( null, session, "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ),
+        //                                    true );
+        EasyMock.expect( servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq(session), eq("internal"),
+                                                   eq(ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD) ) ).andReturn(
+            true );
 
         httpAuthControl.replay();
         servletAuthControl.replay();
@@ -409,7 +453,7 @@ public class RepositoryServletSecurityTe
         File artifactFile = new File( repoRootInternal, commonsLangJar );
         artifactFile.getParentFile().mkdirs();
 
-        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset()  );
+        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
 
         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
         InvocationContext ic = sc.newInvocation( request );
@@ -423,25 +467,37 @@ public class RepositoryServletSecurityTe
         servlet.setResourceFactory( archivaDavResourceFactory );
 
         AuthenticationResult result = new AuthenticationResult();
-        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
-        servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ),
-                                           new AuthenticationException( "Authentication error" ) );
-        servletAuthControl.expectAndReturn(
-                                            servletAuth.isAuthorized( "guest", "internal",
-                                                                      ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ),
-                                            true );
+        //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
+        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), anyObject( HttpServletResponse.class ) ) )
+            .andReturn( result );
+        //servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ),
+        //                                   new AuthenticationException( "Authentication error" ) );
+        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), anyObject( AuthenticationResult.class ) ) ).andThrow(
+            new AuthenticationException( "Authentication error" ) );
+        //servletAuthControl.expectAndReturn(
+        //                                    servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ),
+        //                                    true );
+        EasyMock.expect( servletAuth.isAuthorized( "guest", "internal",
+                                                   ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ) ).andReturn(
+            true );
 
         // ArchivaDavResourceFactory#isAuthorized()
         SecuritySession session = new DefaultSecuritySession();
-        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
-        httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session );
-        httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), null );
-        servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true );
-        servletAuthControl.expectAndReturn(
-                                            servletAuth.isAuthorized( null, session, "internal",
-                                                                      ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ),
-                                            true );
-
+        //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
+        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), anyObject( HttpServletResponse.class ) ) ).andReturn( result );
+        //httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session );
+        EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class ) ) ).andReturn( session );
+        //httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), null );
+        EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class ) ) ).andReturn( null );
+        //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true );
+        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq(result) ) ).andReturn(
+            true );
+        //servletAuthControl.expectAndReturn(
+        //                                    servletAuth.isAuthorized( null, session, "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ),
+        //                                    true );
+        EasyMock.expect( servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq(session), eq("internal"),
+                                                   eq(ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS) ) ).andReturn(
+            true );
         httpAuthControl.replay();
         servletAuthControl.replay();
 
@@ -465,7 +521,7 @@ public class RepositoryServletSecurityTe
         File artifactFile = new File( repoRootInternal, commonsLangJar );
         artifactFile.getParentFile().mkdirs();
 
-        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset()  );
+        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
 
         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
         InvocationContext ic = sc.newInvocation( request );
@@ -473,14 +529,18 @@ public class RepositoryServletSecurityTe
         servlet.setDavSessionProvider( davSessionProvider );
 
         AuthenticationResult result = new AuthenticationResult();
-        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
-        servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ),
-                                           new AuthenticationException( "Authentication error" ) );
-        servletAuthControl.expectAndReturn(
-                                            servletAuth.isAuthorized( "guest", "internal",
-                                                                      ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ),
-                                            false );
-
+        //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
+        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), anyObject( HttpServletResponse.class ) ) ).andReturn( result );
+        //servletAuthControl.expectAndThrow( servletAuth.isAuthenticated( null, null ),
+        //                                   new AuthenticationException( "Authentication error" ) );
+        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), anyObject( AuthenticationResult.class ) ) ).andThrow(
+            new AuthenticationException( "Authentication error" ) );
+        //servletAuthControl.expectAndReturn(
+        //                                    servletAuth.isAuthorized( "guest", "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ),
+        //                                    false );
+        EasyMock.expect( servletAuth.isAuthorized( "guest", "internal",
+                                                   ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ) ).andReturn(
+            false );
         httpAuthControl.replay();
         servletAuthControl.replay();
 
@@ -503,7 +563,7 @@ public class RepositoryServletSecurityTe
         File artifactFile = new File( repoRootInternal, commonsLangJar );
         artifactFile.getParentFile().mkdirs();
 
-        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset()  );
+        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
 
         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
         InvocationContext ic = sc.newInvocation( request );
@@ -517,19 +577,27 @@ public class RepositoryServletSecurityTe
         servlet.setResourceFactory( archivaDavResourceFactory );
 
         AuthenticationResult result = new AuthenticationResult();
-        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
-        servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true );
-
+        //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
+        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), anyObject( HttpServletResponse.class ) ) ).andReturn( result );
+        //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true );
+        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), anyObject( AuthenticationResult.class ) ) ).andReturn( true );
         // ArchivaDavResourceFactory#isAuthorized()
         SecuritySession session = new DefaultSecuritySession();
-        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
-        httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session );
-        httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), new SimpleUser() );
-        servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true );
-        servletAuthControl.expectAndReturn(
-                                            servletAuth.isAuthorized( null, session, "internal",
-                                                                      ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ),
-                                            true );
+        //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
+        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), anyObject( HttpServletResponse.class ) ) ).andReturn( result );
+        //httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session );
+        EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class ) ) ).andReturn( session );
+        //httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), new SimpleUser() );
+        EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class ) ) ).andReturn( new SimpleUser() );
+        //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true );
+        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq(result) ) ).andReturn(
+            true );
+        //servletAuthControl.expectAndReturn(
+        //                                    servletAuth.isAuthorized( null, session, "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ),
+        //                                    true );
+        EasyMock.expect( servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq(session), eq("internal"),
+                                                   eq(ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS) ) ).andReturn(
+            true );
 
         httpAuthControl.replay();
         servletAuthControl.replay();
@@ -554,7 +622,7 @@ public class RepositoryServletSecurityTe
         File artifactFile = new File( repoRootInternal, commonsLangJar );
         artifactFile.getParentFile().mkdirs();
 
-        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset()  );
+        FileUtils.writeStringToFile( artifactFile, expectedArtifactContents, Charset.defaultCharset() );
 
         WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + commonsLangJar );
         InvocationContext ic = sc.newInvocation( request );
@@ -568,20 +636,27 @@ public class RepositoryServletSecurityTe
         servlet.setResourceFactory( archivaDavResourceFactory );
 
         AuthenticationResult result = new AuthenticationResult();
-        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
-        servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true );
+        //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
+        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), anyObject( HttpServletResponse.class ) ) ).andReturn( result );
+        //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, null ), true );
+        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), anyObject( AuthenticationResult.class ) ) ).andReturn( true );
 
         // ArchivaDavResourceFactory#isAuthorized()
         SecuritySession session = new DefaultSecuritySession();
-        httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
-        httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session );
-        httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), new SimpleUser() );
-        servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true );
-        servletAuthControl.expectAndThrow(
-                                           servletAuth.isAuthorized( null, session, "internal",
-                                                                     ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ),
-                                           new UnauthorizedException( "User not authorized to read repository." ) );
-
+        //httpAuthControl.expectAndReturn( httpAuth.getAuthenticationResult( null, null ), result );
+        EasyMock.expect( httpAuth.getAuthenticationResult( anyObject( HttpServletRequest.class ), anyObject( HttpServletResponse.class ) ) ).andReturn( result );
+        //httpAuthControl.expectAndReturn( httpAuth.getSecuritySession( ic.getRequest().getSession( true ) ), session );
+        EasyMock.expect( httpAuth.getSecuritySession( anyObject( HttpSession.class) ) ).andReturn( session );
+        //httpAuthControl.expectAndReturn( httpAuth.getSessionUser( ic.getRequest().getSession() ), new SimpleUser() );
+        EasyMock.expect( httpAuth.getSessionUser( anyObject( HttpSession.class) ) ).andReturn( new SimpleUser() );
+        //servletAuthControl.expectAndReturn( servletAuth.isAuthenticated( null, result ), true );
+        EasyMock.expect( servletAuth.isAuthenticated( anyObject( HttpServletRequest.class ), eq(result) ) ).andReturn(
+            true );
+        //servletAuthControl.expectAndThrow( servletAuth.isAuthorized( null, session, "internal", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD ),
+        //                                   new UnauthorizedException( "User not authorized to read repository." ) );
+        EasyMock.expect( servletAuth.isAuthorized( anyObject( HttpServletRequest.class ), eq(session), eq("internal"),
+                                                   eq(ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS) ) ).andThrow(
+            new UnauthorizedException( "User not authorized to read repository." ) );
         httpAuthControl.replay();
         servletAuthControl.replay();
 



Mime
View raw message