Adjust sparky parent pom
[aai/sparky-be.git] / sparkybe-onap-service / src / test / java / org / onap / aai / sparky / viewandinspect / SchemaVisualizationProcessorTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.aai.sparky.viewandinspect;
23
24 import static org.junit.Assert.assertEquals;
25
26 import java.io.IOException;
27
28 import javax.servlet.http.HttpServletRequest;
29
30 import org.apache.camel.CamelContext;
31 import org.apache.camel.Exchange;
32 import org.apache.camel.Message;
33 import org.apache.camel.impl.DefaultCamelContext;
34 import org.apache.camel.impl.DefaultExchange;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.mockito.Mockito;
38 import org.onap.aai.sparky.util.HttpServletHelper;
39 import org.onap.aai.sparky.viewandinspect.entity.QueryRequest;
40 import org.onap.aai.sparky.viewandinspect.util.SchemaVisualizationTestDataBuilder;
41
42 import com.fasterxml.jackson.annotation.JsonInclude.Include;
43 import com.fasterxml.jackson.core.JsonParseException;
44 import com.fasterxml.jackson.databind.JsonMappingException;
45 import com.fasterxml.jackson.databind.ObjectMapper;
46
47 public class SchemaVisualizationProcessorTest {
48
49   SchemaVisualizationProcessor schemaVisProcessor;
50   VisualizationService mockVisualizationService;
51   
52   private Exchange exchange;
53   private CamelContext camelContext;
54   private Message  mockRequestMessage;
55   
56   @Before
57   public void init() throws Exception {
58       schemaVisProcessor = new SchemaVisualizationProcessor();
59      
60       mockVisualizationService = Mockito.mock(VisualizationService.class);
61
62       camelContext = new DefaultCamelContext();
63       exchange = new DefaultExchange(camelContext);
64     
65       mockRequestMessage = Mockito.mock(Message.class);
66       
67       exchange.setIn(mockRequestMessage);
68       
69   }
70   
71   @Test
72   public void testProcessVisualizationRequest() throws JsonParseException, JsonMappingException, IOException {
73     
74     String queryRequest = SchemaVisualizationTestDataBuilder.getQueryRequest();
75     HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
76     HttpServletHelper.setRequestPayload(request, "application/json", queryRequest);
77     
78     Mockito.when(request.getRequestURI()).thenReturn("fakeUri");
79     Mockito.when(request.getLocalPort()).thenReturn(8001);
80     Mockito.when(mockRequestMessage.getBody(Mockito.eq(HttpServletRequest.class))).thenReturn(request);
81     Mockito.when(mockRequestMessage.getBody(Mockito.eq(String.class))).thenReturn(queryRequest);
82     
83     ObjectMapper nonEmptyMapper = new ObjectMapper();
84     nonEmptyMapper.setSerializationInclusion(Include.NON_EMPTY);
85     QueryRequest queryBody = nonEmptyMapper.readValue(queryRequest, QueryRequest.class);
86     
87     Mockito.when(mockVisualizationService.analyzeQueryRequestBody(Mockito.anyString())).thenReturn(queryBody);
88     Mockito.when(mockVisualizationService.buildVisualization(Mockito.anyObject())).thenReturn(SchemaVisualizationTestDataBuilder.getSchemaVisResult());
89
90     schemaVisProcessor.setVisualizationService(mockVisualizationService);
91     schemaVisProcessor.processVisualizationRequest(exchange);
92     
93     assertEquals("{}", exchange.getOut().getBody(String.class));
94     assertEquals(200, exchange.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
95
96   }
97   
98 }