/*
- * 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,
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
+import org.mockito.Mock;
import org.mockito.Mockito;
-import org.opendaylight.neutron.spi.NeutronSecurityGroup;
-import org.opendaylight.neutron.spi.NeutronSecurityRule;
+import org.mockito.runners.MockitoJUnitRunner;
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.BundleContext;
import org.osgi.framework.ServiceReference;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
/**
* Unit test {@link PortSecurityHandler}
*/
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(ServiceHelper.class)
+@RunWith(MockitoJUnitRunner.class)
public class PortSecurityHandlerTest {
@InjectMocks private PortSecurityHandler portSecurityHandler;
private PortSecurityHandler posrtSecurityHandlerSpy;
+ @Mock EventDispatcher eventDispatcher;
@Before
public void setUp() {
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
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
public void testSetDependencies() throws Exception {
EventDispatcher eventDispatcher = mock(EventDispatcher.class);
- PowerMockito.mockStatic(ServiceHelper.class);
- PowerMockito.when(ServiceHelper.getGlobalInstance(EventDispatcher.class, portSecurityHandler)).thenReturn(eventDispatcher);
+ ServiceHelper.overrideGlobalInstance(EventDispatcher.class, eventDispatcher);
- portSecurityHandler.setDependencies(mock(BundleContext.class), mock(ServiceReference.class));
+ portSecurityHandler.setDependencies(mock(ServiceReference.class));
assertEquals("Error, did not return the correct object", portSecurityHandler.eventDispatcher, eventDispatcher);
}