summaryrefslogtreecommitdiffstats
path: root/controlloop/common/rules-test/src/test
diff options
context:
space:
mode:
authorTaka Cho <takamune.cho@att.com>2020-08-03 19:49:45 -0400
committerTaka Cho <takamune.cho@att.com>2020-08-11 08:27:58 -0400
commit8d0516fd693ae0224100b74a81d09e62cea8ba62 (patch)
treed3f6f8c9d100b2dbd3f596b913b17c96fd05947a /controlloop/common/rules-test/src/test
parent64851e7331f144d19ea62d65b73ce114ee321c6d (diff)
Refactor BaseRuleTest for Drools apps
1, rename BaseRuleTest to BaseTest. 2, remove drools related code in BaseTest that would use for tdjam controller. 3, DroolsRuleTest extends BaseTest that would use for frankfurt controller for drools base. Issue-ID: POLICY-2750 Change-Id: Ica9637a850de6e929f09532f077ae3e997aa2045 Signed-off-by: Taka Cho <takamune.cho@att.com>
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/BaseTestTest.java (renamed from controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/BaseRuleTestTest.java)110
-rw-r--r--controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/DroolsRuleTestTest.java294
2 files changed, 333 insertions, 71 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/BaseTestTest.java
index 9f313ca39..ecff7e0bb 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/BaseTestTest.java
@@ -34,7 +34,6 @@ import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.concurrent.atomic.AtomicLong;
-import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.junit.AfterClass;
@@ -55,7 +54,6 @@ import org.onap.policy.common.utils.coder.StandardCoderInstantAsMillis;
import org.onap.policy.controlloop.ControlLoopNotificationType;
import org.onap.policy.controlloop.VirtualControlLoopNotification;
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;
@@ -64,17 +62,15 @@ import org.onap.policy.sdnr.PciMessage;
import org.onap.policy.sdnr.PciRequest;
import org.powermock.reflect.Whitebox;
-public class BaseRuleTestTest {
- private static final String CONTROLLER_NAME = "my-controller-name";
+public class BaseTestTest {
private static final String POLICY_NAME = "my-policy-name";
// saved values
- private static Function<String, Rules> ruleMaker;
private static Supplier<HttpClients> httpClientMaker;
private static Supplier<Simulators> simMaker;
private static Supplier<Topics> topicMaker;
- private BaseRuleTest base;
+ private BaseTest base;
private LinkedList<VirtualControlLoopNotification> clMgtQueue;
private Queue<AppcLcmDmaapWrapper> appcLcmQueue;
private Queue<Request> appcLegacyQueue;
@@ -83,10 +79,6 @@ public class BaseRuleTestTest {
private int finalCount;
@Mock
- private PolicyController controller;
- @Mock
- private Rules rules;
- @Mock
private HttpClients httpClients;
@Mock
private Simulators simulators;
@@ -113,10 +105,9 @@ public class BaseRuleTestTest {
*/
@BeforeClass
public static void setUpBeforeClass() {
- ruleMaker = Whitebox.getInternalState(BaseRuleTest.class, "ruleMaker");
- httpClientMaker = Whitebox.getInternalState(BaseRuleTest.class, "httpClientMaker");
- simMaker = Whitebox.getInternalState(BaseRuleTest.class, "simMaker");
- topicMaker = Whitebox.getInternalState(BaseRuleTest.class, "topicMaker");
+ httpClientMaker = Whitebox.getInternalState(BaseTest.class, "httpClientMaker");
+ simMaker = Whitebox.getInternalState(BaseTest.class, "simMaker");
+ topicMaker = Whitebox.getInternalState(BaseTest.class, "topicMaker");
}
/**
@@ -124,10 +115,9 @@ public class BaseRuleTestTest {
*/
@AfterClass
public static void tearDownAfterClass() {
- Whitebox.setInternalState(BaseRuleTest.class, "ruleMaker", ruleMaker);
- Whitebox.setInternalState(BaseRuleTest.class, "httpClientMaker", httpClientMaker);
- Whitebox.setInternalState(BaseRuleTest.class, "simMaker", simMaker);
- Whitebox.setInternalState(BaseRuleTest.class, "topicMaker", topicMaker);
+ Whitebox.setInternalState(BaseTest.class, "httpClientMaker", httpClientMaker);
+ Whitebox.setInternalState(BaseTest.class, "simMaker", simMaker);
+ Whitebox.setInternalState(BaseTest.class, "topicMaker", topicMaker);
}
/**
@@ -140,34 +130,22 @@ public class BaseRuleTestTest {
when(policy.getIdentifier()).thenReturn(policyIdent);
when(policyIdent.getName()).thenReturn(POLICY_NAME);
- when(drools.factCount(CONTROLLER_NAME)).thenReturn(0L);
- when(controller.getDrools()).thenReturn(drools);
-
- when(rules.getControllerName()).thenReturn(CONTROLLER_NAME);
- when(rules.getController()).thenReturn(controller);
- when(rules.setupPolicyFromFile(any())).thenAnswer(args -> {
- when(drools.factCount(CONTROLLER_NAME)).thenReturn(2L);
- return policy;
- });
-
- when(topics.createListener(BaseRuleTest.POLICY_CL_MGT_TOPIC, VirtualControlLoopNotification.class, controller))
- .thenReturn(policyClMgt);
- when(topics.createListener(eq(BaseRuleTest.APPC_LCM_READ_TOPIC), eq(AppcLcmDmaapWrapper.class),
+ when(topics.createListener(eq(BaseTest.POLICY_CL_MGT_TOPIC), eq(VirtualControlLoopNotification.class),
+ any(StandardCoder.class))).thenReturn(policyClMgt);
+ when(topics.createListener(eq(BaseTest.APPC_LCM_READ_TOPIC), eq(AppcLcmDmaapWrapper.class),
any(StandardCoder.class))).thenReturn(appcLcmRead);
- when(topics.createListener(eq(BaseRuleTest.APPC_CL_TOPIC), eq(Request.class),
+ when(topics.createListener(eq(BaseTest.APPC_CL_TOPIC), eq(Request.class),
any(StandardCoderInstantAsMillis.class))).thenReturn(appcClSink);
- when(topics.createListener(eq(BaseRuleTest.SDNR_CL_TOPIC), eq(PciMessage.class),
+ when(topics.createListener(eq(BaseTest.SDNR_CL_TOPIC), eq(PciMessage.class),
any(StandardCoder.class))).thenReturn(sdnrClSink);
- Function<String, Rules> ruleMaker = this::makeRules;
Supplier<HttpClients> httpClientMaker = this::makeHttpClients;
Supplier<Simulators> simMaker = this::makeSim;
Supplier<Topics> topicMaker = this::makeTopics;
- Whitebox.setInternalState(BaseRuleTest.class, "ruleMaker", ruleMaker);
- Whitebox.setInternalState(BaseRuleTest.class, "httpClientMaker", httpClientMaker);
- Whitebox.setInternalState(BaseRuleTest.class, "simMaker", simMaker);
- Whitebox.setInternalState(BaseRuleTest.class, "topicMaker", topicMaker);
+ Whitebox.setInternalState(BaseTest.class, "httpClientMaker", httpClientMaker);
+ Whitebox.setInternalState(BaseTest.class, "simMaker", simMaker);
+ Whitebox.setInternalState(BaseTest.class, "topicMaker", topicMaker);
clMgtQueue = new LinkedList<>();
appcLcmQueue = new LinkedList<>();
@@ -207,22 +185,19 @@ public class BaseRuleTestTest {
base = new MyTest();
- BaseRuleTest.initStatics(CONTROLLER_NAME);
+ BaseTest.initStatics();
base.init();
}
@Test
public void testInitStatics() {
- assertSame(rules, BaseRuleTest.rules);
- assertSame(httpClients, BaseRuleTest.httpClients);
- assertSame(simulators, BaseRuleTest.simulators);
+ assertSame(httpClients, BaseTest.httpClients);
+ assertSame(simulators, BaseTest.simulators);
}
@Test
public void testFinishStatics() {
- BaseRuleTest.finishStatics();
-
- verify(rules).destroy();
+ BaseTest.finishStatics();
verify(httpClients).destroy();
verify(simulators).destroy();
}
@@ -230,15 +205,12 @@ public class BaseRuleTestTest {
@Test
public void testInit() {
assertSame(topics, base.getTopics());
- assertSame(controller, base.controller);
}
@Test
public void testFinish() {
base.finish();
-
verify(topics).destroy();
- verify(rules).resetFacts();
}
@Test
@@ -256,10 +228,10 @@ public class BaseRuleTestTest {
assertTrue(clMgtQueue.isEmpty());
// initial event
- verify(topics).inject(eq(BaseRuleTest.DCAE_TOPIC), any());
+ verify(topics).inject(eq(BaseTest.DCAE_TOPIC), any());
// replies to each APPC request
- verify(topics, times(6)).inject(eq(BaseRuleTest.APPC_LCM_WRITE_TOPIC), any(), any());
+ verify(topics, times(6)).inject(eq(BaseTest.APPC_LCM_WRITE_TOPIC), any(), any());
}
@Test
@@ -285,11 +257,11 @@ public class BaseRuleTestTest {
assertTrue(clMgtQueue.isEmpty());
// initial events
- verify(topics).inject(eq(BaseRuleTest.DCAE_TOPIC), any());
- verify(topics, times(2)).inject(eq(BaseRuleTest.DCAE_TOPIC), any(), any());
+ verify(topics).inject(eq(BaseTest.DCAE_TOPIC), any());
+ verify(topics, times(2)).inject(eq(BaseTest.DCAE_TOPIC), any(), any());
// two restarts
- verify(topics, times(2)).inject(eq(BaseRuleTest.APPC_LCM_WRITE_TOPIC), any(), any());
+ verify(topics, times(2)).inject(eq(BaseTest.APPC_LCM_WRITE_TOPIC), any(), any());
}
@Test
@@ -317,10 +289,10 @@ public class BaseRuleTestTest {
assertTrue(clMgtQueue.isEmpty());
// initial events
- verify(topics, times(3)).inject(eq(BaseRuleTest.DCAE_TOPIC), any());
+ verify(topics, times(3)).inject(eq(BaseTest.DCAE_TOPIC), any());
// one restart
- verify(topics).inject(eq(BaseRuleTest.APPC_LCM_WRITE_TOPIC), any(), any());
+ verify(topics).inject(eq(BaseTest.APPC_LCM_WRITE_TOPIC), any(), any());
}
@Test
@@ -397,10 +369,10 @@ public class BaseRuleTestTest {
assertTrue(clMgtQueue.isEmpty());
// initial event
- verify(topics).inject(eq(BaseRuleTest.DCAE_TOPIC), any());
+ verify(topics).inject(eq(BaseTest.DCAE_TOPIC), any());
// reply to each APPC request
- verify(topics).inject(eq(BaseRuleTest.APPC_LCM_WRITE_TOPIC), any(), any());
+ verify(topics).inject(eq(BaseTest.APPC_LCM_WRITE_TOPIC), any(), any());
}
protected void checkAppcLegacyPolicy(String operation, Runnable test) {
@@ -417,10 +389,10 @@ public class BaseRuleTestTest {
assertTrue(clMgtQueue.isEmpty());
// initial event
- verify(topics).inject(eq(BaseRuleTest.DCAE_TOPIC), any());
+ verify(topics).inject(eq(BaseTest.DCAE_TOPIC), any());
// reply to each APPC request
- verify(topics).inject(eq(BaseRuleTest.APPC_CL_TOPIC), any(), any());
+ verify(topics).inject(eq(BaseTest.APPC_CL_TOPIC), any(), any());
}
protected void checkAppcLegacyPolicyOperationFailure(String operation, Runnable test) {
@@ -437,10 +409,10 @@ public class BaseRuleTestTest {
assertTrue(clMgtQueue.isEmpty());
// initial event
- verify(topics).inject(eq(BaseRuleTest.DCAE_TOPIC), any());
+ verify(topics).inject(eq(BaseTest.DCAE_TOPIC), any());
// reply to each APPC request
- verify(topics).inject(eq(BaseRuleTest.APPC_CL_TOPIC), any(), any());
+ verify(topics).inject(eq(BaseTest.APPC_CL_TOPIC), any(), any());
}
protected void checkAppcLegacyPolicyFinalFailure(String operation, Runnable test) {
@@ -456,7 +428,7 @@ public class BaseRuleTestTest {
assertTrue(clMgtQueue.isEmpty());
// initial event
- verify(topics).inject(eq(BaseRuleTest.DCAE_TOPIC), any());
+ verify(topics).inject(eq(BaseTest.DCAE_TOPIC), any());
// There were no requests sent
}
@@ -475,10 +447,10 @@ public class BaseRuleTestTest {
assertTrue(clMgtQueue.isEmpty());
// initial event
- verify(topics).inject(eq(BaseRuleTest.DCAE_TOPIC), any());
+ verify(topics).inject(eq(BaseTest.DCAE_TOPIC), any());
// reply to each SDNR request
- verify(topics).inject(eq(BaseRuleTest.SDNR_CL_RSP_TOPIC), any(), any());
+ verify(topics).inject(eq(BaseTest.SDNR_CL_RSP_TOPIC), any(), any());
}
protected void checkHttpPolicy(Runnable test) {
@@ -493,7 +465,7 @@ public class BaseRuleTestTest {
assertTrue(clMgtQueue.isEmpty());
// initial event
- verify(topics).inject(eq(BaseRuleTest.DCAE_TOPIC), any());
+ verify(topics).inject(eq(BaseTest.DCAE_TOPIC), any());
}
protected void checkHttpPolicyCompliantFailure(Runnable test) {
@@ -508,7 +480,7 @@ public class BaseRuleTestTest {
assertTrue(clMgtQueue.isEmpty());
// initial event
- verify(topics).inject(eq(BaseRuleTest.DCAE_TOPIC), any());
+ verify(topics).inject(eq(BaseTest.DCAE_TOPIC), any());
}
private void enqueueClMgt(ControlLoopNotificationType type) {
@@ -570,10 +542,6 @@ public class BaseRuleTestTest {
}
}
- private Rules makeRules(String controllerName) {
- return rules;
- }
-
private HttpClients makeHttpClients() {
return httpClients;
}
@@ -590,7 +558,7 @@ public class BaseRuleTestTest {
* We don't want junit trying to run this, so it's marked "Ignore".
*/
@Ignore
- private class MyTest extends BaseRuleTest {
+ private class MyTest extends BaseTest {
@Override
protected void waitForLockAndPermit(ToscaPolicy policy, Listener<VirtualControlLoopNotification> policyClMgt) {
diff --git a/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/DroolsRuleTestTest.java b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/DroolsRuleTestTest.java
new file mode 100644
index 000000000..a21fa0a93
--- /dev/null
+++ b/controlloop/common/rules-test/src/test/java/org/onap/policy/controlloop/common/rules/test/DroolsRuleTestTest.java
@@ -0,0 +1,294 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.controlloop.common.rules.test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.LinkedList;
+import java.util.Queue;
+import java.util.function.Function;
+import java.util.function.Predicate;
+import java.util.function.Supplier;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.policy.appc.Request;
+import org.onap.policy.appclcm.AppcLcmBody;
+import org.onap.policy.appclcm.AppcLcmCommonHeader;
+import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
+import org.onap.policy.appclcm.AppcLcmInput;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.common.utils.coder.StandardCoderInstantAsMillis;
+import org.onap.policy.controlloop.ControlLoopNotificationType;
+import org.onap.policy.controlloop.VirtualControlLoopNotification;
+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.PciMessage;
+import org.powermock.reflect.Whitebox;
+
+public class DroolsRuleTestTest {
+
+ private static final String CONTROLLER_NAME = "my-controller-name";
+ private static final String POLICY_NAME = "my-policy-name";
+
+ // saved values
+ private static Function<String, Rules> ruleMaker;
+ private static Supplier<HttpClients> httpClientMaker;
+ private static Supplier<Simulators> simMaker;
+ private static Supplier<Topics> topicMaker;
+
+ private DroolsRuleTest base;
+ private LinkedList<VirtualControlLoopNotification> clMgtQueue;
+ private Queue<AppcLcmDmaapWrapper> appcLcmQueue;
+ private int permitCount;
+ private int finalCount;
+
+ @Mock
+ private PolicyController controller;
+ @Mock
+ private Rules rules;
+ @Mock
+ private HttpClients httpClients;
+ @Mock
+ private Simulators simulators;
+ @Mock
+ private Topics topics;
+ @Mock
+ private Listener<VirtualControlLoopNotification> policyClMgt;
+ @Mock
+ private Listener<Request> appcClSink;
+ @Mock
+ private Listener<AppcLcmDmaapWrapper> appcLcmRead;
+ @Mock
+ private Listener<PciMessage> sdnrClSink;
+ @Mock
+ private DroolsController drools;
+ @Mock
+ private ToscaPolicy policy;
+ @Mock
+ private ToscaPolicyIdentifier policyIdent;
+
+
+ /**
+ * Saves static values from the class.
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() {
+ ruleMaker = Whitebox.getInternalState(DroolsRuleTest.class, "ruleMaker");
+ httpClientMaker = Whitebox.getInternalState(DroolsRuleTest.class, "httpClientMaker");
+ simMaker = Whitebox.getInternalState(DroolsRuleTest.class, "simMaker");
+ topicMaker = Whitebox.getInternalState(DroolsRuleTest.class, "topicMaker");
+ }
+
+ /**
+ * Restores static values.
+ */
+ @AfterClass
+ public static void tearDownAfterClass() {
+ Whitebox.setInternalState(DroolsRuleTest.class, "ruleMaker", ruleMaker);
+ Whitebox.setInternalState(DroolsRuleTest.class, "httpClientMaker", httpClientMaker);
+ Whitebox.setInternalState(DroolsRuleTest.class, "simMaker", simMaker);
+ Whitebox.setInternalState(DroolsRuleTest.class, "topicMaker", topicMaker);
+ }
+
+ /**
+ * Sets up.
+ */
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ when(policy.getIdentifier()).thenReturn(policyIdent);
+ when(policyIdent.getName()).thenReturn(POLICY_NAME);
+
+ when(drools.factCount(CONTROLLER_NAME)).thenReturn(0L);
+ when(controller.getDrools()).thenReturn(drools);
+
+ when(rules.getControllerName()).thenReturn(CONTROLLER_NAME);
+ when(rules.getController()).thenReturn(controller);
+ when(rules.setupPolicyFromFile(any())).thenAnswer(args -> {
+ when(drools.factCount(CONTROLLER_NAME)).thenReturn(2L);
+ return policy;
+ });
+
+ when(topics.createListener(DroolsRuleTest.POLICY_CL_MGT_TOPIC,
+ VirtualControlLoopNotification.class, controller)).thenReturn(policyClMgt);
+ when(topics.createListener(eq(DroolsRuleTest.APPC_LCM_READ_TOPIC), eq(AppcLcmDmaapWrapper.class),
+ any(StandardCoder.class))).thenReturn(appcLcmRead);
+ when(topics.createListener(eq(DroolsRuleTest.APPC_CL_TOPIC), eq(Request.class),
+ any(StandardCoderInstantAsMillis.class))).thenReturn(appcClSink);
+ when(topics.createListener(eq(DroolsRuleTest.SDNR_CL_TOPIC), eq(PciMessage.class),
+ any(StandardCoder.class))).thenReturn(sdnrClSink);
+
+ Function<String, Rules> ruleMaker = this::makeRules;
+ Supplier<HttpClients> httpClientMaker = this::makeHttpClients;
+ Supplier<Simulators> simMaker = this::makeSim;
+ Supplier<Topics> topicMaker = this::makeTopics;
+
+ Whitebox.setInternalState(DroolsRuleTest.class, "ruleMaker", ruleMaker);
+ Whitebox.setInternalState(DroolsRuleTest.class, "httpClientMaker", httpClientMaker);
+ Whitebox.setInternalState(DroolsRuleTest.class, "simMaker", simMaker);
+ Whitebox.setInternalState(DroolsRuleTest.class, "topicMaker", topicMaker);
+
+ clMgtQueue = new LinkedList<>();
+ appcLcmQueue = new LinkedList<>();
+
+ when(policyClMgt.await(any())).thenAnswer(args -> {
+ VirtualControlLoopNotification notif = clMgtQueue.remove();
+ Predicate<VirtualControlLoopNotification> pred = args.getArgument(0);
+ assertTrue(pred.test(notif));
+ return notif;
+ });
+
+ when(appcLcmRead.await(any())).thenAnswer(args -> {
+ AppcLcmDmaapWrapper req = appcLcmQueue.remove();
+ Predicate<AppcLcmDmaapWrapper> pred = args.getArgument(0);
+ assertTrue(pred.test(req));
+ return req;
+ });
+
+ permitCount = 0;
+ finalCount = 0;
+
+ base = new MyDroolsTest();
+ DroolsRuleTest.initStatics(CONTROLLER_NAME);
+ base.init();
+ }
+
+ @Test
+ public void testInitStatics() {
+ assertSame(rules, DroolsRuleTest.rules);
+ assertSame(httpClients, DroolsRuleTest.httpClients);
+ assertSame(simulators, DroolsRuleTest.simulators);
+ }
+
+ @Test
+ public void testFinishStatics() {
+ DroolsRuleTest.finishStatics();
+
+ verify(rules).destroy();
+ verify(httpClients).destroy();
+ verify(simulators).destroy();
+ }
+
+ @Test
+ public void testInit() {
+ assertSame(topics, base.getTopics());
+ assertSame(controller, base.controller);
+ }
+
+ @Test
+ public void testDroolsTestService123Compliant() {
+ enqueueAppcLcm("restart", "restart", "restart", "restart", "rebuild", "migrate");
+ enqueueClMgt(ControlLoopNotificationType.OPERATION_SUCCESS);
+ enqueueClMgt(ControlLoopNotificationType.FINAL_SUCCESS);
+ System.out.println("Drools TestTest Here");
+ base.testService123Compliant();
+
+ assertEquals(1, permitCount);
+ assertEquals(1, finalCount);
+
+ assertTrue(appcLcmQueue.isEmpty());
+ assertTrue(clMgtQueue.isEmpty());
+
+ // initial event
+ verify(topics).inject(eq(DroolsRuleTest.DCAE_TOPIC), any());
+
+ // replies to each APPC request
+ verify(topics, times(6)).inject(eq(DroolsRuleTest.APPC_LCM_WRITE_TOPIC), any(), any());
+ }
+
+ private void enqueueClMgt(ControlLoopNotificationType type) {
+ VirtualControlLoopNotification notif = new VirtualControlLoopNotification();
+ notif.setNotification(type);
+ notif.setPolicyName(POLICY_NAME + ".EVENT.MANAGER.FINAL");
+
+ clMgtQueue.add(notif);
+ }
+
+ private void enqueueAppcLcm(String... operationNames) {
+ for (String oper : operationNames) {
+ AppcLcmDmaapWrapper req = new AppcLcmDmaapWrapper();
+ req.setRpcName(oper);
+
+ AppcLcmBody body = new AppcLcmBody();
+ req.setBody(body);
+
+ AppcLcmInput input = new AppcLcmInput();
+ body.setInput(input);
+
+ AppcLcmCommonHeader header = new AppcLcmCommonHeader();
+ input.setCommonHeader(header);
+
+ header.setSubRequestId("my-subrequest-id");
+
+ appcLcmQueue.add(req);
+ }
+ }
+
+ private Rules makeRules(String controllerName) {
+ return rules;
+ }
+
+ private HttpClients makeHttpClients() {
+ return httpClients;
+ }
+
+ private Simulators makeSim() {
+ return simulators;
+ }
+
+ private Topics makeTopics() {
+ return topics;
+ }
+ /*
+ * We don't want junit trying to run this, so it's marked "Ignore".
+ */
+
+ @Ignore
+ private class MyDroolsTest extends DroolsRuleTest {
+
+ @Override
+ protected void waitForLockAndPermit(ToscaPolicy policy, Listener<VirtualControlLoopNotification> policyClMgt) {
+ permitCount++;
+ }
+
+ @Override
+ protected VirtualControlLoopNotification waitForFinal(ToscaPolicy policy,
+ Listener<VirtualControlLoopNotification> policyClMgt, ControlLoopNotificationType finalType) {
+ finalCount++;
+ return policyClMgt.await(notif -> notif.getNotification() == finalType);
+ }
+ }
+} \ No newline at end of file