diff options
Diffstat (limited to 'models-interactions/model-actors/actor.sdnc/src/test')
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 |