]> source.dussan.org Git - archiva.git/commitdiff
try to respect managed repo configuration before any download. (partial MRM1658)
authorskygo <skygo@unknown>
Wed, 29 Aug 2012 22:27:14 +0000 (22:27 +0000)
committerskygo <skygo@unknown>
Wed, 29 Aug 2012 22:27:14 +0000 (22:27 +0000)
seek for a non S version on a managed repo configured as R and no S => fail
seek for a non R version on a managed repo configured as S and no R => fail
rewrite tests make MRM1411 on a separate class

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1378759 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/plugins/maven2-repository/src/main/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryStorage.java
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411Test.java [new file with mode: 0644]
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverManagedReleaseTest.java [new file with mode: 0644]
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverManagedSnapshotTest.java [new file with mode: 0644]
archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverTest.java

index cf27e99c851fd9419d2a54e2ae3c973360f305cd..01ea63c494bd0ee3b218f5eba3eb07bc3a1affe9 100644 (file)
@@ -156,7 +156,20 @@ public class Maven2RepositoryStorage
             ManagedRepository managedRepository = managedRepositoryAdmin.getManagedRepository( repoId );
 
             String artifactVersion = projectVersion;
-
+            if ( VersionUtil.isSnapshot( projectVersion ) ) // skygo trying to improve speed by honoring managed configuration MRM-1658
+            {
+                if ( managedRepository.isReleases() && !managedRepository.isSnapshots() )
+                {
+                    throw new RepositoryStorageRuntimeException("lookforsnaponreleaseonly", "managed repo is configured for release only");
+                }
+            } 
+            else 
+            {
+                if ( !managedRepository.isReleases() && managedRepository.isSnapshots() )
+                {
+                    throw new RepositoryStorageRuntimeException("lookforsreleaseonsneponly", "managed repo is configured for snapshot only");
+                }
+            }
             File basedir = new File( managedRepository.getLocation() );
             if ( VersionUtil.isSnapshot( projectVersion ) )
             {
diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411Test.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverMRM1411Test.java
new file mode 100644 (file)
index 0000000..e507b76
--- /dev/null
@@ -0,0 +1,393 @@
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import javax.inject.Inject;
+import javax.inject.Named;
+import junit.framework.TestCase;
+import org.apache.archiva.common.utils.FileUtil;
+import org.apache.archiva.configuration.ArchivaConfiguration;
+import org.apache.archiva.configuration.Configuration;
+import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
+import org.apache.archiva.configuration.ProxyConnectorConfiguration;
+import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
+import org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.model.Dependency;
+import org.apache.archiva.metadata.model.License;
+import org.apache.archiva.metadata.model.MailingList;
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.repository.filter.AllFilter;
+import org.apache.archiva.metadata.repository.filter.Filter;
+import org.apache.archiva.proxy.common.WagonFactory;
+import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
+import org.apache.commons.io.FileUtils;
+import org.apache.maven.wagon.Wagon;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import org.springframework.test.context.ContextConfiguration;
+
+@RunWith( ArchivaSpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
+public class Maven2RepositoryMetadataResolverMRM1411Test
+    extends TestCase
+{
+    private static final Filter<String> ALL = new AllFilter<String>();
+
+    @Inject
+    @Named( value = "repositoryStorage#maven2" )
+    private Maven2RepositoryStorage storage;
+
+    private static final String TEST_REPO_ID = "test";
+
+    private static final String TEST_REMOTE_REPO_ID = "central";
+
+    private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
+
+    private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
+
+    private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
+
+    private static final String TEST_SCM_CONN_BASE = "scm:svn:http://svn.example.com/repos/";
+
+    private static final String TEST_SCM_DEV_CONN_BASE = "scm:svn:https://svn.example.com/repos/";
+
+    private static final String TEST_SCM_URL_BASE = "http://svn.example.com/repos/";
+
+    private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
+
+    private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    @Inject
+    private ArchivaConfiguration configuration;
+
+    private WagonFactory wagonFactory;
+
+    ManagedRepositoryConfiguration testRepo;
+    
+    Configuration c;
+    
+    @Before
+    @Override
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        c = new Configuration();
+        testRepo = new ManagedRepositoryConfiguration();
+        testRepo.setId( TEST_REPO_ID );
+        testRepo.setLocation( new File( "target/test-repository" ).getAbsolutePath() );
+        testRepo.setReleases( true );
+        testRepo.setSnapshots( true );
+        c.addManagedRepository( testRepo );
+       
+
+        RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
+        testRemoteRepo.setId( TEST_REMOTE_REPO_ID );
+        testRemoteRepo.setLayout( "default" );
+        testRemoteRepo.setName( "Central Repository" );
+        testRemoteRepo.setUrl( "http://central.repo.com/maven2" );
+        testRemoteRepo.setTimeout( 10 );
+        c.addRemoteRepository( testRemoteRepo );
+
+        ProxyConnectorConfiguration proxyConnector = new ProxyConnectorConfiguration();
+        proxyConnector.setSourceRepoId( TEST_REPO_ID );
+        proxyConnector.setTargetRepoId( TEST_REMOTE_REPO_ID );
+        proxyConnector.setDisabled( false );
+        c.addProxyConnector( proxyConnector );
+
+        configuration.save( c );
+
+        assertTrue ( c.getManagedRepositories().get( 0 ).isSnapshots() );
+        assertTrue ( c.getManagedRepositories().get( 0 ).isReleases() );
+        
+        wagonFactory = mock( WagonFactory.class );
+
+        storage.setWagonFactory( wagonFactory );
+
+        Wagon wagon = new MockWagon();
+        when( wagonFactory.getWagon( "wagon#http" ) ).thenReturn( wagon );
+    }
+
+    // Tests for MRM-1411 - START
+    @Test
+    public void testGetProjectVersionMetadataWithParentSuccessful()
+        throws Exception
+    {
+        copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
+                                    "target/test-repository/com/example/test/test-artifact-module-a" );
+
+        ProjectVersionMetadata metadata =
+            storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-artifact-module-a", "1.0" );
+
+        MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
+        assertEquals( "jar", facet.getPackaging() );
+        assertEquals( "http://maven.apache.org", metadata.getUrl() );
+        assertEquals( "com.example.test", facet.getParent().getGroupId() );
+        assertEquals( "test-artifact-root", facet.getParent().getArtifactId() );
+        assertEquals( "1.0", facet.getParent().getVersion() );
+        assertEquals( "test-artifact-module-a", facet.getArtifactId() );
+        assertEquals( "com.example.test", facet.getGroupId() );
+        assertNull( metadata.getCiManagement() );
+        assertNotNull( metadata.getDescription() );
+
+        checkApacheLicense( metadata );
+
+        assertEquals( "1.0", metadata.getId() );
+        assertEquals( "Test Artifact :: Module A", metadata.getName() );
+        String path = "test-artifact/trunk/test-artifact-module-a";
+        assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
+        assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
+        assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
+
+        List<Dependency> dependencies = metadata.getDependencies();
+        assertEquals( 2, dependencies.size() );
+        assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
+        assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
+
+        List<String> paths = new ArrayList<String>();
+        paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
+        paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
+        paths.add( "target/test-repository/com/example/test/test-artifact-root" );
+
+        deleteTestArtifactWithParent( paths );
+    }
+
+    @Test
+    public void testGetProjectVersionMetadataWithParentNoRemoteReposConfigured()
+        throws Exception
+    {
+        // remove configuration
+        Configuration config = configuration.getConfiguration();
+        RemoteRepositoryConfiguration remoteRepo = config.findRemoteRepositoryById( TEST_REMOTE_REPO_ID );
+        config.removeRemoteRepository( remoteRepo );
+
+        configuration.save( config );
+
+        copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
+                                    "target/test-repository/com/example/test/test-artifact-module-a" );
+
+        ProjectVersionMetadata metadata =
+            storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-artifact-module-a", "1.0" );
+        assertEquals( "1.0", metadata.getId() );
+
+        MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
+        assertNotNull( facet );
+        assertEquals( "com.example.test", facet.getGroupId() );
+        assertEquals( "test-artifact-module-a", facet.getArtifactId() );
+        assertEquals( "jar", facet.getPackaging() );
+
+        List<String> paths = new ArrayList<String>();
+        paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
+        paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
+        paths.add( "target/test-repository/com/example/test/test-artifact-root" );
+
+        deleteTestArtifactWithParent( paths );
+    }
+
+    @Test
+    public void testGetProjectVersionMetadataWithParentNotInAnyRemoteRepo()
+        throws Exception
+    {
+        copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
+                                    "target/test-repository/com/example/test/test-artifact-module-a" );
+
+        ProjectVersionMetadata metadata =
+            storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-parent", "1.1" );
+
+        assertEquals( "1.1", metadata.getId() );
+
+        MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
+        assertNotNull( facet );
+        assertEquals( "com.example.test", facet.getGroupId() );
+        assertEquals( "missing-parent", facet.getArtifactId() );
+        assertEquals( "jar", facet.getPackaging() );
+
+        List<String> paths = new ArrayList<String>();
+        paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
+        paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
+        paths.add( "target/test-repository/com/example/test/test-artifact-root" );
+
+        deleteTestArtifactWithParent( paths );
+    }
+
+    @Test
+    public void testGetProjectVersionMetadataWithParentSnapshotVersion()
+        throws Exception
+    {
+        copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-module-a",
+                                    "target/test-repository/com/example/test/test-snapshot-artifact-module-a" );
+
+        ProjectVersionMetadata metadata =
+            storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-snapshot-artifact-module-a",
+                                                "1.1-SNAPSHOT" );
+
+        MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
+        assertEquals( "jar", facet.getPackaging() );
+        assertEquals( "com.example.test", facet.getParent().getGroupId() );
+        assertEquals( "test-snapshot-artifact-root", facet.getParent().getArtifactId() );
+        assertEquals( "1.1-SNAPSHOT", facet.getParent().getVersion() );
+        assertEquals( "test-snapshot-artifact-module-a", facet.getArtifactId() );
+        assertEquals( "com.example.test", facet.getGroupId() );
+        assertNull( metadata.getCiManagement() );
+        assertNotNull( metadata.getDescription() );
+
+        checkApacheLicense( metadata );
+
+        assertEquals( "1.1-SNAPSHOT", metadata.getId() );
+        assertEquals( "Test Snapshot Artifact :: Module A", metadata.getName() );
+        String path = "test-snapshot-artifact/trunk/test-snapshot-artifact-module-a";
+        assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
+        assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
+        assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
+
+        List<Dependency> dependencies = metadata.getDependencies();
+        assertEquals( 2, dependencies.size() );
+        assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
+        assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
+
+        List<String> paths = new ArrayList<String>();
+        paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-module-a" );
+        paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-root" );
+
+        deleteTestArtifactWithParent( paths );
+    }
+
+    // Tests for MRM-1411 - END
+
+private void assertDependency( Dependency dependency, String groupId, String artifactId, String version )
+    {
+        assertDependency( dependency, groupId, artifactId, version, "compile" );
+    }
+
+    private void assertDependency( Dependency dependency, String groupId, String artifactId, String version,
+                                   String scope )
+    {
+        assertEquals( artifactId, dependency.getArtifactId() );
+        assertEquals( "jar", dependency.getType() );
+        assertEquals( version, dependency.getVersion() );
+        assertEquals( groupId, dependency.getGroupId() );
+        assertEquals( scope, dependency.getScope() );
+        assertNull( dependency.getClassifier() );
+        assertNull( dependency.getSystemPath() );
+    }
+    
+    private void assertArtifact( ArtifactMetadata artifact, String id, int size, String sha1, String md5 )
+    {
+        assertEquals( id, artifact.getId() );
+        assertEquals( md5, artifact.getMd5() );
+        assertEquals( sha1, artifact.getSha1() );
+        assertEquals( size, artifact.getSize() );
+        assertEquals( "org.codehaus.plexus", artifact.getNamespace() );
+        assertEquals( "plexus-spring", artifact.getProject() );
+        assertEquals( "1.2", artifact.getVersion() );
+        assertEquals( TEST_REPO_ID, artifact.getRepositoryId() );
+    }
+
+    private void assertMailingList( MailingList mailingList, String name, String archive, String post, String subscribe,
+                                    String unsubscribe, List<String> otherArchives, boolean allowPost )
+    {
+        assertEquals( archive, mailingList.getMainArchiveUrl() );
+        if ( allowPost )
+        {
+            assertEquals( post, mailingList.getPostAddress() );
+        }
+        else
+        {
+            assertNull( mailingList.getPostAddress() );
+        }
+        assertEquals( subscribe, mailingList.getSubscribeAddress() );
+        assertEquals( unsubscribe, mailingList.getUnsubscribeAddress() );
+        assertEquals( name, mailingList.getName() );
+        assertEquals( otherArchives, mailingList.getOtherArchives() );
+    }
+
+    private void assertMailingList( String prefix, MailingList mailingList, String name, boolean allowPost,
+                                    String nabbleUrl )
+    {
+        List<String> otherArchives = new ArrayList<String>();
+        otherArchives.add( "http://www.mail-archive.com/" + prefix + "@archiva.apache.org" );
+        if ( nabbleUrl != null )
+        {
+            otherArchives.add( nabbleUrl );
+        }
+        otherArchives.add( "http://markmail.org/list/org.apache.archiva." + prefix );
+        assertMailingList( mailingList, name, "http://mail-archives.apache.org/mod_mbox/archiva-" + prefix + "/",
+                           prefix + "@archiva.apache.org", prefix + "-subscribe@archiva.apache.org",
+                           prefix + "-unsubscribe@archiva.apache.org", otherArchives, allowPost );
+    }
+
+    private void checkApacheLicense( ProjectVersionMetadata metadata )
+    {
+        assertEquals( Arrays.asList( new License( "The Apache Software License, Version 2.0",
+                                                  "http://www.apache.org/licenses/LICENSE-2.0.txt" ) ),
+                      metadata.getLicenses() );
+    }
+
+    private void checkOrganizationApache( ProjectVersionMetadata metadata )
+    {
+        assertEquals( "The Apache Software Foundation", metadata.getOrganization().getName() );
+        assertEquals( "http://www.apache.org/", metadata.getOrganization().getUrl() );
+    }
+
+    private void deleteTestArtifactWithParent( List<String> pathsToBeDeleted )
+        throws IOException
+    {
+        for ( String path : pathsToBeDeleted )
+        {
+            File dir = new File( FileUtil.getBasedir(), path );
+            FileUtils.deleteDirectory( dir );
+
+            assertFalse( dir.exists() );
+        }
+        File dest = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-module-a" );
+        File parentPom =
+            new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-parent" );
+        File rootPom = new File( FileUtil.getBasedir(), "target/test-repository/com/example/test/test-artifact-root" );
+
+        FileUtils.deleteDirectory( dest );
+        FileUtils.deleteDirectory( parentPom );
+        FileUtils.deleteDirectory( rootPom );
+
+        assertFalse( dest.exists() );
+        assertFalse( parentPom.exists() );
+        assertFalse( rootPom.exists() );
+    }
+
+    private File copyTestArtifactWithParent( String srcPath, String destPath )
+        throws IOException
+    {
+        File src = new File( FileUtil.getBasedir(), srcPath );
+        File dest = new File( FileUtil.getBasedir(), destPath );
+
+        FileUtils.copyDirectory( src, dest );
+        assertTrue( dest.exists() );
+        return dest;
+    }
+
+}
diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverManagedReleaseTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverManagedReleaseTest.java
new file mode 100644 (file)
index 0000000..5f21122
--- /dev/null
@@ -0,0 +1,135 @@
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.apache.archiva.configuration.ArchivaConfiguration;
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.repository.filter.AllFilter;
+import org.apache.archiva.metadata.repository.filter.Filter;
+import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException;
+import org.apache.archiva.proxy.common.WagonFactory;
+import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+
+
+@RunWith( ArchivaSpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
+public class Maven2RepositoryMetadataResolverManagedReleaseTest
+    extends Maven2RepositoryMetadataResolverTest
+{
+    private static final Filter<String> ALL = new AllFilter<String>();
+
+    @Inject
+    @Named( value = "repositoryStorage#maven2" )
+    private Maven2RepositoryStorage storage;
+
+    private static final String TEST_REPO_ID = "test";
+
+    private static final String TEST_REMOTE_REPO_ID = "central";
+
+    private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
+
+    private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
+
+    private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
+
+    private static final String TEST_SCM_CONN_BASE = "scm:svn:http://svn.example.com/repos/";
+
+    private static final String TEST_SCM_DEV_CONN_BASE = "scm:svn:https://svn.example.com/repos/";
+
+    private static final String TEST_SCM_URL_BASE = "http://svn.example.com/repos/";
+
+    private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
+
+    private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    @Inject
+    private ArchivaConfiguration configuration;
+
+    private WagonFactory wagonFactory;
+
+    @Before
+    @Override
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        testRepo.setReleases( true );
+        testRepo.setSnapshots( false );
+        
+        configuration.save( c );
+
+        assertFalse ( c.getManagedRepositories().get( 0 ).isSnapshots() );
+        assertTrue ( c.getManagedRepositories().get( 0 ).isReleases() );
+              
+    }
+
+    @Test
+    @Override
+    public void testModelWithJdkProfileActivation() 
+        throws Exception
+    {
+        // skygo IMHO must fail because TEST_REPO_ID ( is snap ,no release) and we seek for a snapshot
+      
+        ProjectVersionMetadata metadata =
+            storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache.maven", "maven-archiver", "2.4.1" );
+    }   
+    
+    @Test( expected = RepositoryStorageRuntimeException.class)
+    @Override
+    public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
+        throws Exception
+    {       
+        storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-metadata", "1.0-SNAPSHOT" );        
+    }
+    
+    @Test( expected = RepositoryStorageRuntimeException.class)
+    @Override
+    public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
+        throws Exception
+    {
+        storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "malformed-metadata",
+                                                "1.0-SNAPSHOT" );
+    }
+    
+    @Test( expected = RepositoryStorageRuntimeException.class)
+    @Override
+    public void testGetProjectVersionMetadataForTimestampedSnapshot()
+        throws Exception
+    {
+        super.testGetProjectVersionMetadataForTimestampedSnapshot();
+    }
+    
+    
+    @Test( expected = RepositoryStorageRuntimeException.class)
+    @Override
+    public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
+        throws Exception
+    {
+        super.testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata();
+    }
+    
+}
diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverManagedSnapshotTest.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/Maven2RepositoryMetadataResolverManagedSnapshotTest.java
new file mode 100644 (file)
index 0000000..ea51003
--- /dev/null
@@ -0,0 +1,132 @@
+package org.apache.archiva.metadata.repository.storage.maven2;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import org.apache.archiva.configuration.ArchivaConfiguration;
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.repository.filter.AllFilter;
+import org.apache.archiva.metadata.repository.filter.Filter;
+import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataInvalidException;
+import org.apache.archiva.metadata.repository.storage.RepositoryStorageMetadataNotFoundException;
+import org.apache.archiva.metadata.repository.storage.RepositoryStorageRuntimeException;
+import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+
+
+@RunWith( ArchivaSpringJUnit4ClassRunner.class )
+@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
+public class Maven2RepositoryMetadataResolverManagedSnapshotTest
+    extends Maven2RepositoryMetadataResolverTest
+{
+    private static final Filter<String> ALL = new AllFilter<String>();
+
+    @Inject
+    @Named( value = "repositoryStorage#maven2" )
+    private Maven2RepositoryStorage storage;
+
+    private static final String TEST_REPO_ID = "test";
+
+    private static final String TEST_REMOTE_REPO_ID = "central";
+
+    private static final String ASF_SCM_CONN_BASE = "scm:svn:http://svn.apache.org/repos/asf/";
+
+    private static final String ASF_SCM_DEV_CONN_BASE = "scm:svn:https://svn.apache.org/repos/asf/";
+
+    private static final String ASF_SCM_VIEWVC_BASE = "http://svn.apache.org/viewvc/";
+
+    private static final String TEST_SCM_CONN_BASE = "scm:svn:http://svn.example.com/repos/";
+
+    private static final String TEST_SCM_DEV_CONN_BASE = "scm:svn:https://svn.example.com/repos/";
+
+    private static final String TEST_SCM_URL_BASE = "http://svn.example.com/repos/";
+
+    private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
+
+    private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
+
+    @Inject
+    private ArchivaConfiguration configuration;
+
+
+    @Before
+    @Override
+    public void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        testRepo.setReleases( false );
+        testRepo.setSnapshots( true );
+        
+        configuration.save( c );
+
+        assertTrue ( c.getManagedRepositories().get( 0 ).isSnapshots() );
+        assertFalse ( c.getManagedRepositories().get( 0 ).isReleases() );
+    }
+
+    @Test( expected = RepositoryStorageRuntimeException.class)
+    @Override
+    public void testModelWithJdkProfileActivation() 
+        throws Exception
+    {
+        // skygo IMHO must fail because TEST_REPO_ID ( is snap ,no release) and we seek for a snapshot
+      
+        ProjectVersionMetadata metadata =
+            storage.readProjectVersionMetadata( TEST_REPO_ID, "org.apache.maven", "maven-archiver", "2.4.1" );
+    }   
+    
+    @Test( expected = RepositoryStorageRuntimeException.class )
+    @Override
+    public void testGetProjectVersionMetadataForMislocatedPom()
+        throws Exception    
+    {
+        storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "mislocated-pom", "1.0" );
+        
+    }
+    
+    @Test
+    @Override
+    public void testGetProjectVersionMetadata()
+        throws Exception
+    {
+       // super test is on release
+    }    
+    
+    @Test( expected = RepositoryStorageRuntimeException.class )
+    @Override
+    public void testGetProjectVersionMetadataForInvalidPom()
+        throws Exception
+    {
+        storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "invalid-pom", "1.0" );       
+    }
+    
+    @Test( expected = RepositoryStorageRuntimeException.class )
+    @Override
+    public void testGetProjectVersionMetadataForMissingPom()
+        throws Exception
+    {
+        storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-pom", "1.0" );
+    }
+}
index 62c15cceb327a35a3c362c1797103a9c3b999502..c9e047e503484b393b1e9c2640517d1377cf0f39 100644 (file)
@@ -19,7 +19,6 @@ package org.apache.archiva.metadata.repository.storage.maven2;
  * under the License.
  */
 
-import junit.framework.TestCase;
 import org.apache.archiva.common.utils.FileUtil;
 import org.apache.archiva.configuration.ArchivaConfiguration;
 import org.apache.archiva.configuration.Configuration;
@@ -54,6 +53,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
+import junit.framework.TestCase;
 import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
 
 import static org.mockito.Mockito.mock;
@@ -95,17 +95,25 @@ public class Maven2RepositoryMetadataResolverTest
 
     private WagonFactory wagonFactory;
 
+    ManagedRepositoryConfiguration testRepo;
+    
+    Configuration c;
+    
     @Before
+    @Override
     public void setUp()
         throws Exception
     {
         super.setUp();
 
-        Configuration c = new Configuration();
-        ManagedRepositoryConfiguration testRepo = new ManagedRepositoryConfiguration();
+        c = new Configuration();
+        testRepo = new ManagedRepositoryConfiguration();
         testRepo.setId( TEST_REPO_ID );
         testRepo.setLocation( new File( "target/test-repository" ).getAbsolutePath() );
+        testRepo.setReleases( true );
+        testRepo.setSnapshots( true );
         c.addManagedRepository( testRepo );
+       
 
         RemoteRepositoryConfiguration testRemoteRepo = new RemoteRepositoryConfiguration();
         testRemoteRepo.setId( TEST_REMOTE_REPO_ID );
@@ -123,6 +131,9 @@ public class Maven2RepositoryMetadataResolverTest
 
         configuration.save( c );
 
+        assertTrue ( c.getManagedRepositories().get( 0 ).isSnapshots() );
+        assertTrue ( c.getManagedRepositories().get( 0 ).isReleases() );
+        
         wagonFactory = mock( WagonFactory.class );
 
         storage.setWagonFactory( wagonFactory );
@@ -451,152 +462,6 @@ public class Maven2RepositoryMetadataResolverTest
         }
     }
 
-    // Tests for MRM-1411 - START
-    @Test
-    public void testGetProjectVersionMetadataWithParentSuccessful()
-        throws Exception
-    {
-        copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
-                                    "target/test-repository/com/example/test/test-artifact-module-a" );
-
-        ProjectVersionMetadata metadata =
-            storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-artifact-module-a", "1.0" );
-
-        MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
-        assertEquals( "jar", facet.getPackaging() );
-        assertEquals( "http://maven.apache.org", metadata.getUrl() );
-        assertEquals( "com.example.test", facet.getParent().getGroupId() );
-        assertEquals( "test-artifact-root", facet.getParent().getArtifactId() );
-        assertEquals( "1.0", facet.getParent().getVersion() );
-        assertEquals( "test-artifact-module-a", facet.getArtifactId() );
-        assertEquals( "com.example.test", facet.getGroupId() );
-        assertNull( metadata.getCiManagement() );
-        assertNotNull( metadata.getDescription() );
-
-        checkApacheLicense( metadata );
-
-        assertEquals( "1.0", metadata.getId() );
-        assertEquals( "Test Artifact :: Module A", metadata.getName() );
-        String path = "test-artifact/trunk/test-artifact-module-a";
-        assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
-        assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
-        assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
-
-        List<Dependency> dependencies = metadata.getDependencies();
-        assertEquals( 2, dependencies.size() );
-        assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
-        assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
-
-        List<String> paths = new ArrayList<String>();
-        paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
-        paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
-        paths.add( "target/test-repository/com/example/test/test-artifact-root" );
-
-        deleteTestArtifactWithParent( paths );
-    }
-
-    @Test
-    public void testGetProjectVersionMetadataWithParentNoRemoteReposConfigured()
-        throws Exception
-    {
-        // remove configuration
-        Configuration config = configuration.getConfiguration();
-        RemoteRepositoryConfiguration remoteRepo = config.findRemoteRepositoryById( TEST_REMOTE_REPO_ID );
-        config.removeRemoteRepository( remoteRepo );
-
-        configuration.save( config );
-
-        copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
-                                    "target/test-repository/com/example/test/test-artifact-module-a" );
-
-        ProjectVersionMetadata metadata =
-            storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-artifact-module-a", "1.0" );
-        assertEquals( "1.0", metadata.getId() );
-
-        MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
-        assertNotNull( facet );
-        assertEquals( "com.example.test", facet.getGroupId() );
-        assertEquals( "test-artifact-module-a", facet.getArtifactId() );
-        assertEquals( "jar", facet.getPackaging() );
-
-        List<String> paths = new ArrayList<String>();
-        paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
-        paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
-        paths.add( "target/test-repository/com/example/test/test-artifact-root" );
-
-        deleteTestArtifactWithParent( paths );
-    }
-
-    @Test
-    public void testGetProjectVersionMetadataWithParentNotInAnyRemoteRepo()
-        throws Exception
-    {
-        copyTestArtifactWithParent( "target/test-classes/com/example/test/test-artifact-module-a",
-                                    "target/test-repository/com/example/test/test-artifact-module-a" );
-
-        ProjectVersionMetadata metadata =
-            storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "missing-parent", "1.1" );
-
-        assertEquals( "1.1", metadata.getId() );
-
-        MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
-        assertNotNull( facet );
-        assertEquals( "com.example.test", facet.getGroupId() );
-        assertEquals( "missing-parent", facet.getArtifactId() );
-        assertEquals( "jar", facet.getPackaging() );
-
-        List<String> paths = new ArrayList<String>();
-        paths.add( "target/test-repository/com/example/test/test-artifact-module-a" );
-        paths.add( "target/test-repository/com/example/test/test-artifact-parent" );
-        paths.add( "target/test-repository/com/example/test/test-artifact-root" );
-
-        deleteTestArtifactWithParent( paths );
-    }
-
-    @Test
-    public void testGetProjectVersionMetadataWithParentSnapshotVersion()
-        throws Exception
-    {
-        copyTestArtifactWithParent( "target/test-classes/com/example/test/test-snapshot-artifact-module-a",
-                                    "target/test-repository/com/example/test/test-snapshot-artifact-module-a" );
-
-        ProjectVersionMetadata metadata =
-            storage.readProjectVersionMetadata( TEST_REPO_ID, "com.example.test", "test-snapshot-artifact-module-a",
-                                                "1.1-SNAPSHOT" );
-
-        MavenProjectFacet facet = (MavenProjectFacet) metadata.getFacet( MavenProjectFacet.FACET_ID );
-        assertEquals( "jar", facet.getPackaging() );
-        assertEquals( "com.example.test", facet.getParent().getGroupId() );
-        assertEquals( "test-snapshot-artifact-root", facet.getParent().getArtifactId() );
-        assertEquals( "1.1-SNAPSHOT", facet.getParent().getVersion() );
-        assertEquals( "test-snapshot-artifact-module-a", facet.getArtifactId() );
-        assertEquals( "com.example.test", facet.getGroupId() );
-        assertNull( metadata.getCiManagement() );
-        assertNotNull( metadata.getDescription() );
-
-        checkApacheLicense( metadata );
-
-        assertEquals( "1.1-SNAPSHOT", metadata.getId() );
-        assertEquals( "Test Snapshot Artifact :: Module A", metadata.getName() );
-        String path = "test-snapshot-artifact/trunk/test-snapshot-artifact-module-a";
-        assertEquals( TEST_SCM_CONN_BASE + path, metadata.getScm().getConnection() );
-        assertEquals( TEST_SCM_DEV_CONN_BASE + path, metadata.getScm().getDeveloperConnection() );
-        assertEquals( TEST_SCM_URL_BASE + path, metadata.getScm().getUrl() );
-
-        List<Dependency> dependencies = metadata.getDependencies();
-        assertEquals( 2, dependencies.size() );
-        assertDependency( dependencies.get( 0 ), "commons-io", "commons-io", "1.4" );
-        assertDependency( dependencies.get( 1 ), "junit", "junit", "3.8.1", "test" );
-
-        List<String> paths = new ArrayList<String>();
-        paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-module-a" );
-        paths.add( "target/test-repository/com/example/test/test-snapshot-artifact-root" );
-
-        deleteTestArtifactWithParent( paths );
-    }
-
-    // Tests for MRM-1411 - END
-
     @Test
     public void testGetRootNamespaces()
         throws Exception