summaryrefslogtreecommitdiffstats
path: root/controlloop/m2/base
diff options
context:
space:
mode:
authorChou, Joseph (jc2555) <jc2555@att.com>2020-01-21 13:07:21 -0500
committerJorge Hernandez <jorge.hernandez-herrero@att.com>2020-03-06 15:55:07 +0000
commit55f3e5e9dad4a15b4bbffa892e5851abe5b900c3 (patch)
tree2b121fe44e8ba5bf5ce3240f3324452ac3610f31 /controlloop/m2/base
parentb3a65de5156de7e2f4ac6e69c515576d077443aa (diff)
ONAP m2 base junit coverage
Added testcases to improve code coverage Issue-ID: POLICY-2289 Change-Id: Ib573ae668b5bca008c4600df99e7f1cf4053d1a1 Signed-off-by: Joseph Chou <jc2555@att.com>
Diffstat (limited to 'controlloop/m2/base')
-rw-r--r--controlloop/m2/base/src/test/java/org/onap/policy/m2/base/TransactionTest.java361
-rw-r--r--controlloop/m2/base/src/test/java/org/onap/policy/m2/base/UtilTest.java73
-rw-r--r--controlloop/m2/base/src/test/java/org/onap/policy/m2/base/impl/ActorImpl.java43
-rw-r--r--controlloop/m2/base/src/test/java/org/onap/policy/m2/base/impl/OperationImpl.java75
-rw-r--r--controlloop/m2/base/src/test/resources/META-INF/services/org.onap.policy.m2.base.Actor1
5 files changed, 388 insertions, 165 deletions
diff --git a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/TransactionTest.java b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/TransactionTest.java
index 124509557..30546d0ec 100644
--- a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/TransactionTest.java
+++ b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/TransactionTest.java
@@ -22,7 +22,10 @@ package org.onap.policy.m2.base;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -32,96 +35,47 @@ import java.util.UUID;
import org.drools.core.WorkingMemory;
import org.drools.core.impl.StatefulKnowledgeSessionImpl;
-import org.junit.Ignore;
+import org.junit.BeforeClass;
import org.junit.Test;
-
+import org.kie.api.runtime.rule.FactHandle;
import org.onap.policy.controlloop.ControlLoopEventStatus;
import org.onap.policy.controlloop.ControlLoopNotification;
-import org.onap.policy.controlloop.ControlLoopTargetType;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.policy.ControlLoop;
import org.onap.policy.controlloop.policy.ControlLoopPolicy;
import org.onap.policy.controlloop.policy.FinalResult;
import org.onap.policy.controlloop.policy.Policy;
+import org.onap.policy.controlloop.policy.Target;
+import org.onap.policy.m2.base.GuardAdjunct;
public class TransactionTest {
- private VirtualControlLoopEvent setControlLoopEvent(UUID requestId, String closedLoopControlName,
- Instant eventStart, String targetType, String target) {
+ private static final String CL_NAME = "clTest";
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(closedLoopControlName);
- event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
- event.setRequestId(requestId);
- event.setClosedLoopAlarmStart(eventStart);
- event.setTarget(target);
- event.setTargetType(targetType);
- event.getAai().put("vserver.is-closed-loop-disabled", "false");
- event.getAai().put("complex.state", "NJ");
- event.getAai().put("vserver.l-interface.interface-name", "89ee9ee6-1e96-4063-b690-aa5ca9f73b32");
- event.getAai().put("vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address",
- "135.144.3.49");
- event.getAai().put("vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address", null);
- event.getAai().put("vserver.in-maint", "N");
- event.getAai().put("complex.city", "AAIDefault");
- event.getAai().put("vserver.vserver-id", "aa7a24f9-8791-491f-b31a-c8ba5ad9e2aa");
- event.getAai().put("vserver.l-interface.network-name", "vUSP_DPA3_OAM_3750");
- event.getAai().put("vserver.vserver-name", "ctsf0002vm013");
- event.getAai().put("generic-vnf.vnf-name", "ctsf0002v");
- event.getAai().put("generic-vnf.service-id", "e433710f-9217-458d-a79d-1c7aff376d89");
- event.getAai().put("vserver.selflink", "https://compute-aic.dpa3.cci.att.com:8774/v2/d0719b845a804b368f8ac0bba39e188b/servers/aa7a24f9-8791-491f-b31a-c8ba5ad9e2aa");
- event.getAai().put("generic-vnf.vnf-type", "vUSP - vCTS");
- event.getAai().put("tenant.tenant-id", "d0719b845a804b368f8ac0bba39e188b");
- event.getAai().put("cloud-region.identity-url", "");
- event.getAai().put("vserver.prov-status", "PROV");
- event.getAai().put("complex.physical-location-id", "LSLEILAA");
+ private static WorkingMemory mockWorkingMemory;
- return event;
- }
-
- private ControlLoopPolicy createControlLoop() {
-
- ControlLoop controlLoop = new ControlLoop();
- controlLoop.setControlLoopName("cltest");
- controlLoop.setTrigger_policy("testid");
- controlLoop.setTimeout(15);
-
- Policy policy = new Policy();
- policy.setActor("APPCLCM");
- policy.setId("testid");
- policy.setName("policytest");
- policy.setRecipe("restart");
- policy.setRetry(1);
- policy.setTimeout(10);
- policy.setSuccess(FinalResult.FINAL_SUCCESS.toString());
- policy.setFailure(FinalResult.FINAL_FAILURE.toString());
- policy.setFailure_exception(FinalResult.FINAL_FAILURE_EXCEPTION.toString());
- policy.setFailure_guard(FinalResult.FINAL_FAILURE_GUARD.toString());
- policy.setFailure_retries(FinalResult.FINAL_FAILURE_RETRIES.toString());
- policy.setFailure_timeout(FinalResult.FINAL_FAILURE_TIMEOUT.toString());
-
- LinkedList<Policy> policies = new LinkedList<>();
- policies.add(policy);
-
- ControlLoopPolicy controlLoopPolicy = new ControlLoopPolicy();
- controlLoopPolicy.setControlLoop(controlLoop);
- controlLoopPolicy.setPolicies(policies);
-
- return controlLoopPolicy;
+ /**
+ * Mocks the working memory.
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() {
+ mockWorkingMemory = mock(WorkingMemory.class);
+ FactHandle factHandle = mock(FactHandle.class);
+ when(mockWorkingMemory.getFactHandle(anyObject())).thenReturn(factHandle);
}
@Test
public void testValidControlLoopEvent() {
- VirtualControlLoopEvent event = setControlLoopEvent(UUID.randomUUID(),
- "cltest", Instant.now(), ControlLoopTargetType.VM, "vserver.vserver-name");
+ VirtualControlLoopEvent event =
+ createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
Transaction transaction = new Transaction(null, "clvusptest", event.getRequestId(), createControlLoop());
assertTrue(transaction.isControlLoopEventValid(event));
}
@Test
public void testNoRequestIdControlLoopEvent() {
- VirtualControlLoopEvent event = setControlLoopEvent(null,
- "cltest", Instant.now(), ControlLoopTargetType.VM, "vserver.vserver-name");
+ VirtualControlLoopEvent event =
+ createControlLoopEvent(null, CL_NAME, null, "VM", "vserver.vserver-name");
Transaction transaction = new Transaction(null, "clvusptest", event.getRequestId(), createControlLoop());
assertFalse(transaction.isControlLoopEventValid(event));
assertEquals("No requestID", transaction.getNotificationMessage());
@@ -129,8 +83,8 @@ public class TransactionTest {
@Test
public void testNoTargetTypeControlLoopEvent() {
- VirtualControlLoopEvent event = setControlLoopEvent(UUID.randomUUID(),
- "cltest", Instant.now(), null, "vserver.vserver-name");
+ VirtualControlLoopEvent event =
+ createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, null, "vserver.vserver-name");
Transaction transaction = new Transaction(null, "clvusptest", event.getRequestId(), createControlLoop());
assertFalse(transaction.isControlLoopEventValid(event));
assertEquals("No targetType", transaction.getNotificationMessage());
@@ -138,23 +92,28 @@ public class TransactionTest {
@Test
public void testNoTargetControlLoopEvent() {
- VirtualControlLoopEvent event = setControlLoopEvent(UUID.randomUUID(),
- "cltest", Instant.now(), ControlLoopTargetType.VM, null);
+ VirtualControlLoopEvent event =
+ createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", null);
Transaction transaction = new Transaction(null, "clvusptest", event.getRequestId(), createControlLoop());
assertFalse(transaction.isControlLoopEventValid(event));
assertEquals("No target field", transaction.getNotificationMessage());
}
@Test
- public void getClosedLoopControlNameTest() {
- Transaction transaction = new Transaction(null, "clvusptest", UUID.randomUUID(), createControlLoop());
- assertEquals("clvusptest", transaction.getClosedLoopControlName());
+ public void testEmptyTargetControlLoopEvent() {
+ assertInvalidTarget("");
+ }
+
+ @Test
+ public void testGetClosedLoopControlName() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
+ assertEquals(CL_NAME, transaction.getClosedLoopControlName());
}
@Test
public void testGetRequestId() {
UUID requestId = UUID.randomUUID();
- Transaction transaction = new Transaction(null, "clvusptest", requestId, createControlLoop());
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, requestId, createControlLoop());
assertEquals(requestId, transaction.getRequestId());
}
@@ -168,34 +127,36 @@ public class TransactionTest {
}
@Test
- public void getStateCompleteTest() {
- Transaction transaction = new Transaction(null, "clvusptest", UUID.randomUUID(), createControlLoop());
+ public void testGetStateComplete() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
assertEquals("COMPLETE", transaction.getState());
}
@Test
- public void getFinalResultTest() {
- Transaction transaction = new Transaction(null, "clvusptest", UUID.randomUUID(), createControlLoop());
+ public void testGetFinalResult() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
assertEquals(null, transaction.getFinalResult());
}
@Test
- public void finalResultFailureTest() {
- Transaction transaction = new Transaction(null, "clvusptest", UUID.randomUUID(), createControlLoop());
+ public void testFinalResultFailure() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
assertFalse(transaction.finalResultFailure());
+ transaction.clTimeout();
+ assertTrue(transaction.finalResultFailure());
}
@Test
- public void getTimeoutTest() {
- Transaction transaction = new Transaction(null, "clvusptest", UUID.randomUUID(), createControlLoop());
+ public void testGetTimeout() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
assertEquals("15s", transaction.getTimeout());
}
@Test
public void testGetOperationTimeout() {
Transaction transaction = new Transaction(null, "clvusptest", UUID.randomUUID(), createControlLoop());
- VirtualControlLoopEvent onset = setControlLoopEvent(UUID.randomUUID(),
- "cltest", null, ControlLoopTargetType.VM, "vserver.vserver-name");
+ VirtualControlLoopEvent onset =
+ createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
transaction.setControlLoopEvent(onset);
assertEquals("10s", transaction.getOperationTimeout());
}
@@ -203,28 +164,244 @@ public class TransactionTest {
@Test
public void testGetCurrentPolicy() {
ControlLoopPolicy controlLoopPolicy = createControlLoop();
- Transaction transaction = new Transaction(null, "clvusptest", UUID.randomUUID(), controlLoopPolicy);
- VirtualControlLoopEvent onset = setControlLoopEvent(UUID.randomUUID(),
- "cltest", null, ControlLoopTargetType.VM, "vserver.vserver-name");
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), controlLoopPolicy);
+ VirtualControlLoopEvent onset =
+ createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
transaction.setControlLoopEvent(onset);
assertEquals(controlLoopPolicy.getPolicies().get(0), transaction.getCurrentPolicy());
}
@Test
- public void getOperationTest() {
- Transaction transaction = new Transaction(null, "clvusptest", UUID.randomUUID(), createControlLoop());
+ public void testGetOperation() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
assertEquals(null, transaction.getCurrentOperation());
}
@Test
public void testGetNotification() {
Transaction transaction = new Transaction(null, "clvusptest", UUID.randomUUID(), createControlLoop());
- VirtualControlLoopEvent onset = setControlLoopEvent(UUID.randomUUID(),
- "cltest", null, ControlLoopTargetType.VM, "vserver.vserver-name");
+ VirtualControlLoopEvent onset =
+ createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
transaction.setControlLoopEvent(onset);
ControlLoopNotification notification = transaction.getNotification(onset);
assertEquals(onset.getClosedLoopControlName(), notification.getClosedLoopControlName());
assertEquals(onset.getRequestId(), notification.getRequestId());
assertEquals(onset.getTarget(), notification.getTarget());
+
+ notification = transaction.getNotification(null);
+ assertEquals(onset.getClosedLoopControlName(), notification.getClosedLoopControlName());
+ assertEquals(onset.getRequestId(), notification.getRequestId());
+ assertEquals(onset.getTarget(), notification.getTarget());
+ }
+
+ @Test
+ public void testSetControlLoopEventOnsetNotNull() {
+ UUID requestId = UUID.randomUUID();
+ VirtualControlLoopEvent event = createControlLoopEvent(requestId, CL_NAME, Instant.now(), "VM", "vserver-name");
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, requestId, createControlLoop());
+ assertEquals("COMPLETE", transaction.getState());
+ transaction.setControlLoopEvent(event);
+ assertEquals("TEST.PENDING", transaction.getState());
+ transaction.setControlLoopEvent(event);
+ }
+
+ @Test
+ public void testSetOpenLoopEvent() {
+ ControlLoop controlLoop = new ControlLoop();
+ controlLoop.setControlLoopName(CL_NAME);
+ controlLoop.setTrigger_policy(FinalResult.FINAL_OPENLOOP.toString());
+
+ ControlLoopPolicy controlLoopPolicy = new ControlLoopPolicy();
+ controlLoopPolicy.setControlLoop(controlLoop);
+
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), controlLoopPolicy);
+ VirtualControlLoopEvent onset = createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver-name");
+ transaction.setControlLoopEvent(onset);
+
+ assertEquals("COMPLETE", transaction.getState());
+ }
+
+ @Test
+ public void testIncomingMessage() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
+ ControlLoopNotification notification = transaction.incomingMessage("message 1");
+ assertNull(notification);
+
+ VirtualControlLoopEvent onset = createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver-name");
+ transaction.setControlLoopEvent(onset);
+ notification = transaction.incomingMessage("message 2");
+ assertNotNull(notification);
+ }
+
+ @Test
+ public void testIncomingMessageNullOperation() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
+ ControlLoopNotification notification = transaction.incomingMessage("test");
+ assertNull(notification);
+ }
+
+ @Test
+ public void testTimeout() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
+ VirtualControlLoopEvent onset =
+ createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
+ transaction.setControlLoopEvent(onset);
+ ControlLoopNotification notification = transaction.timeout();
+ assertNotNull(notification);
+
+ transaction.clTimeout();
+ notification = transaction.timeout();
+ assertNull(notification);
+ }
+
+ @Test
+ public void testClTimeout() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
+ transaction.clTimeout();
+ Operation operation = transaction.getCurrentOperation();
+ assertNull(operation);
+ }
+
+ @Test
+ public void testInitialOperationNotification() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
+ VirtualControlLoopEvent onset =
+ createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
+ transaction.setControlLoopEvent(onset);
+ ControlLoopNotification notification = transaction.initialOperationNotification();
+ assertNotNull(notification);
+
+ transaction.clTimeout();
+ notification = transaction.initialOperationNotification();
+ assertNull(notification);
+ }
+
+ @Test
+ public void testFinalNotification() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
+ ControlLoopNotification notification = transaction.finalNotification();
+ assertNull(notification);
+
+ VirtualControlLoopEvent onset =
+ createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
+ transaction.setControlLoopEvent(onset);
+ transaction.timeout();
+ notification = transaction.finalNotification();
+ assertNotNull(notification);
+
+ transaction.clTimeout();
+ notification = transaction.finalNotification();
+ assertNotNull(notification);
+
+ // openloop test case
+ ControlLoop controlLoop = new ControlLoop();
+ controlLoop.setControlLoopName(CL_NAME);
+ controlLoop.setTrigger_policy(FinalResult.FINAL_OPENLOOP.toString());
+ ControlLoopPolicy controlLoopPolicy = new ControlLoopPolicy();
+ controlLoopPolicy.setControlLoop(controlLoop);
+ transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), controlLoopPolicy);
+ transaction.setControlLoopEvent(onset);
+ notification = transaction.finalNotification();
+ assertNotNull(notification);
+ }
+
+ @Test
+ public void testProcessError() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
+ ControlLoopNotification notification = transaction.processError();
+ assertNull(notification);
+
+ VirtualControlLoopEvent onset =
+ createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
+ transaction.setControlLoopEvent(onset);
+ notification = transaction.processError();
+ assertNotNull(notification);
+ }
+
+ @Test
+ public void testSetNotificationMessage() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
+ transaction.setNotificationMessage("test");
+ }
+
+ @Test
+ public void testGetAdjunct() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
+ GuardAdjunct adjunct = transaction.getAdjunct(GuardAdjunct.class);
+ assertNotNull(adjunct);
+ }
+
+ @Test
+ public void testPutAdjunct() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
+ GuardAdjunct adjunct = new GuardAdjunct();
+ boolean status = transaction.putAdjunct(adjunct);
+ assertTrue(status);
+ }
+
+ @Test
+ public void testCleanup() {
+ Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
+ GuardAdjunct adjunct = new GuardAdjunct();
+ transaction.putAdjunct(adjunct);
+ GuardAdjunct adjunct2 = new GuardAdjunct();
+ transaction.putAdjunct(adjunct2);
+ transaction.cleanup();
+ }
+
+ private VirtualControlLoopEvent createControlLoopEvent(UUID requestId, String closedLoopControlName,
+ Instant eventStart, String targetType, String target) {
+
+ VirtualControlLoopEvent event = new VirtualControlLoopEvent();
+ event.setClosedLoopControlName(closedLoopControlName);
+ event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
+ event.setRequestId(requestId);
+ event.setClosedLoopAlarmStart(eventStart);
+ event.setTarget(target);
+ event.setTargetType(targetType);
+ event.getAai().put("vserver.is-closed-loop-disabled", "false");
+ event.getAai().put("vserver.in-maint", "N");
+ event.getAai().put("vserver.vserver-name", "vnf01vm01");
+ event.getAai().put("generic-vnf.vnf-name", "vnf01");
+
+ return event;
+ }
+
+ private ControlLoopPolicy createControlLoop() {
+ ControlLoop controlLoop = new ControlLoop();
+ controlLoop.setControlLoopName(CL_NAME);
+ controlLoop.setTrigger_policy("testId");
+ controlLoop.setTimeout(15);
+
+ Policy policy = new Policy();
+ policy.setActor("testActor");
+ policy.setId("testId");
+ policy.setName("testPolicy");
+ policy.setRecipe("testOperation");
+ policy.setTarget(new Target("testTarget"));
+ policy.setRetry(1);
+ policy.setTimeout(10);
+ policy.setSuccess(FinalResult.FINAL_SUCCESS.toString());
+ policy.setFailure(FinalResult.FINAL_FAILURE.toString());
+ policy.setFailure_exception(FinalResult.FINAL_FAILURE_EXCEPTION.toString());
+ policy.setFailure_guard(FinalResult.FINAL_FAILURE_GUARD.toString());
+ policy.setFailure_retries(FinalResult.FINAL_FAILURE_RETRIES.toString());
+ policy.setFailure_timeout(FinalResult.FINAL_FAILURE_TIMEOUT.toString());
+
+ LinkedList<Policy> policies = new LinkedList<>();
+ policies.add(policy);
+
+ ControlLoopPolicy controlLoopPolicy = new ControlLoopPolicy();
+ controlLoopPolicy.setControlLoop(controlLoop);
+ controlLoopPolicy.setPolicies(policies);
+
+ return controlLoopPolicy;
+ }
+
+ private void assertInvalidTarget(String target) {
+ VirtualControlLoopEvent event = createControlLoopEvent(UUID.randomUUID(), CL_NAME, Instant.now(), "VM", target);
+ Transaction transaction = new Transaction(null, CL_NAME, event.getRequestId(), createControlLoop());
+ assertFalse(transaction.isControlLoopEventValid(event));
+ assertEquals("No target field", transaction.getNotificationMessage());
}
}
diff --git a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/UtilTest.java b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/UtilTest.java
deleted file mode 100644
index d4518ca6f..000000000
--- a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/UtilTest.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/base
- * ================================================================================
- * 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.m2.base;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.Properties;
-
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
-import org.onap.policy.drools.core.PolicyContainer;
-import org.onap.policy.drools.core.PolicySession;
-import org.onap.policy.drools.system.PolicyController;
-
-public class UtilTest {
-
- private static PolicySession session;
-
- /**
- * Class-level initialization.
- */
- @BeforeClass
- public static void setup() {
- PolicyContainer container = mock(PolicyContainer.class);
- when(container.getGroupId()).thenReturn("org.onap.policy");
- when(container.getArtifactId()).thenReturn("test");
- when(container.getVersion()).thenReturn("1.0.0");
-
- session = mock(PolicySession.class);
- when(session.getPolicyContainer()).thenReturn(container);
- }
-
- @Test
- public void testDeliver() {
- Properties prop = new Properties();
- prop.put("noop.sink.topics", "testTopic");
- TopicEndpointManager.getManager().addTopicSinks(prop);
-
- // throws an exception:
- // java.lang.IllegalStateException: Policy Engine is stopped
- // if policy engine is started, it still throws an exception:
- // java.lang.IllegalArgumentException: no reverse coder has been found
- //assertTrue(Util.deliver("testTopic", "test"));
- }
-
- @Test(expected = IllegalStateException.class)
- public void deliverNoTopicTest() {
- Util.deliver("noTopic", "test");
- }
-}
diff --git a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/impl/ActorImpl.java b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/impl/ActorImpl.java
new file mode 100644
index 000000000..fe8836aa4
--- /dev/null
+++ b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/impl/ActorImpl.java
@@ -0,0 +1,43 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * m2/base
+ * ================================================================================
+ * 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.m2.base.impl;
+
+import org.onap.policy.controlloop.ControlLoopEvent;
+import org.onap.policy.controlloop.policy.Policy;
+import org.onap.policy.m2.base.Actor;
+import org.onap.policy.m2.base.Operation;
+import org.onap.policy.m2.base.Transaction;
+
+public class ActorImpl implements Actor {
+
+ public static final String ACTOR_NAME = "testActor";
+
+ @Override
+ public String getName() {
+ return ACTOR_NAME;
+ }
+
+ @Override
+ public Operation createOperation(Transaction transaction, Policy policy, ControlLoopEvent onset, int attempt) {
+ return new OperationImpl();
+ }
+
+} \ No newline at end of file
diff --git a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/impl/OperationImpl.java b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/impl/OperationImpl.java
new file mode 100644
index 000000000..56f79eec3
--- /dev/null
+++ b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/impl/OperationImpl.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * m2/base
+ * ================================================================================
+ * 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.m2.base.impl;
+
+import org.onap.policy.controlloop.ControlLoopException;
+import org.onap.policy.controlloop.policy.Policy;
+import org.onap.policy.controlloop.policy.PolicyResult;
+import org.onap.policy.m2.base.Operation;
+
+public class OperationImpl implements Operation {
+
+ private static final long serialVersionUID = 1L;
+
+ private String state = "TEST.PENDING";
+
+ @Override
+ public Object getRequest() throws ControlLoopException {
+ return "request";
+ }
+
+ @Override
+ public Policy getPolicy() {
+ return null;
+ }
+
+ @Override
+ public String getState() {
+ return state;
+ }
+
+ @Override
+ public int getAttempt() {
+ return 0;
+ }
+
+ @Override
+ public PolicyResult getResult() {
+ return PolicyResult.SUCCESS;
+ }
+
+ @Override
+ public String getMessage() {
+ state = "TEST.PENDING";
+ return "test";
+ }
+
+ @Override
+ public void incomingMessage(Object object) {
+ state = "TEST.COMPLETE";
+ }
+
+ @Override
+ public void timeout() {
+ state = "TEST.COMPLETE";
+ }
+
+} \ No newline at end of file
diff --git a/controlloop/m2/base/src/test/resources/META-INF/services/org.onap.policy.m2.base.Actor b/controlloop/m2/base/src/test/resources/META-INF/services/org.onap.policy.m2.base.Actor
new file mode 100644
index 000000000..c0d6270b2
--- /dev/null
+++ b/controlloop/m2/base/src/test/resources/META-INF/services/org.onap.policy.m2.base.Actor
@@ -0,0 +1 @@
+org.onap.policy.m2.base.impl.ActorImpl \ No newline at end of file