Merge "SouthboundIT: Test to check ovs version for node."
[ovsdb.git] / openstack / net-virt / src / test / java / org / opendaylight / ovsdb / openstack / netvirt / SubnetHandlerTest.java
1 /*
2  * Copyright (c) 2015 Inocybe and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.ovsdb.openstack.netvirt;
10
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;
16
17 import java.net.HttpURLConnection;
18
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;
27
28 /**
29  * Unit test fort {@link SubnetHandler}
30  */
31 @RunWith(MockitoJUnitRunner.class)
32 public class SubnetHandlerTest {
33
34     @InjectMocks private SubnetHandler subnetHandler;
35
36     @Mock NeutronL3Adapter neutronl3Adapter;
37
38     @Test
39     public void testCanCreateSubnet() {
40         assertEquals("Error, canCreateSubnet() did not return the correct HTTP flag", HttpURLConnection.HTTP_OK, subnetHandler.canCreateSubnet(mock(NeutronSubnet.class)));
41     }
42
43     @Test
44     public void testCanUpdateSubnet() {
45         assertEquals("Error, canUpdateSubnet() did not return the correct HTTP flag", HttpURLConnection.HTTP_OK, subnetHandler.canUpdateSubnet(mock(NeutronSubnet.class), mock(NeutronSubnet.class)));
46     }
47
48     @Test
49     public void testCanDeleteSubnet() {
50         assertEquals("Error, canDeleteSubnet() did not return the correct HTTP flag", HttpURLConnection.HTTP_OK, subnetHandler.canDeleteSubnet(mock(NeutronSubnet.class)));
51     }
52
53     @Test
54     public void testProcessEvent() {
55         NorthboundEvent ev = mock(NorthboundEvent.class);
56         when(ev.getSubnet()).thenReturn(mock(NeutronSubnet.class));
57
58         when(ev.getAction()).thenReturn(Action.ADD);
59         subnetHandler.processEvent(ev);
60         verify(neutronl3Adapter, times(1)).handleNeutronSubnetEvent(ev.getSubnet(), ev.getAction());;
61
62         when(ev.getAction()).thenReturn(Action.DELETE);
63         subnetHandler.processEvent(ev);
64         verify(neutronl3Adapter, times(1)).handleNeutronSubnetEvent(ev.getSubnet(), ev.getAction());;
65
66         when(ev.getAction()).thenReturn(Action.UPDATE);
67         subnetHandler.processEvent(ev);
68         verify(neutronl3Adapter, times(1)).handleNeutronSubnetEvent(ev.getSubnet(), ev.getAction());;
69     }
70 }