summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.appc
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.appc
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.appc')
-rw-r--r--models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java24
-rw-r--r--models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java5
-rw-r--r--models-interactions/model-actors/actor.appc/src/test/resources/modifyConfig.json23
3 files changed, 28 insertions, 24 deletions
diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java
index cbdcad6b0..3d4a04612 100644
--- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java
+++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java
@@ -36,10 +36,7 @@ import java.util.function.BiFunction;
import org.onap.policy.appc.Response;
import org.onap.policy.appc.ResponseCode;
import org.onap.policy.appc.ResponseStatus;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.coder.StandardCoderObject;
-import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.Util;
@@ -53,6 +50,7 @@ import org.powermock.reflect.Whitebox;
* Superclass for various operator tests.
*/
public abstract class BasicAppcOperation extends BasicBidirectionalTopicOperation {
+ protected static final String[] IGNORE_FIELDS = {"RequestID", "subRequestID", "seconds", "nanos"};
protected static final String MY_DESCRIPTION = "my-description";
protected static final String MY_VNF = "my-vnf";
protected static final String KEY1 = "my-key-A";
@@ -118,26 +116,6 @@ public abstract class BasicAppcOperation extends BasicBidirectionalTopicOperatio
}
/**
- * 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.
*
diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java
index f7c88f67c..34bbec32f 100644
--- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java
+++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java
@@ -39,6 +39,7 @@ import org.junit.Test;
import org.onap.aai.domain.yang.GenericVnf;
import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.appc.Request;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
@@ -85,7 +86,7 @@ public class ModifyConfigOperationTest extends BasicAppcOperation {
}
@Test
- public void testMakeRequest() {
+ public void testMakeRequest() throws CoderException {
AaiCqResponse cq = new AaiCqResponse("{}");
// missing vnf-id
@@ -101,5 +102,7 @@ public class ModifyConfigOperationTest extends BasicAppcOperation {
Request request = oper.makeRequest(2);
assertNotNull(request);
assertEquals(MY_VNF, request.getPayload().get(ModifyConfigOperation.VNF_ID_KEY));
+
+ verifyRequest("modifyConfig.json", request, IGNORE_FIELDS);
}
}
diff --git a/models-interactions/model-actors/actor.appc/src/test/resources/modifyConfig.json b/models-interactions/model-actors/actor.appc/src/test/resources/modifyConfig.json
new file mode 100644
index 000000000..eae6223f1
--- /dev/null
+++ b/models-interactions/model-actors/actor.appc/src/test/resources/modifyConfig.json
@@ -0,0 +1,23 @@
+{
+ "CommonHeader": {
+ "TimeStamp": {
+ "seconds": 1582057368,
+ "nanos": 981593700
+ },
+ "APIver": "1.01",
+ "RequestID": "9a06c485-ebf1-4780-a183-6a1d862eebeb",
+ "SubRequestID": "2d011587-a311-45e6-a75d-67fcd3dfae1a",
+ "RequestTrack": [],
+ "Flags": []
+ },
+ "Action": "ModifyConfig",
+ "Payload": {
+ "my-key-B": {
+ "output": "world"
+ },
+ "my-key-A": {
+ "input": "hello"
+ },
+ "generic-vnf.vnf-id": "my-vnf"
+ }
+}