From 6be428cd2d0790ebd203be12c306bd8441437f0f Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 25 Sep 2015 15:25:51 +1000 Subject: [PATCH] compilation fix --- .../RepositoryContentConsumersTest.java | 179 ++++++++++-------- 1 file changed, 100 insertions(+), 79 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java index 07176cdf9..db981234a 100644 --- a/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java +++ b/archiva-modules/archiva-base/archiva-repository-scanner/src/test/java/org/apache/archiva/repository/scanner/RepositoryContentConsumersTest.java @@ -25,6 +25,7 @@ import org.apache.archiva.admin.model.beans.RemoteRepository; import org.apache.archiva.configuration.ArchivaConfiguration; import org.apache.archiva.consumers.InvalidRepositoryContentConsumer; import org.apache.archiva.consumers.KnownRepositoryContentConsumer; +import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; import org.apache.commons.lang.SystemUtils; import org.easymock.IMocksControl; import org.junit.Test; @@ -37,6 +38,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationEvent; import org.springframework.context.MessageSourceResolvable; import org.springframework.context.NoSuchMessageException; +import org.springframework.core.ResolvableType; import org.springframework.core.env.Environment; import org.springframework.core.io.Resource; import org.springframework.test.context.ContextConfiguration; @@ -52,13 +54,11 @@ import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; -import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner; + import static org.easymock.EasyMock.*; /** * RepositoryContentConsumersTest - * - * */ @RunWith( ArchivaSpringJUnit4ClassRunner.class ) @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } ) @@ -71,23 +71,23 @@ public class RepositoryContentConsumersTest protected ManagedRepository createRepository( String id, String name, File location ) { - ManagedRepository repo = new ManagedRepository( ); + ManagedRepository repo = new ManagedRepository(); repo.setId( id ); repo.setName( name ); - repo.setLocation( location.getAbsolutePath( ) ); + repo.setLocation( location.getAbsolutePath() ); return repo; } protected RemoteRepository createRemoteRepository( String id, String name, String url ) { - RemoteRepository repo = new RemoteRepository( ); + RemoteRepository repo = new RemoteRepository(); repo.setId( id ); repo.setName( name ); repo.setUrl( url ); return repo; } - private RepositoryContentConsumers lookupRepositoryConsumers( ) + private RepositoryContentConsumers lookupRepositoryConsumers() throws Exception { @@ -100,12 +100,12 @@ public class RepositoryContentConsumersTest RepositoryContentConsumers consumerUtil = 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.setSelectedInvalidConsumers( consumerUtil.getSelectedInvalidConsumers( ) ); - consumerUtilStub.setSelectedKnownConsumers( consumerUtil.getSelectedKnownConsumers( ) ); + consumerUtilStub.setSelectedInvalidConsumers( consumerUtil.getSelectedInvalidConsumers() ); + consumerUtilStub.setSelectedKnownConsumers( consumerUtil.getSelectedKnownConsumers() ); consumerUtilStub.setArchivaAdministration( administrationStub ); assertNotNull( "RepositoryContentConsumers should not be null.", consumerUtilStub ); @@ -114,10 +114,10 @@ public class RepositoryContentConsumersTest } @Test - public void testGetSelectedKnownIds( ) + public void testGetSelectedKnownIds() throws Exception { - RepositoryContentConsumers consumerutil = lookupRepositoryConsumers( ); + RepositoryContentConsumers consumerutil = lookupRepositoryConsumers(); String expectedKnownIds[] = new String[]{ "create-missing-checksums", "validate-checksum", "validate-signature", "index-content", @@ -125,9 +125,9 @@ public class RepositoryContentConsumersTest //update-db-artifact, create-missing-checksums, update-db-repository-metadata, //validate-checksum, validate-signature, index-content, auto-remove, auto-rename, //metadata-updater - List knownConsumers = consumerutil.getSelectedKnownConsumerIds( ); + List knownConsumers = consumerutil.getSelectedKnownConsumerIds(); 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 ) { @@ -136,16 +136,16 @@ public class RepositoryContentConsumersTest } @Test - public void testGetSelectedInvalidIds( ) + public void testGetSelectedInvalidIds() throws Exception { - RepositoryContentConsumers consumerutil = lookupRepositoryConsumers( ); + RepositoryContentConsumers consumerutil = lookupRepositoryConsumers(); String expectedInvalidIds[] = new String[]{ "update-db-bad-content" }; - List invalidConsumers = consumerutil.getSelectedInvalidConsumerIds( ); + List invalidConsumers = consumerutil.getSelectedInvalidConsumerIds(); 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 ) { @@ -154,103 +154,104 @@ public class RepositoryContentConsumersTest } @Test - public void testGetSelectedKnownConsumerMap( ) + public void testGetSelectedKnownConsumerMap() throws Exception { - RepositoryContentConsumers consumerutil = lookupRepositoryConsumers( ); + RepositoryContentConsumers consumerutil = lookupRepositoryConsumers(); String expectedSelectedKnownIds[] = new String[]{ "create-missing-checksums", "validate-checksum", "index-content", "auto-remove", "auto-rename" }; - Map knownConsumerMap = consumerutil.getSelectedKnownConsumersMap( ); + Map knownConsumerMap = consumerutil.getSelectedKnownConsumersMap(); assertNotNull( "Known Consumer Map should not be null", knownConsumerMap ); assertEquals( "Known Consumer Map.size but " + knownConsumerMap, expectedSelectedKnownIds.length, - knownConsumerMap.size( ) ); + knownConsumerMap.size() ); for ( String expectedId : expectedSelectedKnownIds ) { KnownRepositoryContentConsumer consumer = knownConsumerMap.get( expectedId ); assertNotNull( "Known[" + expectedId + "] should not be null.", consumer ); - assertEquals( "Known[" + expectedId + "].id", expectedId, consumer.getId( ) ); + assertEquals( "Known[" + expectedId + "].id", expectedId, consumer.getId() ); } } @Test - public void testGetSelectedInvalidConsumerMap( ) + public void testGetSelectedInvalidConsumerMap() throws Exception { - RepositoryContentConsumers consumerutil = lookupRepositoryConsumers( ); + RepositoryContentConsumers consumerutil = lookupRepositoryConsumers(); String expectedSelectedInvalidIds[] = new String[]{ "update-db-bad-content" }; Map invalidConsumerMap = - consumerutil.getSelectedInvalidConsumersMap( ); + consumerutil.getSelectedInvalidConsumersMap(); 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 ) { InvalidRepositoryContentConsumer consumer = invalidConsumerMap.get( expectedId ); assertNotNull( "Known[" + expectedId + "] should not be null.", consumer ); - assertEquals( "Known[" + expectedId + "].id", expectedId, consumer.getId( ) ); + assertEquals( "Known[" + expectedId + "].id", expectedId, consumer.getId() ); } } @Test - public void testGetAvailableKnownList( ) + public void testGetAvailableKnownList() throws Exception { - RepositoryContentConsumers consumerutil = lookupRepositoryConsumers( ); + RepositoryContentConsumers consumerutil = lookupRepositoryConsumers(); String expectedKnownIds[] = new String[]{ "update-db-artifact", "create-missing-checksums", "update-db-repository-metadata", "validate-checksum", "index-content", "auto-remove", "auto-rename", "available-but-unselected" }; - List knownConsumers = consumerutil.getAvailableKnownConsumers( ); + List knownConsumers = consumerutil.getAvailableKnownConsumers(); assertNotNull( "known consumers should not be null.", knownConsumers ); - assertEquals( "known consumers", expectedKnownIds.length, knownConsumers.size( ) ); + assertEquals( "known consumers", expectedKnownIds.length, knownConsumers.size() ); List expectedIds = Arrays.asList( expectedKnownIds ); 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 - public void testGetAvailableInvalidList( ) + public void testGetAvailableInvalidList() throws Exception { - RepositoryContentConsumers consumerutil = lookupRepositoryConsumers( ); + RepositoryContentConsumers consumerutil = lookupRepositoryConsumers(); String expectedInvalidIds[] = new String[]{ "update-db-bad-content", "move-to-trash-then-notify" }; - List invalidConsumers = consumerutil.getAvailableInvalidConsumers( ); + List invalidConsumers = consumerutil.getAvailableInvalidConsumers(); assertNotNull( "invalid consumers should not be null.", invalidConsumers ); - assertEquals( "invalid consumers", expectedInvalidIds.length, invalidConsumers.size( ) ); + assertEquals( "invalid consumers", expectedInvalidIds.length, invalidConsumers.size() ); List expectedIds = Arrays.asList( expectedInvalidIds ); for ( InvalidRepositoryContentConsumer consumer : invalidConsumers ) { 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 - public void testExecution( ) + public void testExecution() throws Exception { - IMocksControl knownControl = createNiceControl( ); + IMocksControl knownControl = createNiceControl(); - RepositoryContentConsumers consumers = lookupRepositoryConsumers( ); - KnownRepositoryContentConsumer selectedKnownConsumer = knownControl.createMock( KnownRepositoryContentConsumer.class ); - - KnownRepositoryContentConsumer unselectedKnownConsumer = createNiceControl().createMock( KnownRepositoryContentConsumer.class ); + RepositoryContentConsumers consumers = lookupRepositoryConsumers(); + KnownRepositoryContentConsumer selectedKnownConsumer = + knownControl.createMock( KnownRepositoryContentConsumer.class ); + KnownRepositoryContentConsumer unselectedKnownConsumer = + createNiceControl().createMock( KnownRepositoryContentConsumer.class ); consumers.setApplicationContext( new MockApplicationContext( Arrays.asList( selectedKnownConsumer, unselectedKnownConsumer ), null ) ); @@ -259,9 +260,11 @@ public class RepositoryContentConsumersTest 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( new MockApplicationContext( null, Arrays.asList( selectedInvalidConsumer, unselectedInvalidConsumer ) ) ); @@ -271,64 +274,63 @@ public class RepositoryContentConsumersTest ManagedRepository repo = createRepository( "id", "name", new File( "target/test-repo" ) ); 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 ); 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 ); - knownControl.replay( ); + knownControl.replay(); selectedInvalidConsumer.beginScan( repo, startTime, false ); - invalidControl.replay( ); - + invalidControl.replay(); 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" ); selectedKnownConsumer.beginScan( repo, startTime, false ); expect( selectedKnownConsumer.getExcludes() ).andReturn( Collections.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.processFile( _OS( "path/to/test-file.xml" ), false ); expect( selectedInvalidConsumer.getId() ).andReturn( "invalid" ); - invalidControl.replay( ); + invalidControl.replay(); 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" ); selectedKnownConsumer.beginScan( repo, startTime, false ); expect( selectedKnownConsumer.getExcludes() ).andReturn( Collections.singletonList( "**/test-file.txt" ) ); - knownControl.replay( ); + knownControl.replay(); selectedInvalidConsumer.beginScan( repo, startTime, false ); selectedInvalidConsumer.processFile( _OS( "path/to/test-file.txt" ), false ); expect( selectedInvalidConsumer.getId() ).andReturn( "invalid" ); - invalidControl.replay( ); + invalidControl.replay(); consumers.executeConsumers( repo, excludedTestFile, true ); - knownControl.verify( ); - invalidControl.verify( ); + knownControl.verify(); + invalidControl.verify(); } /** @@ -346,7 +348,7 @@ public class RepositoryContentConsumersTest private static Map convertToMap( List objects ) { - HashMap map = new HashMap( ); + HashMap map = new HashMap(); for ( Object o : objects ) { map.put( o, o ); @@ -375,32 +377,32 @@ public class RepositoryContentConsumersTest } @Override - public AutowireCapableBeanFactory getAutowireCapableBeanFactory( ) + public AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException { throw new UnsupportedOperationException( "Not supported yet." ); } @Override - public String getDisplayName( ) + public String getDisplayName() { throw new UnsupportedOperationException( "Not supported yet." ); } @Override - public String getId( ) + public String getId() { throw new UnsupportedOperationException( "Not supported yet." ); } @Override - public ApplicationContext getParent( ) + public ApplicationContext getParent() { throw new UnsupportedOperationException( "Not supported yet." ); } @Override - public long getStartupDate( ) + public long getStartupDate() { throw new UnsupportedOperationException( "Not supported yet." ); } @@ -412,13 +414,13 @@ public class RepositoryContentConsumersTest } @Override - public int getBeanDefinitionCount( ) + public int getBeanDefinitionCount() { throw new UnsupportedOperationException( "Not supported yet." ); } @Override - public String[] getBeanDefinitionNames( ) + public String[] getBeanDefinitionNames() { throw new UnsupportedOperationException( "Not supported yet." ); } @@ -532,7 +534,7 @@ public class RepositoryContentConsumersTest } @Override - public BeanFactory getParentBeanFactory( ) + public BeanFactory getParentBeanFactory() { throw new UnsupportedOperationException( "Not supported yet." ); } @@ -571,7 +573,7 @@ public class RepositoryContentConsumersTest } @Override - public ClassLoader getClassLoader( ) + public ClassLoader getClassLoader() { throw new UnsupportedOperationException( "Not supported yet." ); } @@ -613,5 +615,24 @@ public class RepositoryContentConsumersTest { 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; + } } }