Revert ModuleInfoBundleTracker patches
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / impl / osgi / ModuleFactoryBundleTrackerTest.java
index da585b7151365eec3529161530403371f0016283..9930a887c526e4f66759664c3ad9a047ab49600d 100644 (file)
@@ -15,15 +15,11 @@ 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.reset;
 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;
@@ -50,8 +46,6 @@ public class ModuleFactoryBundleTrackerTest {
     private BundleContext context;
     @Mock
     private ServiceRegistration<?> reg;
-    @Mock
-    private BlankTransactionServiceTracker blankTxTracker;
 
     @Before
     public void setUp() throws Exception {
@@ -63,18 +57,14 @@ 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 {
-        Entry<ModuleFactory, Bundle> entry = ModuleFactoryBundleTracker.registerFactory(
-                TestingFactory.class.getName(), bundle);
-        assertEquals(TestingFactory.currentInstance, entry.getKey());
-        assertEquals(bundle, entry.getValue());
+        ModuleFactoryBundleTracker.registerFactory(TestingFactory.class.getName(), bundle);
+        verify(context).registerService(ModuleFactory.class.getName(), TestingFactory.currentInstance, null);
     }
 
     @Test
@@ -131,38 +121,15 @@ public class ModuleFactoryBundleTrackerTest {
         fail("Cannot register without extend");
     }
 
+    @Mock
+    private BlankTransactionServiceTracker blankTxTracker;
+
     @Test
-    public void testBundleAddAndRemove() throws Exception {
+    public void testAddingBundle() throws Exception {
         final ModuleFactoryBundleTracker tracker = new ModuleFactoryBundleTracker(blankTxTracker);
         doReturn(getClass().getResource("/module-factories/module-factory-ok")).when(bundle).getEntry(anyString());
-        tracker.addingBundle(bundle, null);
-
-        Collection<Entry<ModuleFactory, BundleContext>> entries = tracker.getModuleFactoryEntries();
-        assertNotNull(entries);
-        assertEquals(1, entries.size());
-        Entry<ModuleFactory, BundleContext> entry = entries.iterator().next();
-        assertEquals(TestingFactory.currentInstance, entry.getKey());
-        assertEquals(context, entry.getValue());
-
-        doNothing().when(blankTxTracker).blankTransaction();;
-
-        BundleEvent mockEvent = mock(BundleEvent.class);
-        doReturn(BundleEvent.STOPPING).when(mockEvent).getType();
-
-        tracker.removedBundle(bundle, mockEvent, bundle);
-
-        entries = tracker.getModuleFactoryEntries();
-        assertNotNull(entries);
-        assertEquals(0, entries.size());
-
-        verify(blankTxTracker).blankTransaction();
-
-        reset(mockEvent);
-        doReturn(BundleEvent.STOPPED).when(mockEvent).getType();
-
-        tracker.addingBundle(bundle, mockEvent);
-
-        assertEquals(0, tracker.getModuleFactoryEntries().size());
+        tracker.addingBundle(bundle, mock(BundleEvent.class));
+        verify(context).registerService(ModuleFactory.class.getName(), TestingFactory.currentInstance, null);
     }
 
     @Test