From 64d65262d73039b1c5b1a6c02f087141046a1169 Mon Sep 17 00:00:00 2001 From: Alexey Sandler Date: Sun, 29 Dec 2019 15:53:44 +0200 Subject: Create Service Info file for assertion on Cypress and API test Issue-ID: VID-724 Change-Id: I1008b3ced1f04267513dcde2e26377861009fda2 Signed-off-by: Alexey Sandler Signed-off-by: Ittay Stern --- .../vid/api/InstantiationTemplatesApiTest.java | 60 +++++++++++++++++----- ...vidRequestCreateBulkOfMacro__template_info.json | 45 ++++++++++++++++ 2 files changed, 92 insertions(+), 13 deletions(-) create mode 100644 vid-automation/src/test/resources/asyncInstantiation/vidRequestCreateBulkOfMacro__template_info.json diff --git a/vid-automation/src/test/java/org/onap/vid/api/InstantiationTemplatesApiTest.java b/vid-automation/src/test/java/org/onap/vid/api/InstantiationTemplatesApiTest.java index bc47ad834..145db8b9d 100644 --- a/vid-automation/src/test/java/org/onap/vid/api/InstantiationTemplatesApiTest.java +++ b/vid-automation/src/test/java/org/onap/vid/api/InstantiationTemplatesApiTest.java @@ -2,7 +2,10 @@ package org.onap.vid.api; import static java.util.Arrays.stream; import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals; +import static net.javacrumbs.jsonunit.JsonMatchers.jsonPartEquals; +import static net.javacrumbs.jsonunit.core.Option.IGNORING_VALUES; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.arrayWithSize; import static org.hamcrest.Matchers.greaterThan; import static org.onap.vid.api.TestUtils.convertRequest; @@ -16,6 +19,7 @@ import java.util.Map.Entry; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.apache.commons.lang3.exception.ExceptionUtils; import org.onap.sdc.ci.tests.datatypes.UserCredentials; import org.onap.simulator.presetGenerator.presets.aai.PresetAAIGetSubscribersGet; import org.onap.vid.model.mso.MsoResponseWrapper2; @@ -85,20 +89,24 @@ public class InstantiationTemplatesApiTest extends AsyncInstantiationBase { } @Test - public void templateTopology_givenDeployFromCypressE2E_getTemplateTopologyDataIsEquivalent() throws IOException { + public void templateTopology_givenDeployFromCypressE2E_getTemplateTopologyDataIsEquivalent() { templateTopology_givenDeploy_templateTopologyIsEquivalentToBody( fileAsJsonNode("asyncInstantiation/templates__instance_template.json")); } @Test - public void templateTopology_givenDeployFromEditedTemplateCypressE2E_getTemplateTopologyDataIsEquivalentToOriginalTemplate() throws IOException { + public void templateTopology_givenDeployFromEditedTemplateCypressE2E_getTemplateTopologyDataIsEquivalentToOriginalTemplate() { templateTopology_givenDeploy_templateTopologyIsEquivalent( fileAsJsonNode("asyncInstantiation/templates__instance_from_template__set_without_modify1.json"), fileAsJsonNode("asyncInstantiation/templates__instance_template.json")); } + private ObjectNode templateInfoFromFile() { + return fileAsJsonNode("asyncInstantiation/vidRequestCreateBulkOfMacro__template_info.json"); + } + @Test - public void templateTopology_givenDeploy_OriginalTemplateNotChanged() throws IOException { + public void templateTopology_givenDeploy_OriginalTemplateNotChanged() { String uuidOriginTemplate = postAsyncInstanceRequest(fileAsJsonNode("asyncInstantiation/templates__instance_template.json")); JsonNode originTemplateBeforeDeploy = restTemplate.getForObject(templateTopologyUri(uuidOriginTemplate), JsonNode.class); @@ -113,35 +121,61 @@ public class InstantiationTemplatesApiTest extends AsyncInstantiationBase { @Test @FeatureTogglingTest(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE) - public void templateTopology_givenDeploy_getServiceInfoHoldsRequestSummary() throws IOException { + public void templateTopology_givenDeploy_getServiceInfoHoldsRequestSummary() { ObjectNode request = fileAsJsonNode(CREATE_BULK_OF_MACRO_REQUEST) .put("bulkSize", 1) .put("pause", false); - postAsyncInstanceRequest(request); + String jobId = postAsyncInstanceRequest(request); - assertThat(fetchRequestSummary(request.at("/modelInfo/modelVersionId").asText()), - jsonEquals(ImmutableMap.of( + assertThat(fetchRecentTemplateInfo(request.at("/modelInfo/modelVersionId").asText()), allOf( + jsonPartEquals("jobId", jobId), + jsonPartEquals("requestSummary", ImmutableMap.of( "vnf", 1L, "vfModule", 2L, "volumeGroup", 1L + )))); + } + + @Test + @FeatureTogglingTest(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE) + public void templateTopology_givenDeploy_getServiceInfoReturnsCypressE2EFile() { + ObjectNode request = + fileAsJsonNode(CREATE_BULK_OF_MACRO_REQUEST) + .put("bulkSize", 1) + .put("pause", false); + + String jobId = postAsyncInstanceRequest(request); + + assertThat(fetchRecentTemplateInfo(request.at("/modelInfo/modelVersionId").asText()), allOf( + jsonPartEquals("jobId", jobId), + jsonEquals(templateInfoFromFile()).when(IGNORING_VALUES), // Assert only field types + jsonEquals(templateInfoFromFile()).whenIgnoringPaths( + // Ignore the fields where values are always changing + "id", "templateId", "jobId", + "created", "createdBulkDate", + "modified", "statusModifiedDate", + "jobStatus" ))); } - private JsonNode fetchRequestSummary(String serviceModelId) { + private JsonNode fetchRecentTemplateInfo(String serviceModelId) { return stream(restTemplate.getForObject(getTemplateInfoUrl(serviceModelId), JsonNode[].class)) - .map(it -> it.at("/requestSummary")) .findFirst() .orElseGet(() -> { throw new AssertionError(getTemplateInfoUrl(serviceModelId) + " returned zero results"); }); } - private ObjectNode fileAsJsonNode(String fileName) throws IOException { - return objectMapper.readValue( - convertRequest(objectMapper, fileName), - ObjectNode.class); + private ObjectNode fileAsJsonNode(String fileName) { + try { + return objectMapper.readValue( + convertRequest(objectMapper, fileName), + ObjectNode.class); + } catch (IOException e) { + return ExceptionUtils.rethrow(e); + } } public void templateTopology_givenDeploy_templateTopologyIsEquivalentToBody(JsonNode body) { diff --git a/vid-automation/src/test/resources/asyncInstantiation/vidRequestCreateBulkOfMacro__template_info.json b/vid-automation/src/test/resources/asyncInstantiation/vidRequestCreateBulkOfMacro__template_info.json new file mode 100644 index 000000000..0770025aa --- /dev/null +++ b/vid-automation/src/test/resources/asyncInstantiation/vidRequestCreateBulkOfMacro__template_info.json @@ -0,0 +1,45 @@ +{ + "id": 56, + "created": 1577354225000, + "modified": 1577354325000, + "createdId": null, + "modifiedId": null, + "rowNum": null, + "auditUserId": null, + "auditTrail": null, + "jobId": "ef3430f8-6350-454c-a7c2-89ba301522c1", + "templateId": "a313b887-ccfd-4d85-a232-5ec9d4d94013", + "userId": "us16807000", + "msoRequestId": null, + "jobStatus": "IN_PROGRESS", + "statusModifiedDate": 1577354226000, + "hidden": false, + "pause": false, + "deletedAt": null, + "owningEntityId": "someID", + "owningEntityName": "someName", + "project": "myProject", + "aicZoneId": "NFT1", + "aicZoneName": "NFTJSSSS-NFT1", + "tenantId": "greatTenant", + "tenantName": "greatTenant", + "regionId": "hvf3", + "regionName": null, + "serviceType": "mySubType", + "subscriberName": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", + "subscriberId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", + "serviceInstanceId": null, + "serviceInstanceName": "SERVICE_NAME", + "serviceModelId": "5c9e863f-2716-467b-8799-4a67f378dcaa", + "serviceModelName": "AIM_TRANSPORT_00004", + "serviceModelVersion": "1.0", + "createdBulkDate": 1577354225000, + "action": "INSTANTIATE", + "isRetryEnabled": false, + "aLaCarte": false, + "requestSummary": { + "vnf": 1, + "vfModule": 2, + "volumeGroup": 1 + } +} \ No newline at end of file -- cgit 1.2.3-korg