aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java26
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java16
-rw-r--r--vid-automation/src/main/java/vid/automation/test/infra/Features.java1
-rw-r--r--vid-automation/src/test/java/org/onap/vid/api/InstantiationTemplatesApiTest.java43
4 files changed, 74 insertions, 12 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
index 6729bdac8..2cc76492f 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AsyncInstantiationBusinessLogicImpl.java
@@ -62,6 +62,7 @@ import org.onap.vid.model.Action;
import org.onap.vid.model.NameCounter;
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.BaseResource;
import org.onap.vid.model.serviceInstantiation.ServiceInstantiation;
import org.onap.vid.model.serviceInstantiation.VfModule;
@@ -177,7 +178,10 @@ public class AsyncInstantiationBusinessLogicImpl implements
Job job = jobAdapter.createServiceInstantiationJob(jobType, requestPerJob, templateId, userId, request.getTestApi(), optimisticUniqueServiceInstanceName, i);
UUID jobId = job.getUuid();
- asyncInstantiationRepository.saveServiceInfo(createServiceInfo(userId, requestPerJob, jobId, templateId, createdBulkDate, optimisticUniqueServiceInstanceName, serviceAction));
+ asyncInstantiationRepository.saveServiceInfo(createServiceInfo(
+ userId, requestPerJob, jobId, templateId, createdBulkDate,
+ optimisticUniqueServiceInstanceName, serviceAction,
+ requestSummaryOrNull(requestPerJob)));
asyncInstantiationRepository.addJobRequest(jobId, requestPerJob);
auditService.auditVidStatus(jobId, job.getStatus());
uuids.add(jobId);
@@ -187,7 +191,19 @@ public class AsyncInstantiationBusinessLogicImpl implements
return uuids;
}
- public Map<String, Long> getSummarizedChildrenMap(ServiceInstantiation serviceInstantiation){
+ Map<String, Long> requestSummaryOrNull(ServiceInstantiation request) {
+ if (!featureManager.isActive(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE)) {
+ return null;
+ }
+
+ if (getAction(request) != ServiceAction.INSTANTIATE) {
+ return null;
+ }
+
+ return summarizedChildrenMap(request);
+ }
+
+ public Map<String, Long> summarizedChildrenMap(ServiceInstantiation serviceInstantiation){
Stream<String> existingTypesStream =
allDeepChildResources(serviceInstantiation)
.map(this::getModelTypes)
@@ -242,7 +258,9 @@ public class AsyncInstantiationBusinessLogicImpl implements
return isNotEmpty(instanceName) ? getUniqueNameFromDbOnly(instanceName) : instanceName;
}
- protected ServiceInfo createServiceInfo(String userId, ServiceInstantiation serviceInstantiation, UUID jobId, UUID templateId, Date createdBulkDate, String optimisticUniqueServiceInstanceName, ServiceInfo.ServiceAction serviceAction) {
+ protected ServiceInfo createServiceInfo(String userId, ServiceInstantiation serviceInstantiation, UUID jobId,
+ UUID templateId, Date createdBulkDate, String optimisticUniqueServiceInstanceName,
+ ServiceInfo.ServiceAction serviceAction, Map<String, Long> requestSummary) {
return new ServiceInfo(
userId,
serviceInstantiation.isALaCarte(),
@@ -267,7 +285,7 @@ public class AsyncInstantiationBusinessLogicImpl implements
createdBulkDate,
serviceAction,
false,
- null);
+ requestSummary);
}
@Override
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
index 0cfe8059a..7a6b94a1a 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/AsyncInstantiationBusinessLogicTest.java
@@ -502,14 +502,22 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
}
@Test(dataProvider = "dataProviderSummarizedMap")
- public void getSummarizedMap(String pathInResource, Map<String, Long> expectedMap){
+ public void summarizedChildrenMap_givenServiceInstantiation_yieldCorrectMap(String pathInResource, Map<String, Long> expectedMap){
ServiceInstantiation serviceInstantiation = TestUtils.readJsonResourceFileAsObject(
pathInResource, ServiceInstantiation.class);
- Map<String, Long> childrenMap = asyncInstantiationBL.getSummarizedChildrenMap(serviceInstantiation);
+ Map<String, Long> childrenMap = asyncInstantiationBL.summarizedChildrenMap(serviceInstantiation);
assertEquals(childrenMap,expectedMap);
-
}
+ @Test
+ public void requestSummaryOrNull_givenActionWhichIsNotCreate_yieldNullRegardlessOfPayload(){
+ ServiceInstantiation serviceInstantiation = mock(ServiceInstantiation.class);
+
+ when(serviceInstantiation.getAction()).thenReturn(Action.Upgrade);
+ when(featureManager.isActive(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE)).thenReturn(true);
+
+ assertThat(asyncInstantiationBL.requestSummaryOrNull(serviceInstantiation), is(nullValue()));
+ }
@Test
public void whenPushBulkJob_thenJobRequestIsSaveInJobRequestDb() {
@@ -755,7 +763,7 @@ public class AsyncInstantiationBusinessLogicTest extends AsyncInstantiationBaseT
UUID.randomUUID(),
UUID.randomUUID(),
new Date(),
- "myName", ServiceInfo.ServiceAction.INSTANTIATE);
+ "myName", ServiceInfo.ServiceAction.INSTANTIATE, null);
assertEquals(SERVICE_MODEL_VERSION_ID, serviceInfo.getServiceModelId());
}
diff --git a/vid-automation/src/main/java/vid/automation/test/infra/Features.java b/vid-automation/src/main/java/vid/automation/test/infra/Features.java
index 01e4b7558..9f132e8ab 100644
--- a/vid-automation/src/main/java/vid/automation/test/infra/Features.java
+++ b/vid-automation/src/main/java/vid/automation/test/infra/Features.java
@@ -54,6 +54,7 @@ public enum Features implements Feature {
FLAG_2002_VNF_PLATFORM_MULTI_SELECT,
FLAG_2002_VFM_UPGRADE_ADDITIONAL_OPTIONS,
FLAG_2002_IDENTIFY_INVARIANT_MACRO_UUID_BY_BACKEND,
+ FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE,
FLAG_2004_TEMP_BUTTON_TO_INSTANTIATION_STATUS_FILTER,
FLAG_2002_UNLIMITED_MAX,
;
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 5e4d83af6..3c9786144 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
@@ -1,5 +1,6 @@
package org.onap.vid.api;
+import static java.util.Arrays.stream;
import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.arrayWithSize;
@@ -9,6 +10,7 @@ import static vid.automation.test.services.SimulatorApi.registerExpectationFromP
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.ImmutableMap;
import java.io.IOException;
import java.util.Map.Entry;
import java.util.function.Predicate;
@@ -21,8 +23,11 @@ import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import vid.automation.test.Constants.Users;
+import vid.automation.test.infra.FeatureTogglingTest;
+import vid.automation.test.infra.Features;
import vid.automation.test.model.User;
import vid.automation.test.services.AsyncJobsService;
import vid.automation.test.services.SimulatorApi.RegistrationStrategy;
@@ -63,6 +68,11 @@ public class InstantiationTemplatesApiTest extends AsyncInstantiationBase {
return new UserCredentials(user.credentials.userId, user.credentials.password, Users.SILVIA_ROBBINS_TYLER_SILVIA, "", "");
}
+ @BeforeMethod
+ public void setUp() {
+ registerExpectationFromPreset(new PresetAAIGetSubscribersGet(), RegistrationStrategy.CLEAR_THEN_SET);
+ }
+
@AfterMethod
protected void dropAllFromNameCounter() {
AsyncJobsService asyncJobsService = new AsyncJobsService();
@@ -87,10 +97,37 @@ public class InstantiationTemplatesApiTest extends AsyncInstantiationBase {
fileAsJsonNode("asyncInstantiation/templates__instance_template.json"));
}
- private JsonNode fileAsJsonNode(String fileName) throws IOException {
+ @Test
+ @FeatureTogglingTest(Features.FLAG_2004_CREATE_ANOTHER_INSTANCE_FROM_TEMPLATE)
+ public void templateTopology_givenDeploy_getServiceInfoHoldsRequestSummary() throws IOException {
+ ObjectNode request =
+ fileAsJsonNode(CREATE_BULK_OF_MACRO_REQUEST)
+ .put("bulkSize", 1)
+ .put("pause", false);
+
+ postAsyncInstanceRequest(request);
+
+ assertThat(fetchRequestSummary(request.at("/modelInfo/modelVersionId").asText()),
+ jsonEquals(ImmutableMap.of(
+ "vnf", 1L,
+ "vfModule", 2L,
+ "volumeGroup", 1L
+ )));
+ }
+
+ private JsonNode fetchRequestSummary(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),
- JsonNode.class);
+ ObjectNode.class);
}
public void templateTopology_givenDeploy_templateTopologyIsEquivalentToBody(JsonNode body) {
@@ -98,8 +135,6 @@ public class InstantiationTemplatesApiTest extends AsyncInstantiationBase {
}
public void templateTopology_givenDeploy_templateTopologyIsEquivalent(JsonNode body, JsonNode expectedTemplateTopology) {
- registerExpectationFromPreset(new PresetAAIGetSubscribersGet(), RegistrationStrategy.CLEAR_THEN_SET);
-
String uuid1 = postAsyncInstanceRequest(body);
JsonNode templateTopology1 = restTemplate.getForObject(templateTopologyUri(uuid1), JsonNode.class);