aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/rules-test/src/test/java
diff options
context:
space:
mode:
authorpramod.jamkhedkar <pramod@research.att.com>2020-03-24 15:54:09 -0400
committerpramod.jamkhedkar <pramod@research.att.com>2020-04-10 13:40:25 -0400
commit40ba10444edf0b1ee74429b9b01ad1be40aa203b (patch)
tree7bc2969cdb45baa48246719050a148750897e8b6 /controlloop/common/rules-test/src/test/java
parentdc272e0912390292fa09e84d56380ac3697250cd (diff)
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 <pramod@research.att.com> Signed-off-by: Jim Hahn <jrh3@att.com> Signed-off-by: pramod.jamkhedkar <pramod@research.att.com>
Diffstat (limited to 'controlloop/common/rules-test/src/test/java')
-rw-r--r--controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTestTest.java74
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;
}