aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareModelofE2EServiceInstance.groovy6
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy4
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteServiceInstance.groovy8
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateCustomE2EServiceInstance.groovy8
-rw-r--r--common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java24
-rw-r--r--common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java19
6 files changed, 44 insertions, 25 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareModelofE2EServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareModelofE2EServiceInstance.groovy
index 3702862a04..589bbe9c4f 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareModelofE2EServiceInstance.groovy
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCompareModelofE2EServiceInstance.groovy
@@ -140,9 +140,9 @@ public class DoCompareModelofE2EServiceInstance extends AbstractServiceTaskProce
AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
- ServiceInstance si = wrapper.asBean(ServiceInstance.class)
- execution.setVariable("model-invariant-id-original", si.getModelInvariantId())
- execution.setVariable("model-version-id-original", si.getModelVersionId())
+ Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
+ execution.setVariable("model-invariant-id-original", si.get().getModelInvariantId())
+ execution.setVariable("model-version-id-original", si.get().getModelVersionId())
}catch(BpmnError e) {
throw e;
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy
index 4939173d65..913970b051 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateE2EServiceInstance.groovy
@@ -319,8 +319,8 @@ public class DoCreateE2EServiceInstance extends AbstractServiceTaskProcessor {
AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
- ServiceInstance si = wrapper.asBean(ServiceInstance.class)
- execution.setVariable("serviceInstanceName", si.getServiceInstanceName())
+ Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
+ execution.setVariable("serviceInstanceName", si.get().getServiceInstanceName())
}catch(BpmnError e) {
throw e;
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteServiceInstance.groovy
index c7e3eb437c..a79483f6e9 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteServiceInstance.groovy
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteServiceInstance.groovy
@@ -310,11 +310,11 @@ public class DoDeleteServiceInstance extends AbstractServiceTaskProcessor {
uriList.addAll(wrapper.getRelationships().get().getRelatedAAIUris(AAIObjectType.L3_NETWORK))
if(uriList.isEmpty){
- ServiceInstance si = wrapper.asBean(ServiceInstance.class)
- String orchestrationStatus = si.getOrchestrationStatus()
- String serviceType = si.getServiceType()
+ Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
+ String orchestrationStatus = si.get().getOrchestrationStatus()
+ String serviceType = si.get().getServiceType()
execution.setVariable("serviceType", serviceType)
- execution.setVariable("serviceRole", si.getServiceRole())
+ execution.setVariable("serviceRole", si.get().getServiceRole())
if("TRANSPORT".equalsIgnoreCase(serviceType)){
if("PendingDelete".equals(orchestrationStatus)){
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateCustomE2EServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateCustomE2EServiceInstance.groovy
index ac8e506e1f..20ced72002 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateCustomE2EServiceInstance.groovy
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/UpdateCustomE2EServiceInstance.groovy
@@ -177,10 +177,10 @@ public class UpdateCustomE2EServiceInstance extends AbstractServiceTaskProcessor
AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, globalSubscriberId, serviceType, serviceInstanceId)
AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class)
- ServiceInstance si = wrapper.asBean(ServiceInstance.class)
- execution.setVariable("serviceInstanceName", si.getServiceInstanceName())
- execution.setVariable("model-invariant-id-original", si.getModelInvariantId())
- execution.setVariable("model-version-id-original", si.getModelVersionId())
+ Optional<ServiceInstance> si = wrapper.asBean(ServiceInstance.class)
+ execution.setVariable("serviceInstanceName", si.get().getServiceInstanceName())
+ execution.setVariable("model-invariant-id-original", si.get().getModelInvariantId())
+ execution.setVariable("model-version-id-original", si.get().getModelVersionId())
JSONObject ob = new JSONObject(wrapper.getJson())
JSONArray ar = ob.getJSONObject("relationship-list").getJSONArray("relationship")
diff --git a/common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java b/common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java
index 9087995f97..36e67e2e09 100644
--- a/common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java
+++ b/common/src/main/java/org/onap/so/client/aai/entities/AAIResultWrapper.java
@@ -35,19 +35,19 @@ import com.fasterxml.jackson.databind.ObjectMapper;
public class AAIResultWrapper implements Serializable {
private static final long serialVersionUID = 5895841925807816737L;
- private final Optional<String> jsonBody;
+ private final String jsonBody;
private final ObjectMapper mapper;
public AAIResultWrapper(String json) {
- this.jsonBody = Optional.ofNullable(json);
+ this.jsonBody = json;
this.mapper = new AAICommonObjectMapperProvider().getMapper();
}
public Optional<Relationships> getRelationships() {
final String path = "$.relationship-list";
- if (!jsonBody.isPresent()) {
+ if (isEmpty()) {
return Optional.empty();
}
- Optional<String> result = JsonPathUtil.getInstance().locateResult(jsonBody.get(), path);
+ Optional<String> result = JsonPathUtil.getInstance().locateResult(jsonBody, path);
if (result.isPresent()) {
return Optional.of(new Relationships(result.get()));
} else {
@@ -56,33 +56,37 @@ public class AAIResultWrapper implements Serializable {
}
public String getJson() {
- return jsonBody.orElse("{}");
+ if(jsonBody == null) {
+ return "{}";
+ } else {
+ return jsonBody;
+ }
}
public Map<String, Object> asMap() {
- if (!this.jsonBody.isPresent()) {
+ if (isEmpty()) {
return new HashMap<>();
}
try {
- return mapper.readValue(this.jsonBody.get(), new TypeReference<Map<String, Object>>(){});
+ return mapper.readValue(this.jsonBody, new TypeReference<Map<String, Object>>(){});
} catch (IOException e) {
return new HashMap<>();
}
}
public <T> Optional<T> asBean(Class<T> clazz) {
- if (!this.jsonBody.isPresent()) {
+ if (isEmpty()) {
return Optional.empty();
}
try {
- return Optional.of(mapper.readValue(this.jsonBody.get(), clazz));
+ return Optional.of(mapper.readValue(this.jsonBody, clazz));
} catch (IOException e) {
return Optional.empty();
}
}
public boolean isEmpty() {
- return !this.jsonBody.isPresent();
+ return jsonBody == null;
}
@Override
public String toString() {
diff --git a/common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java b/common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java
index ff940a0dea..e40c25a2e2 100644
--- a/common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java
+++ b/common/src/test/java/org/onap/so/client/aai/entities/AAIResultWrapperTest.java
@@ -20,9 +20,10 @@
package org.onap.so.client.aai.entities;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
import java.io.IOException;
+import java.io.Serializable;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
@@ -30,11 +31,15 @@ import java.util.Map;
import java.util.Optional;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.aai.domain.yang.GenericVnf;
import org.onap.so.client.aai.AAICommonObjectMapperProvider;
+import org.springframework.util.SerializationUtils;
+
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonMappingException;
@@ -43,7 +48,9 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@RunWith(MockitoJUnitRunner.class)
public class AAIResultWrapperTest {
String json;
-
+ @Rule
+ public ExpectedException thrown= ExpectedException.none();
+
AAIResultWrapper aaiResultWrapper;
AAIResultWrapper aaiResultWrapperEmpty;
@@ -57,6 +64,14 @@ public class AAIResultWrapperTest {
}
@Test
+ public void testAAIResultWrapperIsSerializable() throws IOException {
+ AAIResultWrapper original = new AAIResultWrapper("");
+ byte[] serialized = SerializationUtils.serialize(original);
+ AAIResultWrapper deserialized = (AAIResultWrapper) SerializationUtils.deserialize(serialized);
+ assertEquals(deserialized.getJson(), original.getJson());
+ }
+
+ @Test
public void testGetRelationshipsEmpty() {
Optional<Relationships> relationships = aaiResultWrapperEmpty.getRelationships();
assertEquals("Compare relationships", Optional.empty(), relationships);