diff options
9 files changed, 543 insertions, 56 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java b/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java index 01b005c4b..6bd98fff6 100644 --- a/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java +++ b/vid-app-common/src/main/java/org/onap/vid/controller/AsyncInstantiationController.java @@ -20,10 +20,13 @@ package org.onap.vid.controller; +import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER; + +import java.util.List; +import java.util.UUID; +import javax.servlet.http.HttpServletRequest; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.vid.exceptions.AccessDeniedException; -import org.onap.vid.exceptions.OperationNotAllowedException; -import org.onap.vid.model.ExceptionResponse; import org.onap.vid.model.JobAuditStatus; import org.onap.vid.model.ServiceInfo; import org.onap.vid.model.serviceInstantiation.ServiceInstantiation; @@ -34,16 +37,14 @@ import org.onap.vid.services.AsyncInstantiationBusinessLogic; import org.onap.vid.services.AuditService; import org.onap.vid.utils.SystemPropertiesWrapper; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import org.togglz.core.manager.FeatureManager; -import javax.servlet.http.HttpServletRequest; -import java.util.List; -import java.util.UUID; - -import static org.onap.vid.utils.KotlinUtilsKt.JACKSON_OBJECT_MAPPER; -import static org.springframework.http.HttpStatus.METHOD_NOT_ALLOWED; - @RestController @RequestMapping(AsyncInstantiationController.ASYNC_INSTANTIATION) @@ -69,12 +70,6 @@ public class AsyncInstantiationController extends VidRestrictedBaseController { this.systemPropertiesWrapper = systemPropertiesWrapper; } - @ExceptionHandler(OperationNotAllowedException.class) - @ResponseStatus(value=METHOD_NOT_ALLOWED) - public ExceptionResponse illegalStateExceptionHandler(Exception e) { - return ControllersUtils.handleException(e, LOGGER); - } - /** * Gets the new services status. * @param request the request diff --git a/vid-app-common/src/test/java/org/onap/vid/aai/AaiResponseTranslatorTest.java b/vid-app-common/src/test/java/org/onap/vid/aai/AaiResponseTranslatorTest.java index 045488605..c85c96b6d 100644 --- a/vid-app-common/src/test/java/org/onap/vid/aai/AaiResponseTranslatorTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/aai/AaiResponseTranslatorTest.java @@ -21,18 +21,19 @@ package org.onap.vid.aai; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigData; import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigDataError; import org.onap.vid.aai.AaiResponseTranslator.PortMirroringConfigDataOk; import org.testng.annotations.Test; -import java.io.IOException; - -import static org.hamcrest.CoreMatchers.*; -import static org.hamcrest.MatcherAssert.assertThat; - public class AaiResponseTranslatorTest { private static final ObjectMapper objectMapper = new ObjectMapper(); @@ -116,6 +117,7 @@ public class AaiResponseTranslatorTest { } + @Test public void extractPortMirroringConfigData_givenAaiResponseWithoutRegionIdName_yieldException() throws IOException { final JsonNode aaiPayload = objectMapper.readTree("" + diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java index aeb010071..10f272a36 100644 --- a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java +++ b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserImpl2Test.java @@ -127,6 +127,19 @@ public class ToscaParserImpl2Test { assertJsonStringEqualsIgnoreNulls(om.writeValueAsString(expectedService), om.writeValueAsString(actualService)); } + + @Test + public void testScalingPolicyOfGroup() throws AsdcCatalogException, SdcToscaParserException { + String vnfGroupingUuid = "4117a0b6-e234-467d-b5b9-fe2f68c8b0fc"; + ISdcCsarHelper sdcCsarHelper = toscaParserImpl2.getSdcCsarHelper(getCsarPath(vnfGroupingUuid)); + Map<String, Integer> policiesTargets = toscaParserImpl2.extractScalingPolicyOfGroup(sdcCsarHelper); + + assertThat(policiesTargets, is(ImmutableMap.of( + "vdorothea_svc_vprs_proxy 0", 2, + "groupingservicefortest..ResourceInstanceGroup..1", 3 + ))); + } + @Test(dataProvider = "expectedServiceModel") public void assertEqualBetweenObjects(String uuid, ToscaParserMockHelper mockHelper) throws Exception { final Path csarPath = getCsarPath(mockHelper.getUuid()); diff --git a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java index 2ea37f4bc..63cd62cf5 100644 --- a/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java +++ b/vid-app-common/src/test/java/org/onap/vid/mso/MsoBusinessLogicImplTest.java @@ -845,20 +845,14 @@ public class MsoBusinessLogicImplTest extends AbstractTestNGSpringContextTests { @Test public void shouldProperlyGetDeactivateAndCloudDeletePathWithProperParameters() { - // given - String serviceInstanceId = "testServiceId"; - String vnfInstanceId = "testVnfInstanceId"; - String vfModuleInstanceId = "testVfModuleInstanceId"; - String path = validateEndpointPath(MsoProperties.MSO_REST_API_VF_MODULE_INSTANCE); - path = path.replaceFirst(SVC_INSTANCE_ID, serviceInstanceId); - path = path.replaceFirst(VNF_INSTANCE_ID, vnfInstanceId); - path += "/" + vfModuleInstanceId + "/deactivateAndCloudDelete"; // when - String response = msoBusinessLogic.getDeactivateAndCloudDeletePath(serviceInstanceId, vnfInstanceId, vfModuleInstanceId); + String response = msoBusinessLogic.getDeactivateAndCloudDeletePath("testServiceId", "testVnfInstanceId", "testVfModuleInstanceId"); // then - assertThat(response).isEqualTo(path); + String expectedPath = "/serviceInstantiation/v7/serviceInstances/testServiceId/vnfs/testVnfInstanceId/"+ + "vfModules/testVfModuleInstanceId/deactivateAndCloudDelete"; + assertThat(response).isEqualTo(expectedPath); } @Test diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeIntegrativeTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeIntegrativeTest.java new file mode 100644 index 000000000..00a9995cb --- /dev/null +++ b/vid-app-common/src/test/java/org/onap/vid/services/AAIServiceTreeIntegrativeTest.java @@ -0,0 +1,454 @@ +/*- + * ============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.services; + +import static net.javacrumbs.jsonunit.JsonMatchers.jsonEquals; +import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.testng.Assert.assertNull; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; +import java.io.IOException; +import java.net.URI; +import java.util.Arrays; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import javax.ws.rs.core.Response; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.onap.vid.aai.AaiClientInterface; +import org.onap.vid.aai.ExceptionWithRequestInfo; +import org.onap.vid.aai.util.AAITreeConverter; +import org.onap.vid.asdc.AsdcCatalogException; +import org.onap.vid.asdc.parser.ServiceModelInflator; +import org.onap.vid.exceptions.GenericUncheckedException; +import org.onap.vid.model.Action; +import org.onap.vid.model.ServiceModel; +import org.onap.vid.model.aaiTree.AAITreeNode; +import org.onap.vid.model.aaiTree.FailureAAITreeNode; +import org.onap.vid.model.aaiTree.ServiceInstance; +import org.onap.vid.model.aaiTree.Vnf; +import org.onap.vid.testUtils.TestUtils; +import org.springframework.http.HttpMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +public class AAIServiceTreeIntegrativeTest { + + @Mock + private AaiClientInterface aaiClient; + + @Mock + private Response aaiGetVersionByInvariantIdResponse; + + @Mock + ExceptionWithRequestInfo exceptionWithRequestInfo; + + @Mock + VidService sdcService; + + @Mock + ServiceModelInflator serviceModelInflator; + + @InjectMocks + private AAITreeNodeBuilder aaiTreeNodeBuilder; + + @InjectMocks + private AAITreeConverter aaiTreeConverter; + + private ExecutorService executorService = Executors.newFixedThreadPool(10); + + private final ObjectMapper mapper = new ObjectMapper(); + + private String globalCustomerID = "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"; + private String serviceType = "vWINIFRED"; + private String serviceInstanceId = "62888f15-6d24-4f7b-92a7-c3f35beeb215"; + + //TODO Amichai: if in the future it is neede, add here the SUFFIX to the URL: "?format=simple" + private String serviceInstanceRequestUri = "business/customers/customer/" + + globalCustomerID + + "/service-subscriptions/service-subscription/" + + serviceType + + "/service-instances/service-instance/" + + serviceInstanceId; + + private static String ServiceInstanceResponseString = "{\"service-instance-id\":\"62888f15-6d24-4f7b-92a7-c3f35beeb215\"," + + "\"service-instance-name\": \"Dror123\"," + + "\"environment-context\": \"null\"," + + "\"workload-context\": \"null\"," + + "\"model-invariant-id\": \"35340388-0b82-4d3a-823d-cbddf842be52\"," + + "\"model-version-id\": \"4e799efd-fd78-444d-bc25-4a3cde2f8cb0\"," + + "\"resource-version\": \"1515515088894\"," + + "\"orchestration-status\": \"Active\"," + + "\"relationship-list\": {" + + "\"relationship\": [{" + + "\"related-to\": \"project\"," + + "\"relationship-label\": \"org.onap.relationships.inventory.Uses\"," + + "\"related-link\": \"/aai/v12/business/projects/project/DFW\"," + + "\"relationship-data\": [{" + + "\"relationship-key\": \"project.project-name\"," + + "\"relationship-value\": \"WATKINS\"}]},{" + + "\"related-to\": \"generic-vnf\"," + + "\"relationship-label\": \"org.onap.relationships.inventory.ComposedOf\"," + + "\"related-link\": \"/aai/v12/network/generic-vnfs/generic-vnf/59bde732-9b84-46bd-a59a-3c45fee0538b\"," + + "\"relationship-data\": [{" + + "\"relationship-key\": \"generic-vnf.vnf-id\"," + + "\"relationship-value\": \"59bde732-9b84-46bd-a59a-3c45fee0538b\"}]," + + "\"related-to-property\": [{" + + "\"property-key\": \"generic-vnf.vnf-name\"," + + "\"property-value\": \"DROR_vsp\"}]},{" + + "\"related-to\": \"owning-entity\"," + + "\"relationship-label\": \"org.onap.relationships.inventory.BelongsTo\"," + + "\"related-link\": \"/aai/v12/business/owning-entities/owning-entity/43b8a85a-0421-4265-9069-117dd6526b8a\"," + + "\"relationship-data\": [{" + + "\"relationship-key\": \"owning-entity.owning-entity-id\"," + + "\"relationship-value\": \"43b8a85a-0421-4265-9069-117dd6526b8a\"}]}]}}"; + + //TODO Amichai: if in the future it is neede, add here the SUFFIX to the URL: "?format=simple" + private static String genericVnfRequestUri = "/aai/v12/network/generic-vnfs/generic-vnf/59bde732-9b84-46bd-a59a-3c45fee0538b"; + + private String genericVnfResponseString(boolean isDuplicatedKeysInTenantRelation) { + + return + "{\"nf-role\":\"\"," + + "\"service-id\":\"a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb\"," + + "\"relationship-list\":{" + + "\"relationship\":[{" + + "\"related-to\":\"service-instance\"," + + "\"relationship-data\":[{" + + "\"relationship-value\":\"a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb\"," + + "\"relationship-key\":\"customer.global-customer-id\"},{" + + "\"relationship-value\":\"vWINIFRED\"," + + "\"relationship-key\":\"service-subscription.service-type\"},{" + + "\"relationship-value\":\"62888f15-6d24-4f7b-92a7-c3f35beeb215\"," + + "\"relationship-key\":\"service-instance.service-instance-id\"}]," + + "\"related-link\":\"/aai/v12/business/customers/customer/a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb/service-subscriptions/service-subscription/vWINIFRED/service-instances/service-instance/62888f15-6d24-4f7b-92a7-c3f35beeb215\"," + + "\"relationship-label\":\"org.onap.relationships.inventory.ComposedOf\"," + + "\"related-to-property\":[{" + + "\"property-key\":\"service-instance.service-instance-name\"," + + "\"property-value\":\"Dror123\"}]},{" + + "\"related-to\":\"platform\"," + + "\"relationship-data\":[{" + + "\"relationship-value\":\"platformY\"," + + "\"relationship-key\":\"platform.platform-name\"}]," + + "\"related-link\":\"/aai/v12/business/platforms/platform/platformY\"," + + "\"relationship-label\":\"org.onap.relationships.inventory.Uses\"},{" + + "\"related-to\":\"line-of-business\"," + + "\"relationship-data\":[{" + + "\"relationship-value\":\"lob1, lobX\"," + + "\"relationship-key\":\"line-of-business.line-of-business-name\"}]," + + "\"related-link\":\"/aai/v12/business/lines-of-business/line-of-business/lob1%2C%20lobX\"," + + "\"relationship-label\":\"org.onap.relationships.inventory.Uses\"}," + + " {" + + " \"related-to\": \"tenant\"," + + " \"relationship-label\": \"org.onap.relationships.inventory.Uses\"," + + " \"related-link\": \"/aai/v12/cloud-infrastructure/cloud-regions/cloud-region\"," + + " \"relationship-data\": [" + + " {" + + " \"relationship-key\": \"cloud-region.cloud-owner\"," + + " \"relationship-value\": \"irma-aic\"" + + " }," + + " {" + + " \"relationship-key\": \"cloud-region.cloud-region-id\"," + + " \"relationship-value\": \"aCloudRegionId\"" + + " }," + + " {" + + " \"relationship-key\": \"tenant.tenant-id\"," + + " \"relationship-value\": \"someTenantId123\"" + + " }," + + (isDuplicatedKeysInTenantRelation ? "{\"relationship-key\": \"tenant.tenant-id\", \"relationship-value\": \"someTenantId456\"}, " : "" ) + + " {" + + " \"relationship-key\": \"vserver.vserver-id\"," + + " \"relationship-value\": \"5eef9f6d-9933-4bc6-9a1a-862d61309437\"" + + " }" + + " ]," + + " \"related-to-property\": [" + + " {" + + " \"property-key\": \"vserver.vserver-name\"," + + " \"property-value\": \"zolson5bfapn01dns002\"" + + " }" + + " ]" + + " }" + + "]}," + + "\"vnf-id\":\"59bde732-9b84-46bd-a59a-3c45fee0538b\",\n" + + "\"nf-type\":\"\"," + + "\"prov-status\":\"PREPROV\"," + + "\"vnf-type\":\"Lital--1707097/Lital-VSP-1707097 0\"," + + "\"orchestration-status\":\"Created\"," + + "\"nf-naming-code\":\"\"," + + "\"in-maint\":true," + + "\"nf-function\":\"\"," + + "\"model-version-id\":\"11c6dc3e-cd6a-41b3-a50e-b5a10f7157d0\"," + + "\"resource-version\":\"1522431420767\"," + + "\"model-customization-id\":\"14992bf5-d585-4b54-8101-7cf76774337a\"," + + "\"model-invariant-id\":\"55628ce3-ed56-40bd-9b27-072698ce02a9\"," + + "\"vnf-name\":\"DROR_vsp\"," + + "\"is-closed-loop-disabled\":true}"; + } + + private List<String> invariantIDs = Arrays.asList("35340388-0b82-4d3a-823d-cbddf842be52", + "55628ce3-ed56-40bd-9b27-072698ce02a9"); + + private static String getVersionByInvariantIdResponseString = "{" + + "\"model\": [{" + + "\"model-invariant-id\": \"55628ce3-ed56-40bd-9b27-072698ce02a9\"," + + "\"model-type\": \"resource\"," + + "\"resource-version\": \"1499690926297\"," + + "\"model-vers\": {" + + "\"model-ver\": [{" + + "\"model-version-id\": \"11c6dc3e-cd6a-41b3-a50e-b5a10f7157d0\"," + + "\"model-name\": \"Lital-VSP-1707097\"," + + "\"model-version\": \"2.0\",\n" + + "\"distribution-status\": \"DISTRIBUTION_COMPLETE_OK\"," + + "\"model-description\": \"Lital-VSP-1707097-NEW\"," + + "\"resource-version\": \"1499690926298\"," + + "\"model-elements\": {" + + "\"model-element\": [{" + + "\"model-element-uuid\": \"a4f14ef7-daa2-4257-9b81-b4558dc4beaa\"," + + "\"new-data-del-flag\": \"T\"," + + "\"cardinality\": \"unbounded\"," + + "\"resource-version\": \"1499690926300\"," + + "\"relationship-list\": {" + + "\"relationship\": [{" + + "\"related-to\": \"model-ver\"," + + "\"relationship-label\": \"org.onap.relationships.inventory.IsA\"," + + "\"related-link\": \"/aai/v12/service-design-and-creation/models/model/acc6edd8-a8d4-4b93-afaa-0994068be14c/model-vers/model-ver/93a6166f-b3d5-4f06-b4ba-aed48d009ad9\"," + + "\"relationship-data\": [{" + + "\"relationship-key\": \"model.model-invariant-id\"," + + "\"relationship-value\": \"acc6edd8-a8d4-4b93-afaa-0994068be14c\"},{" + + "\"relationship-key\": \"model-ver.model-version-id\"," + + "\"relationship-value\": \"93a6166f-b3d5-4f06-b4ba-aed48d009ad9\"}]," + + "\"related-to-property\": [{" + + "\"property-key\": \"model-ver.model-name\"," + + "\"property-value\": \"generic-vnf\"}]}]}}]}," + + "\"relationship-list\": {" + + "\"relationship\": [{" + + "\"related-to\": \"model-element\"," + + "\"relationship-label\": \"org.onap.relationships.inventory.IsA\"," + + "\"related-link\": \"/aai/v12/service-design-and-creation/models/model/35340388-0b82-4d3a-823d-cbddf842be52/model-vers/model-ver/4e799efd-fd78-444d-bc25-4a3cde2f8cb0/model-elements/model-element/344e8713-f0af-423a-b96d-f45b3a479d11/model-elements/model-element/9e8c8885-601a-4fd6-8424-c233a5333db6\"," + + "\"relationship-data\": [{" + + "\"relationship-key\": \"model.model-invariant-id\"," + + "\"relationship-value\": \"35340388-0b82-4d3a-823d-cbddf842be52\"},{" + + "\"relationship-key\": \"model-ver.model-version-id\"," + + "\"relationship-value\": \"4e799efd-fd78-444d-bc25-4a3cde2f8cb0\"},{" + + "\"relationship-key\": \"model-element.model-element-uuid\"," + + "\"relationship-value\": \"344e8713-f0af-423a-b96d-f45b3a479d11\"},{" + + "\"relationship-key\": \"model-element.model-element-uuid\"," + + "\"relationship-value\": \"9e8c8885-601a-4fd6-8424-c233a5333db6\"}]}]}}]}},{" + + "\"model-invariant-id\": \"35340388-0b82-4d3a-823d-cbddf842be52\"," + + "\"model-type\": \"service\"," + + "\"resource-version\": \"1499690928188\"," + + "\"model-vers\": {" + + "\"model-ver\": [{" + + "\"model-version-id\": \"4e799efd-fd78-444d-bc25-4a3cde2f8cb0\"," + + "\"model-name\": \"Lital--1707097\"," + + "\"model-version\": \"1.0\"," + + "\"distribution-status\": \"DISTRIBUTION_COMPLETE_OK\"," + + "\"model-description\": \"Lital--1707097\"," + + "\"resource-version\": \"1499690928190\"," + + "\"model-elements\": {" + + "\"model-element\": [{" + + "\"model-element-uuid\": \"344e8713-f0af-423a-b96d-f45b3a479d11\"," + + "\"new-data-del-flag\": \"T\"," + + "\"cardinality\": \"unbounded\"," + + "\"resource-version\": \"1499690928191\"," + + "\"relationship-list\": {" + + "\"relationship\": [{" + + "\"related-to\": \"model-ver\"," + + "\"relationship-label\": \"org.onap.relationships.inventory.IsA\"," + + "\"related-link\": \"/aai/v12/service-design-and-creation/models/model/82194af1-3c2c-485a-8f44-420e22a9eaa4/model-vers/model-ver/46b92144-923a-4d20-b85a-3cbd847668a9\"," + + "\"relationship-data\": [{" + + "\"relationship-key\": \"model.model-invariant-id\"," + + "\"relationship-value\": \"82194af1-3c2c-485a-8f44-420e22a9eaa4\"},{" + + "\"relationship-key\": \"model-ver.model-version-id\"," + + "\"relationship-value\": \"46b92144-923a-4d20-b85a-3cbd847668a9\"}]," + + "\"related-to-property\": [{" + + "\"property-key\": \"model-ver.model-name\"," + + "\"property-value\": \"service-instance\"}]}]}}]}}]}}]}"; + + @BeforeClass + public void initMocks() { + MockitoAnnotations.initMocks(this); + } + + @BeforeMethod + public void resetMocks() { + Mockito.reset(aaiClient); + Mockito.reset(aaiGetVersionByInvariantIdResponse); + Mockito.reset(sdcService); + Mockito.reset(serviceModelInflator); + } + + public void getServiceInstanceTreeAndAssert(boolean isDuplicatedKeysInTenantRelation) throws IOException, AsdcCatalogException { + when(aaiClient.typedAaiRest(URI.create(serviceInstanceRequestUri), JsonNode.class, null, HttpMethod.GET, false)).thenReturn(mapper.readTree(ServiceInstanceResponseString)); + when(aaiClient.typedAaiRest(URI.create(genericVnfRequestUri), JsonNode.class, null, HttpMethod.GET, false)). + thenReturn(mapper.readTree(genericVnfResponseString(isDuplicatedKeysInTenantRelation))); + when(aaiClient.getVersionByInvariantId(invariantIDs)).thenReturn(aaiGetVersionByInvariantIdResponse); + + when(aaiGetVersionByInvariantIdResponse.readEntity(String.class)).thenReturn(getVersionByInvariantIdResponseString); + + when(sdcService.getService(any())).thenReturn(mock(ServiceModel.class)); + when(serviceModelInflator.toNamesByVersionId(any())).thenReturn(ImmutableMap.of( + "11c6dc3e-cd6a-41b3-a50e-b5a10f7157d0", new ServiceModelInflator.Names("vnf-model-customization-name", "vnf-key-in-model") + )); + + ServiceInstance root = new AAIServiceTree(aaiClient, aaiTreeNodeBuilder, aaiTreeConverter, sdcService, serviceModelInflator, executorService) + .getServiceInstanceTopology(globalCustomerID, serviceType, serviceInstanceId); + + assertServiceNode(root, 1); + + assertEquals(0, root.getExistingNetworksCounterMap().size()); + assertEquals(1, root.getExistingVNFCounterMap().size()); + assertEquals((Long)1L, root.getExistingVNFCounterMap().get("14992bf5-d585-4b54-8101-7cf76774337a")); + + assertVnfNode(root, isDuplicatedKeysInTenantRelation); + } + + @Test + public void getServiceInstanceTreeTestHappyFlow() throws IOException, AsdcCatalogException { + getServiceInstanceTreeAndAssert(false); + } + + @Test + public void whenDuplicatedKeyInRelationshipData_thenVnfIsParsedButWithoutPlacement() throws IOException, AsdcCatalogException { + getServiceInstanceTreeAndAssert(true); + } + + private void mockAaiGetCall(String aaiPath, String jsonFilePath) { + try { + when(aaiClient.typedAaiRest(URI.create(aaiPath), JsonNode.class, null, HttpMethod.GET, false)).thenReturn(TestUtils.readJsonResourceFileAsObject(jsonFilePath, JsonNode.class)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Test + public void whenGetServiceInstanceWithCR_thenResultAreAsExpected() throws Exception { + + List<String> modelInvIds = ImmutableList.of( + "868b109c-9481-4a18-891b-af974db7705a", + "081ceb56-eb71-4566-a72d-3e7cbee5cdf1", + "f6342be5-d66b-4d03-a1aa-c82c3094c4ea"); + + mockAaiGetCall("business/customers/customer/a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb/service-subscriptions/service-subscription/Emanuel/service-instances/service-instance/a565e6ad-75d1-4493-98f1-33234b5c17e2", + "/getTopology/serviceWithCR/serviceWithCR.json"); + mockAaiGetCall("/aai/v14/network/collections/collection/84a351ae-3601-45e2-98df-878d6c816abc", + "/getTopology/serviceWithCR/CR.json"); + + mockAaiGetCall("/aai/v14/network/instance-groups/instance-group/6b3536cf-3a12-457f-abb5-fa2203e0d923", + "/getTopology/serviceWithCR/instanceGroup-NCF.json"); + + when(aaiClient.getVersionByInvariantId(modelInvIds)).thenReturn(aaiGetVersionByInvariantIdResponse); + + when(aaiGetVersionByInvariantIdResponse.readEntity(String.class)). + thenReturn(TestUtils.readFileAsString("/getTopology/serviceWithCR/service-design-and-creation.json")); + + when(sdcService.getService(any())).thenReturn( + TestUtils.readJsonResourceFileAsObject("/getTopology/serviceWithCR/serviceWithCRModel.json", ServiceModel.class)); + + ServiceInstance serviceInstance = new AAIServiceTree(aaiClient, aaiTreeNodeBuilder, aaiTreeConverter, sdcService, new ServiceModelInflator(), executorService) + .getServiceInstanceTopology("a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", "Emanuel", "a565e6ad-75d1-4493-98f1-33234b5c17e2"); + + String expected = TestUtils.readFileAsString("/getTopology/serviceWithCR/getTopologyWithCR.json"); + assertThat(serviceInstance, jsonEquals(expected).when(IGNORING_ARRAY_ORDER)); + } + + protected void assertVnfNode(ServiceInstance root, boolean isExpectToPlacement) { + Vnf vnf = root.getVnfs().get("59bde732-9b84-46bd-a59a-3c45fee0538b"); + assertEquals(Action.None, vnf.getAction()); + assertEquals("Created", vnf.getOrchStatus()); + assertEquals("PREPROV", vnf.getProvStatus()); + assertEquals(true, vnf.getInMaint()); + assertEquals("11c6dc3e-cd6a-41b3-a50e-b5a10f7157d0", vnf.getModelInfo().getModelVersionId()); + assertEquals("14992bf5-d585-4b54-8101-7cf76774337a", vnf.getModelInfo().getModelCustomizationId()); + assertEquals("55628ce3-ed56-40bd-9b27-072698ce02a9", vnf.getModelInfo().getModelInvariantId()); + assertEquals("Lital-VSP-1707097", vnf.getModelInfo().getModelName()); + assertEquals("vnf-model-customization-name", vnf.getModelInfo().getModelCustomizationName()); + assertEquals("2.0", vnf.getModelInfo().getModelVersion()); + assertEquals("vnf", vnf.getModelInfo().getModelType()); + assertEquals("59bde732-9b84-46bd-a59a-3c45fee0538b", vnf.getInstanceId()); + assertEquals("DROR_vsp", vnf.getInstanceName()); + assertEquals("Lital--1707097/Lital-VSP-1707097 0", vnf.getInstanceType()); + assertEquals("11c6dc3e-cd6a-41b3-a50e-b5a10f7157d0", vnf.getUuid()); + assertEquals("59bde732-9b84-46bd-a59a-3c45fee0538b", vnf.getTrackById()); + assertEquals(0, vnf.getVfModules().size()); + assertEquals(0, vnf.getNetworks().size()); + if (!isExpectToPlacement) { + assertEquals("aCloudRegionId", vnf.getLcpCloudRegionId()); + assertEquals("someTenantId123", vnf.getTenantId()); + assertEquals("irma-aic", vnf.getCloudOwner()); + } + else { + assertNull(vnf.getLcpCloudRegionId()); + assertNull(vnf.getTenantId()); + assertNull(vnf.getCloudOwner()); + } + } + + protected void assertServiceNode(ServiceInstance root, int expectedVnfSize) { + assertEquals(Action.None, root.getAction()); + assertEquals("Active", root.getOrchStatus()); + assertEquals("4e799efd-fd78-444d-bc25-4a3cde2f8cb0", root.getModelInfo().getModelVersionId()); + assertEquals(null, root.getModelInfo().getModelCustomizationId()); + assertEquals("35340388-0b82-4d3a-823d-cbddf842be52", root.getModelInfo().getModelInvariantId()); + assertEquals("1.0", root.getModelInfo().getModelVersion()); + assertEquals("Lital--1707097", root.getModelInfo().getModelName()); + assertEquals("service", root.getModelInfo().getModelType()); + assertEquals("62888f15-6d24-4f7b-92a7-c3f35beeb215", root.getInstanceId()); + assertEquals("Dror123", root.getInstanceName()); + assertEquals(expectedVnfSize, root.getVnfs().size()); + assertEquals(0, root.getNetworks().size()); + //future - after add additional properties - assert it + } + + @Test(expectedExceptions = GenericUncheckedException.class ,expectedExceptionsMessageRegExp = "AAI node fetching failed.") + public void getServiceInstanceTreeTest_errorCreatingVnfNode() throws IOException, AsdcCatalogException { + when(aaiClient.typedAaiRest(URI.create(serviceInstanceRequestUri), JsonNode.class, null, HttpMethod.GET, false)).thenReturn(mapper.readTree(ServiceInstanceResponseString)); + when(aaiClient.typedAaiRest(URI.create(genericVnfRequestUri), JsonNode.class, null, HttpMethod.GET, false)).thenThrow(exceptionWithRequestInfo); + when(aaiClient.getVersionByInvariantId(any())).thenReturn(aaiGetVersionByInvariantIdResponse); + when(exceptionWithRequestInfo.toString()).thenReturn("this is a fetching node exception"); + + when(aaiGetVersionByInvariantIdResponse.readEntity(String.class)).thenReturn(getVersionByInvariantIdResponseString); + + when(sdcService.getService(any())).thenReturn(mock(ServiceModel.class)); + when(serviceModelInflator.toNamesByVersionId(any())).thenReturn(ImmutableMap.of()); + + new AAIServiceTree(aaiClient, aaiTreeNodeBuilder, aaiTreeConverter, sdcService, serviceModelInflator, executorService) + .getServiceInstanceTopology(globalCustomerID, serviceType, serviceInstanceId); + } + + @Test(expectedExceptions = GenericUncheckedException.class ,expectedExceptionsMessageRegExp = "AAI node fetching failed.") + public void testCreateFailureNode() { + AAITreeNode failureNode = FailureAAITreeNode.of(new RuntimeException("Failed to retrieve node data.")); + failureNode.getId(); + } +} diff --git a/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java b/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java index 4fede294d..aae494f84 100644 --- a/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java +++ b/vid-automation/src/main/java/vid/automation/test/services/SimulatorApi.java @@ -1,8 +1,26 @@ package vid.automation.test.services; +import static org.testng.Assert.assertEquals; +import static vid.automation.test.services.DropTestApiField.dropFieldCloudOwnerFromString; +import static vid.automation.test.services.DropTestApiField.dropTestApiFieldFromString; + import com.fasterxml.jackson.databind.DeserializationFeature; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; +import java.net.URI; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.function.UnaryOperator; +import java.util.stream.Collectors; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.GenericType; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; import org.glassfish.jersey.client.ClientProperties; import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJaxbJsonProvider; import org.glassfish.jersey.jackson.internal.jackson.jaxrs.json.JacksonJsonProvider; @@ -14,25 +32,6 @@ import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import vid.automation.test.utils.ReadFile; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; -import javax.ws.rs.client.WebTarget; -import javax.ws.rs.core.GenericType; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.net.URI; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.function.UnaryOperator; -import java.util.stream.Collectors; - -import static org.testng.Assert.assertEquals; -import static vid.automation.test.services.DropTestApiField.dropFieldCloudOwnerFromString; -import static vid.automation.test.services.DropTestApiField.dropTestApiFieldFromString; - public class SimulatorApi { public enum RegistrationStrategy { @@ -63,7 +62,7 @@ public class SimulatorApi { ImmutableList.of(dropTestApiFieldFromString(), dropFieldCloudOwnerFromString()); static { - String host = System.getProperty("VID_HOST", "127.0.0.1" ); + String host = System.getProperty("SIM_HOST", System.getProperty("VID_HOST", "127.0.0.1")); Integer port = Integer.valueOf(System.getProperty("SIM_PORT", System.getProperty("VID_PORT", "8080"))); //port for registration uri = new JerseyUriBuilder().host(host).port(port).scheme("http").path("vidSimulator").build(); client = ClientBuilder.newClient(); diff --git a/vid-ext-services-simulator/src/main/java/org/onap/simulator/controller/SimulatorController.java b/vid-ext-services-simulator/src/main/java/org/onap/simulator/controller/SimulatorController.java index 3845c7419..aec437806 100644 --- a/vid-ext-services-simulator/src/main/java/org/onap/simulator/controller/SimulatorController.java +++ b/vid-ext-services-simulator/src/main/java/org/onap/simulator/controller/SimulatorController.java @@ -1,11 +1,13 @@ package org.onap.simulator.controller; +import static org.apache.commons.lang3.StringUtils.isEmpty; import static org.mockserver.integration.ClientAndServer.startClientAndServer; import static org.mockserver.matchers.Times.exactly; import static org.mockserver.model.JsonBody.json; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.collect.ImmutableMap; import com.google.gson.Gson; import java.io.BufferedInputStream; import java.io.DataInputStream; @@ -107,11 +109,20 @@ public class SimulatorController { private void initJPA() { if (enableJPA) { - entityManagerFactory = Persistence.createEntityManagerFactory("vid"); + entityManagerFactory = Persistence.createEntityManagerFactory("vid", overrideConnectionUrl()); entityManager = entityManagerFactory.createEntityManager(); } } + private Map<Object, Object> overrideConnectionUrl() { + final String connectionUrlEnvProperty = "hibernate.connection.url"; + if (isEmpty(System.getProperty(connectionUrlEnvProperty))) { + return Collections.emptyMap(); + } else { + return ImmutableMap.of(connectionUrlEnvProperty, System.getProperty(connectionUrlEnvProperty)); + } + } + @PreDestroy public void tearDown(){ logger.info("Stopping VID Simulator...."); diff --git a/vid-ext-services-simulator/src/main/resources/META-INF/persistence.xml b/vid-ext-services-simulator/src/main/resources/META-INF/persistence.xml index 9e4453feb..448b5b380 100644 --- a/vid-ext-services-simulator/src/main/resources/META-INF/persistence.xml +++ b/vid-ext-services-simulator/src/main/resources/META-INF/persistence.xml @@ -12,7 +12,7 @@ <property name="hibernate.show_sql" value="false" /> <property name="hibernate.format_sql" value="false" /> <property name="hibernate.dialect" value="org.hibernate.dialect.MariaDB103Dialect" /> - <property name="hibernate.hbm2ddl.auto" value="validate" /> + <property name="hibernate.hbm2ddl.auto" value="none" /> <property name="hibernate.connection.driver_class" value="org.mariadb.jdbc.Driver"/> <property name="hibernate.connection.username" value="euser"/> <property name="hibernate.connection.password" value="euser"/> diff --git a/vid-webpack-master/pom.xml b/vid-webpack-master/pom.xml index d1398cc35..8d4ab156e 100644 --- a/vid-webpack-master/pom.xml +++ b/vid-webpack-master/pom.xml @@ -29,6 +29,7 @@ <stagingNexusPath>content/repositories/staging/</stagingNexusPath> <snapshotNexusPath>content/repositories/snapshots/</snapshotNexusPath> <releaseNexusPath>content/repositories/releases/</releaseNexusPath> + <NPM_CMD>build</NPM_CMD> </properties> @@ -73,7 +74,10 @@ <profile> <id>if-not-webpack</id> <activation> - <activeByDefault>true</activeByDefault> + <property> + <name>skipModernUi</name> + <value>true</value> + </property> </activation> <build> <plugins> @@ -106,6 +110,13 @@ </profile> <profile> <id>webpack-npm</id> + <activation> + <property> + <name>skipModernUi</name> + <value>!true</value> + </property> + <activeByDefault>true</activeByDefault> + </activation> <build> <plugins> <plugin> @@ -161,7 +172,6 @@ <arguments>run ${NPM_CMD}</arguments> </configuration> </execution> - </executions> </plugin> </plugins> @@ -245,7 +255,16 @@ <webXml>src/WEB-INF/web.xml</webXml> </configuration> </plugin> - + <plugin> + <artifactId>maven-clean-plugin</artifactId> + <configuration> + <filesets> + <fileset> + <directory>dist</directory> + </fileset> + </filesets> + </configuration> + </plugin> </plugins> </build> <dependencies> |