Merge "Introducing the extractCreatedOrUpdated method"
[netvirt.git] / openstack / net-virt / src / test / java / org / opendaylight / ovsdb / openstack / netvirt / FloatingIPHandlerTest.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.verifyNoMoreInteractions;
16 import static org.mockito.Mockito.when;
17
18 import java.net.HttpURLConnection;
19
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.mockito.InjectMocks;
23 import org.mockito.Mockito;
24 import org.mockito.runners.MockitoJUnitRunner;
25 import org.opendaylight.neutron.spi.NeutronFloatingIP;
26 import org.opendaylight.ovsdb.openstack.netvirt.api.Action;
27 import org.opendaylight.ovsdb.openstack.netvirt.impl.NeutronL3Adapter;
28
29 /**
30  * Unit test for {@link FloatingIPHandler}
31  */
32 @RunWith(MockitoJUnitRunner.class)
33 public class FloatingIPHandlerTest {
34
35     @InjectMocks private FloatingIPHandler floatingHandler = mock(FloatingIPHandler.class, Mockito.CALLS_REAL_METHODS);
36     @InjectMocks private NeutronL3Adapter neutronL3Adapter = mock(NeutronL3Adapter.class);
37
38     @Test
39     public void testCanCreateFloatingIP(){
40         assertEquals("Error, did not return the correct HTTP status code", HttpURLConnection.HTTP_OK, floatingHandler.canCreateFloatingIP(mock(NeutronFloatingIP.class)));
41     }
42
43     @Test
44     public void testCanUpdateFloatingIP(){
45         assertEquals("Error, did not return the correct HTTP status code", HttpURLConnection.HTTP_OK, floatingHandler.canUpdateFloatingIP(mock(NeutronFloatingIP.class), mock(NeutronFloatingIP.class)));
46     }
47
48     @Test
49     public void testCanDeleteFloatingIP(){
50         assertEquals("Error, did not return the correct HTTP status code", HttpURLConnection.HTTP_OK, floatingHandler.canDeleteFloatingIP(mock(NeutronFloatingIP.class)));
51     }
52
53     @Test
54     public void testProcessEvent(){
55         NorthboundEvent ev = mock(NorthboundEvent.class);
56
57         when(ev.getNeutronFloatingIP()).thenReturn(mock(NeutronFloatingIP.class));
58
59         when(ev.getAction()).thenReturn(Action.UPDATE);
60         floatingHandler.processEvent((AbstractEvent) ev);
61         verify(neutronL3Adapter, times(1)).handleNeutronFloatingIPEvent(ev.getNeutronFloatingIP(), ev.getAction());;
62
63         when(ev.getAction()).thenReturn(Action.ADD);
64         floatingHandler.processEvent((AbstractEvent) ev);
65         verify(neutronL3Adapter, times(1)).handleNeutronFloatingIPEvent(ev.getNeutronFloatingIP(), ev.getAction());;
66
67         when(ev.getAction()).thenReturn(Action.DELETE);
68         floatingHandler.processEvent((AbstractEvent) ev);
69         verify(neutronL3Adapter, times(1)).handleNeutronFloatingIPEvent(ev.getNeutronFloatingIP(), ev.getAction());;
70     }
71 }