diff options
5 files changed, 245 insertions, 18 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/ServiceInstantiationTemplate.java b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/ServiceInstantiationTemplate.java index 17ce1bcc3..4872ce2c8 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/ServiceInstantiationTemplate.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/ServiceInstantiationTemplate.java @@ -20,6 +20,8 @@ package org.onap.vid.model.serviceInstantiation; +import static java.util.Collections.emptyMap; + import java.util.Map; import java.util.Objects; import org.onap.vid.model.aaiTree.ExistingElementsCounterMaps; @@ -30,6 +32,7 @@ public class ServiceInstantiationTemplate extends ServiceInstantiation implement private final Map<String, Long> existingNetworksCounterMap; private final Map<String, Long> existingVnfGroupCounterMap; private final Map<String, Long> existingVRFCounterMap; + private final Map<String, String> existingNames = emptyMap(); public ServiceInstantiationTemplate( ServiceInstantiation baseService, @@ -78,4 +81,7 @@ public class ServiceInstantiationTemplate extends ServiceInstantiation implement return existingVRFCounterMap; } + public Map<String, String> getExistingNames() { + return existingNames; + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/VfModule.java b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/VfModule.java index ad5b39e28..89e25e662 100644 --- a/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/VfModule.java +++ b/vid-app-common/src/main/java/org/onap/vid/model/serviceInstantiation/VfModule.java @@ -22,6 +22,7 @@ package org.onap.vid.model.serviceInstantiation; import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL; +import com.fasterxml.jackson.annotation.JsonAlias; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.Collection; @@ -39,8 +40,8 @@ import org.onap.vid.mso.model.ModelInfo; @JsonInclude(NON_NULL) public class VfModule extends BaseResource implements JobAdapter.AsyncJobRequest { - @JsonInclude(NON_NULL) private final String volumeGroupInstanceName; - @JsonInclude(NON_NULL) private Boolean usePreload; + @JsonInclude(NON_NULL) @JsonProperty("volumeGroupName") private final String volumeGroupInstanceName; + @JsonInclude(NON_NULL) @JsonProperty("sdncPreLoad") private Boolean usePreload; private Map<String, String> supplementaryParams; @JsonInclude(NON_NULL) @@ -51,7 +52,7 @@ public class VfModule extends BaseResource implements JobAdapter.AsyncJobRequest public VfModule(@JsonProperty("modelInfo") ModelInfo modelInfo, @JsonProperty("instanceName") String instanceName, - @JsonProperty("volumeGroupName") String volumeGroupInstanceName, + @JsonProperty("volumeGroupName") @JsonAlias("volumeGroupInstanceName") String volumeGroupInstanceName, @JsonProperty("action") String action, @JsonProperty("lcpCloudRegionId") String lcpCloudRegionId, @JsonProperty("legacyRegion") String legacyRegion, @@ -59,7 +60,7 @@ public class VfModule extends BaseResource implements JobAdapter.AsyncJobRequest @JsonProperty("instanceParams") List<Map<String, String>> instanceParams, @JsonProperty("supplementaryFileContent") Map<String, String> supplementaryParams, @JsonProperty("rollbackOnFailure") boolean rollbackOnFailure, - @JsonProperty("sdncPreLoad") Boolean usePreload, + @JsonProperty("sdncPreLoad") @JsonAlias("usePreload") Boolean usePreload, @JsonProperty("instanceId") String instanceId, @JsonProperty("trackById") String trackById, @JsonProperty("isFailed") Boolean isFailed, diff --git a/vid-app-common/src/test/java/org/onap/vid/model/serviceInstantiation/InstantiationModelSerializationTest.java b/vid-app-common/src/test/java/org/onap/vid/model/serviceInstantiation/InstantiationModelSerializationTest.java new file mode 100644 index 000000000..b5d281622 --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/model/serviceInstantiation/InstantiationModelSerializationTest.java @@ -0,0 +1,215 @@ +/*- + * ============LICENSE_START======================================================= + * VID + * ================================================================================ + * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.vid.model.serviceInstantiation; + +import static java.util.Collections.emptyMap; +import static net.javacrumbs.jsonunit.JsonMatchers.jsonNodeAbsent; +import static net.javacrumbs.jsonunit.JsonMatchers.jsonPartEquals; +import static org.hamcrest.CoreMatchers.either; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasProperty; +import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.Matchers.samePropertyValuesAs; +import static org.onap.vid.model.Action.Create; +import static org.onap.vid.testUtils.TestUtils.setStringsInStringProperties; +import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import java.lang.reflect.InvocationTargetException; +import java.util.Map; +import org.apache.commons.beanutils.PropertyUtils; +import org.onap.vid.model.VidNotions; +import org.onap.vid.model.VidNotions.InstantiationType; +import org.onap.vid.model.VidNotions.InstantiationUI; +import org.onap.vid.model.VidNotions.ModelCategory; +import org.onap.vid.mso.model.ModelInfo; +import org.testng.annotations.Test; + +public class InstantiationModelSerializationTest { + + final ImmutableList<Map<String, String>> instanceParams = + ImmutableList.of( + ImmutableMap.of("one", "1"), + ImmutableMap.of("two", "2") + ); + + @Test + public void serializeAndDeserializeServiceInstantiation() throws Exception { + + ServiceInstantiation serviceInstantiation = new ServiceInstantiation( + newModelInfo(), + "owningEntityId", + "owningEntityName", + "projectName", + "globalSubscriberId", + "subscriberName", + "productFamilyId", + "instanceName", + "subscriptionServiceType", + "lcpCloudRegionId", + "legacyRegion", + "tenantId", + "tenantName", + "aicZoneId", + "aicZoneName", + emptyMap(), + emptyMap(), + emptyMap(), + emptyMap(), + instanceParams, + true, + 1, + true, + true, + "testApi", + "instanceId", + "Delete", + "trackById", + true, + "statusMessage", + new VidNotions(InstantiationUI.ANY_ALACARTE_WHICH_NOT_EXCLUDED, + ModelCategory.INFRASTRUCTURE_VPN, + InstantiationUI.INFRASTRUCTURE_VPN, + InstantiationType.Macro) + ); + + verifySerializationAndDeserialization(serviceInstantiation); + } + + @Test + public void serializeAndDeserializeVnf() throws Exception { + + Vnf vnf = new Vnf( + newModelInfo(), "productFamilyId", + "instanceName", + "Upgrade", + "platformName", + "lcpCloudRegionId", + "legacyRegion", + "tenantId", + instanceParams, + "lineOfBusinessName", + true, + "instanceId", + emptyMap(), + "trackById", + true, + "statusMessage", + 5); + + verifySerializationAndDeserialization(vnf); + } + + @Test + public void serializeAndDeserializeVfModule() throws Exception { + + ImmutableMap<String, String> supplementaryParams = ImmutableMap.of( + "uno", "1", + "dos", "2", + "tres", "3" + ); + + VfModule vfModule = new VfModule( + newModelInfo(), + "instanceName", + "volumeGroupInstanceName", + "Delete", + "lcpCloudRegionId", + "legacyRegion", + "tenantId", + instanceParams, + supplementaryParams, + true, + true, + "instanceId", + "trackById", + true, + "statusMessage", + true, + true, + 1); + + verifySerializationAndDeserialization(vfModule); + } + + @Test + public void VfModule_sdncPreLoad_shouldBeSerializedWithCorrectName() { + + final boolean USE_PRELOAD = true; + + VfModule vfModule = new VfModule(newModelInfo(), null, null, null, + null, null, null, null, null, false, + /* HERE ====> */ USE_PRELOAD, + null, null, null, null, null, null, null); + + assertThat(vfModule, jsonPartEquals("sdncPreLoad", USE_PRELOAD)); + assertThat(vfModule, jsonNodeAbsent("usePreload")); + } + + @Test + public void VfModule_volumeGroupName_shouldBeSerializedWithCorrectName() { + + final String VOLUME_GROUP_INSTANCE_NAME = "my volume group name"; + + VfModule vfModule = new VfModule(newModelInfo(), null, + /* HERE ====> */ VOLUME_GROUP_INSTANCE_NAME, + null, null, null, null, null, null, + false, null, null, null, null, null, + null, null, null); + + assertThat(vfModule, jsonPartEquals("volumeGroupName", VOLUME_GROUP_INSTANCE_NAME)); + assertThat(vfModule, jsonNodeAbsent("volumeGroupInstanceName")); + } + + private ModelInfo newModelInfo() { + ModelInfo modelInfo = new ModelInfo(); + setStringsInStringProperties(modelInfo); + return modelInfo; + } + + private void verifySerializationAndDeserialization(Object object) throws Exception { + + assertThatAllValuesAreNotDefaultValues(object); + + String valueAsString = JACKSON_OBJECT_MAPPER.writeValueAsString(object); + Object objectReconstructed = JACKSON_OBJECT_MAPPER.readValue(valueAsString, object.getClass()); + + // verify that all fields' values were reconstructed + assertThat(objectReconstructed, samePropertyValuesAs(object)); + } + + private void assertThatAllValuesAreNotDefaultValues(Object object) + throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { + assertThat("setup is expected to have no field with a default Java value", + PropertyUtils.describe(object).entrySet(), + not(hasItem(hasProperty("value", + either(nullValue()) + .or(equalTo(0)) + .or(equalTo("")) + .or(equalTo(false)) + .or(equalTo(Create)))))); + } + +} diff --git a/vid-automation/src/test/resources/asyncInstantiation/templates__instance_template.json b/vid-automation/src/test/resources/asyncInstantiation/templates__instance_template.json index a7b3a04c5..5a327fdd7 100644 --- a/vid-automation/src/test/resources/asyncInstantiation/templates__instance_template.json +++ b/vid-automation/src/test/resources/asyncInstantiation/templates__instance_template.json @@ -30,6 +30,8 @@ "existingVRFCounterMap": {}, "existingVnfGroupCounterMap": {}, "existingNetworksCounterMap": {}, + "existingNames": { + }, "vnfs": { "vProbe_NC_VNF 0": { "modelInfo": { @@ -87,7 +89,7 @@ "modelType": "vfModule", "modelVersion": "1" }, - "instanceName": "hvf6arlba007_lba_dj_01", + "instanceName": "my_hvf6arlba007_lba_dj_01", "action": "Create", "lcpCloudRegionId": "hvf6", "tenantId": "4914ab0ab3a743e58f0eefdacc1dde77", @@ -97,8 +99,8 @@ "rollbackOnFailure": true, "trackById": "b134410e-3bc0-478e-883e-1b6bdf8a28df", "isFailed": false, - "volumeGroupInstanceName": "hvf6arlba007_lba_dj_01_vol", - "usePreload": true + "volumeGroupName": "my_special_hvf6arlba007_lba_dj_01_vol", + "sdncPreLoad": true } } }, diff --git a/vid-webpack-master/cypress/integration/iFrames/instantiation-templates.e2e.ts b/vid-webpack-master/cypress/integration/iFrames/instantiation-templates.e2e.ts index dbb9bca4d..f9fe68b20 100644 --- a/vid-webpack-master/cypress/integration/iFrames/instantiation-templates.e2e.ts +++ b/vid-webpack-master/cypress/integration/iFrames/instantiation-templates.e2e.ts @@ -1,5 +1,3 @@ -import ObjectLike = Cypress.ObjectLike; - describe('Drawing Board: Instantiation Templates', function () { describe('Instantiation templates ', () => { @@ -31,13 +29,12 @@ describe('Drawing Board: Instantiation Templates', function () { assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd(); }); - it('View a template’s details as expected', ()=> { + it('Given a stored template - when "edit" vnf and vfmodules are opened - then template’s details are visible as expected', ()=> { loadDrawingBoardWithRecreateMode(); // Then... - cy.drawingBoardTreeOpenContextMenuByElementDataTestId("node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0") - .drawingBoardTreeClickOnContextMenuOptionByName('Edit') + editNode("node-21ae311e-432f-4c54-b855-446d0b8ded72-vProbe_NC_VNF 0") .getElementByDataTestsId("instanceName").should('have.value', 'hvf6arlba007') .getElementByDataTestsId("productFamily").should('contain', 'Emanuel') .getElementByDataTestsId("tenant").should('contain', 'DN5242-Nov21-T1') @@ -47,19 +44,20 @@ describe('Drawing Board: Instantiation Templates', function () { .checkPlatformValue('xxx1') .getElementByDataTestsId("cancelButton").click(); - cy.drawingBoardTreeOpenContextMenuByElementDataTestId("node-c5b26cc1-a66f-4b69-aa23-6abc7c647c88-vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0") - .drawingBoardTreeClickOnContextMenuOptionByName('Edit') + editNode("node-c5b26cc1-a66f-4b69-aa23-6abc7c647c88-vprobe_nc_vnf0..VprobeNcVnf..FE_base_module..module-0") .getElementByDataTestsId("instanceName").should('have.value', 'hvf6arlba007_lba_Base_01') .getElementByDataTestsId("lcpRegion").should('contain', 'hvf6') .getElementByDataTestsId("tenant").should('contain', 'DN5242-Nov21-T1') .getElementByDataTestsId("rollback").should('contain', 'Rollback') .getElementByDataTestsId("cancelButton").click(); - cy.drawingBoardTreeOpenContextMenuByElementDataTestId("node-c09e4530-8fd8-418f-9483-2f57ce927b05-vprobe_nc_vnf0..VprobeNcVnf..FE_Add_On_Module_vlbagent_eph..module-1") - .drawingBoardTreeClickOnContextMenuOptionByName('Edit') + editNode("node-c09e4530-8fd8-418f-9483-2f57ce927b05-vprobe_nc_vnf0..VprobeNcVnf..FE_Add_On_Module_vlbagent_eph..module-1") + .getElementByDataTestsId("instanceName").should('have.value', 'my_hvf6arlba007_lba_dj_01') + .getElementByDataTestsId("volumeGroupName").should('have.value', 'my_special_hvf6arlba007_lba_dj_01_vol') .getElementByDataTestsId("lcpRegion").should('contain', 'hvf6') .getElementByDataTestsId("tenant").should('contain', 'DN5242-Nov21-T1') .getElementByDataTestsId("rollback").should('contain', 'Rollback') + .getElementByDataTestsId("sdncPreLoad").should('have.value', 'on') .getElementByDataTestsId("cancelButton").click(); @@ -67,7 +65,7 @@ describe('Drawing Board: Instantiation Templates', function () { assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd(); }); - it(`Edit the service`, function () { + it(`Given a stored template - when "edit" service is opened - then template’s details are visible as expected`, function () { loadDrawingBoardWithRecreateMode(); @@ -80,11 +78,11 @@ describe('Drawing Board: Instantiation Templates', function () { .getElementByDataTestsId("project").should('contain', 'WATKINS') .getElementByDataTestsId("rollback").should('contain', 'Rollback'); + }); }); - }); }); }); @@ -112,6 +110,11 @@ function loadDrawingBoardWithRecreateMode() { cy.wait('@templateTopology'); } +function editNode(dataTestId: string) { + return cy.drawingBoardTreeOpenContextMenuByElementDataTestId(dataTestId) + .drawingBoardTreeClickOnContextMenuOptionByName('Edit') +} + function assertThatBodyFromDeployRequestEqualsToTemplateFromBackEnd() { cy.getDrawingBoardDeployBtn().click(); cy.wait('@expectedPostAsyncInstantiation').then(xhr => { |