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;
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.times;
14 import static org.mockito.Mockito.verify;
15 import static org.mockito.Mockito.when;
17 import java.net.HttpURLConnection;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.mockito.InjectMocks;
22 import org.mockito.Mock;
23 import org.mockito.runners.MockitoJUnitRunner;
24 import org.opendaylight.neutron.spi.NeutronSubnet;
25 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
26 import org.opendaylight.ovsdb.openstack.netvirt.impl.NeutronL3Adapter;
29 * Unit test fort {@link SubnetHandler}
31 @RunWith(MockitoJUnitRunner.class)
32 public class SubnetHandlerTest {
34 @InjectMocks private SubnetHandler subnetHandler;
36 @Mock NeutronL3Adapter neutronl3Adapter;
39 public void testCanCreateSubnet() {
40 assertEquals("Error, canCreateSubnet() did not return the correct HTTP flag", HttpURLConnection.HTTP_CREATED, subnetHandler.canCreateSubnet(mock(NeutronSubnet.class)));
44 public void testCanUpdateSubnet() {
45 assertEquals("Error, canUpdateSubnet() did not return the correct HTTP flag", HttpURLConnection.HTTP_CREATED, subnetHandler.canUpdateSubnet(mock(NeutronSubnet.class), mock(NeutronSubnet.class)));
49 public void testCanDeleteSubnet() {
50 assertEquals("Error, canDeleteSubnet() did not return the correct HTTP flag", HttpURLConnection.HTTP_CREATED, subnetHandler.canDeleteSubnet(mock(NeutronSubnet.class)));
54 public void testProcessEvent() {
55 NorthboundEvent ev = mock(NorthboundEvent.class);
56 when(ev.getSubnet()).thenReturn(mock(NeutronSubnet.class));
58 when(ev.getAction()).thenReturn(Action.ADD);
59 subnetHandler.processEvent(ev);
60 verify(neutronl3Adapter, times(1)).handleNeutronSubnetEvent(ev.getSubnet(), ev.getAction());;
62 when(ev.getAction()).thenReturn(Action.DELETE);
63 subnetHandler.processEvent(ev);
64 verify(neutronl3Adapter, times(1)).handleNeutronSubnetEvent(ev.getSubnet(), ev.getAction());;
66 when(ev.getAction()).thenReturn(Action.UPDATE);
67 subnetHandler.processEvent(ev);
68 verify(neutronl3Adapter, times(1)).handleNeutronSubnetEvent(ev.getSubnet(), ev.getAction());;