From e761fa50f80b2d6888f510f67cab1d6e740fd28e Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Tue, 16 Oct 2018 16:46:17 -0400 Subject: Bug fixes October 16 Treat the VfModule returned from PrepareUpdateAAIVfModule call as an AAI object collection create, connect instanceGroup to cloudRegion Fix a typo in the name of the method for getting a variable testing mapping of instance group role test NetworkInstanceGroup role to be SUB-INTERFACE use enum value with hyphen for subtype Some updates based on feedback to java codes updated client to use optional instead of passing null added case where client sends null due to mapping issue added generic response object and pinc returns response build relationship now correctly removes wrapper Ensure that no null object gets referenced while checking if VNF is empty. Change-Id: I6177877518475c1f2e8e4e9dbd2ad1e2f3e10d18 Issue-ID: SO-1144 Signed-off-by: Benjamin, Max (mb388a) --- .../bpmn/common/scripts/DeleteAAIVfModule.groovy | 2 +- .../onap/so/bpmn/common/baseclient/BaseClient.java | 15 +++++++ .../BuildingBlock/CreateNetworkCollectionBB.bpmn | 51 ++++++++++++++-------- .../subprocess/CreateNetworkCollectionBBTest.java | 2 +- .../infrastructure/scripts/DoDeleteVfModule.groovy | 4 +- .../bpmn/infrastructure/scripts/DoDeleteVnf.groovy | 8 +++- .../infrastructure/scripts/DoUpdateVfModule.groovy | 21 ++++++--- .../tasks/CreateNetworkCollection.java | 17 ++++++++ .../client/orchestration/AAINetworkResources.java | 8 ++++ .../tasks/CreateNetworkCollectionTest.java | 10 +++++ .../so/client/aai/mapper/AAIObjectMapperTest.java | 3 +- .../orchestration/AAINetworkResourcesTest.java | 10 +++++ .../org/onap/so/client/aai/AAIResourcesClient.java | 8 ++-- .../onap/so/client/aai/AAIResourcesClientTest.java | 20 ++++++++- .../java/org/onap/so/db/catalog/beans/SubType.java | 11 ++++- 15 files changed, 153 insertions(+), 37 deletions(-) diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DeleteAAIVfModule.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DeleteAAIVfModule.groovy index 178b4d1695..6da1f6d6ff 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DeleteAAIVfModule.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DeleteAAIVfModule.groovy @@ -132,7 +132,7 @@ public class DeleteAAIVfModule extends AbstractServiceTaskProcessor{ def responseData = "" try { String vnfId = execution.getVariable("DAAIVfMod_vnfId") - String vfModuleId = execution.setVariable("DAAIVfMod_vfModuleId") + String vfModuleId = execution.getVariable("DAAIVfMod_vfModuleId") String resourceVersion = execution.getVariable("DAAIVfMod_vfModRsrcVer") AaiUtil aaiUriUtil = new AaiUtil(this) diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/baseclient/BaseClient.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/baseclient/BaseClient.java index 78f3e96978..af93c1bfc0 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/baseclient/BaseClient.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/common/baseclient/BaseClient.java @@ -20,11 +20,15 @@ package org.onap.so.bpmn.common.baseclient; +import java.util.ArrayList; +import java.util.List; + import org.onap.so.logging.jaxrs.filter.SpringClientFilter; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.http.client.BufferingClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; @@ -40,6 +44,17 @@ public class BaseClient { public HttpHeaders getHttpHeader() { return httpHeader; } + + public HttpHeaders setDefaultHttpHeaders(String auth) { + httpHeader = new HttpHeaders(); + httpHeader.set("Authorization", auth); + httpHeader.setContentType(MediaType.APPLICATION_JSON); + List acceptMediaTypes = new ArrayList(); + acceptMediaTypes.add(MediaType.APPLICATION_JSON); + acceptMediaTypes.add(MediaType.TEXT_PLAIN); + httpHeader.setAccept(acceptMediaTypes); + return httpHeader; + } public void setHttpHeader(HttpHeaders httpHeader) { this.httpHeader = httpHeader; diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CreateNetworkCollectionBB.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CreateNetworkCollectionBB.bpmn index fb2bfae01a..293ba5db9b 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CreateNetworkCollectionBB.bpmn +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/BuildingBlock/CreateNetworkCollectionBB.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_1maepy7 @@ -23,41 +23,46 @@ SequenceFlow_0z4c30j - SequenceFlow_1hij1px + SequenceFlow_0904jyg - SequenceFlow_1hij1px + SequenceFlow_0gkrvg6 SequenceFlow_0hhklb4 - + + SequenceFlow_0904jyg + SequenceFlow_0gkrvg6 + + + - + - + - + - + - + - + @@ -91,20 +96,30 @@ - + - + + + + + + + + + + + - + - + - - - + + + - + diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/CreateNetworkCollectionBBTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/CreateNetworkCollectionBBTest.java index bd285f11e1..421e09c9cf 100644 --- a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/CreateNetworkCollectionBBTest.java +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/CreateNetworkCollectionBBTest.java @@ -35,7 +35,7 @@ public class CreateNetworkCollectionBBTest extends BaseBPMNTest{ public void sunnyDayCreateNetworkCollection_Test() throws InterruptedException { ProcessInstance pi = runtimeService.startProcessInstanceByKey("CreateNetworkCollectionBB",variables); assertThat(pi).isNotNull(); - assertThat(pi).isStarted().hasPassedInOrder("createNetworkCollection_startEvent", "BuildName_ServiceTask", "ServiceTask_create_NetworkCollection", "ServiceTask_create_NetworkCollectionInstanceGroup", "ServiceTask_Connect_Collection_to_InstanceGroup", "ServiceTask_Connect_Collection_to_ServiceInstance", "createNetworkCollection_EndEvent"); + assertThat(pi).isStarted().hasPassedInOrder("createNetworkCollection_startEvent", "BuildName_ServiceTask", "ServiceTask_create_NetworkCollection", "ServiceTask_create_NetworkCollectionInstanceGroup", "ServiceTask_Connect_Collection_to_InstanceGroup", "ServiceTask_Connect_InstanceGroup_to_CloudRegion", "ServiceTask_Connect_Collection_to_ServiceInstance", "createNetworkCollection_EndEvent"); assertThat(pi).isEnded(); } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteVfModule.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteVfModule.groovy index 1a3e8aa4e6..85e67c51a7 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteVfModule.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteVfModule.groovy @@ -217,8 +217,8 @@ public class DoDeleteVfModule extends AbstractServiceTaskProcessor{ // Get vfModuleName from AAI response if it was not specified on the request if (vfModuleName == null || vfModuleName.isEmpty()) { if (execution.getVariable("vfModuleFromAAI") != null) { - VfModule vfModuleFromAAI = execution.getVariable("vfModuleFromAAI") - vfModuleName = vfModuleFromAAI.getElementText("vf-module-name") + org.onap.aai.domain.yang.VfModule vfModuleFromAAI = execution.getVariable("vfModuleFromAAI") + vfModuleName = vfModuleFromAAI.getVfModuleName() } } String vfModuleModelName = execution.getVariable("vfModuleModelName") diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteVnf.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteVnf.groovy index 456a9cfabf..47a4d55e0c 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteVnf.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteVnf.groovy @@ -118,8 +118,12 @@ class DoDeleteVnf extends AbstractServiceTaskProcessor { } Optional vnf = wrapper.asBean(GenericVnf.class) - if(!vnf.get().getVfModules().getVfModule().isEmpty()){ - execution.setVariable("DoDVNF_vnfInUse", true) + if (vnf.get() != null) { + if (vnf.get().getVfModules() != null) { + if((vnf.get().getVfModules().getVfModule() != null) && !vnf.get().getVfModules().getVfModule().isEmpty()){ + execution.setVariable("DoDVNF_vnfInUse", true) + } + } } }else{ execution.setVariable("GENGV_FoundIndicator", false) diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateVfModule.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateVfModule.groovy index bce19795ac..33cb6d4760 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateVfModule.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoUpdateVfModule.groovy @@ -458,8 +458,11 @@ public class DoUpdateVfModule extends VfModuleBase { def vnfType = execution.getVariable('DOUPVfMod_vnfType') def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId') def vfModuleModelName = execution.getVariable('DOUPVfMod_vfModuleModelName') - def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule') - def vfModuleName = vfModule.getElementText('vf-module-name') + def vfModuleName = "" + if (execution.getVariable('DOUPVfMod_vfModule') != null) { + org.onap.aai.domain.yang.VfModule vfModule = execution.getVariable('DOUPVfMod_vfModule') + vfModuleName = vfModule.getVfModuleName() + } def tenantId = execution.getVariable('DOUPVfMod_tenantId') def aicCloudRegion = execution.getVariable('DOUPVfMod_aicCloudRegion') boolean usePreload = execution.getVariable("DOUPVfMod_usePreload") @@ -616,8 +619,11 @@ public class DoUpdateVfModule extends VfModuleBase { def tenantId = execution.getVariable('DOUPVfMod_tenantId') def volumeGroupId = execution.getVariable('DOUPVfMod_volumeGroupId') def volumeGroupStackId = execution.getVariable('DOUPVfMod_volumeGroupStackId') - def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule') - def heatStackId = vfModule.getElementText('heat-stack-id') + def heatStackId = "" + if (execution.getVariable('DOUPVfMod_vfModule') != null) { + org.onap.aai.domain.yang.VfModule vfModule = execution.getVariable('DOUPVfMod_vfModule') + heatStackId = vfModule.getHeatStackId() + } def cloudId = execution.getVariable('DOUPVfMod_aicCloudRegion') def vnfType = execution.getVariable('DOUPVfMod_vnfType') def vnfName = execution.getVariable('DOUPVfMod_vnfName') @@ -836,8 +842,11 @@ public class DoUpdateVfModule extends VfModuleBase { def vnfType = execution.getVariable('DOUPVfMod_vnfType') def vfModuleId = execution.getVariable('DOUPVfMod_vfModuleId') def vfModuleModelName = execution.getVariable('DOUPVfMod_vfModuleModelName') - def VfModule vfModule = (VfModule) execution.getVariable('DOUPVfMod_vfModule') - def vfModuleName = vfModule.getElementText('vf-module-name') + def vfModuleName = "" + if (execution.getVariable('DOUPVfMod_vfModule') != null) { + org.onap.aai.domain.yang.VfModule vfModule = execution.getVariable('DOUPVfMod_vfModule') + vfModuleName = vfModule.getVfModuleName() + } def tenantId = execution.getVariable('DOUPVfMod_tenantId') def aicCloudRegion = execution.getVariable('DOUPVfMod_aicCloudRegion') diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkCollection.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkCollection.java index 222a5482c5..c8c4d439bd 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkCollection.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkCollection.java @@ -90,6 +90,23 @@ public class CreateNetworkCollection { } } + /** + * BPMN access method to connect Instance Group to Cloud Region + * @param execution + * @throws Exception + */ + public void connectInstanceGroupToCloudRegion(BuildingBlockExecution execution) throws Exception { + execution.setVariable("connectInstanceGroupToCloudRegionRollback", false); + try{ + ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID, execution.getLookupMap().get(ResourceKey.SERVICE_INSTANCE_ID)); + Collection networkCollection = serviceInstance.getCollection(); + aaiNetworkResources.connectInstanceGroupToCloudRegion(networkCollection.getInstanceGroup(), execution.getGeneralBuildingBlock().getCloudRegion()); + execution.setVariable("connectInstanceGroupToCloudRegionRollback", true); + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + /** * BPMN access method to connect Network Collection * @param execution diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java index dc5ba64d2d..a4c705b0c7 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAINetworkResources.java @@ -33,6 +33,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet; import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.entities.AAIEdgeLabel; import org.onap.so.client.aai.entities.AAIResultWrapper; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; @@ -144,6 +145,13 @@ public class AAINetworkResources { injectionHelper.getAaiClient().connect(networkCollectionUri, netwrokCollectionInstanceGroupURI); } + public void connectInstanceGroupToCloudRegion(InstanceGroup instanceGroup, CloudRegion cloudRegion) { + AAIResourceUri cloudRegionURI = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, + cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId()); + AAIResourceUri instanceGroupURI = AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId()); + injectionHelper.getAaiClient().connect(instanceGroupURI, cloudRegionURI, AAIEdgeLabel.USES); + } + public void connectNetworkCollectionToServiceInstance(Collection networkCollection, ServiceInstance networkCollectionServiceInstance) { AAIResourceUri networkCollectionUri = AAIUriFactory.createResourceUri(AAIObjectType.COLLECTION, networkCollection.getId()); AAIResourceUri networkCollectionServiceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, networkCollectionServiceInstance.getServiceInstanceId()); diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkCollectionTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkCollectionTest.java index cde7797ed0..207447ae35 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkCollectionTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkCollectionTest.java @@ -30,6 +30,7 @@ import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Test; import org.onap.so.bpmn.BaseTaskTest; +import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext; @@ -43,11 +44,13 @@ public class CreateNetworkCollectionTest extends BaseTaskTest{ private L3Network network; private ServiceInstance serviceInstance; private OrchestrationContext orchestrationContext; + private CloudRegion cloudRegion; @Before public void before() { serviceInstance = setServiceInstance(); network = setL3Network(); + cloudRegion = setCloudRegion(); List l3NetworkList = new ArrayList(); l3NetworkList.add(network); @@ -92,4 +95,11 @@ public class CreateNetworkCollectionTest extends BaseTaskTest{ createNetworkCollection.connectCollectionToServiceInstance(execution); verify(aaiNetworkResources, times(1)).connectNetworkCollectionToServiceInstance(serviceInstance.getCollection(), serviceInstance); } + + @Test + public void connectInstanceGroupToCloudRegionTest() throws Exception { + doNothing().when(aaiNetworkResources).connectInstanceGroupToCloudRegion(serviceInstance.getCollection().getInstanceGroup(), cloudRegion); + createNetworkCollection.connectInstanceGroupToCloudRegion(execution); + verify(aaiNetworkResources, times(1)).connectInstanceGroupToCloudRegion(serviceInstance.getCollection().getInstanceGroup(), cloudRegion); + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java index d86453b87c..db01399b82 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java @@ -280,7 +280,6 @@ public class AAIObjectMapperTest { instanceGroup.setInstanceGroupName("test-instanceGroupName"); instanceGroup.setResourceVersion("test-resourceVersion"); - ModelInfoInstanceGroup model = new ModelInfoInstanceGroup(); model.setFunction("test-function"); model.setInstanceGroupRole("SUB-INTERFACE"); @@ -288,6 +287,7 @@ public class AAIObjectMapperTest { model.setModelInvariantUUID("modelInvariantUUID-000"); model.setModelUUID("modelUUID-000"); model.setDescription("test-description"); + model.setInstanceGroupRole("SUB-INTERFACE"); instanceGroup.setModelInfoInstanceGroup(model); @@ -311,6 +311,7 @@ public class AAIObjectMapperTest { assertEquals(aaiInstanceGroup.getModelVersionId(), instanceGroup.getModelInfoInstanceGroup().getModelUUID()); assertEquals(aaiInstanceGroup.getResourceVersion(), instanceGroup.getResourceVersion()); assertEquals(aaiInstanceGroup.getInstanceGroupType(), instanceGroup.getModelInfoInstanceGroup().getType()); + assertEquals(aaiInstanceGroup.getInstanceGroupRole(), instanceGroup.getModelInfoInstanceGroup().getInstanceGroupRole()); } @Test diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAINetworkResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAINetworkResourcesTest.java index cf270c21a7..bd61424a45 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAINetworkResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAINetworkResourcesTest.java @@ -58,6 +58,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet; import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.AAIEdgeLabel; import org.onap.so.client.aai.entities.AAIResultWrapper; import org.onap.so.client.aai.entities.Relationships; import org.onap.so.client.aai.entities.uri.AAIResourceUri; @@ -330,4 +331,13 @@ public class AAINetworkResourcesTest extends TestDataSetup{ verify(MOCK_aaiResourcesClient, times(1)).update(any(AAIResourceUri.class), isA(org.onap.aai.domain.yang.Subnet.class)); } + + @Test + public void connectInstanceGroupToCloudRegionTest() throws Exception { + aaiNetworkResources.connectInstanceGroupToCloudRegion(instanceGroup, cloudRegion); + verify(MOCK_aaiResourcesClient, times(1)).connect( + eq(AAIUriFactory.createResourceUri(AAIObjectType.INSTANCE_GROUP, instanceGroup.getId())), + eq(AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId())), + eq(AAIEdgeLabel.USES)); + } } diff --git a/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java b/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java index e91dc43af9..87951d516b 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java +++ b/common/src/main/java/org/onap/so/client/aai/AAIResourcesClient.java @@ -269,18 +269,18 @@ public class AAIResourcesClient extends AAIClient { return e; } - private Relationship buildRelationship(AAIResourceUri uri) { + protected Relationship buildRelationship(AAIResourceUri uri) { return buildRelationship(uri, Optional.empty()); } - private Relationship buildRelationship(AAIResourceUri uri, AAIEdgeLabel label) { + protected Relationship buildRelationship(AAIResourceUri uri, AAIEdgeLabel label) { return buildRelationship(uri, Optional.of(label)); } - private Relationship buildRelationship(AAIResourceUri uri, Optional label) { + protected Relationship buildRelationship(AAIResourceUri uri, Optional label) { final Relationship result = new Relationship(); result.setRelatedLink(uri.build().toString()); if (label.isPresent()) { - result.setRelationshipLabel(label.toString()); + result.setRelationshipLabel(label.get().toString()); } return result; } diff --git a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java index 63f8f652ce..22dc1cac30 100644 --- a/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java +++ b/common/src/test/java/org/onap/so/client/aai/AAIResourcesClientTest.java @@ -28,15 +28,18 @@ import static com.github.tomakehurst.wiremock.client.WireMock.post; import static com.github.tomakehurst.wiremock.client.WireMock.put; import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.hamcrest.CoreMatchers.containsString; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import org.onap.aai.domain.yang.Relationship; +import org.onap.so.client.aai.entities.AAIEdgeLabel; import org.onap.so.client.aai.entities.AAIResultWrapper; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; @@ -183,6 +186,21 @@ public class AAIResourcesClientTest { AAIResultWrapper result = client.get(path, NotFoundException.class); } + @Test + public void buildRelationshipTest() { + AAIResourcesClient client = createClient(); + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "test"); + Relationship relationship = new Relationship(); + relationship.setRelatedLink(uri.build().toString()); + Relationship actual = client.buildRelationship(uri); + assertThat("expect equal no label", actual, sameBeanAs(relationship)); + + relationship.setRelationshipLabel(AAIEdgeLabel.USES.toString()); + actual = client.buildRelationship(uri, AAIEdgeLabel.USES); + assertThat("expect equal has label", actual, sameBeanAs(relationship)); + + } + private AAIResourcesClient createClient() { AAIResourcesClient client = spy(new AAIResourcesClient()); doReturn(new DefaultAAIPropertiesImpl()).when(client).getRestProperties(); diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/SubType.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/SubType.java index bc4f07b54b..3230d8427b 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/SubType.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/SubType.java @@ -21,5 +21,14 @@ package org.onap.so.db.catalog.beans; public enum SubType { - SUB_INTERFACE + SUB_INTERFACE("SUB-INTERFACE"); + + private final String value; + SubType(String value){ + this.value = value; + } + @Override + public String toString() { + return this.value; + } } -- cgit 1.2.3-korg