summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--gson/pom.xml6
-rw-r--r--policy-endpoints/src/main/java/org/onap/policy/common/endpoints/properties/PolicyEndPointProperties.java1
-rw-r--r--utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java34
-rw-r--r--utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java6
4 files changed, 28 insertions, 19 deletions
diff --git a/gson/pom.xml b/gson/pom.xml
index 110fccbd..81b95497 100644
--- a/gson/pom.xml
+++ b/gson/pom.xml
@@ -34,7 +34,6 @@
<properties>
<!-- TODO move to top-level or parent -->
<jersey.version>2.25.1</jersey.version>
- <jackson.version>2.9.5</jackson.version>
</properties>
<dependencies>
@@ -48,11 +47,6 @@
<artifactId>gson</artifactId>
</dependency>
<dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-annotations</artifactId>
- <version>${jackson.version}</version>
- </dependency>
- <dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
diff --git a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/properties/PolicyEndPointProperties.java b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/properties/PolicyEndPointProperties.java
index 2b1a9a3f..2979c7e9 100644
--- a/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/properties/PolicyEndPointProperties.java
+++ b/policy-endpoints/src/main/java/org/onap/policy/common/endpoints/properties/PolicyEndPointProperties.java
@@ -32,7 +32,6 @@ public interface PolicyEndPointProperties {
String PROPERTY_TOPIC_EVENTS_SUFFIX = ".events";
String PROPERTY_TOPIC_EVENTS_FILTER_SUFFIX = ".filter";
String PROPERTY_TOPIC_EVENTS_CUSTOM_MODEL_CODER_GSON_SUFFIX = ".events.custom.gson";
- String PROPERTY_TOPIC_EVENTS_CUSTOM_MODEL_CODER_JACKSON_SUFFIX = ".events.custom.jackson";
String PROPERTY_TOPIC_SOURCE_CONSUMER_GROUP_SUFFIX = ".consumerGroup";
String PROPERTY_TOPIC_SOURCE_CONSUMER_INSTANCE_SUFFIX = ".consumerInstance";
diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java b/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java
index bfdca97c..d3354e49 100644
--- a/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java
+++ b/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java
@@ -61,7 +61,7 @@ public class GsonTestUtils {
/**
* Engine used to interpolate strings before they're compared.
*/
- private static volatile ScriptEngine engine = null;
+ private static volatile ScriptEngine engineInstance = null;
/**
* Used to encode and decode an object via gson.
@@ -198,13 +198,9 @@ public class GsonTestUtils {
return text;
}
- // create the engine and bind the object to the variable, "obj"
- if (engine == null) {
- // race condition here, but it's ok to overwrite with a new engine
- engine = new ScriptEngineManager().getEngineByName("javascript");
- }
-
- Bindings bindings = engine.createBindings();
+ // bind the object to the variable, "obj"
+ ScriptEngine eng = getEngine();
+ Bindings bindings = eng.createBindings();
bindings.put("obj", object);
// work our way through the text, interpolating script elements as we go
@@ -222,11 +218,15 @@ public class GsonTestUtils {
// interpolate the script
String script = mat.group(1);
try {
- Object result = engine.eval(script, bindings);
+ /*
+ * Note: must use "eng" instead of "engineInstance" to ensure that we use
+ * the same engine that's associated with the bindings.
+ */
+ Object result = eng.eval(script, bindings);
bldr.append(result == null ? "null" : result.toString());
} catch (ScriptException e) {
- throw new RuntimeException("cannot expand element: " + mat.group(), e);
+ throw new JsonParseException("cannot expand element: " + mat.group(), e);
}
}
@@ -237,6 +237,20 @@ public class GsonTestUtils {
}
/**
+ * Gets the script engine instance.
+ *
+ * @return the script engine
+ */
+ private static ScriptEngine getEngine() {
+ if (engineInstance == null) {
+ // race condition here, but it's ok to overwrite with a new engine
+ engineInstance = new ScriptEngineManager().getEngineByName("javascript");
+ }
+
+ return engineInstance;
+ }
+
+ /**
* Encodes an object using gson.
*
* @param object the object to be encoded
diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java
index 39cde7dc..58beb2a6 100644
--- a/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java
+++ b/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java
@@ -135,8 +135,10 @@ public class GsonTestUtilsTest {
result = utils.applyScripts("use ${obj.text} this", data);
assertEquals("use null this", result);
- assertThatThrownBy(() -> utils.applyScripts("use ${obj.text} this", null)).isInstanceOf(RuntimeException.class)
- .hasCauseInstanceOf(ScriptException.class).hasMessage("cannot expand element: ${obj.text}");
+ assertThatThrownBy(() -> utils.applyScripts("use ${obj.text} this", null))
+ .isInstanceOf(JsonParseException.class)
+ .hasCauseInstanceOf(ScriptException.class)
+ .hasMessage("cannot expand element: ${obj.text}");
}
@Test