[MRM-1704] Refactor to remove maven specific part from various repository/metadata apis

fix some unit tests due to some move spring conf for test need to be adapted.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1403511 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-10-29 21:02:19 +00:00
parent 7e8b82411a
commit 00ee48b77b
18 changed files with 56 additions and 159 deletions

View File

@ -72,6 +72,7 @@ import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
@ -136,8 +137,7 @@ public class Maven2RepositoryStorage
private WagonFactory wagonFactory;
@Inject
@Named ( value = "repositoryProxyConnectors#default" )
private RepositoryProxyConnectors connectors;
private ApplicationContext applicationContext;
private static final Logger log = LoggerFactory.getLogger( Maven2RepositoryStorage.class );
@ -644,6 +644,9 @@ public class Maven2RepositoryStorage
pomReference.setVersion( artifact.getVersion() );
pomReference.setType( "pom" );
RepositoryProxyConnectors connectors =
applicationContext.getBean( "repositoryProxyConnectors#default", RepositoryProxyConnectors.class );
// Get the artifact POM from proxied repositories if needed
connectors.fetchFromProxies( managedRepository, pomReference );

View File

@ -47,17 +47,17 @@ public class TestConfiguration
public void addListener( ConfigurationListener listener )
{
throw new UnsupportedOperationException();
// no op
}
public void removeListener( ConfigurationListener listener )
{
throw new UnsupportedOperationException();
// no op
}
public void addChangeListener( RegistryListener listener )
{
throw new UnsupportedOperationException();
// no op
}
public void reload()

View File

@ -35,7 +35,7 @@ public class TestMetadataResolver
String projectId, String projectVersion )
throws MetadataResolutionException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
return null;
}
public Collection<ProjectVersionReference> resolveProjectReferences( RepositorySession session, String repoId,
@ -43,38 +43,38 @@ public class TestMetadataResolver
String projectVersion )
throws MetadataResolutionException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
return null;
}
public Collection<String> resolveRootNamespaces( RepositorySession session, String repoId )
throws MetadataResolutionException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
return null;
}
public Collection<String> resolveNamespaces( RepositorySession session, String repoId, String namespace )
throws MetadataResolutionException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
return null;
}
public Collection<String> resolveProjects( RepositorySession session, String repoId, String namespace )
throws MetadataResolutionException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
return null;
}
public Collection<String> resolveProjectVersions( RepositorySession session, String repoId, String namespace,
String projectId )
throws MetadataResolutionException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
return null;
}
public Collection<ArtifactMetadata> resolveArtifacts( RepositorySession session, String repoId, String namespace,
String projectId, String projectVersion )
throws MetadataResolutionException
{
return null; //To change body of implemented methods use File | Settings | File Templates.
return null;
}
}

View File

@ -20,6 +20,7 @@ package org.apache.archiva.metadata.repository.storage.maven2;
*/
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.repository.AbstractRepositoryLayerTestCase;
import org.apache.archiva.repository.layout.LayoutException;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.lang.StringUtils;
@ -33,7 +34,7 @@ import static org.junit.Assert.*;
* AbstractDefaultRepositoryContentTestCase
*/
@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-no-mock-conf.xml" } )
public abstract class AbstractDefaultRepositoryContentTestCase
extends AbstractRepositoryLayerTestCase
{

View File

@ -20,6 +20,7 @@ package org.apache.archiva.metadata.repository.storage.maven2;
*/
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.repository.AbstractRepositoryLayerTestCase;
import org.apache.archiva.repository.layout.LayoutException;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.junit.Test;
@ -32,10 +33,11 @@ import static org.junit.Assert.*;
* AbstractLegacyRepositoryContentTestCase
*/
@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-no-mock-conf.xml" } )
public abstract class AbstractLegacyRepositoryContentTestCase
extends AbstractRepositoryLayerTestCase
{
@Test
public void testBadPathArtifactIdMissingA()
{
@ -48,6 +50,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase
assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" );
}
@Test
public void testBadPathMissingType()
{
@ -61,6 +64,7 @@ public abstract class AbstractLegacyRepositoryContentTestCase
assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
}
@Test
public void testBadPathWrongPackageExtension()
{

View File

@ -1,101 +0,0 @@
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 org.apache.archiva.admin.model.beans.ManagedRepository;
import org.apache.archiva.admin.model.beans.RemoteRepository;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.RemoteRepositoryContent;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.junit.Rule;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import javax.inject.Inject;
import java.io.File;
/**
* AbstractRepositoryLayerTestCase
*
*
*/
@RunWith( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
public abstract class AbstractRepositoryLayerTestCase
{
@Rule
public TestName name = new TestName();
@Inject
protected ApplicationContext applicationContext;
protected ManagedRepository createRepository( String id, String name, File location )
{
ManagedRepository repo = new ManagedRepository();
repo.setId( id );
repo.setName( name );
repo.setLocation( location.getAbsolutePath() );
return repo;
}
protected RemoteRepository createRemoteRepository( String id, String name, String url )
{
RemoteRepository repo = new RemoteRepository();
repo.setId( id );
repo.setName( name );
repo.setUrl( url );
return repo;
}
protected ManagedRepositoryContent createManagedRepositoryContent( String id, String name, File location,
String layout )
throws Exception
{
ManagedRepository repo = new ManagedRepository();
repo.setId( id );
repo.setName( name );
repo.setLocation( location.getAbsolutePath() );
repo.setLayout( layout );
ManagedRepositoryContent repoContent =
applicationContext.getBean( "managedRepositoryContent#" + layout, ManagedRepositoryContent.class );
repoContent.setRepository( repo );
return repoContent;
}
protected RemoteRepositoryContent createRemoteRepositoryContent( String id, String name, String url, String layout )
throws Exception
{
RemoteRepository repo = new RemoteRepository();
repo.setId( id );
repo.setName( name );
repo.setUrl( url );
repo.setLayout( layout );
RemoteRepositoryContent repoContent =
applicationContext.getBean( "remoteRepositoryContent#" + layout, RemoteRepositoryContent.class );
repoContent.setRepository( repo );
return repoContent;
}
}

View File

@ -50,8 +50,6 @@ import static org.junit.Assert.fail;
/**
* ManagedDefaultRepositoryContentTest
*/
@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
public class ManagedDefaultRepositoryContentTest
extends AbstractDefaultRepositoryContentTestCase
{

View File

@ -47,8 +47,6 @@ import static org.junit.Assert.*;
*
*
*/
@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
public class ManagedLegacyRepositoryContentTest
extends AbstractDefaultRepositoryContentTestCase
{

View File

@ -56,8 +56,10 @@ import java.util.List;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith (ArchivaSpringJUnit4ClassRunner.class)
@ContextConfiguration (locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration (
locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-no-mock-conf.xml" } )
public class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest
extends TestCase
{
@ -92,6 +94,7 @@ public class Maven2RepositoryMetadataResolverMRM1411RepoGroupTest
private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
@Inject
@Named (value = "archivaConfiguration#default")
private ArchivaConfiguration configuration;
private WagonFactory wagonFactory;

View File

@ -58,14 +58,15 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
@ContextConfiguration (
locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-no-mock-conf.xml" } )
public class Maven2RepositoryMetadataResolverMRM1411Test
extends TestCase
{
private static final Filter<String> ALL = new AllFilter<String>();
@Inject
@Named ( value = "repositoryStorage#maven2" )
@Named (value = "repositoryStorage#maven2")
private Maven2RepositoryStorage storage;
private static final String TEST_REPO_ID = "test";
@ -89,6 +90,7 @@ public class Maven2RepositoryMetadataResolverMRM1411Test
private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
@Inject
@Named (value = "archivaConfiguration#default")
private ArchivaConfiguration configuration;
private WagonFactory wagonFactory;

View File

@ -19,32 +19,26 @@ package org.apache.archiva.metadata.repository.storage.maven2;
* under the License.
*/
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.ReadMetadataRequest;
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;
import javax.inject.Inject;
import javax.inject.Named;
@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" )
@Named (value = "repositoryStorage#maven2")
private Maven2RepositoryStorage storage;
private static final String TEST_REPO_ID = "test";
@ -67,9 +61,6 @@ public class Maven2RepositoryMetadataResolverManagedReleaseTest
private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
@Inject
private ArchivaConfiguration configuration;
private WagonFactory wagonFactory;
@Before
@ -103,7 +94,7 @@ public class Maven2RepositoryMetadataResolverManagedReleaseTest
ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
}
@Test ( expected = RepositoryStorageRuntimeException.class )
@Test (expected = RepositoryStorageRuntimeException.class)
@Override
public void testGetProjectVersionMetadataForTimestampedSnapshotMissingMetadata()
throws Exception
@ -114,7 +105,7 @@ public class Maven2RepositoryMetadataResolverManagedReleaseTest
storage.readProjectVersionMetadata( readMetadataRequest );
}
@Test ( expected = RepositoryStorageRuntimeException.class )
@Test (expected = RepositoryStorageRuntimeException.class)
@Override
public void testGetProjectVersionMetadataForTimestampedSnapshotMalformedMetadata()
throws Exception
@ -125,7 +116,7 @@ public class Maven2RepositoryMetadataResolverManagedReleaseTest
storage.readProjectVersionMetadata( readMetadataRequest );
}
@Test ( expected = RepositoryStorageRuntimeException.class )
@Test (expected = RepositoryStorageRuntimeException.class)
@Override
public void testGetProjectVersionMetadataForTimestampedSnapshot()
throws Exception
@ -134,7 +125,7 @@ public class Maven2RepositoryMetadataResolverManagedReleaseTest
}
@Test ( expected = RepositoryStorageRuntimeException.class )
@Test (expected = RepositoryStorageRuntimeException.class)
@Override
public void testGetProjectVersionMetadataForTimestampedSnapshotIncompleteMetadata()
throws Exception

View File

@ -19,7 +19,6 @@ package org.apache.archiva.metadata.repository.storage.maven2;
* under the License.
*/
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;
@ -34,16 +33,16 @@ import org.springframework.test.context.ContextConfiguration;
import javax.inject.Inject;
import javax.inject.Named;
@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
@ContextConfiguration (
locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-no-mock-conf.xml" } )
public class Maven2RepositoryMetadataResolverManagedSnapshotTest
extends Maven2RepositoryMetadataResolverTest
{
private static final Filter<String> ALL = new AllFilter<String>();
@Inject
@Named ( value = "repositoryStorage#maven2" )
@Named (value = "repositoryStorage#maven2")
private Maven2RepositoryStorage storage;
private static final String TEST_REPO_ID = "test";
@ -64,10 +63,8 @@ public class Maven2RepositoryMetadataResolverManagedSnapshotTest
private static final String EMPTY_MD5 = "d41d8cd98f00b204e9800998ecf8427e";
private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
@Inject
private ArchivaConfiguration configuration;
private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
@Before
@ -86,7 +83,7 @@ public class Maven2RepositoryMetadataResolverManagedSnapshotTest
assertFalse( c.getManagedRepositories().get( 0 ).isReleases() );
}
@Test ( expected = RepositoryStorageRuntimeException.class )
@Test (expected = RepositoryStorageRuntimeException.class)
@Override
public void testModelWithJdkProfileActivation()
throws Exception
@ -100,7 +97,7 @@ public class Maven2RepositoryMetadataResolverManagedSnapshotTest
ProjectVersionMetadata metadata = storage.readProjectVersionMetadata( readMetadataRequest );
}
@Test ( expected = RepositoryStorageRuntimeException.class )
@Test (expected = RepositoryStorageRuntimeException.class)
@Override
public void testGetProjectVersionMetadataForMislocatedPom()
throws Exception
@ -120,7 +117,7 @@ public class Maven2RepositoryMetadataResolverManagedSnapshotTest
// super test is on release
}
@Test ( expected = RepositoryStorageRuntimeException.class )
@Test (expected = RepositoryStorageRuntimeException.class)
@Override
public void testGetProjectVersionMetadataForInvalidPom()
throws Exception
@ -131,7 +128,7 @@ public class Maven2RepositoryMetadataResolverManagedSnapshotTest
storage.readProjectVersionMetadata( readMetadataRequest );
}
@Test ( expected = RepositoryStorageRuntimeException.class )
@Test (expected = RepositoryStorageRuntimeException.class)
@Override
public void testGetProjectVersionMetadataForMissingPom()
throws Exception

View File

@ -62,15 +62,16 @@ import java.util.List;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
@RunWith (ArchivaSpringJUnit4ClassRunner.class)
@ContextConfiguration (
locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-no-mock-conf.xml" })
public class Maven2RepositoryMetadataResolverTest
extends TestCase
{
private static final Filter<String> ALL = new AllFilter<String>();
@Inject
@Named ( value = "repositoryStorage#maven2" )
@Named (value = "repositoryStorage#maven2")
private Maven2RepositoryStorage storage;
private static final String TEST_REPO_ID = "test";
@ -94,7 +95,8 @@ public class Maven2RepositoryMetadataResolverTest
private static final String EMPTY_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
@Inject
private ArchivaConfiguration configuration;
@Named ( value = "archivaConfiguration#default" )
protected ArchivaConfiguration configuration;
private WagonFactory wagonFactory;

View File

@ -34,8 +34,6 @@ import javax.inject.Named;
/**
* RemoteDefaultRepositoryContentTest
*/
@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
public class RemoteDefaultRepositoryContentTest
extends AbstractDefaultRepositoryContentTestCase
{

View File

@ -41,7 +41,7 @@ import static org.junit.Assert.*;
*
*/
@RunWith ( ArchivaSpringJUnit4ClassRunner.class )
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-no-mock-conf.xml" } )
public class LegacyPathParserTest
{
private LegacyPathParser parser;

View File

@ -16,7 +16,7 @@
-->
<!--+
| This is the main Maven file that contains all global settings, management and information.
| @version $Id$
| @version $Id: cocoon-1.pom 580582 2007-09-29 13:37:01Z joakime $
+-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

View File

@ -27,7 +27,8 @@
http://www.springframework.org/schema/context/spring-context-3.0.xsd"
default-lazy-init="true">
<bean name="archivaConfiguration#mock" class="org.apache.archiva.repository.MockConfiguration"/>
<alias name="archivaConfiguration#mock" alias="archivaConfiguration#default"/>
<bean name="metadataTools#test" class="org.apache.archiva.repository.metadata.MetadataTools">
<property name="configuration" ref="archivaConfiguration#mock"/>
</bean>

View File

@ -25,6 +25,6 @@
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<alias name="archivaConfiguration#mock" alias="archivaConfiguration#default"/>
<alias name="archivaConfiguration#mock" alias="archivaConfiguration#test"/>
</beans>