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.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;
18 import java.net.HttpURLConnection;
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;
30 * Unit test for {@link AbstractHandler}
32 @RunWith(MockitoJUnitRunner.class)
33 public class AbstractHandlerTest {
35 @InjectMocks private AbstractHandler abstractHandler = mock(AbstractHandler.class, Mockito.CALLS_REAL_METHODS);
36 @Mock private EventDispatcher eventDispatcher;
39 public void testGetException() {
40 Status status = mock(Status.class);
42 when(status.getCode())
43 .thenReturn(StatusCode.BADREQUEST)
44 .thenReturn(StatusCode.CONFLICT)
45 .thenReturn(StatusCode.NOTACCEPTABLE)
46 .thenReturn(StatusCode.NOTFOUND)
47 .thenReturn(StatusCode.GONE);
50 "Error, getException() did not return the correct neutron API service error",
51 HttpURLConnection.HTTP_BAD_REQUEST,
52 AbstractHandler.getException(status));
54 "Error, getException() did not return the correct neutron API service error",
55 HttpURLConnection.HTTP_CONFLICT,
56 AbstractHandler.getException(status));
58 "Error, getException() did not return the correct neutron API service error",
59 HttpURLConnection.HTTP_NOT_ACCEPTABLE,
60 AbstractHandler.getException(status));
62 "Error, getException() did not return the correct neutron API service error",
63 HttpURLConnection.HTTP_NOT_FOUND,
64 AbstractHandler.getException(status));
66 "Error, getException() did not return the correct neutron API service error",
67 HttpURLConnection.HTTP_INTERNAL_ERROR,
68 AbstractHandler.getException(status));
72 public void testEnqueueEvent() throws Exception {
73 abstractHandler.enqueueEvent(mock(AbstractEvent.class));
74 verify(eventDispatcher, times(1)).enqueueEvent(any(AbstractEvent.class));