Adding UI extensibility
[aai/sparky-be.git] / src / test / java / org / onap / aai / sparky / dal / proxy / processor / AaiUiProxyProcessorTest.java
1 package org.onap.aai.sparky.dal.proxy.processor;
2 /**
3  * ============LICENSE_START======================================================= SPARKY (AAI UI
4  * service) ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. Copyright © 2017 Amdocs All rights reserved.
6  * ================================================================================ Licensed under
7  * the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License. ============LICENSE_END=========================================================
16  *
17  * ECOMP and OpenECOMP are trademarks and service marks of AT&T Intellectual Property.
18  */
19
20 /*
21  * package org.openecomp.sparky.dal.proxy.processor;
22  * 
23  * import static org.junit.Assert.assertEquals;
24  * 
25  * import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.MediaType;
26  * 
27  * import org.apache.camel.Exchange; import org.apache.camel.Message; import
28  * org.codehaus.groovy.grails.web.json.JSONObject; import org.junit.Before; import org.junit.Test;
29  * import org.mockito.AdditionalMatchers; import org.mockito.Matchers; import org.mockito.Mockito;
30  * import org.onap.aai.restclient.client.OperationResult; import
31  * org.onap.aai.restclient.client.RestClient; import
32  * org.openecomp.sparky.dal.proxy.config.DataRouterConfig; import org.restlet.data.Status;
33  * 
34  * public class AaiUiProxyProcessorTest {
35  * 
36  * private RestClient client = null; private OperationResult successResult = null; OperationResult
37  * failureResult = null; private Exchange mockExchange; private Message mockRequestMessage; private
38  * Message mockResponseMessage;
39  * 
40  * private HttpServletRequest mockHttpServletRequest;
41  * 
42  * private AaiUiProxyProcessor aaiUiProxyProcessor;
43  * 
44  * private String goodBeTargetUrl = "https://0.0.0.0:8000/services/routerService/servicegraph";
45  * private String badBeTargetUrl = "https://0.0.0.0:8000/aservicegraph"; private String
46  * goodDrTargetUrl = "https://0.0.0.0:9502/ui-request/servicegraph";
47  * 
48  * String successResponsePayload = "good-payload"; String failureResponsePayload = "Server Error";
49  * 
50  * @Before public void init() { client = Mockito.mock(RestClient.class); mockExchange =
51  * Mockito.mock(Exchange.class); mockRequestMessage = Mockito.mock(Message.class);
52  * mockResponseMessage = Mockito.mock(Message.class); mockHttpServletRequest =
53  * Mockito.mock(HttpServletRequest.class);
54  * 
55  * DataRouterConfig config = new DataRouterConfig(DataRouterConfigUtil.getTestProperties());
56  * aaiUiProxyProcessor = new AaiUiProxyProcessor(config);
57  * 
58  * initializeMocks(getProxyRequestJson("someHashValue")); aaiUiProxyProcessor.setClient(client); }
59  * 
60  * @Test public void testProxyMessage_successPath() { OperationResult successResultSpy =
61  * Mockito.spy(successResult); Mockito.when(client.post(Mockito.eq(goodDrTargetUrl),
62  * Mockito.anyString(), Mockito.anyMap(), Mockito.eq(MediaType.APPLICATION_JSON_TYPE),
63  * Mockito.eq(MediaType.APPLICATION_JSON_TYPE))) .thenReturn(successResultSpy);
64  * 
65  * Mockito.when(mockExchange.getIn().getHeader(Exchange.HTTP_URI)).thenReturn(goodBeTargetUrl);
66  * Mockito.when(mockExchange.getIn().getBody(HttpServletRequest.class)).thenReturn(
67  * mockHttpServletRequest); aaiUiProxyProcessor.proxyMessage(mockExchange);
68  * 
69  * Mockito.verify(successResultSpy).getResult(); assertEquals(Status.SUCCESS_OK.getCode(),
70  * aaiUiProxyProcessor.getOperationResult().getResultCode()); }
71  * 
72  * @Test public void testProxyMessage_failurePath() { OperationResult failureResultSpy =
73  * Mockito.spy(failureResult);
74  * Mockito.when(client.post(AdditionalMatchers.not(Matchers.eq(goodDrTargetUrl)),
75  * Mockito.anyString(), Mockito.anyMap(), Mockito.eq(MediaType.APPLICATION_JSON_TYPE),
76  * Mockito.eq(MediaType.APPLICATION_JSON_TYPE))).thenReturn(failureResultSpy);
77  * 
78  * Mockito.when(mockExchange.getIn().getHeader(Exchange.HTTP_URI)).thenReturn(badBeTargetUrl);
79  * Mockito.when(mockExchange.getIn().getBody(HttpServletRequest.class)).thenReturn(
80  * mockHttpServletRequest); aaiUiProxyProcessor.proxyMessage(mockExchange);
81  * 
82  * Mockito.verify(failureResultSpy).getFailureCause();
83  * assertEquals(Status.SERVER_ERROR_INTERNAL.getCode(),
84  * aaiUiProxyProcessor.getOperationResult().getResultCode()); }
85  * 
86  * private String getProxyRequestJson(String hashId) { JSONObject root = new JSONObject();
87  * root.put("hashId", hashId); return root.toString();
88  * 
89  * }
90  * 
91  * @SuppressWarnings("unchecked") private void initializeMocks(String requestPayload) {
92  * 
93  * client = Mockito.mock(RestClient.class); successResult = new OperationResult(200,
94  * successResponsePayload); failureResult = new OperationResult(500, failureResponsePayload);
95  * failureResult.setFailureCause(failureResponsePayload);
96  * 
97  * Mockito.when(client.post(Mockito.eq(goodDrTargetUrl), Mockito.anyString(), Mockito.anyMap(),
98  * Mockito.eq(MediaType.APPLICATION_JSON_TYPE), Mockito.eq(MediaType.APPLICATION_JSON_TYPE)))
99  * .thenReturn(successResult);
100  * 
101  * Mockito.when(client.post(AdditionalMatchers.not(Matchers.eq(goodDrTargetUrl)),
102  * Mockito.anyString(), Mockito.anyMap(), Mockito.eq(MediaType.APPLICATION_JSON_TYPE),
103  * Mockito.eq(MediaType.APPLICATION_JSON_TYPE))).thenReturn(failureResult);
104  * 
105  * Mockito.when(mockHttpServletRequest.getRequestURI()).thenReturn("fakeUri");
106  * Mockito.when(mockHttpServletRequest.getLocalPort()).thenReturn(8001);
107  * 
108  * Mockito.when(mockExchange.getIn()).thenReturn(mockRequestMessage);
109  * Mockito.when(mockExchange.getOut()).thenReturn(mockResponseMessage); }
110  * 
111  * }
112  */