From 40ba10444edf0b1ee74429b9b01ad1be40aa203b Mon Sep 17 00:00:00 2001 From: "pramod.jamkhedkar" Date: Tue, 24 Mar 2020 15:54:09 -0400 Subject: Added vpci and vsonh tests Added test cases for vpci and vsonh usecases Issue-ID: POLICY-2162 Change-Id: Ia69b16e74b82b92366b5065eeccab8d35f647742 Signed-off-by: pramod.jamkhedkar Signed-off-by: Jim Hahn Signed-off-by: pramod.jamkhedkar --- .../common/rules/test/BaseRuleTestTest.java | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'controlloop/common/rules-test/src/test') diff --git a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTestTest.java b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTestTest.java index ed3d62738..0753aacd3 100644 --- a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTestTest.java +++ b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTestTest.java @@ -56,6 +56,10 @@ import org.onap.policy.drools.controller.DroolsController; import org.onap.policy.drools.system.PolicyController; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy; import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyIdentifier; +import org.onap.policy.sdnr.PciBody; +import org.onap.policy.sdnr.PciCommonHeader; +import org.onap.policy.sdnr.PciMessage; +import org.onap.policy.sdnr.PciRequest; import org.powermock.reflect.Whitebox; public class BaseRuleTestTest { @@ -72,6 +76,7 @@ public class BaseRuleTestTest { private LinkedList clMgtQueue; private Queue appcLcmQueue; private Queue appcLegacyQueue; + private Queue sdnrQueue; private int permitCount; private int finalCount; @@ -92,6 +97,8 @@ public class BaseRuleTestTest { @Mock private Listener appcLcmRead; @Mock + private Listener sdnrClSink; + @Mock private DroolsController drools; @Mock private ToscaPolicy policy; @@ -147,6 +154,8 @@ public class BaseRuleTestTest { any(StandardCoder.class))).thenReturn(appcLcmRead); when(topics.createListener(eq(BaseRuleTest.APPC_CL_TOPIC), eq(Request.class), any(StandardCoderInstantAsMillis.class))).thenReturn(appcClSink); + when(topics.createListener(eq(BaseRuleTest.SDNR_CL_TOPIC), eq(PciMessage.class), + any(StandardCoder.class))).thenReturn(sdnrClSink); Function ruleMaker = this::makeRules; Supplier httpClientMaker = this::makeHttpClients; @@ -161,6 +170,7 @@ public class BaseRuleTestTest { clMgtQueue = new LinkedList<>(); appcLcmQueue = new LinkedList<>(); appcLegacyQueue = new LinkedList<>(); + sdnrQueue = new LinkedList<>(); when(policyClMgt.await(any())).thenAnswer(args -> { VirtualControlLoopNotification notif = clMgtQueue.remove(); @@ -183,6 +193,13 @@ public class BaseRuleTestTest { return req; }); + when(sdnrClSink.await(any())).thenAnswer(args -> { + PciMessage pcireq = sdnrQueue.remove(); + Predicate pred = args.getArgument(0); + assertTrue(pred.test(pcireq)); + return pcireq; + }); + permitCount = 0; finalCount = 0; @@ -335,6 +352,26 @@ public class BaseRuleTestTest { checkAppcLegacyPolicyFinalFailure("ModifyConfig", base::testVfwRainyDayCompliantTimeout); } + @Test + public void testTestVpciSunnyDayLegacy() { + checkSdnrPolicy("ModifyConfig", base::testVpciSunnyDayLegacy); + } + + @Test + public void testTestVpciSunnyDayCompliant() { + checkSdnrPolicy("ModifyConfig", base::testVpciSunnyDayCompliant); + } + + @Test + public void testTestVsonhSunnyDayLegacy() { + checkSdnrPolicy("ModifyConfigANR", base::testVsonhSunnyDayLegacy); + } + + @Test + public void testTestVsonhSunnyDayCompliant() { + checkSdnrPolicy("ModifyConfigANR", base::testVsonhSunnyDayCompliant); + } + protected void checkAppcLcmPolicy(String operation, Runnable test) { enqueueAppcLcm(operation); enqueueClMgt(ControlLoopNotificationType.OPERATION_SUCCESS); @@ -413,6 +450,26 @@ public class BaseRuleTestTest { // There were no requests sent } + protected void checkSdnrPolicy(String operation, Runnable test) { + enqueueSdnr(operation); + enqueueClMgt(ControlLoopNotificationType.OPERATION_SUCCESS); + enqueueClMgt(ControlLoopNotificationType.FINAL_SUCCESS); + + test.run(); + + assertEquals(1, permitCount); + assertEquals(1, finalCount); + + assertTrue(sdnrQueue.isEmpty()); + assertTrue(clMgtQueue.isEmpty()); + + // initial event + verify(topics).inject(eq(BaseRuleTest.DCAE_TOPIC), any()); + + // reply to each SDNR request + verify(topics).inject(eq(BaseRuleTest.SDNR_CL_RSP_TOPIC), any(), any()); + } + protected void checkHttpPolicy(Runnable test) { enqueueClMgt(ControlLoopNotificationType.OPERATION_SUCCESS); enqueueClMgt(ControlLoopNotificationType.FINAL_SUCCESS); @@ -470,6 +527,23 @@ public class BaseRuleTestTest { } } + private void enqueueSdnr(String... operationNames) { + for (String oper : operationNames) { + PciMessage pcimessage = new PciMessage(); + PciRequest req = new PciRequest(); + PciBody body = new PciBody(); + body.setInput(req); + pcimessage.setBody(body); + pcimessage.getBody().getInput().setAction(oper); + PciCommonHeader header = new PciCommonHeader(); + pcimessage.getBody().getInput().setCommonHeader(header); + + header.setSubRequestId("my-subrequest-id"); + + sdnrQueue.add(pcimessage); + } + } + private Rules makeRules(String controllerName) { return rules; } -- cgit 1.2.3-korg