Merge "Add JUnit testing for FWaasHandler class."
[ovsdb.git] / openstack / net-virt / src / test / java / org / opendaylight / ovsdb / openstack / netvirt / AbstractHandlerTest.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.Matchers.any;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.times;
15 import static org.mockito.Mockito.verify;
16 import static org.mockito.Mockito.verifyNoMoreInteractions;
17 import static org.mockito.Mockito.when;
18
19 import java.net.HttpURLConnection;
20
21 import org.junit.Test;
22 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
23 import org.opendaylight.ovsdb.plugin.api.Status;
24 import org.opendaylight.ovsdb.plugin.api.StatusCode;
25 /**
26  * Unit test for {@link AbstractHandler}
27  */
28 public class AbstractHandlerTest {
29
30     @Test
31     public void testAbstractHandler() {
32         Status status = mock(Status.class);
33
34         when(status.getCode())
35                 .thenReturn(StatusCode.BADREQUEST)
36                 .thenReturn(StatusCode.CONFLICT)
37                 .thenReturn(StatusCode.NOTACCEPTABLE)
38                 .thenReturn(StatusCode.NOTFOUND)
39                 .thenReturn(StatusCode.GONE);
40
41         assertEquals(
42                 "Error, getException() did not return the correct neutron API service error",
43                 HttpURLConnection.HTTP_BAD_REQUEST,
44                 AbstractHandler.getException(status));
45         assertEquals(
46                 "Error, getException() did not return the correct neutron API service error",
47                 HttpURLConnection.HTTP_CONFLICT,
48                 AbstractHandler.getException(status));
49         assertEquals(
50                 "Error, getException() did not return the correct neutron API service error",
51                 HttpURLConnection.HTTP_NOT_ACCEPTABLE,
52                 AbstractHandler.getException(status));
53         assertEquals(
54                 "Error, getException() did not return the correct neutron API service error",
55                 HttpURLConnection.HTTP_NOT_FOUND,
56                 AbstractHandler.getException(status));
57         assertEquals(
58                 "Error, getException() did not return the correct neutron API service error",
59                 HttpURLConnection.HTTP_INTERNAL_ERROR,
60                 AbstractHandler.getException(status));
61     }
62
63     @Test
64     public void testEnqueueEvent(){
65         EventDispatcher eventDispatcher = mock(EventDispatcher.class);
66
67         verifyNoMoreInteractions(eventDispatcher);
68         eventDispatcher.enqueueEvent(mock(AbstractEvent.class));
69         verify(eventDispatcher, times(1)).enqueueEvent(any(AbstractEvent.class));
70     }
71 }