summaryrefslogtreecommitdiffstats
path: root/bpmn
diff options
context:
space:
mode:
authork.kazak <k.kazak@samsung.com>2019-04-08 11:48:16 +0200
committerk.kazak <k.kazak@samsung.com>2019-04-08 11:48:16 +0200
commit70ff098fd488850655ad7ac98ad06712f0340552 (patch)
tree5ed781d5800db7b8a19e9fe1bb288fb58d18f758 /bpmn
parent2c8c818a1815758e14e88fe74b782c3e8be8ac4b (diff)
fix sonar bugs in ServicePluginFactory
Fixed potential NullPointerException in lines: 123, 286, 480 and 607 - uuiObject is nullable here Change-Id: I01b30d090add7faccf3958f2fa37c7905d4bd5a3 Issue-ID: SO-1490 Signed-off-by: k.kazak <k.kazak@samsung.com>
Diffstat (limited to 'bpmn')
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java255
-rw-r--r--bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactoryTest.java187
2 files changed, 326 insertions, 116 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java
index 113f05d3ca..9b878afb7c 100644
--- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java
+++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java
@@ -22,15 +22,18 @@
package org.onap.so.bpmn.infrastructure.workflow.service;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.SerializationFeature;
import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
-
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
@@ -68,17 +71,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.util.UriUtils;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
-
public class ServicePluginFactory {
// SOTN calculate route
public static final String OOF_DEFAULT_ENDPOINT = "http://192.168.1.223:8443/oof/sotncalc";
public static final String THIRD_SP_DEFAULT_ENDPOINT = "http://192.168.1.223:8443/sp/resourcemgr/querytps";
-
+
public static final String INVENTORY_OSS_DEFAULT_ENDPOINT = "http://192.168.1.199:8443/oss/inventory";
private static final int DEFAULT_TIME_OUT = 60000;
@@ -88,7 +87,7 @@ public class ServicePluginFactory {
private static Logger logger = LoggerFactory.getLogger(ServicePluginFactory.class);
private static ServicePluginFactory instance;
-
+
public static synchronized ServicePluginFactory getInstance() {
if (null == instance) {
@@ -100,11 +99,11 @@ public class ServicePluginFactory {
private ServicePluginFactory() {
}
-
+
private String getInventoryOSSEndPoint(){
return UrnPropertiesReader.getVariable("mso.service-plugin.inventory-oss-endpoint", INVENTORY_OSS_DEFAULT_ENDPOINT);
}
-
+
private String getThirdSPEndPoint(){
return UrnPropertiesReader.getVariable("mso.service-plugin.third-sp-endpoint", THIRD_SP_DEFAULT_ENDPOINT);
}
@@ -118,18 +117,23 @@ public class ServicePluginFactory {
if(!isNeedProcessSite(uuiRequest)) {
return uuiRequest;
}
-
- Map<String, Object> uuiObject = getJsonObject(uuiRequest, Map.class);
- Map<String, Object> serviceObject = (Map<String, Object>) uuiObject.get("service");
- Map<String, Object> serviceParametersObject = (Map<String, Object>) serviceObject.get("parameters");
- Map<String, Object> serviceRequestInputs = (Map<String, Object>) serviceParametersObject.get("requestInputs");
- List<Object> resources = (List<Object>) serviceParametersObject.get("resources");
-
- if (isSiteLocationLocal(serviceRequestInputs, resources)) {
- // resources changed : added TP info
- String newRequest = getJsonString(uuiObject);
- return newRequest;
- }
+
+ Map<String, Object> uuiObject = getJsonObject(uuiRequest, Map.class);
+ if (uuiObject == null) {
+ return uuiRequest;
+ }
+ Map<String, Object> serviceObject = (Map<String, Object>) uuiObject
+ .getOrDefault("service", Collections.emptyMap());
+ Map<String, Object> serviceParametersObject = (Map<String, Object>) serviceObject
+ .getOrDefault("parameters", Collections.emptyMap());
+ Map<String, Object> serviceRequestInputs = (Map<String, Object>) serviceParametersObject
+ .getOrDefault("requestInputs", Collections.emptyMap());
+ List<Object> resources = (List<Object>) serviceParametersObject.getOrDefault("resources", Collections.emptyList());
+
+ if (isSiteLocationLocal(serviceRequestInputs, resources)) {
+ // resources changed : added TP info
+ return getJsonString(uuiObject);
+ }
List<Resource> addResourceList = new ArrayList<>();
addResourceList.addAll(serviceDecomposition.getServiceResources());
@@ -155,9 +159,9 @@ public class ServicePluginFactory {
}
@SuppressWarnings("unchecked")
- private boolean isSiteLocationLocal(Map<String, Object> serviceRequestInputs, List<Object> resources) {
- Map<String, Object> tpInfoMap = getTPforVPNAttachment(serviceRequestInputs);
-
+ private boolean isSiteLocationLocal(Map<String, Object> serviceRequestInputs, List<Object> resources) {
+ Map<String, Object> tpInfoMap = getTPforVPNAttachment(serviceRequestInputs);
+
if(tpInfoMap.isEmpty()) {
return true;
}
@@ -166,7 +170,7 @@ public class ServicePluginFactory {
if (!host.isEmpty()) {
return false;
}
-
+
Map<String, Object> accessTPInfo = new HashMap<String, Object>();
accessTPInfo.put("access-provider-id", tpInfoMap.get("access-provider-id"));
accessTPInfo.put("access-client-id", tpInfoMap.get("access-client-id"));
@@ -180,7 +184,7 @@ public class ServicePluginFactory {
Map<String, Object> resource = (Map<String, Object>)curResource;
String curResourceName = (String) resource.get("resourceName");
curResourceName = curResourceName.replaceAll(" ", "");
- if(resourceName.equalsIgnoreCase(curResourceName)) {
+ if(resourceName.equalsIgnoreCase(curResourceName)) {
putResourceRequestInputs(resource, accessTPInfo);
break;
}
@@ -188,7 +192,7 @@ public class ServicePluginFactory {
return true;
}
-
+
@SuppressWarnings("unchecked")
private Map<String, Object> getTPforVPNAttachment(Map<String, Object> serviceRequestInputs) {
Object location = null;
@@ -199,24 +203,24 @@ public class ServicePluginFactory {
// logic for R2 uuiRequest params in service level
for (Entry<String, Object> entry : serviceRequestInputs.entrySet()) {
String key = entry.getKey();
- if (key.toLowerCase().contains("site_address")) {
+ if (key.toLowerCase().contains("site_address")) {
location = entry.getValue();
- }
- if (key.toLowerCase().contains("sotncondition_clientsignal")) {
+ }
+ if (key.toLowerCase().contains("sotncondition_clientsignal")) {
clientSignal = entry.getValue();
vpnAttachmentResourceName = key.substring(0, key.indexOf("_"));
}
}
Map<String, Object> tpInfoMap = new HashMap<String, Object>();
-
+
// Site resource has location param and SOTNAttachment resource has clientSignal param
if(location == null || clientSignal == null ) {
return tpInfoMap;
}
-
- // Query terminal points from InventoryOSS system by location.
- String locationAddress = (String) location;
+
+ // Query terminal points from InventoryOSS system by location.
+ String locationAddress = (String) location;
List<Object> locationTPList = queryAccessTPbyLocationFromInventoryOSS(locationAddress);
if(locationTPList != null && !locationTPList.isEmpty()) {
for(Object tp: locationTPList) {
@@ -232,10 +236,10 @@ public class ServicePluginFactory {
logger.debug("Get Terminal TP from InventoryOSS");
return tpInfoMap;
}
-
+
return tpInfoMap;
}
-
+
@SuppressWarnings("unchecked")
private List<Object> queryAccessTPbyLocationFromInventoryOSS(String locationAddress) {
String url = getInventoryOSSEndPoint();
@@ -247,7 +251,7 @@ public class ServicePluginFactory {
}
return accessTPs;
}
-
+
@SuppressWarnings("unchecked")
private void putResourceRequestInputs(Map<String, Object> resource, Map<String, Object> resourceInputs) {
Map<String, Object> resourceParametersObject = new HashMap<>();
@@ -260,7 +264,7 @@ public class ServicePluginFactory {
if(resParametersObject.containsKey("requestInputs")) {
Map<String, Object> resRequestInputs = (Map<String, Object>) resourceRequestInputs.get("requestInputs");
Map<String, Object> oldRequestInputs = (Map<String, Object>) resParametersObject.get("requestInputs");
- if(oldRequestInputs != null) {
+ if(oldRequestInputs != null) {
oldRequestInputs.putAll(resRequestInputs);
}
else {
@@ -268,7 +272,7 @@ public class ServicePluginFactory {
}
}
else {
- resParametersObject.putAll(resourceRequestInputs);
+ resParametersObject.putAll(resourceRequestInputs);
}
}
else {
@@ -277,24 +281,29 @@ public class ServicePluginFactory {
return;
}
-
-
+
+
@SuppressWarnings("unchecked")
- public String doTPResourcesAllocation(DelegateExecution execution, String uuiRequest) {
- Map<String, Object> uuiObject = getJsonObject(uuiRequest, Map.class);
- Map<String, Object> serviceObject = (Map<String, Object>) uuiObject.get("service");
- Map<String, Object> serviceParametersObject = (Map<String, Object>) serviceObject.get("parameters");
- Map<String, Object> serviceRequestInputs = (Map<String, Object>) serviceParametersObject.get("requestInputs");
-
- if(!isNeedAllocateCrossTPResources(serviceRequestInputs)) {
- return uuiRequest;
- }
-
- allocateCrossTPResources(execution, serviceRequestInputs);
- String newRequest = getJsonString(uuiObject);
- return newRequest;
- }
+ public String doTPResourcesAllocation(DelegateExecution execution, String uuiRequest) {
+ Map<String, Object> uuiObject = getJsonObject(uuiRequest, Map.class);
+ if (uuiObject == null) {
+ return uuiRequest;
+ }
+ Map<String, Object> serviceObject = (Map<String, Object>) uuiObject
+ .getOrDefault("service", Collections.emptyMap());
+ Map<String, Object> serviceParametersObject = (Map<String, Object>) serviceObject
+ .getOrDefault("parameters", Collections.emptyMap());
+ Map<String, Object> serviceRequestInputs = (Map<String, Object>) serviceParametersObject
+ .getOrDefault("requestInputs", Collections.emptyMap());
+
+ if (!isNeedAllocateCrossTPResources(serviceRequestInputs)) {
+ return uuiRequest;
+ }
+
+ allocateCrossTPResources(execution, serviceRequestInputs);
+ return getJsonString(uuiObject);
+ }
@SuppressWarnings("unchecked")
private boolean isNeedAllocateCrossTPResources(Map<String, Object> serviceRequestInputs) {
@@ -303,7 +312,7 @@ public class ServicePluginFactory {
String callSource = (String) serviceRequestInputs.get("CallSource");
if("ExternalAPI".equalsIgnoreCase(callSource)) {
return false;
- }
+ }
}
for (String input : serviceRequestInputs.keySet())
{
@@ -313,12 +322,12 @@ public class ServicePluginFactory {
}
return false;
}
-
+
@SuppressWarnings("unchecked")
private void allocateCrossTPResources(DelegateExecution execution, Map<String, Object> serviceRequestInputs) {
Map<String, Object> crossTPs = this.getTPsfromAAI();
-
+
if(crossTPs == null || crossTPs.isEmpty()) {
serviceRequestInputs.put("local-access-provider-id", "");
serviceRequestInputs.put("local-access-client-id", "");
@@ -329,7 +338,7 @@ public class ServicePluginFactory {
serviceRequestInputs.put("remote-access-client-id", "");
serviceRequestInputs.put("remote-access-topology-id", "");
serviceRequestInputs.put("remote-access-node-id", "");
- serviceRequestInputs.put("remote-access-ltp-id", "");
+ serviceRequestInputs.put("remote-access-ltp-id", "");
}
else {
serviceRequestInputs.put("local-access-provider-id", crossTPs.get("local-access-provider-id"));
@@ -343,24 +352,24 @@ public class ServicePluginFactory {
serviceRequestInputs.put("remote-access-node-id", crossTPs.get("remote-node-id"));
serviceRequestInputs.put("remote-access-ltp-id", crossTPs.get("remote-ltp-id"));
}
-
+
return;
}
- // This method returns Local and remote TPs information from AAI
+ // This method returns Local and remote TPs information from AAI
public Map getTPsfromAAI() {
Map<String, Object> tpInfo = new HashMap<>();
-
+
AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.LOGICAL_LINK);
AAIResourcesClient client = new AAIResourcesClient();
Optional<LogicalLinks> result = client.get(LogicalLinks.class, uri);
-
+
if (result.isPresent()) {
LogicalLinks links = result.get();
boolean isRemoteLink = false;
-
+
links.getLogicalLink();
-
+
for (LogicalLink link : links.getLogicalLink()) {
AAIResultWrapper wrapper = new AAIResultWrapper(link);
Optional<Relationships> optRelationships = wrapper.getRelationships();
@@ -372,7 +381,7 @@ public class ServicePluginFactory {
}
pInterfaces.addAll(relationships.getRelatedAAIUris(AAIObjectType.P_INTERFACE));
}
-
+
if (isRemoteLink) {
// find remote p interface
AAIResourceUri localTP = null;
@@ -393,7 +402,7 @@ public class ServicePluginFactory {
String tpUrl = localTP.build().toString();
PInterface intfLocal = client.get(PInterface.class, localTP).get();
tpInfo.put("local-access-node-id", tpUrl.split("/")[6]);
-
+
String[] networkRef = intfLocal.getNetworkRef().split("/");
if (networkRef.length == 6) {
tpInfo.put("local-access-provider-id", networkRef[1]);
@@ -404,7 +413,7 @@ public class ServicePluginFactory {
if (ltpIdStr.contains("-")) {
tpInfo.put("local-access-ltp-id", ltpIdStr.substring(ltpIdStr.lastIndexOf("-") + 1));
}
-
+
// give remote tp
tpUrl = remoteTP.build().toString();
PInterface intfRemote = client.get(PInterface.class, remoteTP).get();
@@ -431,7 +440,7 @@ public class ServicePluginFactory {
// this method check if pInterface is remote
private boolean isRemotePInterface(AAIResourcesClient client, AAIResourceUri uri) {
-
+
String uriString = uri.build().toString();
if (uriString != null) {
@@ -447,7 +456,7 @@ public class ServicePluginFactory {
return !relationships.getRelatedAAIUris(AAIObjectType.EXT_AAI_NETWORK).isEmpty();
}
}
-
+
return false;
}
@@ -475,12 +484,19 @@ public class ServicePluginFactory {
return uuiRequest.contains("clientSignal") && uuiRequest.contains("vpnType");
}
+ @SuppressWarnings("unchecked")
private String preProcessSOTNService(ServiceDecomposition serviceDecomposition, String uuiRequest) {
Map<String, Object> uuiObject = getJsonObject(uuiRequest, Map.class);
- Map<String, Object> serviceObject = (Map<String, Object>) uuiObject.get("service");
- Map<String, Object> serviceParametersObject = (Map<String, Object>) serviceObject.get("parameters");
- Map<String, Object> serviceRequestInputs = (Map<String, Object>) serviceParametersObject.get("requestInputs");
- List<Object> resources = (List<Object>) serviceParametersObject.get("resources");
+ if (uuiObject == null) {
+ return uuiRequest;
+ }
+ Map<String, Object> serviceObject = (Map<String, Object>) uuiObject
+ .getOrDefault("service", Collections.emptyMap());
+ Map<String, Object> serviceParametersObject = (Map<String, Object>) serviceObject
+ .getOrDefault("parameters", Collections.emptyMap());
+ Map<String, Object> serviceRequestInputs = (Map<String, Object>) serviceParametersObject
+ .getOrDefault("requestInputs", Collections.emptyMap());
+ List<Object> resources = (List<Object>) serviceParametersObject.getOrDefault("resources", Collections.emptyList());
// This is a logic for demo , it could not be finalized to community.
String srcLocation = "";
String dstLocation = "";
@@ -534,7 +550,7 @@ public class ServicePluginFactory {
vpnRequestInputs.put("src-client-signal", srcClientSignal);
vpnRequestInputs.put("dst-client-signal", dstClientSignal);
}
-
+
// Now we need to query terminal points from SP resourcemgr system.
List<Object> locationTerminalPointList = queryTerminalPointsFromServiceProviderSystem(srcLocation, dstLocation);
@@ -589,54 +605,61 @@ public class ServicePluginFactory {
}
return null;
}
-
+
public static void main(String args[]){
String str = "restconf/config/GENERIC-RESOURCE-API:services/service/eca7e542-12ba-48de-8544-fac59303b14e/service-data/networks/network/aec07806-1671-4af2-b722-53c8e320a633/network-data/";
-
+
int index1 = str.indexOf("/network/");
int index2 = str.indexOf("/network-data");
-
+
String str1 = str.substring(index1 + "/network/".length(), index2);
System.out.println(str1);
-
+
}
- private String doSOTNServiceHoming(ServiceDecomposition serviceDecomposition, String uuiRequest) {
- // query the route for the service.
- Map<String, Object> uuiObject = getJsonObject(uuiRequest, Map.class);
- Map<String, Object> serviceObject = (Map<String, Object>) uuiObject.get("service");
- Map<String, Object> serviceParametersObject = (Map<String, Object>) serviceObject.get("parameters");
- Map<String, Object> serviceRequestInputs = (Map<String, Object>) serviceParametersObject.get("requestInputs");
- Map<String, Object> oofQueryObject = new HashMap<>();
- List<Object> resources = (List<Object>) serviceParametersObject.get("resources");
- oofQueryObject.put("src-access-provider-id", serviceRequestInputs.get("inner-src-access-provider-id"));
- oofQueryObject.put("src-access-client-id", serviceRequestInputs.get("inner-src-access-client-id"));
- oofQueryObject.put("src-access-topology-id", serviceRequestInputs.get("inner-src-access-topology-id"));
- oofQueryObject.put("src-access-node-id", serviceRequestInputs.get("inner-src-access-node-id"));
- oofQueryObject.put("src-access-ltp-id", serviceRequestInputs.get("inner-src-access-ltp-id"));
- oofQueryObject.put("dst-access-provider-id", serviceRequestInputs.get("inner-dst-access-provider-id"));
- oofQueryObject.put("dst-access-client-id", serviceRequestInputs.get("inner-dst-access-client-id"));
- oofQueryObject.put("dst-access-topology-id", serviceRequestInputs.get("inner-dst-access-topology-id"));
- oofQueryObject.put("dst-access-node-id", serviceRequestInputs.get("inner-dst-access-node-id"));
- oofQueryObject.put("dst-access-ltp-id", serviceRequestInputs.get("inner-dst-access-ltp-id"));
- String oofRequestReq = getJsonString(oofQueryObject);
- String url = getOOFCalcEndPoint();
- String responseContent = sendRequest(url, "POST", oofRequestReq);
+ @SuppressWarnings("unchecked")
+ private String doSOTNServiceHoming(ServiceDecomposition serviceDecomposition, String uuiRequest) {
+ // query the route for the service.
+ Map<String, Object> uuiObject = getJsonObject(uuiRequest, Map.class);
+ if (uuiObject == null) {
+ return uuiRequest;
+ }
+ Map<String, Object> serviceObject = (Map<String, Object>) uuiObject
+ .getOrDefault("service", Collections.emptyMap());
+ Map<String, Object> serviceParametersObject = (Map<String, Object>) serviceObject
+ .getOrDefault("parameters", Collections.emptyMap());
+ Map<String, Object> serviceRequestInputs = (Map<String, Object>) serviceParametersObject
+ .getOrDefault("requestInputs", Collections.emptyMap());
+ Map<String, Object> oofQueryObject = new HashMap<>();
+ List<Object> resources = (List<Object>) serviceParametersObject
+ .getOrDefault("resources", Collections.emptyList());
+ oofQueryObject.put("src-access-provider-id", serviceRequestInputs.get("inner-src-access-provider-id"));
+ oofQueryObject.put("src-access-client-id", serviceRequestInputs.get("inner-src-access-client-id"));
+ oofQueryObject.put("src-access-topology-id", serviceRequestInputs.get("inner-src-access-topology-id"));
+ oofQueryObject.put("src-access-node-id", serviceRequestInputs.get("inner-src-access-node-id"));
+ oofQueryObject.put("src-access-ltp-id", serviceRequestInputs.get("inner-src-access-ltp-id"));
+ oofQueryObject.put("dst-access-provider-id", serviceRequestInputs.get("inner-dst-access-provider-id"));
+ oofQueryObject.put("dst-access-client-id", serviceRequestInputs.get("inner-dst-access-client-id"));
+ oofQueryObject.put("dst-access-topology-id", serviceRequestInputs.get("inner-dst-access-topology-id"));
+ oofQueryObject.put("dst-access-node-id", serviceRequestInputs.get("inner-dst-access-node-id"));
+ oofQueryObject.put("dst-access-ltp-id", serviceRequestInputs.get("inner-dst-access-ltp-id"));
+ String oofRequestReq = getJsonString(oofQueryObject);
+ String url = getOOFCalcEndPoint();
+ String responseContent = sendRequest(url, "POST", oofRequestReq);
+
+ List<Object> returnList = new ArrayList<>();
+ if (null != responseContent) {
+ returnList = getJsonObject(responseContent, List.class);
+ }
+ // in demo we have only one VPN. no cross VPNs, so get first item.
+ Map<String, Object> returnRoute = getReturnRoute(returnList);
+ Map<String, Object> vpnRequestInputs = getVPNResourceRequestInputs(resources);
+ if (null != vpnRequestInputs) {
+ vpnRequestInputs.putAll(returnRoute);
+ }
+ return getJsonString(uuiObject);
+ }
- List<Object> returnList = new ArrayList<>();
- if (null != responseContent) {
- returnList = getJsonObject(responseContent, List.class);
- }
- // in demo we have only one VPN. no cross VPNs, so get first item.
- Map<String, Object> returnRoute = getReturnRoute(returnList);
- Map<String, Object> vpnRequestInputs = getVPNResourceRequestInputs(resources);
- if(null!=vpnRequestInputs) {
- vpnRequestInputs.putAll(returnRoute);
- }
- String newRequest = getJsonString(uuiObject);
- return newRequest;
- }
-
private Map<String, Object> getReturnRoute(List<Object> returnList){
Map<String, Object> returnRoute = new HashMap<>();
for(Object returnVpn :returnList){
@@ -681,7 +704,7 @@ public class ServicePluginFactory {
return resourceInputsFromUuiMap;
}
- public static <T> T getJsonObject(String jsonstr, Class<T> type) {
+ private static <T> T getJsonObject(String jsonstr, Class<T> type) {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
try {
@@ -706,7 +729,7 @@ public class ServicePluginFactory {
}
private static String sendRequest(String url, String methodType, String content) {
-
+
String msbUrl = url;
HttpRequestBase method = null;
HttpResponse httpResponse = null;
diff --git a/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactoryTest.java b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactoryTest.java
new file mode 100644
index 0000000000..6e22123996
--- /dev/null
+++ b/bpmn/so-bpmn-infrastructure-common/src/test/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactoryTest.java
@@ -0,0 +1,187 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2019 Samsung 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.service;
+
+import static org.mockito.Mockito.doReturn;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Spy;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.onap.so.bpmn.core.domain.ServiceDecomposition;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ServicePluginFactoryTest {
+
+ @Mock
+ ServiceDecomposition serviceDecomposition;
+
+ @Spy
+ ServicePluginFactory servicePluginFactory;
+
+ String uuiRequest = "{"
+ + " \"service\":{"
+ + " \"name\":\"ONAP_223531\","
+ + " \"description\":\"ONAP_1546\","
+ + " \"serviceInvariantUuid\":\"4a09419a-c9fd-4a53-b1bd-b49603169ca1\","
+ + " \"serviceUuid\":\"1bd0eae6-2dcc-4461-9ae6-56d641f369d6\","
+ + " \"globalSubscriberId\":\"test_custormer\","
+ + " \"serviceType\":\"example-service-type\","
+ + " \"parameters\":{"
+ + " \"locationConstraints\":["
+ + " ],"
+ + " \"resources\":["
+ + " {"
+ + " \"resourceName\":\"vEPC_ONAP01\","
+ + " \"resourceInvariantUuid\":\"36ebe421-283a-4ee8-92f1-d09e7c44b911\","
+ + " \"resourceUuid\":\"27a0e235-b67a-4ea4-a0cf-25761afed111\","
+ + " \"resourceCustomizationUuid\":\"47a0e235-b67a-4ea4-a0cf-25761afed231\","
+ + " \"parameters\":{"
+ + " \"locationConstraints\":["
+ + " {"
+ + " \"vnfProfileId\":\"b244d433-8c9c-49ad-9c70-8e34b8dc8328\","
+ + " \"locationConstraints\":{"
+ + " \"vimId\":\"vmware_vio\""
+ + " }"
+ + " },"
+ + " {"
+ + " \"vnfProfileId\":\"8a9f7c48-21ce-41b7-95b8-a8ac61ccb1ff\","
+ + " \"locationConstraints\":{"
+ + " \"vimId\":\"core-dc_RegionOne\""
+ + " }"
+ + " }"
+ + " ],"
+ + " \"resources\":["
+ + " ],"
+ + " \"requestInputs\":{"
+ + " \"sdncontroller\":\"\""
+ + " }"
+ + " }"
+ + " },"
+ + " {"
+ + " \"resourceName\":\"VL OVERLAYTUNNEL\","
+ + " \"resourceInvariantUuid\":\"184494cf-472f-436f-82e2-d83dddde21cb\","
+ + " \"resourceUuid\":\"95bc3e59-c9c5-458f-ad6e-78874ab4b3cc\","
+ + " \"resourceCustomizationUuid\":\"27a0e235-b67a-4ea4-a0cf-25761afed232\","
+ + " \"parameters\":{"
+ + " \"locationConstraints\":["
+ + " ],"
+ + " \"resources\":["
+ + " ],"
+ + " \"requestInputs\":{"
+ + " }"
+ + " }"
+ + " }"
+ + " ],"
+ + " \"requestInputs\":{"
+ + " \"vlunderlayvpn0_name\":\"l3connect\","
+ + " \"vlunderlayvpn0_site1_id\":\"IP-WAN-Controller-1\","
+ + " \"vlunderlayvpn0_site2_id\":\"SPTNController\","
+ + " \"vlunderlayvpn0_site1_networkName\":\"network1,network2\","
+ + " \"vlunderlayvpn0_site2_networkName\":\"network3,network4\","
+ + " \"vlunderlayvpn0_site1_routerId\":\"a8098c1a-f86e-11da-bd1a-00112444be1a\","
+ + " \"vlunderlayvpn0_site2_routerId\":\"a8098c1a-f86e-11da-bd1a-00112444be1e\","
+ + " \"vlunderlayvpn0_site2_importRT1\":\"200:1,200:2\","
+ + " \"vlunderlayvpn0_site1_exportRT1\":\"300:1,300:2\","
+ + " \"vlunderlayvpn0_site2_exportRT1\":\"400:1,400:2\","
+ + " \"vlunderlayvpn0_site1_vni\":\"2000\","
+ + " \"vlunderlayvpn0_site2_vni\":\"3000\","
+ + " \"vlunderlayvpn0_tunnelType\":\"L3-DCI\","
+ + " \"CallSource\":\"NOT-ExternalAPI\","
+ + " \"sotnconnectivity\":\"\""
+ + " }"
+ + " }"
+ + " }"
+ + "}";
+
+
+ @Test
+ public void doProcessSiteLocation_isNeedProcessSite() {
+ String result = servicePluginFactory.doProcessSiteLocation(serviceDecomposition, uuiRequest);
+ Assert.assertEquals(result, uuiRequest);
+ }
+
+ @Test
+ public void doProcessSiteLocation_uuiObjectNull() {
+ String faultyJsonInput = "site_address,sotncondition_clientsignal";
+ String result = servicePluginFactory.doProcessSiteLocation(
+ serviceDecomposition, faultyJsonInput);
+ Assert.assertEquals(result, faultyJsonInput);
+ }
+
+ @Test
+ public void doProcessSiteLocation_isSiteLocationLocal() {
+ String jsonWithOnlyNeededValues = "{\"site_address\":\"\",\"sotncondition_clientsignal\":\"\"}";
+ String result = servicePluginFactory.doProcessSiteLocation(
+ serviceDecomposition, jsonWithOnlyNeededValues);
+ Assert.assertEquals(result, jsonWithOnlyNeededValues);
+ }
+
+
+ @Test
+ public void doTPResourcesAllocation_Success() {
+ doReturn(null).when(servicePluginFactory).getTPsfromAAI();
+ String result = servicePluginFactory.doTPResourcesAllocation(null, uuiRequest);
+ Assert.assertNotEquals(result, uuiRequest);
+ }
+
+ @Test
+ public void doTPResourcesAllocation_uuiObjectNull() {
+ String faultyJsonInput = "site_address,sotncondition_clientsignal";
+ String result = servicePluginFactory.doTPResourcesAllocation(null, faultyJsonInput);
+ Assert.assertEquals(result, faultyJsonInput);
+ }
+
+ @Test
+ public void doTPResourcesAllocation_isNeedAllocateCrossTPResources() {
+ //doReturn(null).when(servicePluginFactory).getTPsfromAAI();
+ String jsonWithOnlyNeededValues = "{\"site_address\":\"\",\"sotncondition_clientsignal\":\"\"}";
+ String result = servicePluginFactory.doTPResourcesAllocation(null, jsonWithOnlyNeededValues);
+ Assert.assertEquals(result, jsonWithOnlyNeededValues);
+ }
+
+ @Test
+ public void preProcessService_isSOTN() {
+ String invalidJsonWithOnlyNeededValues = "\"clientSignal\":\"\",\"vpnType\":\"\"}";
+ String result = servicePluginFactory.preProcessService(null, invalidJsonWithOnlyNeededValues);
+ Assert.assertEquals(result, invalidJsonWithOnlyNeededValues);
+ }
+
+ @Test
+ public void preProcessService() {
+ String result = servicePluginFactory.preProcessService(null, uuiRequest);
+ Assert.assertEquals(result, uuiRequest);
+ }
+
+ @Test
+ public void doServiceHoming() {
+ String result = servicePluginFactory.doServiceHoming(null, uuiRequest);
+ Assert.assertEquals(result, uuiRequest);
+ }
+
+ @Test
+ public void doServiceHoming_isSOTN() {
+ String invalidJsonWithOnlyNeededValues = "\"clientSignal\":\"\",\"vpnType\":\"\"}";
+ String result = servicePluginFactory.doServiceHoming(null, invalidJsonWithOnlyNeededValues);
+ Assert.assertEquals(result, invalidJsonWithOnlyNeededValues);
+ }
+}