summaryrefslogtreecommitdiffstats
path: root/feature-pooling-dmaap/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'feature-pooling-dmaap/src/test/java')
-rw-r--r--feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/EndToEndFeatureTest.java24
-rw-r--r--feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java27
-rw-r--r--feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SerializerTest.java20
-rw-r--r--feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/SupportBasicMessageTester.java14
4 files changed, 42 insertions, 43 deletions
diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/EndToEndFeatureTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/EndToEndFeatureTest.java
index 362c3b01..0cbc0e00 100644
--- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/EndToEndFeatureTest.java
+++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/EndToEndFeatureTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-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.
@@ -28,9 +28,8 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.onap.policy.drools.pooling.PoolingProperties.PREFIX;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.IOException;
+import com.google.gson.Gson;
+import com.google.gson.JsonParseException;
import java.util.Arrays;
import java.util.Deque;
import java.util.IdentityHashMap;
@@ -114,20 +113,9 @@ public class EndToEndFeatureTest {
private static final long EVENT_WAIT_SEC = 15;
/**
- * Used to decode events into a Map.
- */
- private static final TypeReference<TreeMap<String, String>> typeRef =
- new TypeReference<TreeMap<String, String>>() {};
-
- /**
* Used to decode events from the external topic.
*/
- private static final ThreadLocal<ObjectMapper> mapper = new ThreadLocal<ObjectMapper>() {
- @Override
- protected ObjectMapper initialValue() {
- return new ObjectMapper();
- }
- };
+ private static final Gson mapper = new Gson();
/**
* Used to identify the current host.
@@ -281,9 +269,9 @@ public class EndToEndFeatureTest {
*/
private static Object decodeEvent(String event) {
try {
- return mapper.get().readValue(event, typeRef);
+ return mapper.fromJson(event, TreeMap.class);
- } catch (IOException e) {
+ } catch (JsonParseException e) {
logger.warn("cannot decode external event", e);
return null;
}
diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java
index 01253fbf..0d5b5e06 100644
--- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java
+++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/FeatureTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-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.
@@ -28,9 +28,8 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.onap.policy.drools.pooling.PoolingProperties.PREFIX;
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import java.io.IOException;
+import com.google.gson.Gson;
+import com.google.gson.JsonParseException;
import java.util.Arrays;
import java.util.Deque;
import java.util.IdentityHashMap;
@@ -108,22 +107,10 @@ public class FeatureTest {
private static long stdPollMs = 2;
private static long stdInterPollMs = 2;
private static long stdEventWaitSec = 10;
-
- /**
- * Used to decode events into a Map.
- */
- private static final TypeReference<TreeMap<String, String>> typeRef =
- new TypeReference<TreeMap<String, String>>() {};
-
/**
* Used to decode events from the external topic.
*/
- private static final ThreadLocal<ObjectMapper> mapper = new ThreadLocal<ObjectMapper>() {
- @Override
- protected ObjectMapper initialValue() {
- return new ObjectMapper();
- }
- };
+ private static final Gson mapper = new Gson();
/**
* Used to identify the current context.
@@ -215,9 +202,9 @@ public class FeatureTest {
*/
private static Object decodeEvent(String event) {
try {
- return mapper.get().readValue(event, typeRef);
+ return mapper.fromJson(event, TreeMap.class);
- } catch (IOException e) {
+ } catch (JsonParseException e) {
logger.warn("cannot decode external event", e);
return null;
}
@@ -722,7 +709,7 @@ public class FeatureTest {
return true;
- } catch (IOException e) {
+ } catch (JsonParseException e) {
logger.warn("could not decode message: {}", message);
context.bumpDecodeErrors();
return false;
diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SerializerTest.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SerializerTest.java
index 0b098c13..b51a18f2 100644
--- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SerializerTest.java
+++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/SerializerTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-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.
@@ -20,6 +20,7 @@
package org.onap.policy.drools.pooling;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -27,6 +28,7 @@ import static org.onap.policy.drools.pooling.state.FilterUtils.makeAnd;
import static org.onap.policy.drools.pooling.state.FilterUtils.makeEquals;
import static org.onap.policy.drools.pooling.state.FilterUtils.makeOr;
+import com.google.gson.JsonParseException;
import java.util.Map;
import java.util.TreeMap;
import org.junit.Test;
@@ -92,6 +94,22 @@ public class SerializerTest {
assertEquals(msg.getSource(), decoded.getSource());
assertEquals(msg.getChannel(), decoded.getChannel());
+
+ // invalid subclass when encoding
+ assertThatThrownBy(() -> ser.encodeMsg(new Message() {})).isInstanceOf(JsonParseException.class)
+ .hasMessageContaining("cannot serialize");
+
+ // missing type when decoding
+ final String enc2 = encoded.replaceAll("type", "other-field-name");
+
+ assertThatThrownBy(() -> ser.decodeMsg(enc2)).isInstanceOf(JsonParseException.class)
+ .hasMessageContaining("does not contain a field named");
+
+ // invalid type
+ final String enc3 = encoded.replaceAll("query", "invalid-type");
+
+ assertThatThrownBy(() -> ser.decodeMsg(enc3)).isInstanceOf(JsonParseException.class)
+ .hasMessage("cannot deserialize \"invalid-type\"");
}
}
diff --git a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/SupportBasicMessageTester.java b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/SupportBasicMessageTester.java
index e30d78d4..19e7ab0b 100644
--- a/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/SupportBasicMessageTester.java
+++ b/feature-pooling-dmaap/src/test/java/org/onap/policy/drools/pooling/message/SupportBasicMessageTester.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-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.
@@ -24,9 +24,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.onap.policy.drools.pooling.PoolingFeatureException;
+import org.onap.policy.drools.pooling.Serializer;
/**
* Superclass used to test subclasses of {@link Message}.
@@ -42,7 +42,7 @@ public abstract class SupportBasicMessageTester<T extends Message> {
/**
* Used to perform JSON serialization and de-serialization.
*/
- public final ObjectMapper mapper = new ObjectMapper();
+ public final Serializer mapper = new Serializer();
/**
* The subclass of the type of Message being tested.
@@ -89,7 +89,13 @@ public abstract class SupportBasicMessageTester<T extends Message> {
public final void testJsonEncodeDecode() throws Exception {
T originalMsg = makeValidMessage();
- Message msg = mapper.readValue(mapper.writeValueAsString(originalMsg), Message.class);
+ Message msg;
+ if (originalMsg.getClass() == Message.class) {
+ msg = originalMsg;
+ } else {
+ msg = mapper.decodeMsg(mapper.encodeMsg(originalMsg));
+ }
+
assertEquals(subclazz, msg.getClass());
msg.checkValidity();