2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.get;
25 import static com.github.tomakehurst.wiremock.client.WireMock.post;
26 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
28 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertThat;
32 import java.io.IOException;
33 import java.text.ParseException;
34 import java.util.ArrayList;
35 import java.util.List;
37 import javax.ws.rs.core.MediaType;
38 import javax.ws.rs.core.Response;
40 import org.apache.http.HttpStatus;
41 import org.json.JSONException;
42 import org.junit.Test;
43 import org.onap.so.apihandlerinfra.tasksbeans.TaskList;
44 import org.onap.so.apihandlerinfra.tasksbeans.TasksGetResponse;
45 import org.onap.so.apihandlerinfra.tasksbeans.ValidResponses;
46 import org.springframework.http.HttpEntity;
47 import org.springframework.http.HttpHeaders;
48 import org.springframework.http.HttpMethod;
49 import org.springframework.http.ResponseEntity;
50 import org.springframework.web.util.UriComponentsBuilder;
52 import com.fasterxml.jackson.core.JsonParseException;
53 import com.fasterxml.jackson.databind.DeserializationFeature;
54 import com.fasterxml.jackson.databind.JsonMappingException;
55 import com.fasterxml.jackson.databind.ObjectMapper;
57 public class TasksHandlerTest extends BaseTest{
59 private final String basePath = "onap/so/infra/tasks/v1";
62 public void getTasksTestByOriginalRequestId() throws ParseException, JSONException, JsonParseException, JsonMappingException, IOException{
63 stubFor(post(urlPathEqualTo("/sobpmnengine/task"))
64 .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("Camunda/GetTaskResponse.json").withStatus(HttpStatus.SC_OK)));
66 stubFor(get(urlPathEqualTo("/sobpmnengine/task/b5fa707a-f55a-11e7-a796-005056856d52/variables"))
67 .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("Camunda/GetTaskVariablesResponse.json").withStatus(HttpStatus.SC_OK)));
69 String requestId = "4f6fe9ac-800c-4540-a93e-10d179fa1b0a";
72 TasksGetResponse expectedResponse = new TasksGetResponse();
74 List<TaskList> taskList = new ArrayList<TaskList>();
75 TaskList taskList1 = new TaskList();
76 List<String> validEntries = new ArrayList<String>();
77 validEntries.add(ValidResponses.rollback.toString());
78 validEntries.add(ValidResponses.skip.toString());
79 validEntries.add(ValidResponses.manual.toString());
80 validEntries.add(ValidResponses.abort.toString());
81 taskList1.setBuildingBlockName("UpdateConfigurationState");
82 taskList1.setBuildingBlockStep("Configurationactivate SDNO Post-Check");
83 taskList1.setErrorCode("1002");
84 taskList1.setErrorSource("SDNO");
85 taskList1.setErrorMessage("SDN-O exception: failed with message FAIL - AnsibleOperations exception: Failed : HTTP error code : 400 - Error Msg : no node list provided and no inventory file found");
86 taskList1.setNfRole("VPROBE");
87 taskList1.setType("fallout");
88 taskList1.setOriginalRequestId(requestId);
89 taskList1.setOriginalRequestorId("VID");
90 taskList1.setSubscriptionServiceType("PORT-MIRROR");
91 taskList1.setTaskId("b5fa707a-f55a-11e7-a796-005056856d52");
92 taskList1.setValidResponses(validEntries);
93 taskList.add(taskList1);
95 expectedResponse.setTaskList(taskList);
96 HttpHeaders headers = new HttpHeaders();
97 headers.set("Accept", MediaType.APPLICATION_JSON);
98 headers.set("Content-Type", MediaType.APPLICATION_JSON);
99 HttpEntity<String> entity = new HttpEntity<String>(null, headers);
101 UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(basePath))
102 .queryParam("taskId", "b5fa707a-f55a-11e7-a796-005056856d52");
104 ResponseEntity<String> response = restTemplate.exchange(
105 builder.toUriString(),
106 HttpMethod.GET, entity, String.class);
108 ObjectMapper mapper = new ObjectMapper();
110 mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
114 assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value());
115 TasksGetResponse realResponse = mapper.readValue(response.getBody(), TasksGetResponse.class);
116 assertThat(realResponse, sameBeanAs(expectedResponse));
117 assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
118 assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
119 assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
120 assertEquals("1.0.0", response.getHeaders().get("X-LatestVersion").get(0));