diff options
Diffstat (limited to 'controlloop/common/rules-test/src/test')
-rw-r--r-- | controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTestTest.java | 74 |
1 files changed, 74 insertions, 0 deletions
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<VirtualControlLoopNotification> clMgtQueue; private Queue<AppcLcmDmaapWrapper> appcLcmQueue; private Queue<Request> appcLegacyQueue; + private Queue<PciMessage> sdnrQueue; private int permitCount; private int finalCount; @@ -92,6 +97,8 @@ public class BaseRuleTestTest { @Mock private Listener<AppcLcmDmaapWrapper> appcLcmRead; @Mock + private Listener<PciMessage> 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<String, Rules> ruleMaker = this::makeRules; Supplier<HttpClients> 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<PciMessage> 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; } |