+
+ @Test
+ public void testGetOvsdbNodes() {
+ addItem();
+
+ when(southbound.extractOvsdbNode(any(Node.class))).thenReturn(mock(OvsdbNodeAugmentation.class));
+
+ assertEquals("Error, getOvsdbNodes() did not return the correct value", 1, nodeCacheManagerImpl.getOvsdbNodes().size());
+ }
+
+ @Test
+ public void testGetBridgeNodes() {
+ addItem();
+
+ when(southbound.getBridge(any(Node.class))).thenReturn(mock(OvsdbBridgeAugmentation.class));
+
+ assertEquals("Error, getBridgeNodes() did not return the correct value", 1, nodeCacheManagerImpl.getBridgeNodes().size());
+ }
+
+ @Test
+ public void testGetNodes() {
+ addItem();
+
+ assertEquals("Error, getNodes() did not return the correct value", 1, nodeCacheManagerImpl.getNodes().size());
+ }
+
+ private void addItem() {
+ NodeCacheManagerEvent ev = mock(NodeCacheManagerEvent.class);
+ Node node = mock(Node.class);
+ when(node.getNodeId()).thenReturn(mock(NodeId.class));
+ when(ev.getNode()).thenReturn(node);
+
+ when(ev.getAction()).thenReturn(Action.UPDATE);
+ nodeCacheManagerImpl.processEvent(ev);
+ }
+
+ @Test
+ public void testSetDependencies() throws Exception {
+ Southbound southbound = mock(Southbound.class);
+ EventDispatcher eventDispatcher = mock(EventDispatcher.class);
+
+ PowerMockito.mockStatic(ServiceHelper.class);
+ PowerMockito.when(ServiceHelper.getGlobalInstance(Southbound.class, nodeCacheManagerImpl)).thenReturn(southbound);
+ PowerMockito.when(ServiceHelper.getGlobalInstance(EventDispatcher.class, nodeCacheManagerImpl)).thenReturn(eventDispatcher);
+
+ nodeCacheManagerImpl.setDependencies(mock(ServiceReference.class));
+
+ assertEquals("Error, did not return the correct object", getField("southbound"), southbound);
+ assertEquals("Error, did not return the correct object", getSuperField("eventDispatcher"), eventDispatcher);
+ }
+
+ private Object getField(String fieldName) throws Exception {
+ Field field = NodeCacheManagerImpl.class.getDeclaredField(fieldName);
+ field.setAccessible(true);
+ return field.get(nodeCacheManagerImpl);
+ }
+
+ private Object getSuperField(String fieldName) throws Exception {
+ Field field = NodeCacheManagerImpl.class.getSuperclass().getDeclaredField(fieldName);
+ field.setAccessible(true);
+ return field.get(nodeCacheManagerImpl);
+ }