2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.apihandlerinfra;
23 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertThat;
26 import java.io.IOException;
27 import java.nio.file.Files;
28 import java.nio.file.Paths;
29 import java.text.ParseException;
30 import javax.ws.rs.core.MediaType;
31 import javax.ws.rs.core.Response;
32 import org.json.JSONException;
33 import org.junit.Test;
34 import org.onap.so.apihandlerinfra.workflowspecificationbeans.WorkflowSpecifications;
35 import org.springframework.http.HttpEntity;
36 import org.springframework.http.HttpHeaders;
37 import org.springframework.http.HttpMethod;
38 import org.springframework.http.ResponseEntity;
39 import org.springframework.web.util.UriComponentsBuilder;
40 import com.fasterxml.jackson.core.JsonParseException;
41 import com.fasterxml.jackson.databind.DeserializationFeature;
42 import com.fasterxml.jackson.databind.JsonMappingException;
43 import com.fasterxml.jackson.databind.ObjectMapper;
45 public class WorkflowSpecificationsHandlerTest extends BaseTest {
47 private final String basePath = "onap/so/infra/workflowSpecifications/v1/workflows";
50 public void getTasksTestByOriginalRequestId()
51 throws ParseException, JSONException, JsonParseException, JsonMappingException, IOException {
53 HttpHeaders headers = new HttpHeaders();
54 headers.set("Accept", MediaType.APPLICATION_JSON);
55 headers.set("Content-Type", MediaType.APPLICATION_JSON);
56 HttpEntity<String> entity = new HttpEntity<String>(null, headers);
58 UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(basePath))
59 .queryParam("vnfModelVersionId", "b5fa707a-f55a-11e7-a796-005056856d52");
61 ResponseEntity<String> response =
62 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
64 ObjectMapper mapper = new ObjectMapper();
66 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
68 WorkflowSpecifications expectedResponse = mapper.readValue(
69 new String(Files.readAllBytes(Paths.get("src/test/resources/__files/WorkflowSpecifications.json"))),
70 WorkflowSpecifications.class);
72 assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
73 WorkflowSpecifications realResponse = mapper.readValue(response.getBody(), WorkflowSpecifications.class);
74 assertThat(realResponse, sameBeanAs(expectedResponse));
75 assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
76 assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
77 assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
78 assertEquals("1.0.0", response.getHeaders().get("X-LatestVersion").get(0));