summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@ericsson.com>2018-01-16 18:42:01 +0000
committerLiam Fallon <liam.fallon@ericsson.com>2018-01-16 18:47:17 +0000
commit59d71c593d295b2bd48a9971d89635f95759a0a2 (patch)
tree8cbdbd5180979b0c3aeb19739716462983bcb1cc
parent2b9b989f99700ebc11f77d8da2df4538fe7105d2 (diff)
Fix Sonar Technical Debt, Unit Test for APPC POJOs
Mainly making fields private, fixing field and methods to follow Java guidelines, and adding getter and setter methods. Unit test added for all classes in org.onap.policy.appc Change-Id: If3db740bc146a09f8f7387f02c12b048ad00b201 Signed-off-by: Liam Fallon <liam.fallon@ericsson.com> Issue-ID: POLICY-455 Signed-off-by: Liam Fallon <liam.fallon@ericsson.com>
-rw-r--r--controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java60
-rw-r--r--controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java16
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java13
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/drools/impl/PolicyEngineJUnitImpl.java2
-rw-r--r--controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/CommonHeader.java149
-rw-r--r--controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/Request.java99
-rw-r--r--controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/Response.java53
-rw-r--r--controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseCode.java7
-rw-r--r--controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseStatus.java55
-rw-r--r--controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseValue.java4
-rw-r--r--controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/util/Serialization.java19
-rw-r--r--controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestCommonHeader.java174
-rw-r--r--controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestEnums.java73
-rw-r--r--controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestRequest.java120
-rw-r--r--controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestResponse.java100
-rw-r--r--controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestResponseStatus.java84
-rw-r--r--controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/util/TestSerialization.java55
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java1
-rw-r--r--controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java6
19 files changed, 907 insertions, 183 deletions
diff --git a/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java b/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java
index d525c4c85..41a99496c 100644
--- a/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java
+++ b/controlloop/common/actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/APPCActorServiceProvider.java
@@ -41,15 +41,15 @@ public class APPCActorServiceProvider implements Actor {
private static final ImmutableList<String> recipes = ImmutableList.of("Restart", "Rebuild", "Migrate", "ModifyConfig");
private static final ImmutableMap<String, List<String>> targets = new ImmutableMap.Builder<String, List<String>>()
- .put("Restart", ImmutableList.of("VM"))
- .put("Rebuild", ImmutableList.of("VM"))
- .put("Migrate", ImmutableList.of("VM"))
- .put("ModifyConfig", ImmutableList.of("VNF"))
- .build();
+ .put("Restart", ImmutableList.of("VM"))
+ .put("Rebuild", ImmutableList.of("VM"))
+ .put("Migrate", ImmutableList.of("VM"))
+ .put("ModifyConfig", ImmutableList.of("VNF"))
+ .build();
private static final ImmutableMap<String, List<String>> payloads = new ImmutableMap.Builder<String, List<String>>()
- .put("ModifyConfig", ImmutableList.of("generic-vnf.vnf-id"))
- .build();
-
+ .put("ModifyConfig", ImmutableList.of("generic-vnf.vnf-id"))
+ .build();
+
@Override
public String actor() {
return "APPC";
@@ -77,52 +77,52 @@ public class APPCActorServiceProvider implements Actor {
*
* @param onset
* the event that is reporting the alert for policy
- * to perform an action
+ * to perform an action
* @param operation
* the control loop operation specifying the actor,
- * operation, target, etc.
+ * operation, target, etc.
* @param policy
* the policy the was specified from the yaml generated
- * by CLAMP or through the Policy GUI/API
+ * by CLAMP or through the Policy GUI/API
* @return an APPC request conforming to the legacy API
* @throws AAIException
*/
public static Request constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation,
- Policy policy, String targetVnf) {
+ Policy policy, String targetVnf) {
/*
* Construct an APPC request
*/
Request request = new Request();
- request.CommonHeader = new CommonHeader();
- request.CommonHeader.RequestID = onset.requestID;
- request.CommonHeader.SubRequestID = operation.subRequestId;
- request.Action = policy.getRecipe().substring(0, 1).toUpperCase()
- + policy.getRecipe().substring(1);
-
+ request.setCommonHeader(new CommonHeader());
+ request.getCommonHeader().setRequestID(onset.requestID);
+ request.getCommonHeader().setSubRequestID(operation.subRequestId);
+ request.setAction(policy.getRecipe().substring(0, 1).toUpperCase()
+ + policy.getRecipe().substring(1));
+
/*
* For now Policy generates the PG Streams as a demo, in the
* future the payload can be provided by CLAMP
*/
- request.Payload.put("generic-vnf.vnf-id", targetVnf);
-
+ request.getPayload().put("generic-vnf.vnf-id", targetVnf);
+
PGRequest pgRequest = new PGRequest();
pgRequest.pgStreams = new PGStreams();
-
+
PGStream pgStream;
for (int i = 0; i < 5; i++) {
- pgStream = new PGStream();
- pgStream.streamId = "fw_udp"+(i+1);
- pgStream.isEnabled = "true";
- pgRequest.pgStreams.pgStream.add(pgStream);
+ pgStream = new PGStream();
+ pgStream.streamId = "fw_udp"+(i+1);
+ pgStream.isEnabled = "true";
+ pgRequest.pgStreams.pgStream.add(pgStream);
}
- request.Payload.put("pg-streams", pgRequest.pgStreams);
-
+ request.getPayload().put("pg-streams", pgRequest.pgStreams);
+
/*
* Return the request
*/
-
+
return request;
}
-
-
+
+
}
diff --git a/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java b/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java
index 31a041d4b..e07589081 100644
--- a/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java
+++ b/controlloop/common/actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcServiceProviderTest.java
@@ -123,11 +123,11 @@ public class AppcServiceProviderTest {
/* A common header is required and cannot be null */
assertNotNull(appcRequest.getCommonHeader());
- assertEquals(appcRequest.getCommonHeader().RequestID, onsetEvent.requestID);
+ assertEquals(appcRequest.getCommonHeader().getRequestID(), onsetEvent.requestID);
/* An action is required and cannot be null */
- assertNotNull(appcRequest.Action);
- assertEquals(appcRequest.Action, "ModifyConfig");
+ assertNotNull(appcRequest.getAction());
+ assertEquals(appcRequest.getAction(), "ModifyConfig");
/* A payload is required and cannot be null */
assertNotNull(appcRequest.getPayload());
@@ -142,16 +142,16 @@ public class AppcServiceProviderTest {
logger.debug("JSON Output: \n" + jsonRequest);
/* The JSON string must contain the following fields */
- assertTrue(jsonRequest.contains("CommonHeader"));
- assertTrue(jsonRequest.contains("Action"));
+ assertTrue(jsonRequest.contains("commonHeader"));
+ assertTrue(jsonRequest.contains("action"));
assertTrue(jsonRequest.contains("ModifyConfig"));
- assertTrue(jsonRequest.contains("Payload"));
+ assertTrue(jsonRequest.contains("payload"));
assertTrue(jsonRequest.contains("generic-vnf.vnf-id"));
assertTrue(jsonRequest.contains("pg-streams"));
Response appcResponse = new Response(appcRequest);
- appcResponse.getStatus().Code = ResponseCode.SUCCESS.getValue();
- appcResponse.getStatus().Description = "AppC success";
+ appcResponse.getStatus().setCode(ResponseCode.SUCCESS.getValue());
+ appcResponse.getStatus().setDescription("AppC success");
/* Print out request as json to make sure serialization works */
String jsonResponse = Serialization.gsonPretty.toJson(appcResponse);
logger.debug("JSON Output: \n" + jsonResponse);
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
index 5084d4cbc..0ce3bc5c3 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager.java
@@ -47,7 +47,6 @@ import org.onap.policy.controlloop.policy.Policy;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.guard.Util;
-import org.onap.policy.so.SOResponse;
import org.onap.policy.so.SOResponseWrapper;
import org.onap.policy.vfc.VFCResponse;
import org.slf4j.Logger;
@@ -324,7 +323,7 @@ public class ControlLoopOperationManager implements Serializable {
//
Integer operationAttempt = null;
try {
- operationAttempt = Integer.parseInt(appcResponse.CommonHeader.SubRequestID);
+ operationAttempt = Integer.parseInt(appcResponse.getCommonHeader().getSubRequestID());
} catch (NumberFormatException e) {
//
// We cannot tell what happened if this doesn't exist
@@ -335,7 +334,7 @@ public class ControlLoopOperationManager implements Serializable {
//
// Sanity check the response message
//
- if (appcResponse.Status == null) {
+ if (appcResponse.getStatus() == null) {
//
// We cannot tell what happened if this doesn't exist
//
@@ -345,7 +344,7 @@ public class ControlLoopOperationManager implements Serializable {
//
// Get the Response Code
//
- ResponseCode code = ResponseCode.toResponseCode(appcResponse.Status.Code);
+ ResponseCode code = ResponseCode.toResponseCode(appcResponse.getStatus().getCode());
if (code == null) {
//
// We are unaware of this code
@@ -370,7 +369,7 @@ public class ControlLoopOperationManager implements Serializable {
//
// We'll consider these two codes as exceptions
//
- this.completeOperation(operationAttempt, appcResponse.getStatus().Description, PolicyResult.FAILURE_EXCEPTION);
+ this.completeOperation(operationAttempt, appcResponse.getStatus().getDescription(), PolicyResult.FAILURE_EXCEPTION);
if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
return null;
}
@@ -379,7 +378,7 @@ public class ControlLoopOperationManager implements Serializable {
//
//
//
- this.completeOperation(operationAttempt, appcResponse.getStatus().Description, PolicyResult.SUCCESS);
+ this.completeOperation(operationAttempt, appcResponse.getStatus().getDescription(), PolicyResult.SUCCESS);
if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
return null;
}
@@ -388,7 +387,7 @@ public class ControlLoopOperationManager implements Serializable {
//
//
//
- this.completeOperation(operationAttempt, appcResponse.getStatus().Description, PolicyResult.FAILURE);
+ this.completeOperation(operationAttempt, appcResponse.getStatus().getDescription(), PolicyResult.FAILURE);
if (this.policyResult != null && this.policyResult.equals(PolicyResult.FAILURE_TIMEOUT)) {
return null;
}
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/drools/impl/PolicyEngineJUnitImpl.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/drools/impl/PolicyEngineJUnitImpl.java
index a20731aaf..36feaaf93 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/drools/impl/PolicyEngineJUnitImpl.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/drools/impl/PolicyEngineJUnitImpl.java
@@ -74,7 +74,7 @@ public class PolicyEngineJUnitImpl implements PolicyEngine {
}
if (obj instanceof Request) {
Request request = (Request) obj;
- logger.debug("Request: {} subrequest {}", request.Action, request.CommonHeader.SubRequestID);
+ logger.debug("Request: {} subrequest {}", request.getAction(), request.getCommonHeader().getSubRequestID());
}
else if (obj instanceof LCMRequestWrapper) {
LCMRequestWrapper dmaapRequest = (LCMRequestWrapper) obj;
diff --git a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/CommonHeader.java b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/CommonHeader.java
index 1e92744ef..8ae029b76 100644
--- a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/CommonHeader.java
+++ b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/CommonHeader.java
@@ -28,52 +28,107 @@ import java.util.Map;
import java.util.UUID;
public class CommonHeader implements Serializable {
-
private static final long serialVersionUID = -3581658269910980336L;
- public Instant TimeStamp = Instant.now();
- public String APIver = "1.01";
- public String OriginatorID;
- public UUID RequestID;
- public String SubRequestID;
- public Collection<String> RequestTrack = new ArrayList<>();
- public Collection<Map<String, String>> Flags = new ArrayList<>();
+ private Instant timeStamp = Instant.now();
+ private String apiVer = "1.01";
+ private String originatorID;
+ private UUID requestID;
+ private String subRequestID;
+ private Collection<String> requestTrack = new ArrayList<>();
+ private Collection<Map<String, String>> flags = new ArrayList<>();
public CommonHeader() {
-
}
public CommonHeader(CommonHeader commonHeader) {
- this.OriginatorID = commonHeader.OriginatorID;
- this.RequestID = commonHeader.RequestID;
- this.SubRequestID = commonHeader.SubRequestID;
- if (commonHeader.RequestTrack != null) {
- this.RequestTrack.addAll(commonHeader.RequestTrack);
+ this.originatorID = commonHeader.originatorID;
+ this.requestID = commonHeader.requestID;
+ this.subRequestID = commonHeader.subRequestID;
+ if (commonHeader.requestTrack != null) {
+ this.requestTrack.addAll(commonHeader.requestTrack);
}
- if (commonHeader.Flags != null) {
- this.Flags.addAll(commonHeader.Flags);
+ if (commonHeader.flags != null) {
+ this.flags.addAll(commonHeader.flags);
}
}
+ public Instant getTimeStamp() {
+ return timeStamp;
+ }
+
+ public void setTimeStamp(Instant timeStamp) {
+ this.timeStamp = timeStamp;
+ }
+
+ public String getApiVer() {
+ return apiVer;
+ }
+
+ public void setApiVer(String apiVer) {
+ this.apiVer = apiVer;
+ }
+
+ public String getOriginatorID() {
+ return originatorID;
+ }
+
+ public void setOriginatorID(String originatorID) {
+ this.originatorID = originatorID;
+ }
+
+ public UUID getRequestID() {
+ return requestID;
+ }
+
+ public void setRequestID(UUID requestID) {
+ this.requestID = requestID;
+ }
+
+ public String getSubRequestID() {
+ return subRequestID;
+ }
+
+ public void setSubRequestID(String subRequestID) {
+ this.subRequestID = subRequestID;
+ }
+
+ public Collection<String> getRequestTrack() {
+ return requestTrack;
+ }
+
+ public void setRequestTrack(Collection<String> requestTrack) {
+ this.requestTrack = requestTrack;
+ }
+
+ public Collection<Map<String, String>> getFlags() {
+ return flags;
+ }
+
+ public void setFlags(Collection<Map<String, String>> flags) {
+ this.flags = flags;
+ }
+
@Override
public String toString() {
- return "CommonHeader [TimeStamp=" + TimeStamp + ", APIver=" + APIver + ", OriginatorID=" + OriginatorID
- + ", RequestID=" + RequestID + ", SubrequestID=" + SubRequestID + ", RequestTrack=" + RequestTrack
- + ", Flags=" + Flags + "]";
+ return "CommonHeader [TimeStamp=" + timeStamp + ", APIver=" + apiVer + ", OriginatorID=" + originatorID
+ + ", RequestID=" + requestID + ", SubrequestID=" + subRequestID + ", RequestTrack=" + requestTrack
+ + ", Flags=" + flags + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((APIver == null) ? 0 : APIver.hashCode());
- result = prime * result + ((Flags == null) ? 0 : Flags.hashCode());
- result = prime * result + ((OriginatorID == null) ? 0 : OriginatorID.hashCode());
- result = prime * result + ((RequestID == null) ? 0 : RequestID.hashCode());
- result = prime * result + ((RequestTrack == null) ? 0 : RequestTrack.hashCode());
- result = prime * result + ((SubRequestID == null) ? 0 : SubRequestID.hashCode());
- result = prime * result + ((TimeStamp == null) ? 0 : TimeStamp.hashCode());
+ result = prime * result + ((apiVer == null) ? 0 : apiVer.hashCode());
+ result = prime * result + ((flags == null) ? 0 : flags.hashCode());
+ result = prime * result + ((originatorID == null) ? 0 : originatorID.hashCode());
+ result = prime * result + ((requestID == null) ? 0 : requestID.hashCode());
+ result = prime * result + ((requestTrack == null) ? 0 : requestTrack.hashCode());
+ result = prime * result + ((subRequestID == null) ? 0 : subRequestID.hashCode());
+ result = prime * result + ((timeStamp == null) ? 0 : timeStamp.hashCode());
return result;
}
+
@Override
public boolean equals(Object obj) {
if (this == obj)
@@ -83,40 +138,40 @@ public class CommonHeader implements Serializable {
if (getClass() != obj.getClass())
return false;
CommonHeader other = (CommonHeader) obj;
- if (APIver == null) {
- if (other.APIver != null)
+ if (apiVer == null) {
+ if (other.apiVer != null)
return false;
- } else if (!APIver.equals(other.APIver))
+ } else if (!apiVer.equals(other.apiVer))
return false;
- if (Flags == null) {
- if (other.Flags != null)
+ if (flags == null) {
+ if (other.flags != null)
return false;
- } else if (!Flags.equals(other.Flags))
+ } else if (!flags.equals(other.flags))
return false;
- if (OriginatorID == null) {
- if (other.OriginatorID != null)
+ if (originatorID == null) {
+ if (other.originatorID != null)
return false;
- } else if (!OriginatorID.equals(other.OriginatorID))
+ } else if (!originatorID.equals(other.originatorID))
return false;
- if (RequestID == null) {
- if (other.RequestID != null)
+ if (requestID == null) {
+ if (other.requestID != null)
return false;
- } else if (!RequestID.equals(other.RequestID))
+ } else if (!requestID.equals(other.requestID))
return false;
- if (RequestTrack == null) {
- if (other.RequestTrack != null)
+ if (requestTrack == null) {
+ if (other.requestTrack != null)
return false;
- } else if (!RequestTrack.equals(other.RequestTrack))
+ } else if (!requestTrack.equals(other.requestTrack))
return false;
- if (SubRequestID == null) {
- if (other.SubRequestID != null)
+ if (subRequestID == null) {
+ if (other.subRequestID != null)
return false;
- } else if (!SubRequestID.equals(other.SubRequestID))
+ } else if (!subRequestID.equals(other.subRequestID))
return false;
- if (TimeStamp == null) {
- if (other.TimeStamp != null)
+ if (timeStamp == null) {
+ if (other.timeStamp != null)
return false;
- } else if (!TimeStamp.equals(other.TimeStamp))
+ } else if (!timeStamp.equals(other.timeStamp))
return false;
return true;
}
diff --git a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/Request.java b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/Request.java
index a9634a7b2..a74626000 100644
--- a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/Request.java
+++ b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/Request.java
@@ -25,36 +25,67 @@ import java.util.HashMap;
import java.util.Map;
public class Request implements Serializable{
-
private static final long serialVersionUID = -3912323643990646431L;
- public CommonHeader CommonHeader;
- public String Action;
- public String TargetID;
- public String ObjectID;
- public Map<String, Object> Payload = new HashMap<>();
+ private CommonHeader commonHeader;
+ private String action;
+ private String targetID;
+ private String objectID;
+ private HashMap<String, Object> payload = new HashMap<>();
public Request() {
-
+ // Initiate an empty Request instance
}
public CommonHeader getCommonHeader() {
- return CommonHeader;
+ return commonHeader;
}
public Map<String, Object> getPayload() {
- return Payload;
+ return payload;
}
+ public String getAction() {
+ return action;
+ }
+
+ public void setAction(String action) {
+ this.action = action;
+ }
+
+ public String getTargetID() {
+ return targetID;
+ }
+
+ public void setTargetID(String targetID) {
+ this.targetID = targetID;
+ }
+
+ public String getObjectID() {
+ return objectID;
+ }
+
+ public void setObjectID(String objectID) {
+ this.objectID = objectID;
+ }
+
+ public void setCommonHeader(CommonHeader commonHeader) {
+ this.commonHeader = commonHeader;
+ }
+
+ public void setPayload(Map<String, Object> payload) {
+ this.payload = new HashMap<>(payload);
+ }
+
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((Action == null) ? 0 : Action.hashCode());
- result = prime * result + ((CommonHeader == null) ? 0 : CommonHeader.hashCode());
- result = prime * result + ((ObjectID == null) ? 0 : ObjectID.hashCode());
- result = prime * result + ((Payload == null) ? 0 : Payload.hashCode());
- result = prime * result + ((TargetID == null) ? 0 : TargetID.hashCode());
+ result = prime * result + ((action == null) ? 0 : action.hashCode());
+ result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode());
+ result = prime * result + ((objectID == null) ? 0 : objectID.hashCode());
+ result = prime * result + ((payload == null) ? 0 : payload.hashCode());
+ result = prime * result + ((targetID == null) ? 0 : targetID.hashCode());
return result;
}
@@ -66,39 +97,45 @@ public class Request implements Serializable{
return false;
if (getClass() != obj.getClass())
return false;
+
Request other = (Request) obj;
- if (Action == null) {
- if (other.Action != null)
+ if (action == null) {
+ if (other.action != null)
return false;
- } else if (!Action.equals(other.Action))
+ } else if (!action.equals(other.action))
return false;
- if (CommonHeader == null) {
- if (other.CommonHeader != null)
+
+ if (commonHeader == null) {
+ if (other.commonHeader != null)
return false;
- } else if (!CommonHeader.equals(other.CommonHeader))
+ } else if (!commonHeader.equals(other.commonHeader))
return false;
- if (ObjectID == null) {
- if (other.ObjectID != null)
+
+ if (objectID == null) {
+ if (other.objectID != null)
return false;
- } else if (!ObjectID.equals(other.ObjectID))
+ } else if (!objectID.equals(other.objectID))
return false;
- if (Payload == null) {
- if (other.Payload != null)
+
+ if (payload == null) {
+ if (other.payload != null)
return false;
- } else if (!Payload.equals(other.Payload))
+ } else if (!payload.equals(other.payload))
return false;
- if (TargetID == null) {
- if (other.TargetID != null)
+
+ if (targetID == null) {
+ if (other.targetID != null)
return false;
- } else if (!TargetID.equals(other.TargetID))
+ } else if (!targetID.equals(other.targetID))
return false;
+
return true;
}
@Override
public String toString() {
- return "Request [CommonHeader=" + CommonHeader + ", Action=" + Action + ", TargetID=" + TargetID + ", ObjectID="
- + ObjectID + ", Payload=" + Payload + "]";
+ return "Request [CommonHeader=" + commonHeader + ", Action=" + action + ", TargetID=" + targetID + ", ObjectID="
+ + objectID + ", Payload=" + payload + "]";
}
}
diff --git a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/Response.java b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/Response.java
index 0aeb1d483..e00205998 100644
--- a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/Response.java
+++ b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/Response.java
@@ -25,59 +25,60 @@ import java.util.HashMap;
import java.util.Map;
public class Response implements Serializable {
-
private static final long serialVersionUID = 434953706339865151L;
- public CommonHeader CommonHeader;
- public ResponseStatus Status = new ResponseStatus();
- public Map<String, Object> Payload = new HashMap<>();
+ private CommonHeader commonHeader;
+ private ResponseStatus status = new ResponseStatus();
+ private HashMap<String, Object> payload = new HashMap<>();
public Response() {
}
public Response(Request request) {
- this.CommonHeader = new CommonHeader(request.CommonHeader);
- if (request.Payload != null) {
- this.Payload.putAll(request.Payload);
+ if (request.getCommonHeader() != null) {
+ this.commonHeader = new CommonHeader(request.getCommonHeader());
+ }
+ if (request.getPayload() != null) {
+ this.payload.putAll(request.getPayload());
}
}
public CommonHeader getCommonHeader() {
- return CommonHeader;
+ return commonHeader;
}
public void setCommonHeader(CommonHeader commonHeader) {
- CommonHeader = commonHeader;
+ this.commonHeader = commonHeader;
}
public ResponseStatus getStatus() {
- return Status;
+ return status;
}
public void setStatus(ResponseStatus status) {
- Status = status;
+ this.status = status;
}
public Map<String, Object> getPayload() {
- return Payload;
+ return payload;
}
public void setPayload(Map<String, Object> payload) {
- Payload = payload;
+ this.payload = new HashMap<>(payload);
}
@Override
public String toString() {
- return "Response [CommonHeader=" + CommonHeader + ", Status=" + Status + ", Payload=" + Payload + "]";
+ return "Response [CommonHeader=" + commonHeader + ", Status=" + status + ", Payload=" + payload + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + ((CommonHeader == null) ? 0 : CommonHeader.hashCode());
- result = prime * result + ((Payload == null) ? 0 : Payload.hashCode());
- result = prime * result + ((Status == null) ? 0 : Status.hashCode());
+ result = prime * result + ((commonHeader == null) ? 0 : commonHeader.hashCode());
+ result = prime * result + ((payload == null) ? 0 : payload.hashCode());
+ result = prime * result + ((status == null) ? 0 : status.hashCode());
return result;
}
@Override
@@ -89,20 +90,20 @@ public class Response implements Serializable {
if (getClass() != obj.getClass())
return false;
Response other = (Response) obj;
- if (CommonHeader == null) {
- if (other.CommonHeader != null)
+ if (commonHeader == null) {
+ if (other.commonHeader != null)
return false;
- } else if (!CommonHeader.equals(other.CommonHeader))
+ } else if (!commonHeader.equals(other.commonHeader))
return false;
- if (Payload == null) {
- if (other.Payload != null)
+ if (payload == null) {
+ if (other.payload != null)
return false;
- } else if (!Payload.equals(other.Payload))
+ } else if (!payload.equals(other.payload))
return false;
- if (Status == null) {
- if (other.Status != null)
+ if (status == null) {
+ if (other.status != null)
return false;
- } else if (!Status.equals(other.Status))
+ } else if (!status.equals(other.status))
return false;
return true;
}
diff --git a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseCode.java b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseCode.java
index 9bc9bb13e..fa96067c4 100644
--- a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseCode.java
+++ b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseCode.java
@@ -27,9 +27,9 @@ public enum ResponseCode {
SUCCESS(400),
FAILURE(500)
;
-
+
private Integer code;
-
+
private ResponseCode(int code) {
this.code = code;
}
@@ -37,7 +37,8 @@ public enum ResponseCode {
public int getValue() {
return this.code;
}
-
+
+ @Override
public String toString() {
return Integer.toString(this.code);
}
diff --git a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseStatus.java b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseStatus.java
index 6319dd8ad..7cef50127 100644
--- a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseStatus.java
+++ b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseStatus.java
@@ -23,26 +23,51 @@ package org.onap.policy.appc;
import java.io.Serializable;
public class ResponseStatus implements Serializable {
-
private static final long serialVersionUID = 2421770469587860452L;
- public int Code;
- public String Value;
- public String Description;
+ private int code;
+ private String value;
+ private String description;
@Override
public String toString() {
- return "ResponseStatus [Code=" + Code + ", Value=" + Value + ", Description=" + Description + "]";
+ return "ResponseStatus [Code=" + code + ", Value=" + value + ", Description=" + description + "]";
+ }
+
+ public int getCode() {
+ return code;
+ }
+
+ public void setCode(int code) {
+ this.code = code;
+ }
+
+ public String getValue() {
+ return value;
}
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + Code;
- result = prime * result + ((Description == null) ? 0 : Description.hashCode());
- result = prime * result + ((Value == null) ? 0 : Value.hashCode());
+ result = prime * result + code;
+ result = prime * result + ((description == null) ? 0 : description.hashCode());
+ result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
+
@Override
public boolean equals(Object obj) {
if (this == obj)
@@ -52,17 +77,17 @@ public class ResponseStatus implements Serializable {
if (getClass() != obj.getClass())
return false;
ResponseStatus other = (ResponseStatus) obj;
- if (Code != other.Code)
+ if (code != other.code)
return false;
- if (Description == null) {
- if (other.Description != null)
+ if (description == null) {
+ if (other.description != null)
return false;
- } else if (!Description.equals(other.Description))
+ } else if (!description.equals(other.description))
return false;
- if (Value == null) {
- if (other.Value != null)
+ if (value == null) {
+ if (other.value != null)
return false;
- } else if (!Value.equals(other.Value))
+ } else if (!value.equals(other.value))
return false;
return true;
}
diff --git a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseValue.java b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseValue.java
index 7bd745936..e750b60a6 100644
--- a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseValue.java
+++ b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseValue.java
@@ -40,6 +40,10 @@ public enum ResponseValue {
}
public static ResponseValue toResponseValue(String value) {
+ if (value == null) {
+ return null;
+ }
+
if (value.equals(ACCEPT.toString())) {
return ACCEPT;
}
diff --git a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/util/Serialization.java b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/util/Serialization.java
index 3afde0a06..6e04ee977 100644
--- a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/util/Serialization.java
+++ b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/util/Serialization.java
@@ -33,24 +33,21 @@ import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
-import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
public final class Serialization {
-
public static final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx");
private Serialization(){
}
- public static class gsonUTCAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> {
- private static final Logger logger = LoggerFactory.getLogger(gsonUTCAdapter.class);
+ public static class GSONUTCAdapter implements JsonSerializer<ZonedDateTime>, JsonDeserializer<ZonedDateTime> {
+ private static final Logger logger = LoggerFactory.getLogger(GSONUTCAdapter.class);
@Override
- public ZonedDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context)
- throws JsonParseException {
+ public ZonedDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context) {
try {
return ZonedDateTime.parse(element.getAsString(), format);
} catch (Exception e) {
@@ -63,11 +60,11 @@ public final class Serialization {
return new JsonPrimitive(datetime.format(format));
}
}
- public static class gsonInstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> {
+
+ public static class GSONInstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> {
@Override
- public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
- throws JsonParseException {
+ public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
return Instant.ofEpochMilli(json.getAsLong());
}
@@ -81,8 +78,8 @@ public final class Serialization {
public static final Gson gsonPretty = new GsonBuilder()
.disableHtmlEscaping()
.setPrettyPrinting()
- .registerTypeAdapter(ZonedDateTime.class, new gsonUTCAdapter())
- .registerTypeAdapter(Instant.class, new gsonInstantAdapter())
+ .registerTypeAdapter(ZonedDateTime.class, new GSONUTCAdapter())
+ .registerTypeAdapter(Instant.class, new GSONInstantAdapter())
// .registerTypeAdapter(CommonHeader1607.class, new gsonCommonHeaderInstance())
// .registerTypeAdapter(ResponseStatus1607.class, new gsonResponseStatus())
.create();
diff --git a/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestCommonHeader.java b/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestCommonHeader.java
new file mode 100644
index 000000000..039117272
--- /dev/null
+++ b/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestCommonHeader.java
@@ -0,0 +1,174 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * appc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T 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=========================================================
+ */
+
+/*-
+ * ============LICENSE_START=======================================================
+ * appc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T 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.policy.appc;
+
+import static org.junit.Assert.*;
+
+import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.junit.Test;
+
+public class TestCommonHeader {
+
+ @Test
+ public void testCommonHeader() {
+ CommonHeader commonHeader = new CommonHeader();
+ assertNotNull(commonHeader);
+ assertNotNull(new CommonHeader(commonHeader));
+ assertNotEquals(0, commonHeader.hashCode());
+
+ commonHeader.setApiVer("Kansas");
+ assertEquals("Kansas", commonHeader.getApiVer());
+
+ List<Map<String, String>> flagSet = new ArrayList<>();
+ commonHeader.setFlags(flagSet);
+ assertEquals(flagSet, commonHeader.getFlags());
+
+ commonHeader.setOriginatorID("Dorothy");
+ assertEquals("Dorothy", commonHeader.getOriginatorID());
+
+ UUID requestID = UUID.randomUUID();
+ commonHeader.setRequestID(requestID);
+ assertEquals(requestID, commonHeader.getRequestID());
+
+ List<String> requestTrackSet = new ArrayList<>();
+ commonHeader.setRequestTrack(requestTrackSet);
+ assertEquals(requestTrackSet, commonHeader.getRequestTrack());
+
+ commonHeader.setSubRequestID("Can I go home?");
+ assertEquals("Can I go home?", commonHeader.getSubRequestID());
+
+ Instant timestamp = Instant.now();
+ commonHeader.setTimeStamp(timestamp);
+ assertEquals(timestamp, commonHeader.getTimeStamp());
+
+ assertNotEquals(0, commonHeader.hashCode());
+
+ assertEquals("CommonHeader [TimeStamp=", commonHeader.toString().substring(0, 24));
+
+ CommonHeader copiedCommonHeader = new CommonHeader();
+ copiedCommonHeader.setApiVer(commonHeader.getApiVer());
+ copiedCommonHeader.setFlags(commonHeader.getFlags());
+ copiedCommonHeader.setOriginatorID(commonHeader.getOriginatorID());
+ copiedCommonHeader.setRequestID(commonHeader.getRequestID());
+ copiedCommonHeader.setRequestTrack(commonHeader.getRequestTrack());
+ copiedCommonHeader.setSubRequestID(commonHeader.getSubRequestID());
+ copiedCommonHeader.setTimeStamp(commonHeader.getTimeStamp());
+
+ assertTrue(commonHeader.equals(commonHeader));
+ assertTrue(commonHeader.equals(copiedCommonHeader));
+ assertFalse(commonHeader.equals(null));
+ assertFalse(commonHeader.equals("Hello"));
+
+ CommonHeader clonedCommonHeader = new CommonHeader(commonHeader);
+ clonedCommonHeader.setApiVer(commonHeader.getApiVer());
+ clonedCommonHeader.setTimeStamp(commonHeader.getTimeStamp());
+
+ assertTrue(commonHeader.equals(clonedCommonHeader));
+
+ commonHeader.setApiVer(null);
+ assertFalse(commonHeader.equals(copiedCommonHeader));
+ copiedCommonHeader.setApiVer(null);
+ assertTrue(commonHeader.equals(copiedCommonHeader));
+ commonHeader.setApiVer("Kansas");
+ assertFalse(commonHeader.equals(copiedCommonHeader));
+ copiedCommonHeader.setApiVer("Kansas");
+ assertTrue(commonHeader.equals(copiedCommonHeader));
+
+ commonHeader.setFlags(null);
+ assertFalse(commonHeader.equals(copiedCommonHeader));
+ copiedCommonHeader.setFlags(null);
+ assertTrue(commonHeader.equals(copiedCommonHeader));
+ commonHeader.setFlags(flagSet);
+ assertFalse(commonHeader.equals(copiedCommonHeader));
+ copiedCommonHeader.setFlags(flagSet);
+ assertTrue(commonHeader.equals(copiedCommonHeader));
+
+ commonHeader.setOriginatorID(null);
+ assertFalse(commonHeader.equals(copiedCommonHeader));
+ copiedCommonHeader.setOriginatorID(null);
+ assertTrue(commonHeader.equals(copiedCommonHeader));
+ commonHeader.setOriginatorID("Dorothy");
+ assertFalse(commonHeader.equals(copiedCommonHeader));
+ copiedCommonHeader.setOriginatorID("Dorothy");
+ assertTrue(commonHeader.equals(copiedCommonHeader));
+
+ commonHeader.setRequestID(null);
+ assertFalse(commonHeader.equals(copiedCommonHeader));
+ copiedCommonHeader.setRequestID(null);
+ assertTrue(commonHeader.equals(copiedCommonHeader));
+ commonHeader.setRequestID(requestID);
+ assertFalse(commonHeader.equals(copiedCommonHeader));
+ copiedCommonHeader.setRequestID(requestID);
+ assertTrue(commonHeader.equals(copiedCommonHeader));
+
+ commonHeader.setRequestTrack(null);
+ assertFalse(commonHeader.equals(copiedCommonHeader));
+ copiedCommonHeader.setRequestTrack(null);
+ assertTrue(commonHeader.equals(copiedCommonHeader));
+ commonHeader.setRequestTrack(requestTrackSet);
+ assertFalse(commonHeader.equals(copiedCommonHeader));
+ copiedCommonHeader.setRequestTrack(requestTrackSet);
+ assertTrue(commonHeader.equals(copiedCommonHeader));
+
+ commonHeader.setSubRequestID(null);
+ assertFalse(commonHeader.equals(copiedCommonHeader));
+ copiedCommonHeader.setSubRequestID(null);
+ assertTrue(commonHeader.equals(copiedCommonHeader));
+ commonHeader.setSubRequestID("Can I go home?");
+ assertFalse(commonHeader.equals(copiedCommonHeader));
+ copiedCommonHeader.setSubRequestID("Can I go home?");
+ assertTrue(commonHeader.equals(copiedCommonHeader));
+
+ commonHeader.setTimeStamp(null);
+ assertFalse(commonHeader.equals(copiedCommonHeader));
+ copiedCommonHeader.setTimeStamp(null);
+ assertTrue(commonHeader.equals(copiedCommonHeader));
+ commonHeader.setTimeStamp(timestamp);
+ assertFalse(commonHeader.equals(copiedCommonHeader));
+ copiedCommonHeader.setTimeStamp(timestamp);
+ assertTrue(commonHeader.equals(copiedCommonHeader));
+ }
+}
diff --git a/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestEnums.java b/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestEnums.java
new file mode 100644
index 000000000..e04da3cce
--- /dev/null
+++ b/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestEnums.java
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * appc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T 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.policy.appc;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class TestEnums {
+
+ @Test
+ public void testResponseCode() {
+ assertEquals(5, ResponseCode.values().length);
+
+ assertNull(ResponseCode.toResponseCode(0));
+
+ assertEquals(ResponseCode.ACCEPT, ResponseCode.toResponseCode(100));
+ assertEquals(ResponseCode.ERROR, ResponseCode.toResponseCode(200));
+ assertEquals(ResponseCode.REJECT, ResponseCode.toResponseCode(300));
+ assertEquals(ResponseCode.SUCCESS, ResponseCode.toResponseCode(400));
+ assertEquals(ResponseCode.FAILURE, ResponseCode.toResponseCode(500));
+
+ assertEquals(100, ResponseCode.ACCEPT.getValue());
+ assertEquals(200, ResponseCode.ERROR.getValue());
+ assertEquals(300, ResponseCode.REJECT.getValue());
+ assertEquals(400, ResponseCode.SUCCESS.getValue());
+ assertEquals(500, ResponseCode.FAILURE.getValue());
+
+ assertEquals("100", ResponseCode.ACCEPT.toString());
+ assertEquals("200", ResponseCode.ERROR.toString());
+ assertEquals("300", ResponseCode.REJECT.toString());
+ assertEquals("400", ResponseCode.SUCCESS.toString());
+ assertEquals("500", ResponseCode.FAILURE.toString());
+ }
+
+ @Test
+ public void testResponseValue() {
+ assertEquals(5, ResponseValue.values().length);
+
+ assertNull(ResponseValue.toResponseValue("Dorothy"));
+ assertNull(ResponseValue.toResponseValue(null));
+
+ assertEquals(ResponseValue.ACCEPT, ResponseValue.toResponseValue("ACCEPT"));
+ assertEquals(ResponseValue.ERROR, ResponseValue.toResponseValue("ERROR"));
+ assertEquals(ResponseValue.REJECT, ResponseValue.toResponseValue("REJECT"));
+ assertEquals(ResponseValue.SUCCESS, ResponseValue.toResponseValue("SUCCESS"));
+ assertEquals(ResponseValue.FAILURE, ResponseValue.toResponseValue("FAILURE"));
+
+ assertEquals("ACCEPT", ResponseValue.ACCEPT.toString());
+ assertEquals("ERROR", ResponseValue.ERROR.toString());
+ assertEquals("REJECT", ResponseValue.REJECT.toString());
+ assertEquals("SUCCESS", ResponseValue.SUCCESS.toString());
+ assertEquals("FAILURE", ResponseValue.FAILURE.toString());
+ }
+}
diff --git a/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestRequest.java b/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestRequest.java
new file mode 100644
index 000000000..6fdfe0968
--- /dev/null
+++ b/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestRequest.java
@@ -0,0 +1,120 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * appc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T 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.policy.appc;
+
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+
+public class TestRequest {
+
+ @Test
+ public void testRequest() {
+ Request request = new Request();
+ assertNotNull(request);
+ assertNotEquals(0, request.hashCode());
+
+ CommonHeader commonHeader = new CommonHeader();
+
+ request.setCommonHeader(commonHeader);
+ assertEquals(commonHeader, request.getCommonHeader());
+
+ request.setAction("Go to Oz");
+ assertEquals("Go to Oz", request.getAction());
+
+ request.setObjectID("Wizard");
+ assertEquals("Wizard", request.getObjectID());
+
+ request.setTargetID("Oz");
+ assertEquals("Oz", request.getTargetID());
+
+ Map<String, Object> payload = new HashMap<>();
+ payload.put("North", "Good Witch");
+ payload.put("West", "Bad Witch");
+
+ request.setPayload(payload);
+ assertEquals(payload, request.getPayload());
+
+ assertNotEquals(0, request.hashCode());
+
+ assertEquals("Request [CommonHeader=CommonHeader [TimeStamp=", request.toString().substring(0, 46));
+
+ Request copiedRequest = new Request();
+ copiedRequest.setCommonHeader(request.getCommonHeader());
+ copiedRequest.setAction(request.getAction());
+ copiedRequest.setObjectID(request.getObjectID());
+ copiedRequest.setPayload(request.getPayload());
+ copiedRequest.setTargetID(request.getTargetID());
+
+ assertTrue(request.equals(request));
+ assertTrue(request.equals(copiedRequest));
+ assertFalse(request.equals(null));
+ assertFalse(request.equals("Hello"));
+
+ request.setCommonHeader(null);
+ assertFalse(request.equals(copiedRequest));
+ copiedRequest.setCommonHeader(null);
+ assertTrue(request.equals(copiedRequest));
+ request.setCommonHeader(commonHeader);
+ assertFalse(request.equals(copiedRequest));
+ copiedRequest.setCommonHeader(commonHeader);
+ assertTrue(request.equals(copiedRequest));
+
+ request.setAction(null);
+ assertFalse(request.equals(copiedRequest));
+ copiedRequest.setAction(null);
+ assertTrue(request.equals(copiedRequest));
+ request.setAction("Go to Oz");
+ assertFalse(request.equals(copiedRequest));
+ copiedRequest.setAction("Go to Oz");
+ assertTrue(request.equals(copiedRequest));
+
+ request.setObjectID(null);
+ assertFalse(request.equals(copiedRequest));
+ copiedRequest.setObjectID(null);
+ assertTrue(request.equals(copiedRequest));
+ request.setObjectID("Wizard");
+ assertFalse(request.equals(copiedRequest));
+ copiedRequest.setObjectID("Wizard");
+ assertTrue(request.equals(copiedRequest));
+
+ request.setTargetID(null);
+ assertFalse(request.equals(copiedRequest));
+ copiedRequest.setTargetID(null);
+ assertTrue(request.equals(copiedRequest));
+ request.setTargetID("Oz");
+ assertFalse(request.equals(copiedRequest));
+ copiedRequest.setTargetID("Oz");
+ assertTrue(request.equals(copiedRequest));
+
+ request.setPayload(new HashMap<String, Object>());
+ assertFalse(request.equals(copiedRequest));
+ copiedRequest.setPayload(new HashMap<String, Object>());
+ assertTrue(request.equals(copiedRequest));
+ request.setPayload(payload);
+ assertFalse(request.equals(copiedRequest));
+ copiedRequest.setPayload(payload);
+ assertTrue(request.equals(copiedRequest));
+ }
+}
diff --git a/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestResponse.java b/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestResponse.java
new file mode 100644
index 000000000..5306a3344
--- /dev/null
+++ b/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestResponse.java
@@ -0,0 +1,100 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * appc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T 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.policy.appc;
+
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+
+public class TestResponse {
+
+ @Test
+ public void testResonse() {
+ Response response = new Response();
+ assertNotNull(response);
+ assertNotNull(new Response(new Request()));
+ assertNotEquals(0, response.hashCode());
+
+ CommonHeader commonHeader = new CommonHeader();
+
+ Request request = new Request();
+ request.setCommonHeader(commonHeader);
+ assertNotNull(new Response(request));
+
+ response.setCommonHeader(commonHeader);
+ assertEquals(commonHeader, response.getCommonHeader());
+
+ ResponseStatus status = new ResponseStatus();
+ response.setStatus(status );
+ assertEquals(status, response.getStatus());
+
+ Map<String, Object> payload = new HashMap<>();
+ payload.put("North", "Good Witch");
+ payload.put("West", "Bad Witch");
+
+ response.setPayload(payload);
+ assertEquals(payload, response.getPayload());
+
+ assertNotEquals(0, response.hashCode());
+
+ assertEquals("Response [CommonHeader=CommonHeader [TimeStamp=", response.toString().substring(0, 47));
+
+ Response copiedResponse = new Response();
+ copiedResponse.setCommonHeader(response.getCommonHeader());
+ copiedResponse.setStatus(response.getStatus());
+ copiedResponse.setPayload(response.getPayload());
+
+ assertTrue(response.equals(response));
+ assertTrue(response.equals(copiedResponse));
+ assertFalse(response.equals(null));
+ assertFalse(response.equals("Hello"));
+
+ response.setCommonHeader(null);
+ assertFalse(response.equals(copiedResponse));
+ copiedResponse.setCommonHeader(null);
+ assertTrue(response.equals(copiedResponse));
+ response.setCommonHeader(commonHeader);
+ assertFalse(response.equals(copiedResponse));
+ copiedResponse.setCommonHeader(commonHeader);
+ assertTrue(response.equals(copiedResponse));
+
+ response.setStatus(null);
+ assertFalse(response.equals(copiedResponse));
+ copiedResponse.setStatus(null);
+ assertTrue(response.equals(copiedResponse));
+ response.setStatus(status);
+ assertFalse(response.equals(copiedResponse));
+ copiedResponse.setStatus(status);
+ assertTrue(response.equals(copiedResponse));
+
+ response.setPayload(new HashMap<String, Object>());
+ assertFalse(response.equals(copiedResponse));
+ copiedResponse.setPayload(new HashMap<String, Object>());
+ assertTrue(response.equals(copiedResponse));
+ response.setPayload(payload);
+ assertFalse(response.equals(copiedResponse));
+ copiedResponse.setPayload(payload);
+ assertTrue(response.equals(copiedResponse));
+ }
+}
diff --git a/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestResponseStatus.java b/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestResponseStatus.java
new file mode 100644
index 000000000..0cac93ca4
--- /dev/null
+++ b/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/TestResponseStatus.java
@@ -0,0 +1,84 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * appc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T 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.policy.appc;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class TestResponseStatus {
+
+ @Test
+ public void testResonseStatus() {
+ ResponseStatus status = new ResponseStatus();
+ assertNotNull(status);
+ assertNotEquals(0, status.hashCode());
+
+ status.setCode(1234);
+ assertEquals(1234, status.getCode());
+
+ status.setDescription("The wonderful land of Oz");
+ assertEquals("The wonderful land of Oz", status.getDescription());
+
+ status.setValue("There's no place like home");
+ assertEquals("There's no place like home", status.getValue());
+ assertNotEquals(0, status.hashCode());
+
+ assertEquals("ResponseStatus [Code=1234, Value=There's no pla", status.toString().substring(0, 47));
+
+ ResponseStatus copiedStatus = new ResponseStatus();
+ copiedStatus.setCode(status.getCode());
+ copiedStatus.setDescription(status.getDescription());
+ copiedStatus.setValue(status.getValue());
+
+ assertTrue(status.equals(status));
+ assertTrue(status.equals(copiedStatus));
+ assertFalse(status.equals(null));
+ assertFalse(status.equals("Hello"));
+
+ status.setCode(-1);
+ assertFalse(status.equals(copiedStatus));
+ copiedStatus.setCode(-1);
+ assertTrue(status.equals(copiedStatus));
+ status.setCode(1234);
+ assertFalse(status.equals(copiedStatus));
+ copiedStatus.setCode(1234);
+ assertTrue(status.equals(copiedStatus));
+
+ status.setDescription(null);
+ assertFalse(status.equals(copiedStatus));
+ copiedStatus.setDescription(null);
+ assertTrue(status.equals(copiedStatus));
+ status.setDescription("The wonderful land of Oz");
+ assertFalse(status.equals(copiedStatus));
+ copiedStatus.setDescription("The wonderful land of Oz");
+ assertTrue(status.equals(copiedStatus));
+
+ status.setValue(null);
+ assertFalse(status.equals(copiedStatus));
+ copiedStatus.setValue(null);
+ assertTrue(status.equals(copiedStatus));
+ status.setValue("There's no place like home");
+ assertFalse(status.equals(copiedStatus));
+ copiedStatus.setValue("There's no place like home");
+ assertTrue(status.equals(copiedStatus));
+ }
+}
diff --git a/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/util/TestSerialization.java b/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/util/TestSerialization.java
new file mode 100644
index 000000000..0a82892ea
--- /dev/null
+++ b/controlloop/common/model-impl/appc/src/test/java/org/onap/policy/appc/util/TestSerialization.java
@@ -0,0 +1,55 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * appc
+ * ================================================================================
+ * Copyright (C) 2017 AT&T 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.policy.appc.util;
+
+import static org.junit.Assert.*;
+
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+
+import org.junit.Test;
+
+public class TestSerialization {
+
+ @Test
+ public void test() {
+ String nameString = "Dorothy";
+ String jsonName = Serialization.gsonPretty.toJson(nameString, String.class);
+ assertEquals("\"Dorothy\"", jsonName);
+ String jsonInOutName = Serialization.gsonPretty.fromJson(jsonName, String.class);
+ assertEquals("Dorothy", jsonInOutName);
+
+ Instant instant = Instant.ofEpochMilli(1516127215000L);
+ String instantString = Serialization.gsonPretty.toJson(instant, Instant.class);
+ assertEquals("1516127215000", instantString);
+ Instant outInstant = Serialization.gsonPretty.fromJson(instantString, Instant.class);
+ assertEquals(instant, outInstant);
+
+ ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, ZoneId.of("UTC"));
+ String zdtString = Serialization.gsonPretty.toJson(zdt, ZonedDateTime.class);
+ assertEquals("\"2018-01-16 18:26:55.000000+00:00\"", zdtString);
+ ZonedDateTime outZdt = Serialization.gsonPretty.fromJson(zdtString, ZonedDateTime.class);
+ assertEquals(zdt.getDayOfWeek(), outZdt.getDayOfWeek());
+
+ assertNull(Serialization.gsonPretty.fromJson("oz time is weird", ZonedDateTime.class));
+ }
+}
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java
index 377cff465..c95d558a5 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VCPEControlLoopTest.java
@@ -45,7 +45,6 @@ import org.onap.policy.controlloop.ControlLoopTargetType;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.VirtualControlLoopNotification;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
-import org.onap.policy.controlloop.policy.TargetType;
import org.onap.policy.drools.event.comm.Topic.CommInfrastructure;
import org.onap.policy.drools.event.comm.TopicEndpoint;
import org.onap.policy.drools.event.comm.TopicListener;
diff --git a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java
index 5ef20b544..95737b9c8 100644
--- a/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java
+++ b/controlloop/templates/template.demo/src/test/java/org/onap/policy/template/demo/VFWControlLoopTest.java
@@ -380,7 +380,7 @@ public class VFWControlLoopTest implements TopicListener {
}
}
else if (obj instanceof Request) {
- assertTrue(((Request)obj).getCommonHeader().SubRequestID.equals("1"));
+ assertTrue(((Request)obj).getCommonHeader().getSubRequestID().equals("1"));
assertNotNull(((Request)obj).getPayload().get("generic-vnf.vnf-id"));
logger.debug("\n============ APPC received the request!!! ===========\n");
@@ -390,8 +390,8 @@ public class VFWControlLoopTest implements TopicListener {
* the response into the working memory
*/
Response appcResponse = new Response((Request)obj);
- appcResponse.getStatus().Code = ResponseCode.SUCCESS.getValue();
- appcResponse.getStatus().Value = "SUCCESS";
+ appcResponse.getStatus().setCode(ResponseCode.SUCCESS.getValue());
+ appcResponse.getStatus().setValue("SUCCESS");
kieSession.insert(appcResponse);
}
}