Fix technical debt/JUnit on SO/VFC/SO ACTOR 75/29675/1
authorliamfallon <liam.fallon@ericsson.com>
Tue, 30 Jan 2018 17:06:20 +0000 (17:06 +0000)
committerliamfallon <liam.fallon@ericsson.com>
Tue, 30 Jan 2018 17:06:52 +0000 (17:06 +0000)
Unit test expanded for SO POJOs, technical debt removed in SO actor and VFC pojos.

Change-Id: I23b886c40c1ac6ac8dc2ebbaade315b71cca9dd0
Signed-off-by: liamfallon <liam.fallon@ericsson.com>
Issue-ID: POLICY-455

15 files changed:
controlloop/common/actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SOActorServiceProvider.java
controlloop/common/model-impl/so/pom.xml
controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOManager.java
controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOPolicyExceptionHolder.java [moved from controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOPolicyException.java with 91% similarity]
controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestDetails.java
controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SORequestError.java
controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOResponseWrapper.java
controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOServiceExceptionHolder.java [moved from controlloop/common/model-impl/so/src/main/java/org/onap/policy/so/SOServiceException.java with 91% similarity]
controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSOManager.java [new file with mode: 0644]
controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoPolicyExceptionHolder.java [moved from controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoPolicyException.java with 86% similarity]
controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequestDetails.java
controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoRequestError.java
controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoResponseWrapper.java
controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoServiceExceptionHolder.java [moved from controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSoServiceException.java with 86% similarity]
controlloop/common/model-impl/vfc/src/main/java/org/onap/policy/vfc/VFCManager.java

index cb31b74..bc10a9b 100644 (file)
@@ -127,16 +127,16 @@ public class SOActorServiceProvider implements Actor {
                        return null;
                }
 
-               AAINQInventoryResponseItem vnfItem = null;
-               AAINQInventoryResponseItem vnfServiceItem = null;
-               AAINQInventoryResponseItem tenantItem = null;
+               AAINQInventoryResponseItem vnfItem;
+               AAINQInventoryResponseItem vnfServiceItem;
+               AAINQInventoryResponseItem tenantItem;
 
                // Extract the items we're interested in from the response
                try     {
                        vnfItem = aaiResponseWrapper.getAainqresponse().getInventoryResponseItems().get(0).getItems().getInventoryResponseItems().get(0);
                }
                catch (Exception e) {
-                       logger.error("VNF Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiResponseWrapper));
+                       logger.error("VNF Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiResponseWrapper), e);
                        return null;
                }
 
@@ -144,7 +144,7 @@ public class SOActorServiceProvider implements Actor {
                        vnfServiceItem = vnfItem.getItems().getInventoryResponseItems().get(0);
                }
                catch (Exception e) {
-                       logger.error("VNF Service Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiResponseWrapper));
+                       logger.error("VNF Service Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiResponseWrapper), e);
                        return null;
                }
 
@@ -152,7 +152,7 @@ public class SOActorServiceProvider implements Actor {
                        tenantItem = aaiResponseWrapper.getAainqresponse().getInventoryResponseItems().get(0).getItems().getInventoryResponseItems().get(1);
                }
                catch (Exception e) {
-                       logger.error("Tenant Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiResponseWrapper));
+                       logger.error("Tenant Item not found in AAI response {}", Serialization.gsonPretty.toJson(aaiResponseWrapper), e);
                        return null;
                }
 
index 05d2258..718a82e 100644 (file)
@@ -19,9 +19,9 @@
   -->
 
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-  <modelVersion>4.0.0</modelVersion>
+       <modelVersion>4.0.0</modelVersion>
 
-  <artifactId>so</artifactId>
+       <artifactId>so</artifactId>
 
        <parent>
                <groupId>org.onap.policy.drools-applications</groupId>
                <version>1.2.0-SNAPSHOT</version>
        </parent>
 
-  <dependencies>
-       <dependency>
-               <groupId>junit</groupId>
-               <artifactId>junit</artifactId>
-               <version>4.12</version>
-               <scope>provided</scope>
-       </dependency>
-       <dependency>
-               <groupId>com.google.code.gson</groupId>
-               <artifactId>gson</artifactId>
-               <version>2.5</version>
-               <scope>provided</scope>
-       </dependency>
-       <dependency>
+       <dependencies>
+               <dependency>
+                       <groupId>junit</groupId>
+                       <artifactId>junit</artifactId>
+                       <version>4.12</version>
+                       <scope>test</scope>
+               </dependency>
+               <dependency>
+                       <groupId>com.google.code.gson</groupId>
+                       <artifactId>gson</artifactId>
+                       <version>2.5</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
                        <groupId>org.drools</groupId>
                        <artifactId>drools-core</artifactId>
                        <version>6.5.0.Final</version>
                        <scope>provided</scope>
                </dependency>
-       <dependency>
-               <groupId>org.onap.policy.drools-applications</groupId>
-               <artifactId>rest</artifactId>
-               <version>${project.version}</version>
-       </dependency>
-       <dependency>
-                  <groupId>org.onap.policy.drools-pdp</groupId>
-                  <artifactId>policy-management</artifactId>
-                  <version>${project.version}</version>
-                  <scope>provided</scope>
-       </dependency>
-  </dependencies>
+               <dependency>
+                       <groupId>org.onap.policy.drools-applications</groupId>
+                       <artifactId>rest</artifactId>
+                       <version>${project.version}</version>
+               </dependency>
+               <dependency>
+                       <groupId>org.onap.policy.drools-pdp</groupId>
+                       <artifactId>policy-management</artifactId>
+                       <version>${project.version}</version>
+                       <scope>provided</scope>
+               </dependency>
+               <dependency>
+                       <groupId>org.mockito</groupId>
+                       <artifactId>mockito-core</artifactId>
+                       <version>2.13.0</version>
+                       <scope>test</scope>
+               </dependency>
+       </dependencies>
 </project>
index 4b1d1d6..35227d3 100644 (file)
@@ -32,6 +32,7 @@ import org.drools.core.WorkingMemory;
 
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,176 +43,212 @@ import com.google.gson.JsonSyntaxException;
 
 public final class SOManager {
 
-    private static final Logger logger = LoggerFactory.getLogger(SOManager.class);
-    private static final Logger netLogger =
-            LoggerFactory.getLogger(org.onap.policy.drools.event.comm.Topic.NETWORK_LOGGER);
-    private static ExecutorService executors = Executors.newCachedThreadPool();
-
-    static final String MEDIA_TYPE = "application/json";
-
-    static final String LINE_SEPARATOR = System.lineSeparator();
-
-    public static SOResponse createModuleInstance(String url, String urlBase, String username,
-            String password, SORequest request) {
-
-        //
-        // Call REST
-        //
-        Map<String, String> headers = new HashMap<>();
-        headers.put("Accept", MEDIA_TYPE);
-
-        //
-        // 201 - CREATED - you are done just return
-        //
-        String requestJson = Serialization.gsonPretty.toJson(request);
-        netLogger.info("[OUT|{}|{}|]{}{}", "SO", url, LINE_SEPARATOR, requestJson);
-        Pair<Integer, String> httpDetails =
-                new RESTManager().post(url, username, password, headers, MEDIA_TYPE, requestJson);
-
-        if (httpDetails == null) {
-            return null;
-        }
-
-        if (httpDetails.a == 202) {
-            try {
-                SOResponse response =
-                        Serialization.gsonPretty.fromJson(httpDetails.b, SOResponse.class);
-
-                String body = Serialization.gsonPretty.toJson(response);
-                logger.debug("***** Response to post:");
-                logger.debug(body);
-
-                String requestId = response.getRequestReferences().getRequestId();
-                int attemptsLeft = 20;
-
-                String urlGet = urlBase + "/orchestrationRequests/v2/" + requestId;
-                SOResponse responseGet = null;
-
-                while (attemptsLeft-- > 0) {
-
-                    Pair<Integer, String> httpDetailsGet =
-                            new RESTManager().get(urlGet, username, password, headers);
-                    responseGet =
-                            Serialization.gsonPretty.fromJson(httpDetailsGet.b, SOResponse.class);
-                    netLogger.info("[IN|{}|{}|]{}{}", "SO", urlGet, LINE_SEPARATOR,
-                            httpDetailsGet.b);
-
-                    body = Serialization.gsonPretty.toJson(responseGet);
-                    logger.debug("***** Response to get:");
-                    logger.debug(body);
-
-                    if (httpDetailsGet.a == 200) {
-                        if (responseGet.getRequest().getRequestStatus().getRequestState()
-                                .equalsIgnoreCase("COMPLETE")
-                                || responseGet.getRequest().getRequestStatus().getRequestState()
-                                        .equalsIgnoreCase("FAILED")) {
-                            logger.debug("***** ########  VF Module Creation {}",
-                                    responseGet.getRequest().getRequestStatus().getRequestState());
-                            return responseGet;
-                        }
-                    }
-                    Thread.sleep(20000);
-                }
-
-                if (responseGet != null && responseGet.getRequest() != null
-                        && responseGet.getRequest().getRequestStatus() != null
-                        && responseGet.getRequest().getRequestStatus().getRequestState() != null) {
-                    logger.warn("***** ########  VF Module Creation timeout. Status: ( {})",
-                            responseGet.getRequest().getRequestStatus().getRequestState());
-                }
-
-                return responseGet;
-            }
-            catch (JsonSyntaxException e) {
-                logger.error("Failed to deserialize into SOResponse: ", e);
-            }
-            catch (InterruptedException e) {
-                logger.error("Interrupted exception: ", e);
-                Thread.currentThread().interrupt();
-            }
-        }
-
-
-
-        return null;
-    }
-
-    /**
-     * 
-     * @param wm
-     * @param url
-     * @param urlBase
-     * @param username
-     * @param password
-     * @param request
-     * 
-     *        This method makes an asynchronous Rest call to MSO and inserts the response into the
-     *        Drools working memory
-     */
-    public void asyncSORestCall(String requestID, WorkingMemory wm, String serviceInstanceId,
-            String vnfInstanceId, SORequest request) {
-        executors.submit(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    String serverRoot = PolicyEngine.manager.getEnvironmentProperty("so.url");
-                    String username = PolicyEngine.manager.getEnvironmentProperty("so.username");
-                    String password = PolicyEngine.manager.getEnvironmentProperty("so.password");
-
-                    String url = serverRoot + "/serviceInstances/v5/" + serviceInstanceId + "/vnfs/"
-                            + vnfInstanceId + "/vfModules";
-
-                    String auth = username + ":" + password;
-
-                    Map<String, String> headers = new HashMap<>();
-                    byte[] encodedBytes = Base64.getEncoder().encode(auth.getBytes());
-                    headers.put("Accept", MEDIA_TYPE);
-                    headers.put("Authorization", "Basic " + new String(encodedBytes));
-
-                    Gson gsonPretty =
-                            new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
-
-                    String soJson = gsonPretty.toJson(request);
-
-                    SOResponse so = new SOResponse();
-                    netLogger.info("[OUT|{}|{}|]{}{}", "SO", url, LINE_SEPARATOR, soJson);
-                    Pair<Integer, String> httpResponse = new RESTManager().post(url, "policy",
-                            "policy", headers, MEDIA_TYPE, soJson);
-
-                    if (httpResponse != null) {
-                        if (httpResponse.b != null && httpResponse.a != null) {
-                            netLogger.info("[IN|{}|{}|]{}{}", url, "SO", LINE_SEPARATOR,
-                                    httpResponse.b);
-
-                            Gson gson = new Gson();
-                            so = gson.fromJson(httpResponse.b, SOResponse.class);
-                            so.setHttpResponseCode(httpResponse.a);
-                        }
-                        else {
-                            logger.error("SO Response status/code is null.");
-                            so.setHttpResponseCode(999);
-                        }
-
-                    }
-                    else {
-                        logger.error("SO Response returned null.");
-                        so.setHttpResponseCode(999);
-                    }
-
-                    SOResponseWrapper soWrapper = new SOResponseWrapper(so, requestID);
-                    wm.insert(soWrapper);
-                    logger.info("SOResponse inserted " + gsonPretty.toJson(soWrapper));
-                }
-                catch (Exception e) {
-                    logger.error("Error while performing asyncSORestCall: " + e.getMessage(), e);
-
-                    // create dummy SO object to trigger cleanup
-                    SOResponse so = new SOResponse();
-                    so.setHttpResponseCode(999);
-                    wm.insert(so);
-                }
-            }
-        });
-    }
-
+       private static final Logger logger = LoggerFactory.getLogger(SOManager.class);
+       private static final Logger netLogger = LoggerFactory.getLogger(org.onap.policy.drools.event.comm.Topic.NETWORK_LOGGER);
+       private static ExecutorService executors = Executors.newCachedThreadPool();
+
+       static final String MEDIA_TYPE = "application/json";
+
+       static final String LINE_SEPARATOR = System.lineSeparator();
+       
+       // REST get timeout value in milliseconds
+       private static final long DEFAULT_GET_REQUEST_TIMEOUT = 20000;
+
+       // The REST manager used for processing REST calls for this VFC manager
+       private RESTManager restManager;
+       
+       private long restGetTimeout = DEFAULT_GET_REQUEST_TIMEOUT;
+       
+       public SOManager() {
+               restManager = new RESTManager();
+       }
+
+       public SOResponse createModuleInstance(String url, String urlBase, String username, String password, SORequest request) {
+
+               //
+               // Call REST
+               //
+               Map<String, String> headers = new HashMap<>();
+               headers.put("Accept", MEDIA_TYPE);
+
+               //
+               // 201 - CREATED - you are done just return
+               //
+               String requestJson = Serialization.gsonPretty.toJson(request);
+               netLogger.info("[OUT|{}|{}|{}|{}|{}|{}|]{}{}", "SO", url, username, password, headers, MEDIA_TYPE, LINE_SEPARATOR, requestJson);
+               Pair<Integer, String> httpDetails =     restManager.post(url, username, password, headers, MEDIA_TYPE, requestJson);
+
+               if (httpDetails == null) {
+                       return null;
+               }
+
+               if (httpDetails.a != 202) {
+                       return null;
+               }
+
+               try {
+                       SOResponse response = Serialization.gsonPretty.fromJson(httpDetails.b, SOResponse.class);
+
+                       String body = Serialization.gsonPretty.toJson(response);
+                       logger.debug("***** Response to post:");
+                       logger.debug(body);
+
+                       String requestId = response.getRequestReferences().getRequestId();
+                       int attemptsLeft = 20;
+
+                       String urlGet = urlBase + "/orchestrationRequests/v2/" + requestId;
+                       SOResponse responseGet = null;
+
+                       while (attemptsLeft-- > 0) {
+                               Pair<Integer, String> httpDetailsGet = restManager.get(urlGet, username, password, headers);
+                               if (httpDetailsGet == null) {
+                                       return null;
+                               }
+
+                               responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.b, SOResponse.class);
+                               netLogger.info("[IN|{}|{}|]{}{}", "SO", urlGet, LINE_SEPARATOR, httpDetailsGet.b);
+
+                               body = Serialization.gsonPretty.toJson(responseGet);
+                               logger.debug("***** Response to get:");
+                               logger.debug(body);
+
+                               if (httpDetailsGet.a == 200  &&
+                                               (responseGet.getRequest().getRequestStatus().getRequestState().equalsIgnoreCase("COMPLETE")
+                                                               || responseGet.getRequest().getRequestStatus().getRequestState().equalsIgnoreCase("FAILED"))) {
+                                       logger.debug("***** ########  VF Module Creation {}",
+                                                       responseGet.getRequest().getRequestStatus().getRequestState());
+                                       return responseGet;
+                               }
+                               Thread.sleep(restGetTimeout);
+                       }
+
+                       if (responseGet != null && responseGet.getRequest() != null
+                                       && responseGet.getRequest().getRequestStatus() != null
+                                       && responseGet.getRequest().getRequestStatus().getRequestState() != null) {
+                               logger.warn("***** ########  VF Module Creation timeout. Status: ( {})",
+                                               responseGet.getRequest().getRequestStatus().getRequestState());
+                       }
+
+                       return responseGet;
+               }
+               catch (JsonSyntaxException e) {
+                       logger.error("Failed to deserialize into SOResponse: ", e);
+               }
+               catch (InterruptedException e) {
+                       logger.error("Interrupted exception: ", e);
+                       Thread.currentThread().interrupt();
+               }
+
+               return null;
+       }
+
+       /**
+        * 
+        * @param wm
+        * @param url
+        * @param urlBase
+        * @param username
+        * @param password
+        * @param request
+        * 
+        *        This method makes an asynchronous Rest call to MSO and inserts the response into the
+        *        Drools working memory
+        * @return 
+        */
+       public Future<?> asyncSORestCall(String requestID, WorkingMemory wm, String serviceInstanceId,  String vnfInstanceId, SORequest request) {
+               return executors.submit(new AsyncSORestCallThread(requestID, wm, serviceInstanceId, vnfInstanceId, request));
+       }
+
+       private class AsyncSORestCallThread implements Runnable {
+               final String requestID;
+               final WorkingMemory wm;
+               final String serviceInstanceId;
+               final String vnfInstanceId;
+               final SORequest request;
+
+               private AsyncSORestCallThread(final String requestID, final WorkingMemory wm, final String serviceInstanceId,   final String vnfInstanceId, final SORequest request) {
+                       this.requestID = requestID;
+                       this.wm = wm;
+                       this.serviceInstanceId = serviceInstanceId;
+                       this.vnfInstanceId = vnfInstanceId;
+                       this.request = request;
+               }
+
+               @Override
+               public void run() {
+                       try {
+                               String serverRoot = PolicyEngine.manager.getEnvironmentProperty("so.url");
+                               String username = PolicyEngine.manager.getEnvironmentProperty("so.username");
+                               String password = PolicyEngine.manager.getEnvironmentProperty("so.password");
+
+                               String url = serverRoot + "/serviceInstances/v5/" + serviceInstanceId + "/vnfs/"
+                                               + vnfInstanceId + "/vfModules";
+
+                               String auth = username + ":" + password;
+
+                               Map<String, String> headers = new HashMap<>();
+                               byte[] encodedBytes = Base64.getEncoder().encode(auth.getBytes());
+                               headers.put("Accept", MEDIA_TYPE);
+                               headers.put("Authorization", "Basic " + new String(encodedBytes));
+
+                               Gson gsonPretty =
+                                               new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();
+
+                               String soJson = gsonPretty.toJson(request);
+
+                               SOResponse so = new SOResponse();
+                               netLogger.info("[OUT|{}|{}|]{}{}", "SO", url, LINE_SEPARATOR, soJson);
+                               Pair<Integer, String> httpResponse = restManager.post(url, "policy",    "policy", headers, MEDIA_TYPE, soJson);
+
+                               if (httpResponse != null) {
+                                       if (httpResponse.b != null && httpResponse.a != null) {
+                                               netLogger.info("[IN|{}|{}|]{}{}", url, "SO", LINE_SEPARATOR,    httpResponse.b);
+
+                                               Gson gson = new Gson();
+                                               so = gson.fromJson(httpResponse.b, SOResponse.class);
+                                               so.setHttpResponseCode(httpResponse.a);
+                                       }
+                                       else {
+                                               logger.error("SO Response status/code is null.");
+                                               so.setHttpResponseCode(999);
+                                       }
+
+                               }
+                               else {
+                                       logger.error("SO Response returned null.");
+                                       so.setHttpResponseCode(999);
+                               }
+
+                               SOResponseWrapper soWrapper = new SOResponseWrapper(so, requestID);
+                               wm.insert(soWrapper);
+                               if (logger.isInfoEnabled()) {
+                                       logger.info("SOResponse inserted " + gsonPretty.toJson(soWrapper));
+                               }
+                       }
+                       catch (Exception e) {
+                               logger.error("Error while performing asyncSORestCall: " + e.getMessage(), e);
+
+                               // create dummy SO object to trigger cleanup
+                               SOResponse so = new SOResponse();
+                               so.setHttpResponseCode(999);
+                               wm.insert(so);
+                       }
+               }
+       }
+
+       /**
+        * method to allow tuning of REST get timeout 
+        * @param restGetTimeout the timeout value
+        */
+       protected void setRestGetTimeout(final long restGetTimeout) {
+               this.restGetTimeout = restGetTimeout;
+       }
+       
+       /**
+        * Protected setter for rest manager to allow mocked rest manager to be used for testing 
+        * @param restManager the test REST manager
+        */
+       protected void setRestManager(final RESTManager restManager) {
+               this.restManager = restManager;
+       }
 }
@@ -24,7 +24,7 @@ import java.io.Serializable;
 \r
 import com.google.gson.annotations.SerializedName;\r
 \r
-public class SOPolicyException implements Serializable {\r
+public class SOPolicyExceptionHolder implements Serializable {\r
 \r
     private static final long serialVersionUID = -3283942659786236032L;\r
 \r
@@ -34,7 +34,7 @@ public class SOPolicyException implements Serializable {
     @SerializedName("text")\r
     private String text;\r
 \r
-    public SOPolicyException() {\r
+    public SOPolicyExceptionHolder() {\r
       //required by author\r
     }\r
 \r
index a864181..72e35d9 100644 (file)
@@ -58,6 +58,7 @@ public class SORequestDetails implements Serializable {
         this.requestInfo = soRequestDetails.requestInfo;
         this.relatedInstanceList = soRequestDetails.relatedInstanceList;
         this.requestParameters = soRequestDetails.requestParameters;
+        this.subscriberInfo = soRequestDetails.subscriberInfo;
     }
 
     @Override
@@ -99,6 +100,12 @@ public class SORequestDetails implements Serializable {
         }
         else if (!requestParameters.equals(other.requestParameters))
             return false;
+        if (subscriberInfo == null) {
+            if (other.subscriberInfo != null)
+                return false;
+        }
+        else if (!subscriberInfo.equals(other.subscriberInfo))
+            return false;
         return true;
     }
 
@@ -160,11 +167,16 @@ public class SORequestDetails implements Serializable {
         this.subscriberInfo = subscriberInfo;
     }
 
+    public void setRelatedInstanceList(List<SORelatedInstanceListElement> relatedInstanceList) {
+        this.relatedInstanceList = relatedInstanceList;
+    }
+
     @Override
     public String toString() {
         return "SORequestDetails [modelInfo=" + modelInfo + ", cloudConfiguration="
                 + cloudConfiguration + ", requestInfo=" + requestInfo + ", relatedInstanceList="
-                + relatedInstanceList + ", requestParameters=" + requestParameters + "]";
+                + relatedInstanceList + ", requestParameters=" + requestParameters +
+                ", subscriberInfo=" + subscriberInfo + "]";
     }
 
 }
index c9dad03..4986041 100644 (file)
@@ -29,28 +29,28 @@ public class SORequestError implements Serializable {
     private static final long serialVersionUID = -3283942659786236032L;\r
 \r
     @SerializedName("policyException")\r
-    private SOPolicyException policyException;\r
+    private SOPolicyExceptionHolder policyException;\r
 \r
     @SerializedName("serviceException")\r
-    private SOServiceException serviceException;\r
+    private SOServiceExceptionHolder serviceException;\r
 \r
     public SORequestError() {\r
         // required by author\r
     }\r
 \r
-    public SOPolicyException getPolicyException() {\r
+    public SOPolicyExceptionHolder getPolicyException() {\r
         return policyException;\r
     }\r
 \r
-    public SOServiceException getServiceException() {\r
+    public SOServiceExceptionHolder getServiceException() {\r
         return serviceException;\r
     }\r
 \r
-    public void setPolicyException(SOPolicyException policyException) {\r
+    public void setPolicyException(SOPolicyExceptionHolder policyException) {\r
         this.policyException = policyException;\r
     }\r
 \r
-    public void setServiceException(SOServiceException serviceException) {\r
+    public void setServiceException(SOServiceExceptionHolder serviceException) {\r
         this.serviceException = serviceException;\r
     }\r
 \r
index 184ae5e..e18cbb6 100644 (file)
@@ -29,12 +29,12 @@ public class SOResponseWrapper implements Serializable {
     private static final long serialVersionUID = 7673023687132889069L;
 
     @SerializedName("SoResponse")
-    private SOResponse SoResponse;
+    private SOResponse soResponse;
 
     private transient String requestID;
 
     public SOResponseWrapper(SOResponse response, String reqID) {
-        this.SoResponse = response;
+        this.soResponse = response;
         this.requestID = reqID;
     }
 
@@ -50,12 +50,12 @@ public class SOResponseWrapper implements Serializable {
             return false;
         }
         SOResponseWrapper other = (SOResponseWrapper) obj;
-        if (SoResponse == null) {
-            if (other.SoResponse != null) {
+        if (soResponse == null) {
+            if (other.soResponse != null) {
                 return false;
             }
         }
-        else if (!SoResponse.equals(other.SoResponse)) {
+        else if (!soResponse.equals(other.soResponse)) {
             return false;
         }
         if (requestID == null) {
@@ -74,14 +74,14 @@ public class SOResponseWrapper implements Serializable {
     }
 
     public SOResponse getSoResponse() {
-        return SoResponse;
+        return soResponse;
     }
 
     @Override
     public int hashCode() {
         final int prime = 31;
         int result = super.hashCode();
-        result = prime * result + ((SoResponse == null) ? 0 : SoResponse.hashCode());
+        result = prime * result + ((soResponse == null) ? 0 : soResponse.hashCode());
         result = prime * result + ((requestID == null) ? 0 : requestID.hashCode());
         return result;
     }
@@ -91,12 +91,12 @@ public class SOResponseWrapper implements Serializable {
     }
 
     public void setSoResponse(SOResponse sOResponse) {
-        SoResponse = sOResponse;
+        soResponse = sOResponse;
     }
 
     @Override
     public String toString() {
-        return "SOResponseWrapper [SOResponse=" + SoResponse + ", RequestID=" + requestID + "]";
+        return "SOResponseWrapper [SOResponse=" + soResponse + ", RequestID=" + requestID + "]";
     }
 
 }
@@ -26,7 +26,7 @@ import java.util.List;
 \r
 import com.google.gson.annotations.SerializedName;\r
 \r
-public class SOServiceException implements Serializable {\r
+public class SOServiceExceptionHolder implements Serializable {\r
 \r
     private static final long serialVersionUID = -3283942659786236032L;\r
 \r
@@ -39,7 +39,7 @@ public class SOServiceException implements Serializable {
     @SerializedName("variables")\r
     private List<String> variables = new LinkedList<>();\r
 \r
-    public SOServiceException() {\r
+    public SOServiceExceptionHolder() {\r
         // required by author\r
     }\r
 \r
diff --git a/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSOManager.java b/controlloop/common/model-impl/so/src/test/java/org/onap/policy/so/TestSOManager.java
new file mode 100644 (file)
index 0000000..a2beb57
--- /dev/null
@@ -0,0 +1,252 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * TestSOManager
+ * ================================================================================
+ * Copyright (C) 2018 Ericsson. 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.policy.so;
+
+import static org.junit.Assert.*;
+import static org.mockito.ArgumentMatchers.anyMap;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.startsWith;
+import static org.mockito.Mockito.*;
+
+import java.util.UUID;
+import java.util.concurrent.Future;
+
+import org.drools.core.WorkingMemory;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.policy.drools.system.PolicyEngine;
+import org.onap.policy.rest.RESTManager;
+import org.onap.policy.rest.RESTManager.Pair;
+import org.onap.policy.so.util.Serialization;
+
+public class TestSOManager {
+       private static WorkingMemory mockedWorkingMemory;
+
+       private RESTManager   mockedRESTManager;
+
+       private Pair<Integer, String> httpResponsePutOK;
+       private Pair<Integer, String> httpResponseGetOK;
+       private Pair<Integer, String> httpResponsePostOK;
+       private Pair<Integer, String> httpResponseErr;
+
+       private SORequest  request;
+       private SOResponse response;
+
+       @BeforeClass
+       public static void beforeTestSOManager() {
+               mockedWorkingMemory = mock(WorkingMemory.class);
+       }
+
+       @Before
+       public void setupMockedRest() {
+               mockedRESTManager   = mock(RESTManager.class);
+
+               httpResponsePutOK       = mockedRESTManager.new Pair<>(202, Serialization.gsonPretty.toJson(response));
+               httpResponseGetOK       = mockedRESTManager.new Pair<>(200, Serialization.gsonPretty.toJson(response));
+               httpResponsePostOK      = mockedRESTManager.new Pair<>(202, Serialization.gsonPretty.toJson(response));
+               httpResponseErr         = mockedRESTManager.new Pair<>(200, "{");
+       }
+
+       @Before
+       public void createRequestAndResponse() {
+               request = new SORequest();
+               SORequestStatus requestStatus = new SORequestStatus();
+               requestStatus.setRequestState("COMPLETE");
+               request.setRequestStatus(requestStatus);
+               request.setRequestId(UUID.randomUUID());
+               
+               response = new SOResponse();
+               
+               SORequestReferences requestReferences = new SORequestReferences();
+               String requestId = UUID.randomUUID().toString();
+               requestReferences.setRequestId(requestId);
+               response.setRequestReferences(requestReferences);
+               
+               response.setRequest(request);
+       }
+
+       @Test
+       public void testSOInitiation() {
+               assertNotNull(new SOManager());
+       }
+
+       @Test
+       public void testCreateModuleInstance() throws InterruptedException {
+               SOManager manager = new SOManager();
+               manager.setRestManager(mockedRESTManager);
+               
+               assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "OK", request));
+               
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Null"), anyMap(), anyString(), anyString()))
+               .thenReturn(null);
+               assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "Null", request));
+               
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Not202"), anyMap(), anyString(), anyString()))
+               .thenReturn(httpResponseErr);
+               assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "Not202", request));
+               
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetNull"), anyMap(), anyString(), anyString()))
+               .thenReturn(httpResponsePutOK);
+               when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetNull"), anyMap()))
+               .thenReturn(null);
+               assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetNull", request));
+               
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetOK"), anyMap(), anyString(), anyString()))
+               .thenReturn(httpResponsePutOK);
+               when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetOK"), anyMap()))
+               .thenReturn(httpResponseGetOK);
+               request.getRequestStatus().setRequestState("COMPLETE");
+               SOResponse response = manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetOK", request);
+               assertNotNull(response);
+               assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+
+               response.getRequest().getRequestStatus().setRequestState("FAILED");
+               Pair<Integer, String> httpResponseGetOKRequestFailed = mockedRESTManager.new Pair<>(200, Serialization.gsonPretty.toJson(response));
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetOKReqFailed"), anyMap(), anyString(), anyString()))
+               .thenReturn(httpResponsePutOK);
+               when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetOKReqFailed"), anyMap()))
+               .thenReturn(httpResponseGetOKRequestFailed);
+               response = manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetOKReqFailed", request);
+               assertNotNull(response);
+               assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState());
+
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetBadJSON"), anyMap(), anyString(), anyString()))
+               .thenReturn(httpResponsePutOK);
+               when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetBadJSON"), anyMap()))
+               .thenReturn(httpResponseErr);
+               assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetBadJSON", request));
+
+               response.getRequest().getRequestStatus().setRequestState("IN-PROGRESS");
+               Pair<Integer, String> httpResponseGetOKRequestTimeout = mockedRESTManager.new Pair<>(200, Serialization.gsonPretty.toJson(response));
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetOKReqTimeout"), anyMap(), anyString(), anyString()))
+               .thenReturn(httpResponsePutOK);
+               when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetOKReqTimeout"), anyMap()))
+               .thenReturn(httpResponseGetOKRequestTimeout);
+               
+               manager.setRestGetTimeout(10);
+               response = manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetOKReqTimeout", request);
+               assertNotNull(response);
+               assertEquals("IN-PROGRESS", response.getRequest().getRequestStatus().getRequestState());
+       }
+
+       @Test
+       public void testAsyncSORestCall() throws InterruptedException {
+               PolicyEngine.manager.getEnvironment().put("so.url", "http://somewhere.over.the.rainbow.null");
+               PolicyEngine.manager.getEnvironment().put("so.username", "Dorothy");
+               PolicyEngine.manager.getEnvironment().put("so.password", "OK");
+
+               SOManager manager = new SOManager();
+               manager.setRestManager(mockedRESTManager);
+               
+               String serviceInstanceId = UUID.randomUUID().toString();
+               String vnfInstanceId = UUID.randomUUID().toString();
+               
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow.null"), eq("policy"), eq("policy"), anyMap(), anyString(), anyString()))
+               .thenReturn(null);
+
+               Future<?> asyncRestCallFuture = manager.asyncSORestCall(request.getRequestId().toString(), mockedWorkingMemory, serviceInstanceId, vnfInstanceId, request);
+               try {
+                       assertNull(asyncRestCallFuture.get());
+               }
+               catch (Exception e) {
+                       fail("test should not throw an exception");
+               }
+
+               PolicyEngine.manager.getEnvironment().put("so.url", "http://somewhere.over.the.rainbow.err");
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow.err"), eq("policy"), eq("policy"), anyMap(), anyString(), anyString()))
+               .thenReturn(httpResponseErr);
+
+               asyncRestCallFuture = manager.asyncSORestCall(request.getRequestId().toString(), mockedWorkingMemory, serviceInstanceId, vnfInstanceId, request);
+               try {
+                       assertNull(asyncRestCallFuture.get());
+               }
+               catch (Exception e) {
+                       System.err.println(e);
+                       fail("test should not throw an exception");
+               }
+               
+               PolicyEngine.manager.getEnvironment().put("so.url", "http://somewhere.over.the.rainbow.ok");
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow.ok"), eq("policy"), eq("policy"), anyMap(), anyString(), anyString()))
+               .thenReturn(httpResponsePostOK);
+
+               asyncRestCallFuture = manager.asyncSORestCall(request.getRequestId().toString(), mockedWorkingMemory, serviceInstanceId, vnfInstanceId, request);
+               try {
+                       assertNull(asyncRestCallFuture.get());
+               }
+               catch (Exception e) {
+                       System.err.println(e);
+                       fail("test should not throw an exception");
+               }
+/*             
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Null"), anyMap(), anyString(), anyString()))
+               .thenReturn(null);
+               assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "Null", request));
+               
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("Not202"), anyMap(), anyString(), anyString()))
+               .thenReturn(httpResponseErr);
+               assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "Not202", request));
+               
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetNull"), anyMap(), anyString(), anyString()))
+               .thenReturn(httpResponsePutOK);
+               when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetNull"), anyMap()))
+               .thenReturn(null);
+               assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetNull", request));
+               
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetOK"), anyMap(), anyString(), anyString()))
+               .thenReturn(httpResponsePutOK);
+               when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetOK"), anyMap()))
+               .thenReturn(httpResponseGetOK);
+               request.getRequestStatus().setRequestState("COMPLETE");
+               SOResponse response = manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetOK", request);
+               assertNotNull(response);
+               assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+
+               response.getRequest().getRequestStatus().setRequestState("FAILED");
+               Pair<Integer, String> httpResponseGetOKRequestFailed = mockedRESTManager.new Pair<>(200, Serialization.gsonPretty.toJson(response));
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetOKReqFailed"), anyMap(), anyString(), anyString()))
+               .thenReturn(httpResponsePutOK);
+               when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetOKReqFailed"), anyMap()))
+               .thenReturn(httpResponseGetOKRequestFailed);
+               response = manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetOKReqFailed", request);
+               assertNotNull(response);
+               assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState());
+
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetBadJSON"), anyMap(), anyString(), anyString()))
+               .thenReturn(httpResponsePutOK);
+               when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetBadJSON"), anyMap()))
+               .thenReturn(httpResponseErr);
+               assertNull(manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetBadJSON", request));
+
+               response.getRequest().getRequestStatus().setRequestState("IN-PROGRESS");
+               Pair<Integer, String> httpResponseGetOKRequestTimeout = mockedRESTManager.new Pair<>(200, Serialization.gsonPretty.toJson(response));
+               when(mockedRESTManager.post(startsWith("http://somewhere.over.the.rainbow"), eq("Dorothy"), eq("PutOKGetOKReqTimeout"), anyMap(), anyString(), anyString()))
+               .thenReturn(httpResponsePutOK);
+               when(mockedRESTManager.get(startsWith("http://somewhere.over.the.rainbow/InOz"), eq("Dorothy"), eq("PutOKGetOKReqTimeout"), anyMap()))
+               .thenReturn(httpResponseGetOKRequestTimeout);
+               
+               manager.setRestGetTimeout(10);
+               response = manager.createModuleInstance("http://somewhere.over.the.rainbow", "http://somewhere.over.the.rainbow/InOz", "Dorothy", "PutOKGetOKReqTimeout", request);
+               assertNotNull(response);
+               assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState());
+               */
+       }
+}
@@ -25,11 +25,11 @@ import static org.junit.Assert.assertTrue;
 \r
 import org.junit.Test;\r
 \r
-public class TestSoPolicyException {\r
+public class TestSoPolicyExceptionHolder {\r
 \r
     @Test\r
     public void testConstructor() {\r
-        SOPolicyException obj = new SOPolicyException();\r
+        SOPolicyExceptionHolder obj = new SOPolicyExceptionHolder();\r
 \r
         assertTrue(obj.getMessageId() == null);\r
         assertTrue(obj.getText() == null);\r
@@ -37,7 +37,7 @@ public class TestSoPolicyException {
 \r
     @Test\r
     public void testSetGet() {\r
-        SOPolicyException obj = new SOPolicyException();\r
+        SOPolicyExceptionHolder obj = new SOPolicyExceptionHolder();\r
 \r
         obj.setMessageId("messageId");\r
         assertEquals("messageId", obj.getMessageId());\r
index 5c3c1a4..42dfe08 100755 (executable)
 package org.onap.policy.so;\r
 \r
 import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertNotEquals;\r
+import static org.junit.Assert.assertNotNull;\r
 import static org.junit.Assert.assertTrue;\r
 \r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
 import org.junit.Test;\r
 \r
 public class TestSoRequestDetails {\r
@@ -65,4 +71,104 @@ public class TestSoRequestDetails {
         obj.setSubscriberInfo(subscriberInfo);\r
         assertEquals(subscriberInfo, obj.getSubscriberInfo());\r
     }\r
+    \r
+       @Test\r
+       public void testSOMRequestDetailsMethods() {\r
+               SORequestDetails details = new SORequestDetails();\r
+               assertNotNull(details);\r
+               assertNotEquals(0, details.hashCode());\r
+               \r
+               SOCloudConfiguration cloudConfiguration = new SOCloudConfiguration();\r
+               details.setCloudConfiguration(cloudConfiguration);\r
+               assertEquals(cloudConfiguration, details.getCloudConfiguration());\r
+               assertNotEquals(0, details.hashCode());\r
+               \r
+               SOModelInfo modelInfo = new SOModelInfo();\r
+               details.setModelInfo(modelInfo);\r
+               assertEquals(modelInfo, details.getModelInfo());\r
+               assertNotEquals(0, details.hashCode());\r
+               \r
+               List<SORelatedInstanceListElement> relatedInstanceList = new ArrayList<>();\r
+               details.setRelatedInstanceList(relatedInstanceList);\r
+               assertEquals(relatedInstanceList, details.getRelatedInstanceList());\r
+               assertNotEquals(0, details.hashCode());\r
+               \r
+               SORequestInfo requestInfo = new SORequestInfo();\r
+               details.setRequestInfo(requestInfo);\r
+               assertEquals(requestInfo, details.getRequestInfo());\r
+               assertNotEquals(0, details.hashCode());\r
+               \r
+               SORequestParameters requestParameters = new SORequestParameters();\r
+               details.setRequestParameters(requestParameters);\r
+               assertEquals(requestParameters, details.getRequestParameters());\r
+               assertNotEquals(0, details.hashCode());\r
+               \r
+               SOSubscriberInfo subscriberInfo = new SOSubscriberInfo();\r
+               details.setSubscriberInfo(subscriberInfo);\r
+               assertEquals(subscriberInfo, details.getSubscriberInfo());\r
+               assertNotEquals(0, details.hashCode());\r
+               \r
+               assertEquals("SORequestDetails [modelInfo=org.onap.policy.so", details.toString().substring(0,  46));\r
+               \r
+               SORequestDetails copiedDetails = new SORequestDetails(details);\r
+\r
+        assertTrue(details.equals(details));\r
+        assertTrue(details.equals(copiedDetails));\r
+        assertFalse(details.equals(null));\r
+        assertFalse(details.equals("Hello"));\r
+        \r
+        details.setCloudConfiguration(null);\r
+        assertFalse(details.equals(copiedDetails));\r
+        copiedDetails.setCloudConfiguration(null);\r
+        assertTrue(details.equals(copiedDetails));\r
+        details.setCloudConfiguration(cloudConfiguration);\r
+        assertFalse(details.equals(copiedDetails));\r
+        copiedDetails.setCloudConfiguration(cloudConfiguration);\r
+        assertTrue(details.equals(copiedDetails));\r
+\r
+        details.setModelInfo(null);\r
+        assertFalse(details.equals(copiedDetails));\r
+        copiedDetails.setModelInfo(null);\r
+        assertTrue(details.equals(copiedDetails));\r
+        details.setModelInfo(modelInfo);\r
+        assertFalse(details.equals(copiedDetails));\r
+        copiedDetails.setModelInfo(modelInfo);\r
+        assertTrue(details.equals(copiedDetails));\r
+        \r
+        details.setRequestInfo(null);\r
+        assertFalse(details.equals(copiedDetails));\r
+        copiedDetails.setRequestInfo(null);\r
+        assertTrue(details.equals(copiedDetails));\r
+        details.setRequestInfo(requestInfo);\r
+        assertFalse(details.equals(copiedDetails));\r
+        copiedDetails.setRequestInfo(requestInfo);\r
+        assertTrue(details.equals(copiedDetails));\r
+               \r
+        details.setRequestParameters(null);\r
+        assertFalse(details.equals(copiedDetails));\r
+        copiedDetails.setRequestParameters(null);\r
+        assertTrue(details.equals(copiedDetails));\r
+        details.setRequestParameters(requestParameters);\r
+        assertFalse(details.equals(copiedDetails));\r
+        copiedDetails.setRequestParameters(requestParameters);\r
+        assertTrue(details.equals(copiedDetails));\r
+               \r
+        details.setSubscriberInfo(null);\r
+        assertFalse(details.equals(copiedDetails));\r
+        copiedDetails.setSubscriberInfo(null);\r
+        assertTrue(details.equals(copiedDetails));\r
+        details.setSubscriberInfo(subscriberInfo);\r
+        assertFalse(details.equals(copiedDetails));\r
+        copiedDetails.setSubscriberInfo(subscriberInfo);\r
+        assertTrue(details.equals(copiedDetails));\r
+               \r
+        details.setRelatedInstanceList(null);\r
+        assertFalse(details.equals(copiedDetails));\r
+               copiedDetails.setRelatedInstanceList(null);\r
+        assertTrue(details.equals(copiedDetails));\r
+        details.setRelatedInstanceList(relatedInstanceList);\r
+        assertFalse(details.equals(copiedDetails));\r
+               copiedDetails.setRelatedInstanceList(relatedInstanceList);\r
+        assertTrue(details.equals(copiedDetails));\r
+       }\r
 }\r
index 31f3b6c..1108daf 100755 (executable)
@@ -39,11 +39,11 @@ public class TestSoRequestError {
     public void testSetGet() {\r
         SORequestError obj = new SORequestError();\r
 \r
-        SOPolicyException policyException = new SOPolicyException();\r
+        SOPolicyExceptionHolder policyException = new SOPolicyExceptionHolder();\r
         obj.setPolicyException(policyException);\r
         assertEquals(policyException, obj.getPolicyException());\r
 \r
-        SOServiceException serviceException = new SOServiceException();\r
+        SOServiceExceptionHolder serviceException = new SOServiceExceptionHolder();\r
         obj.setServiceException(serviceException);\r
         assertEquals(serviceException, obj.getServiceException());\r
     }\r
index 93549a2..7b48301 100755 (executable)
 package org.onap.policy.so;\r
 \r
 import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertNotEquals;\r
+import static org.junit.Assert.assertNotNull;\r
+\r
+import java.util.UUID;\r
 \r
 import org.junit.Test;\r
 \r
@@ -48,4 +53,54 @@ public class TestSoResponseWrapper {
         obj.setRequestID("id2");\r
         assertEquals("id2", obj.getRequestID());\r
     }\r
+    \r
+       @SuppressWarnings("unlikely-arg-type")\r
+       @Test\r
+       public void testSOResponseWrapperMethods() {\r
+               String requestID = UUID.randomUUID().toString();\r
+               SOResponse response = new SOResponse();\r
+\r
+               SOResponseWrapper responseWrapper = new SOResponseWrapper(response, requestID);\r
+               assertNotNull(responseWrapper);\r
+               assertNotEquals(0, responseWrapper.hashCode());\r
+               \r
+               assertEquals(response, responseWrapper.getSoResponse());\r
+               \r
+               assertNotEquals(0, responseWrapper.hashCode());\r
+               \r
+               assertEquals("SOResponseWrapper [SOResponse=org.onap.policy.", responseWrapper.toString().substring(0,  46));\r
+               \r
+               SOResponseWrapper identicalResponseWrapper = new SOResponseWrapper(response, requestID);\r
+\r
+        assertEquals(responseWrapper,  responseWrapper);\r
+        assertEquals(responseWrapper,  identicalResponseWrapper);\r
+        assertNotEquals(null, responseWrapper);\r
+        assertNotEquals("Hello", responseWrapper);\r
+        assertFalse(responseWrapper.equals(null));\r
+        assertFalse(responseWrapper.equals("AString"));\r
+        \r
+        assertEquals(new SOResponseWrapper(null, null), new SOResponseWrapper(null, null));\r
+        assertNotEquals(new SOResponseWrapper(null, null), identicalResponseWrapper);\r
+        \r
+               assertNotEquals(0, new SOResponseWrapper(null, null).hashCode());\r
+\r
+               identicalResponseWrapper.setSoResponse(new SOResponse());\r
+        assertNotEquals(responseWrapper,  identicalResponseWrapper);\r
+        identicalResponseWrapper.setSoResponse(response);\r
+        assertEquals(responseWrapper,  identicalResponseWrapper);\r
+        \r
+        identicalResponseWrapper.setRequestID(UUID.randomUUID().toString());\r
+        assertNotEquals(responseWrapper,  identicalResponseWrapper);\r
+        identicalResponseWrapper.setRequestID(requestID);\r
+        assertEquals(responseWrapper,  identicalResponseWrapper);\r
+        \r
+        responseWrapper.setRequestID(null);\r
+        assertNotEquals(responseWrapper,  identicalResponseWrapper);\r
+        identicalResponseWrapper.setRequestID(null);\r
+        assertEquals(responseWrapper,  identicalResponseWrapper);\r
+        responseWrapper.setRequestID(requestID);\r
+        assertNotEquals(responseWrapper,  identicalResponseWrapper);\r
+        identicalResponseWrapper.setRequestID(requestID);\r
+        assertEquals(responseWrapper,  identicalResponseWrapper);\r
+       }\r
 }\r
@@ -25,11 +25,11 @@ import static org.junit.Assert.assertTrue;
 \r
 import org.junit.Test;\r
 \r
-public class TestSoServiceException {\r
+public class TestSoServiceExceptionHolder {\r
 \r
     @Test\r
     public void testConstructor() {\r
-        SOServiceException obj = new SOServiceException();\r
+        SOServiceExceptionHolder obj = new SOServiceExceptionHolder();\r
 \r
         assertTrue(obj.getMessageId() == null);\r
         assertTrue(obj.getText() == null);\r
@@ -39,7 +39,7 @@ public class TestSoServiceException {
 \r
     @Test\r
     public void testSetGet() {\r
-        SOServiceException obj = new SOServiceException();\r
+        SOServiceExceptionHolder obj = new SOServiceExceptionHolder();\r
 \r
         obj.setMessageId("messageId");\r
         assertEquals("messageId", obj.getMessageId());\r
index 7146e43..1752239 100644 (file)
@@ -119,7 +119,7 @@ public final class VFCManager implements Runnable {
                                logger.debug(body);
 
                                String responseStatus = responseGet.getResponseDescriptor().getStatus();
-                               if (httpDetailsGet.a == 200 && (responseStatus.equalsIgnoreCase("finished") || responseStatus.equalsIgnoreCase("error"))) {
+                               if (httpDetailsGet.a == 200 && ("finished".equalsIgnoreCase(responseStatus) || "error".equalsIgnoreCase(responseStatus))) {
                                        logger.debug("VFC Heal Status {}", responseGet.getResponseDescriptor().getStatus());
                                        workingMem.insert(responseGet);
                                        break;