Use interfaces rather than classes where appropriate
[netvirt.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.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.Mock;
24 import org.mockito.Mockito;
25 import org.mockito.runners.MockitoJUnitRunner;
26 import org.opendaylight.ovsdb.openstack.netvirt.api.EventDispatcher;
27 import org.opendaylight.ovsdb.openstack.netvirt.api.Status;
28 import org.opendaylight.ovsdb.openstack.netvirt.api.StatusCode;
29 /**
30  * Unit test for {@link AbstractHandler}
31  */
32 @RunWith(MockitoJUnitRunner.class)
33 public class AbstractHandlerTest {
34
35     @InjectMocks private AbstractHandler abstractHandler = mock(AbstractHandler.class, Mockito.CALLS_REAL_METHODS);
36     @Mock private EventDispatcher eventDispatcher;
37
38     @Test
39     public void testGetException() {
40         Status status = mock(Status.class);
41
42         when(status.getCode())
43                 .thenReturn(StatusCode.BADREQUEST)
44                 .thenReturn(StatusCode.CONFLICT)
45                 .thenReturn(StatusCode.NOTACCEPTABLE)
46                 .thenReturn(StatusCode.NOTFOUND)
47                 .thenReturn(StatusCode.GONE);
48
49         assertEquals(
50                 "Error, getException() did not return the correct neutron API service error",
51                 HttpURLConnection.HTTP_BAD_REQUEST,
52                 AbstractHandler.getException(status));
53         assertEquals(
54                 "Error, getException() did not return the correct neutron API service error",
55                 HttpURLConnection.HTTP_CONFLICT,
56                 AbstractHandler.getException(status));
57         assertEquals(
58                 "Error, getException() did not return the correct neutron API service error",
59                 HttpURLConnection.HTTP_NOT_ACCEPTABLE,
60                 AbstractHandler.getException(status));
61         assertEquals(
62                 "Error, getException() did not return the correct neutron API service error",
63                 HttpURLConnection.HTTP_NOT_FOUND,
64                 AbstractHandler.getException(status));
65         assertEquals(
66                 "Error, getException() did not return the correct neutron API service error",
67                 HttpURLConnection.HTTP_INTERNAL_ERROR,
68                 AbstractHandler.getException(status));
69     }
70
71     @Test
72     public void testEnqueueEvent() throws Exception {
73         abstractHandler.enqueueEvent(mock(AbstractEvent.class));
74         verify(eventDispatcher, times(1)).enqueueEvent(any(AbstractEvent.class));
75     }
76 }