From 1196463dbf4c6ef051dd7f68580fc7d77c5d054c Mon Sep 17 00:00:00 2001 From: Wojciech Sliwka Date: Fri, 1 Feb 2019 07:23:42 +0100 Subject: First part of Tests Issue-ID: VID-385 add first part of new tests for AAI, move some files to proper directory Change-Id: I6600c48d26387faf9e6cd6dbe7107e10428f4b52 Signed-off-by: Wojciech Sliwka --- .../onap/vid/services/AAITreeConverterTest.java | 242 --------------------- .../vid/services/AaiResponseTranslatorTest.java | 151 ------------- 2 files changed, 393 deletions(-) delete mode 100644 vid-app-common/src/test/java/org/onap/vid/services/AAITreeConverterTest.java delete mode 100644 vid-app-common/src/test/java/org/onap/vid/services/AaiResponseTranslatorTest.java (limited to 'vid-app-common/src/test/java/org/onap/vid/services') diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AAITreeConverterTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AAITreeConverterTest.java deleted file mode 100644 index 5abe8e426..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/services/AAITreeConverterTest.java +++ /dev/null @@ -1,242 +0,0 @@ -/*- - * ============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.opencomp.vid.services; - -import com.google.common.collect.ImmutableList; -import org.mockito.InjectMocks; -import org.mockito.MockitoAnnotations; -import org.onap.vid.aai.util.AAITreeConverter; -import org.onap.vid.model.Action; -import org.onap.vid.model.aaiTree.*; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.DataProvider; -import org.testng.annotations.Test; - -import java.util.List; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; -import static org.onap.vid.asdc.parser.ToscaParserImpl2.Constants.A_LA_CARTE; - -public class AAITreeConverterTest { - - @InjectMocks - private AAITreeConverter aaiTreeConverter; - - @BeforeTest - public void initMocks() { - MockitoAnnotations.initMocks(this); - } - - @Test - public void testConvertTreeToUIModel_NoChildren() throws Exception { - - AAITreeNode aaiTree = generateAaiTreeToConvert(0, 0); - - ServiceInstance result = aaiTreeConverter.convertTreeToUIModel(aaiTree, "global-customer-id", "service-type", A_LA_CARTE); - - assertService(result, 0, 0, true); - } - - @Test - public void testConvertTreeToUIModel_MultipleChildren() throws Exception { - - AAITreeNode aaiTree = generateAaiTreeToConvert(2, 2); - - ServiceInstance serviceInstance = aaiTreeConverter.convertTreeToUIModel(aaiTree, "global-customer-id", "service-type", null); - - assertService(serviceInstance, 2, 2, false); - - int nodesCounter = 0; - assertThat(serviceInstance.getVnfs().entrySet(), hasSize(2)); - assertVnf(serviceInstance.getVnfs().get("vnf-model-version-id:00"+(nodesCounter++)), 0, 0, false); - assertVnf(serviceInstance.getVnfs().get("vnf-model-version-id:00"+(nodesCounter++)), 0, 0, false); - - assertThat(serviceInstance.getNetworks().entrySet(), hasSize(2)); - assertNetwork(serviceInstance.getNetworks().get("network-model-version-id:00"+(nodesCounter++)), false); - assertNetwork(serviceInstance.getNetworks().get("network-model-version-id:00"+(nodesCounter)), false); - } - - @DataProvider - public static Object[][] vnfWithChildren() { - return new Object[][]{ - {ImmutableList.of(), ImmutableList.of()}, - {ImmutableList.of(true, false), ImmutableList.of()}, - {ImmutableList.of(), ImmutableList.of(false)} - }; - } - - @Test(dataProvider = "vnfWithChildren") - public void testComplexVnfConversion(List vfModules, List networks) { - - AAITreeNode vnfTreeNode = createVnf(1, false); - int nodesCounter = 0; - - for (Boolean customizationName: vfModules) { - vnfTreeNode.getChildren().add(createVfModule(nodesCounter++, customizationName)); - } - - for (Boolean customizationName: networks) { - vnfTreeNode.getChildren().add(createNetwork(nodesCounter++, customizationName)); - } - - Vnf actualVnf = Vnf.from(vnfTreeNode); - - assertVnf(actualVnf, vfModules.size(), networks.size(), false); - - nodesCounter = 0; - for (Boolean customizationName: vfModules) { - String key = customizationName ? "vfModule key in model" : "vfModule-model-version-id"; - - assertThat(actualVnf.getVfModules(), hasKey(key)); - assertThat(actualVnf.getVfModules().get(key), hasKey(key + ":00" + nodesCounter)); - VfModule actualVfModule = actualVnf.getVfModules().get(key).get(key + ":00" + nodesCounter); - assertVfModule(actualVfModule, customizationName); - nodesCounter++; - } - - for (Boolean customizationName: networks) { - String key = customizationName ? "network key in model" : "network-model-version-id"; - - assertThat(actualVnf.getNetworks(), hasKey(key + ":00" + nodesCounter)); - Network actualNetwork = actualVnf.getNetworks().get(key + ":00" + nodesCounter); - assertNetwork(actualNetwork, customizationName); - nodesCounter++; - } - } - - @Test - public void testNetworkConversion() { - AAITreeNode networkTreeNode = createNetwork(1, true); - - Network actualNetwork = Network.from(networkTreeNode); - - assertNetwork(actualNetwork, true); - } - - private AAITreeNode createVnf(int uniqueNumber, boolean hasCustomizationName) { - AAITreeNode vnfTreeNode = new AAITreeNode(); - vnfTreeNode.setId("vnf-instance-id"); - vnfTreeNode.setName("vnf-instance-name"); - vnfTreeNode.setType("generic-vnf"); - vnfTreeNode.setModelVersionId("vnf-model-version-id"); - if (hasCustomizationName) { - vnfTreeNode.setModelCustomizationName("vnf model customization name"); - vnfTreeNode.setKeyInModel("vnf key in model"); - } - vnfTreeNode.setUniqueNumber(uniqueNumber); - return vnfTreeNode; - } - - private AAITreeNode createVfModule(int uniqueNumber, boolean hasCustomizationName) { - AAITreeNode vfModuleTreeNode = new AAITreeNode(); - vfModuleTreeNode.setId("vfModule-instance-id"); - vfModuleTreeNode.setName("vfModule-instance-name"); - vfModuleTreeNode.setType("vf-module"); - vfModuleTreeNode.setModelVersionId("vfModule-model-version-id"); - if (hasCustomizationName) { - vfModuleTreeNode.setModelCustomizationName("vfModule model customization name"); - vfModuleTreeNode.setKeyInModel("vfModule key in model"); - } - vfModuleTreeNode.setUniqueNumber(uniqueNumber); - - return vfModuleTreeNode; - } - - private AAITreeNode createNetwork(int uniqueNumber, boolean hasCustomizationName) { - AAITreeNode networkTreeNode = new AAITreeNode(); - networkTreeNode.setId("network-instance-id"); - networkTreeNode.setName("network-instance-name"); - networkTreeNode.setType("l3-network"); - networkTreeNode.setModelVersionId("network-model-version-id"); - if (hasCustomizationName) { - networkTreeNode.setModelCustomizationName("network model customization name"); - networkTreeNode.setKeyInModel("network key in model"); - } - networkTreeNode.setUniqueNumber(uniqueNumber); - - return networkTreeNode; - } - - private void assertService(ServiceInstance serviceInstance, int expectedVnfs, int expectedNetworks, boolean isALaCarte) { - assertThat(serviceInstance.getInstanceId(), is("service-instance-id")); - assertThat(serviceInstance.getInstanceName(), is("service-instance-name")); - assertThat(serviceInstance.getAction(), is(Action.None)); - assertThat(serviceInstance.getGlobalSubscriberId(), is("global-customer-id")); - assertThat(serviceInstance.getSubscriptionServiceType(), is("service-type")); - assertThat(serviceInstance.getModelInfo().getModelType(), is("service")); - assertThat(serviceInstance.getVnfs().entrySet(), hasSize(expectedVnfs)); - assertThat(serviceInstance.getNetworks().entrySet(), hasSize(expectedNetworks)); - assertThat(serviceInstance.getIsALaCarte(), is(isALaCarte)); - } - - private void assertVnf(Vnf actualVnf, int expectedVfModules, int expectedNetworks, boolean hasCustomizationName) { - assertThat(actualVnf.getInstanceId(), is("vnf-instance-id")); - assertThat(actualVnf.getInstanceName(), is("vnf-instance-name")); - assertThat(actualVnf.getAction(), is(Action.None)); - assertThat(actualVnf.getModelInfo().getModelType(), is("vnf")); - assertThat(actualVnf.getModelInfo().getModelVersionId(), is("vnf-model-version-id")); - assertThat(actualVnf.getVfModules().entrySet(), hasSize(expectedVfModules)); - assertThat(actualVnf.getNetworks().entrySet(), hasSize(expectedNetworks)); - assertThat(actualVnf.getTrackById(), is(not(emptyOrNullString()))); - String expectedCustomizationName = hasCustomizationName ? "vnf model customization name" : null; - assertThat(actualVnf.getModelInfo().getModelCustomizationName(), is(expectedCustomizationName)); - } - - private void assertVfModule(VfModule actualVfModule, boolean hasCustomizationName) { - assertThat(actualVfModule.getInstanceId(), is("vfModule-instance-id")); - assertThat(actualVfModule.getInstanceName(), is("vfModule-instance-name")); - assertThat(actualVfModule.getAction(), is(Action.None)); - assertThat(actualVfModule.getModelInfo().getModelType(), is("vfModule")); - assertThat(actualVfModule.getModelInfo().getModelVersionId(), is("vfModule-model-version-id")); - assertThat(actualVfModule.getTrackById(), is(not(emptyOrNullString()))); - String expectedCustomizationName = hasCustomizationName ? "vfModule model customization name" : null; - assertThat(actualVfModule.getModelInfo().getModelCustomizationName(), is(expectedCustomizationName)); - } - - private void assertNetwork(Network actualNetwork, boolean hasCustomizationName) { - assertThat(actualNetwork.getInstanceId(), is("network-instance-id")); - assertThat(actualNetwork.getInstanceName(), is("network-instance-name")); - assertThat(actualNetwork.getAction(), is(Action.None)); - assertThat(actualNetwork.getModelInfo().getModelType(), is("network")); - assertThat(actualNetwork.getModelInfo().getModelVersionId(), is("network-model-version-id")); - assertThat(actualNetwork.getTrackById(), is(not(emptyOrNullString()))); - String expectedCustomizationName = hasCustomizationName ? "network model customization name" : null; - assertThat(actualNetwork.getModelInfo().getModelCustomizationName(), is(expectedCustomizationName)); - } - - private AAITreeNode generateAaiTreeToConvert(int numberOfVnfs, int numberOfNetworks) { - int counter = 0; - AAITreeNode aaiTree = new AAITreeNode(); - aaiTree.setId("service-instance-id"); - aaiTree.setName("service-instance-name"); - - for (int i = 0; i < numberOfVnfs; i++) { - aaiTree.getChildren().add(createVnf(counter++, false)); - } - - for (int i = 0; i < numberOfNetworks; i++) { - aaiTree.getChildren().add(createNetwork(counter++, false)); - } - - return aaiTree; - } -} diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AaiResponseTranslatorTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AaiResponseTranslatorTest.java deleted file mode 100644 index cc6f99fc6..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/services/AaiResponseTranslatorTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/*- - * ============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 com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.onap.vid.aai.AaiResponseTranslator; -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(); - - @Test - public void extractPortMirroringConfigData_givenValidAaiResponse_yieldCloudRegionId() throws IOException { - - final JsonNode aaiPayload = objectMapper.readTree("" + - "{" + - " \"results\": [{" + - " \"id\": \"2979590232\"," + - " \"node-type\": \"cloud-region\"," + - " \"url\": \"/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/att-aic/SDNO-S-BcloudReg-E1802\"," + - " \"properties\": {" + - " \"cloud-owner\": \"att-aic\"," + - " \"cloud-region-id\": \"THE-EXPECTED-REGION-ID\"," + - " \"sriov-automation\": false," + - " \"resource-version\": \"1513631040564\"" + - " }" + - " }," + - " {" + - " \"id\": \"2979598424\"," + - " \"node-type\": \"generic-vnf\"," + - " \"url\": \"/aai/v12/network/generic-vnfs/generic-vnf/SOURCE-gVnf-E1802\"," + - " \"properties\": {" + - " \"vnf-id\": \"SOURCE-gVnf-E1802\"," + - " \"vnf-name\": \"SOURCE-vnf-SDNO\"," + - " \"vnf-type\": \"S-1-SDNO\"," + - " \"service-id\": \"a9a77d5a-123e-4-SDNO\"," + - " \"orchestration-status\": \"active\"," + - " \"in-maint\": true," + - " \"is-closed-loop-disabled\": false," + - " \"resource-version\": \"1513631043149\"" + - " }" + - " }" + - " ]" + - "}"); - - PortMirroringConfigData portMirroringConfigData = - new AaiResponseTranslator().extractPortMirroringConfigData(aaiPayload); - - assertThat(portMirroringConfigData, is(instanceOf(PortMirroringConfigDataOk.class))); - assertThat(((PortMirroringConfigDataOk) portMirroringConfigData).getCloudRegionId(), is("THE-EXPECTED-REGION-ID")); - - } - - @Test - public void extractPortMirroringConfigData_givenKindOfValidAaiResponse_yieldCloudRegionId() throws IOException { - // some completley different response, but with - // the results[cloud-region]->properties->cloud-region-id - - final JsonNode aaiPayload = objectMapper.readTree("" + - "{ " + - " \"results\": [{ " + - " \"node-type\": \"generic-vnf\", " + - " \"url\": \"configuration entries) so that git\" " + - " }, " + - " {}, " + - " { " + - " \"node-type\": \"cloud-region\", " + - " \"but it will not switch\": \"tip commits are reachable\", " + - " \"named\": [{ " + - " \"resource-version\": \"1513631040564\" " + - " }], " + - " \"properties\": { " + - " \"cloud-region-id\": \"THE-EXPECTED-REGION-ID\", " + - " \"oldbranch> will be renamed\": false " + - " } " + - " }, " + - " { " + - " \"node-type\": [\"generic-vnf\", \"can be overridden by using\"] " + - " } " + - " ] " + - "}"); - - PortMirroringConfigData portMirroringConfigData = - new AaiResponseTranslator().extractPortMirroringConfigData(aaiPayload); - - assertThat(portMirroringConfigData, is(instanceOf(PortMirroringConfigDataOk.class))); - assertThat(((PortMirroringConfigDataOk) portMirroringConfigData).getCloudRegionId(), is("THE-EXPECTED-REGION-ID")); - - } - - public void extractPortMirroringConfigData_givenAaiResponseWithoutRegionIdName_yieldException() throws IOException { - - final JsonNode aaiPayload = objectMapper.readTree("" + - "{" + - " \"results\": [{" + - " \"node-type\": \"cloud-region\"," + - " \"url\": \"/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/att-aic/SDNO-S-BcloudReg-E1802\"," + - " \"properties\": {" + - " \"resource-version\": \"1513631040564\"" + - " }" + - " }" + - " ]" + - "}"); - - PortMirroringConfigData portMirroringConfigData = - new AaiResponseTranslator().extractPortMirroringConfigData(aaiPayload); - - assertThat(portMirroringConfigData, is(instanceOf(PortMirroringConfigDataError.class))); - assertThat(((PortMirroringConfigDataError) portMirroringConfigData).getErrorDescription(), - containsString("The node-type 'cloud-region' does not contain the property 'cloud-region-id'")); - assertThat(((PortMirroringConfigDataError) portMirroringConfigData).getRawAaiResponse(), - containsString(aaiPayload.toString()) - ); - - } - - /* - More tests: - [x] cloud-region-id field is missing -- descriptive exception is thrown, including the problematic payload itself - [ ] cloud-region-id field is empty -- descriptive exception etc. - [ ] node-type=="cloud-region" entry is empty -- descriptive exception etc. - */ -} -- cgit 1.2.3-korg