2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.sparky.util;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.Mockito;
27 import org.mockito.runners.MockitoJUnitRunner;
28 import org.onap.aai.cl.api.Logger;
29 import org.onap.aai.sparky.search.SearchServiceAdapter;
30 import org.restlet.Response;
31 import org.restlet.Server;
32 import org.restlet.engine.adapter.Call;
33 import org.restlet.engine.adapter.HttpResponse;
34 import org.restlet.ext.servlet.internal.ServletCall;
36 import static org.junit.Assert.assertNotNull;
37 import static org.junit.Assert.assertEquals;
39 import javax.servlet.http.HttpServletRequest;
40 import javax.servlet.http.HttpServletResponse;
41 @RunWith(MockitoJUnitRunner.class)
42 public class RestletUtilsTest {
44 static final String EMPTY_STRING = "";
45 RestletUtils restletUtils;
49 restletUtils = new RestletUtils();
53 public void testConvertRestletResponseToHttpServletResponse() {
54 Response restletResponse = Mockito.mock(HttpResponse.class);
55 Call call = new ServletCall(Mockito.mock(Server.class),Mockito.mock(HttpServletRequest.class),Mockito.mock(HttpServletResponse.class));
56 Mockito.when(((HttpResponse)restletResponse).getHttpCall()).thenReturn((ServletCall)call);
57 restletUtils.convertRestletResponseToHttpServletResponse(restletResponse);
61 public void testExecutePostQueryNullCheck() {
62 Logger logger = Mockito.mock(Logger.class);
63 Response response = Mockito.mock(Response.class);
64 SearchServiceAdapter search = Mockito.mock(SearchServiceAdapter.class);
65 String requestUrl = EMPTY_STRING;
66 String requestJsonPayload = EMPTY_STRING;
68 restletUtils.executePostQuery(logger,search,response,requestUrl,requestJsonPayload);
69 }catch (NullPointerException e){
75 public void testHandleRestletErrors() {
76 Logger logger = Mockito.mock(Logger.class);
77 Response response = Mockito.mock(Response.class);
78 Exception exc = Mockito.mock(Exception.class);
80 restletUtils.handleRestletErrors(logger,errorMsg,exc,response);
84 public void testSetRestletResponse() {
85 Logger logger = Mockito.mock(Logger.class);
86 Response response = Mockito.mock(Response.class);
87 Exception exc = Mockito.mock(Exception.class);
88 boolean isError = true;
89 int responseCode =200;
91 restletUtils.setRestletResponse(logger,false,responseCode,response,payload);