diff options
author | mmis <michael.morris@ericsson.com> | 2018-03-27 13:13:57 +0100 |
---|---|---|
committer | mmis <michael.morris@ericsson.com> | 2018-03-27 16:00:35 +0100 |
commit | 03bded5317a0c50e2a7a3c95f553f612f877ddef (patch) | |
tree | ebb1f01121f8842e087a49abf10810705b78dd46 /controlloop/common/model-impl/appc | |
parent | 0c2b7a2fc65ec7c8252764acafdcc3852db7b411 (diff) |
Removed checkstyle warnings
Removed checkstyle warnings from:
policy/drools-applications/controlloop/common/model-impl/appc
policy/drools-applications/controlloop/common/model-impl/appclcm
policy/drools-applications/controlloop/common/model-impl/events
including changes to template files due to renamed methods
Issue-ID: POLICY-705
Change-Id: Ieb93baf43268aa608f204eef1a610354f2adec32
Signed-off-by: mmis <michael.morris@ericsson.com>
Diffstat (limited to 'controlloop/common/model-impl/appc')
14 files changed, 952 insertions, 834 deletions
diff --git a/controlloop/common/model-impl/appc/pom.xml b/controlloop/common/model-impl/appc/pom.xml index d69f1eda8..2703b3e61 100644 --- a/controlloop/common/model-impl/appc/pom.xml +++ b/controlloop/common/model-impl/appc/pom.xml @@ -43,4 +43,45 @@ <scope>provided</scope> </dependency> </dependencies> + + <build> + <plugins> + <plugin> + <artifactId>maven-checkstyle-plugin</artifactId> + <executions> + <execution> + <id>onap-java-style</id> + <goals> + <goal>check</goal> + </goals> + <phase>process-sources</phase> + <configuration> + <!-- Use Google Java Style Guide: + https://github.com/checkstyle/checkstyle/blob/master/src/main/resources/google_checks.xml + with minor changes --> + <configLocation>onap-checkstyle/onap-java-style.xml</configLocation> + <!-- <sourceDirectory> is needed so that checkstyle ignores the generated sources directory --> + <sourceDirectory>${project.build.sourceDirectory}</sourceDirectory> + <includeResources>true</includeResources> + <includeTestSourceDirectory>true</includeTestSourceDirectory> + <includeTestResources>true</includeTestResources> + <excludes> + </excludes> + <consoleOutput>true</consoleOutput> + <failOnViolation>true</failOnViolation> + <violationSeverity>warning</violationSeverity> + </configuration> + </execution> + </executions> + <dependencies> + <dependency> + <groupId>org.onap.oparent</groupId> + <artifactId>checkstyle</artifactId> + <version>0.1.1</version> + <scope>compile</scope> + </dependency> + </dependencies> + </plugin> + </plugins> + </build> </project> 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 506303fc2..b2beb5548 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -20,6 +20,8 @@ package org.onap.policy.appc; +import com.google.gson.annotations.SerializedName; + import java.io.Serializable; import java.time.Instant; import java.util.ArrayList; @@ -27,168 +29,188 @@ import java.util.Collection; import java.util.Map; import java.util.UUID; -import com.google.gson.annotations.SerializedName; - public class CommonHeader implements Serializable { - private static final long serialVersionUID = -3581658269910980336L; - - @SerializedName("TimeStamp") - private Instant timeStamp = Instant.now(); - - @SerializedName("APIver") - private String apiVer = "1.01"; - - @SerializedName("OriginatorID") - private String originatorID; - - @SerializedName("RequestID") - private UUID requestID; - - @SerializedName("SubRequestID") - private String subRequestID; - - @SerializedName("RequestTrack") - private Collection<String> requestTrack = new ArrayList<>(); - - @SerializedName("Flags") - 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); - } - 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 + "]"; - } - @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()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - CommonHeader other = (CommonHeader) obj; - if (apiVer == null) { - if (other.apiVer != null) - return false; - } else if (!apiVer.equals(other.apiVer)) - return false; - if (flags == null) { - if (other.flags != null) - return false; - } else if (!flags.equals(other.flags)) - return false; - if (originatorID == null) { - if (other.originatorID != null) - return false; - } else if (!originatorID.equals(other.originatorID)) - return false; - if (requestID == null) { - if (other.requestID != null) - return false; - } else if (!requestID.equals(other.requestID)) - return false; - if (requestTrack == null) { - if (other.requestTrack != null) - return false; - } else if (!requestTrack.equals(other.requestTrack)) - return false; - if (subRequestID == null) { - if (other.subRequestID != null) - return false; - } else if (!subRequestID.equals(other.subRequestID)) - return false; - if (timeStamp == null) { - if (other.timeStamp != null) - return false; - } else if (!timeStamp.equals(other.timeStamp)) - return false; - return true; - } - + private static final long serialVersionUID = -3581658269910980336L; + + @SerializedName("TimeStamp") + private Instant timeStamp = Instant.now(); + + @SerializedName("APIver") + private String apiVer = "1.01"; + + @SerializedName("OriginatorID") + private String originatorId; + + @SerializedName("RequestID") + private UUID requestId; + + @SerializedName("SubRequestID") + private String subRequestId; + + @SerializedName("RequestTrack") + private Collection<String> requestTrack = new ArrayList<>(); + + @SerializedName("Flags") + private Collection<Map<String, String>> flags = new ArrayList<>(); + + public CommonHeader() {} + + /** + * Construct an instance from an existing instance. + * + * @param commonHeader the existing instance + */ + 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); + } + 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 + "]"; + } + + @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()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + CommonHeader other = (CommonHeader) obj; + if (apiVer == null) { + if (other.apiVer != null) { + return false; + } + } else if (!apiVer.equals(other.apiVer)) { + return false; + } + if (flags == null) { + if (other.flags != null) { + return false; + } + } else if (!flags.equals(other.flags)) { + return false; + } + if (originatorId == null) { + if (other.originatorId != null) { + return false; + } + } else if (!originatorId.equals(other.originatorId)) { + return false; + } + if (requestId == null) { + if (other.requestId != null) { + return false; + } + } else if (!requestId.equals(other.requestId)) { + return false; + } + if (requestTrack == null) { + if (other.requestTrack != null) { + return false; + } + } else if (!requestTrack.equals(other.requestTrack)) { + return false; + } + if (subRequestId == null) { + if (other.subRequestId != null) { + return false; + } + } else if (!subRequestId.equals(other.subRequestId)) { + return false; + } + if (timeStamp == null) { + if (other.timeStamp != null) { + return false; + } + } 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 fd37d31b2..c25e881a8 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -20,133 +20,146 @@ package org.onap.policy.appc; +import com.google.gson.annotations.SerializedName; + import java.io.Serializable; import java.util.HashMap; import java.util.Map; -import com.google.gson.annotations.SerializedName; - -public class Request implements Serializable{ - private static final long serialVersionUID = -3912323643990646431L; - - @SerializedName("CommonHeader") - private CommonHeader commonHeader; - - @SerializedName("Action") - private String action; - - @SerializedName("TargetID") - private String targetID; - - @SerializedName("ObjectID") - private String objectID; - - @SerializedName("Payload") - private HashMap<String, Object> payload = new HashMap<>(); - - public Request() { - // Initiate an empty Request instance - } - - public CommonHeader getCommonHeader() { - return commonHeader; - } - - public Map<String, Object> getPayload() { - 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()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - - Request other = (Request) obj; - if (action == null) { - if (other.action != null) - return false; - } else if (!action.equals(other.action)) - return false; - - if (commonHeader == null) { - if (other.commonHeader != null) - return false; - } else if (!commonHeader.equals(other.commonHeader)) - return false; - - if (objectID == null) { - if (other.objectID != null) - return false; - } else if (!objectID.equals(other.objectID)) - return false; - - if (payload == null) { - if (other.payload != null) - return false; - } else if (!payload.equals(other.payload)) - return false; - - if (targetID == null) { - if (other.targetID != null) - return false; - } 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 + "]"; - } +public class Request implements Serializable { + private static final long serialVersionUID = -3912323643990646431L; + + @SerializedName("CommonHeader") + private CommonHeader commonHeader; + + @SerializedName("Action") + private String action; + + @SerializedName("TargetID") + private String targetId; + + @SerializedName("ObjectID") + private String objectId; + + @SerializedName("Payload") + private HashMap<String, Object> payload = new HashMap<>(); + + public Request() { + // Initiate an empty Request instance + } + + public CommonHeader getCommonHeader() { + return commonHeader; + } + + public Map<String, Object> getPayload() { + 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()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + + Request other = (Request) obj; + if (action == null) { + if (other.action != null) { + return false; + } + } else if (!action.equals(other.action)) { + return false; + } + + if (commonHeader == null) { + if (other.commonHeader != null) { + return false; + } + } else if (!commonHeader.equals(other.commonHeader)) { + return false; + } + + if (objectId == null) { + if (other.objectId != null) { + return false; + } + } else if (!objectId.equals(other.objectId)) { + return false; + } + + if (payload == null) { + if (other.payload != null) { + return false; + } + } else if (!payload.equals(other.payload)) { + return false; + } + + if (targetId == null) { + if (other.targetId != null) { + return false; + } + } 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 + "]"; + } } 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 b117350ae..af503b104 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -20,101 +20,117 @@ package org.onap.policy.appc; +import com.google.gson.annotations.SerializedName; + import java.io.Serializable; import java.util.HashMap; import java.util.Map; -import com.google.gson.annotations.SerializedName; - public class Response implements Serializable { - private static final long serialVersionUID = 434953706339865151L; - - @SerializedName("CommonHeader") - private CommonHeader commonHeader; - - @SerializedName("Status") - private ResponseStatus status = new ResponseStatus(); - - @SerializedName("Payload") - private HashMap<String, Object> payload = new HashMap<>(); - - public Response() { - - } - - public Response(Request request) { - if (request.getCommonHeader() != null) { - this.commonHeader = new CommonHeader(request.getCommonHeader()); - } - if (request.getPayload() != null) { - this.payload.putAll(request.getPayload()); - } - } - - public CommonHeader getCommonHeader() { - return commonHeader; - } - - public void setCommonHeader(CommonHeader commonHeader) { - this.commonHeader = commonHeader; - } - - public ResponseStatus getStatus() { - return status; - } - - public void setStatus(ResponseStatus status) { - this.status = status; - } - - public Map<String, Object> getPayload() { - return payload; - } - - public void setPayload(Map<String, Object> payload) { - this.payload = new HashMap<>(payload); - } - - @Override - public String toString() { - 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()); - return result; - } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Response other = (Response) obj; - if (commonHeader == null) { - if (other.commonHeader != null) - return false; - } else if (!commonHeader.equals(other.commonHeader)) - return false; - if (payload == null) { - if (other.payload != null) - return false; - } else if (!payload.equals(other.payload)) - return false; - if (status == null) { - if (other.status != null) - return false; - } else if (!status.equals(other.status)) - return false; - return true; - } - - - + private static final long serialVersionUID = 434953706339865151L; + + @SerializedName("CommonHeader") + private CommonHeader commonHeader; + + @SerializedName("Status") + private ResponseStatus status = new ResponseStatus(); + + @SerializedName("Payload") + private HashMap<String, Object> payload = new HashMap<>(); + + public Response() { + + } + + /** + * Construct an instance from an existing instance. + * + * @param request the existing instance + */ + public Response(Request request) { + if (request.getCommonHeader() != null) { + this.commonHeader = new CommonHeader(request.getCommonHeader()); + } + if (request.getPayload() != null) { + this.payload.putAll(request.getPayload()); + } + } + + public CommonHeader getCommonHeader() { + return commonHeader; + } + + public void setCommonHeader(CommonHeader commonHeader) { + this.commonHeader = commonHeader; + } + + public ResponseStatus getStatus() { + return status; + } + + public void setStatus(ResponseStatus status) { + this.status = status; + } + + public Map<String, Object> getPayload() { + return payload; + } + + public void setPayload(Map<String, Object> payload) { + this.payload = new HashMap<>(payload); + } + + @Override + public String toString() { + 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()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Response other = (Response) obj; + if (commonHeader == null) { + if (other.commonHeader != null) { + return false; + } + } else if (!commonHeader.equals(other.commonHeader)) { + return false; + } + if (payload == null) { + if (other.payload != null) { + return false; + } + } else if (!payload.equals(other.payload)) { + return false; + } + if (status == null) { + if (other.status != null) { + return false; + } + } 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 3b0d445aa..b62f917ba 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -23,45 +23,46 @@ package org.onap.policy.appc; import com.google.gson.annotations.SerializedName; public enum ResponseCode { - ACCEPT(100), - ERROR(200), - REJECT(300), - SUCCESS(400), - FAILURE(500) - ; + ACCEPT(100), ERROR(200), REJECT(300), SUCCESS(400), FAILURE(500); - @SerializedName("Code") - private Integer code; + @SerializedName("Code") + private Integer code; - private ResponseCode(int code) { - this.code = code; - } + private ResponseCode(int code) { + this.code = code; + } - public int getValue() { - return this.code; - } + public int getValue() { + return this.code; + } - @Override - public String toString() { - return Integer.toString(this.code); - } + @Override + public String toString() { + return Integer.toString(this.code); + } - public static ResponseCode toResponseCode(int code) { - if (code == ACCEPT.code) { - return ACCEPT; - } - if (code == ERROR.code) { - return ERROR; - } - if (code == REJECT.code) { - return REJECT; - } - if (code == SUCCESS.code) { - return SUCCESS; - } - if (code == FAILURE.code) { - return FAILURE; - } - return null; - } + /** + * Convert an integer code to a ResponseCode. + * + * @param code the integer code + * @return the ResponseCode + */ + public static ResponseCode toResponseCode(int code) { + if (code == ACCEPT.code) { + return ACCEPT; + } + if (code == ERROR.code) { + return ERROR; + } + if (code == REJECT.code) { + return REJECT; + } + if (code == SUCCESS.code) { + return SUCCESS; + } + if (code == FAILURE.code) { + return FAILURE; + } + return null; + } } 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 7f85ac7a7..f54117862 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -20,83 +20,91 @@ package org.onap.policy.appc; -import java.io.Serializable; - import com.google.gson.annotations.SerializedName; +import java.io.Serializable; + public class ResponseStatus implements Serializable { - private static final long serialVersionUID = 2421770469587860452L; - - @SerializedName("Code") - private int code; - - @SerializedName("Value") - private String value; - - @SerializedName("Description") - private String description; - - @Override - public String toString() { - 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()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - ResponseStatus other = (ResponseStatus) obj; - if (code != other.code) - return false; - if (description == null) { - if (other.description != null) - return false; - } else if (!description.equals(other.description)) - return false; - if (value == null) { - if (other.value != null) - return false; - } else if (!value.equals(other.value)) - return false; - return true; - } - + private static final long serialVersionUID = 2421770469587860452L; + + @SerializedName("Code") + private int code; + + @SerializedName("Value") + private String value; + + @SerializedName("Description") + private String description; + + @Override + public String toString() { + 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()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + ResponseStatus other = (ResponseStatus) obj; + if (code != other.code) { + return false; + } + if (description == null) { + if (other.description != null) { + return false; + } + } else if (!description.equals(other.description)) { + return false; + } + if (value == null) { + if (other.value != null) { + return false; + } + } 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 8d9bede23..a12f9d139 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -23,47 +23,48 @@ package org.onap.policy.appc; import com.google.gson.annotations.SerializedName; public enum ResponseValue { - ACCEPT("ACCEPT"), - ERROR("ERROR"), - REJECT("REJECT"), - SUCCESS("SUCCESS"), - FAILURE("FAILURE") - ; - - @SerializedName("Value") - private String value; - - private ResponseValue(String value) { - this.value = value; - } + ACCEPT("ACCEPT"), ERROR("ERROR"), REJECT("REJECT"), SUCCESS("SUCCESS"), FAILURE("FAILURE"); - @Override - public String toString() { - return this.value; - } + @SerializedName("Value") + private String value; + + private ResponseValue(String value) { + this.value = value; + } + + @Override + public String toString() { + return this.value; + } + + /** + * Convert a String value to a ResponseValue. + * + * @param value the String value + * @return the ResponseValue + */ + public static ResponseValue toResponseValue(String value) { + if (value == null) { + return null; + } + + if (value.equals(ACCEPT.toString())) { + return ACCEPT; + } + if (value.equals(ERROR.toString())) { + return ERROR; + } + if (value.equals(REJECT.toString())) { + return REJECT; + } + if (value.equals(SUCCESS.toString())) { + return SUCCESS; + } + if (value.equals(FAILURE.toString())) { + return FAILURE; + } + + return null; + } - public static ResponseValue toResponseValue(String value) { - if (value == null) { - return null; - } - - if (value.equals(ACCEPT.toString())) { - return ACCEPT; - } - if (value.equals(ERROR.toString())) { - return ERROR; - } - if (value.equals(REJECT.toString())) { - return REJECT; - } - if (value.equals(SUCCESS.toString())) { - return SUCCESS; - } - if (value.equals(FAILURE.toString())) { - return FAILURE; - } - - return null; - } - } 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 6e04ee977..3e16f2943 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -20,14 +20,6 @@ package org.onap.policy.appc.util; -import java.lang.reflect.Type; -import java.time.Instant; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonDeserializationContext; @@ -37,51 +29,57 @@ import com.google.gson.JsonPrimitive; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; +import java.lang.reflect.Type; +import java.time.Instant; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public final class Serialization { - public static final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx"); + 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); + + @Override + public ZonedDateTime deserialize(JsonElement element, Type type, JsonDeserializationContext context) { + try { + return ZonedDateTime.parse(element.getAsString(), format); + } catch (Exception e) { + logger.error("deserialize threw: ", e); + } + return null; + } + + @Override + public JsonElement serialize(ZonedDateTime datetime, Type type, JsonSerializationContext context) { + return new JsonPrimitive(datetime.format(format)); + } + } - private Serialization(){ - } + public static class GsonInstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { - 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) { - try { - return ZonedDateTime.parse(element.getAsString(), format); - } catch (Exception e) { - logger.error("deserialize threw: ", e); - } - return null; - } + @Override + public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { + return Instant.ofEpochMilli(json.getAsLong()); + } - public JsonElement serialize(ZonedDateTime datetime, Type type, JsonSerializationContext context) { - return new JsonPrimitive(datetime.format(format)); - } - } - - public static class GSONInstantAdapter implements JsonSerializer<Instant>, JsonDeserializer<Instant> { + @Override + public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.toEpochMilli()); + } - @Override - public Instant deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) { - return Instant.ofEpochMilli(json.getAsLong()); - } + } - @Override - public JsonElement serialize(Instant src, Type typeOfSrc, JsonSerializationContext context) { - return new JsonPrimitive(src.toEpochMilli()); - } - - } + public static final Gson gsonPretty = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting() + .registerTypeAdapter(ZonedDateTime.class, new GsonUtcAdapter()) + .registerTypeAdapter(Instant.class, new GsonInstantAdapter()) + // .registerTypeAdapter(CommonHeader1607.class, new gsonCommonHeaderInstance()) + // .registerTypeAdapter(ResponseStatus1607.class, new gsonResponseStatus()) + .create(); - public static final Gson gsonPretty = new GsonBuilder() - .disableHtmlEscaping() - .setPrettyPrinting() - .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 index 039117272..2e456bca0 100644 --- 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -40,7 +40,11 @@ package org.onap.policy.appc; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.time.Instant; import java.util.ArrayList; @@ -52,56 +56,56 @@ 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)); - + @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.setOriginatorId(commonHeader.getOriginatorId()); + copiedCommonHeader.setRequestId(commonHeader.getRequestId()); copiedCommonHeader.setRequestTrack(commonHeader.getRequestTrack()); - copiedCommonHeader.setSubRequestID(commonHeader.getSubRequestID()); + 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()); @@ -116,7 +120,7 @@ public class TestCommonHeader { assertFalse(commonHeader.equals(copiedCommonHeader)); copiedCommonHeader.setApiVer("Kansas"); assertTrue(commonHeader.equals(copiedCommonHeader)); - + commonHeader.setFlags(null); assertFalse(commonHeader.equals(copiedCommonHeader)); copiedCommonHeader.setFlags(null); @@ -125,50 +129,50 @@ public class TestCommonHeader { assertFalse(commonHeader.equals(copiedCommonHeader)); copiedCommonHeader.setFlags(flagSet); assertTrue(commonHeader.equals(copiedCommonHeader)); - - commonHeader.setOriginatorID(null); + + commonHeader.setOriginatorId(null); assertFalse(commonHeader.equals(copiedCommonHeader)); - copiedCommonHeader.setOriginatorID(null); + copiedCommonHeader.setOriginatorId(null); assertTrue(commonHeader.equals(copiedCommonHeader)); - commonHeader.setOriginatorID("Dorothy"); + commonHeader.setOriginatorId("Dorothy"); assertFalse(commonHeader.equals(copiedCommonHeader)); - copiedCommonHeader.setOriginatorID("Dorothy"); + copiedCommonHeader.setOriginatorId("Dorothy"); assertTrue(commonHeader.equals(copiedCommonHeader)); - - commonHeader.setRequestID(null); + + commonHeader.setRequestId(null); assertFalse(commonHeader.equals(copiedCommonHeader)); - copiedCommonHeader.setRequestID(null); + copiedCommonHeader.setRequestId(null); assertTrue(commonHeader.equals(copiedCommonHeader)); - commonHeader.setRequestID(requestID); + commonHeader.setRequestId(requestId); assertFalse(commonHeader.equals(copiedCommonHeader)); - copiedCommonHeader.setRequestID(requestID); + copiedCommonHeader.setRequestId(requestId); assertTrue(commonHeader.equals(copiedCommonHeader)); - + commonHeader.setRequestTrack(null); assertFalse(commonHeader.equals(copiedCommonHeader)); - copiedCommonHeader.setRequestTrack(null); + copiedCommonHeader.setRequestTrack(null); assertTrue(commonHeader.equals(copiedCommonHeader)); commonHeader.setRequestTrack(requestTrackSet); assertFalse(commonHeader.equals(copiedCommonHeader)); - copiedCommonHeader.setRequestTrack(requestTrackSet); + copiedCommonHeader.setRequestTrack(requestTrackSet); assertTrue(commonHeader.equals(copiedCommonHeader)); - - commonHeader.setSubRequestID(null); + + commonHeader.setSubRequestId(null); assertFalse(commonHeader.equals(copiedCommonHeader)); - copiedCommonHeader.setSubRequestID(null); + copiedCommonHeader.setSubRequestId(null); assertTrue(commonHeader.equals(copiedCommonHeader)); - commonHeader.setSubRequestID("Can I go home?"); + commonHeader.setSubRequestId("Can I go home?"); assertFalse(commonHeader.equals(copiedCommonHeader)); - copiedCommonHeader.setSubRequestID("Can I go home?"); + copiedCommonHeader.setSubRequestId("Can I go home?"); assertTrue(commonHeader.equals(copiedCommonHeader)); - + commonHeader.setTimeStamp(null); assertFalse(commonHeader.equals(copiedCommonHeader)); - copiedCommonHeader.setTimeStamp(null); + copiedCommonHeader.setTimeStamp(null); assertTrue(commonHeader.equals(copiedCommonHeader)); commonHeader.setTimeStamp(timestamp); assertFalse(commonHeader.equals(copiedCommonHeader)); - copiedCommonHeader.setTimeStamp(timestamp); + 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 index e04da3cce..95adec84f 100644 --- 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -20,54 +20,55 @@ package org.onap.policy.appc; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; 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()); + @Test + public void testResponseCode() { + assertEquals(5, ResponseCode.values().length); - 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()); - } + assertNull(ResponseCode.toResponseCode(0)); - @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(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("ACCEPT", ResponseValue.ACCEPT.toString()); - assertEquals("ERROR", ResponseValue.ERROR.toString()); - assertEquals("REJECT", ResponseValue.REJECT.toString()); - assertEquals("SUCCESS", ResponseValue.SUCCESS.toString()); - assertEquals("FAILURE", ResponseValue.FAILURE.toString()); - } + 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 index 6fdfe0968..462fb7a01 100644 --- 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -20,7 +20,11 @@ package org.onap.policy.appc; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.util.HashMap; import java.util.Map; @@ -29,49 +33,49 @@ 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)); - + @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.setObjectId(request.getObjectId()); copiedRequest.setPayload(request.getPayload()); - copiedRequest.setTargetID(request.getTargetID()); + 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); @@ -80,7 +84,7 @@ public class TestRequest { assertFalse(request.equals(copiedRequest)); copiedRequest.setCommonHeader(commonHeader); assertTrue(request.equals(copiedRequest)); - + request.setAction(null); assertFalse(request.equals(copiedRequest)); copiedRequest.setAction(null); @@ -89,32 +93,32 @@ public class TestRequest { assertFalse(request.equals(copiedRequest)); copiedRequest.setAction("Go to Oz"); assertTrue(request.equals(copiedRequest)); - - request.setObjectID(null); + + request.setObjectId(null); assertFalse(request.equals(copiedRequest)); - copiedRequest.setObjectID(null); + copiedRequest.setObjectId(null); assertTrue(request.equals(copiedRequest)); - request.setObjectID("Wizard"); + request.setObjectId("Wizard"); assertFalse(request.equals(copiedRequest)); - copiedRequest.setObjectID("Wizard"); + copiedRequest.setObjectId("Wizard"); assertTrue(request.equals(copiedRequest)); - - request.setTargetID(null); + + request.setTargetId(null); assertFalse(request.equals(copiedRequest)); - copiedRequest.setTargetID(null); + copiedRequest.setTargetId(null); assertTrue(request.equals(copiedRequest)); - request.setTargetID("Oz"); + request.setTargetId("Oz"); assertFalse(request.equals(copiedRequest)); - copiedRequest.setTargetID("Oz"); + copiedRequest.setTargetId("Oz"); assertTrue(request.equals(copiedRequest)); - + request.setPayload(new HashMap<String, Object>()); assertFalse(request.equals(copiedRequest)); - copiedRequest.setPayload(new HashMap<String, Object>()); + copiedRequest.setPayload(new HashMap<String, Object>()); assertTrue(request.equals(copiedRequest)); request.setPayload(payload); assertFalse(request.equals(copiedRequest)); - copiedRequest.setPayload(payload); + 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 index 5306a3344..bf5fec86a 100644 --- 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -20,7 +20,11 @@ package org.onap.policy.appc; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.util.HashMap; import java.util.Map; @@ -29,37 +33,37 @@ 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)); - + @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()); @@ -69,7 +73,7 @@ public class TestResponse { assertTrue(response.equals(copiedResponse)); assertFalse(response.equals(null)); assertFalse(response.equals("Hello")); - + response.setCommonHeader(null); assertFalse(response.equals(copiedResponse)); copiedResponse.setCommonHeader(null); @@ -78,7 +82,7 @@ public class TestResponse { assertFalse(response.equals(copiedResponse)); copiedResponse.setCommonHeader(commonHeader); assertTrue(response.equals(copiedResponse)); - + response.setStatus(null); assertFalse(response.equals(copiedResponse)); copiedResponse.setStatus(null); @@ -87,14 +91,14 @@ public class TestResponse { 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>()); + copiedResponse.setPayload(new HashMap<String, Object>()); assertTrue(response.equals(copiedResponse)); response.setPayload(payload); assertFalse(response.equals(copiedResponse)); - copiedResponse.setPayload(payload); + 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 index 0cac93ca4..46d8a0b25 100644 --- 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -20,30 +20,34 @@ package org.onap.policy.appc; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; 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)); - + @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()); @@ -53,7 +57,7 @@ public class TestResponseStatus { assertTrue(status.equals(copiedStatus)); assertFalse(status.equals(null)); assertFalse(status.equals("Hello")); - + status.setCode(-1); assertFalse(status.equals(copiedStatus)); copiedStatus.setCode(-1); @@ -62,7 +66,7 @@ public class TestResponseStatus { assertFalse(status.equals(copiedStatus)); copiedStatus.setCode(1234); assertTrue(status.equals(copiedStatus)); - + status.setDescription(null); assertFalse(status.equals(copiedStatus)); copiedStatus.setDescription(null); @@ -71,7 +75,7 @@ public class TestResponseStatus { 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); @@ -80,5 +84,5 @@ public class TestResponseStatus { 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 index 0a82892ea..ae1890acf 100644 --- 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 @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * appc * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2018 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. @@ -20,7 +20,8 @@ package org.onap.policy.appc.util; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import java.time.Instant; import java.time.ZoneId; @@ -30,26 +31,26 @@ 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)); - } + @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)); + } } |