Merge "Use ${project.version} for internal dependencies"
[ovsdb.git] / openstack / net-virt / src / test / java / org / opendaylight / ovsdb / openstack / netvirt / PortSecurityHandlerTest.java
index 4012eb3eb4620e155454a524730b6dbc1cfd4fd9..bb975af41eb30744d96849e064143a66cc8fc7cb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Inocybe and others.  All rights reserved.
+ * Copyright (c) 2015, 2016 Inocybe and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -14,16 +14,21 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 
+import java.lang.reflect.Field;
 import java.net.HttpURLConnection;
 
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.InjectMocks;
+import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
-import org.opendaylight.neutron.spi.NeutronSecurityGroup;
-import org.opendaylight.neutron.spi.NeutronSecurityRule;
+import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronSecurityGroup;
+import org.opendaylight.ovsdb.openstack.netvirt.translator.NeutronSecurityRule;
+import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
+import org.osgi.framework.ServiceReference;
 
 /**
  * Unit test {@link PortSecurityHandler}
@@ -33,6 +38,7 @@ public class PortSecurityHandlerTest {
 
     @InjectMocks private PortSecurityHandler portSecurityHandler;
     private PortSecurityHandler posrtSecurityHandlerSpy;
+    @Mock EventDispatcher eventDispatcher;
 
     @Before
     public void setUp() {
@@ -65,7 +71,7 @@ public class PortSecurityHandlerTest {
         assertEquals("Error, did not return the correct HTTP flag", HttpURLConnection.HTTP_CREATED, portSecurityHandler.canCreateNeutronSecurityRule(mock(NeutronSecurityRule.class)));
 
         posrtSecurityHandlerSpy.neutronSecurityRuleCreated(any(NeutronSecurityRule.class));
-        verify(posrtSecurityHandlerSpy, times(1)).canCreateNeutronSecurityRule(any(NeutronSecurityRule.class));
+        verify(posrtSecurityHandlerSpy, times(1)).enqueueEvent(any(AbstractEvent.class));
     }
 
     @Test
@@ -78,7 +84,7 @@ public class PortSecurityHandlerTest {
         assertEquals("Error, did not return the correct HTTP flag", HttpURLConnection.HTTP_OK, portSecurityHandler.canDeleteNeutronSecurityRule(mock(NeutronSecurityRule.class)));
 
         posrtSecurityHandlerSpy.neutronSecurityRuleDeleted(any(NeutronSecurityRule.class));
-        verify(posrtSecurityHandlerSpy, times(1)).canDeleteNeutronSecurityRule(any(NeutronSecurityRule.class));
+        verify(posrtSecurityHandlerSpy, times(1)).enqueueEvent(any(AbstractEvent.class));
    }
 
     @Test
@@ -86,4 +92,22 @@ public class PortSecurityHandlerTest {
         // TODO see PortSecurityHandler#processEvent()
     }
 
+    @Test
+    public void testSetDependencies() throws Exception {
+        EventDispatcher eventDispatcher = mock(EventDispatcher.class);
+
+        ServiceHelper.overrideGlobalInstance(EventDispatcher.class, eventDispatcher);
+
+        portSecurityHandler.setDependencies(mock(ServiceReference.class));
+
+        assertEquals("Error, did not return the correct object", portSecurityHandler.eventDispatcher, eventDispatcher);
+    }
+
+
+    private Object getField(String fieldName) throws Exception {
+        Field field = PortSecurityHandler.class.getDeclaredField(fieldName);
+        field.setAccessible(true);
+        return field.get(portSecurityHandler);
+    }
+
 }