diff options
author | Jim Hahn <jrh3@att.com> | 2019-02-15 12:24:14 -0500 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-02-15 12:26:37 -0500 |
commit | cb8557e068ec89473dcb4d01a68e7dfd0a4644c5 (patch) | |
tree | 4e5eaea52f9a5f5416e75f28f18b5ffdef0b86e6 /policy-management/src/main/java/org/onap | |
parent | b47140e63ebc5d878c66935698df99a987a6418e (diff) |
Test gson in policy-management
Added jackson-like Gson annotations to policy-management classes.
Also added tests to verify that the classes serialize the same
with gson as with jackson.
Removed some trailing spaces.
Replaced tabs and adjusted spacing in json files.
Removed trailing newlines.
Updated license data per review comment.
Fixed merge conflict.
Added files that were inadvertently deleted.
Change-Id: Ib546e70f9d9d83187a6a93ff5c634000c4d53da5
Issue-ID: POLICY-1431
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'policy-management/src/main/java/org/onap')
8 files changed, 84 insertions, 10 deletions
diff --git a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java index 55352fe2..6a4b8f22 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java @@ -36,6 +36,8 @@ import org.kie.api.runtime.rule.FactHandle; import org.kie.api.runtime.rule.QueryResults; import org.kie.api.runtime.rule.QueryResultsRow; import org.onap.policy.common.endpoints.event.comm.TopicSink; +import org.onap.policy.common.gson.annotation.GsonJsonIgnore; +import org.onap.policy.common.gson.annotation.GsonJsonProperty; import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.core.PolicyContainer; import org.onap.policy.drools.core.PolicySession; @@ -67,6 +69,7 @@ public class MavenDroolsController implements DroolsController { * Policy Container, the access object to the policy-core layer. */ @JsonIgnore + @GsonJsonIgnore protected final PolicyContainer policyContainer; /** @@ -646,12 +649,14 @@ public class MavenDroolsController implements DroolsController { } @JsonIgnore + @GsonJsonIgnore @Override public PolicyContainer getContainer() { return this.policyContainer; } @JsonProperty("sessions") + @GsonJsonProperty("sessions") @Override public List<String> getSessionNames() { return getSessionNames(true); @@ -681,6 +686,7 @@ public class MavenDroolsController implements DroolsController { } @JsonProperty("sessionCoordinates") + @GsonJsonProperty("sessionCoordinates") @Override public List<String> getCanonicalSessionNames() { return getSessionNames(false); diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java index 97598df4..f125c134 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java @@ -41,7 +41,7 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; - +import org.onap.policy.common.gson.annotation.GsonJsonIgnore; import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.protocol.coders.EventProtocolCoder.CoderFilters; import org.onap.policy.drools.protocol.coders.TopicCoderFilterConfiguration.CustomCoder; @@ -340,9 +340,11 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { * Formatter for JSON encoding/decoding. */ @JsonIgnore + @GsonJsonIgnore public static final DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSxxx"); @JsonIgnore + @GsonJsonIgnore public static final DateTimeFormatter zuluFormat = DateTimeFormatter.ISO_INSTANT; /** @@ -386,6 +388,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { * decoder. */ @JsonIgnore + @GsonJsonIgnore protected final Gson decoder = new GsonBuilder().disableHtmlEscaping() .registerTypeAdapter(ZonedDateTime.class, new GsonUTCAdapter()) .registerTypeAdapter(Instant.class, new GsonInstantAdapter()).create(); @@ -394,6 +397,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { * encoder. */ @JsonIgnore + @GsonJsonIgnore protected final Gson encoder = new GsonBuilder().disableHtmlEscaping() .registerTypeAdapter(ZonedDateTime.class, new GsonUTCAdapter()) .registerTypeAdapter(Instant.class, new GsonInstantAdapter()).create(); @@ -414,6 +418,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { * @return the Gson decoder */ @JsonIgnore + @GsonJsonIgnore protected Gson getDecoder() { return this.decoder; } @@ -424,6 +429,7 @@ class GsonProtocolCoderToolset extends ProtocolCoderToolset { * @return the Gson encoder */ @JsonIgnore + @GsonJsonIgnore protected Gson getEncoder() { return this.encoder; } diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java index 69e13b43..23a8855f 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java @@ -32,6 +32,10 @@ import java.util.Map; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; +import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter; +import org.onap.policy.common.gson.annotation.GsonJsonAnySetter; +import org.onap.policy.common.gson.annotation.GsonJsonIgnore; +import org.onap.policy.common.gson.annotation.GsonJsonProperty; /** @@ -51,6 +55,7 @@ public class ControllerConfiguration { * */ @JsonProperty("name") + @GsonJsonProperty("name") private String name; /** * Set of operations that can be applied to a controller: create, lock @@ -58,15 +63,20 @@ public class ControllerConfiguration { * */ @JsonProperty("operation") + @GsonJsonProperty("operation") private String operation; /** * Maven Related Information. * */ @JsonProperty("drools") + @GsonJsonProperty("drools") private DroolsConfiguration drools; + @JsonIgnore + @GsonJsonIgnore private Map<String, Object> additionalProperties = new HashMap<>(); + protected static final Object NOT_FOUND_VALUE = new Object(); /** @@ -97,6 +107,7 @@ public class ControllerConfiguration { * The name */ @JsonProperty("name") + @GsonJsonProperty("name") public String getName() { return name; } @@ -108,6 +119,7 @@ public class ControllerConfiguration { * The name */ @JsonProperty("name") + @GsonJsonProperty("name") public void setName(String name) { this.name = name; } @@ -125,6 +137,7 @@ public class ControllerConfiguration { * The operation */ @JsonProperty("operation") + @GsonJsonProperty("operation") public String getOperation() { return operation; } @@ -137,6 +150,7 @@ public class ControllerConfiguration { * The operation */ @JsonProperty("operation") + @GsonJsonProperty("operation") public void setOperation(String operation) { this.operation = operation; } @@ -153,6 +167,7 @@ public class ControllerConfiguration { * The drools */ @JsonProperty("drools") + @GsonJsonProperty("drools") public DroolsConfiguration getDrools() { return drools; } @@ -164,6 +179,7 @@ public class ControllerConfiguration { * The drools */ @JsonProperty("drools") + @GsonJsonProperty("drools") public void setDrools(DroolsConfiguration drools) { this.drools = drools; } @@ -179,11 +195,13 @@ public class ControllerConfiguration { } @JsonAnyGetter + @GsonJsonAnyGetter public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; } @JsonAnySetter + @GsonJsonAnySetter public void setAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); } diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java index e1f7f63a..9c0e125b 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 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. @@ -32,6 +32,10 @@ import java.util.Map; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; +import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter; +import org.onap.policy.common.gson.annotation.GsonJsonAnySetter; +import org.onap.policy.common.gson.annotation.GsonJsonIgnore; +import org.onap.policy.common.gson.annotation.GsonJsonProperty; /** * Maven Related Information. @@ -46,6 +50,7 @@ public class DroolsConfiguration { * */ @JsonProperty("artifactId") + @GsonJsonProperty("artifactId") private String artifactId; /** @@ -54,6 +59,7 @@ public class DroolsConfiguration { * */ @JsonProperty("groupId") + @GsonJsonProperty("groupId") private String groupId; /** @@ -62,9 +68,13 @@ public class DroolsConfiguration { * */ @JsonProperty("version") + @GsonJsonProperty("version") private String version; + @JsonIgnore + @GsonJsonIgnore private Map<String, Object> additionalProperties = new HashMap<>(); + protected static final Object NOT_FOUND_VALUE = new Object(); /** @@ -96,6 +106,7 @@ public class DroolsConfiguration { * The artifactId */ @JsonProperty("artifactId") + @GsonJsonProperty("artifactId") public String getArtifactId() { return artifactId; } @@ -108,6 +119,7 @@ public class DroolsConfiguration { * The artifactId */ @JsonProperty("artifactId") + @GsonJsonProperty("artifactId") public void setArtifactId(String artifactId) { this.artifactId = artifactId; } @@ -125,6 +137,7 @@ public class DroolsConfiguration { * The groupId */ @JsonProperty("groupId") + @GsonJsonProperty("groupId") public String getGroupId() { return groupId; } @@ -137,6 +150,7 @@ public class DroolsConfiguration { * The groupId */ @JsonProperty("groupId") + @GsonJsonProperty("groupId") public void setGroupId(String groupId) { this.groupId = groupId; } @@ -154,6 +168,7 @@ public class DroolsConfiguration { * The version */ @JsonProperty("version") + @GsonJsonProperty("version") public String getVersion() { return version; } @@ -166,6 +181,7 @@ public class DroolsConfiguration { * The version */ @JsonProperty("version") + @GsonJsonProperty("version") public void setVersion(String version) { this.version = version; } @@ -181,11 +197,13 @@ public class DroolsConfiguration { } @JsonAnyGetter + @GsonJsonAnyGetter public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; } @JsonAnySetter + @GsonJsonAnySetter public void setAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); } diff --git a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java index 58cd67fd..f83f480e 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java +++ b/policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 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. @@ -32,6 +32,10 @@ import java.util.Map; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import org.apache.commons.lang3.builder.ToStringBuilder; +import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter; +import org.onap.policy.common.gson.annotation.GsonJsonAnySetter; +import org.onap.policy.common.gson.annotation.GsonJsonIgnore; +import org.onap.policy.common.gson.annotation.GsonJsonProperty; /** @@ -45,15 +49,18 @@ public class PdpdConfiguration { /** Unique Transaction ID. This is an UUID. (Required) */ @JsonProperty("requestID") + @GsonJsonProperty("requestID") private String requestID; /* Set of entities on which configuration can be performed: controller (Required) */ @JsonProperty("entity") + @GsonJsonProperty("entity") private String entity; /* Controller Information, only applicable when the entity is set to controller */ @JsonProperty("controllers") + @GsonJsonProperty("controllers") private List<ControllerConfiguration> controllers = new ArrayList<>(); - @JsonIgnore private Map<String, Object> additionalProperties = new HashMap<>(); + @JsonIgnore @GsonJsonIgnore private Map<String, Object> additionalProperties = new HashMap<>(); protected static final Object NOT_FOUND_VALUE = new Object(); /** No args constructor for use in serialization. */ @@ -81,6 +88,7 @@ public class PdpdConfiguration { * @return The requestID */ @JsonProperty("requestID") + @GsonJsonProperty("requestID") public String getRequestID() { return requestID; } @@ -91,6 +99,7 @@ public class PdpdConfiguration { * @param requestID The requestID */ @JsonProperty("requestID") + @GsonJsonProperty("requestID") public void setRequestID(String requestID) { this.requestID = requestID; } @@ -106,6 +115,7 @@ public class PdpdConfiguration { * @return The entity */ @JsonProperty("entity") + @GsonJsonProperty("entity") public String getEntity() { return entity; } @@ -116,6 +126,7 @@ public class PdpdConfiguration { * @param entity The entity */ @JsonProperty("entity") + @GsonJsonProperty("entity") public void setEntity(String entity) { this.entity = entity; } @@ -130,7 +141,8 @@ public class PdpdConfiguration { * * @return The controller */ - @JsonProperty("controller") + @JsonProperty("controllers") + @GsonJsonProperty("controllers") public List<ControllerConfiguration> getControllers() { return controllers; } @@ -140,7 +152,8 @@ public class PdpdConfiguration { * * @param controllers controllers */ - @JsonProperty("controller") + @JsonProperty("controllers") + @GsonJsonProperty("controllers") public void setControllers(List<ControllerConfiguration> controllers) { this.controllers = controllers; } @@ -156,11 +169,13 @@ public class PdpdConfiguration { } @JsonAnyGetter + @GsonJsonAnyGetter public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; } @JsonAnySetter + @GsonJsonAnySetter public void setAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); } diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java index c0749790..8baf667a 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 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. @@ -26,7 +26,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Properties; - +import org.onap.policy.common.gson.annotation.GsonJsonIgnore; import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.features.PolicyControllerFeatureAPI; import org.onap.policy.drools.protocol.configuration.DroolsConfiguration; @@ -489,6 +489,7 @@ class IndexedPolicyControllerFactory implements PolicyControllerFactory { * {@inheritDoc}. */ @JsonIgnore + @GsonJsonIgnore @Override public List<PolicyControllerFeatureAPI> getFeatureProviders() { return getProviders(); diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java index e08b3704..959114a2 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 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,6 +40,8 @@ import org.onap.policy.common.endpoints.event.comm.TopicSource; import org.onap.policy.common.endpoints.http.server.HttpServletServer; import org.onap.policy.common.endpoints.http.server.HttpServletServerFactory; import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties; +import org.onap.policy.common.gson.annotation.GsonJsonIgnore; +import org.onap.policy.common.gson.annotation.GsonJsonProperty; import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.core.PolicyContainer; import org.onap.policy.drools.core.jmx.PdpJmxListener; @@ -431,6 +433,7 @@ class PolicyEngineManager implements PolicyEngine { } @JsonIgnore + @GsonJsonIgnore @Override public synchronized Properties getEnvironment() { return this.environment; @@ -1167,12 +1170,14 @@ class PolicyEngineManager implements PolicyEngine { } @JsonIgnore + @GsonJsonIgnore @Override public List<PolicyController> getPolicyControllers() { return getControllerFactory().inventory(); } @JsonProperty("controllers") + @GsonJsonProperty("controllers") @Override public List<String> getPolicyControllerIds() { final List<String> controllerNames = new ArrayList<>(); @@ -1184,6 +1189,7 @@ class PolicyEngineManager implements PolicyEngine { @Override @JsonIgnore + @GsonJsonIgnore public Properties getProperties() { return this.properties; } @@ -1216,6 +1222,7 @@ class PolicyEngineManager implements PolicyEngine { } @JsonIgnore + @GsonJsonIgnore @Override public List<PolicyEngineFeatureAPI> getFeatureProviders() { return getEngineProviders(); diff --git a/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java b/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java index cd578fca..5bfde9a7 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java +++ b/policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * policy-management * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 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. @@ -31,6 +31,7 @@ import org.onap.policy.common.endpoints.event.comm.TopicEndpoint; import org.onap.policy.common.endpoints.event.comm.TopicListener; import org.onap.policy.common.endpoints.event.comm.TopicSink; import org.onap.policy.common.endpoints.event.comm.TopicSource; +import org.onap.policy.common.gson.annotation.GsonJsonIgnore; import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.controller.DroolsControllerFactory; import org.onap.policy.drools.features.PolicyControllerFeatureAPI; @@ -71,6 +72,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen * Mapping topics to sinks. */ @JsonIgnore + @GsonJsonIgnore private final HashMap<String, TopicSink> topic2Sinks = new HashMap<>(); /** @@ -624,6 +626,7 @@ public class AggregatedPolicyController implements PolicyController, TopicListen */ @Override @JsonIgnore + @GsonJsonIgnore public Properties getProperties() { return this.properties; } |