Merge "correctly generate local fields when prefix has"
[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  * Modifications Copyright (c) 2020 Nordix
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.apihandlerinfra;
24
25 import com.fasterxml.jackson.core.JsonParseException;
26 import com.fasterxml.jackson.databind.DeserializationFeature;
27 import com.fasterxml.jackson.databind.JsonMappingException;
28 import com.fasterxml.jackson.databind.ObjectMapper;
29 import org.json.JSONException;
30 import org.junit.Test;
31 import org.onap.so.apihandlerinfra.workflowspecificationbeans.WorkflowInputParameter;
32 import org.onap.so.apihandlerinfra.workflowspecificationbeans.WorkflowSpecifications;
33 import org.onap.so.db.catalog.beans.*;
34 import org.skyscreamer.jsonassert.JSONAssert;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.beans.factory.annotation.Value;
37 import org.springframework.http.HttpEntity;
38 import org.springframework.http.HttpHeaders;
39 import org.springframework.http.HttpMethod;
40 import org.springframework.http.ResponseEntity;
41 import org.springframework.util.ResourceUtils;
42 import org.springframework.web.util.UriComponentsBuilder;
43 import javax.ws.rs.core.MediaType;
44 import javax.ws.rs.core.Response;
45 import java.io.File;
46 import java.io.IOException;
47 import java.nio.file.Files;
48 import java.nio.file.Paths;
49 import java.text.ParseException;
50 import java.util.ArrayList;
51 import java.util.List;
52 import static com.github.tomakehurst.wiremock.client.WireMock.*;
53 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
54 import static org.junit.Assert.assertEquals;
55 import static org.junit.Assert.assertThat;
56
57 public class WorkflowSpecificationsHandlerTest extends BaseTest {
58     @Autowired
59     WorkflowSpecificationsHandler workflowSpecificationsHandler;
60
61     @Autowired
62     ObjectMapper mapper;
63
64     @Value("${wiremock.server.port}")
65     private String wiremockPort;
66
67     private final String basePath = "onap/so/infra/workflowSpecifications";
68
69     @Test
70     public void queryWorkflowSpecificationsByVnfModelUUID_Test_Success()
71             throws ParseException, JSONException, JsonParseException, JsonMappingException, IOException {
72
73         final String urlPath = basePath + "/v1/workflows";
74         HttpHeaders headers = new HttpHeaders();
75         headers.set("Accept", MediaType.APPLICATION_JSON);
76         headers.set("Content-Type", MediaType.APPLICATION_JSON);
77         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
78
79         wireMockServer.stubFor(get(urlMatching(
80                 "/workflow/search/findWorkflowByVnfModelUUID[?]vnfResourceModelUUID=b5fa707a-f55a-11e7-a796-005056856d52"))
81                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
82                                 .withBody(getWiremockResponseForCatalogdb("WorkflowSpecificationsQuery_Response.json"))
83                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
84
85         wireMockServer.stubFor(get(urlMatching("/workflow/1/workflowActivitySpecSequence"))
86                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
87                         .withBody(getWiremockResponseForCatalogdb("WorkflowActivitySpecSequence_Response.json"))
88                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
89
90         wireMockServer.stubFor(get(urlMatching("/workflowActivitySpecSequence/1/activitySpec"))
91                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
92                         .withBody(getWiremockResponseForCatalogdb("ActivitySpecSequence1_Response.json"))
93                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
94
95         wireMockServer.stubFor(get(urlMatching("/workflowActivitySpecSequence/2/activitySpec"))
96                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
97                         .withBody(getWiremockResponseForCatalogdb("ActivitySpecSequence2_Response.json"))
98                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
99
100         wireMockServer.stubFor(get(urlMatching("/workflowActivitySpecSequence/3/activitySpec"))
101                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
102                         .withBody(getWiremockResponseForCatalogdb("ActivitySpecSequence3_Response.json"))
103                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
104
105         wireMockServer.stubFor(get(urlMatching("/activitySpec/1/activitySpecUserParameters"))
106                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
107                         .withBody(getWiremockResponseForCatalogdb("ActivitySpecUserParameters1_Response.json"))
108                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
109
110         wireMockServer.stubFor(get(urlMatching("/activitySpec/2/activitySpecUserParameters"))
111                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
112                         .withBody(getWiremockResponseForCatalogdb("ActivitySpecUserParameters2_Response.json"))
113                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
114
115         wireMockServer.stubFor(get(urlMatching("/activitySpec/3/activitySpecUserParameters"))
116                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
117                         .withBody(getWiremockResponseForCatalogdb("ActivitySpecUserParameters3_Response.json"))
118                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
119
120         wireMockServer.stubFor(get(urlMatching("/activitySpecUserParameters/1/userParameters"))
121                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
122                         .withBody(getWiremockResponseForCatalogdb("UserParameters1_Response.json"))
123                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
124
125         wireMockServer.stubFor(get(urlMatching("/activitySpecUserParameters/2/userParameters"))
126                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
127                         .withBody(getWiremockResponseForCatalogdb("UserParameters2_Response.json"))
128                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
129
130         wireMockServer.stubFor(get(urlMatching("/activitySpecUserParameters/3/userParameters"))
131                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
132                         .withBody(getWiremockResponseForCatalogdb("UserParameters3_Response.json"))
133                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
134
135         wireMockServer.stubFor(get(urlMatching("/activitySpecUserParameters/4/userParameters"))
136                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
137                         .withBody(getWiremockResponseForCatalogdb("UserParameters4_Response.json"))
138                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
139
140         wireMockServer.stubFor(get(urlMatching("/activitySpecUserParameters/5/userParameters"))
141                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
142                         .withBody(getWiremockResponseForCatalogdb("UserParameters5_Response.json"))
143                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
144
145         wireMockServer.stubFor(get(urlMatching("/activitySpecUserParameters/6/userParameters"))
146                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
147                         .withBody(getWiremockResponseForCatalogdb("UserParameters6_Response.json"))
148                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
149
150         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(urlPath))
151                 .queryParam("vnfModelVersionId", "b5fa707a-f55a-11e7-a796-005056856d52");
152
153         ResponseEntity<String> response =
154                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
155
156         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
157
158         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
159
160         WorkflowSpecifications expectedResponse = mapper.readValue(
161                 new String(Files
162                         .readAllBytes(Paths.get("src/test/resources/__files/catalogdb/WorkflowSpecifications.json"))),
163                 WorkflowSpecifications.class);
164         WorkflowSpecifications realResponse = mapper.readValue(response.getBody(), WorkflowSpecifications.class);
165
166         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
167         assertThat(expectedResponse, sameBeanAs(realResponse));
168         assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
169         assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
170         assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
171         assertEquals("1.0.0", response.getHeaders().get("X-LatestVersion").get(0));
172     }
173
174     @Test
175     public void mapWorkflowsToWorkflowSpecifications_Test_Success() throws Exception {
176         List<Workflow> workflows = new ArrayList<>();
177         Workflow workflow = new Workflow();
178         workflow.setArtifactUUID("ab6478e4-ea33-3346-ac12-ab121484a333");
179         workflow.setArtifactName("inPlaceSoftwareUpdate-1_0.bpmn");
180         workflow.setVersion(1.0);
181         workflow.setDescription("xyz xyz");
182         workflow.setName("inPlaceSoftwareUpdate");
183         workflow.setOperationName("inPlaceSoftwareUpdate");
184         workflow.setSource("sdc");
185         workflow.setResourceTarget("vnf");
186
187         UserParameters userParameter1 = new UserParameters();
188         userParameter1.setLabel("Operations Timeout");
189         userParameter1.setType("text");
190         userParameter1.setIsRequried(true);
191         userParameter1.setMaxLength(50);
192         userParameter1.setAllowableChars("someRegEx");
193         userParameter1.setName("operations_timeout");
194         userParameter1.setPayloadLocation("userParams");
195
196         UserParameters userParameter2 = new UserParameters();
197         userParameter2.setLabel("Existing Software Version");
198         userParameter2.setType("text");
199         userParameter2.setIsRequried(true);
200         userParameter2.setMaxLength(50);
201         userParameter2.setAllowableChars("someRegEx");
202         userParameter2.setName("existing_software_version");
203         userParameter2.setPayloadLocation("userParams");
204
205         UserParameters userParameter3 = new UserParameters();
206         userParameter3.setLabel("Cloud Owner");
207         userParameter3.setType("text");
208         userParameter3.setIsRequried(true);
209         userParameter3.setMaxLength(7);
210         userParameter3.setAllowableChars("someRegEx");
211         userParameter3.setName("cloudOwner");
212         userParameter3.setPayloadLocation("cloudConfiguration");
213
214         UserParameters userParameter4 = new UserParameters();
215         userParameter4.setLabel("Tenant/Project ID");
216         userParameter4.setType("text");
217         userParameter4.setIsRequried(true);
218         userParameter4.setMaxLength(36);
219         userParameter4.setAllowableChars("someRegEx");
220         userParameter4.setName("tenantId");
221         userParameter4.setPayloadLocation("cloudConfiguration");
222
223         UserParameters userParameter5 = new UserParameters();
224         userParameter5.setLabel("New Software Version");
225         userParameter5.setType("text");
226         userParameter5.setIsRequried(true);
227         userParameter5.setMaxLength(50);
228         userParameter5.setAllowableChars("someRegEx");
229         userParameter5.setName("new_software_version");
230         userParameter5.setPayloadLocation("userParams");
231
232         UserParameters userParameter6 = new UserParameters();
233         userParameter6.setLabel("Cloud Region ID");
234         userParameter6.setType("text");
235         userParameter6.setIsRequried(true);
236         userParameter6.setMaxLength(7);
237         userParameter6.setAllowableChars("someRegEx");
238         userParameter6.setName("lcpCloudRegionId");
239         userParameter6.setPayloadLocation("cloudConfiguration");
240
241
242         List<ActivitySpecUserParameters> activitySpecUserParameters = new ArrayList<ActivitySpecUserParameters>();
243
244         ActivitySpecUserParameters activitySpecUserParameter1 = new ActivitySpecUserParameters();
245         activitySpecUserParameter1.setUserParameters(userParameter1);
246         activitySpecUserParameters.add(activitySpecUserParameter1);
247
248         ActivitySpecUserParameters activitySpecUserParameter2 = new ActivitySpecUserParameters();
249         activitySpecUserParameter2.setUserParameters(userParameter2);
250         activitySpecUserParameters.add(activitySpecUserParameter2);
251
252         ActivitySpecUserParameters activitySpecUserParameter3 = new ActivitySpecUserParameters();
253         activitySpecUserParameter3.setUserParameters(userParameter3);
254         activitySpecUserParameters.add(activitySpecUserParameter3);
255
256
257         ActivitySpecUserParameters activitySpecUserParameter4 = new ActivitySpecUserParameters();
258         activitySpecUserParameter4.setUserParameters(userParameter4);
259         activitySpecUserParameters.add(activitySpecUserParameter4);
260
261         ActivitySpecUserParameters activitySpecUserParameter5 = new ActivitySpecUserParameters();
262         activitySpecUserParameter5.setUserParameters(userParameter5);
263         activitySpecUserParameters.add(activitySpecUserParameter5);
264
265         ActivitySpecUserParameters activitySpecUserParameter6 = new ActivitySpecUserParameters();
266         activitySpecUserParameter6.setUserParameters(userParameter6);
267         activitySpecUserParameters.add(activitySpecUserParameter6);
268
269         List<WorkflowActivitySpecSequence> workflowActivitySpecSequences = new ArrayList<>();
270
271         ActivitySpec activitySpec1 = new ActivitySpec();
272         activitySpec1.setName("VNFQuiesceTrafficActivity");
273         activitySpec1.setDescription("Activity to QuiesceTraffic on VNF");
274         activitySpec1.setActivitySpecUserParameters(activitySpecUserParameters);
275         WorkflowActivitySpecSequence workflowActivitySpecSequence1 = new WorkflowActivitySpecSequence();
276         workflowActivitySpecSequence1.setActivitySpec(activitySpec1);
277         workflowActivitySpecSequences.add(workflowActivitySpecSequence1);
278
279         ActivitySpec activitySpec2 = new ActivitySpec();
280         activitySpec2.setName("VNFHealthCheckActivity");
281         activitySpec2.setDescription("Activity to HealthCheck VNF");
282         activitySpec2.setActivitySpecUserParameters(activitySpecUserParameters);
283         WorkflowActivitySpecSequence workflowActivitySpecSequence2 = new WorkflowActivitySpecSequence();
284         workflowActivitySpecSequence2.setActivitySpec(activitySpec2);
285         workflowActivitySpecSequences.add(workflowActivitySpecSequence2);
286
287         ActivitySpec activitySpec3 = new ActivitySpec();
288         activitySpec3.setName("FlowCompleteActivity");
289         activitySpec3.setDescription("Activity to Complete the BPMN Flow");
290         activitySpec3.setActivitySpecUserParameters(activitySpecUserParameters);
291         WorkflowActivitySpecSequence workflowActivitySpecSequence3 = new WorkflowActivitySpecSequence();
292         workflowActivitySpecSequence3.setActivitySpec(activitySpec3);
293         workflowActivitySpecSequences.add(workflowActivitySpecSequence3);
294
295         workflow.setWorkflowActivitySpecSequence(workflowActivitySpecSequences);
296         workflows.add(workflow);
297
298         Workflow workflowNative = new Workflow();
299         workflowNative.setArtifactUUID("da6478e4-ea33-3346-ac12-ab121284a333");
300         workflowNative.setArtifactName("VnfInPlaceUpdate.bpmn");
301         workflowNative.setVersion(1.0);
302         workflowNative.setDescription("native workflow");
303         workflowNative.setName("VnfInPlaceUpdate");
304         workflowNative.setOperationName("inPlaceSoftwareUpdate");
305         workflowNative.setSource("native");
306         workflowNative.setResourceTarget("vnf");
307         workflows.add(workflowNative);
308
309         WorkflowSpecifications workflowSpecifications =
310                 workflowSpecificationsHandler.mapWorkflowsToWorkflowSpecifications(workflows);
311
312         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
313         String workflowSpecificationsJson = mapper.writeValueAsString(workflowSpecifications);
314         WorkflowSpecifications expectedResult = mapper.readValue(
315                 new String(Files
316                         .readAllBytes(Paths.get("src/test/resources/__files/catalogdb/WorkflowSpecifications.json"))),
317                 WorkflowSpecifications.class);
318         String expectedResultJson = mapper.writeValueAsString(expectedResult);
319
320         JSONAssert.assertEquals(expectedResultJson, workflowSpecificationsJson, false);
321         assertThat(expectedResult, sameBeanAs(workflowSpecifications).ignoring(WorkflowInputParameter.class));
322     }
323
324     @Test
325     public void queryWorkflowSpecificationsByPnfModelUUID_Test_Success() throws JSONException, IOException {
326
327         final String urlPath = basePath + "/v1/workflows";
328         HttpHeaders headers = new HttpHeaders();
329         headers.set("Accept", MediaType.APPLICATION_JSON);
330         headers.set("Content-Type", MediaType.APPLICATION_JSON);
331         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
332
333         wireMockServer.stubFor(get(urlMatching(
334                 "/workflow/search/findWorkflowByPnfModelUUID[?]pnfResourceModelUUID=f2d1f2b2-88bb-49da-b716-36ae420ccbff"))
335                         .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
336                                 .withBody(getWiremockResponseForCatalogdb(
337                                         "WorkflowSpecificationsForPnfQuery_Response.json"))
338                                 .withStatus(org.apache.http.HttpStatus.SC_OK)));
339
340         wireMockServer.stubFor(get(urlMatching("/workflow/4/workflowActivitySpecSequence"))
341                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
342                         .withBody(getWiremockResponseForCatalogdb("Empty_workflowActivitySpecSequence_Response.json"))
343                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
344
345         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(urlPath))
346                 .queryParam("pnfModelVersionId", "f2d1f2b2-88bb-49da-b716-36ae420ccbff");
347
348         ResponseEntity<String> response =
349                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
350
351         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
352
353         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
354
355         WorkflowSpecifications expectedResponse = mapper.readValue(
356                 new String(Files.readAllBytes(
357                         Paths.get("src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnf.json"))),
358                 WorkflowSpecifications.class);
359         WorkflowSpecifications realResponse = mapper.readValue(response.getBody(), WorkflowSpecifications.class);
360
361         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
362         assertThat(expectedResponse, sameBeanAs(realResponse));
363         assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
364         assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
365         assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
366         assertEquals("1.0.0", response.getHeaders().get("X-LatestVersion").get(0));
367     }
368
369     @Test
370     public void queryWorkflowSpecificationsByResourceTarget_Test_Success() throws JSONException, IOException {
371
372         String URL_PATH = basePath + "/v1/workflows";
373         HttpHeaders headers = new HttpHeaders();
374         headers.set("Accept", MediaType.APPLICATION_JSON);
375         headers.set("Content-Type", MediaType.APPLICATION_JSON);
376         HttpEntity<String> entity = new HttpEntity<String>(null, headers);
377         String WORKFLOW_QUERY = "/workflow/search/findByResourceTarget[?]resourceTarget=service";
378         String WORKFLOW_SPEC_QUERY = "/workflow/5/workflowActivitySpecSequence";
379         String JSON_FILE_PATH = "src/test/resources/__files/catalogdb/WorkflowSpecificationsForService.json";
380         String MOCK_RESP_FILE = "WorkflowSpecificationsForServiceWorkflows_Response.json";
381         String MOCK_RESP_SPEC_FILE = "Empty_workflowActivitySpecSequence_Response.json";
382
383         wireMockServer.stubFor(get(urlMatching(WORKFLOW_QUERY))
384                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
385                         .withBody(getWiremockResponseForCatalogdb(MOCK_RESP_FILE))
386                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
387
388         wireMockServer.stubFor(get(urlMatching(WORKFLOW_SPEC_QUERY))
389                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
390                         .withBody(getWiremockResponseForCatalogdb(MOCK_RESP_SPEC_FILE))
391                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
392
393         UriComponentsBuilder builder =
394                 UriComponentsBuilder.fromHttpUrl(createURLWithPort(URL_PATH)).queryParam("resourceTarget", "service");
395
396         ResponseEntity<String> response =
397                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
398
399         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
400
401         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
402
403         WorkflowSpecifications expectedResponse = mapper
404                 .readValue(new String(Files.readAllBytes(Paths.get(JSON_FILE_PATH))), WorkflowSpecifications.class);
405         WorkflowSpecifications realResponse = mapper.readValue(response.getBody(), WorkflowSpecifications.class);
406
407         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
408         assertThat(expectedResponse, sameBeanAs(realResponse));
409         assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
410         assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
411         assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
412         assertEquals("1.0.0", response.getHeaders().get("X-LatestVersion").get(0));
413     }
414
415     @Test
416     public void testWorkflowSpecificationsForPnf_Success() throws JSONException, IOException {
417
418         final String urlPath = basePath + "/v1/pnfWorkflows";
419         HttpHeaders headers = new HttpHeaders();
420         headers.set("Accept", MediaType.APPLICATION_JSON);
421         headers.set("Content-Type", MediaType.APPLICATION_JSON);
422         HttpEntity<String> entity = new HttpEntity(null, headers);
423
424         wireMockServer.stubFor(get(urlMatching("/workflow/search/findByResourceTarget[?]resourceTarget=pnf"))
425                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
426                         .withBody(
427                                 getWiremockResponseForCatalogdb("WorkflowSpecificationsForPnfWorkflows_Response.json"))
428                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
429
430         wireMockServer.stubFor(get(urlMatching("/infraActiveRequests.*"))
431                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
432                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
433
434         wireMockServer.stubFor(get(urlMatching("/workflow/1/workflowActivitySpecSequence"))
435                 .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
436                         .withBody(getWiremockResponseForCatalogdb("Empty_workflowActivitySpecSequence_Response.json"))
437                         .withStatus(org.apache.http.HttpStatus.SC_OK)));
438
439         UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(urlPath));
440
441         ResponseEntity<String> response =
442                 restTemplate.exchange(builder.toUriString(), HttpMethod.GET, entity, String.class);
443
444         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
445
446         mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
447
448         WorkflowSpecifications expectedResponse = mapper.readValue(
449                 new String(Files.readAllBytes(
450                         Paths.get("src/test/resources/__files/catalogdb/WorkflowSpecificationsForPnf.json"))),
451                 WorkflowSpecifications.class);
452         WorkflowSpecifications realResponse = mapper.readValue(response.getBody(), WorkflowSpecifications.class);
453
454         assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
455         assertThat(expectedResponse, sameBeanAs(realResponse));
456         assertEquals("application/json", response.getHeaders().get(HttpHeaders.CONTENT_TYPE).get(0));
457         assertEquals("0", response.getHeaders().get("X-MinorVersion").get(0));
458         assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0));
459         assertEquals("1.0.0", response.getHeaders().get("X-LatestVersion").get(0));
460     }
461
462     private String getWiremockResponseForCatalogdb(String file) {
463         try {
464             File resource = ResourceUtils.getFile("classpath:__files/catalogdb/" + file);
465             return new String(Files.readAllBytes(resource.toPath())).replaceAll("localhost:8090",
466                     "localhost:" + wiremockPort);
467         } catch (IOException e) {
468             e.printStackTrace();
469             return null;
470         }
471     }
472 }