aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.sdnc/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-02-18 15:28:39 -0500
committerJim Hahn <jrh3@att.com>2020-02-18 16:39:14 -0500
commit4ccc26577b51545b4b4db6823c6d926bc0ffc5a4 (patch)
tree81e84b3579d4ac7af81dcc25649db5e3d926c8e5 /models-interactions/model-actors/actor.sdnc/src/test
parentca409ee108f3f653d66be804e8a9f95f794e26d4 (diff)
Validate request content of various actors
Created common junit superclass, BasicOperation, containing verifyRequest() method, among others. Issue-ID: POLICY-2363 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: I7ff4428e94bfd301ff4194e1766ef61906714dcf
Diffstat (limited to 'models-interactions/model-actors/actor.sdnc/src/test')
-rw-r--r--models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java4
-rw-r--r--models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java28
-rw-r--r--models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java4
3 files changed, 9 insertions, 27 deletions
diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java
index 42042da67..e8490627e 100644
--- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java
+++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java
@@ -59,13 +59,13 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation {
assertEquals(BandwidthOnDemandOperation.URI, request.getUrl());
assertNotNull(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId());
- verifyRequest("bod.json", request);
+ verifyRequest("bod.json", request, IGNORE_FIELDS);
verifyMissing(BandwidthOnDemandOperation.SERVICE_ID_KEY, "service", BandwidthOnDemandOperation::new);
// perform the operation
makeContext();
- verifyRequest("bod.json", verifyOperation(oper));
+ verifyRequest("bod.json", verifyOperation(oper), IGNORE_FIELDS);
}
@Override
diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java
index db8751d26..c1278f1b1 100644
--- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java
+++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java
@@ -33,9 +33,7 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import java.util.function.BiFunction;
-import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.controlloop.actor.test.BasicHttpOperation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperator;
@@ -50,6 +48,10 @@ import org.powermock.reflect.Whitebox;
* Superclass for various operator tests.
*/
public abstract class BasicSdncOperation extends BasicHttpOperation<SdncRequest> {
+ /**
+ * Fields to be ignored when comparing requests with JSON.
+ */
+ protected static final String[] IGNORE_FIELDS = {"svc-request-id"};
protected SdncResponse response;
@@ -110,26 +112,6 @@ public abstract class BasicSdncOperation extends BasicHttpOperation<SdncRequest>
}
/**
- * Pretty-prints a request and verifies that the result matches the expected JSON.
- *
- * @param <T> request type
- * @param expectedJsonFile name of the file containing the expected JSON
- * @param request request to verify
- * @throws CoderException if the request cannot be pretty-printed
- */
- protected <T> void verifyRequest(String expectedJsonFile, T request) throws CoderException {
- String json = new StandardCoder().encode(request, true);
- String expected = ResourceUtils.getResourceAsString(expectedJsonFile);
-
- // strip request id, because it changes each time
- final String stripper = "svc-request-id[^,]*";
- json = json.replaceFirst(stripper, "").trim();
- expected = expected.replaceFirst(stripper, "").trim();
-
- assertEquals(expected, json);
- }
-
- /**
* Verifies that an exception is thrown if a field is missing from the enrichment
* data.
*
@@ -137,7 +119,7 @@ public abstract class BasicSdncOperation extends BasicHttpOperation<SdncRequest>
* @param expectedText text expected in the exception message
*/
protected void verifyMissing(String fieldName, String expectedText,
- BiFunction<ControlLoopOperationParams,HttpOperator,SdncOperation> maker) {
+ BiFunction<ControlLoopOperationParams, HttpOperator, SdncOperation> maker) {
makeContext();
enrichment.remove(fieldName);
diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java
index a98c38180..f0836b939 100644
--- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java
+++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java
@@ -59,14 +59,14 @@ public class RerouteOperationTest extends BasicSdncOperation {
assertEquals(RerouteOperation.URI, request.getUrl());
assertNotNull(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId());
- verifyRequest("reroute.json", request);
+ verifyRequest("reroute.json", request, IGNORE_FIELDS);
verifyMissing(RerouteOperation.SERVICE_ID_KEY, "service", RerouteOperation::new);
verifyMissing(RerouteOperation.NETWORK_ID_KEY, "network", RerouteOperation::new);
// perform the operation
makeContext();
- verifyRequest("reroute.json", verifyOperation(oper));
+ verifyRequest("reroute.json", verifyOperation(oper), IGNORE_FIELDS);
}
@Override