@Test
public void testExecution( )
throws Exception
{
IMocksControl knownControl = createNiceControl( );
RepositoryContentConsumers consumers = lookupRepositoryConsumers( );
KnownRepositoryContentConsumer selectedKnownConsumer = knownControl.createMock( KnownRepositoryContentConsumer.class );
KnownRepositoryContentConsumer unselectedKnownConsumer = createNiceControl().createMock( KnownRepositoryContentConsumer.class );
consumers.setApplicationContext(
new MockApplicationContext( Arrays.asList( selectedKnownConsumer, unselectedKnownConsumer ), null ) );
consumers.setSelectedKnownConsumers( Collections.singletonList( selectedKnownConsumer ) );
IMocksControl invalidControl = createControl();
InvalidRepositoryContentConsumer selectedInvalidConsumer = invalidControl.createMock( InvalidRepositoryContentConsumer.class );
InvalidRepositoryContentConsumer unselectedInvalidConsumer = createControl().createMock( InvalidRepositoryContentConsumer.class );
consumers.setApplicationContext(
new MockApplicationContext( null, Arrays.asList( selectedInvalidConsumer, unselectedInvalidConsumer ) ) );
consumers.setSelectedInvalidConsumers( Collections.singletonList( selectedInvalidConsumer ) );
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( ) );
startTime.setTime( 12345678 );
selectedKnownConsumer.beginScan( repo, startTime, false );
expect( selectedKnownConsumer.getIncludes( ) ).andReturn( Collections.singletonList( "**/*.txt" ) );
selectedKnownConsumer.processFile( _OS( "path/to/test-file.txt" ), false );
knownControl.replay( );
selectedInvalidConsumer.beginScan( repo, startTime, false );
invalidControl.replay( );
consumers.executeConsumers( repo, testFile, true );
knownControl.verify( );
invalidControl.verify( );
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.<String>emptyList() );
expect( selectedKnownConsumer.getIncludes( ) ).andReturn( Collections.singletonList( "**/*.txt" ) );
knownControl.replay( );
selectedInvalidConsumer.beginScan( repo, startTime, false );
selectedInvalidConsumer.processFile( _OS( "path/to/test-file.xml" ), false );
expect( selectedInvalidConsumer.getId() ).andReturn( "invalid" );
invalidControl.replay( );
consumers.executeConsumers( repo, notIncludedTestFile, true );
knownControl.verify( );
invalidControl.verify( );
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( );
selectedInvalidConsumer.beginScan( repo, startTime, false );
selectedInvalidConsumer.processFile( _OS( "path/to/test-file.txt" ), false );
expect( selectedInvalidConsumer.getId() ).andReturn( "invalid" );
invalidControl.replay( );
consumers.executeConsumers( repo, excludedTestFile, true );
knownControl.verify( );
invalidControl.verify( );
}