2 * Copyright (c) 2016 Cisco Systems, Inc. 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.groupbasedpolicy.renderer.ofoverlay.statistics;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertSame;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.when;
17 import com.sun.jersey.api.client.ClientHandlerException;
18 import com.sun.jersey.api.client.ClientResponse;
19 import com.sun.jersey.api.client.UniformInterfaceException;
20 import org.junit.Before;
21 import org.junit.Test;
23 public class JsonRestClientResponseTest {
25 private static final String STRING_ENTITY = "string entity";
26 private ClientResponse clientResponse;
30 clientResponse = mock(ClientResponse.class);
35 public void testResponse_Ok() {
36 when(clientResponse.getEntity(String.class)).thenReturn(STRING_ENTITY);
37 when(clientResponse.getStatus()).thenReturn(200);
38 JsonRestClientResponse response = new JsonRestClientResponse(clientResponse);
40 assertSame(clientResponse, response.getClientResponse());
41 assertEquals(STRING_ENTITY, response.getJsonResponse());
42 assertEquals(200, response.getStatusCode());
43 assertNull(response.getClientHandlerException());
47 public void testResponse_UniformInterfaceException() {
48 UniformInterfaceException ex = new UniformInterfaceException(clientResponse);
49 when(clientResponse.getEntity(String.class)).thenThrow(ex);
50 when(clientResponse.getStatus()).thenReturn(204);
52 JsonRestClientResponse response = new JsonRestClientResponse(clientResponse);
54 assertNull(response.getJsonResponse());
55 assertEquals(204, response.getStatusCode());
56 assertNull(response.getClientHandlerException());
60 public void testResponse_ClientHandlerException() {
61 ClientHandlerException ex = new ClientHandlerException();
62 when(clientResponse.getEntity(String.class)).thenThrow(ex);
63 when(clientResponse.getStatus()).thenReturn(404);
65 JsonRestClientResponse response = new JsonRestClientResponse(clientResponse);
67 assertNull(response.getJsonResponse());
68 assertEquals(404, response.getStatusCode());
69 assertSame(ex, response.getClientHandlerException());