diff options
author | Ittay Stern <ittay.stern@att.com> | 2019-12-16 20:07:50 +0200 |
---|---|---|
committer | Ittay Stern <ittay.stern@att.com> | 2019-12-17 11:11:32 +0200 |
commit | 8f0f72817fa60e62091590081e1662ec88c45ba9 (patch) | |
tree | 82c88a9747087b4295181e3f72426616ad558fb6 /vid-app-common/src/test/java/org/onap | |
parent | 5f8ce4adff724009dad903887cd320a0095c1437 (diff) |
Templates: show correct values of sdnc-preload, volume-group name
Rename fields in VfModule:
- volumeGroupName instead of volumeGroupInstanceName
- sdncPreLoad instead of usePreload
Also allow "set" on pupups by providing an empty "existingNames"
Issue-ID: VID-724
Change-Id: I18ea0c3fdb4fe716c01902effbb577844000f958
Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/test/java/org/onap')
-rw-r--r-- | vid-app-common/src/test/java/org/onap/vid/model/serviceInstantiation/InstantiationModelSerializationTest.java | 215 |
1 files changed, 215 insertions, 0 deletions
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)))))); + } + +} |