From edd8f30798d42f26ca6f23d7883f88f2c246760b Mon Sep 17 00:00:00 2001 From: Marcin Rzepecki Date: Mon, 29 Mar 2021 15:24:42 +0200 Subject: SO refactor - extract Workflow type Service Issue-ID: SO-3581 Signed-off-by: Marcin Rzepecki Change-Id: I5bbe63371045333213542c275e763ac7305369a1 --- .../tasks/UserParamsServiceTraversalTest.java | 219 -------------------- .../workflow/tasks/VrfValidationTest.java | 219 -------------------- .../workflow/tasks/WorkflowActionTest.java | 30 ++- .../ebb/loader/UserParamsServiceTraversalTest.java | 221 +++++++++++++++++++++ .../tasks/ebb/loader/VrfValidationTest.java | 220 ++++++++++++++++++++ 5 files changed, 460 insertions(+), 449 deletions(-) delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversalTest.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfValidationTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversalTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VrfValidationTest.java (limited to 'bpmn/so-bpmn-tasks/src/test') diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversalTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversalTest.java deleted file mode 100644 index 99f17a3628..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/UserParamsServiceTraversalTest.java +++ /dev/null @@ -1,219 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Modifications Copyright (c) 2020 Nokia - * ================================================================================ - * 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.so.bpmn.infrastructure.workflow.tasks; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.onap.so.bpmn.BaseTaskTest; -import org.onap.so.bpmn.common.BBConstants; -import org.onap.so.client.exception.ExceptionBuilder; -import org.onap.so.db.catalog.beans.ConfigurationResource; -import org.onap.so.db.catalog.beans.CvnfcCustomization; -import org.onap.so.db.catalog.beans.HeatTemplate; -import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization; -import org.onap.so.db.catalog.beans.VfModuleCustomization; -import org.onap.so.db.catalog.beans.Service; -import org.onap.so.db.catalog.beans.VfModule; -import org.onap.so.db.catalog.beans.CollectionResourceCustomization; -import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization; -import org.onap.so.db.catalog.beans.HeatEnvironment; -import org.onap.so.db.catalog.client.CatalogDbClient; -import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.mock; - -public class UserParamsServiceTraversalTest extends BaseTaskTest { - - private static final String MACRO_ASSIGN_JSON = "Macro/ServiceMacroAssign.json"; - private static final String MACRO_ASSIGN_PNF_JSON = "Macro/ServiceMacroAssignPnf.json"; - private static final String NETWORK_COLLECTION_JSON = "Macro/CreateNetworkCollection.json"; - private static final String serviceInstanceId = "123"; - private DelegateExecution execution; - private CatalogDbClient mockCatalogDbClient; - private UserParamsServiceTraversal userParamsServiceTraversal; - private String requestAction; - - @Before - public void before() throws Exception { - execution = new DelegateExecutionFake(); - mockCatalogDbClient = mock(CatalogDbClient.class); - userParamsServiceTraversal = new UserParamsServiceTraversal(mockCatalogDbClient, mock(ExceptionBuilder.class)); - requestAction = "assignInstance"; - } - - @Test - public void getResourceListFromUserParamsForVnfs() throws Exception { - initExecution(requestAction, readBpmnRequestFromFile(MACRO_ASSIGN_JSON), false); - Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) - .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); - Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), - anyString(), anyString()); - - List resourceListFromUserParams = userParamsServiceTraversal.getResourceListFromUserParams(execution, - getUserParams(), serviceInstanceId, requestAction); - List expected = List.of(WorkflowType.SERVICE, WorkflowType.VNF, WorkflowType.VOLUMEGROUP, - WorkflowType.VFMODULE, WorkflowType.CONFIGURATION); - List result = - resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); - - assertEquals(5, resourceListFromUserParams.size()); - assertThat(expected, is(result)); - } - - @Test - public void getResourceListFromUserParamsForPnfs() throws Exception { - initExecution(requestAction, readBpmnRequestFromFile(MACRO_ASSIGN_PNF_JSON), false); - Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) - .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); - Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), - anyString(), anyString()); - - List resourceListFromUserParams = userParamsServiceTraversal.getResourceListFromUserParams(execution, - getUserParams(), serviceInstanceId, requestAction); - List expected = List.of(WorkflowType.SERVICE, WorkflowType.PNF); - List result = - resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); - - assertEquals(2, resourceListFromUserParams.size()); - assertThat(expected, is(result)); - } - - @Test - public void getResourceListFromUserParamsForNetworks() throws Exception { - requestAction = "createInstance"; - initExecution(requestAction, readBpmnRequestFromFile(NETWORK_COLLECTION_JSON), false); - Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) - .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); - Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), - anyString(), anyString()); - Mockito.doReturn(getService()).when(mockCatalogDbClient).getServiceByID(anyString()); - Mockito.doReturn(new NetworkCollectionResourceCustomization()).when(mockCatalogDbClient) - .getNetworkCollectionResourceCustomizationByID(anyString()); - - List resourceListFromUserParams = userParamsServiceTraversal.getResourceListFromUserParams(execution, - getUserParams(), serviceInstanceId, requestAction); - List expected = List.of(WorkflowType.SERVICE, WorkflowType.NETWORK, WorkflowType.NETWORK, - WorkflowType.NETWORKCOLLECTION); - List result = - resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); - - assertEquals(4, resourceListFromUserParams.size()); - assertThat(expected, is(result)); - } - - @Test - public void getResourceListFromUserParamsBuildAndThrowExceptionWhenVfModuleAreEmpty() throws Exception { - initExecution(requestAction, readBpmnRequestFromFile(MACRO_ASSIGN_JSON), false); - VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); - vfModuleCustomization.setVfModule(null); - Mockito.doReturn(vfModuleCustomization).when(mockCatalogDbClient) - .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); - - List resourceListFromUserParams = userParamsServiceTraversal.getResourceListFromUserParams(execution, - getUserParams(), serviceInstanceId, requestAction); - List expected = List.of(WorkflowType.SERVICE, WorkflowType.VNF); - List result = - resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); - - assertEquals(2, resourceListFromUserParams.size()); - assertThat(expected, is(result)); - } - - private List> getUserParams() throws IOException { - String bpmnRequest = (String) execution.getVariable(BBConstants.G_BPMN_REQUEST); - ServiceInstancesRequest sIRequest = new ObjectMapper().readValue(bpmnRequest, ServiceInstancesRequest.class); - return sIRequest.getRequestDetails().getRequestParameters().getUserParams(); - } - - @Test - public void getResourceListFromUserParamsWhenUserParamsAreNull() throws Exception { - List expectedResourceList = new ArrayList<>(); - List resultResourceList = userParamsServiceTraversal.getResourceListFromUserParams(execution, null, - serviceInstanceId, requestAction); - - assertEquals(expectedResourceList, resultResourceList); - } - - private String readBpmnRequestFromFile(String fileName) throws IOException { - return new String(Files.readAllBytes(Paths.get("src/test/resources/__files/" + fileName))); - } - - private void initExecution(String gAction, String bpmnRequest, boolean isAlaCarte) { - execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); - execution.setVariable("requestAction", gAction); - execution.setVariable("bpmnRequest", bpmnRequest); - execution.setVariable("aLaCarte", isAlaCarte); - execution.setVariable("apiVersion", "7"); - } - - private Service getService() { - Service service = new Service(); - List collectionResourceCustomizations = new ArrayList<>(); - CollectionResourceCustomization collectionResourceCustomization = new CollectionResourceCustomization(); - collectionResourceCustomization.setModelCustomizationUUID("123"); - collectionResourceCustomizations.add(collectionResourceCustomization); - service.setCollectionResourceCustomizations(collectionResourceCustomizations); - return service; - } - - private VfModuleCustomization getVfModuleCustomization() { - VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); - vfModuleCustomization.setVolumeHeatEnv(new HeatEnvironment()); - vfModuleCustomization.setModelCustomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); - VfModule vfModule = new VfModule(); - vfModule.setVolumeHeatTemplate(new HeatTemplate()); - vfModule.setModelName("helm"); - vfModule.setModuleHeatTemplate(new HeatTemplate()); - vfModuleCustomization.setVfModule(vfModule); - return vfModuleCustomization; - } - - private List getCvnfcCustomizations() { - ConfigurationResource configurationResource = new ConfigurationResource(); - configurationResource.setToscaNodeType("FabricConfiguration"); - - CvnfcConfigurationCustomization cvnfcConfigurationCustomization = new CvnfcConfigurationCustomization(); - cvnfcConfigurationCustomization.setConfigurationResource(configurationResource); - CvnfcCustomization cvnfcCustomization = new CvnfcCustomization(); - - List cvnfcConfigurationCustomizations = new ArrayList<>(); - cvnfcConfigurationCustomizations.add(cvnfcConfigurationCustomization); - cvnfcCustomization.setCvnfcConfigurationCustomization(cvnfcConfigurationCustomizations); - - List cvnfcCustomizations = new ArrayList<>(); - cvnfcCustomizations.add(cvnfcCustomization); - return cvnfcCustomizations; - } -} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfValidationTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfValidationTest.java deleted file mode 100644 index 7f9f0417ea..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/VrfValidationTest.java +++ /dev/null @@ -1,219 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * 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.so.bpmn.infrastructure.workflow.tasks; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.doReturn; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.InjectMocks; -import org.mockito.Mockito; -import org.onap.aai.domain.yang.AggregateRoute; -import org.onap.aai.domain.yang.AggregateRoutes; -import org.onap.aai.domain.yang.L3Network; -import org.onap.aai.domain.yang.RouteTarget; -import org.onap.aai.domain.yang.RouteTargets; -import org.onap.aai.domain.yang.Subnet; -import org.onap.aai.domain.yang.Subnets; -import org.onap.aai.domain.yang.VpnBinding; -import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; -import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; -import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; -import org.onap.so.bpmn.BaseTaskTest; -import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization; -import org.onap.so.db.catalog.beans.Service; -import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class VrfValidationTest extends BaseTaskTest { - - protected ObjectMapper mapper = new ObjectMapper(); - - @InjectMocks - protected VrfValidation vrfValidation; - - @Rule - public ExpectedException exceptionRule = ExpectedException.none(); - - @Before - public void before() throws Exception { - vrfValidation.setBbInputSetupUtils(bbSetupUtils); - } - - @Test - public void testVrfServiceValidation() throws VrfBondingServiceException { - Service service = new Service(); - service.setModelName("modelName"); - service.setServiceType("BONDING"); - service.setServiceRole("VPN"); - exceptionRule.expect(VrfBondingServiceException.class); - exceptionRule.expectMessage( - "Service: modelName does not have service type of BONDING and does not have service role of INFRASTRUCTURE-VPN"); - vrfValidation.vrfServiceValidation(service); - - service.setServiceType("BOND"); - service.setServiceRole("INFRASTRUCTURE-VPN"); - exceptionRule.expect(VrfBondingServiceException.class); - exceptionRule.expectMessage( - "Service: modelName does not have service type of BONDING and does not have service role of INFRASTRUCTURE-VPN"); - vrfValidation.vrfServiceValidation(service); - - service.setServiceType("BONDING"); - service.setServiceRole("INFRASTRUCTURE-VPN"); - ExpectedException.none(); - vrfValidation.vrfServiceValidation(service); - } - - @Test - public void testVrfCatalogDbChecks() throws VrfBondingServiceException { - Service service = new Service(); - service.setModelName("modelName"); - ConfigurationResourceCustomization configuration = new ConfigurationResourceCustomization(); - service.setConfigurationCustomizations(new ArrayList<>()); - service.getConfigurationCustomizations().add(configuration); - ServiceProxyResourceCustomization serviceProxy = new ServiceProxyResourceCustomization(); - configuration.setServiceProxyResourceCustomization(serviceProxy); - service.setServiceProxyCustomizations(new ArrayList<>()); - service.getServiceProxyCustomizations().add(serviceProxy); - Service sourceService = new Service(); - sourceService.setServiceType("TRANSPORT"); - serviceProxy.setSourceService(sourceService); - configuration.setType("VRF-ENTRY"); - configuration.setRole("INFRASTRUCTURE-CLOUD-VPN"); - ExpectedException.none(); - vrfValidation.vrfCatalogDbChecks(service); - } - - @Test - public void testAaiVpnBindingValidation() throws VrfBondingServiceException { - org.onap.aai.domain.yang.VpnBinding aaiVpnBinding = new org.onap.aai.domain.yang.VpnBinding(); - aaiVpnBinding.setVpnType("SERVICE-INFRASTRUCTURE"); - ExpectedException.none(); - vrfValidation.aaiVpnBindingValidation("test-vpn", aaiVpnBinding); - } - - @Test - public void testAaiVpnBindingValidationVpnBindingIsNull() throws VrfBondingServiceException { - exceptionRule.expect(VrfBondingServiceException.class); - exceptionRule.expectMessage("The infrastructure vpn test-vpn does not exist in A&AI."); - vrfValidation.aaiVpnBindingValidation("test-vpn", null); - } - - @Test - public void testAaiNetworkValidation() throws VrfBondingServiceException { - org.onap.aai.domain.yang.L3Network aaiLocalNetwork = new org.onap.aai.domain.yang.L3Network(); - aaiLocalNetwork.setNetworkId("test-network"); - ExpectedException.none(); - vrfValidation.aaiNetworkValidation("test-network", aaiLocalNetwork); - } - - @Test - public void testAaiNetworkValidationNetworkIsNull() throws VrfBondingServiceException { - exceptionRule.expect(VrfBondingServiceException.class); - exceptionRule.expectMessage("The local network test-network does not exist in A&AI."); - vrfValidation.aaiNetworkValidation("test-network", null); - } - - @Test - public void testAaiAggregateRouteValidation() throws VrfBondingServiceException { - org.onap.aai.domain.yang.L3Network aaiLocalNetwork = new org.onap.aai.domain.yang.L3Network(); - aaiLocalNetwork.setAggregateRoutes(new AggregateRoutes()); - aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().add(new AggregateRoute()); - aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().get(0).setIpVersion("4"); - ExpectedException.none(); - vrfValidation.aaiAggregateRouteValidation(aaiLocalNetwork); - - aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().add(new AggregateRoute()); - aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().get(1).setIpVersion("6"); - ExpectedException.none(); - vrfValidation.aaiAggregateRouteValidation(aaiLocalNetwork); - - aaiLocalNetwork.setAggregateRoutes(null); - ExpectedException.none(); - vrfValidation.aaiAggregateRouteValidation(aaiLocalNetwork); - } - - @Test - public void testAaiSubnetValidation() throws VrfBondingServiceException { - org.onap.aai.domain.yang.L3Network aaiLocalNetwork = new org.onap.aai.domain.yang.L3Network(); - aaiLocalNetwork.setNetworkId("myNetworkID"); - aaiLocalNetwork.setSubnets(new Subnets()); - aaiLocalNetwork.getSubnets().getSubnet().add(new Subnet()); - aaiLocalNetwork.getSubnets().getSubnet().get(0).setIpVersion("4"); - ExpectedException.none(); - vrfValidation.aaiSubnetValidation(aaiLocalNetwork); - - aaiLocalNetwork.getSubnets().getSubnet().add(new Subnet()); - aaiLocalNetwork.getSubnets().getSubnet().get(1).setIpVersion("6"); - ExpectedException.none(); - vrfValidation.aaiSubnetValidation(aaiLocalNetwork); - - aaiLocalNetwork.setSubnets(null); - exceptionRule.expect(VrfBondingServiceException.class); - exceptionRule.expectMessage("LocalNetwork: myNetworkID has no subnets"); - vrfValidation.aaiSubnetValidation(aaiLocalNetwork); - } - - @Test - public void testIpVersionValidation() { - String ipVersion1 = "4"; - String ipVersion2 = "6"; - boolean validation = vrfValidation.ipVersionValidation(ipVersion1, ipVersion2); - assertEquals("Validation is correct", true, validation); - - - validation = vrfValidation.ipVersionValidation(ipVersion2, ipVersion1); - assertEquals("Validation is correct", true, validation); - - ipVersion1 = "6"; - validation = vrfValidation.ipVersionValidation(ipVersion1, ipVersion2); - assertEquals("Validation is correct", false, validation); - } - - @Test - public void testAaiRouteTargetValidation() - throws VrfBondingServiceException, JsonParseException, JsonMappingException, IOException { - L3Network l3Network = mapper.readValue( - new File("src/test/resources/__files/BuildingBlocks/aaiNetworkWrapper.json"), L3Network.class); - AAIResultWrapper networkWrapper = new AAIResultWrapper(l3Network); - if (networkWrapper.getRelationships().isPresent()) { - List vpnBindingUris = - networkWrapper.getRelationships().get().getRelatedUris(Types.VPN_BINDING); - VpnBinding vpnBinding = new VpnBinding(); - vpnBinding.setRouteTargets(new RouteTargets()); - vpnBinding.getRouteTargets().getRouteTarget().add(new RouteTarget()); - AAIResultWrapper wrapper = Mockito.mock(AAIResultWrapper.class); - doReturn(wrapper).when(bbSetupUtils).getAAIResourceDepthOne(vpnBindingUris.get(0)); - doReturn(Optional.of(vpnBinding)).when(wrapper).asBean(VpnBinding.class); - ExpectedException.none(); - vrfValidation.aaiRouteTargetValidation(l3Network); - } - } -} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java index 55529b5bf0..31f37f4ac3 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionTest.java @@ -78,6 +78,8 @@ import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.ServiceEBBLoader; +import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.UserParamsServiceTraversal; import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.VnfEBBLoader; import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; @@ -141,6 +143,10 @@ public class WorkflowActionTest extends BaseTaskTest { @Spy protected VnfEBBLoader vnfEBBLoaderSpy; + @InjectMocks + @Spy + protected ServiceEBBLoader serviceEBBLoader; + @Rule public ExpectedException thrown = ExpectedException.none(); @@ -2094,7 +2100,7 @@ public class WorkflowActionTest extends BaseTaskTest { List resourceCounter = new ArrayList<>(); thrown.expect(BpmnError.class); List> aaiResourceIds = new ArrayList<>(); - workflowAction.traverseCatalogDbService(execution, sIRequest, resourceCounter, aaiResourceIds); + serviceEBBLoader.traverseCatalogDbService(execution, sIRequest, resourceCounter, aaiResourceIds); } @@ -2106,7 +2112,8 @@ public class WorkflowActionTest extends BaseTaskTest { networkCustomization.setModelCustomizationUUID("123"); service.getCollectionResourceCustomizations().add(networkCustomization); doReturn(networkCustomization).when(catalogDbClient).getNetworkCollectionResourceCustomizationByID("123"); - CollectionResourceCustomization customization = workflowAction.findCatalogNetworkCollection(execution, service); + CollectionResourceCustomization customization = + serviceEBBLoader.findCatalogNetworkCollection(execution, service); assertNotNull(customization); } @@ -2116,7 +2123,8 @@ public class WorkflowActionTest extends BaseTaskTest { NetworkCollectionResourceCustomization networkCustomization = new NetworkCollectionResourceCustomization(); networkCustomization.setModelCustomizationUUID("123"); service.getCollectionResourceCustomizations().add(networkCustomization); - CollectionResourceCustomization customization = workflowAction.findCatalogNetworkCollection(execution, service); + CollectionResourceCustomization customization = + serviceEBBLoader.findCatalogNetworkCollection(execution, service); assertNull(customization); } @@ -2131,7 +2139,7 @@ public class WorkflowActionTest extends BaseTaskTest { service.getCollectionResourceCustomizations().add(networkCustomization2); doReturn(networkCustomization1).when(catalogDbClient).getNetworkCollectionResourceCustomizationByID("123"); doReturn(networkCustomization2).when(catalogDbClient).getNetworkCollectionResourceCustomizationByID("321"); - workflowAction.findCatalogNetworkCollection(execution, service); + serviceEBBLoader.findCatalogNetworkCollection(execution, service); assertEquals("Found multiple Network Collections in the Service model, only one per Service is supported.", execution.getVariable("WorkflowActionErrorMessage")); } @@ -2183,7 +2191,7 @@ public class WorkflowActionTest extends BaseTaskTest { .getConfiguration("testConfigurationId"); doReturn(Optional.of(aaiConfiguration2)).when(aaiConfigurationResources) .getConfiguration("testConfigurationId2"); - workflowAction.traverseAAIService(execution, resourceCounter, resourceId, aaiResourceIds); + serviceEBBLoader.traverseAAIService(execution, resourceCounter, resourceId, aaiResourceIds); assertEquals(8, resourceCounter.size()); assertTrue(resourceCounter.get(2).isBaseVfModule()); assertThat(aaiResourceIds, sameBeanAs(getExpectedResourceIds())); @@ -2200,7 +2208,7 @@ public class WorkflowActionTest extends BaseTaskTest { resourceList.add(new Resource(WorkflowType.NETWORK, "model customization id", false)); resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, "model customization id", false)); - assertEquals(workflowAction.foundRelated(resourceList), true); + assertEquals(serviceEBBLoader.foundRelated(resourceList), true); } @Test @@ -2211,11 +2219,11 @@ public class WorkflowActionTest extends BaseTaskTest { resourceList.add(new Resource(WorkflowType.NETWORK, "model customization id", false)); resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, "model customization id", false)); - assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.PNF), true); - assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.VNF), true); - assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.NETWORK), true); - assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.NETWORKCOLLECTION), true); - assertEquals(workflowAction.containsWorkflowType(resourceList, WorkflowType.CONFIGURATION), false); + assertEquals(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.PNF), true); + assertEquals(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.VNF), true); + assertEquals(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.NETWORK), true); + assertEquals(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.NETWORKCOLLECTION), true); + assertEquals(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.CONFIGURATION), false); } private List> getExpectedResourceIds() { diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversalTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversalTest.java new file mode 100644 index 0000000000..75514b15d7 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/UserParamsServiceTraversalTest.java @@ -0,0 +1,221 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ + * 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.so.bpmn.infrastructure.workflow.tasks.ebb.loader; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.common.BBConstants; +import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource; +import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.db.catalog.beans.ConfigurationResource; +import org.onap.so.db.catalog.beans.CvnfcCustomization; +import org.onap.so.db.catalog.beans.HeatTemplate; +import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization; +import org.onap.so.db.catalog.beans.VfModuleCustomization; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.catalog.beans.VfModule; +import org.onap.so.db.catalog.beans.CollectionResourceCustomization; +import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization; +import org.onap.so.db.catalog.beans.HeatEnvironment; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; + +public class UserParamsServiceTraversalTest extends BaseTaskTest { + + private static final String MACRO_ASSIGN_JSON = "Macro/ServiceMacroAssign.json"; + private static final String MACRO_ASSIGN_PNF_JSON = "Macro/ServiceMacroAssignPnf.json"; + private static final String NETWORK_COLLECTION_JSON = "Macro/CreateNetworkCollection.json"; + private static final String serviceInstanceId = "123"; + private DelegateExecution execution; + private CatalogDbClient mockCatalogDbClient; + private UserParamsServiceTraversal userParamsServiceTraversal; + private String requestAction; + + @Before + public void before() throws Exception { + execution = new DelegateExecutionFake(); + mockCatalogDbClient = mock(CatalogDbClient.class); + userParamsServiceTraversal = new UserParamsServiceTraversal(mockCatalogDbClient, mock(ExceptionBuilder.class)); + requestAction = "assignInstance"; + } + + @Test + public void getResourceListFromUserParamsForVnfs() throws Exception { + initExecution(requestAction, readBpmnRequestFromFile(MACRO_ASSIGN_JSON), false); + Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) + .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); + Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), + anyString(), anyString()); + + List resourceListFromUserParams = userParamsServiceTraversal.getResourceListFromUserParams(execution, + getUserParams(), serviceInstanceId, requestAction); + List expected = List.of(WorkflowType.SERVICE, WorkflowType.VNF, WorkflowType.VOLUMEGROUP, + WorkflowType.VFMODULE, WorkflowType.CONFIGURATION); + List result = + resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); + + assertEquals(5, resourceListFromUserParams.size()); + assertThat(expected, is(result)); + } + + @Test + public void getResourceListFromUserParamsForPnfs() throws Exception { + initExecution(requestAction, readBpmnRequestFromFile(MACRO_ASSIGN_PNF_JSON), false); + Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) + .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); + Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), + anyString(), anyString()); + + List resourceListFromUserParams = userParamsServiceTraversal.getResourceListFromUserParams(execution, + getUserParams(), serviceInstanceId, requestAction); + List expected = List.of(WorkflowType.SERVICE, WorkflowType.PNF); + List result = + resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); + + assertEquals(2, resourceListFromUserParams.size()); + assertThat(expected, is(result)); + } + + @Test + public void getResourceListFromUserParamsForNetworks() throws Exception { + requestAction = "createInstance"; + initExecution(requestAction, readBpmnRequestFromFile(NETWORK_COLLECTION_JSON), false); + Mockito.doReturn(getVfModuleCustomization()).when(mockCatalogDbClient) + .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); + Mockito.doReturn(getCvnfcCustomizations()).when(mockCatalogDbClient).getCvnfcCustomization(anyString(), + anyString(), anyString()); + Mockito.doReturn(getService()).when(mockCatalogDbClient).getServiceByID(anyString()); + Mockito.doReturn(new NetworkCollectionResourceCustomization()).when(mockCatalogDbClient) + .getNetworkCollectionResourceCustomizationByID(anyString()); + + List resourceListFromUserParams = userParamsServiceTraversal.getResourceListFromUserParams(execution, + getUserParams(), serviceInstanceId, requestAction); + List expected = List.of(WorkflowType.SERVICE, WorkflowType.NETWORK, WorkflowType.NETWORK, + WorkflowType.NETWORKCOLLECTION); + List result = + resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); + + assertEquals(4, resourceListFromUserParams.size()); + assertThat(expected, is(result)); + } + + @Test + public void getResourceListFromUserParamsBuildAndThrowExceptionWhenVfModuleAreEmpty() throws Exception { + initExecution(requestAction, readBpmnRequestFromFile(MACRO_ASSIGN_JSON), false); + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + vfModuleCustomization.setVfModule(null); + Mockito.doReturn(vfModuleCustomization).when(mockCatalogDbClient) + .getVfModuleCustomizationByModelCuztomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); + + List resourceListFromUserParams = userParamsServiceTraversal.getResourceListFromUserParams(execution, + getUserParams(), serviceInstanceId, requestAction); + List expected = List.of(WorkflowType.SERVICE, WorkflowType.VNF); + List result = + resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); + + assertEquals(2, resourceListFromUserParams.size()); + assertThat(expected, is(result)); + } + + private List> getUserParams() throws IOException { + String bpmnRequest = (String) execution.getVariable(BBConstants.G_BPMN_REQUEST); + ServiceInstancesRequest sIRequest = new ObjectMapper().readValue(bpmnRequest, ServiceInstancesRequest.class); + return sIRequest.getRequestDetails().getRequestParameters().getUserParams(); + } + + @Test + public void getResourceListFromUserParamsWhenUserParamsAreNull() throws Exception { + List expectedResourceList = new ArrayList<>(); + List resultResourceList = userParamsServiceTraversal.getResourceListFromUserParams(execution, null, + serviceInstanceId, requestAction); + + assertEquals(expectedResourceList, resultResourceList); + } + + private String readBpmnRequestFromFile(String fileName) throws IOException { + return new String(Files.readAllBytes(Paths.get("src/test/resources/__files/" + fileName))); + } + + private void initExecution(String gAction, String bpmnRequest, boolean isAlaCarte) { + execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688"); + execution.setVariable("requestAction", gAction); + execution.setVariable("bpmnRequest", bpmnRequest); + execution.setVariable("aLaCarte", isAlaCarte); + execution.setVariable("apiVersion", "7"); + } + + private Service getService() { + Service service = new Service(); + List collectionResourceCustomizations = new ArrayList<>(); + CollectionResourceCustomization collectionResourceCustomization = new CollectionResourceCustomization(); + collectionResourceCustomization.setModelCustomizationUUID("123"); + collectionResourceCustomizations.add(collectionResourceCustomization); + service.setCollectionResourceCustomizations(collectionResourceCustomizations); + return service; + } + + private VfModuleCustomization getVfModuleCustomization() { + VfModuleCustomization vfModuleCustomization = new VfModuleCustomization(); + vfModuleCustomization.setVolumeHeatEnv(new HeatEnvironment()); + vfModuleCustomization.setModelCustomizationUUID("a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f"); + VfModule vfModule = new VfModule(); + vfModule.setVolumeHeatTemplate(new HeatTemplate()); + vfModule.setModelName("helm"); + vfModule.setModuleHeatTemplate(new HeatTemplate()); + vfModuleCustomization.setVfModule(vfModule); + return vfModuleCustomization; + } + + private List getCvnfcCustomizations() { + ConfigurationResource configurationResource = new ConfigurationResource(); + configurationResource.setToscaNodeType("FabricConfiguration"); + + CvnfcConfigurationCustomization cvnfcConfigurationCustomization = new CvnfcConfigurationCustomization(); + cvnfcConfigurationCustomization.setConfigurationResource(configurationResource); + CvnfcCustomization cvnfcCustomization = new CvnfcCustomization(); + + List cvnfcConfigurationCustomizations = new ArrayList<>(); + cvnfcConfigurationCustomizations.add(cvnfcConfigurationCustomization); + cvnfcCustomization.setCvnfcConfigurationCustomization(cvnfcConfigurationCustomizations); + + List cvnfcCustomizations = new ArrayList<>(); + cvnfcCustomizations.add(cvnfcCustomization); + return cvnfcCustomizations; + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VrfValidationTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VrfValidationTest.java new file mode 100644 index 0000000000..dcccb74f58 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VrfValidationTest.java @@ -0,0 +1,220 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.so.bpmn.infrastructure.workflow.tasks.ebb.loader; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.doReturn; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.InjectMocks; +import org.mockito.Mockito; +import org.onap.aai.domain.yang.AggregateRoute; +import org.onap.aai.domain.yang.AggregateRoutes; +import org.onap.aai.domain.yang.L3Network; +import org.onap.aai.domain.yang.RouteTarget; +import org.onap.aai.domain.yang.RouteTargets; +import org.onap.aai.domain.yang.Subnet; +import org.onap.aai.domain.yang.Subnets; +import org.onap.aai.domain.yang.VpnBinding; +import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.infrastructure.workflow.tasks.VrfBondingServiceException; +import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class VrfValidationTest extends BaseTaskTest { + + protected ObjectMapper mapper = new ObjectMapper(); + + @InjectMocks + protected VrfValidation vrfValidation; + + @Rule + public ExpectedException exceptionRule = ExpectedException.none(); + + @Before + public void before() throws Exception { + vrfValidation.setBbInputSetupUtils(bbSetupUtils); + } + + @Test + public void testVrfServiceValidation() throws VrfBondingServiceException { + Service service = new Service(); + service.setModelName("modelName"); + service.setServiceType("BONDING"); + service.setServiceRole("VPN"); + exceptionRule.expect(VrfBondingServiceException.class); + exceptionRule.expectMessage( + "Service: modelName does not have service type of BONDING and does not have service role of INFRASTRUCTURE-VPN"); + vrfValidation.vrfServiceValidation(service); + + service.setServiceType("BOND"); + service.setServiceRole("INFRASTRUCTURE-VPN"); + exceptionRule.expect(VrfBondingServiceException.class); + exceptionRule.expectMessage( + "Service: modelName does not have service type of BONDING and does not have service role of INFRASTRUCTURE-VPN"); + vrfValidation.vrfServiceValidation(service); + + service.setServiceType("BONDING"); + service.setServiceRole("INFRASTRUCTURE-VPN"); + ExpectedException.none(); + vrfValidation.vrfServiceValidation(service); + } + + @Test + public void testVrfCatalogDbChecks() throws VrfBondingServiceException { + Service service = new Service(); + service.setModelName("modelName"); + ConfigurationResourceCustomization configuration = new ConfigurationResourceCustomization(); + service.setConfigurationCustomizations(new ArrayList<>()); + service.getConfigurationCustomizations().add(configuration); + ServiceProxyResourceCustomization serviceProxy = new ServiceProxyResourceCustomization(); + configuration.setServiceProxyResourceCustomization(serviceProxy); + service.setServiceProxyCustomizations(new ArrayList<>()); + service.getServiceProxyCustomizations().add(serviceProxy); + Service sourceService = new Service(); + sourceService.setServiceType("TRANSPORT"); + serviceProxy.setSourceService(sourceService); + configuration.setType("VRF-ENTRY"); + configuration.setRole("INFRASTRUCTURE-CLOUD-VPN"); + ExpectedException.none(); + vrfValidation.vrfCatalogDbChecks(service); + } + + @Test + public void testAaiVpnBindingValidation() throws VrfBondingServiceException { + org.onap.aai.domain.yang.VpnBinding aaiVpnBinding = new org.onap.aai.domain.yang.VpnBinding(); + aaiVpnBinding.setVpnType("SERVICE-INFRASTRUCTURE"); + ExpectedException.none(); + vrfValidation.aaiVpnBindingValidation("test-vpn", aaiVpnBinding); + } + + @Test + public void testAaiVpnBindingValidationVpnBindingIsNull() throws VrfBondingServiceException { + exceptionRule.expect(VrfBondingServiceException.class); + exceptionRule.expectMessage("The infrastructure vpn test-vpn does not exist in A&AI."); + vrfValidation.aaiVpnBindingValidation("test-vpn", null); + } + + @Test + public void testAaiNetworkValidation() throws VrfBondingServiceException { + org.onap.aai.domain.yang.L3Network aaiLocalNetwork = new org.onap.aai.domain.yang.L3Network(); + aaiLocalNetwork.setNetworkId("test-network"); + ExpectedException.none(); + vrfValidation.aaiNetworkValidation("test-network", aaiLocalNetwork); + } + + @Test + public void testAaiNetworkValidationNetworkIsNull() throws VrfBondingServiceException { + exceptionRule.expect(VrfBondingServiceException.class); + exceptionRule.expectMessage("The local network test-network does not exist in A&AI."); + vrfValidation.aaiNetworkValidation("test-network", null); + } + + @Test + public void testAaiAggregateRouteValidation() throws VrfBondingServiceException { + org.onap.aai.domain.yang.L3Network aaiLocalNetwork = new org.onap.aai.domain.yang.L3Network(); + aaiLocalNetwork.setAggregateRoutes(new AggregateRoutes()); + aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().add(new AggregateRoute()); + aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().get(0).setIpVersion("4"); + ExpectedException.none(); + vrfValidation.aaiAggregateRouteValidation(aaiLocalNetwork); + + aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().add(new AggregateRoute()); + aaiLocalNetwork.getAggregateRoutes().getAggregateRoute().get(1).setIpVersion("6"); + ExpectedException.none(); + vrfValidation.aaiAggregateRouteValidation(aaiLocalNetwork); + + aaiLocalNetwork.setAggregateRoutes(null); + ExpectedException.none(); + vrfValidation.aaiAggregateRouteValidation(aaiLocalNetwork); + } + + @Test + public void testAaiSubnetValidation() throws VrfBondingServiceException { + org.onap.aai.domain.yang.L3Network aaiLocalNetwork = new org.onap.aai.domain.yang.L3Network(); + aaiLocalNetwork.setNetworkId("myNetworkID"); + aaiLocalNetwork.setSubnets(new Subnets()); + aaiLocalNetwork.getSubnets().getSubnet().add(new Subnet()); + aaiLocalNetwork.getSubnets().getSubnet().get(0).setIpVersion("4"); + ExpectedException.none(); + vrfValidation.aaiSubnetValidation(aaiLocalNetwork); + + aaiLocalNetwork.getSubnets().getSubnet().add(new Subnet()); + aaiLocalNetwork.getSubnets().getSubnet().get(1).setIpVersion("6"); + ExpectedException.none(); + vrfValidation.aaiSubnetValidation(aaiLocalNetwork); + + aaiLocalNetwork.setSubnets(null); + exceptionRule.expect(VrfBondingServiceException.class); + exceptionRule.expectMessage("LocalNetwork: myNetworkID has no subnets"); + vrfValidation.aaiSubnetValidation(aaiLocalNetwork); + } + + @Test + public void testIpVersionValidation() { + String ipVersion1 = "4"; + String ipVersion2 = "6"; + boolean validation = vrfValidation.ipVersionValidation(ipVersion1, ipVersion2); + assertEquals("Validation is correct", true, validation); + + + validation = vrfValidation.ipVersionValidation(ipVersion2, ipVersion1); + assertEquals("Validation is correct", true, validation); + + ipVersion1 = "6"; + validation = vrfValidation.ipVersionValidation(ipVersion1, ipVersion2); + assertEquals("Validation is correct", false, validation); + } + + @Test + public void testAaiRouteTargetValidation() + throws VrfBondingServiceException, JsonParseException, JsonMappingException, IOException { + L3Network l3Network = mapper.readValue( + new File("src/test/resources/__files/BuildingBlocks/aaiNetworkWrapper.json"), L3Network.class); + AAIResultWrapper networkWrapper = new AAIResultWrapper(l3Network); + if (networkWrapper.getRelationships().isPresent()) { + List vpnBindingUris = + networkWrapper.getRelationships().get().getRelatedUris(Types.VPN_BINDING); + VpnBinding vpnBinding = new VpnBinding(); + vpnBinding.setRouteTargets(new RouteTargets()); + vpnBinding.getRouteTargets().getRouteTarget().add(new RouteTarget()); + AAIResultWrapper wrapper = Mockito.mock(AAIResultWrapper.class); + doReturn(wrapper).when(bbSetupUtils).getAAIResourceDepthOne(vpnBindingUris.get(0)); + doReturn(Optional.of(vpnBinding)).when(wrapper).asBean(VpnBinding.class); + ExpectedException.none(); + vrfValidation.aaiRouteTargetValidation(l3Network); + } + } +} -- cgit