2 * Copyright (c) 2015 Inocybe 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.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;
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;
28 import com.google.common.collect.Maps;
31 * Unit test for {@link NodeCacheManagerImpl}
33 /* TODO SB_MIGRATION */ @Ignore
34 @RunWith(PowerMockRunner.class)
35 //@PrepareForTest(NodeUtils.class)
36 public class NodeCacheManagerImplTest {
38 @InjectMocks NodeCacheManagerImpl nodeCacheManagerImpl;
39 @Spy private Map<Long, NodeCacheListener> handlers = Maps.newHashMap();
42 public void testProcessEvent() {
43 NodeCacheManagerEvent ev = mock(NodeCacheManagerEvent.class);
44 when(ev.getNodeIdentifier()).thenReturn("node_identifier");
46 //PowerMockito.mockStatic(NodeUtils.class);
47 //when(NodeUtils.getOpenFlowNode(anyString())).thenReturn(mock(Node.class));
49 when(ev.getAction()).thenReturn(Action.ADD);
50 nodeCacheManagerImpl.processEvent(ev);
51 assertEquals("Error, did not add the event", 1, nodeCacheManagerImpl.getBridgeNodes().size());
53 when(ev.getAction()).thenReturn(Action.DELETE);
54 nodeCacheManagerImpl.processEvent(ev);
55 assertEquals("Error, did not delete the event", 0, nodeCacheManagerImpl.getBridgeNodes().size());
59 public void testCacheListenerAddedAndRemoved() {
60 ServiceReference ref = mock(ServiceReference.class);
61 when(ref.getProperty(org.osgi.framework.Constants.SERVICE_ID)).thenReturn(Long.valueOf(1));
64 nodeCacheManagerImpl.cacheListenerAdded(ref, mock(NodeCacheListener.class));
65 assertEquals("Error, cacheListenerAdded() did not add any listener", 1, handlers.size());
67 nodeCacheManagerImpl.cacheListenerRemoved(ref);
68 assertEquals("Error, cacheListenerAdded() did not remove any listener", 0, handlers.size());