Fix license header violations in config-manager
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / impl / osgi / ExtensibleBundleTrackerTest.java
1 /*
2  * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.config.manager.impl.osgi;
10
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;
15
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;
27
28 public class ExtensibleBundleTrackerTest {
29
30     @Mock
31     private BundleContext bundleContext;
32     @Mock
33     private Bundle bundle;
34     @Mock
35     private BundleEvent bundleEvent;
36
37     @Mock
38     private BundleTrackerCustomizer<Object> primaryTracker;
39     @Mock
40     private BundleTrackerCustomizer<?> additionalTracker;
41
42     private ExtensibleBundleTracker<Object> extensibleBundleTracker;
43     private Object primaryValue = new Object();
44
45     @Before
46     public void setUp() throws Exception {
47         MockitoAnnotations.initMocks(this);
48         doReturn("bundle").when(bundle).toString();
49         doReturn("bundleEvent").when(bundleEvent).toString();
50
51         doReturn(primaryValue).when(primaryTracker).addingBundle(bundle, bundleEvent);
52         doNothing().when(primaryTracker).modifiedBundle(bundle, bundleEvent, primaryValue);
53         doNothing().when(primaryTracker).removedBundle(bundle, bundleEvent, primaryValue);
54
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);
59     }
60
61     @Test
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);
67     }
68
69     @Test
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);
75     }
76
77     @Test
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);
83     }
84 }