diff options
author | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2018-08-28 10:23:08 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2018-08-28 10:31:34 -0400 |
commit | 1ffe9a2d3bec70d522ff65b72b6b2726e9ce7de6 (patch) | |
tree | e8069fe77c5d208f1afac722e71496607d2d4090 /mso-api-handlers/mso-api-handler-infra/src/test/java/org | |
parent | eb94991c543a1d9cf3c9b6c4dfca921dedf48da5 (diff) |
Converted ServiceInstances to catalog db client
- Fixed issues related to created Date Format, enabled required Test
- Fixed issues related to queryParam names, enabled required Test
- Fixed issues related to queryParam names
- Improving coverage for catalogDbClient by another 10% (its 78% now)
- Improving coverage for catalogDbClient by another 10%. There is a
failing test which will be explored shortly
- Improving coverage for catalogDbClient, adding some tests and their
basic asserts
- merging with dev and resolving the compilation issue arising due to it
- Removing some TODO introduced in code for incremental pushes
- Fixing failing unit test cases with the build
- Refactoring done for code change in catalogDBClient
- merged changes with development branch
- Modified unit tests for Catalogdb Client related code
- Modified unit tests for Catalogdb Client related code
- Fixed some of the repository code for retrieving single resource
- Modified unit tests for Catalogdb Client related code
- Modified unit tests for Catalogdb Client related code
- Modified unit tests for Catalogdb Client related code
- Removed @Param from repositories and added -Parameters argument in
maven compile plugin
...
Change-Id: Ieeb7bcc21a573465e485fedfbbe771c8b89db3f8
Issue-ID: SO-925
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/test/java/org')
-rw-r--r-- | mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java | 1257 |
1 files changed, 973 insertions, 284 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java index 48d424c8d1..5b37d772c6 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java @@ -21,33 +21,17 @@ package org.onap.so.apihandlerinfra; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.List; -import java.util.Map; - -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.apache.log4j.MDC; -import org.junit.Ignore; +import ch.qos.logback.classic.spi.ILoggingEvent; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.tomakehurst.wiremock.http.Fault; +import org.apache.http.HttpStatus; +import org.junit.Before; import org.junit.Test; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.catalog.beans.ServiceRecipe; import org.onap.so.db.request.beans.InfraActiveRequests; -import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository; import org.onap.so.logger.MsoLogger; import org.onap.so.serviceinstancebeans.CloudConfiguration; import org.onap.so.serviceinstancebeans.ModelInfo; @@ -57,50 +41,84 @@ import org.onap.so.serviceinstancebeans.RequestReferences; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.onap.so.serviceinstancebeans.ServiceInstancesResponse; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; +import org.springframework.util.ResourceUtils; import org.springframework.web.util.UriComponentsBuilder; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.github.tomakehurst.wiremock.http.Fault; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.List; +import java.util.Map; -import ch.qos.logback.classic.spi.ILoggingEvent; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; public class ServiceInstancesTest extends BaseTest{ - @Autowired - private InfraActiveRequestsRepository iar; - + private final ObjectMapper mapper = new ObjectMapper(); + @Autowired private ServiceInstances servInstances; + @Value("${wiremock.server.port}") + private String wiremockPort; + private final String servInstanceuri = "/onap/so/infra/serviceInstantiation/"; private final String servInstanceUriPrev7 = "/onap/so/infra/serviceInstances/"; private String uri; + @Before + public void beforeClass() { + stubFor(post(urlMatching(".*/infraActiveRequests.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withStatus(HttpStatus.SC_OK))); + } + public String inputStream(String JsonInput)throws IOException{ JsonInput = "src/test/resources/ServiceInstanceTest" + JsonInput; - String input = new String(Files.readAllBytes(Paths.get(JsonInput))); - return input; + return new String(Files.readAllBytes(Paths.get(JsonInput))); } + private String getWiremockResponseForCatalogdb(String file) { + try { + File resource= ResourceUtils.getFile("classpath:__files/catalogdb/"+file); + return new String(Files.readAllBytes(resource.toPath())).replaceAll("localhost:8090","localhost:"+wiremockPort); + } catch (IOException e) { + e.printStackTrace(); + return null; + } + + } + + public ResponseEntity<String> sendRequest(String requestJson, String uriPath, HttpMethod reqMethod){ headers.set("Accept", MediaType.APPLICATION_JSON); - headers.set("Content-Type",MediaType.APPLICATION_JSON); + headers.set(HttpHeaders.CONTENT_TYPE,MediaType.APPLICATION_JSON); UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(uriPath)); - HttpEntity<String> request = new HttpEntity<String>(requestJson, headers); - ResponseEntity<String> response = restTemplate.exchange(builder.toUriString(), - reqMethod, request, String.class); + HttpEntity<String> request = new HttpEntity<>(requestJson, headers); - return response; + return restTemplate.exchange(builder.toUriString(), + reqMethod, request, String.class); } @Test @@ -118,13 +136,34 @@ public class ServiceInstancesTest extends BaseTest{ } @Test - public void createServiceInstanceVIDDefault() throws JsonParseException, JsonMappingException, IOException{ + public void createServiceInstanceVIDDefault() throws IOException{ TestAppender.events.clear(); + + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB"); + serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + serviceRecipe.setAction(Action.createInstance.toString()); + serviceRecipe.setId(1); + serviceRecipe.setRecipeTimeout(180); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); - headers.set(MsoLogger.ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); + stubFor(get(urlMatching(".*/service/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/serviceRecipe/search.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)) + .withStatus(HttpStatus.SC_OK))); + + headers.set(MsoLogger.TRANSACTION_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); headers.set(MsoLogger.CLIENT_ID, "VID"); //expect ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); @@ -171,33 +210,33 @@ public class ServiceInstancesTest extends BaseTest{ assertEquals("0", response.getHeaders().get("X-PatchVersion").get(0)); assertEquals("5.0.0", response.getHeaders().get("X-LatestVersion").get(0)); } - - //ExpectedRecord - InfraActiveRequests expectedRecord = new InfraActiveRequests(); - expectedRecord.setRequestStatus("IN_PROGRESS"); - expectedRecord.setRequestBody(inputStream("/ServiceInstanceDefault.json")); - expectedRecord.setAction("createInstance"); - expectedRecord.setSource("VID"); - expectedRecord.setVnfId("1882938"); - expectedRecord.setLastModifiedBy("APIH"); - expectedRecord.setServiceInstanceId("1882939"); - expectedRecord.setServiceInstanceName("testService9"); - expectedRecord.setRequestScope("service"); - expectedRecord.setRequestorId("xxxxxx"); - expectedRecord.setRequestAction("createInstance"); - expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d"); - - //ActualRecord - InfraActiveRequests requestRecord = iar.findOneByRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d"); - assertEquals(sameBeanAs(expectedRecord).toString(), sameBeanAs(requestRecord).ignoring("startTime").ignoring("modifyTime").toString()); - } @Test - public void createServiceInstanceServiceInstancesUri() throws JsonParseException, JsonMappingException, IOException{ + public void createServiceInstanceServiceInstancesUri() throws IOException{ + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setOrchestrationUri("/mso/async/services/CreateGenericALaCarteServiceInstance"); + serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + serviceRecipe.setAction(Action.createInstance.toString()); + serviceRecipe.setId(1); + serviceRecipe.setRecipeTimeout(180); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + stubFor(post(urlPathEqualTo("/mso/async/services/CreateGenericALaCarteServiceInstance")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + + stubFor(get(urlMatching(".*/service/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/serviceRecipe/search.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)) + .withStatus(HttpStatus.SC_OK))); + //expect ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -215,10 +254,31 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void createServiceInstanceBpelStatusError() throws JsonParseException, JsonMappingException, IOException{ + public void createServiceInstanceBpelStatusError() throws IOException{ + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB"); + serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + serviceRecipe.setAction(Action.createInstance.toString()); + serviceRecipe.setId(1); + serviceRecipe.setRecipeTimeout(180); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY))); + + + stubFor(get(urlMatching(".*/service/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/serviceRecipe/search.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)) + .withStatus(HttpStatus.SC_OK))); uri = servInstanceuri + "v5/serviceInstances"; ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceStatusError.json"), uri, HttpMethod.POST); @@ -226,19 +286,28 @@ public class ServiceInstancesTest extends BaseTest{ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); } @Test - public void createServiceInstanceBadGateway() throws JsonParseException, JsonMappingException, IOException{ + public void createServiceInstanceBadGateway() throws IOException{ + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB"); + serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + serviceRecipe.setAction(Action.createInstance.toString()); + serviceRecipe.setId(1); + serviceRecipe.setRecipeTimeout(180); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) .willReturn(aResponse().withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY).withBody("{}"))); + + stubFor(get(urlMatching(".*/service/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); - uri = servInstanceuri + "v5/serviceInstances"; - ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceBadGateway.json"), uri, HttpMethod.POST); - - assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); - } - @Test - public void createServiceInstanceBadData() throws JsonParseException, JsonMappingException, IOException{ - stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withStatus(org.apache.http.HttpStatus.SC_BAD_GATEWAY).withBody("{I AM REALLY BAD}"))); + stubFor(get(urlMatching(".*/serviceRecipe/search.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)) + .withStatus(HttpStatus.SC_OK))); uri = servInstanceuri + "v5/serviceInstances"; ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceBadGateway.json"), uri, HttpMethod.POST); @@ -246,56 +315,98 @@ public class ServiceInstancesTest extends BaseTest{ assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatusCode().value()); } @Test - public void createServiceInstanceEmptyResponse() throws JsonParseException, JsonMappingException, IOException{ + public void createServiceInstanceEmptyResponse() throws IOException{ + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB"); + serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + serviceRecipe.setAction(Action.createInstance.toString()); + serviceRecipe.setId(1); + serviceRecipe.setRecipeTimeout(180); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) .willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE))); - + + stubFor(get(urlMatching(".*/service/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/serviceRecipe/search.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)) + .withStatus(HttpStatus.SC_OK))); + uri = servInstanceuri + "v5/serviceInstances"; ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceEmpty.json"), uri, HttpMethod.POST); assertEquals(Response.Status.BAD_GATEWAY.getStatusCode(), response.getStatusCode().value()); } @Test - public void activateServiceInstanceNoRecipeALaCarte() throws JsonParseException, JsonMappingException, IOException{ + public void activateServiceInstanceNoRecipeALaCarte() throws IOException{ uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate"; headers.set("X-ECOMP-RequestID", "32807a28-1a14-4b88-b7b3-2950918aa76d"); ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json"), uri, HttpMethod.POST); - //ExpectedRecord - InfraActiveRequests expectedRecord = new InfraActiveRequests(); - expectedRecord.setRequestStatus("FAILED"); - expectedRecord.setAction("activateInstance"); - expectedRecord.setStatusMessage("Recipe could not be retrieved from catalog DB."); - expectedRecord.setProgress(new Long(100)); - expectedRecord.setSource("VID"); - expectedRecord.setVnfId("1882938"); - expectedRecord.setRequestBody(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json")); - expectedRecord.setLastModifiedBy("APIH"); - expectedRecord.setServiceInstanceId("f7ce78bb-423b-11e7-93f8-0050569a7968"); - expectedRecord.setServiceInstanceName("testService7"); - expectedRecord.setRequestScope("service"); - expectedRecord.setRequestAction("activateInstance"); - expectedRecord.setRequestorId("xxxxxx"); - expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d"); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + + stubFor(get(urlMatching(".*/service/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + + stubFor(get(urlMatching(".*/serviceRecipe/search/findFirstByServiceModelUUIDAndAction?serviceModelUUID=d88da85c-d9e8-4f73-b837-3a72a431622a&action=activateInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withStatus(HttpStatus.SC_NOT_FOUND))); - //ActualRecord - InfraActiveRequests requestRecord = iar.findOneByRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d"); - assertEquals(sameBeanAs(expectedRecord).toString(), sameBeanAs(requestRecord).ignoring("startTime").ignoring("endTime").ignoring("modifyTime").toString()); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value()); } @Test - public void activateServiceInstanceNoRecipe() throws JsonParseException, JsonMappingException, IOException{ + public void activateServiceInstanceNoRecipe() throws IOException{ uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/activate"; + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + stubFor(get(urlMatching(".*/service/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/serviceRecipe/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withStatus(HttpStatus.SC_NOT_FOUND))); + ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceNoRecipe.json"), uri, HttpMethod.POST); assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatusCode().value()); } @Test - public void activateServiceInstance() throws JsonParseException, JsonMappingException, IOException{ - stubFor(post(urlPathEqualTo("/mso/async/services/ActivateInstance")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + public void activateServiceInstance() throws IOException{ + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB"); + serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + serviceRecipe.setAction(Action.createInstance.toString()); + serviceRecipe.setId(1); + serviceRecipe.setRecipeTimeout(180); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/service/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/serviceRecipe/search.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)) + .withStatus(HttpStatus.SC_OK))); + headers.set("X-TransactionID", "32807a28-1a14-4b88-b7b3-2950918aa76d"); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); @@ -313,10 +424,36 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void deactivateServiceInstance() throws JsonParseException, JsonMappingException, IOException{ - stubFor(post(urlPathEqualTo("/mso/async/services/DeactivateInstance")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + public void deactivateServiceInstance() throws IOException{ + + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB"); + serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + serviceRecipe.setAction(Action.createInstance.toString()); + serviceRecipe.setId(1); + serviceRecipe.setRecipeTimeout(180); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/service/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/service/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/serviceRecipe/search.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)) + .withStatus(HttpStatus.SC_OK))); + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -333,10 +470,34 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void deleteServiceInstance() throws JsonParseException, JsonMappingException, IOException { - stubFor(post(urlPathEqualTo("/mso/async/services/DeleteInstance")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + public void deleteServiceInstance() throws IOException { + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB"); + serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + serviceRecipe.setAction(Action.createInstance.toString()); + serviceRecipe.setId(1); + serviceRecipe.setRecipeTimeout(180); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/service/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/service/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/serviceRecipe/search.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)) + .withStatus(HttpStatus.SC_OK))); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -353,10 +514,34 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void assignServiceInstance() throws JsonParseException, JsonMappingException, IOException { - stubFor(post(urlPathEqualTo("/mso/async/services/AssignServiceInstance")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + public void assignServiceInstance() throws IOException { + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB"); + serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + serviceRecipe.setAction(Action.createInstance.toString()); + serviceRecipe.setId(1); + serviceRecipe.setRecipeTimeout(180); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/service/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/service/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/serviceRecipe/search.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)) + .withStatus(HttpStatus.SC_OK))); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -374,10 +559,34 @@ public class ServiceInstancesTest extends BaseTest{ } @Test - public void unassignServiceInstance() throws JsonParseException, JsonMappingException, IOException { - stubFor(post(urlPathEqualTo("/mso/async/services/UnassignServiceInstance")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + public void unassignServiceInstance() throws IOException { + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB"); + serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + serviceRecipe.setAction(Action.createInstance.toString()); + serviceRecipe.setId(1); + serviceRecipe.setRecipeTimeout(180); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/service/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/service/search/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/serviceRecipe/search.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)) + .withStatus(HttpStatus.SC_OK))); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -394,9 +603,9 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void createPortConfiguration() throws JsonParseException, JsonMappingException, IOException { + public void createPortConfiguration() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); headers.set("X-TransactionID", "32807a28-1a14-4b88-b7b3-2950918aa76d"); //expected response @@ -416,16 +625,16 @@ public class ServiceInstancesTest extends BaseTest{ assertTrue(response.getBody().contains("1882939")); } @Test - public void createPortConfigurationEmptyProductFamilyId() throws JsonParseException, JsonMappingException, IOException { + public void createPortConfigurationEmptyProductFamilyId() throws IOException { uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7968/configurations"; ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceParseFail.json"), uri, HttpMethod.POST); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); } @Test - public void deletePortConfiguration() throws JsonParseException, JsonMappingException, IOException { + public void deletePortConfiguration() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); headers.set("X-ECOMP-RequestID", "32807a28-1a14-4b88-b7b3-2950918aa76d"); @@ -445,9 +654,9 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void enablePort() throws JsonParseException, JsonMappingException, IOException { + public void enablePort() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); @@ -465,9 +674,9 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void disablePort() throws JsonParseException, JsonMappingException, IOException { + public void disablePort() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); @@ -485,9 +694,9 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void activatePort() throws JsonParseException, JsonMappingException, IOException { + public void activatePort() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); @@ -505,9 +714,9 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void deactivatePort() throws JsonParseException, JsonMappingException, IOException { + public void deactivatePort() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); @@ -525,9 +734,9 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void addRelationships() throws JsonParseException, JsonMappingException, IOException { + public void addRelationships() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); //expected response @@ -546,9 +755,9 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void removeRelationships() throws JsonParseException, JsonMappingException, IOException { + public void removeRelationships() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/ALaCarteOrchestrator")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); //expected response @@ -567,11 +776,27 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void createVnfInstanceNoALaCarte() throws JsonParseException, JsonMappingException, IOException { + public void createVnfInstanceNoALaCarte() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002671")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomization_ReplaceVnf_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002671/vnfResources")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfResources_ReplaceVnf_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]nfRole=GR-API-DEFAULT&action=createInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfRecipeReplaceInstance_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -588,11 +813,31 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void createVnfInstance() throws JsonParseException, JsonMappingException, IOException { + public void createVnfInstance() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/service/5df8b6de-2083-11e7-93ae-92361f002672")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("serviceVnf_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/service/5df8b6de-2083-11e7-93ae-92361f002672/vnfCustomizations")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomizationsList_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + + stubFor(get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002672/vnfResources")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfResourcesCreateVnf_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]nfRole=GR-API-DEFAULT&action=createInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfRecipeCreateInstance_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + String requestId = "b7a6b76f-2ee2-416c-971b-548472a8c5c3"; headers.set(MsoLogger.ONAP_REQUEST_ID, requestId); //expected response @@ -606,22 +851,20 @@ public class ServiceInstancesTest extends BaseTest{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - InfraActiveRequests record = iar.findOneByRequestId(requestId); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); assertTrue(response.getBody().contains("1882939")); - assertEquals(record.getVnfType(), "vSAMP12/test"); } @Test - public void createVnfWithServiceRelatedInstanceFail() throws JsonParseException, JsonMappingException, IOException { + public void createVnfWithServiceRelatedInstanceFail() throws IOException { uri = servInstanceUriPrev7 + "v6" + "/f7ce78bb-423b-11e7-93f8-0050569a7968/vnfs"; ResponseEntity<String> response = sendRequest(inputStream("/VnfWithServiceRelatedInstanceFail.json"), uri, HttpMethod.POST); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); } @Test - public void createVnfInstanceInvalidVnfResource() throws JsonParseException, JsonMappingException, IOException { + public void createVnfInstanceInvalidVnfResource() throws IOException { uri = servInstanceuri + "v7" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs"; ResponseEntity<String> response = sendRequest(inputStream("/NoVnfResource.json"), uri, HttpMethod.POST); @@ -631,14 +874,28 @@ public class ServiceInstancesTest extends BaseTest{ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); - assertTrue(realResponse.getServiceException().getText().equals("No valid vnfResource is specified")); + assertEquals("No valid vnfResource is specified", realResponse.getServiceException().getText()); } @Test - public void replaceVnfInstance() throws JsonParseException, JsonMappingException, IOException { + public void replaceVnfInstance() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002671")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomization_ReplaceVnf_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002671/vnfResources")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfResources_ReplaceVnf_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]nfRole=GR-API-DEFAULT&action=replaceInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfRecipeReplaceInstance_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -655,11 +912,26 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void replaceVnfRecreateInstance() throws JsonParseException, JsonMappingException, IOException { + public void replaceVnfRecreateInstance() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/RecreateInfraVce")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002674")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomization_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002674/vnfResources")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfResources_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]nfRole=TEST&action=replaceInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfRecipe_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -676,11 +948,27 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void updateVnfInstance() throws JsonParseException, JsonMappingException, IOException { + public void updateVnfInstance() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002674")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomization_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002674/vnfResources")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfResources_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction" + + "[?]nfRole=GR-API-DEFAULT&action=updateInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("UpdateVnfRecipe_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -697,11 +985,18 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void applyUpdatedConfig() throws JsonParseException, JsonMappingException, IOException { + public void applyUpdatedConfig() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/VnfConfigUpdate")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction" + + "[?]nfRole=GR-API-DEFAULT&action=applyUpdatedConfig")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfRecipeApplyUpdatedConfig_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + String requestId = "b7a6b76f-2ee2-416c-971b-548472a8c5c5"; headers.set(MsoLogger.ONAP_REQUEST_ID, requestId); //expected response @@ -715,18 +1010,21 @@ public class ServiceInstancesTest extends BaseTest{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - InfraActiveRequests record = iar.findOneByRequestId(requestId); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); - assertNull(record.getVnfType()); } @Test - public void deleteVnfInstanceV5() throws JsonParseException, JsonMappingException, IOException { + public void deleteVnfInstanceV5() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction" + + "[?]nfRole=GR-API-DEFAULT&action=deleteInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfRecipeDelete_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -743,11 +1041,32 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void createVfModuleInstance() throws JsonParseException, JsonMappingException, IOException { - stubFor(post(urlPathEqualTo("/mso/async/services/CreateVfModuleInfra")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + public void createVfModuleInstance() throws IOException { + + stubFor(get(urlMatching(".*/vfModuleCustomization/cb82ffd8-252a-11e7-93ae-92361f002671")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModuleCustomization_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModuleCustomization/cb82ffd8-252a-11e7-93ae-92361f002671/vfModule")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModule/20c4431c-246d-11e7-93ae-92361f002671")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(post(urlPathEqualTo("/mso/async/services/CreateVfModuleInfra")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" + + "[?]vfModuleModelUUID=20c4431c-246d-11e7-93ae-92361f002671&vnfComponentType=vfModule&action=createInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipe_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -765,11 +1084,50 @@ public class ServiceInstancesTest extends BaseTest{ assertTrue(response.getBody().contains("1882939")); } @Test - public void createVfModuleInstanceNoModelCustomization() throws JsonParseException, JsonMappingException, IOException { - stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + public void createVfModuleInstanceNoModelCustomization() throws IOException { + stubFor(post(urlPathEqualTo("/mso/async/services/CreateVfModuleInfra")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/vnfResource/fe6478e4-ea33-3346-ac12-ab121484a3fe")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfResourceForVfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfResourceCustomization/search/findByModelInstanceNameAndVnfResources" + + "[?]modelInstanceName=test&vnfResourceModelUUID=fe6478e4-ea33-3346-ac12-ab121484a3fe")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomizationForVfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002673/vfModuleCustomizations")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationsPCM_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModuleCustomization/search/findByModelCustomizationUUIDAndVfModuleModelUUID[?]" + + "modelCustomizationUUID=b4ea86b4-253f-11e7-93ae-92361f002672&vfModuleModelUUID=066de97e-253e-11e7-93ae-92361f002672")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationPCM_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002672/vfModule")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModulePCM_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModule/066de97e-253e-11e7-93ae-92361f002672")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModulePCM_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + + stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVnfComponentTypeAndAction" + + "[?]vnfComponentType=vfModule&action=createInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeVNF_API_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -783,11 +1141,47 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void deleteVfModuleInstanceNoMatchingModelUUD() throws JsonParseException, JsonMappingException, IOException { + public void deleteVfModuleInstanceNoMatchingModelUUD() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/vnfResource/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfResourceForVfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfResourceCustomization/search/findByModelInstanceNameAndVnfResources.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomizationForVfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002673/vfModuleCustomizations")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationsPCM_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002672")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationPCM_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002672/vfModule")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModulePCM_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModule/066de97e-253e-11e7-93ae-92361f002672")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModulePCM_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" + + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=deleteInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeDeleteVfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -802,22 +1196,56 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void createVfModuleInstanceNoRecipe() throws JsonParseException, JsonMappingException, IOException { - uri = servInstanceuri + "v6" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules"; + public void createVfModuleInstanceNoRecipe() throws IOException { + + stubFor(get(urlMatching(".*/vnfResource/fe6478e4-ea33-3346-ac12-ab121484a3fe")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfResourceForVfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfResourceCustomization/search/findByModelInstanceNameAndVnfResources" + + "[?]modelInstanceName=test&vnfResourceModelUUID=fe6478e4-ea33-3346-ac12-ab121484a3fe")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfResourceCustomizationForVfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfResourceCustomization/68dc9a92-214c-11e7-93ae-92361f002673/vfModuleCustomizations")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationsPCM_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModuleCustomization/search/findByModelCustomizationUUIDAndVfModuleModelUUID[?]" + + "modelCustomizationUUID=b4ea86b4-253f-11e7-93ae-92361f002672&vfModuleModelUUID=066de97e-253e-11e7-93ae-92361f002672")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationPCM_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + uri = servInstanceuri + "v6" + "/serviceInstances/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff000/vfModules"; ResponseEntity<String> response = sendRequest(inputStream("/VfModuleInvalid.json"), uri, HttpMethod.POST); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true); RequestError realResponse = mapper.readValue(response.getBody(), RequestError.class); - assertTrue(realResponse.getServiceException().getText().equals("No valid vfModuleCustomization is specified")); + assertEquals("No valid vfModuleCustomization is specified", realResponse.getServiceException().getText()); } @Test - public void replaceVfModuleInstance() throws JsonParseException, JsonMappingException, IOException { + public void replaceVfModuleInstance() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); - + + stubFor(get(urlMatching(".*/vfModule/search/findFirstVfModuleByModelInvariantUUIDAndModelVersion[?]" + + "modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671&modelVersion=2")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" + + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=replaceInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeDeleteVfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -834,11 +1262,32 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void updateVfModuleInstance() throws JsonParseException, JsonMappingException, IOException { + public void updateVfModuleInstance() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/vfModuleCustomization/cb82ffd8-252a-11e7-93ae-92361f002671")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModuleCustomization_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModuleCustomization/cb82ffd8-252a-11e7-93ae-92361f002671/vfModule")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModule/20c4431c-246d-11e7-93ae-92361f002671")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" + + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=updateInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipe_GRAPI_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -856,13 +1305,13 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void createVfModuleNoModelType() throws JsonParseException, JsonMappingException, IOException{ + public void createVfModuleNoModelType() throws IOException{ headers.set(MsoLogger.ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); InfraActiveRequests expectedRecord = new InfraActiveRequests(); expectedRecord.setRequestStatus("FAILED"); expectedRecord.setAction("createInstance"); expectedRecord.setStatusMessage("Error parsing request: No valid modelType is specified"); - expectedRecord.setProgress(new Long(100)); + expectedRecord.setProgress(100L); expectedRecord.setSource("VID"); expectedRecord.setRequestBody(inputStream("/VfModuleNoModelType.json")); expectedRecord.setLastModifiedBy("APIH"); @@ -878,17 +1327,19 @@ public class ServiceInstancesTest extends BaseTest{ ResponseEntity<String> response = sendRequest(inputStream("/VfModuleNoModelType.json"), uri, HttpMethod.POST); //ActualRecord - InfraActiveRequests requestRecord = iar.findOneByRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d"); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); - assertEquals(sameBeanAs(expectedRecord).toString(), sameBeanAs(requestRecord).ignoring("startTime").ignoring("endTime").ignoring("modifyTime").toString()); - assertNotNull(requestRecord.getStartTime()); - assertNotNull(requestRecord.getEndTime()); } @Test - public void inPlaceSoftwareUpdate() throws JsonParseException, JsonMappingException, IOException { + public void inPlaceSoftwareUpdate() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/VnfInPlaceUpdate")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfRecipe/search/findFirstVnfRecipeByNfRoleAndAction[?]" + + "nfRole=GR-API-DEFAULT&action=inPlaceSoftwareUpdate")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfRecipeInPlaceUpdate_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); @@ -905,52 +1356,25 @@ public class ServiceInstancesTest extends BaseTest{ ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } - + @Test - public void inPlaceSoftwareUpdateDuplicate() throws JsonParseException, JsonMappingException, IOException { - stubFor(post(urlPathEqualTo("/mso/async/services/VnfInPlaceUpdate")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); - - InfraActiveRequests req = new InfraActiveRequests(); - req.setRequestStatus("IN_PROGRESS"); - req.setAction("inPlaceSoftwareUpdate"); - req.setProgress(new Long(10)); - req.setRequestBody(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json")); - req.setServiceInstanceId("f7ce78bb-423b-11e7-93f8-0050569a7908"); - req.setVnfId("ff305d54-75b4-431b-adb2-eb6b9e5ff033"); - req.setRequestScope("vnf"); - req.setVnfName("duplicateCheck123"); - req.setRequestAction("inPlaceSoftwareUpdate"); - req.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d"); - iar.save(req); - - //expected response - ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); - RequestReferences requestReferences = new RequestReferences(); - requestReferences.setInstanceId("1882939"); - expectedResponse.setRequestReferences(requestReferences); - uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7908/vnfs/ff305d54-75b4-431b-adb2-eb6b9e5ff033/inPlaceSoftwareUpdate"; - ResponseEntity<String> response = sendRequest(inputStream("/InPlaceSoftwareUpdate2.json"), uri, HttpMethod.POST); - - ObjectMapper mapper = new ObjectMapper(); - mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - - assertEquals(Response.Status.CONFLICT.getStatusCode(), response.getStatusCode().value()); - - InfraActiveRequests newRecord = iar.findOneByRequestBody(inputStream("/InPlaceSoftwareUpdate2.json")); - - assertNotNull(newRecord.getServiceInstanceId()); - assertNotNull(newRecord.getVnfId()); - - } - - @Test - public void deleteVfModuleInstance() throws JsonParseException, JsonMappingException, IOException { + public void deleteVfModuleInstance() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/vfModule/search/findFirstVfModuleByModelInvariantUUIDAndModelVersion[?]" + + "modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671&modelVersion=2")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" + + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=deleteInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeDeleteVfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -967,11 +1391,23 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void deactivateAndCloudDeleteVfModuleInstance() throws JsonParseException, JsonMappingException, IOException { + public void deactivateAndCloudDeleteVfModuleInstance() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/vfModule/search/findFirstVfModuleByModelInvariantUUIDAndModelVersion[?]" + + "modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671&modelVersion=2")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" + + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=deactivateAndCloudDelete")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeDeactivate_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -988,11 +1424,27 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void createVolumeGroupInstance() throws JsonParseException, JsonMappingException, IOException { + public void createVolumeGroupInstance() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002671")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationVolGrp_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002671/vfModule")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModuleVolGroup_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" + + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=volumeGroup&action=createInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeVolGrp_GRAPI_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -1010,11 +1462,27 @@ public class ServiceInstancesTest extends BaseTest{ assertTrue(response.getBody().contains("1882939")); } @Test - public void updateVolumeGroupInstance() throws JsonParseException, JsonMappingException, IOException { + public void updateVolumeGroupInstance() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002671")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationVolGrp_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002671/vfModule")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModuleVolGroup_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" + + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=volumeGroup&action=updateInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeVolGrp_GRAPI_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -1031,11 +1499,31 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void deleteVolumeGroupInstance() throws JsonParseException, JsonMappingException, IOException { + public void deleteVolumeGroupInstance() throws IOException { + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002671")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModuleCustomizationVolGrp_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModuleCustomization/b4ea86b4-253f-11e7-93ae-92361f002671/vfModule")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModuleVolGroup_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" + + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=volumeGroup&action=deleteInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeVolGrp_GRAPI_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -1052,11 +1540,27 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void createNetworkInstance() throws JsonParseException, JsonMappingException, IOException { + public void createNetworkInstance() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json")) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json")) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" + + "modelName=GR-API-DEFAULT&action=createInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + String requestId = "b7a6b76f-2ee2-416c-971b-548472a8c5c4"; headers.set(MsoLogger.ONAP_REQUEST_ID, requestId); //expected response @@ -1070,18 +1574,31 @@ public class ServiceInstancesTest extends BaseTest{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - InfraActiveRequests record = iar.findOneByRequestId(requestId); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); - assertEquals(record.getNetworkType(), "TestNetworkType"); } @Test - public void updateNetworkInstance() throws JsonParseException, JsonMappingException, IOException { + public void updateNetworkInstance() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json")) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json")) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" + + "modelName=GR-API-DEFAULT&action=updateInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -1099,11 +1616,27 @@ public class ServiceInstancesTest extends BaseTest{ assertTrue(response.getBody().contains("1882939")); } @Test - public void deleteNetworkInstance() throws JsonParseException, JsonMappingException, IOException { + public void deleteNetworkInstance() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json")) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json")) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" + + "modelName=GR-API-DEFAULT&action=deleteInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -1120,11 +1653,18 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void deleteNetworkInstanceNoReqParams() throws JsonParseException, JsonMappingException, IOException { + public void deleteNetworkInstanceNoReqParams() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" + + "modelName=GR-API-DEFAULT&action=deleteInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -1141,13 +1681,13 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); } @Test - public void convertJsonToServiceInstanceRequestFail() throws JsonParseException, JsonMappingException, IOException { + public void convertJsonToServiceInstanceRequestFail() throws IOException { headers.set(MsoLogger.ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); //ExpectedRecord InfraActiveRequests expectedRecord = new InfraActiveRequests(); expectedRecord.setRequestStatus("FAILED"); expectedRecord.setStatusMessage("Error mapping request: "); - expectedRecord.setProgress(new Long(100)); + expectedRecord.setProgress(100L); expectedRecord.setRequestBody(inputStream("/ConvertRequestFail.json")); expectedRecord.setLastModifiedBy("APIH"); expectedRecord.setRequestScope("network"); @@ -1158,16 +1698,11 @@ public class ServiceInstancesTest extends BaseTest{ ResponseEntity<String> response = sendRequest(inputStream("/ConvertRequestFail.json"), uri, HttpMethod.DELETE); //ActualRecord - InfraActiveRequests requestRecord = iar.findOneByRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d"); assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatusCode().value()); - assertThat(expectedRecord, sameBeanAs(requestRecord).ignoring("startTime").ignoring("endTime").ignoring("modifyTime").ignoring("statusMessage")); - assertThat(requestRecord.getStatusMessage(), containsString("Error mapping request: ")); - assertNotNull(requestRecord.getStartTime()); - assertNotNull(requestRecord.getEndTime()); } @Test - public void convertJsonToServiceInstanceRequestConfigurationFail() throws JsonParseException, JsonMappingException, IOException { + public void convertJsonToServiceInstanceRequestConfigurationFail() throws IOException { uri = servInstanceuri + "v5" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/configurations/test/enablePort"; ResponseEntity<String> response = sendRequest(inputStream("/ConvertRequestFail.json"), uri, HttpMethod.POST); @@ -1177,9 +1712,28 @@ public class ServiceInstancesTest extends BaseTest{ @Test public void creatServiceInstanceGRTestApiNoCustomRecipeFound() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB"); + serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + serviceRecipe.setAction(Action.createInstance.toString()); + serviceRecipe.setId(1); + serviceRecipe.setRecipeTimeout(180); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + + stubFor(get(urlMatching(".*/service/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/serviceRecipe/search.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)) + .withStatus(HttpStatus.SC_OK))); + uri = servInstanceuri + "v7" + "/serviceInstances"; ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceMacro.json"), uri, HttpMethod.POST); @@ -1200,9 +1754,25 @@ public class ServiceInstancesTest extends BaseTest{ @Test public void createNetworkInstanceTestApiUndefinedUsePropertiesDefault() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json")) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json")) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" + + "modelName=GR-API-DEFAULT&action=createInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks"; ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateAlternateInstanceName.json"), uri, HttpMethod.POST); @@ -1223,7 +1793,7 @@ public class ServiceInstancesTest extends BaseTest{ @Test public void createNetworkInstanceTestApiIncorrectUsePropertiesDefault() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks"; @@ -1244,9 +1814,25 @@ public class ServiceInstancesTest extends BaseTest{ @Test public void createNetworkInstanceTestApiGrApi() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json")) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json")) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" + + "modelName=GR-API-DEFAULT&action=createInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkRecipe_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks"; ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateTestApiGrApi.json"), uri, HttpMethod.POST); @@ -1267,9 +1853,25 @@ public class ServiceInstancesTest extends BaseTest{ @Test public void createNetworkInstanceTestApiVnfApi() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/CreateNetworkInstance")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkResourceCustomization_Response.json")) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/networkResourceCustomization/3bdbb104-476c-483e-9f8b-c095b3d308ac/networkResource")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkResource_Response.json")) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/networkRecipe/search/findFirstByModelNameAndAction[?]" + + "modelName=VNF-API-DEFAULT&action=createInstance")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("networkRecipeVNF_API_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + uri = servInstanceuri + "v7" + "/serviceInstances/f7ce78bb-423b-11e7-93f8-0050569a7969/networks"; ResponseEntity<String> response = sendRequest(inputStream("/NetworkCreateTestApiVnfApi.json"), uri, HttpMethod.POST); @@ -1288,27 +1890,31 @@ public class ServiceInstancesTest extends BaseTest{ } @Test - public void activateServiceInstanceRequestStatus() throws JsonParseException, JsonMappingException, IOException{ - stubFor(post(urlPathEqualTo("/mso/async/services/ActivateInstance")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + public void activateServiceInstanceRequestStatus() throws IOException{ + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB"); + serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + serviceRecipe.setAction(Action.createInstance.toString()); + serviceRecipe.setId(1); + serviceRecipe.setRecipeTimeout(180); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); headers.set("X-ECOMP-RequestID", "32807a28-1a14-4b88-b7b3-2950918aa76d"); - InfraActiveRequests expectedRecord = new InfraActiveRequests(); - expectedRecord.setRequestStatus("FAILED"); - expectedRecord.setAction("activateInstance"); - expectedRecord.setStatusMessage("Recipe could not be retrieved from catalog DB."); - expectedRecord.setProgress(new Long(100)); - expectedRecord.setSource("VID"); - expectedRecord.setRequestBody(inputStream("/ServiceInstanceALaCarteTrueNoRecipe.json")); - expectedRecord.setLastModifiedBy("APIH"); - expectedRecord.setServiceInstanceId("f7ce78bb-423b-11e7-93f8-0050569a7999"); - expectedRecord.setServiceInstanceName("testService1234"); - expectedRecord.setRequestScope("service"); - expectedRecord.setRequestAction("activateInstance"); - expectedRecord.setRequestorId("xxxxxx"); - expectedRecord.setRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d"); + stubFor(get(urlMatching(".*/service/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/serviceRecipe/search.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)) + .withStatus(HttpStatus.SC_OK))); + //expect ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -1320,10 +1926,6 @@ public class ServiceInstancesTest extends BaseTest{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - InfraActiveRequests requestRecord = iar.findOneByRequestId("32807a28-1a14-4b88-b7b3-2950918aa76d"); - - //then - assertEquals(Status.IN_PROGRESS.name(), requestRecord.getRequestStatus()); assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); ServiceInstancesResponse realResponse = mapper.readValue(response.getBody(), ServiceInstancesResponse.class); assertThat(realResponse, sameBeanAs(expectedResponse).ignoring("requestReferences.requestId")); @@ -1342,10 +1944,30 @@ public class ServiceInstancesTest extends BaseTest{ } @Test public void invalidBPELResponse() throws IOException{ - stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB"); + serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + serviceRecipe.setAction(Action.createInstance.toString()); + serviceRecipe.setId(1); + serviceRecipe.setRecipeTimeout(180); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponseInvalid2.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/service/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/serviceRecipe/search.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)) + .withStatus(HttpStatus.SC_OK))); + uri = servInstanceuri + "v5/serviceInstances"; ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST); @@ -1360,10 +1982,29 @@ public class ServiceInstancesTest extends BaseTest{ @Test public void invalidBPELResponse2() throws IOException{ - stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setOrchestrationUri("/mso/async/services/WorkflowActionBB"); + serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + serviceRecipe.setAction(Action.createInstance.toString()); + serviceRecipe.setId(1); + serviceRecipe.setRecipeTimeout(180); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponseInvalid.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/service/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/serviceRecipe/search.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)) + .withStatus(HttpStatus.SC_OK))); uri = servInstanceuri + "v5/serviceInstances"; ResponseEntity<String> response = sendRequest(inputStream("/ServiceInstanceDefault.json"), uri, HttpMethod.POST); @@ -1377,11 +2018,34 @@ public class ServiceInstancesTest extends BaseTest{ } @Test - public void createMacroServiceInstance() throws JsonParseException, JsonMappingException, IOException{ - stubFor(post(urlPathEqualTo("/mso/async/services/CreateMacroServiceNetworkVnf")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + public void createMacroServiceInstance() throws IOException{ + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setOrchestrationUri("/mso/async/services/CreateMacroServiceNetworkVnf"); + serviceRecipe.setServiceModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + serviceRecipe.setAction(Action.createInstance.toString()); + serviceRecipe.setId(1); + serviceRecipe.setRecipeTimeout(180); + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + + stubFor(post(urlPathEqualTo("/mso/async/services/CreateMacroServiceNetworkVnf")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("Camunda/TestResponseInvalid.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/service/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)) + .withStatus(HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/serviceRecipe/search.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)) + .withStatus(HttpStatus.SC_OK))); + //expect ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); @@ -1400,7 +2064,7 @@ public class ServiceInstancesTest extends BaseTest{ } @Test - public void testUserParams() throws JsonParseException, JsonMappingException, IOException { + public void testUserParams() throws IOException { ObjectMapper mapper = new ObjectMapper(); ServiceInstancesRequest request = mapper.readValue(inputStream("/MacroServiceInstance.json"), ServiceInstancesRequest.class); RequestParameters requestParameters = request.getRequestDetails().getRequestParameters(); @@ -1411,7 +2075,7 @@ public class ServiceInstancesTest extends BaseTest{ assertTrue(userParams.size() > 0); assertTrue(userParams.get(0).containsKey("name")); assertTrue(userParams.get(0).containsKey("value")); - assertTrue(userParamsTxt.replaceAll("\\s+","").equals(userParams.toString().replaceAll("\\s+",""))); + assertEquals(userParamsTxt.replaceAll("\\s+", ""), userParams.toString().replaceAll("\\s+", "")); } @Test @@ -1434,11 +2098,36 @@ public class ServiceInstancesTest extends BaseTest{ assertThat(request, sameBeanAs(expected)); } @Test - public void scaleOutVfModule() throws JsonParseException, JsonMappingException, IOException { + public void scaleOutVfModule() throws IOException { stubFor(post(urlPathEqualTo("/mso/async/services/WorkflowActionBB")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBodyFile("Camunda/TestResponse.json").withStatus(org.apache.http.HttpStatus.SC_OK))); + stubFor(get(urlMatching(".*/vfModuleCustomization/cb82ffd8-252a-11e7-93ae-92361f002671")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModuleCustomization_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModuleCustomization/cb82ffd8-252a-11e7-93ae-92361f002671/vfModule")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModule/20c4431c-246d-11e7-93ae-92361f002671")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModule_Response.json")) + .withStatus(org.apache.http.HttpStatus.SC_OK))); + + + stubFor(get(urlMatching(".*/vnfComponentsRecipe/search/findFirstVnfComponentsRecipeByVfModuleModelUUIDAndVnfComponentTypeAndAction" + + "[?]vfModuleModelUUID=GR-API-DEFAULT&vnfComponentType=vfModule&action=scaleOut")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vnfComponentRecipeVfModuleScaleOut_Response.json")).withStatus(org.apache.http.HttpStatus.SC_OK))); + + stubFor(get(urlMatching(".*/vfModule/search/findByModelInvariantUUIDOrderByModelVersionDesc[?]modelInvariantUUID=78ca26d0-246d-11e7-93ae-92361f002671")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(getWiremockResponseForCatalogdb("vfModulesListByInvariantId_Response.json")).withStatus(org.apache.http.HttpStatus.SC_OK))); + //expected response ServiceInstancesResponse expectedResponse = new ServiceInstancesResponse(); RequestReferences requestReferences = new RequestReferences(); |