]> source.dussan.org Git - archiva.git/commitdiff
[MRM-138] add legacy layout tests
authorBrett Porter <brett@apache.org>
Mon, 14 Aug 2006 15:20:08 +0000 (15:20 +0000)
committerBrett Porter <brett@apache.org>
Mon, 14 Aug 2006 15:20:08 +0000 (15:20 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@431367 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-proxy/src/test/java/org/apache/maven/repository/proxy/ProxyRequestHandlerTest.java
maven-repository-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/get-default-layout-present-1.0.jar [new file with mode: 0644]
maven-repository-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-1.0.jar [new file with mode: 0644]
maven-repository-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-present-1.0.jar [new file with mode: 0644]
maven-repository-proxy/src/test/repositories/managed/org/apache/maven/test/get-updated-metadata/.metadata-proxied1

index e5af26ed7ca2bc4f48f4c442568e8452a3ff36d9..b71be98b9901e78965d35493317b9f427aebdabf 100644 (file)
@@ -40,6 +40,7 @@ import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Locale;
@@ -48,10 +49,6 @@ import java.util.Locale;
  * Test the proxy handler.
  *
  * @author Brett Porter
- * @todo! tests to do vvv
- * @todo test when managed repo is m1 layout (proxy is m2), including metadata
- * @todo test when one proxied repo is m1 layout (managed is m2), including metadata
- * @todo test when one proxied repo is m1 layout (managed is m1), including metadata
  */
 public class ProxyRequestHandlerTest
     extends PlexusTestCase
@@ -60,12 +57,18 @@ public class ProxyRequestHandlerTest
 
     private List proxiedRepositories;
 
+    private List legacyProxiedRepositories;
+
     private ArtifactRepository defaultManagedRepository;
 
+    private ArtifactRepository legacyManagedRepository;
+
     private ArtifactRepository proxiedRepository1;
 
     private ArtifactRepository proxiedRepository2;
 
+    private ArtifactRepository legacyProxiedRepository;
+
     private ArtifactRepositoryLayout defaultLayout;
 
     private ArtifactRepositoryFactory factory;
@@ -87,15 +90,25 @@ public class ProxyRequestHandlerTest
 
         requestHandler = (ProxyRequestHandler) lookup( ProxyRequestHandler.ROLE );
 
+        factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
+
         File repoLocation = getTestFile( "target/test-repository/managed" );
         FileUtils.deleteDirectory( repoLocation );
         copyDirectoryStructure( getTestFile( "src/test/repositories/managed" ), repoLocation );
 
         defaultLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "default" );
-        factory = (ArtifactRepositoryFactory) lookup( ArtifactRepositoryFactory.ROLE );
 
         defaultManagedRepository = createRepository( "managed-repository", repoLocation );
 
+        repoLocation = getTestFile( "target/test-repository/legacy-managed" );
+        FileUtils.deleteDirectory( repoLocation );
+        copyDirectoryStructure( getTestFile( "src/test/repositories/legacy-managed" ), repoLocation );
+
+        ArtifactRepositoryLayout legacyLayout =
+            (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
+
+        legacyManagedRepository = createRepository( "managed-repository", repoLocation );
+
         File location = getTestFile( "src/test/repositories/proxied1" );
         proxiedRepository1 = createRepository( "proxied1", location );
 
@@ -106,6 +119,11 @@ public class ProxyRequestHandlerTest
         proxiedRepositories.add( createProxiedRepository( proxiedRepository1 ) );
         proxiedRepositories.add( createProxiedRepository( proxiedRepository2 ) );
 
+        location = getTestFile( "src/test/repositories/legacy-proxied" );
+        legacyProxiedRepository = createRepository( "legacy-proxied", location, legacyLayout );
+
+        legacyProxiedRepositories = Collections.singletonList( createProxiedRepository( legacyProxiedRepository ) );
+
         wagonMockControl = MockControl.createNiceControl( Wagon.class );
         wagonMock = (Wagon) wagonMockControl.getMock();
         WagonDelegate delegate = (WagonDelegate) lookup( Wagon.ROLE, "test" );
@@ -1457,6 +1475,136 @@ public class ProxyRequestHandlerTest
         assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) );
     }
 
+    public void testLegacyManagedRepoGetNotPresent()
+        throws IOException, ResourceDoesNotExistException, ProxyException
+    {
+        String path = "org.apache.maven.test/jars/get-default-layout-1.0.jar";
+        File expectedFile = new File( legacyManagedRepository.getBasedir(), path );
+
+        assertFalse( expectedFile.exists() );
+
+        File file = requestHandler.get( path, proxiedRepositories, legacyManagedRepository );
+
+        assertEquals( "Check file matches", expectedFile, file );
+        assertTrue( "Check file created", file.exists() );
+        File proxiedFile = new File( proxiedRepository1.getBasedir(),
+                                     "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar" );
+        String expectedContents = FileUtils.fileRead( proxiedFile );
+        assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) );
+        // TODO: timestamp preservation requires support for that in wagon
+//        assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() );
+    }
+
+    public void testLegacyManagedRepoGetAlreadyPresent()
+        throws IOException, ResourceDoesNotExistException, ProxyException
+    {
+        String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
+        File expectedFile = new File( legacyManagedRepository.getBasedir(), path );
+        String expectedContents = FileUtils.fileRead( expectedFile );
+        long originalModificationTime = expectedFile.lastModified();
+
+        assertTrue( expectedFile.exists() );
+
+        File file = requestHandler.get( path, proxiedRepositories, legacyManagedRepository );
+
+        assertEquals( "Check file matches", expectedFile, file );
+        assertTrue( "Check file created", file.exists() );
+        assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) );
+        File proxiedFile = new File( proxiedRepository1.getBasedir(),
+                                     "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar" );
+        String unexpectedContents = FileUtils.fileRead( proxiedFile );
+        assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) );
+        assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() );
+        assertEquals( "Check file timestamp is that of original managed file", originalModificationTime,
+                      file.lastModified() );
+    }
+
+    public void testLegacyProxyRepoGetNotPresent()
+        throws IOException, ResourceDoesNotExistException, ProxyException
+    {
+        String path = "org/apache/maven/test/get-default-layout/1.0/get-default-layout-1.0.jar";
+        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
+
+        assertFalse( expectedFile.exists() );
+
+        File file = requestHandler.get( path, legacyProxiedRepositories, defaultManagedRepository );
+
+        assertEquals( "Check file matches", expectedFile, file );
+        assertTrue( "Check file created", file.exists() );
+        File proxiedFile =
+            new File( legacyProxiedRepository.getBasedir(), "org.apache.maven.test/jars/get-default-layout-1.0.jar" );
+        String expectedContents = FileUtils.fileRead( proxiedFile );
+        assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) );
+        // TODO: timestamp preservation requires support for that in wagon
+//        assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() );
+    }
+
+    public void testLegacyProxyRepoGetAlreadyPresent()
+        throws IOException, ResourceDoesNotExistException, ProxyException
+    {
+        String path = "org/apache/maven/test/get-default-layout-present/1.0/get-default-layout-present-1.0.jar";
+        File expectedFile = new File( defaultManagedRepository.getBasedir(), path );
+        String expectedContents = FileUtils.fileRead( expectedFile );
+        long originalModificationTime = expectedFile.lastModified();
+
+        assertTrue( expectedFile.exists() );
+
+        File file = requestHandler.get( path, legacyProxiedRepositories, defaultManagedRepository );
+
+        assertEquals( "Check file matches", expectedFile, file );
+        assertTrue( "Check file created", file.exists() );
+        assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) );
+        File proxiedFile = new File( legacyProxiedRepository.getBasedir(),
+                                     "org.apache.maven.test/jars/get-default-layout-present-1.0.jar" );
+        String unexpectedContents = FileUtils.fileRead( proxiedFile );
+        assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) );
+        assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() );
+        assertEquals( "Check file timestamp is that of original managed file", originalModificationTime,
+                      file.lastModified() );
+    }
+
+    public void testLegacyManagedAndProxyRepoGetNotPresent()
+        throws IOException, ResourceDoesNotExistException, ProxyException
+    {
+        String path = "org.apache.maven.test/jars/get-default-layout-1.0.jar";
+        File expectedFile = new File( legacyManagedRepository.getBasedir(), path );
+
+        assertFalse( expectedFile.exists() );
+
+        File file = requestHandler.get( path, legacyProxiedRepositories, legacyManagedRepository );
+
+        assertEquals( "Check file matches", expectedFile, file );
+        assertTrue( "Check file created", file.exists() );
+        File proxiedFile = new File( legacyProxiedRepository.getBasedir(), path );
+        String expectedContents = FileUtils.fileRead( proxiedFile );
+        assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) );
+        // TODO: timestamp preservation requires support for that in wagon
+//        assertEquals( "Check file timestamp", proxiedFile.lastModified(), file.lastModified() );
+    }
+
+    public void testLegacyManagedAndProxyRepoGetAlreadyPresent()
+        throws IOException, ResourceDoesNotExistException, ProxyException
+    {
+        String path = "org.apache.maven.test/jars/get-default-layout-present-1.0.jar";
+        File expectedFile = new File( legacyManagedRepository.getBasedir(), path );
+        String expectedContents = FileUtils.fileRead( expectedFile );
+        long originalModificationTime = expectedFile.lastModified();
+
+        assertTrue( expectedFile.exists() );
+
+        File file = requestHandler.get( path, legacyProxiedRepositories, legacyManagedRepository );
+
+        assertEquals( "Check file matches", expectedFile, file );
+        assertTrue( "Check file created", file.exists() );
+        assertEquals( "Check file contents", expectedContents, FileUtils.fileRead( file ) );
+        File proxiedFile = new File( legacyProxiedRepository.getBasedir(), path );
+        String unexpectedContents = FileUtils.fileRead( proxiedFile );
+        assertFalse( "Check file contents", unexpectedContents.equals( FileUtils.fileRead( file ) ) );
+        assertFalse( "Check file timestamp is not that of proxy", proxiedFile.lastModified() == file.lastModified() );
+        assertEquals( "Check file timestamp is that of original managed file", originalModificationTime,
+                      file.lastModified() );
+    }
+
     private static Date getPastDate()
         throws ParseException
     {
@@ -1569,6 +1717,12 @@ public class ProxyRequestHandlerTest
         return createRepository( id, repoLocation.toURI().toURL().toExternalForm() );
     }
 
+    private ArtifactRepository createRepository( String id, File location, ArtifactRepositoryLayout layout )
+        throws MalformedURLException
+    {
+        return createRepository( id, location.toURI().toURL().toExternalForm(), layout );
+    }
+
     private ArtifactRepository createRepository( String id, String url )
     {
         return createRepository( id, url, defaultLayout );
diff --git a/maven-repository-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/get-default-layout-present-1.0.jar b/maven-repository-proxy/src/test/repositories/legacy-managed/org.apache.maven.test/jars/get-default-layout-present-1.0.jar
new file mode 100644 (file)
index 0000000..bf26f6b
--- /dev/null
@@ -0,0 +1,2 @@
+get-default-layout-present-1.0.jar\r
+(managed)\r
diff --git a/maven-repository-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-1.0.jar b/maven-repository-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-1.0.jar
new file mode 100644 (file)
index 0000000..77dbb78
--- /dev/null
@@ -0,0 +1 @@
+get-default-layout-1.0.jar
diff --git a/maven-repository-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-present-1.0.jar b/maven-repository-proxy/src/test/repositories/legacy-proxied/org.apache.maven.test/jars/get-default-layout-present-1.0.jar
new file mode 100644 (file)
index 0000000..9f4121a
--- /dev/null
@@ -0,0 +1,2 @@
+get-default-layout-present-1.0.jar\r
+(proxied)\r
index 98361ced9b977ec3242ce54a485ce03a072aa365..76b43d62a1ea4d4e10ea7cc5239071ec59a6f9cb 100644 (file)
@@ -17,9 +17,9 @@
 <metadata>\r
   <groupId>org.apache.maven.test</groupId>\r
   <artifactId>get-updated-metadata</artifactId>\r
-  <versionining>\r
+  <versioning>\r
     <versions>\r
       <version>1.0</version>\r
     </versions>\r
-  </versionining>\r
-</metadata>
\ No newline at end of file
+  </versioning>\r
+</metadata>\r