Browse Source

compilation fix

tags/archiva-2.2.1
Olivier Lamy 8 years ago
parent
commit
6be428cd2d

+ 100
- 79
archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java View File

import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; import org.apache.archiva.consumers.InvalidRepositoryContentConsumer;
import org.apache.archiva.consumers.KnownRepositoryContentConsumer; import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import org.apache.commons.lang.SystemUtils; import org.apache.commons.lang.SystemUtils;
import org.easymock.IMocksControl; import org.easymock.IMocksControl;
import org.junit.Test; import org.junit.Test;
import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEvent;
import org.springframework.context.MessageSourceResolvable; import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.NoSuchMessageException; import org.springframework.context.NoSuchMessageException;
import org.springframework.core.ResolvableType;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource; import org.springframework.core.io.Resource;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
import static org.easymock.EasyMock.*; import static org.easymock.EasyMock.*;


/** /**
* RepositoryContentConsumersTest * RepositoryContentConsumersTest
*
*
*/ */
@RunWith( ArchivaSpringJUnit4ClassRunner.class ) @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.xml" } )


protected ManagedRepository createRepository( String id, String name, File location ) protected ManagedRepository createRepository( String id, String name, File location )
{ {
ManagedRepository repo = new ManagedRepository( );
ManagedRepository repo = new ManagedRepository();
repo.setId( id ); repo.setId( id );
repo.setName( name ); repo.setName( name );
repo.setLocation( location.getAbsolutePath( ) );
repo.setLocation( location.getAbsolutePath() );
return repo; return repo;
} }


protected RemoteRepository createRemoteRepository( String id, String name, String url ) protected RemoteRepository createRemoteRepository( String id, String name, String url )
{ {
RemoteRepository repo = new RemoteRepository( );
RemoteRepository repo = new RemoteRepository();
repo.setId( id ); repo.setId( id );
repo.setName( name ); repo.setName( name );
repo.setUrl( url ); repo.setUrl( url );
return repo; return repo;
} }


private RepositoryContentConsumers lookupRepositoryConsumers( )
private RepositoryContentConsumers lookupRepositoryConsumers()
throws Exception throws Exception
{ {




RepositoryContentConsumers consumerUtil = RepositoryContentConsumers consumerUtil =
applicationContext.getBean( "repositoryContentConsumers#test", RepositoryContentConsumers.class ); applicationContext.getBean( "repositoryContentConsumers#test", RepositoryContentConsumers.class );
ApplicationContext context = new MockApplicationContext( consumerUtil.getAvailableKnownConsumers( ), //
consumerUtil.getAvailableInvalidConsumers( ) );
ApplicationContext context = new MockApplicationContext( consumerUtil.getAvailableKnownConsumers(), //
consumerUtil.getAvailableInvalidConsumers() );


consumerUtilStub.setApplicationContext( context ); consumerUtilStub.setApplicationContext( context );
consumerUtilStub.setSelectedInvalidConsumers( consumerUtil.getSelectedInvalidConsumers( ) );
consumerUtilStub.setSelectedKnownConsumers( consumerUtil.getSelectedKnownConsumers( ) );
consumerUtilStub.setSelectedInvalidConsumers( consumerUtil.getSelectedInvalidConsumers() );
consumerUtilStub.setSelectedKnownConsumers( consumerUtil.getSelectedKnownConsumers() );
consumerUtilStub.setArchivaAdministration( administrationStub ); consumerUtilStub.setArchivaAdministration( administrationStub );


assertNotNull( "RepositoryContentConsumers should not be null.", consumerUtilStub ); assertNotNull( "RepositoryContentConsumers should not be null.", consumerUtilStub );
} }


@Test @Test
public void testGetSelectedKnownIds( )
public void testGetSelectedKnownIds()
throws Exception throws Exception
{ {
RepositoryContentConsumers consumerutil = lookupRepositoryConsumers( );
RepositoryContentConsumers consumerutil = lookupRepositoryConsumers();


String expectedKnownIds[] = String expectedKnownIds[] =
new String[]{ "create-missing-checksums", "validate-checksum", "validate-signature", "index-content", new String[]{ "create-missing-checksums", "validate-checksum", "validate-signature", "index-content",
//update-db-artifact, create-missing-checksums, update-db-repository-metadata, //update-db-artifact, create-missing-checksums, update-db-repository-metadata,
//validate-checksum, validate-signature, index-content, auto-remove, auto-rename, //validate-checksum, validate-signature, index-content, auto-remove, auto-rename,
//metadata-updater //metadata-updater
List<String> knownConsumers = consumerutil.getSelectedKnownConsumerIds( );
List<String> knownConsumers = consumerutil.getSelectedKnownConsumerIds();
assertNotNull( "Known Consumer IDs should not be null", knownConsumers ); assertNotNull( "Known Consumer IDs should not be null", knownConsumers );
assertEquals( "Known Consumer IDs.size " + knownConsumers, expectedKnownIds.length, knownConsumers.size( ) );
assertEquals( "Known Consumer IDs.size " + knownConsumers, expectedKnownIds.length, knownConsumers.size() );


for ( String expectedId : expectedKnownIds ) for ( String expectedId : expectedKnownIds )
{ {
} }


@Test @Test
public void testGetSelectedInvalidIds( )
public void testGetSelectedInvalidIds()
throws Exception throws Exception
{ {
RepositoryContentConsumers consumerutil = lookupRepositoryConsumers( );
RepositoryContentConsumers consumerutil = lookupRepositoryConsumers();


String expectedInvalidIds[] = new String[]{ "update-db-bad-content" }; String expectedInvalidIds[] = new String[]{ "update-db-bad-content" };


List<String> invalidConsumers = consumerutil.getSelectedInvalidConsumerIds( );
List<String> invalidConsumers = consumerutil.getSelectedInvalidConsumerIds();
assertNotNull( "Invalid Consumer IDs should not be null", invalidConsumers ); assertNotNull( "Invalid Consumer IDs should not be null", invalidConsumers );
assertEquals( "Invalid Consumer IDs.size", expectedInvalidIds.length, invalidConsumers.size( ) );
assertEquals( "Invalid Consumer IDs.size", expectedInvalidIds.length, invalidConsumers.size() );


for ( String expectedId : expectedInvalidIds ) for ( String expectedId : expectedInvalidIds )
{ {
} }


@Test @Test
public void testGetSelectedKnownConsumerMap( )
public void testGetSelectedKnownConsumerMap()
throws Exception throws Exception
{ {
RepositoryContentConsumers consumerutil = lookupRepositoryConsumers( );
RepositoryContentConsumers consumerutil = lookupRepositoryConsumers();


String expectedSelectedKnownIds[] = String expectedSelectedKnownIds[] =
new String[]{ "create-missing-checksums", "validate-checksum", "index-content", "auto-remove", new String[]{ "create-missing-checksums", "validate-checksum", "index-content", "auto-remove",
"auto-rename" }; "auto-rename" };


Map<String, KnownRepositoryContentConsumer> knownConsumerMap = consumerutil.getSelectedKnownConsumersMap( );
Map<String, KnownRepositoryContentConsumer> knownConsumerMap = consumerutil.getSelectedKnownConsumersMap();
assertNotNull( "Known Consumer Map should not be null", knownConsumerMap ); assertNotNull( "Known Consumer Map should not be null", knownConsumerMap );
assertEquals( "Known Consumer Map.size but " + knownConsumerMap, expectedSelectedKnownIds.length, assertEquals( "Known Consumer Map.size but " + knownConsumerMap, expectedSelectedKnownIds.length,
knownConsumerMap.size( ) );
knownConsumerMap.size() );


for ( String expectedId : expectedSelectedKnownIds ) for ( String expectedId : expectedSelectedKnownIds )
{ {
KnownRepositoryContentConsumer consumer = knownConsumerMap.get( expectedId ); KnownRepositoryContentConsumer consumer = knownConsumerMap.get( expectedId );
assertNotNull( "Known[" + expectedId + "] should not be null.", consumer ); assertNotNull( "Known[" + expectedId + "] should not be null.", consumer );
assertEquals( "Known[" + expectedId + "].id", expectedId, consumer.getId( ) );
assertEquals( "Known[" + expectedId + "].id", expectedId, consumer.getId() );
} }
} }


@Test @Test
public void testGetSelectedInvalidConsumerMap( )
public void testGetSelectedInvalidConsumerMap()
throws Exception throws Exception
{ {
RepositoryContentConsumers consumerutil = lookupRepositoryConsumers( );
RepositoryContentConsumers consumerutil = lookupRepositoryConsumers();


String expectedSelectedInvalidIds[] = new String[]{ "update-db-bad-content" }; String expectedSelectedInvalidIds[] = new String[]{ "update-db-bad-content" };


Map<String, InvalidRepositoryContentConsumer> invalidConsumerMap = Map<String, InvalidRepositoryContentConsumer> invalidConsumerMap =
consumerutil.getSelectedInvalidConsumersMap( );
consumerutil.getSelectedInvalidConsumersMap();
assertNotNull( "Invalid Consumer Map should not be null", invalidConsumerMap ); assertNotNull( "Invalid Consumer Map should not be null", invalidConsumerMap );
assertEquals( "Invalid Consumer Map.size", expectedSelectedInvalidIds.length, invalidConsumerMap.size( ) );
assertEquals( "Invalid Consumer Map.size", expectedSelectedInvalidIds.length, invalidConsumerMap.size() );


for ( String expectedId : expectedSelectedInvalidIds ) for ( String expectedId : expectedSelectedInvalidIds )
{ {
InvalidRepositoryContentConsumer consumer = invalidConsumerMap.get( expectedId ); InvalidRepositoryContentConsumer consumer = invalidConsumerMap.get( expectedId );
assertNotNull( "Known[" + expectedId + "] should not be null.", consumer ); assertNotNull( "Known[" + expectedId + "] should not be null.", consumer );
assertEquals( "Known[" + expectedId + "].id", expectedId, consumer.getId( ) );
assertEquals( "Known[" + expectedId + "].id", expectedId, consumer.getId() );
} }
} }


@Test @Test
public void testGetAvailableKnownList( )
public void testGetAvailableKnownList()
throws Exception throws Exception
{ {
RepositoryContentConsumers consumerutil = lookupRepositoryConsumers( );
RepositoryContentConsumers consumerutil = lookupRepositoryConsumers();


String expectedKnownIds[] = String expectedKnownIds[] =
new String[]{ "update-db-artifact", "create-missing-checksums", "update-db-repository-metadata", new String[]{ "update-db-artifact", "create-missing-checksums", "update-db-repository-metadata",
"validate-checksum", "index-content", "auto-remove", "auto-rename", "available-but-unselected" }; "validate-checksum", "index-content", "auto-remove", "auto-rename", "available-but-unselected" };


List<KnownRepositoryContentConsumer> knownConsumers = consumerutil.getAvailableKnownConsumers( );
List<KnownRepositoryContentConsumer> knownConsumers = consumerutil.getAvailableKnownConsumers();
assertNotNull( "known consumers should not be null.", knownConsumers ); assertNotNull( "known consumers should not be null.", knownConsumers );
assertEquals( "known consumers", expectedKnownIds.length, knownConsumers.size( ) );
assertEquals( "known consumers", expectedKnownIds.length, knownConsumers.size() );


List<String> expectedIds = Arrays.asList( expectedKnownIds ); List<String> expectedIds = Arrays.asList( expectedKnownIds );
for ( KnownRepositoryContentConsumer consumer : knownConsumers ) for ( KnownRepositoryContentConsumer consumer : knownConsumers )
{ {
assertTrue( "Consumer [" + consumer.getId( ) + "] returned by .getAvailableKnownConsumers() is unexpected.",
expectedIds.contains( consumer.getId( ) ) );
assertTrue( "Consumer [" + consumer.getId() + "] returned by .getAvailableKnownConsumers() is unexpected.",
expectedIds.contains( consumer.getId() ) );
} }
} }


@Test @Test
public void testGetAvailableInvalidList( )
public void testGetAvailableInvalidList()
throws Exception throws Exception
{ {
RepositoryContentConsumers consumerutil = lookupRepositoryConsumers( );
RepositoryContentConsumers consumerutil = lookupRepositoryConsumers();


String expectedInvalidIds[] = new String[]{ "update-db-bad-content", "move-to-trash-then-notify" }; String expectedInvalidIds[] = new String[]{ "update-db-bad-content", "move-to-trash-then-notify" };


List<InvalidRepositoryContentConsumer> invalidConsumers = consumerutil.getAvailableInvalidConsumers( );
List<InvalidRepositoryContentConsumer> invalidConsumers = consumerutil.getAvailableInvalidConsumers();
assertNotNull( "invalid consumers should not be null.", invalidConsumers ); assertNotNull( "invalid consumers should not be null.", invalidConsumers );
assertEquals( "invalid consumers", expectedInvalidIds.length, invalidConsumers.size( ) );
assertEquals( "invalid consumers", expectedInvalidIds.length, invalidConsumers.size() );


List<String> expectedIds = Arrays.asList( expectedInvalidIds ); List<String> expectedIds = Arrays.asList( expectedInvalidIds );
for ( InvalidRepositoryContentConsumer consumer : invalidConsumers ) for ( InvalidRepositoryContentConsumer consumer : invalidConsumers )
{ {
assertTrue( assertTrue(
"Consumer [" + consumer.getId( ) + "] returned by .getAvailableInvalidConsumers() is unexpected.",
expectedIds.contains( consumer.getId( ) ) );
"Consumer [" + consumer.getId() + "] returned by .getAvailableInvalidConsumers() is unexpected.",
expectedIds.contains( consumer.getId() ) );
} }
} }


@Test @Test
public void testExecution( )
public void testExecution()
throws Exception throws Exception
{ {
IMocksControl knownControl = createNiceControl( );

RepositoryContentConsumers consumers = lookupRepositoryConsumers( );
KnownRepositoryContentConsumer selectedKnownConsumer = knownControl.createMock( KnownRepositoryContentConsumer.class );
IMocksControl knownControl = createNiceControl();


KnownRepositoryContentConsumer unselectedKnownConsumer = createNiceControl().createMock( KnownRepositoryContentConsumer.class );
RepositoryContentConsumers consumers = lookupRepositoryConsumers();
KnownRepositoryContentConsumer selectedKnownConsumer =
knownControl.createMock( KnownRepositoryContentConsumer.class );


KnownRepositoryContentConsumer unselectedKnownConsumer =
createNiceControl().createMock( KnownRepositoryContentConsumer.class );


consumers.setApplicationContext( consumers.setApplicationContext(
new MockApplicationContext( Arrays.asList( selectedKnownConsumer, unselectedKnownConsumer ), null ) ); new MockApplicationContext( Arrays.asList( selectedKnownConsumer, unselectedKnownConsumer ), null ) );


IMocksControl invalidControl = createControl(); IMocksControl invalidControl = createControl();


InvalidRepositoryContentConsumer selectedInvalidConsumer = invalidControl.createMock( InvalidRepositoryContentConsumer.class );
InvalidRepositoryContentConsumer selectedInvalidConsumer =
invalidControl.createMock( InvalidRepositoryContentConsumer.class );


InvalidRepositoryContentConsumer unselectedInvalidConsumer = createControl().createMock( InvalidRepositoryContentConsumer.class );
InvalidRepositoryContentConsumer unselectedInvalidConsumer =
createControl().createMock( InvalidRepositoryContentConsumer.class );


consumers.setApplicationContext( consumers.setApplicationContext(
new MockApplicationContext( null, Arrays.asList( selectedInvalidConsumer, unselectedInvalidConsumer ) ) ); new MockApplicationContext( null, Arrays.asList( selectedInvalidConsumer, unselectedInvalidConsumer ) ) );
ManagedRepository repo = createRepository( "id", "name", new File( "target/test-repo" ) ); ManagedRepository repo = createRepository( "id", "name", new File( "target/test-repo" ) );
File testFile = new File( "target/test-repo/path/to/test-file.txt" ); File testFile = new File( "target/test-repo/path/to/test-file.txt" );


Date startTime = new Date( System.currentTimeMillis( ) );
Date startTime = new Date( System.currentTimeMillis() );
startTime.setTime( 12345678 ); startTime.setTime( 12345678 );


selectedKnownConsumer.beginScan( repo, startTime, false ); selectedKnownConsumer.beginScan( repo, startTime, false );
expect( selectedKnownConsumer.getIncludes( ) ).andReturn( Collections.singletonList( "**/*.txt" ) );
expect( selectedKnownConsumer.getIncludes() ).andReturn( Collections.singletonList( "**/*.txt" ) );
selectedKnownConsumer.processFile( _OS( "path/to/test-file.txt" ), false ); selectedKnownConsumer.processFile( _OS( "path/to/test-file.txt" ), false );


knownControl.replay( );
knownControl.replay();


selectedInvalidConsumer.beginScan( repo, startTime, false ); selectedInvalidConsumer.beginScan( repo, startTime, false );
invalidControl.replay( );

invalidControl.replay();


consumers.executeConsumers( repo, testFile, true ); consumers.executeConsumers( repo, testFile, true );


knownControl.verify( );
invalidControl.verify( );
knownControl.verify();
invalidControl.verify();


knownControl.reset( );
invalidControl.reset( );
knownControl.reset();
invalidControl.reset();


File notIncludedTestFile = new File( "target/test-repo/path/to/test-file.xml" ); File notIncludedTestFile = new File( "target/test-repo/path/to/test-file.xml" );


selectedKnownConsumer.beginScan( repo, startTime, false ); selectedKnownConsumer.beginScan( repo, startTime, false );
expect( selectedKnownConsumer.getExcludes() ).andReturn( Collections.<String>emptyList() ); expect( selectedKnownConsumer.getExcludes() ).andReturn( Collections.<String>emptyList() );


expect( selectedKnownConsumer.getIncludes( ) ).andReturn( Collections.singletonList( "**/*.txt" ) );
expect( selectedKnownConsumer.getIncludes() ).andReturn( Collections.singletonList( "**/*.txt" ) );


knownControl.replay( );
knownControl.replay();


selectedInvalidConsumer.beginScan( repo, startTime, false ); selectedInvalidConsumer.beginScan( repo, startTime, false );
selectedInvalidConsumer.processFile( _OS( "path/to/test-file.xml" ), false ); selectedInvalidConsumer.processFile( _OS( "path/to/test-file.xml" ), false );
expect( selectedInvalidConsumer.getId() ).andReturn( "invalid" ); expect( selectedInvalidConsumer.getId() ).andReturn( "invalid" );
invalidControl.replay( );
invalidControl.replay();


consumers.executeConsumers( repo, notIncludedTestFile, true ); consumers.executeConsumers( repo, notIncludedTestFile, true );


knownControl.verify( );
invalidControl.verify( );
knownControl.verify();
invalidControl.verify();


knownControl.reset( );
invalidControl.reset( );
knownControl.reset();
invalidControl.reset();


File excludedTestFile = new File( "target/test-repo/path/to/test-file.txt" ); File excludedTestFile = new File( "target/test-repo/path/to/test-file.txt" );


selectedKnownConsumer.beginScan( repo, startTime, false ); selectedKnownConsumer.beginScan( repo, startTime, false );
expect( selectedKnownConsumer.getExcludes() ).andReturn( Collections.singletonList( "**/test-file.txt" ) ); expect( selectedKnownConsumer.getExcludes() ).andReturn( Collections.singletonList( "**/test-file.txt" ) );
knownControl.replay( );
knownControl.replay();


selectedInvalidConsumer.beginScan( repo, startTime, false ); selectedInvalidConsumer.beginScan( repo, startTime, false );
selectedInvalidConsumer.processFile( _OS( "path/to/test-file.txt" ), false ); selectedInvalidConsumer.processFile( _OS( "path/to/test-file.txt" ), false );
expect( selectedInvalidConsumer.getId() ).andReturn( "invalid" ); expect( selectedInvalidConsumer.getId() ).andReturn( "invalid" );
invalidControl.replay( );
invalidControl.replay();


consumers.executeConsumers( repo, excludedTestFile, true ); consumers.executeConsumers( repo, excludedTestFile, true );


knownControl.verify( );
invalidControl.verify( );
knownControl.verify();
invalidControl.verify();
} }


/** /**


private static Map convertToMap( List objects ) private static Map convertToMap( List objects )
{ {
HashMap map = new HashMap( );
HashMap map = new HashMap();
for ( Object o : objects ) for ( Object o : objects )
{ {
map.put( o, o ); map.put( o, o );
} }


@Override @Override
public AutowireCapableBeanFactory getAutowireCapableBeanFactory( )
public AutowireCapableBeanFactory getAutowireCapableBeanFactory()
throws IllegalStateException throws IllegalStateException
{ {
throw new UnsupportedOperationException( "Not supported yet." ); throw new UnsupportedOperationException( "Not supported yet." );
} }


@Override @Override
public String getDisplayName( )
public String getDisplayName()
{ {
throw new UnsupportedOperationException( "Not supported yet." ); throw new UnsupportedOperationException( "Not supported yet." );
} }


@Override @Override
public String getId( )
public String getId()
{ {
throw new UnsupportedOperationException( "Not supported yet." ); throw new UnsupportedOperationException( "Not supported yet." );
} }


@Override @Override
public ApplicationContext getParent( )
public ApplicationContext getParent()
{ {
throw new UnsupportedOperationException( "Not supported yet." ); throw new UnsupportedOperationException( "Not supported yet." );
} }


@Override @Override
public long getStartupDate( )
public long getStartupDate()
{ {
throw new UnsupportedOperationException( "Not supported yet." ); throw new UnsupportedOperationException( "Not supported yet." );
} }
} }


@Override @Override
public int getBeanDefinitionCount( )
public int getBeanDefinitionCount()
{ {
throw new UnsupportedOperationException( "Not supported yet." ); throw new UnsupportedOperationException( "Not supported yet." );
} }


@Override @Override
public String[] getBeanDefinitionNames( )
public String[] getBeanDefinitionNames()
{ {
throw new UnsupportedOperationException( "Not supported yet." ); throw new UnsupportedOperationException( "Not supported yet." );
} }
} }


@Override @Override
public BeanFactory getParentBeanFactory( )
public BeanFactory getParentBeanFactory()
{ {
throw new UnsupportedOperationException( "Not supported yet." ); throw new UnsupportedOperationException( "Not supported yet." );
} }
} }


@Override @Override
public ClassLoader getClassLoader( )
public ClassLoader getClassLoader()
{ {
throw new UnsupportedOperationException( "Not supported yet." ); throw new UnsupportedOperationException( "Not supported yet." );
} }
{ {
return new String[0]; return new String[0];
} }

@Override
public void publishEvent( Object o )
{
// no op
}

@Override
public String[] getBeanNamesForType( ResolvableType resolvableType )
{
return new String[0];
}

@Override
public boolean isTypeMatch( String s, ResolvableType resolvableType )
throws NoSuchBeanDefinitionException
{
return false;
}
} }
} }

Loading…
Cancel
Save