aboutsummaryrefslogtreecommitdiffstats
path: root/common/src
diff options
context:
space:
mode:
authorPlummer, Brittany <brittany.plummer@att.com>2019-05-31 15:56:32 -0400
committerBenjamin, Max (mb388a) <mb388a@us.att.com>2019-05-31 15:56:44 -0400
commita8e40692a53109fde1eb6e977947db907a611287 (patch)
treebb070e9203b971784212f18560ccf6d206dd8033 /common/src
parent89b396152a7f5ca62175d13342c1b3a1a9067ccb (diff)
apih resume request handling more generic
getInstanceName throws exception if requestScope doesn't match modelType Updated to combine separate return statements Replaced if statements for modelType and added tests Replace if statements for modelType in ResumeOrchestrationRequest and added tests Added coverage for setId in ModelType Updated to use ModelType setters/getters model type can now get and set generically Added modelInfo to RequestBody for resume request Added getModelType call and unit tests Moved getModelType from ServiceInstances Moved getModelType and added unit tests Added tests for getIsBaseVfModule Added more tests for isBaseVfModule Began adding tests for getIsBaseVfModule Updated currentActiveRequest creation and isBaseVfModule Updated recipe lookup and setting of aLaCarte to be more general Updated concurrency control to include other resources Change-Id: I12ad011d0a021c3ee066e16b4c8a4526d040cbe3 Issue-ID: SO-1963 Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'common/src')
-rw-r--r--common/src/main/java/org/onap/so/serviceinstancebeans/ModelType.java77
-rw-r--r--common/src/test/java/org/onap/so/serviceinstancebeans/ModelTypeTest.java38
-rw-r--r--common/src/test/java/org/onap/so/serviceinstancebeans/TestServiceInstanceBean.java24
3 files changed, 129 insertions, 10 deletions
diff --git a/common/src/main/java/org/onap/so/serviceinstancebeans/ModelType.java b/common/src/main/java/org/onap/so/serviceinstancebeans/ModelType.java
index 11cd3d42b7..34edf91c0c 100644
--- a/common/src/main/java/org/onap/so/serviceinstancebeans/ModelType.java
+++ b/common/src/main/java/org/onap/so/serviceinstancebeans/ModelType.java
@@ -20,18 +20,75 @@
package org.onap.so.serviceinstancebeans;
+import java.lang.reflect.InvocationTargetException;
+import com.google.common.base.CaseFormat;
+
/*
* Enum for Model Type values returned by API Handler to BPMN
*/
public enum ModelType {
- service,
- vnf,
- vfModule,
- volumeGroup,
- network,
- configuration,
- connectionPoint,
- pnf,
- networkInstanceGroup,
- instanceGroup
+ service("serviceInstance"),
+ vnf("vnf"),
+ vfModule("vfModule"),
+ volumeGroup("volumeGroup"),
+ network("network"),
+ configuration("configuration"),
+ connectionPoint("connectionPoint"),
+ pnf("pnf"),
+ networkInstanceGroup("networkInstanceGroup"),
+ instanceGroup("instanceGroup");
+
+ final String name;
+
+ private ModelType(String name) {
+ this.name = name;
+ }
+
+
+ public <T> T getId(Object obj) {
+ return this.get(obj, "Id");
+ }
+
+ public <T> T getName(Object obj) {
+ return this.get(obj, "Name");
+ }
+
+ public void setId(Object obj, Object value) {
+ this.set(obj, "Id", value);
+ }
+
+ public void setName(Object obj, Object value) {
+ this.set(obj, "Name", value);
+ }
+
+ protected <T> T get(Object obj, String field) {
+ T result = null;
+ if (obj != null) {
+ try {
+ result = (T) obj.getClass().getMethod(String.format("%s%s%s", "get",
+ CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, this.name), field)).invoke(obj);
+ } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException
+ | NoSuchMethodException | SecurityException e) {
+ // silent fail
+ }
+ }
+
+ return result;
+ }
+
+ protected void set(Object obj, String field, Object value) {
+ if (obj != null) {
+ try {
+ obj.getClass()
+ .getMethod(
+ String.format("%s%s%s", "set",
+ CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, this.name), field),
+ value.getClass())
+ .invoke(obj, value);
+ } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
+ | InvocationTargetException e) {
+ // silent fail
+ }
+ }
+ }
}
diff --git a/common/src/test/java/org/onap/so/serviceinstancebeans/ModelTypeTest.java b/common/src/test/java/org/onap/so/serviceinstancebeans/ModelTypeTest.java
new file mode 100644
index 0000000000..e4b694cd15
--- /dev/null
+++ b/common/src/test/java/org/onap/so/serviceinstancebeans/ModelTypeTest.java
@@ -0,0 +1,38 @@
+package org.onap.so.serviceinstancebeans;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import org.junit.Test;
+
+public class ModelTypeTest {
+
+
+
+ @Test
+ public void reflectionTest() {
+ TestServiceInstanceBean a = new TestServiceInstanceBean();
+ TestServiceInstanceBean b = new TestServiceInstanceBean();
+
+ a.setServiceInstanceId("my-id-a");
+ a.setServiceInstanceName("my-name-a");
+
+ b.setServiceInstanceId("my-id-b");
+ b.setServiceInstanceName("my-name-b");
+
+ assertEquals("my-id-a", ModelType.service.getId(a));
+ assertEquals("my-name-a", ModelType.service.getName(a));
+ ModelType.service.setName(a, ModelType.service.getName(b));
+ ModelType.service.setId(a, ModelType.service.getId(b));
+ assertEquals("my-name-b", ModelType.service.getName(a));
+ assertEquals("my-id-b", ModelType.service.getId(a));
+ }
+
+ @Test
+ public void testSilentFail() {
+ TestServiceInstanceBean a = new TestServiceInstanceBean();
+
+ a.setServiceInstanceId("my-id-a");
+ a.setServiceInstanceName("my-name-a");
+ assertNull(ModelType.service.get(a, "NoField"));
+ }
+}
diff --git a/common/src/test/java/org/onap/so/serviceinstancebeans/TestServiceInstanceBean.java b/common/src/test/java/org/onap/so/serviceinstancebeans/TestServiceInstanceBean.java
new file mode 100644
index 0000000000..b8cf6141e3
--- /dev/null
+++ b/common/src/test/java/org/onap/so/serviceinstancebeans/TestServiceInstanceBean.java
@@ -0,0 +1,24 @@
+package org.onap.so.serviceinstancebeans;
+
+public class TestServiceInstanceBean {
+
+ private String serviceInstanceId;
+ private String serviceInstanceName;
+
+ public String getServiceInstanceId() {
+ return serviceInstanceId;
+ }
+
+ public void setServiceInstanceId(String serviceInstanceId) {
+ this.serviceInstanceId = serviceInstanceId;
+ }
+
+ public String getServiceInstanceName() {
+ return serviceInstanceName;
+ }
+
+ public void setServiceInstanceName(String serviceInstanceName) {
+ this.serviceInstanceName = serviceInstanceName;
+ }
+
+}