aboutsummaryrefslogtreecommitdiffstats
path: root/bpmn/MSOCommonBPMN/src
diff options
context:
space:
mode:
Diffstat (limited to 'bpmn/MSOCommonBPMN/src')
-rw-r--r--bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java44
-rw-r--r--bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java90
2 files changed, 97 insertions, 37 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java
index 31275f7143..3d5533de32 100644
--- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java
+++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtils.java
@@ -359,7 +359,7 @@ public class BBInputSetupUtils {
}
public Optional<ServiceInstance> getAAIServiceInstanceByName(String globalCustomerId, String serviceType,
- String serviceInstanceName) throws Exception {
+ String serviceInstanceName) throws MultipleObjectsFoundException {
ServiceInstance aaiServiceInstance = null;
ServiceInstances aaiServiceInstances = null;
aaiServiceInstances = getAAIServiceInstancesByName(globalCustomerId, serviceType, serviceInstanceName);
@@ -367,7 +367,10 @@ public class BBInputSetupUtils {
if (aaiServiceInstances == null) {
return Optional.empty();
} else if (aaiServiceInstances.getServiceInstance().size() > 1) {
- throw new Exception("Multiple Service Instances Returned");
+ String message = String.format(
+ "Multiple service instances found for customer-id: %s, service-type: %s and service-instance-name: %s.",
+ globalCustomerId, serviceType, serviceInstanceName);
+ throw new MultipleObjectsFoundException(message);
} else {
aaiServiceInstance = aaiServiceInstances.getServiceInstance().get(0);
}
@@ -472,7 +475,9 @@ public class BBInputSetupUtils {
if (serviceInstances.get().getServiceInstance().isEmpty()) {
throw new NoServiceInstanceFoundException("No ServiceInstances Returned");
} else if (serviceInstances.get().getServiceInstance().size() > 1) {
- throw new MultipleObjectsFoundException("Multiple ServiceInstances Returned");
+ String message = String.format("Mulitple service instances were found for instance-group-id: %s.",
+ instanceGroupId);
+ throw new MultipleObjectsFoundException(message);
} else {
serviceInstance = serviceInstances.get().getServiceInstance().get(0);
}
@@ -481,7 +486,7 @@ public class BBInputSetupUtils {
}
public Optional<L3Network> getRelatedNetworkByNameFromServiceInstance(String serviceInstanceId, String networkName)
- throws Exception {
+ throws MultipleObjectsFoundException {
AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
uri.relatedTo(AAIObjectPlurals.L3_NETWORK).queryParam("network-name", networkName);
Optional<L3Networks> networks = injectionHelper.getAaiClient().get(L3Networks.class, uri);
@@ -491,7 +496,10 @@ public class BBInputSetupUtils {
return Optional.empty();
} else {
if (networks.get().getL3Network().size() > 1) {
- throw new Exception("Multiple Networks Returned");
+ String message =
+ String.format("Multiple networks found for service-instance-id: %s and network-name: %s.",
+ serviceInstanceId, networkName);
+ throw new MultipleObjectsFoundException(message);
} else {
network = networks.get().getL3Network().get(0);
}
@@ -500,7 +508,7 @@ public class BBInputSetupUtils {
}
public Optional<GenericVnf> getRelatedVnfByNameFromServiceInstance(String serviceInstanceId, String vnfName)
- throws Exception {
+ throws MultipleObjectsFoundException {
AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
uri.relatedTo(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName);
Optional<GenericVnfs> vnfs = injectionHelper.getAaiClient().get(GenericVnfs.class, uri);
@@ -510,7 +518,9 @@ public class BBInputSetupUtils {
return Optional.empty();
} else {
if (vnfs.get().getGenericVnf().size() > 1) {
- throw new Exception("Multiple Vnfs Returned");
+ String message = String.format("Multiple vnfs found for service-instance-id: %s and vnf-name: %s.",
+ serviceInstanceId, vnfName);
+ throw new MultipleObjectsFoundException(message);
} else {
vnf = vnfs.get().getGenericVnf().get(0);
}
@@ -519,7 +529,7 @@ public class BBInputSetupUtils {
}
public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVnf(String vnfId, String volumeGroupName)
- throws Exception {
+ throws MultipleObjectsFoundException {
AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP).queryParam("volume-group-name", volumeGroupName);
Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri);
@@ -529,7 +539,9 @@ public class BBInputSetupUtils {
return Optional.empty();
} else {
if (volumeGroups.get().getVolumeGroup().size() > 1) {
- throw new Exception("Multiple VolumeGroups Returned");
+ String message = String.format("Multiple volume-groups found for vnf-id: %s and volume-group-name: %s.",
+ vnfId, volumeGroupName);
+ throw new MultipleObjectsFoundException(message);
} else {
volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
}
@@ -538,7 +550,7 @@ public class BBInputSetupUtils {
}
public Optional<VolumeGroup> getRelatedVolumeGroupByNameFromVfModule(String vnfId, String vfModuleId,
- String volumeGroupName) throws Exception {
+ String volumeGroupName) throws MultipleObjectsFoundException {
AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId);
uri.relatedTo(AAIObjectPlurals.VOLUME_GROUP).queryParam("volume-group-name", volumeGroupName);
Optional<VolumeGroups> volumeGroups = injectionHelper.getAaiClient().get(VolumeGroups.class, uri);
@@ -548,7 +560,10 @@ public class BBInputSetupUtils {
return Optional.empty();
} else {
if (volumeGroups.get().getVolumeGroup().size() > 1) {
- throw new Exception("Multiple VolumeGroups Returned");
+ String message = String.format(
+ "Multiple voulme-groups found for vnf-id: %s, vf-module-id: %s and volume-group-name: %s.",
+ vnfId, vfModuleId, volumeGroupName);
+ throw new MultipleObjectsFoundException(message);
} else {
volumeGroup = volumeGroups.get().getVolumeGroup().get(0);
}
@@ -617,7 +632,7 @@ public class BBInputSetupUtils {
}
public Optional<Configuration> getRelatedConfigurationByNameFromServiceInstance(String serviceInstanceId,
- String configurationName) throws Exception {
+ String configurationName) throws MultipleObjectsFoundException {
AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId);
uri.relatedTo(AAIObjectPlurals.CONFIGURATION).queryParam("configuration-name", configurationName);
Optional<Configurations> configurations = injectionHelper.getAaiClient().get(Configurations.class, uri);
@@ -627,7 +642,10 @@ public class BBInputSetupUtils {
return Optional.empty();
} else {
if (configurations.get().getConfiguration().size() > 1) {
- throw new Exception("Multiple Configurations Returned");
+ String message = String.format(
+ "Multiple configurations found for service-instance-d: %s and configuration-name: %s.",
+ serviceInstanceId, configurationName);
+ throw new MultipleObjectsFoundException(message);
} else {
configuration = configurations.get().getConfiguration().get(0);
}
diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java
index 53d167e4af..2b78690e27 100644
--- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java
+++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupUtilsTest.java
@@ -22,6 +22,7 @@ package org.onap.so.bpmn.servicedecomposition.tasks;
import static com.shazam.shazamcrest.MatcherAssert.assertThat;
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.assertNull;
import static org.mockito.ArgumentMatchers.any;
@@ -480,7 +481,9 @@ public class BBInputSetupUtilsTest {
@Test
public void testGetOptionalAAIServiceInstanceByNameException() throws Exception {
- expectedException.expect(Exception.class);
+ expectedException.expect(MultipleObjectsFoundException.class);
+ expectedException.expectMessage(containsString(
+ "Multiple service instances found for customer-id: globalCustomerId, service-type: serviceType and service-instance-name: serviceInstanceId."));
String globalCustomerId = "globalCustomerId";
String serviceType = "serviceType";
@@ -628,7 +631,9 @@ public class BBInputSetupUtilsTest {
@Test
public void getRelatedNetworkByNameFromServiceInstanceMultipleNetworksExceptionTest() throws Exception {
- expectedException.expect(Exception.class);
+ expectedException.expect(MultipleObjectsFoundException.class);
+ expectedException.expectMessage(containsString(
+ "Multiple networks found for service-instance-id: serviceInstanceId and network-name: networkName."));
String serviceInstanceId = "serviceInstanceId";
String networkName = "networkName";
@@ -637,11 +642,12 @@ public class BBInputSetupUtilsTest {
network.setNetworkId("id123");
network.setNetworkName("name123");
- L3Networks expected = new L3Networks();
- expected.getL3Network().add(network);
- expected.getL3Network().add(network);
+ L3Networks l3Networks = new L3Networks();
+ l3Networks.getL3Network().add(network);
+ l3Networks.getL3Network().add(network);
+ Optional<L3Networks> optNetworks = Optional.of(l3Networks);
- doReturn(expected).when(MOCK_aaiResourcesClient).get(eq(L3Networks.class), any(AAIResourceUri.class));
+ doReturn(optNetworks).when(MOCK_aaiResourcesClient).get(eq(L3Networks.class), any(AAIResourceUri.class));
bbInputSetupUtils.getRelatedNetworkByNameFromServiceInstance(serviceInstanceId, networkName);
}
@@ -711,7 +717,9 @@ public class BBInputSetupUtilsTest {
@Test
public void getRelatedVnfByNameFromServiceInstanceMultipleVnfsExceptionTest() throws Exception {
- expectedException.expect(Exception.class);
+ expectedException.expect(MultipleObjectsFoundException.class);
+ expectedException.expectMessage(containsString(
+ "Multiple vnfs found for service-instance-id: serviceInstanceId and vnf-name: vnfName."));
String serviceInstanceId = "serviceInstanceId";
String vnfName = "vnfName";
@@ -720,11 +728,13 @@ public class BBInputSetupUtilsTest {
vnf.setVnfId("id123");
vnf.setVnfName("name123");
- GenericVnfs expectedVnf = new GenericVnfs();
- expectedVnf.getGenericVnf().add(vnf);
- expectedVnf.getGenericVnf().add(vnf);
+ GenericVnfs vnfs = new GenericVnfs();
+ vnfs.getGenericVnf().add(vnf);
+ vnfs.getGenericVnf().add(vnf);
+
+ Optional<GenericVnfs> optVnfs = Optional.of(vnfs);
- doReturn(expectedVnf).when(MOCK_aaiResourcesClient).get(eq(GenericVnfs.class), any(AAIResourceUri.class));
+ doReturn(optVnfs).when(MOCK_aaiResourcesClient).get(eq(GenericVnfs.class), any(AAIResourceUri.class));
bbInputSetupUtils.getRelatedVnfByNameFromServiceInstance(serviceInstanceId, vnfName);
}
@@ -756,7 +766,10 @@ public class BBInputSetupUtilsTest {
@Test
public void getRelatedVolumeGroupByNameFromVnfMultipleVolumeGroupsExceptionTest() throws Exception {
- expectedException.expect(Exception.class);
+ expectedException.expect(MultipleObjectsFoundException.class);
+ expectedException.expectMessage(containsString(
+ "Multiple volume-groups found for vnf-id: vnfId and volume-group-name: volumeGroupName."));
+
String vnfId = "vnfId";
String volumeGroupName = "volumeGroupName";
@@ -765,12 +778,12 @@ public class BBInputSetupUtilsTest {
volumeGroup.setVolumeGroupId("id123");
volumeGroup.setVolumeGroupName("name123");
- VolumeGroups expectedVolumeGroup = new VolumeGroups();
- expectedVolumeGroup.getVolumeGroup().add(volumeGroup);
- expectedVolumeGroup.getVolumeGroup().add(volumeGroup);
+ VolumeGroups volumeGroups = new VolumeGroups();
+ volumeGroups.getVolumeGroup().add(volumeGroup);
+ volumeGroups.getVolumeGroup().add(volumeGroup);
+ Optional<VolumeGroups> optVolumeGroups = Optional.of(volumeGroups);
- doReturn(expectedVolumeGroup).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class),
- any(AAIResourceUri.class));
+ doReturn(optVolumeGroups).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class));
bbInputSetupUtils.getRelatedVolumeGroupByNameFromVnf(vnfId, volumeGroupName);
}
@@ -803,8 +816,9 @@ public class BBInputSetupUtilsTest {
@Test
public void getRelatedVolumeGroupByNameFromVfModuleMultipleVolumeGroupsExceptionTest() throws Exception {
- expectedException.expect(Exception.class);
-
+ expectedException.expect(MultipleObjectsFoundException.class);
+ expectedException.expectMessage(containsString(
+ "Multiple voulme-groups found for vnf-id: vnfId, vf-module-id: volumeGroupId and volume-group-name: volumeGroupName."));
String vnfId = "vnfId";
String volumeGroupId = "volumeGroupId";
String volumeGroupName = "volumeGroupName";
@@ -813,12 +827,13 @@ public class BBInputSetupUtilsTest {
volumeGroup.setVolumeGroupId("id123");
volumeGroup.setVolumeGroupName("name123");
- VolumeGroups expectedVolumeGroup = new VolumeGroups();
- expectedVolumeGroup.getVolumeGroup().add(volumeGroup);
- expectedVolumeGroup.getVolumeGroup().add(volumeGroup);
+ VolumeGroups volumeGroups = new VolumeGroups();
+ volumeGroups.getVolumeGroup().add(volumeGroup);
+ volumeGroups.getVolumeGroup().add(volumeGroup);
- doReturn(expectedVolumeGroup).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class),
- any(AAIResourceUri.class));
+ Optional<VolumeGroups> optVolumeGroups = Optional.of(volumeGroups);
+
+ doReturn(optVolumeGroups).when(MOCK_aaiResourcesClient).get(eq(VolumeGroups.class), any(AAIResourceUri.class));
bbInputSetupUtils.getRelatedVolumeGroupByNameFromVfModule(vnfId, volumeGroupId, volumeGroupName);
}
@@ -867,6 +882,33 @@ public class BBInputSetupUtilsTest {
}
@Test
+ public void getRelatedConfigurationByNameFromServiceInstanceExceptionTest() throws Exception {
+ Configuration configuration = new Configuration();
+ configuration.setConfigurationId("id123");
+
+ Configurations configurations = new Configurations();
+ configurations.getConfiguration().add(configuration);
+ configurations.getConfiguration().add(configuration);
+
+ Optional<Configurations> optConfigurations = Optional.of(configurations);
+
+ doReturn(optConfigurations).when(MOCK_aaiResourcesClient).get(eq(Configurations.class),
+ any(AAIResourceUri.class));
+
+ expectedException.expect(MultipleObjectsFoundException.class);
+ this.bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance("id123", "name123");
+ }
+
+ @Test
+ public void getRelatedConfigurationByNameFromServiceInstanceNotFoundTest() throws Exception {
+ doReturn(Optional.empty()).when(MOCK_aaiResourcesClient).get(eq(Configurations.class),
+ any(AAIResourceUri.class));
+ Optional<Configuration> actualConfiguration =
+ bbInputSetupUtils.getRelatedConfigurationByNameFromServiceInstance("id123", "name123");
+ assertEquals(actualConfiguration, Optional.empty());
+ }
+
+ @Test
public void getRelatedConfigurationByNameFromServiceInstanceTest() throws Exception {
Optional<Configurations> expected = Optional.of(new Configurations());
Configuration configuration = new Configuration();