summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/test')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java24
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/model/serviceInstantiation/InstantiationModelSerializationTest.java215
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java24
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/MsoRequestBuilderTest.java25
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java5
-rw-r--r--vid-app-common/src/test/resources/payload_jsons/vfmodule/upgrade_vfmodule_e2e__fe_input_cypress.json1
-rw-r--r--vid-app-common/src/test/resources/payload_jsons/vfmodule/upgrade_vfmodule_e2e__payload_to_mso.json1
7 files changed, 271 insertions, 24 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java b/vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java
index 012c37f4d..27be3fb50 100644
--- a/vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/dal/AsyncInstantiationRepositoryTest.java
@@ -45,6 +45,7 @@ import org.onap.vid.config.MockedAaiClientAndFeatureManagerConfig;
import org.onap.vid.job.Job;
import org.onap.vid.model.ResourceInfo;
import org.onap.vid.model.ServiceInfo;
+import org.onap.vid.model.ServiceInfo.ServiceAction;
import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
import org.onap.vid.mso.rest.AsyncRequestStatus;
import org.onap.vid.mso.rest.RequestStatus;
@@ -73,14 +74,16 @@ public class AsyncInstantiationRepositoryTest extends AsyncInstantiationBaseTest
LocalDateTime NOW = LocalDateTime.now();
- addNewServiceInfo(UUID.randomUUID(), "abc", "1", NOW.minusYears(1L), NOW, COMPLETED, false, false,
- MODEL_UUID);
- addNewServiceInfo(UUID.randomUUID(), "abc", "2", NOW, NOW, COMPLETED, false, false,
- MODEL_UUID_2);
- addNewServiceInfo(UUID.randomUUID(), "abc", "3", NOW, NOW, COMPLETED, false, false,
- MODEL_UUID);
- addNewServiceInfo(UUID.randomUUID(), "abc", "hidden", NOW, NOW, COMPLETED, true, false,
- MODEL_UUID);
+ addNewServiceInfoWithAction(UUID.randomUUID(), "abc", "0", NOW.minusYears(1L), NOW, COMPLETED, false, false,
+ MODEL_UUID, ServiceAction.RESUME);
+ addNewServiceInfoWithAction(UUID.randomUUID(), "abc", "1", NOW.minusYears(1L), NOW, COMPLETED, false, false,
+ MODEL_UUID, ServiceAction.INSTANTIATE);
+ addNewServiceInfoWithAction(UUID.randomUUID(), "abc", "2", NOW, NOW, COMPLETED, false, false,
+ MODEL_UUID_2, ServiceAction.INSTANTIATE);
+ addNewServiceInfoWithAction(UUID.randomUUID(), "abc", "3", NOW, NOW, COMPLETED, false, false,
+ MODEL_UUID, ServiceAction.INSTANTIATE);
+ addNewServiceInfoWithAction(UUID.randomUUID(), "abc", "hidden", NOW, NOW, COMPLETED, true, false,
+ MODEL_UUID, ServiceAction.INSTANTIATE);
}
@DataProvider
@@ -93,14 +96,15 @@ public class AsyncInstantiationRepositoryTest extends AsyncInstantiationBaseTest
@Test(dataProvider = "listServicesByServiceModelIdDataProvider")
public void testListServicesByServiceModelId(String desc, String modelUUID, String... expectedResult) {
- List<ServiceInfo> serviceInfoListResult = asyncInstantiationRepository.listServicesByServiceModelId(UUID.fromString(modelUUID));
+ List<ServiceInfo> serviceInfoListResult = asyncInstantiationRepository.
+ listInstantiatedServicesByServiceModelId(UUID.fromString(modelUUID));
assertThat(desc, serviceInfoListResult.stream().map(ServiceInfo::getServiceInstanceName).collect(toList()),
contains(expectedResult));
}
@Test
public void whenFilterServiceByNotExistUUID_emptyListIsReturned() {
- List<ServiceInfo> serviceInfoListResult = asyncInstantiationRepository.listServicesByServiceModelId(UUID.randomUUID());
+ List<ServiceInfo> serviceInfoListResult = asyncInstantiationRepository.listInstantiatedServicesByServiceModelId(UUID.randomUUID());
assertThat(serviceInfoListResult, is(empty()));
}
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-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java
index d41ce87bf..7c0abbe6e 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBaseTest.java
@@ -23,7 +23,6 @@ package org.onap.vid.services;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.core.IsEqual.equalTo;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
@@ -49,6 +48,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.inject.Inject;
import org.hibernate.SessionFactory;
+import org.jetbrains.annotations.NotNull;
import org.onap.portalsdk.core.domain.FusionObject;
import org.onap.portalsdk.core.service.DataAccessService;
import org.onap.vid.aai.AaiClientInterface;
@@ -56,6 +56,7 @@ import org.onap.vid.aai.ExceptionWithRequestInfo;
import org.onap.vid.job.Job.JobStatus;
import org.onap.vid.model.Action;
import org.onap.vid.model.ServiceInfo;
+import org.onap.vid.model.ServiceInfo.ServiceAction;
import org.onap.vid.model.VidNotions;
import org.onap.vid.model.serviceInstantiation.InstanceGroup;
import org.onap.vid.model.serviceInstantiation.Network;
@@ -67,7 +68,6 @@ import org.onap.vid.mso.model.ModelInfo;
import org.onap.vid.mso.rest.AsyncRequestStatus;
import org.onap.vid.mso.rest.RequestStatus;
import org.onap.vid.properties.Features;
-import org.onap.vid.services.AsyncInstantiationBusinessLogicTest.ServiceInfoComparator;
import org.onap.vid.utils.DaoUtils;
import org.onap.vid.utils.TimeUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -149,9 +149,19 @@ public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests
});
}
+
protected void addNewServiceInfo(UUID uuid, String userId, String serviceName, LocalDateTime createDate,
LocalDateTime statusModifiedDate, JobStatus status, boolean isHidden, boolean retryEnabled,
String modelUUID) {
+ ServiceInfo serviceInfo = createServiceInfo(uuid, userId, serviceName, createDate, statusModifiedDate, status,
+ isHidden, retryEnabled, modelUUID);
+ dataAccessService.saveDomainObject(serviceInfo, getPropsMap());
+ setCreateDateToServiceInfo(uuid, createDate);
+ serviceCount++;
+ }
+ @NotNull
+ private ServiceInfo createServiceInfo(UUID uuid, String userId, String serviceName, LocalDateTime createDate,
+ LocalDateTime statusModifiedDate, JobStatus status, boolean isHidden, boolean retryEnabled, String modelUUID) {
ServiceInfo serviceInfo = new ServiceInfo();
serviceInfo.setJobId(uuid);
serviceInfo.setUserId(userId);
@@ -164,10 +174,18 @@ public class AsyncInstantiationBaseTest extends AbstractTestNGSpringContextTests
serviceInfo.setRetryEnabled(retryEnabled);
serviceInfo.setServiceModelId(modelUUID);
serviceInfo.setHidden(isHidden);
+ return serviceInfo;
+ }
+
+ protected void addNewServiceInfoWithAction(UUID uuid, String userId, String serviceName, LocalDateTime createDate,
+ LocalDateTime statusModifiedDate, JobStatus status, boolean isHidden, boolean retryEnabled,
+ String modelUUID, ServiceAction action) {
+ ServiceInfo serviceInfo = createServiceInfo(uuid, userId, serviceName, createDate, statusModifiedDate, status,
+ isHidden, retryEnabled, modelUUID);
+ serviceInfo.setAction(action);
dataAccessService.saveDomainObject(serviceInfo, getPropsMap());
setCreateDateToServiceInfo(uuid, createDate);
serviceCount++;
-
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/MsoRequestBuilderTest.java b/vid-app-common/src/test/java/org/onap/vid/services/MsoRequestBuilderTest.java
index cb59129c3..efd9e2b27 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/MsoRequestBuilderTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/MsoRequestBuilderTest.java
@@ -22,6 +22,7 @@ package org.onap.vid.services;
import static com.google.common.collect.Maps.newHashMap;
import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
+import static net.javacrumbs.jsonunit.JsonMatchers.jsonNodeAbsent;
import static net.javacrumbs.jsonunit.JsonMatchers.jsonPartEquals;
import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
import static org.hamcrest.MatcherAssert.assertThat;
@@ -47,7 +48,9 @@ import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.inject.Inject;
+import net.javacrumbs.jsonunit.ConfigurableJsonMatcher;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.BooleanUtils;
import org.hibernate.SessionFactory;
import org.mockito.Mock;
import org.mockito.Mockito;
@@ -611,19 +614,23 @@ public class MsoRequestBuilderTest extends AsyncInstantiationBaseTest {
assertThat(result, jsonEquals(expected).when(IGNORING_ARRAY_ORDER));
}
- @Test(dataProvider = "trueAndFalse", dataProviderClass = TestUtils.class)
- public void generateReplaceVfModuleRequest_whenRetainAssignmentsProvidedFromFrontend_retainAssignmentsToMsoIsTheSame(boolean retainAssignments) {
-
+ @Test(dataProvider = "trueAndFalseAndNull", dataProviderClass = TestUtils.class)
+ public void generateReplaceVfModuleRequest_whenRetainAssignmentsProvidedFromFrontend_retainAssignmentsToMsoIsTheSame(Boolean retainAssignments) {
assertThat(generatedVfModuleReplaceRequest(retainAssignments, null, null),
- jsonPartEquals("requestDetails.requestParameters.retainAssignments", retainAssignments));
+ jsonPartEqualsOrUndefined(
+ "requestDetails.requestParameters.retainAssignments", retainAssignments));
}
- @Test
- public void generateReplaceVfModuleRequest_whenRetainVolumeGroupIsTrue_rebuildVolumeGroupIsFalse() {
- boolean retainVolumeGroups = true;
-
+ @Test(dataProvider = "trueAndFalseAndNull", dataProviderClass = TestUtils.class)
+ public void generateReplaceVfModuleRequest_whenRetainVolumeGroupIsGiven_rebuildVolumeGroupIsNegated(Boolean retainVolumeGroups) {
assertThat(generatedVfModuleReplaceRequest(null, retainVolumeGroups, null),
- jsonPartEquals("requestDetails.requestParameters.rebuildVolumeGroups", false));
+ jsonPartEqualsOrUndefined("requestDetails.requestParameters.rebuildVolumeGroups", BooleanUtils.negate(retainVolumeGroups)));
+ }
+
+ private <T> ConfigurableJsonMatcher<T> jsonPartEqualsOrUndefined(String path, Boolean expected) {
+ return (expected != null)
+ ? jsonPartEquals(path, expected)
+ : jsonNodeAbsent(path);
}
@Test
diff --git a/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java b/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java
index 857221a2a..862b8db8f 100644
--- a/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java
+++ b/vid-app-common/src/test/java/org/onap/vid/testUtils/TestUtils.java
@@ -389,4 +389,9 @@ public class TestUtils {
return new Object[][]{{true}, {false}};
}
+ @DataProvider
+ public static Object[][] trueAndFalseAndNull() {
+ return new Boolean[][]{{Boolean.TRUE}, {Boolean.FALSE}, {null}};
+ }
+
}
diff --git a/vid-app-common/src/test/resources/payload_jsons/vfmodule/upgrade_vfmodule_e2e__fe_input_cypress.json b/vid-app-common/src/test/resources/payload_jsons/vfmodule/upgrade_vfmodule_e2e__fe_input_cypress.json
index 748b5f267..d215a4331 100644
--- a/vid-app-common/src/test/resources/payload_jsons/vfmodule/upgrade_vfmodule_e2e__fe_input_cypress.json
+++ b/vid-app-common/src/test/resources/payload_jsons/vfmodule/upgrade_vfmodule_e2e__fe_input_cypress.json
@@ -34,7 +34,6 @@
"b0732bed-3ddf-43cc-b193-7f18db84e476": {
"action": "None_Upgrade",
"retainAssignments" : false,
- "retainVolumeGroups" : false,
"sdncPreLoad" : true,
"instanceName": "PST-VfMod-Replace-5-Vfmod",
"instanceId": "b0732bed-3ddf-43cc-b193-7f18db84e476",
diff --git a/vid-app-common/src/test/resources/payload_jsons/vfmodule/upgrade_vfmodule_e2e__payload_to_mso.json b/vid-app-common/src/test/resources/payload_jsons/vfmodule/upgrade_vfmodule_e2e__payload_to_mso.json
index 45b89f730..91f80e9f1 100644
--- a/vid-app-common/src/test/resources/payload_jsons/vfmodule/upgrade_vfmodule_e2e__payload_to_mso.json
+++ b/vid-app-common/src/test/resources/payload_jsons/vfmodule/upgrade_vfmodule_e2e__payload_to_mso.json
@@ -34,7 +34,6 @@
],
"requestParameters": {
"retainAssignments": false,
- "rebuildVolumeGroups":true,
"usePreload" : true,
"userParams": [],
"testApi": "VNF_API"