diff options
Diffstat (limited to 'models-interactions/model-actors/actor.guard/src/test')
7 files changed, 44 insertions, 56 deletions
diff --git a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardConfigTest.java b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardConfigTest.java index 49c1c916a..d30c71172 100644 --- a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardConfigTest.java +++ b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardConfigTest.java @@ -33,7 +33,6 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.onap.policy.common.endpoints.http.client.HttpClient; import org.onap.policy.common.endpoints.http.client.HttpClientFactory; -import org.onap.policy.controlloop.actorserviceprovider.Util; import org.onap.policy.models.decisions.concepts.DecisionRequest; public class GuardConfigTest { @@ -77,7 +76,7 @@ public class GuardConfigTest { expected.setOnapName(ONAP_NAME); expected.setAction(MY_ACTION); - DecisionRequest actual = Util.translate("", config.makeRequest(), DecisionRequest.class); + DecisionRequest actual = config.makeRequest(); assertEquals(expected, actual); // check value from superclass @@ -89,7 +88,7 @@ public class GuardConfigTest { config = new GuardConfig(executor, params, factory); assertFalse(config.isDisabled()); - actual = Util.translate("", config.makeRequest(), DecisionRequest.class); + actual = config.makeRequest(); assertEquals(new DecisionRequest(), actual); // try with disabled=true diff --git a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java index be40ef3b4..13a241124 100644 --- a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java +++ b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java @@ -23,6 +23,7 @@ package org.onap.policy.controlloop.actor.guard; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -63,7 +64,14 @@ public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> { super.setUpBasic(); guardConfig = mock(GuardConfig.class); - when(guardConfig.makeRequest()).thenAnswer(args -> new TreeMap<>(Map.of("action", "guard"))); + when(guardConfig.makeRequest()).thenAnswer(args -> { + DecisionRequest req = new DecisionRequest(); + req.setAction("guard"); + req.setOnapComponent("my-onap-component"); + req.setOnapInstance("my-onap-instance"); + req.setOnapName("my-onap-name"); + return req; + }); config = guardConfig; initConfig(); @@ -128,19 +136,6 @@ public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> { verifyPayload("makeReqStd.json", makePayload()); verifyPayload("makeReqDefault.json", new TreeMap<>()); - Map<String, Object> payload = new TreeMap<>(); - payload.put("action", "some action"); - payload.put("hello", "world"); - payload.put("r u there?", "yes"); - payload.put("requestId", "some request id"); - - Map<String, Object> resource = new TreeMap<>(); - payload.put("resource", resource); - resource.put("abc", "def"); - resource.put("ghi", "jkl"); - - verifyPayload("makeReq.json", payload); - // null payload - start with fresh parameters and operation params = params.toBuilder().payload(null).build(); oper = new GuardOperation(params, config); @@ -151,9 +146,16 @@ public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> { params.getPayload().clear(); params.getPayload().putAll(payload); - Map<String, Object> requestMap = oper.makeRequest(); + DecisionRequest request = oper.makeRequest(); + + assertEquals("guard", request.getAction()); + assertEquals("my-onap-component", request.getOnapComponent()); + assertEquals("my-onap-instance", request.getOnapInstance()); + assertEquals("my-onap-name", request.getOnapName()); + assertNotNull(request.getRequestId()); + assertEquals(Map.of("guard", payload), request.getResource()); - verifyRequest(expectedJsonFile, requestMap, "requestId"); + verifyRequest(expectedJsonFile, request, "requestId"); } @Test @@ -189,22 +191,6 @@ public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> { @Override protected Map<String, Object> makePayload() { - DecisionRequest req = new DecisionRequest(); - req.setAction("my-action"); - req.setOnapComponent("my-onap-component"); - req.setOnapInstance("my-onap-instance"); - req.setOnapName("my-onap-name"); - req.setRequestId("my-request-id"); - - // add resources - Map<String, Object> resource = new TreeMap<>(); - req.setResource(resource); - resource.put("actor", "resource-actor"); - resource.put("operation", "resource-operation"); - - @SuppressWarnings("unchecked") - Map<String, Object> map = Util.translate("", req, TreeMap.class); - - return map; + return new TreeMap<>(Map.of("hello", "world", "abc", "123")); } } diff --git a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardParamsTest.java b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardParamsTest.java index 172368349..102dcbb08 100644 --- a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardParamsTest.java +++ b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardParamsTest.java @@ -60,12 +60,13 @@ public class GuardParamsTest { public void testValidate() { assertTrue(params.validate(CONTAINER).isValid()); + testValidateField("onapName", "null", bldr -> bldr.onapName(null)); + testValidateField("onapComponent", "null", bldr -> bldr.onapComponent(null)); + testValidateField("onapInstance", "null", bldr -> bldr.onapInstance(null)); + testValidateField("action", "null", bldr -> bldr.action(null)); + // validate one of the superclass fields testValidateField("clientName", "null", bldr -> bldr.clientName(null)); - - // validate with mostly empty params - params = GuardParams.builder().clientName(CLIENT).path(PATH).timeoutSec(TIMEOUT).build(); - assertTrue(params.validate(CONTAINER).isValid()); } @Test diff --git a/models-interactions/model-actors/actor.guard/src/test/resources/makeReq.json b/models-interactions/model-actors/actor.guard/src/test/resources/makeReq.json deleted file mode 100644 index 2716d030e..000000000 --- a/models-interactions/model-actors/actor.guard/src/test/resources/makeReq.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "action": "some action", - "hello": "world", - "r u there?": "yes", - "requestId": "abcdefghi", - "resource": { - "abc": "def", - "ghi": "jkl" - } -} diff --git a/models-interactions/model-actors/actor.guard/src/test/resources/makeReqDefault.json b/models-interactions/model-actors/actor.guard/src/test/resources/makeReqDefault.json index d757eb993..a08f13f43 100644 --- a/models-interactions/model-actors/actor.guard/src/test/resources/makeReqDefault.json +++ b/models-interactions/model-actors/actor.guard/src/test/resources/makeReqDefault.json @@ -1,4 +1,10 @@ { + "ONAPName": "my-onap-name", + "ONAPComponent": "my-onap-component", + "ONAPInstance": "my-onap-instance", + "requestId": "abcdefghi", "action": "guard", - "requestId": "abcdefghi" + "resource": { + "guard": {} + } } diff --git a/models-interactions/model-actors/actor.guard/src/test/resources/makeReqStd.json b/models-interactions/model-actors/actor.guard/src/test/resources/makeReqStd.json index 6ae886726..fd1f4c716 100644 --- a/models-interactions/model-actors/actor.guard/src/test/resources/makeReqStd.json +++ b/models-interactions/model-actors/actor.guard/src/test/resources/makeReqStd.json @@ -1,11 +1,13 @@ { + "ONAPName": "my-onap-name", "ONAPComponent": "my-onap-component", "ONAPInstance": "my-onap-instance", - "ONAPName": "my-onap-name", - "action": "my-action", "requestId": "abcdefghi", + "action": "guard", "resource": { - "actor": "resource-actor", - "operation": "resource-operation" + "guard": { + "abc": "123", + "hello": "world" + } } -}
\ No newline at end of file +} diff --git a/models-interactions/model-actors/actor.guard/src/test/resources/service.yaml b/models-interactions/model-actors/actor.guard/src/test/resources/service.yaml index 131cf785b..998928d44 100644 --- a/models-interactions/model-actors/actor.guard/src/test/resources/service.yaml +++ b/models-interactions/model-actors/actor.guard/src/test/resources/service.yaml @@ -26,6 +26,10 @@ httpClients: actors: GUARD: clientName: my-client + onapName: my-onap-name + onapComponent: my-onap-component + onapInstance: my-onap-instance + action: guard operations: Decision: path: decide
\ No newline at end of file |