1 package org.opendaylight.controller.config.manager.impl.osgi;
3 import static org.junit.Assert.assertEquals;
4 import static org.mockito.Mockito.doNothing;
5 import static org.mockito.Mockito.doReturn;
6 import static org.mockito.Mockito.verifyZeroInteractions;
8 import com.google.common.util.concurrent.Futures;
9 import org.junit.Before;
10 import org.junit.Test;
11 import org.mockito.InOrder;
12 import org.mockito.Mock;
13 import org.mockito.Mockito;
14 import org.mockito.MockitoAnnotations;
15 import org.osgi.framework.Bundle;
16 import org.osgi.framework.BundleContext;
17 import org.osgi.framework.BundleEvent;
18 import org.osgi.util.tracker.BundleTrackerCustomizer;
20 public class ExtensibleBundleTrackerTest {
23 private BundleContext bundleContext;
25 private Bundle bundle;
27 private BundleEvent bundleEvent;
30 private BundleTrackerCustomizer<Object> primaryTracker;
32 private BundleTrackerCustomizer<?> additionalTracker;
34 private ExtensibleBundleTracker<Object> extensibleBundleTracker;
35 private Object primaryValue = new Object();
38 public void setUp() throws Exception {
39 MockitoAnnotations.initMocks(this);
40 doReturn("bundle").when(bundle).toString();
41 doReturn("bundleEvent").when(bundleEvent).toString();
43 doReturn(primaryValue).when(primaryTracker).addingBundle(bundle, bundleEvent);
44 doNothing().when(primaryTracker).modifiedBundle(bundle, bundleEvent, primaryValue);
45 doNothing().when(primaryTracker).removedBundle(bundle, bundleEvent, primaryValue);
47 doReturn(new Object()).when(additionalTracker).addingBundle(bundle, bundleEvent);
48 doNothing().when(additionalTracker).modifiedBundle(bundle, bundleEvent, null);
49 doNothing().when(additionalTracker).removedBundle(bundle, bundleEvent, null);
50 extensibleBundleTracker = new ExtensibleBundleTracker<>(bundleContext, primaryTracker, additionalTracker);
54 public void testAddingBundle() throws Exception {
55 assertEquals(primaryValue, extensibleBundleTracker.addingBundle(bundle, bundleEvent).get());
56 InOrder inOrder = Mockito.inOrder(primaryTracker, additionalTracker);
57 inOrder.verify(primaryTracker).addingBundle(bundle, bundleEvent);
58 inOrder.verify(additionalTracker).addingBundle(bundle, bundleEvent);
62 public void testRemovedBundle() throws Exception {
63 extensibleBundleTracker.removedBundle(bundle, bundleEvent, Futures.immediateFuture(primaryValue));
64 InOrder inOrder = Mockito.inOrder(primaryTracker, additionalTracker);
65 inOrder.verify(primaryTracker).removedBundle(bundle, bundleEvent, primaryValue);
66 inOrder.verify(additionalTracker).removedBundle(bundle, bundleEvent, null);
70 public void testRemovedBundleWithEx() throws Exception {
71 IllegalStateException throwable = new IllegalStateException();
72 extensibleBundleTracker.removedBundle(bundle, bundleEvent, Futures.immediateFailedFuture(throwable));
73 verifyZeroInteractions(primaryTracker);
74 verifyZeroInteractions(additionalTracker);