From a48d97f0fff248d2b58be4a516227b77638e3982 Mon Sep 17 00:00:00 2001 From: Marcin Rzepecki Date: Tue, 20 Apr 2021 15:00:58 +0200 Subject: SO refactor - extract junit from WorkflowActionTest to ServiceEBBLoaderTest Issue-ID: SO-3489 Signed-off-by: Marcin Rzepecki Change-Id: I54b3a72e1ddd34b3039eccbb3ef3c32a3428ad99 --- .../tasks/WorkflowActionExtractResourcesAAI.java | 76 ----- .../tasks/ebb/loader/ServiceEBBLoader.java | 1 - .../workflow/tasks/ebb/loader/VnfEBBLoader.java | 1 - .../loader/WorkflowActionExtractResourcesAAI.java | 76 +++++ .../test/java/org/onap/so/bpmn/BaseTaskTest.java | 2 +- .../WorkflowActionExtractResourcesAAITest.java | 175 ---------- .../workflow/tasks/WorkflowActionTest.java | 178 ---------- .../tasks/ebb/loader/ServiceEBBLoaderTest.java | 357 +++++++++++++++++++++ .../ebb/loader/UserParamsServiceTraversalTest.java | 19 ++ .../WorkflowActionExtractResourcesAAITest.java | 176 ++++++++++ .../Macro/ServiceMacroCreateWithoutResources.json | 48 +++ 11 files changed, 677 insertions(+), 432 deletions(-) delete mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAI.java create mode 100644 bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/WorkflowActionExtractResourcesAAI.java delete mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAITest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoaderTest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/WorkflowActionExtractResourcesAAITest.java create mode 100644 bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroCreateWithoutResources.json (limited to 'bpmn/so-bpmn-tasks/src') diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAI.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAI.java deleted file mode 100644 index 4140692b44..0000000000 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAI.java +++ /dev/null @@ -1,76 +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 java.util.List; -import java.util.Optional; -import org.onap.aai.domain.yang.VpnBinding; -import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; -import org.onap.aaiclient.client.aai.entities.Relationships; -import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; -import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; -import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -@Component -public class WorkflowActionExtractResourcesAAI { - private static final Logger logger = LoggerFactory.getLogger(WorkflowActionExtractResourcesAAI.class); - - @Autowired - protected BBInputSetupUtils bbInputSetupUtils; - - public Optional extractRelationshipsConfiguration(Relationships relationships) { - List configurations = relationships.getByType(Types.CONFIGURATION); - for (AAIResultWrapper configWrapper : configurations) { - Optional config = configWrapper.asBean(Configuration.class); - if (config.isPresent()) { - return config; - } - } - return Optional.empty(); - } - - public Optional extractRelationshipsVpnBinding(Relationships relationships) { - List configurations = relationships.getRelatedUris(Types.VPN_BINDING); - for (AAIResourceUri vpnBindingUri : configurations) { - AAIResultWrapper vpnBindingWrapper = bbInputSetupUtils.getAAIResourceDepthOne(vpnBindingUri); - Optional vpnBinding = vpnBindingWrapper.asBean(VpnBinding.class); - if (vpnBinding.isPresent()) { - return vpnBinding; - } - } - return Optional.empty(); - } - - public Optional extractRelationshipsVnfc(Relationships relationships) { - List vnfcs = relationships.getByType(Types.VNFC); - for (AAIResultWrapper vnfcWrapper : vnfcs) { - if (vnfcWrapper.getRelationships().isPresent()) { - return vnfcWrapper.getRelationships(); - } - } - return Optional.empty(); - } -} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java index 55a92b0b81..068c287ee7 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoader.java @@ -12,7 +12,6 @@ import org.onap.aaiclient.client.aai.entities.Relationships; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource; import org.onap.so.bpmn.infrastructure.workflow.tasks.VrfBondingServiceException; -import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionExtractResourcesAAI; import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoader.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoader.java index 210d5195e5..b271226414 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoader.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/VnfEBBLoader.java @@ -32,7 +32,6 @@ import org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider; import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; import org.onap.aaiclient.client.aai.entities.Relationships; import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource; -import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionExtractResourcesAAI; import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType; import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/WorkflowActionExtractResourcesAAI.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/WorkflowActionExtractResourcesAAI.java new file mode 100644 index 0000000000..7f1eb0ef07 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/WorkflowActionExtractResourcesAAI.java @@ -0,0 +1,76 @@ +/*- + * ============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 java.util.List; +import java.util.Optional; +import org.onap.aai.domain.yang.VpnBinding; +import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; +import org.onap.aaiclient.client.aai.entities.Relationships; +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class WorkflowActionExtractResourcesAAI { + private static final Logger logger = LoggerFactory.getLogger(WorkflowActionExtractResourcesAAI.class); + + @Autowired + protected BBInputSetupUtils bbInputSetupUtils; + + public Optional extractRelationshipsConfiguration(Relationships relationships) { + List configurations = relationships.getByType(Types.CONFIGURATION); + for (AAIResultWrapper configWrapper : configurations) { + Optional config = configWrapper.asBean(Configuration.class); + if (config.isPresent()) { + return config; + } + } + return Optional.empty(); + } + + public Optional extractRelationshipsVpnBinding(Relationships relationships) { + List configurations = relationships.getRelatedUris(Types.VPN_BINDING); + for (AAIResourceUri vpnBindingUri : configurations) { + AAIResultWrapper vpnBindingWrapper = bbInputSetupUtils.getAAIResourceDepthOne(vpnBindingUri); + Optional vpnBinding = vpnBindingWrapper.asBean(VpnBinding.class); + if (vpnBinding.isPresent()) { + return vpnBinding; + } + } + return Optional.empty(); + } + + public Optional extractRelationshipsVnfc(Relationships relationships) { + List vnfcs = relationships.getByType(Types.VNFC); + for (AAIResultWrapper vnfcWrapper : vnfcs) { + if (vnfcWrapper.getRelationships().isPresent()) { + return vnfcWrapper.getRelationships(); + } + } + return Optional.empty(); + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java index ab83acaec2..78b9bf1ee6 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/BaseTaskTest.java @@ -27,7 +27,7 @@ import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.common.data.TestDataSetup; import org.onap.so.bpmn.infrastructure.flowspecific.tasks.AssignNetworkBBUtils; -import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionExtractResourcesAAI; +import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.WorkflowActionExtractResourcesAAI; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAITest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAITest.java deleted file mode 100644 index 7ac245d0f4..0000000000 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowActionExtractResourcesAAITest.java +++ /dev/null @@ -1,175 +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 static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Optional; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.aai.domain.yang.VpnBinding; -import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; -import org.onap.aaiclient.client.aai.entities.Relationships; -import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; -import org.onap.aaiclient.client.aai.entities.uri.AAISimpleUri; -import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; -import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; - -@RunWith(MockitoJUnitRunner.class) -public class WorkflowActionExtractResourcesAAITest { - - private static final String CONFIGURATION_ID = "configTestId"; - private static final String VPN_ID = "vpnTestId"; - - @Mock - private BBInputSetupUtils bbInputSetupUtils; - @InjectMocks - private WorkflowActionExtractResourcesAAI testedObject; - - @Test - public void extractRelationshipsConfigurationSuccess() { - // given - Relationships relationships = mock(Relationships.class); - when(relationships.getByType(Types.CONFIGURATION)) - .thenReturn(getConfigurationList("{\"configuration-id\" : \"" + CONFIGURATION_ID + "\"}")); - // when - Optional resultOpt = testedObject.extractRelationshipsConfiguration(relationships); - // then - assertThat(resultOpt).isNotEmpty(); - assertThat(resultOpt.get().getConfigurationId()).isEqualTo(CONFIGURATION_ID); - } - - @Test - public void extractRelationshipsConfiguration_noConfigurationFoundInList() { - // given - Relationships relationships = mock(Relationships.class); - when(relationships.getByType(Types.CONFIGURATION)).thenReturn(getConfigurationList("noJson")); - // when - Optional resultOpt = testedObject.extractRelationshipsConfiguration(relationships); - // then - assertThat(resultOpt).isEmpty(); - } - - @Test - public void extractRelationshipsConfiguration_notFound_listEmpty() { - // given - Relationships relationships = mock(Relationships.class); - when(relationships.getByType(Types.CONFIGURATION)).thenReturn(Collections.emptyList()); - // when - Optional resultOpt = testedObject.extractRelationshipsConfiguration(relationships); - // then - assertThat(resultOpt).isEmpty(); - } - - @Test - public void extractRelationshipsVpnBindingSuccess() { - // given - Relationships relationships = mock(Relationships.class); - AAIResourceUri aaiResourceUri = mock(AAISimpleUri.class); - List aaiResourceUriList = new ArrayList<>(); - aaiResourceUriList.add(aaiResourceUri); - when(relationships.getRelatedUris(Types.VPN_BINDING)).thenReturn(aaiResourceUriList); - AAIResultWrapper aaiResultWrapper = new AAIResultWrapper("{\"vpn-id\" : \"" + VPN_ID + "\"}"); - when(bbInputSetupUtils.getAAIResourceDepthOne(aaiResourceUri)).thenReturn(aaiResultWrapper); - // when - Optional resultOpt = testedObject.extractRelationshipsVpnBinding(relationships); - // then - assertThat(resultOpt).isNotEmpty(); - assertThat(resultOpt.get().getVpnId()).isEqualTo(VPN_ID); - } - - @Test - public void extractRelationshipsVpnBinding_noVpnBindingFoundInList() { - // given - Relationships relationships = mock(Relationships.class); - AAIResourceUri aaiResourceUri = mock(AAISimpleUri.class); - List aaiResourceUriList = new ArrayList<>(); - aaiResourceUriList.add(aaiResourceUri); - when(relationships.getRelatedUris(Types.VPN_BINDING)).thenReturn(aaiResourceUriList); - AAIResultWrapper aaiResultWrapper = new AAIResultWrapper("noJson"); - when(bbInputSetupUtils.getAAIResourceDepthOne(aaiResourceUri)).thenReturn(aaiResultWrapper); - // when - Optional resultOpt = testedObject.extractRelationshipsVpnBinding(relationships); - // then - assertThat(resultOpt).isEmpty(); - } - - @Test - public void extractRelationshipsVpnBinding_notFound_listEmpty() { - // given - Relationships relationships = mock(Relationships.class); - when(relationships.getRelatedUris(Types.VPN_BINDING)).thenReturn(Collections.emptyList()); - // when - Optional resultOpt = testedObject.extractRelationshipsVpnBinding(relationships); - // then - assertThat(resultOpt).isEmpty(); - } - - @Test - public void extractRelationshipsVnfcSuccess() { - // given - Relationships relationships = mock(Relationships.class); - when(relationships.getByType(Types.VNFC)).thenReturn( - getConfigurationList("{\"relationship-list\": {\"relationship\": [{\"related-to\": \"tenant\"}]}}")); - // when - Optional resultOpt = testedObject.extractRelationshipsVnfc(relationships); - // then - assertThat(resultOpt).isNotEmpty(); - assertThat(resultOpt.get().getJson()).isEqualTo("{\"relationship\":[{\"related-to\":\"tenant\"}]}"); - } - - @Test - public void extractRelationshipsVnfc_noRelationFoundList() { - // given - Relationships relationships = mock(Relationships.class); - when(relationships.getByType(Types.VNFC)).thenReturn(getConfigurationList("{\"jsonWithNoRelation\": {}}")); - // when - Optional resultOpt = testedObject.extractRelationshipsVnfc(relationships); - // then - assertThat(resultOpt).isEmpty(); - } - - @Test - public void extractRelationshipsVnfc_notFound_listEmpty() { - // given - Relationships relationships = mock(Relationships.class); - when(relationships.getByType(Types.VNFC)).thenReturn(Collections.emptyList()); - // when - Optional resultOpt = testedObject.extractRelationshipsVnfc(relationships); - // then - assertThat(resultOpt).isEmpty(); - } - - private List getConfigurationList(String json) { - List configurations = new ArrayList<>(); - AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(json); - configurations.add(aaiResultWrapper); - return configurations; - } -} 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 31f37f4ac3..10e6ed4895 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 @@ -24,16 +24,13 @@ package org.onap.so.bpmn.infrastructure.workflow.tasks; -import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyList; import static org.mockito.ArgumentMatchers.anyObject; @@ -57,7 +54,6 @@ import java.util.UUID; import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; -import org.javatuples.Pair; import org.junit.Before; import org.junit.Ignore; import org.junit.Rule; @@ -2064,180 +2060,6 @@ public class WorkflowActionTest extends BaseTaskTest { } } - @Ignore - @Test - public void traverseCatalogDbServiceMultipleNetworkTest() throws IOException, VrfBondingServiceException { - execution.setVariable("testProcessKey", "testProcessKeyValue"); - Service service = new Service(); - List networkCustomizations = new ArrayList<>(); - NetworkResourceCustomization networkCust = new NetworkResourceCustomization(); - networkCust.setModelCustomizationUUID("123"); - networkCustomizations.add(networkCust); - service.setNetworkCustomizations(networkCustomizations); - NetworkCollectionResourceCustomization collectionResourceCustomization = - new NetworkCollectionResourceCustomization(); - collectionResourceCustomization.setModelCustomizationUUID("123"); - CollectionResource collectionResource = new CollectionResource(); - collectionResource.setToscaNodeType("NetworkCollection"); - InstanceGroup instanceGroup = new InstanceGroup(); - List collectionInstanceGroupCustomizations = new ArrayList<>(); - CollectionResourceInstanceGroupCustomization collectionInstanceGroupCustomization = - new CollectionResourceInstanceGroupCustomization(); - collectionInstanceGroupCustomization.setSubInterfaceNetworkQuantity(3); - collectionInstanceGroupCustomizations.add(collectionInstanceGroupCustomization); - instanceGroup.setCollectionInstanceGroupCustomizations(collectionInstanceGroupCustomizations); - collectionResource.setInstanceGroup(instanceGroup); - collectionResourceCustomization.setCollectionResource(collectionResource);; - service.setModelUUID("abc"); - service.getCollectionResourceCustomizations().add(collectionResourceCustomization); - service.getCollectionResourceCustomizations().add(collectionResourceCustomization); - doReturn(service).when(catalogDbClient).getServiceByID("3c40d244-808e-42ca-b09a-256d83d19d0a"); - doReturn(collectionResourceCustomization).when(catalogDbClient) - .getNetworkCollectionResourceCustomizationByID("123"); - String bpmnRequest = readBpmnRequestFromFile(MACRO_ACTIVATE_DELETE_UNASSIGN_JSON); - ObjectMapper mapper = new ObjectMapper(); - ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class); - List resourceCounter = new ArrayList<>(); - thrown.expect(BpmnError.class); - List> aaiResourceIds = new ArrayList<>(); - serviceEBBLoader.traverseCatalogDbService(execution, sIRequest, resourceCounter, aaiResourceIds); - } - - - - @Test - public void findCatalogNetworkCollectionTest() { - Service service = new Service(); - NetworkCollectionResourceCustomization networkCustomization = new NetworkCollectionResourceCustomization(); - networkCustomization.setModelCustomizationUUID("123"); - service.getCollectionResourceCustomizations().add(networkCustomization); - doReturn(networkCustomization).when(catalogDbClient).getNetworkCollectionResourceCustomizationByID("123"); - CollectionResourceCustomization customization = - serviceEBBLoader.findCatalogNetworkCollection(execution, service); - assertNotNull(customization); - } - - @Test - public void findCatalogNetworkCollectionEmptyTest() { - Service service = new Service(); - NetworkCollectionResourceCustomization networkCustomization = new NetworkCollectionResourceCustomization(); - networkCustomization.setModelCustomizationUUID("123"); - service.getCollectionResourceCustomizations().add(networkCustomization); - CollectionResourceCustomization customization = - serviceEBBLoader.findCatalogNetworkCollection(execution, service); - assertNull(customization); - } - - @Test - public void findCatalogNetworkCollectionMoreThanOneTest() { - Service service = new Service(); - NetworkCollectionResourceCustomization networkCustomization1 = new NetworkCollectionResourceCustomization(); - networkCustomization1.setModelCustomizationUUID("123"); - NetworkCollectionResourceCustomization networkCustomization2 = new NetworkCollectionResourceCustomization(); - networkCustomization2.setModelCustomizationUUID("321"); - service.getCollectionResourceCustomizations().add(networkCustomization1); - service.getCollectionResourceCustomizations().add(networkCustomization2); - doReturn(networkCustomization1).when(catalogDbClient).getNetworkCollectionResourceCustomizationByID("123"); - doReturn(networkCustomization2).when(catalogDbClient).getNetworkCollectionResourceCustomizationByID("321"); - serviceEBBLoader.findCatalogNetworkCollection(execution, service); - assertEquals("Found multiple Network Collections in the Service model, only one per Service is supported.", - execution.getVariable("WorkflowActionErrorMessage")); - } - - - @Test - public void traverseAAIServiceTest() { - List resourceCounter = new ArrayList<>(); - String resourceId = "si0"; - List> aaiResourceIds = new ArrayList<>(); - - ServiceInstance serviceInstanceAAI = new ServiceInstance(); - serviceInstanceAAI.setServiceInstanceId(resourceId); - - org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstance = setServiceInstance(); - setGenericVnf(); - setVfModule(true); - setVolumeGroup(); - setL3Network(); - setCollection(); - setConfiguration(); - - Configuration config = new Configuration(); - config.setConfigurationId("testConfigurationId2"); - serviceInstance.getConfigurations().add(config); - - Relationship relationship1 = new Relationship(); - relationship1.setRelatedTo("vnfc"); - RelationshipList relationshipList1 = new RelationshipList(); - relationshipList1.getRelationship().add(relationship1); - - Relationship relationship2 = new Relationship(); - relationship2.setRelatedTo("vpn-binding"); - RelationshipList relationshipList2 = new RelationshipList(); - relationshipList2.getRelationship().add(relationship2); - - org.onap.aai.domain.yang.Configuration aaiConfiguration1 = new org.onap.aai.domain.yang.Configuration(); - aaiConfiguration1.setConfigurationId("testConfigurationId"); - aaiConfiguration1.setRelationshipList(relationshipList1); - - org.onap.aai.domain.yang.Configuration aaiConfiguration2 = new org.onap.aai.domain.yang.Configuration(); - aaiConfiguration2.setConfigurationId("testConfigurationId2"); - aaiConfiguration2.setRelationshipList(relationshipList1); - - try { - doReturn(serviceInstanceAAI).when(bbSetupUtils).getAAIServiceInstanceById(resourceId); - doReturn(serviceInstance).when(bbInputSetup).getExistingServiceInstance(serviceInstanceAAI); - doReturn(Optional.of(aaiConfiguration1)).when(aaiConfigurationResources) - .getConfiguration("testConfigurationId"); - doReturn(Optional.of(aaiConfiguration2)).when(aaiConfigurationResources) - .getConfiguration("testConfigurationId2"); - serviceEBBLoader.traverseAAIService(execution, resourceCounter, resourceId, aaiResourceIds); - assertEquals(8, resourceCounter.size()); - assertTrue(resourceCounter.get(2).isBaseVfModule()); - assertThat(aaiResourceIds, sameBeanAs(getExpectedResourceIds())); - } catch (Exception e) { - fail("Unexpected exception was thrown."); - } - } - - @Test - public void foundRelatedTest() { - List resourceList = new ArrayList<>(); - resourceList.add(new Resource(WorkflowType.PNF, "model customization id", false)); - resourceList.add(new Resource(WorkflowType.VNF, "model customization id", false)); - resourceList.add(new Resource(WorkflowType.NETWORK, "model customization id", false)); - resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, "model customization id", false)); - - assertEquals(serviceEBBLoader.foundRelated(resourceList), true); - } - - @Test - public void containsWorkflowTypeTest() { - List resourceList = new ArrayList<>(); - resourceList.add(new Resource(WorkflowType.PNF, "resource id", false)); - resourceList.add(new Resource(WorkflowType.VNF, "model customization id", false)); - resourceList.add(new Resource(WorkflowType.NETWORK, "model customization id", false)); - resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, "model customization id", 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() { - List> resourceIds = new ArrayList<>(); - resourceIds.add(new Pair(WorkflowType.VNF, "testVnfId1")); - resourceIds.add(new Pair(WorkflowType.VFMODULE, "testVfModuleId1")); - resourceIds.add(new Pair(WorkflowType.VOLUMEGROUP, "testVolumeGroupId1")); - resourceIds.add(new Pair(WorkflowType.NETWORK, "testNetworkId1")); - resourceIds.add(new Pair(WorkflowType.NETWORKCOLLECTION, "testId")); - resourceIds.add(new Pair(WorkflowType.CONFIGURATION, "testConfigurationId")); - resourceIds.add(new Pair(WorkflowType.CONFIGURATION, "testConfigurationId2")); - return resourceIds; - } - private List createFlowList(String... flowNames) { List result = new ArrayList<>(); int sequenceNumber = 1; diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoaderTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoaderTest.java new file mode 100644 index 0000000000..a5ecf364a6 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/ServiceEBBLoaderTest.java @@ -0,0 +1,357 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake; +import org.javatuples.Pair; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mock; +import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipList; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.aaiclient.client.aai.entities.Relationships; +import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.infrastructure.workflow.tasks.Resource; +import org.onap.so.bpmn.infrastructure.workflow.tasks.VrfBondingServiceException; +import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.so.client.orchestration.AAIConfigurationResources; +import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.catalog.beans.CollectionResourceCustomization; +import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization; +import org.onap.so.db.catalog.beans.NetworkResourceCustomization; +import org.onap.so.db.catalog.beans.CollectionResource; +import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization; +import org.onap.so.db.catalog.beans.InstanceGroup; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.serviceinstancebeans.RelatedInstance; +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.Optional; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyList; +import static org.mockito.Mockito.anyString; + +public class ServiceEBBLoaderTest extends BaseTaskTest { + + private static final String MACRO_ACTIVATE_DELETE_UNASSIGN_JSON = "Macro/ServiceMacroActivateDeleteUnassign.json"; + private static final String MACRO_ASSIGN_JSON = "Macro/ServiceMacroAssign.json"; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Mock + protected Relationships relationships; + + private DelegateExecution execution; + private ServiceEBBLoader serviceEBBLoader; + private UserParamsServiceTraversal mockUserParamsServiceTraversal; + private CatalogDbClient mockCatalogDbClient; + private VrfValidation mockVrfValidation; + private AAIConfigurationResources mockAaiConfigurationResources; + private WorkflowActionExtractResourcesAAI mockWorkflowActionExtractResourcesAAI; + private BBInputSetupUtils mockBbInputSetupUtils; + private BBInputSetup mockBbInputSetup; + + @Before + public void before() throws Exception { + execution = new DelegateExecutionFake(); + mockUserParamsServiceTraversal = mock(UserParamsServiceTraversal.class); + mockCatalogDbClient = mock(CatalogDbClient.class); + mockVrfValidation = mock(VrfValidation.class); + mockAaiConfigurationResources = mock(AAIConfigurationResources.class); + mockWorkflowActionExtractResourcesAAI = mock(WorkflowActionExtractResourcesAAI.class); + mockBbInputSetupUtils = mock(BBInputSetupUtils.class); + mockBbInputSetup = mock(BBInputSetup.class); + serviceEBBLoader = new ServiceEBBLoader(mockUserParamsServiceTraversal, mockCatalogDbClient, mockVrfValidation, + mockAaiConfigurationResources, mockWorkflowActionExtractResourcesAAI, mockBbInputSetupUtils, + mockBbInputSetup, mock(ExceptionBuilder.class)); + } + + + @Test + public void getResourceListForServiceWithRequestActionAssignInstance() + throws IOException, VrfBondingServiceException { + String bpmnRequest = readBpmnRequestFromFile(MACRO_ASSIGN_JSON); + ObjectMapper mapper = new ObjectMapper(); + ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class); + String requestAction = "assignInstance"; + String serviceInstanceId = "123"; + String resourceId = "si0"; + List> aaiResourceIds = new ArrayList<>(); + doReturn(prepareListWithResources()).when(mockUserParamsServiceTraversal).getResourceListFromUserParams(any(), + anyList(), anyString(), anyString()); + List resources = serviceEBBLoader.getResourceListForService(sIRequest, requestAction, execution, + serviceInstanceId, resourceId, aaiResourceIds); + assertNotNull(resources); + assertEquals(resources.size(), 6); + } + + @Test + public void findCatalogNetworkCollectionTest() { + Service service = new Service(); + NetworkCollectionResourceCustomization networkCustomization = new NetworkCollectionResourceCustomization(); + networkCustomization.setModelCustomizationUUID("123"); + service.getCollectionResourceCustomizations().add(networkCustomization); + doReturn(networkCustomization).when(mockCatalogDbClient).getNetworkCollectionResourceCustomizationByID("123"); + CollectionResourceCustomization customization = + serviceEBBLoader.findCatalogNetworkCollection(execution, service); + assertNotNull(customization); + } + + @Test + public void findCatalogNetworkCollectionEmptyTest() { + Service service = new Service(); + NetworkCollectionResourceCustomization networkCustomization = new NetworkCollectionResourceCustomization(); + networkCustomization.setModelCustomizationUUID("123"); + service.getCollectionResourceCustomizations().add(networkCustomization); + CollectionResourceCustomization customization = + serviceEBBLoader.findCatalogNetworkCollection(execution, service); + assertNull(customization); + } + + @Test + public void findCatalogNetworkCollectionMoreThanOneTest() { + Service service = new Service(); + NetworkCollectionResourceCustomization networkCustomization1 = new NetworkCollectionResourceCustomization(); + networkCustomization1.setModelCustomizationUUID("123"); + NetworkCollectionResourceCustomization networkCustomization2 = new NetworkCollectionResourceCustomization(); + networkCustomization2.setModelCustomizationUUID("321"); + service.getCollectionResourceCustomizations().add(networkCustomization1); + service.getCollectionResourceCustomizations().add(networkCustomization2); + doReturn(networkCustomization1).when(mockCatalogDbClient).getNetworkCollectionResourceCustomizationByID("123"); + doReturn(networkCustomization2).when(mockCatalogDbClient).getNetworkCollectionResourceCustomizationByID("321"); + serviceEBBLoader.findCatalogNetworkCollection(execution, service); + assertEquals("Found multiple Network Collections in the Service model, only one per Service is supported.", + execution.getVariable("WorkflowActionErrorMessage")); + } + + @Test + public void foundRelatedTest() { + List resourceList = new ArrayList<>(); + resourceList.add(new Resource(WorkflowType.PNF, "model customization id", false)); + resourceList.add(new Resource(WorkflowType.VNF, "model customization id", false)); + resourceList.add(new Resource(WorkflowType.NETWORK, "model customization id", false)); + resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, "model customization id", false)); + + assertTrue(serviceEBBLoader.foundRelated(resourceList)); + } + + @Test + public void containsWorkflowTypeTest() { + List resourceList = new ArrayList<>(); + resourceList.add(new Resource(WorkflowType.PNF, "resource id", false)); + resourceList.add(new Resource(WorkflowType.VNF, "model customization id", false)); + resourceList.add(new Resource(WorkflowType.NETWORK, "model customization id", false)); + resourceList.add(new Resource(WorkflowType.NETWORKCOLLECTION, "model customization id", false)); + + assertTrue(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.PNF)); + assertTrue(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.VNF)); + assertTrue(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.NETWORK)); + assertTrue(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.NETWORKCOLLECTION)); + assertFalse(serviceEBBLoader.containsWorkflowType(resourceList, WorkflowType.CONFIGURATION)); + } + + @Test + public void traverseAAIServiceTest() { + List resourceCounter = new ArrayList<>(); + String resourceId = "si0"; + List> aaiResourceIds = new ArrayList<>(); + + ServiceInstance serviceInstanceAAI = new ServiceInstance(); + serviceInstanceAAI.setServiceInstanceId(resourceId); + + org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance serviceInstance = setServiceInstance(); + setGenericVnf(); + setVfModule(true); + setVolumeGroup(); + setL3Network(); + setCollection(); + setConfiguration(); + + Configuration config = new Configuration(); + config.setConfigurationId("testConfigurationId2"); + serviceInstance.getConfigurations().add(config); + + Relationship relationship1 = new Relationship(); + relationship1.setRelatedTo("vnfc"); + RelationshipList relationshipList1 = new RelationshipList(); + relationshipList1.getRelationship().add(relationship1); + + Relationship relationship2 = new Relationship(); + relationship2.setRelatedTo("vpn-binding"); + RelationshipList relationshipList2 = new RelationshipList(); + relationshipList2.getRelationship().add(relationship2); + + org.onap.aai.domain.yang.Configuration aaiConfiguration1 = new org.onap.aai.domain.yang.Configuration(); + aaiConfiguration1.setConfigurationId("testConfigurationId"); + aaiConfiguration1.setRelationshipList(relationshipList1); + + org.onap.aai.domain.yang.Configuration aaiConfiguration2 = new org.onap.aai.domain.yang.Configuration(); + aaiConfiguration2.setConfigurationId("testConfigurationId2"); + aaiConfiguration2.setRelationshipList(relationshipList1); + + try { + doReturn(serviceInstanceAAI).when(mockBbInputSetupUtils).getAAIServiceInstanceById(resourceId); + doReturn(serviceInstance).when(mockBbInputSetup).getExistingServiceInstance(serviceInstanceAAI); + doReturn(Optional.of(aaiConfiguration1)).when(mockAaiConfigurationResources) + .getConfiguration("testConfigurationId"); + doReturn(Optional.of(aaiConfiguration2)).when(mockAaiConfigurationResources) + .getConfiguration("testConfigurationId2"); + serviceEBBLoader.traverseAAIService(execution, resourceCounter, resourceId, aaiResourceIds); + assertEquals(8, resourceCounter.size()); + assertTrue(resourceCounter.get(2).isBaseVfModule()); + assertThat(aaiResourceIds, sameBeanAs(getExpectedResourceIds())); + } catch (Exception e) { + fail("Unexpected exception was thrown."); + } + } + + @Test + public void traverseVrfConfigurationTest() throws VrfBondingServiceException, JsonProcessingException { + List resource = new ArrayList<>(); + List> aaiResourceIds = new ArrayList<>(); + + Service service = new Service(); + List resourceCustomizations = new ArrayList<>(); + + ConfigurationResourceCustomization configuration = new ConfigurationResourceCustomization(); + configuration.setModelCustomizationUUID("123"); + resourceCustomizations.add(configuration); + service.setConfigurationCustomizations(resourceCustomizations); + + Relationship relationship = new Relationship(); + relationship.setRelatedTo("vpn-binding"); + + RelationshipList relationshipList = new RelationshipList(); + relationshipList.getRelationship().add(relationship); + + org.onap.aai.domain.yang.L3Network aaiLocalNetwork = new org.onap.aai.domain.yang.L3Network(); + aaiLocalNetwork.setNetworkId("localNetworkId"); + aaiLocalNetwork.setRelationshipList(relationshipList); + + RelatedInstance relatedVpnBinding = new RelatedInstance(); + relatedVpnBinding.setInstanceId("vpnBindingInstanceId"); + RelatedInstance relatedLocalNetwork = new RelatedInstance(); + relatedLocalNetwork.setInstanceId("localNetworkInstanceId"); + + + doReturn(aaiLocalNetwork).when(mockBbInputSetupUtils).getAAIL3Network("localNetworkInstanceId"); + + serviceEBBLoader.traverseVrfConfiguration(aaiResourceIds, resource, service, relatedVpnBinding, + relatedLocalNetwork); + assertEquals(resource.size(), 1); + assertEquals(aaiResourceIds.size(), 0); + } + + private List> getExpectedResourceIds() { + List> resourceIds = new ArrayList<>(); + resourceIds.add(new Pair(WorkflowType.VNF, "testVnfId1")); + resourceIds.add(new Pair(WorkflowType.VFMODULE, "testVfModuleId1")); + resourceIds.add(new Pair(WorkflowType.VOLUMEGROUP, "testVolumeGroupId1")); + resourceIds.add(new Pair(WorkflowType.NETWORK, "testNetworkId1")); + resourceIds.add(new Pair(WorkflowType.NETWORKCOLLECTION, "testId")); + resourceIds.add(new Pair(WorkflowType.CONFIGURATION, "testConfigurationId")); + resourceIds.add(new Pair(WorkflowType.CONFIGURATION, "testConfigurationId2")); + return resourceIds; + } + + @Test + public void traverseCatalogDbServiceMultipleNetworkTest() throws IOException, VrfBondingServiceException { + execution.setVariable("testProcessKey", "testProcessKeyValue"); + Service service = new Service(); + List networkCustomizations = new ArrayList<>(); + NetworkResourceCustomization networkCust = new NetworkResourceCustomization(); + networkCust.setModelCustomizationUUID("123"); + networkCustomizations.add(networkCust); + service.setNetworkCustomizations(networkCustomizations); + NetworkCollectionResourceCustomization collectionResourceCustomization = + new NetworkCollectionResourceCustomization(); + collectionResourceCustomization.setModelCustomizationUUID("123"); + CollectionResource collectionResource = new CollectionResource(); + collectionResource.setToscaNodeType("NetworkCollection"); + InstanceGroup instanceGroup = new InstanceGroup(); + List collectionInstanceGroupCustomizations = new ArrayList<>(); + CollectionResourceInstanceGroupCustomization collectionInstanceGroupCustomization = + new CollectionResourceInstanceGroupCustomization(); + collectionInstanceGroupCustomization.setSubInterfaceNetworkQuantity(3); + collectionInstanceGroupCustomizations.add(collectionInstanceGroupCustomization); + instanceGroup.setCollectionInstanceGroupCustomizations(collectionInstanceGroupCustomizations); + collectionResource.setInstanceGroup(instanceGroup); + collectionResourceCustomization.setCollectionResource(collectionResource);; + service.setModelUUID("abc"); + service.getCollectionResourceCustomizations().add(collectionResourceCustomization); + service.getCollectionResourceCustomizations().add(collectionResourceCustomization); + + + doReturn(service).when(mockCatalogDbClient).getServiceByID("3c40d244-808e-42ca-b09a-256d83d19d0a"); + doReturn(collectionResourceCustomization).when(mockCatalogDbClient) + .getNetworkCollectionResourceCustomizationByID("123"); + String bpmnRequest = readBpmnRequestFromFile(MACRO_ACTIVATE_DELETE_UNASSIGN_JSON); + ObjectMapper mapper = new ObjectMapper(); + ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class); + + List resource = new ArrayList<>(); + List> aaiResourceIds = new ArrayList<>(); + + serviceEBBLoader.traverseCatalogDbService(execution, sIRequest, resource, aaiResourceIds); + assertEquals(resource.size(), 2); + } + + private String readBpmnRequestFromFile(String fileName) throws IOException { + return new String(Files.readAllBytes(Paths.get("src/test/resources/__files/" + fileName))); + } + + private List prepareListWithResources() { + List resourceList = new ArrayList<>(); + resourceList.add(new Resource(WorkflowType.SERVICE, "3c40d244-808e-42ca-b09a-256d83d19d0a", false)); + resourceList.add(new Resource(WorkflowType.VNF, "ab153b6e-c364-44c0-bef6-1f2982117f04", false)); + resourceList.add(new Resource(WorkflowType.VOLUMEGROUP, "a25e8e8c-58b8-4eec-810c-97dcc1f5cb7f", false)); + resourceList.add(new Resource(WorkflowType.VFMODULE, "72d9d1cd-f46d-447a-abdb-451d6fb05fa8", false)); + resourceList.add(new Resource(WorkflowType.VFMODULE, "3c40d244-808e-42ca-b09a-256d83d19d0a", false)); + resourceList.add(new Resource(WorkflowType.VFMODULE, "72d9d1cd-f46d-447a-abdb-451d6fb05fa8", false)); + return resourceList; + } +} 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 index 75514b15d7..9f4bd97ac6 100644 --- 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 @@ -61,6 +61,7 @@ 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 MACRO_CREATE_WITHOUT_RESOURCES_JSON = "Macro/ServiceMacroCreateWithoutResources.json"; private static final String serviceInstanceId = "123"; private DelegateExecution execution; private CatalogDbClient mockCatalogDbClient; @@ -75,6 +76,24 @@ public class UserParamsServiceTraversalTest extends BaseTaskTest { requestAction = "assignInstance"; } + @Test + public void getResourceListFromUserParams() throws Exception { + initExecution(requestAction, readBpmnRequestFromFile(MACRO_CREATE_WITHOUT_RESOURCES_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); + List result = + resourceListFromUserParams.stream().map(Resource::getResourceType).collect(Collectors.toList()); + + assertEquals(1, resourceListFromUserParams.size()); + assertThat(expected, is(result)); + } + @Test public void getResourceListFromUserParamsForVnfs() throws Exception { initExecution(requestAction, readBpmnRequestFromFile(MACRO_ASSIGN_JSON), false); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/WorkflowActionExtractResourcesAAITest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/WorkflowActionExtractResourcesAAITest.java new file mode 100644 index 0000000000..ba55dd0365 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/workflow/tasks/ebb/loader/WorkflowActionExtractResourcesAAITest.java @@ -0,0 +1,176 @@ +/*- + * ============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 static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.aai.domain.yang.VpnBinding; +import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; +import org.onap.aaiclient.client.aai.entities.Relationships; +import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; +import org.onap.aaiclient.client.aai.entities.uri.AAISimpleUri; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; +import org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.WorkflowActionExtractResourcesAAI; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; +import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; + +@RunWith(MockitoJUnitRunner.class) +public class WorkflowActionExtractResourcesAAITest { + + private static final String CONFIGURATION_ID = "configTestId"; + private static final String VPN_ID = "vpnTestId"; + + @Mock + private BBInputSetupUtils bbInputSetupUtils; + @InjectMocks + private WorkflowActionExtractResourcesAAI testedObject; + + @Test + public void extractRelationshipsConfigurationSuccess() { + // given + Relationships relationships = mock(Relationships.class); + when(relationships.getByType(Types.CONFIGURATION)) + .thenReturn(getConfigurationList("{\"configuration-id\" : \"" + CONFIGURATION_ID + "\"}")); + // when + Optional resultOpt = testedObject.extractRelationshipsConfiguration(relationships); + // then + assertThat(resultOpt).isNotEmpty(); + assertThat(resultOpt.get().getConfigurationId()).isEqualTo(CONFIGURATION_ID); + } + + @Test + public void extractRelationshipsConfiguration_noConfigurationFoundInList() { + // given + Relationships relationships = mock(Relationships.class); + when(relationships.getByType(Types.CONFIGURATION)).thenReturn(getConfigurationList("noJson")); + // when + Optional resultOpt = testedObject.extractRelationshipsConfiguration(relationships); + // then + assertThat(resultOpt).isEmpty(); + } + + @Test + public void extractRelationshipsConfiguration_notFound_listEmpty() { + // given + Relationships relationships = mock(Relationships.class); + when(relationships.getByType(Types.CONFIGURATION)).thenReturn(Collections.emptyList()); + // when + Optional resultOpt = testedObject.extractRelationshipsConfiguration(relationships); + // then + assertThat(resultOpt).isEmpty(); + } + + @Test + public void extractRelationshipsVpnBindingSuccess() { + // given + Relationships relationships = mock(Relationships.class); + AAIResourceUri aaiResourceUri = mock(AAISimpleUri.class); + List aaiResourceUriList = new ArrayList<>(); + aaiResourceUriList.add(aaiResourceUri); + when(relationships.getRelatedUris(Types.VPN_BINDING)).thenReturn(aaiResourceUriList); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper("{\"vpn-id\" : \"" + VPN_ID + "\"}"); + when(bbInputSetupUtils.getAAIResourceDepthOne(aaiResourceUri)).thenReturn(aaiResultWrapper); + // when + Optional resultOpt = testedObject.extractRelationshipsVpnBinding(relationships); + // then + assertThat(resultOpt).isNotEmpty(); + assertThat(resultOpt.get().getVpnId()).isEqualTo(VPN_ID); + } + + @Test + public void extractRelationshipsVpnBinding_noVpnBindingFoundInList() { + // given + Relationships relationships = mock(Relationships.class); + AAIResourceUri aaiResourceUri = mock(AAISimpleUri.class); + List aaiResourceUriList = new ArrayList<>(); + aaiResourceUriList.add(aaiResourceUri); + when(relationships.getRelatedUris(Types.VPN_BINDING)).thenReturn(aaiResourceUriList); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper("noJson"); + when(bbInputSetupUtils.getAAIResourceDepthOne(aaiResourceUri)).thenReturn(aaiResultWrapper); + // when + Optional resultOpt = testedObject.extractRelationshipsVpnBinding(relationships); + // then + assertThat(resultOpt).isEmpty(); + } + + @Test + public void extractRelationshipsVpnBinding_notFound_listEmpty() { + // given + Relationships relationships = mock(Relationships.class); + when(relationships.getRelatedUris(Types.VPN_BINDING)).thenReturn(Collections.emptyList()); + // when + Optional resultOpt = testedObject.extractRelationshipsVpnBinding(relationships); + // then + assertThat(resultOpt).isEmpty(); + } + + @Test + public void extractRelationshipsVnfcSuccess() { + // given + Relationships relationships = mock(Relationships.class); + when(relationships.getByType(Types.VNFC)).thenReturn( + getConfigurationList("{\"relationship-list\": {\"relationship\": [{\"related-to\": \"tenant\"}]}}")); + // when + Optional resultOpt = testedObject.extractRelationshipsVnfc(relationships); + // then + assertThat(resultOpt).isNotEmpty(); + assertThat(resultOpt.get().getJson()).isEqualTo("{\"relationship\":[{\"related-to\":\"tenant\"}]}"); + } + + @Test + public void extractRelationshipsVnfc_noRelationFoundList() { + // given + Relationships relationships = mock(Relationships.class); + when(relationships.getByType(Types.VNFC)).thenReturn(getConfigurationList("{\"jsonWithNoRelation\": {}}")); + // when + Optional resultOpt = testedObject.extractRelationshipsVnfc(relationships); + // then + assertThat(resultOpt).isEmpty(); + } + + @Test + public void extractRelationshipsVnfc_notFound_listEmpty() { + // given + Relationships relationships = mock(Relationships.class); + when(relationships.getByType(Types.VNFC)).thenReturn(Collections.emptyList()); + // when + Optional resultOpt = testedObject.extractRelationshipsVnfc(relationships); + // then + assertThat(resultOpt).isEmpty(); + } + + private List getConfigurationList(String json) { + List configurations = new ArrayList<>(); + AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(json); + configurations.add(aaiResultWrapper); + return configurations; + } +} diff --git a/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroCreateWithoutResources.json b/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroCreateWithoutResources.json new file mode 100644 index 0000000000..579c924d9b --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/test/resources/__files/Macro/ServiceMacroCreateWithoutResources.json @@ -0,0 +1,48 @@ +{ + "requestDetails": { + "modelInfo": { + "modelType": "service", + "modelInvariantId": "5d48acb5-097d-4982-aeb2-f4a3bd87d31b", + "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a", + "modelName": "Sample Service Model", + "modelVersion": "10.0" + }, + "cloudConfiguration": { + "cloudOwner" : "my-custom-cloud-owner" + }, + "owningEntity": { + "owningEntityId": "038d99af-0427-42c2-9d15-971b99b9b489", + "owningEntityName": "PACKET CORE" + }, + "project": { + "projectName": "{some project name}" + }, + "subscriberInfo": { + "globalSubscriberId": "{some subscriber id}" + }, + "requestInfo": { + "productFamilyId": "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb", + "source": "VID", + "suppressRollback": true, + "requestorId": "xxxxxx", + "instanceName": "test" + }, + "requestParameters": { + "subscriptionServiceType": "VMX", + "aLaCarte": false, + "userParams": [ + { + "service": { + "modelInfo": { + "modelType": "service", + "modelName": "Sample Service Model", + "modelVersionId": "3c40d244-808e-42ca-b09a-256d83d19d0a" + }, + "instanceParams": [], + "resources": {} + } + } + ] + } + } +} -- cgit 1.2.3-korg