aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--policy-management/pom.xml6
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/controller/internal/MavenDroolsController.java6
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/coders/ProtocolCoderToolset.java8
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/ControllerConfiguration.java18
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/DroolsConfiguration.java20
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/protocol/configuration/PdpdConfiguration.java23
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyControllerFactory.java5
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/PolicyEngine.java9
-rw-r--r--policy-management/src/main/java/org/onap/policy/drools/system/internal/AggregatedPolicyController.java5
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsControllerTest.java5
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.java6
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/ControllerConfigurationTest.java69
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.java24
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/PdpdConfigurationTest.java47
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/GsonMgmtTestBuilder.java162
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyControllerFactoryTest.java8
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java20
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java20
-rw-r--r--policy-management/src/test/java/org/onap/policy/drools/system/internal/AggregatedPolicyControllerTest.java7
-rw-r--r--policy-management/src/test/resources/org/onap/policy/drools/controller/internal/MavenDroolsControllerTest.json14
-rw-r--r--policy-management/src/test/resources/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.json14
-rw-r--r--policy-management/src/test/resources/org/onap/policy/drools/protocol/configuration/ControllerConfigurationTest.json11
-rw-r--r--policy-management/src/test/resources/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.json7
-rw-r--r--policy-management/src/test/resources/org/onap/policy/drools/protocol/configuration/PdpdConfigurationTest.json14
-rw-r--r--policy-management/src/test/resources/org/onap/policy/drools/system/PolicyControllerFactoryTest.json3
-rw-r--r--policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineManagerTest.json24
-rw-r--r--policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestAdd.json20
-rw-r--r--policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestConfig.json18
-rw-r--r--policy-management/src/test/resources/org/onap/policy/drools/system/internal/AggregatedPolicyControllerTest.json18
29 files changed, 555 insertions, 56 deletions
diff --git a/policy-management/pom.xml b/policy-management/pom.xml
index 557e1f44..d0bbb1db 100644
--- a/policy-management/pom.xml
+++ b/policy-management/pom.xml
@@ -222,6 +222,12 @@
</dependency>
<dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>gson</artifactId>
+ <version>${policy.common.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
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;
}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsControllerTest.java b/policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsControllerTest.java
index dce38f9b..4c262775 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsControllerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/controller/internal/MavenDroolsControllerTest.java
@@ -26,6 +26,7 @@ import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.kie.api.builder.ReleaseId;
+import org.onap.policy.common.utils.gson.GsonTestUtils;
import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.util.KieUtils;
@@ -43,7 +44,7 @@ public class MavenDroolsControllerTest {
/**
* Set up.
- *
+ *
* @throws IOException throws an IO exception
*/
@BeforeClass
@@ -77,6 +78,8 @@ public class MavenDroolsControllerTest {
controller.halt();
Assert.assertFalse(controller.isAlive());
+
+ new GsonTestUtils().compareGson(controller, MavenDroolsControllerTest.class);
}
private DroolsController createDroolsController(long courtesyStartTimeMs) throws InterruptedException {
diff --git a/policy-management/src/test/java/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.java b/policy-management/src/test/java/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.java
index 8cb754c1..77da1c1f 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.java
@@ -22,6 +22,7 @@ package org.onap.policy.drools.controller.internal;
import org.junit.Assert;
import org.junit.Test;
+import org.onap.policy.common.utils.gson.GsonTestUtils;
import org.onap.policy.drools.controller.DroolsController;
public class NullDroolsControllerTest {
@@ -40,6 +41,11 @@ public class NullDroolsControllerTest {
}
@Test
+ public void testSerialize() {
+ new GsonTestUtils().compareGson(new NullDroolsController(), NullDroolsControllerTest.class);
+ }
+
+ @Test
public void lock() {
DroolsController controller = new NullDroolsController();
controller.lock();
diff --git a/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/ControllerConfigurationTest.java b/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/ControllerConfigurationTest.java
index f3817d5c..a3d53eba 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/ControllerConfigurationTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/ControllerConfigurationTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* Configuration Test
* ================================================================================
- * 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -27,78 +27,97 @@ import static org.junit.Assert.assertTrue;
import java.util.Properties;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.junit.Test;
+import org.onap.policy.common.utils.gson.GsonTestUtils;
public class ControllerConfigurationTest {
-
-
+
private static final String NAME = "name";
private static final String OPERATION = "operation";
private static final String NAME2 = "name2";
private static final String OPERATION2 = "operation2";
-
+
private static final String ARTIFACT = "org.onap.artifact";
private static final String GROUPID = "group";
private static final String VERSION = "1.0.0";
-
+
private static final String ARTIFACT2 = "org.onap.artifact2";
private static final String GROUPID2 = "group2";
private static final String VERSION2 = "1.0.1";
-
+
private static final String ADDITIONAL_PROPERTY_KEY = "foo";
private static final String ADDITIONAL_PROPERTY_VALUE = "bar";
-
+
+ private static final String ADDITIONAL_PROPERTY_KEY2 = "hello";
+ private static final String ADDITIONAL_PROPERTY_VALUE2 = "world";
+
private static final DroolsConfiguration DROOLS_CONFIG = new DroolsConfiguration(ARTIFACT, GROUPID, VERSION);
private static final DroolsConfiguration DROOLS_CONFIG2 = new DroolsConfiguration(ARTIFACT2, GROUPID2, VERSION2);
-
+
private static final String DROOLS_STRING = "drools";
-
+
/**
* Test.
*/
@Test
public void test() {
-
+
Properties additionalProperties = new Properties();
additionalProperties.put(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE);
-
+
ControllerConfiguration controllerConfig = new ControllerConfiguration(NAME, OPERATION, DROOLS_CONFIG);
-
+
assertTrue(controllerConfig.equals(controllerConfig));
assertFalse(controllerConfig.equals(new Object()));
-
+
ControllerConfiguration controllerConfig2 = new ControllerConfiguration();
controllerConfig2.setName(NAME2);
controllerConfig2.setOperation(OPERATION2);
controllerConfig2.setDrools(DROOLS_CONFIG2);
-
+
assertEquals(controllerConfig2.getName(), NAME2);
assertEquals(controllerConfig2.getOperation(), OPERATION2);
assertEquals(controllerConfig2.getDrools(), DROOLS_CONFIG2);
-
+
assertEquals(controllerConfig2, controllerConfig2.withName(NAME2));
assertEquals(controllerConfig2, controllerConfig2.withOperation(OPERATION2));
assertEquals(controllerConfig2, controllerConfig2.withDrools(DROOLS_CONFIG2));
-
+
controllerConfig2.setAdditionalProperty(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE);
assertEquals(controllerConfig2.getAdditionalProperties(), additionalProperties);
-
- assertEquals(controllerConfig2, controllerConfig2.withAdditionalProperty(ADDITIONAL_PROPERTY_KEY,
+
+ assertEquals(controllerConfig2, controllerConfig2.withAdditionalProperty(ADDITIONAL_PROPERTY_KEY,
ADDITIONAL_PROPERTY_VALUE));
-
+
assertTrue(controllerConfig2.declaredProperty(NAME, NAME2));
assertTrue(controllerConfig2.declaredProperty(OPERATION, OPERATION2));
assertTrue(controllerConfig2.declaredProperty(DROOLS_STRING, DROOLS_CONFIG2));
assertFalse(controllerConfig2.declaredProperty("dummy", NAME));
-
-
+
+
assertEquals(controllerConfig2.declaredPropertyOrNotFound(NAME, NAME2), NAME2);
assertEquals(controllerConfig2.declaredPropertyOrNotFound(OPERATION, OPERATION2), OPERATION2);
assertEquals(controllerConfig2.declaredPropertyOrNotFound(DROOLS_STRING, DROOLS_CONFIG2), DROOLS_CONFIG2);
assertEquals(controllerConfig2.declaredPropertyOrNotFound("dummy", NAME), NAME);
-
+
int hashCode = new HashCodeBuilder().append(NAME2).append(OPERATION2).append(DROOLS_CONFIG2)
.append(additionalProperties).toHashCode();
assertEquals(controllerConfig2.hashCode(), hashCode);
-
+ }
+
+ @Test
+ public void testSerialize() {
+ ControllerConfiguration controllerConfig = new ControllerConfiguration(NAME, OPERATION, DROOLS_CONFIG);
+ controllerConfig.setAdditionalProperty(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE);
+ controllerConfig.setAdditionalProperty(ADDITIONAL_PROPERTY_KEY2, ADDITIONAL_PROPERTY_VALUE2);
+
+ GsonTestUtils gson = new GsonTestUtils();
+
+ // ensure jackson and gson give same result
+ gson.compareGson(controllerConfig, ControllerConfigurationTest.class);
+
+ // ensure we get the same value when decoding
+ ControllerConfiguration config2 = gson.gsonRoundTrip(controllerConfig, ControllerConfiguration.class);
+ assertEquals(controllerConfig, config2);
+ assertEquals(gson.gsonEncode(controllerConfig), gson.gsonEncode(config2));
}
}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.java b/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.java
index 7d9b6551..4ad4f880 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Configuration Test
* ================================================================================
- * 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.
@@ -25,9 +25,9 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Properties;
-
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.junit.Test;
+import org.onap.policy.common.utils.gson.GsonTestUtils;
public class DroolsConfigurationTest {
private static final String ARTIFACT_ID_STRING = "artifactId";
@@ -47,6 +47,9 @@ public class DroolsConfigurationTest {
private static final String ADDITIONAL_PROPERTY_KEY = "foo";
private static final String ADDITIONAL_PROPERTY_VALUE = "bar";
+ private static final String ADDITIONAL_PROPERTY_KEY2 = "hello";
+ private static final String ADDITIONAL_PROPERTY_VALUE2 = "world";
+
@Test
public void test() {
final Properties additionalProperties = new Properties();
@@ -94,4 +97,21 @@ public class DroolsConfigurationTest {
.append(additionalProperties).toHashCode();
assertEquals(droolsConfig2.hashCode(), hashCode);
}
+
+ @Test
+ public void testSerialize() {
+ final DroolsConfiguration droolsConfig = new DroolsConfiguration(ARTIFACT, GROUPID, VERSION);
+ droolsConfig.setAdditionalProperty(ADDITIONAL_PROPERTY_KEY, ADDITIONAL_PROPERTY_VALUE);
+ droolsConfig.setAdditionalProperty(ADDITIONAL_PROPERTY_KEY2, ADDITIONAL_PROPERTY_VALUE2);
+
+ GsonTestUtils gson = new GsonTestUtils();
+
+ // ensure jackson and gson give same result
+ gson.compareGson(droolsConfig, DroolsConfigurationTest.class);
+
+ // ensure we get the same value when decoding
+ DroolsConfiguration config2 = gson.gsonRoundTrip(droolsConfig, DroolsConfiguration.class);
+ assertEquals(droolsConfig, config2);
+ assertEquals(gson.gsonEncode(droolsConfig), gson.gsonEncode(config2));
+ }
}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/PdpdConfigurationTest.java b/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/PdpdConfigurationTest.java
index b5f3c535..4ab42f44 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/PdpdConfigurationTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/protocol/configuration/PdpdConfigurationTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* Configuration Test
* ================================================================================
- * 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.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -24,11 +24,13 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.UUID;
-
import org.junit.Test;
+import org.onap.policy.common.utils.gson.GsonTestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -82,8 +84,8 @@ public class PdpdConfigurationTest {
// Constructor with values test get calls
//
DroolsConfiguration drools2 = new DroolsConfiguration(
- drools.get("artifactId"),
- drools.get("groupId"),
+ drools.get("artifactId"),
+ drools.get("groupId"),
drools.get("version"));
//
@@ -139,8 +141,8 @@ public class PdpdConfigurationTest {
// Controller Constructor gets
//
ControllerConfiguration controller2 = new ControllerConfiguration(
- controller.get("name"),
- controller.get("operation"),
+ controller.get("name"),
+ controller.get("operation"),
controller.get("drools"));
//
@@ -251,4 +253,33 @@ public class PdpdConfigurationTest {
assertEquals(config.getEntity(), ENTITY);
}
+ @Test
+ public void testSerialize() throws IOException {
+ List<ControllerConfiguration> controllers = Arrays.asList(new ControllerConfiguration(NAME, OPERATION, null),
+ new ControllerConfiguration(NAME2, OPERATION2, null));
+ PdpdConfiguration pdpConfig = new PdpdConfiguration(REQUEST_ID, ENTITY, controllers);
+
+ GsonTestUtils gson = new GsonTestUtils();
+
+ // ensure jackson and gson give same result
+ gson.compareGson(pdpConfig, PdpdConfigurationTest.class);
+
+ // ensure we get the same value when decoding
+ PdpdConfiguration config2 = gson.gsonRoundTrip(pdpConfig, PdpdConfiguration.class);
+ assertEquals(stripIdent(pdpConfig.toString()), stripIdent(config2.toString()));
+ assertEquals(pdpConfig, config2);
+ assertEquals(gson.gsonEncode(pdpConfig), gson.gsonEncode(config2));
+ }
+
+ /**
+ * Object identifiers may change with each execution, so this method is used to strip
+ * the identifier from the text string so that the strings will still match across
+ * different runs.
+ *
+ * @param text text from which to strip the identifier
+ * @return the text, without the identifier
+ */
+ private String stripIdent(String text) {
+ return text.replaceAll("@\\w+", "@");
+ }
}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/GsonMgmtTestBuilder.java b/policy-management/src/test/java/org/onap/policy/drools/system/GsonMgmtTestBuilder.java
new file mode 100644
index 00000000..e6569bc5
--- /dev/null
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/GsonMgmtTestBuilder.java
@@ -0,0 +1,162 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * policy-management
+ * ================================================================================
+ * Copyright (C) 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.drools.system;
+
+import com.google.gson.Gson;
+import com.google.gson.TypeAdapter;
+import com.google.gson.TypeAdapterFactory;
+import com.google.gson.reflect.TypeToken;
+import com.google.gson.stream.JsonWriter;
+import java.io.IOException;
+import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.common.endpoints.event.comm.TopicSource;
+import org.onap.policy.common.endpoints.http.server.HttpServletServer;
+import org.onap.policy.common.utils.gson.GsonSerializer;
+import org.onap.policy.common.utils.gson.GsonTestUtilsBuilder;
+import org.onap.policy.drools.controller.DroolsController;
+
+/**
+ * Utilities used to test encoding and decoding of Policy objects.
+ */
+public class GsonMgmtTestBuilder extends GsonTestUtilsBuilder {
+
+ /**
+ * Adds support for serializing a topic source mock.
+ *
+ * @return the builder
+ */
+ public GsonMgmtTestBuilder addTopicSourceMock() {
+ TypeAdapterFactory sgson = new TypeAdapterFactory() {
+ @Override
+ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
+ Class<? super T> clazz = type.getRawType();
+
+ if (TopicSource.class.isAssignableFrom(clazz)) {
+ return new GsonSerializer<T>() {
+ @Override
+ public void write(JsonWriter out, T value) throws IOException {
+ TopicSource obj = (TopicSource) value;
+ out.beginObject().name("name").value(obj.getTopic()).endObject();
+ }
+ };
+ }
+
+ return null;
+ }
+ };
+
+ addMock(TopicSource.class, sgson);
+
+ return this;
+ }
+
+ /**
+ * Adds support for serializing a topic sink mock.
+ *
+ * @return the builder
+ */
+ public GsonMgmtTestBuilder addTopicSinkMock() {
+ TypeAdapterFactory sgson = new TypeAdapterFactory() {
+ @Override
+ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
+ Class<? super T> clazz = type.getRawType();
+
+ if (TopicSink.class.isAssignableFrom(clazz)) {
+ return new GsonSerializer<T>() {
+ @Override
+ public void write(JsonWriter out, T value) throws IOException {
+ TopicSink obj = (TopicSink) value;
+ out.beginObject().name("name").value(obj.getTopic()).endObject();
+ }
+ };
+ }
+
+ return null;
+ }
+ };
+
+ addMock(TopicSink.class, sgson);
+
+ return this;
+ }
+
+ /**
+ * Adds support for serializing a drools controller mock.
+ *
+ * @return the builder
+ */
+ public GsonMgmtTestBuilder addDroolsControllerMock() {
+ TypeAdapterFactory sgson = new TypeAdapterFactory() {
+ @Override
+ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
+ Class<? super T> clazz = type.getRawType();
+
+ if (DroolsController.class.isAssignableFrom(clazz)) {
+ return new GsonSerializer<T>() {
+ @Override
+ public void write(JsonWriter out, T value) throws IOException {
+ DroolsController obj = (DroolsController) value;
+ out.beginObject().name("group").value(obj.getGroupId()).name("artifact")
+ .value(obj.getArtifactId()).name("version").value(obj.getVersion())
+ .endObject();
+ }
+ };
+ }
+
+ return null;
+ }
+ };
+
+ addMock(DroolsController.class, sgson);
+
+ return this;
+ }
+
+ /**
+ * Adds support for serializing an http servlet mock.
+ *
+ * @return the builder
+ */
+ public GsonMgmtTestBuilder addHttpServletServerMock() {
+ TypeAdapterFactory sgson = new TypeAdapterFactory() {
+ @Override
+ public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
+ Class<? super T> clazz = type.getRawType();
+
+ if (HttpServletServer.class.isAssignableFrom(clazz)) {
+ return new GsonSerializer<T>() {
+ @Override
+ public void write(JsonWriter out, T value) throws IOException {
+ HttpServletServer obj = (HttpServletServer) value;
+ out.beginObject().name("port").value(obj.getPort()).endObject();
+ }
+ };
+ }
+
+ return null;
+ }
+ };
+
+ addMock(HttpServletServer.class, sgson);
+
+ return this;
+ }
+}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyControllerFactoryTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyControllerFactoryTest.java
index f5fc8a5c..e56670bd 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyControllerFactoryTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyControllerFactoryTest.java
@@ -37,6 +37,7 @@ import java.util.List;
import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.gson.GsonTestUtils;
import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.features.PolicyControllerFeatureAPI;
import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
@@ -126,6 +127,13 @@ public class PolicyControllerFactoryTest {
}
@Test
+ public void testSerialize() {
+ assertEquals(controller, ipc.build(MY_NAME, properties));
+
+ new GsonTestUtils().compareGson(ipc, PolicyControllerFactoryTest.class);
+ }
+
+ @Test
public void testPatchStringDroolsConfiguration() {
// unknown controller
assertThatIllegalArgumentException().isThrownBy(() -> ipc.patch(MY_NAME, config));
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
index 4f7e1b0a..4b8357a2 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java
@@ -37,8 +37,6 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@@ -53,6 +51,7 @@ import org.onap.policy.common.endpoints.event.comm.TopicSink;
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.utils.gson.GsonTestUtils;
import org.onap.policy.drools.controller.DroolsController;
import org.onap.policy.drools.features.PolicyControllerFeatureAPI;
import org.onap.policy.drools.features.PolicyEngineFeatureAPI;
@@ -80,7 +79,8 @@ public class PolicyEngineManagerTest {
private static final Object MY_EVENT = new Object();
- private static final Gson encoder = new GsonBuilder().disableHtmlEscaping().create();
+ private static final GsonTestUtils gson = new GsonMgmtTestBuilder().addTopicSourceMock().addTopicSinkMock()
+ .addHttpServletServerMock().build();
private Properties properties;
private PolicyEngineFeatureAPI prov1;
@@ -186,25 +186,31 @@ public class PolicyEngineManagerTest {
when(controllerFactory.get(CONTROLLER2)).thenReturn(controller2);
// do NOT return controller3 or controller4
+ when(server1.getPort()).thenReturn(1001);
when(server1.waitedStart(anyLong())).thenReturn(true);
when(server1.stop()).thenReturn(true);
+ when(server2.getPort()).thenReturn(1002);
when(server2.waitedStart(anyLong())).thenReturn(true);
when(server2.stop()).thenReturn(true);
when(serverFactory.build(any())).thenReturn(servers);
+ when(source1.getTopic()).thenReturn("source1-topic");
when(source1.start()).thenReturn(true);
when(source1.stop()).thenReturn(true);
+ when(source2.getTopic()).thenReturn("source2-topic");
when(source2.start()).thenReturn(true);
when(source2.stop()).thenReturn(true);
+ when(sink1.getTopic()).thenReturn("sink1-topic");
when(sink1.start()).thenReturn(true);
when(sink1.stop()).thenReturn(true);
when(sink1.send(any())).thenReturn(true);
when(sink1.getTopicCommInfrastructure()).thenReturn(CommInfrastructure.NOOP);
+ when(sink2.getTopic()).thenReturn("sink2-topic");
when(sink2.start()).thenReturn(true);
when(sink2.stop()).thenReturn(true);
@@ -261,12 +267,18 @@ public class PolicyEngineManagerTest {
pdpConfig.getControllers().add(config4);
pdpConfig.setEntity(PdpdConfiguration.CONFIG_ENTITY_CONTROLLER);
- pdpConfigJson = encoder.toJson(pdpConfig);
+ pdpConfigJson = gson.gsonEncode(pdpConfig);
mgr = new PolicyEngineManagerImpl();
}
@Test
+ public void testSerialize() {
+ mgr.configure(properties);
+ gson.compareGson(mgr, PolicyEngineManagerTest.class);
+ }
+
+ @Test
public void testFactory() {
mgr = new PolicyEngineManager();
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
index dae409ee..a00d6db2 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineTest.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.
@@ -23,12 +23,12 @@ package org.onap.policy.drools.system;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Properties;
-
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
@@ -38,6 +38,7 @@ import org.onap.policy.common.endpoints.event.comm.TopicEndpoint;
import org.onap.policy.common.endpoints.event.comm.TopicSink;
import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSink;
import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
+import org.onap.policy.common.utils.gson.GsonTestUtils;
import org.onap.policy.drools.persistence.SystemPersistence;
import org.onap.policy.drools.properties.DroolsProperties;
import org.onap.policy.drools.protocol.coders.EventProtocolCoder;
@@ -98,6 +99,8 @@ public class PolicyEngineTest {
*/
private static Logger logger = LoggerFactory.getLogger(PolicyEngineTest.class);
+ private static GsonTestUtils gson;
+
/**
* clean up working directory.
*/
@@ -121,13 +124,15 @@ public class PolicyEngineTest {
/**
* Start up.
- *
+ *
* @throws IOException throws IO exception
*/
@BeforeClass
public static void startUp() throws IOException {
logger.info("enter");
+ gson = new GsonTestUtils();
+
cleanUpWorkingDir();
/* ensure presence of config directory */
@@ -151,14 +156,16 @@ public class PolicyEngineTest {
/* override default port */
engineProps.put(PolicyEndPointProperties.PROPERTY_HTTP_SERVER_SERVICES + "."
- + PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX,
- "" + DEFAULT_TELEMETRY_PORT);
+ + PolicyEngine.TELEMETRY_SERVER_DEFAULT_NAME
+ + PolicyEndPointProperties.PROPERTY_HTTP_PORT_SUFFIX, "" + DEFAULT_TELEMETRY_PORT);
assertFalse(PolicyEngine.manager.isAlive());
PolicyEngine.manager.configure(engineProps);
assertFalse(PolicyEngine.manager.isAlive());
logger.info("policy-engine {} has configuration {}", PolicyEngine.manager, engineProps);
+
+ gson.compareGson(PolicyEngine.manager, new File(PolicyEngineTest.class.getSimpleName() + "Config.json"));
}
@Test
@@ -229,6 +236,8 @@ public class PolicyEngineTest {
PolicyEngine.manager.createPolicyController(TEST_CONTROLLER_NAME, controllerProperties);
assertTrue(PolicyController.factory.inventory().size() == 1);
+
+ gson.compareGson(PolicyEngine.manager, new File(PolicyEngineTest.class.getSimpleName() + "Add.json"));
}
@Test
@@ -292,5 +301,4 @@ public class PolicyEngineTest {
Thread.sleep(10000L);
assertFalse(PolicyEngine.manager.isAlive());
}
-
}
diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/internal/AggregatedPolicyControllerTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/internal/AggregatedPolicyControllerTest.java
index 83344486..43068810 100644
--- a/policy-management/src/test/java/org/onap/policy/drools/system/internal/AggregatedPolicyControllerTest.java
+++ b/policy-management/src/test/java/org/onap/policy/drools/system/internal/AggregatedPolicyControllerTest.java
@@ -49,6 +49,7 @@ import org.onap.policy.drools.controller.DroolsControllerFactory;
import org.onap.policy.drools.features.PolicyControllerFeatureAPI;
import org.onap.policy.drools.persistence.SystemPersistence;
import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
+import org.onap.policy.drools.system.GsonMgmtTestBuilder;
public class AggregatedPolicyControllerTest {
@@ -260,6 +261,12 @@ public class AggregatedPolicyControllerTest {
}
@Test
+ public void testSerialize() {
+ new GsonMgmtTestBuilder().addDroolsControllerMock().addTopicSinkMock().addTopicSourceMock().build()
+ .compareGson(apc, AggregatedPolicyControllerTest.class);
+ }
+
+ @Test
public void testGetName() {
assertEquals(AGG_NAME, apc.getName());
}
diff --git a/policy-management/src/test/resources/org/onap/policy/drools/controller/internal/MavenDroolsControllerTest.json b/policy-management/src/test/resources/org/onap/policy/drools/controller/internal/MavenDroolsControllerTest.json
new file mode 100644
index 00000000..5ff6c2af
--- /dev/null
+++ b/policy-management/src/test/resources/org/onap/policy/drools/controller/internal/MavenDroolsControllerTest.json
@@ -0,0 +1,14 @@
+{
+ "alive": false,
+ "locked": false,
+ "recentSourceEvents": [],
+ "recentSinkEvents": [],
+ "modelClassLoaderHash": ${obj.modelClassLoaderHash},
+ "groupId": "org.onap.policy.drools.test",
+ "artifactId": "echo",
+ "version": "${obj.version}",
+ "baseDomainNames": ["onap.policies.test"],
+ "brained": true,
+ "sessions": ["echo"],
+ "sessionCoordinates": ["org.onap.policy.drools.test:echo:${obj.version}:echo"]
+}
diff --git a/policy-management/src/test/resources/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.json b/policy-management/src/test/resources/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.json
new file mode 100644
index 00000000..58bd0d90
--- /dev/null
+++ b/policy-management/src/test/resources/org/onap/policy/drools/controller/internal/NullDroolsControllerTest.json
@@ -0,0 +1,14 @@
+{
+ "alive": false,
+ "locked": false,
+ "groupId": "NO-GROUP-ID",
+ "artifactId": "NO-ARTIFACT-ID",
+ "version": "NO-VERSION",
+ "sessionNames": [],
+ "container": null,
+ "baseDomainNames": [],
+ "brained": false,
+ "canonicalSessionNames": [],
+ "recentSourceEvents": [],
+ "recentSinkEvents": []
+}
diff --git a/policy-management/src/test/resources/org/onap/policy/drools/protocol/configuration/ControllerConfigurationTest.json b/policy-management/src/test/resources/org/onap/policy/drools/protocol/configuration/ControllerConfigurationTest.json
new file mode 100644
index 00000000..6b4196fd
--- /dev/null
+++ b/policy-management/src/test/resources/org/onap/policy/drools/protocol/configuration/ControllerConfigurationTest.json
@@ -0,0 +1,11 @@
+{
+ "name": "name",
+ "operation": "operation",
+ "drools": {
+ "artifactId": "org.onap.artifact",
+ "groupId": "group",
+ "version": "1.0.0"
+ },
+ "foo": "bar",
+ "hello": "world"
+}
diff --git a/policy-management/src/test/resources/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.json b/policy-management/src/test/resources/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.json
new file mode 100644
index 00000000..3869ea28
--- /dev/null
+++ b/policy-management/src/test/resources/org/onap/policy/drools/protocol/configuration/DroolsConfigurationTest.json
@@ -0,0 +1,7 @@
+{
+ "artifactId": "org.onap.artifact",
+ "groupId": "group",
+ "version": "1.0.0",
+ "foo": "bar",
+ "hello": "world"
+}
diff --git a/policy-management/src/test/resources/org/onap/policy/drools/protocol/configuration/PdpdConfigurationTest.json b/policy-management/src/test/resources/org/onap/policy/drools/protocol/configuration/PdpdConfigurationTest.json
new file mode 100644
index 00000000..f5495ffb
--- /dev/null
+++ b/policy-management/src/test/resources/org/onap/policy/drools/protocol/configuration/PdpdConfigurationTest.json
@@ -0,0 +1,14 @@
+{
+ "requestID": "${obj.requestID}",
+ "entity": "entity1",
+ "controllers": [
+ {
+ "name": "name",
+ "operation": "operation"
+ },
+ {
+ "name": "name2",
+ "operation": "operation2"
+ }
+ ]
+}
diff --git a/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyControllerFactoryTest.json b/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyControllerFactoryTest.json
new file mode 100644
index 00000000..0c17f35f
--- /dev/null
+++ b/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyControllerFactoryTest.json
@@ -0,0 +1,3 @@
+{
+ "features": ["feature-a", "feature-b"]
+}
diff --git a/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineManagerTest.json b/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineManagerTest.json
new file mode 100644
index 00000000..db50e53c
--- /dev/null
+++ b/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineManagerTest.json
@@ -0,0 +1,24 @@
+{
+ "alive": false,
+ "controllers": [
+ "controller-a",
+ "controller-b"
+ ],
+ "features": [
+ "feature-a",
+ "feature-b"
+ ],
+ "httpServers": [
+ { "port": 1001 },
+ { "port": 1002 }
+ ],
+ "locked": false,
+ "sinks": [
+ { "name": "sink1-topic" },
+ { "name": "sink2-topic" }
+ ],
+ "sources": [
+ { "name": "source1-topic" },
+ { "name": "source2-topic" }
+ ]
+}
diff --git a/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestAdd.json b/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestAdd.json
new file mode 100644
index 00000000..7a247d32
--- /dev/null
+++ b/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestAdd.json
@@ -0,0 +1,20 @@
+{
+ "alive": true,
+ "locked": false,
+ "sources": [],
+ "sinks": [],
+ "httpServers": [
+ {
+ "name": "TELEMETRY",
+ "host": "localhost",
+ "port": 9698,
+ "user": null,
+ "alive": true,
+ "aaf": false
+ }
+ ],
+ "features": [],
+ "controllers": [
+ "foo"
+ ]
+}
diff --git a/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestConfig.json b/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestConfig.json
new file mode 100644
index 00000000..7f06f5a0
--- /dev/null
+++ b/policy-management/src/test/resources/org/onap/policy/drools/system/PolicyEngineTestConfig.json
@@ -0,0 +1,18 @@
+{
+ "alive": false,
+ "locked": false,
+ "sources": [],
+ "sinks": [],
+ "httpServers": [
+ {
+ "name": "TELEMETRY",
+ "host": "localhost",
+ "port": 9698,
+ "user": null,
+ "alive": false,
+ "aaf": false
+ }
+ ],
+ "features": [],
+ "controllers": []
+}
diff --git a/policy-management/src/test/resources/org/onap/policy/drools/system/internal/AggregatedPolicyControllerTest.json b/policy-management/src/test/resources/org/onap/policy/drools/system/internal/AggregatedPolicyControllerTest.json
new file mode 100644
index 00000000..3557f21d
--- /dev/null
+++ b/policy-management/src/test/resources/org/onap/policy/drools/system/internal/AggregatedPolicyControllerTest.json
@@ -0,0 +1,18 @@
+{
+ "alive": false,
+ "drools": {
+ "artifact": "artifact-a",
+ "group": "group-a",
+ "version": "version-a"
+ },
+ "locked": false,
+ "name": "agg-name",
+ "topicSinks": [
+ { "name": "sink-a" },
+ { "name": "sink-b" }
+ ],
+ "topicSources": [
+ { "name": "source-a" },
+ { "name": "source-b" }
+ ]
+}