@Test
public void test_optional_single_static() throws Exception
{
final SimpleServiceImpl srv1 = SimpleServiceImpl.create( bundleContext, "srv1" );
String name = "test_optional_single_static_target";
getDisabledConfigurationAndEnable(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp10 = SimpleComponent.INSTANCE;
TestCase.assertNotNull( comp10 );
TestCase.assertEquals( srv1, comp10.m_singleRef );
TestCase.assertTrue( comp10.m_multiRef.isEmpty() );
TestCase.assertEquals( 1, comp10.m_singleRefBind );
TestCase.assertEquals( 0, comp10.m_singleRefUnbind);
// update a service property
srv1.update( "srv1-modified" );
// no changes in bindings expected
TestCase.assertEquals( srv1, comp10.m_singleRef );
TestCase.assertTrue( comp10.m_multiRef.isEmpty() );
TestCase.assertEquals( 1, comp10.m_singleRefBind );
TestCase.assertEquals( 0, comp10.m_singleRefUnbind);
// set target to not match any more -> recreate !
srv1.setFilterProperty( "don't match" );
delay(); // async reactivation
findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp11 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp11 );
TestCase.assertNull( comp11.m_singleRef );
TestCase.assertTrue( comp11.m_multiRef.isEmpty() );
TestCase.assertEquals( 0, comp11.m_singleRefBind );
TestCase.assertEquals( 0, comp11.m_singleRefUnbind);
final SimpleServiceImpl srv2 = SimpleServiceImpl.create( bundleContext, "srv2" );
delay(); // async binding
findComponentConfigurationByName(name, ComponentConfigurationDTO.ACTIVE);
final SimpleComponent comp12 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp12 );
TestCase.assertSame( comp11, comp12 );
TestCase.assertNull( comp12.m_singleRef );
TestCase.assertTrue( comp12.m_multiRef.isEmpty() );
TestCase.assertEquals( 0, comp12.m_singleRefBind );
TestCase.assertEquals( 0, comp12.m_singleRefUnbind);
// make srv1 match again, expect not changes in bindings
srv1.setFilterProperty( "match" );
final SimpleComponent comp13 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp13 );
TestCase.assertSame( comp11, comp13 );
TestCase.assertSame( comp12, comp13 );
TestCase.assertNull( comp13.m_singleRef );
TestCase.assertTrue( comp13.m_multiRef.isEmpty() );
TestCase.assertEquals( 0, comp13.m_singleRefBind );
TestCase.assertEquals( 0, comp13.m_singleRefUnbind);
// make srv2 to not match, expect binding to srv1
srv2.setFilterProperty( "don't match" );
final SimpleComponent comp14 = SimpleComponent.INSTANCE;
TestCase.assertNotSame( comp10, comp14 );
TestCase.assertSame( comp11, comp14 );
TestCase.assertSame( comp12, comp14 );
TestCase.assertSame( comp13, comp14 );