Add WorkflowSpecification Beans for APIH
[so.git] / mso-api-handlers / mso-api-handler-infra / src / test / java / org / onap / so / apihandlerinfra / WorkflowSpecificationsHandlerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.apihandlerinfra;
22
23 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertThat;
26
27 import java.io.IOException;
28 import java.nio.file.Files;
29 import java.nio.file.Paths;
30 import java.text.ParseException;
31
32 import javax.ws.rs.core.MediaType;
33 import javax.ws.rs.core.Response;
34
35 import org.json.JSONException;
36 import org.junit.Test;
37 import org.onap.so.apihandlerinfra.workflowspecificationbeans.WorkflowSpecifications;
38 import org.springframework.http.HttpEntity;
39 import org.springframework.http.HttpHeaders;
40 import org.springframework.http.HttpMethod;
41 import org.springframework.http.ResponseEntity;
42 import org.springframework.web.util.UriComponentsBuilder;
43
44 import com.fasterxml.jackson.core.JsonParseException;
45 import com.fasterxml.jackson.databind.DeserializationFeature;
46 import com.fasterxml.jackson.databind.JsonMappingException;
47 import com.fasterxml.jackson.databind.ObjectMapper;
48
49 public class WorkflowSpecificationsHandlerTest extends BaseTest{
50         
51         private final String basePath = "onap/so/infra/workflowSpecifications/v1/workflows";
52         
53         @Test
54         public void getTasksTestByOriginalRequestId() throws ParseException, JSONException, JsonParseException, JsonMappingException, IOException{
55                 
56                 HttpHeaders headers = new HttpHeaders();
57                 headers.set("Accept", MediaType.APPLICATION_JSON);
58                 headers.set("Content-Type", MediaType.APPLICATION_JSON);
59                 HttpEntity<String> entity = new HttpEntity<String>(null, headers);
60                 
61                 UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(basePath))
62                                 .queryParam("vnfModelVersionId", "b5fa707a-f55a-11e7-a796-005056856d52");
63                 
64                 ResponseEntity<String> response = restTemplate.exchange(
65                                 builder.toUriString(),
66                                 HttpMethod.GET, entity, String.class);
67         
68                 ObjectMapper mapper = new ObjectMapper();
69                 
70                 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
71                 
72                 WorkflowSpecifications expectedResponse = mapper.readValue(new String(Files.readAllBytes(Paths.get("src/test/resources/__files/WorkflowSpecifications.json"))), WorkflowSpecifications.class);
73
74                 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());       
75                 WorkflowSpecifications realResponse = mapper.readValue(response.getBody(), WorkflowSpecifications.class);
76                 assertThat(realResponse, sameBeanAs(expectedResponse)); 
77         assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
78         assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
79         assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
80         assertEquals("1.0.0", response.getHeaders().get("X-LatestVersion").get(0));
81         }
82 }