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.netvirt.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.netvirt.openstack.netvirt.api.StatusCode;
27 import org.opendaylight.netvirt.openstack.netvirt.api.EventDispatcher;
28 import org.opendaylight.netvirt.openstack.netvirt.api.Status;
31 * Unit test for {@link AbstractHandler}
33 @RunWith(MockitoJUnitRunner.class)
34 public class AbstractHandlerTest {
36 @InjectMocks private AbstractHandler abstractHandler = mock(AbstractHandler.class, Mockito.CALLS_REAL_METHODS);
37 @Mock private EventDispatcher eventDispatcher;
40 public void testGetException() {
41 Status status = mock(Status.class);
43 when(status.getCode())
44 .thenReturn(StatusCode.BADREQUEST)
45 .thenReturn(StatusCode.CONFLICT)
46 .thenReturn(StatusCode.NOTACCEPTABLE)
47 .thenReturn(StatusCode.NOTFOUND)
48 .thenReturn(StatusCode.GONE);
51 "Error, getException() did not return the correct neutron API service error",
52 HttpURLConnection.HTTP_BAD_REQUEST,
53 AbstractHandler.getException(status));
55 "Error, getException() did not return the correct neutron API service error",
56 HttpURLConnection.HTTP_CONFLICT,
57 AbstractHandler.getException(status));
59 "Error, getException() did not return the correct neutron API service error",
60 HttpURLConnection.HTTP_NOT_ACCEPTABLE,
61 AbstractHandler.getException(status));
63 "Error, getException() did not return the correct neutron API service error",
64 HttpURLConnection.HTTP_NOT_FOUND,
65 AbstractHandler.getException(status));
67 "Error, getException() did not return the correct neutron API service error",
68 HttpURLConnection.HTTP_INTERNAL_ERROR,
69 AbstractHandler.getException(status));
73 public void testEnqueueEvent() throws Exception {
74 abstractHandler.enqueueEvent(mock(AbstractEvent.class));
75 verify(eventDispatcher, times(1)).enqueueEvent(any(AbstractEvent.class));