@Test
public void givenMixedSuccessFailurePassivationWhenPassivatingExpectAllPassivateMethodsToBeCalled()
throws Exception
{
SingletonAssembler assembly = new SingletonAssembler()
{
public void assemble( ModuleAssembly module )
throws AssemblyException
{
module.addServices( SuccessDataService.class );
module.addServices( SuccessDataService.class );
module.addServices( SuccessDataService.class );
module.addServices( FailingDataService.class );
module.addServices( SuccessDataService.class );
module.addServices( SuccessDataService.class );
module.addServices( FailingDataService.class );
module.addServices( SuccessDataService.class );
module.addServices( SuccessDataService.class );
module.addServices( FailingDataService.class );
module.addServices( SuccessDataService.class );
module.addServices( SuccessDataService.class );
module.addServices( FailingDataService.class );
}
};
ArrayList<Data> datas = new ArrayList<Data>();
Iterable<ServiceReference<DataAccess>> iterable = assembly.module().findServices( DataAccess.class );
for( ServiceReference<DataAccess> service : iterable )
{
assertTrue( "Service should not be Active before accessed", !service.isActive() );
Data data = service.get().data();
if( SuccessDataService.class.isInstance( service.get() ) )
{
// Collect the expected successes.
datas.add( data );
}
assertTrue( data.activated );
assertTrue( "Service should be Active after access.", service.isActive() );
}
try
{
assembly.application().passivate();
fail( "PassivationException should have been thrown." );
}
catch( PassivationException e )
{
// Expected