23114ec845672ee796b873b2ce007d0db4b821cb
[ovsdb.git] / openstack / net-virt / src / test / java / org / opendaylight / ovsdb / openstack / netvirt / impl / NodeCacheManagerImplTest.java
1 /*
2  * Copyright (c) 2015 Inocybe 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.ovsdb.openstack.netvirt.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.when;
13
14 import java.util.Map;
15
16 import org.junit.Ignore;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.InjectMocks;
20 import org.mockito.Spy;
21 import org.opendaylight.ovsdb.openstack.netvirt.NodeCacheManagerEvent;
22 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
23 import org.opendaylight.ovsdb.openstack.netvirt.api.NodeCacheListener;
24 //import org.opendaylight.ovsdb.utils.mdsal.node.NodeUtils;
25 import org.osgi.framework.ServiceReference;
26 import org.powermock.modules.junit4.PowerMockRunner;
27
28 import com.google.common.collect.Maps;
29
30 /**
31  * Unit test for {@link NodeCacheManagerImpl}
32  */
33 /* TODO SB_MIGRATION */ @Ignore
34 @RunWith(PowerMockRunner.class)
35 //@PrepareForTest(NodeUtils.class)
36 public class NodeCacheManagerImplTest {
37
38     @InjectMocks NodeCacheManagerImpl nodeCacheManagerImpl;
39     @Spy private Map<Long, NodeCacheListener> handlers = Maps.newHashMap();
40
41     @Test
42     public void testProcessEvent() {
43         NodeCacheManagerEvent ev = mock(NodeCacheManagerEvent.class);
44         when(ev.getNodeIdentifier()).thenReturn("node_identifier");
45
46         //PowerMockito.mockStatic(NodeUtils.class);
47         //when(NodeUtils.getOpenFlowNode(anyString())).thenReturn(mock(Node.class));
48
49         when(ev.getAction()).thenReturn(Action.ADD);
50         nodeCacheManagerImpl.processEvent(ev);
51         assertEquals("Error, did not add the event", 1, nodeCacheManagerImpl.getBridgeNodes().size());
52
53         when(ev.getAction()).thenReturn(Action.DELETE);
54         nodeCacheManagerImpl.processEvent(ev);
55         assertEquals("Error, did not delete the event", 0, nodeCacheManagerImpl.getBridgeNodes().size());
56     }
57
58     @Test
59     public void testCacheListenerAddedAndRemoved() {
60         ServiceReference ref = mock(ServiceReference.class);
61         when(ref.getProperty(org.osgi.framework.Constants.SERVICE_ID)).thenReturn(Long.valueOf(1));
62
63         // add
64         nodeCacheManagerImpl.cacheListenerAdded(ref, mock(NodeCacheListener.class));
65         assertEquals("Error, cacheListenerAdded() did not add any listener", 1, handlers.size());
66         // remove
67         nodeCacheManagerImpl.cacheListenerRemoved(ref);
68         assertEquals("Error, cacheListenerAdded() did not remove any listener", 0, handlers.size());
69     }
70 }