X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fosgi%2FModuleFactoryBundleTrackerTest.java;fp=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Fosgi%2FModuleFactoryBundleTrackerTest.java;h=9ac570e2eed166045ac7930425b77932b5229263;hp=66063c98b36ed2df8611f5e52401d52e0353357c;hb=493c4f70a0a315d77927e4c0d90a90acbbcb2897;hpb=7873bfcd1735ce86a58c015b2865c7f3627fb121;ds=sidebyside diff --git a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTrackerTest.java b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTrackerTest.java index 66063c98b3..9ac570e2ee 100644 --- a/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTrackerTest.java +++ b/opendaylight/config/config-manager/src/test/java/org/opendaylight/controller/config/manager/impl/osgi/ModuleFactoryBundleTrackerTest.java @@ -15,12 +15,14 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyObject; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doAnswer; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; - +import java.util.Collection; import java.util.Dictionary; +import java.util.Map.Entry; import java.util.Set; import org.junit.Before; import org.junit.Test; @@ -47,6 +49,8 @@ public class ModuleFactoryBundleTrackerTest { private BundleContext context; @Mock private ServiceRegistration reg; + @Mock + private BlankTransactionServiceTracker blankTxTracker; @Before public void setUp() throws Exception { @@ -58,14 +62,18 @@ public class ModuleFactoryBundleTrackerTest { } }).when(bundle).loadClass(anyString()); doReturn("mockBundle").when(bundle).toString(); + doReturn("mockBundleContext").when(context).toString(); doReturn(context).when(bundle).getBundleContext(); + doReturn(100L).when(bundle).getBundleId(); doReturn(reg).when(context).registerService(anyString(), anyObject(), any(Dictionary.class)); } @Test public void testRegisterFactory() throws Exception { - ModuleFactoryBundleTracker.registerFactory(TestingFactory.class.getName(), bundle); - verify(context).registerService(ModuleFactory.class.getName(), TestingFactory.currentInstance, null); + Entry entry = ModuleFactoryBundleTracker.registerFactory( + TestingFactory.class.getName(), bundle); + assertEquals(TestingFactory.currentInstance, entry.getKey()); + assertEquals(bundle, entry.getValue()); } @Test @@ -122,15 +130,28 @@ public class ModuleFactoryBundleTrackerTest { fail("Cannot register without extend"); } - @Mock - private BlankTransactionServiceTracker blankTxTracker; - @Test - public void testAddingBundle() throws Exception { + public void testBundleAddAndRemove() throws Exception { final ModuleFactoryBundleTracker tracker = new ModuleFactoryBundleTracker(blankTxTracker); doReturn(getClass().getResource("/module-factories/module-factory-ok")).when(bundle).getEntry(anyString()); tracker.addingBundle(bundle, mock(BundleEvent.class)); - verify(context).registerService(ModuleFactory.class.getName(), TestingFactory.currentInstance, null); + + Collection> entries = tracker.getModuleFactoryEntries(); + assertNotNull(entries); + assertEquals(1, entries.size()); + Entry entry = entries.iterator().next(); + assertEquals(TestingFactory.currentInstance, entry.getKey()); + assertEquals(context, entry.getValue()); + + doNothing().when(blankTxTracker).blankTransaction();; + + tracker.removedBundle(bundle, mock(BundleEvent.class), bundle); + + entries = tracker.getModuleFactoryEntries(); + assertNotNull(entries); + assertEquals(0, entries.size()); + + verify(blankTxTracker).blankTransaction();; } @Test