2 * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.controller.config.manager.impl.osgi;
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Mockito.doNothing;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.verifyZeroInteractions;
16 import com.google.common.util.concurrent.Futures;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.mockito.InOrder;
20 import org.mockito.Mock;
21 import org.mockito.Mockito;
22 import org.mockito.MockitoAnnotations;
23 import org.osgi.framework.Bundle;
24 import org.osgi.framework.BundleContext;
25 import org.osgi.framework.BundleEvent;
26 import org.osgi.util.tracker.BundleTrackerCustomizer;
28 public class ExtensibleBundleTrackerTest {
31 private BundleContext bundleContext;
33 private Bundle bundle;
35 private BundleEvent bundleEvent;
38 private BundleTrackerCustomizer<Object> primaryTracker;
40 private BundleTrackerCustomizer<?> additionalTracker;
42 private ExtensibleBundleTracker<Object> extensibleBundleTracker;
43 private Object primaryValue = new Object();
46 public void setUp() throws Exception {
47 MockitoAnnotations.initMocks(this);
48 doReturn("bundle").when(bundle).toString();
49 doReturn("bundleEvent").when(bundleEvent).toString();
51 doReturn(primaryValue).when(primaryTracker).addingBundle(bundle, bundleEvent);
52 doNothing().when(primaryTracker).modifiedBundle(bundle, bundleEvent, primaryValue);
53 doNothing().when(primaryTracker).removedBundle(bundle, bundleEvent, primaryValue);
55 doReturn(new Object()).when(additionalTracker).addingBundle(bundle, bundleEvent);
56 doNothing().when(additionalTracker).modifiedBundle(bundle, bundleEvent, null);
57 doNothing().when(additionalTracker).removedBundle(bundle, bundleEvent, null);
58 extensibleBundleTracker = new ExtensibleBundleTracker<>(bundleContext, primaryTracker, additionalTracker);
62 public void testAddingBundle() throws Exception {
63 assertEquals(primaryValue, extensibleBundleTracker.addingBundle(bundle, bundleEvent).get());
64 InOrder inOrder = Mockito.inOrder(primaryTracker, additionalTracker);
65 inOrder.verify(primaryTracker).addingBundle(bundle, bundleEvent);
66 inOrder.verify(additionalTracker).addingBundle(bundle, bundleEvent);
70 public void testRemovedBundle() throws Exception {
71 extensibleBundleTracker.removedBundle(bundle, bundleEvent, Futures.immediateFuture(primaryValue));
72 InOrder inOrder = Mockito.inOrder(primaryTracker, additionalTracker);
73 inOrder.verify(primaryTracker).removedBundle(bundle, bundleEvent, primaryValue);
74 inOrder.verify(additionalTracker).removedBundle(bundle, bundleEvent, null);
78 public void testRemovedBundleWithEx() throws Exception {
79 IllegalStateException throwable = new IllegalStateException();
80 extensibleBundleTracker.removedBundle(bundle, bundleEvent, Futures.immediateFailedFuture(throwable));
81 verifyZeroInteractions(primaryTracker);
82 verifyZeroInteractions(additionalTracker);