aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/eventmanager')
-rw-r--r--controlloop/common/eventmanager/pom.xml15
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java14
-rw-r--r--controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml8
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopExceptionTest.java9
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/drl/legacy/ControlLoopParamsTest.java42
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithEventTest.java85
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithOutcomeTest.java99
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithStepsTest.java114
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java105
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java34
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockDataTest.java72
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/StepTest.java84
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java61
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParamsTest.java28
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStubTest.java9
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java70
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java21
17 files changed, 404 insertions, 466 deletions
diff --git a/controlloop/common/eventmanager/pom.xml b/controlloop/common/eventmanager/pom.xml
index 78338f8c1..fc3da2ae6 100644
--- a/controlloop/common/eventmanager/pom.xml
+++ b/controlloop/common/eventmanager/pom.xml
@@ -27,15 +27,20 @@
<parent>
<groupId>org.onap.policy.drools-applications.controlloop.common</groupId>
<artifactId>drools-applications-common</artifactId>
- <version>2.0.0-SNAPSHOT</version>
+ <version>2.0.1-SNAPSHOT</version>
</parent>
<artifactId>eventmanager</artifactId>
<dependencies>
<dependency>
+ <groupId>org.hibernate.orm</groupId>
+ <artifactId>hibernate-core</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.hibernate</groupId>
- <artifactId>hibernate-entitymanager</artifactId>
+ <artifactId>hibernate-core-jakarta</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
@@ -176,9 +181,9 @@
<scope>provided</scope>
</dependency>
<dependency>
- <groupId>org.onap.policy.models</groupId>
- <artifactId>policy-models-decisions</artifactId>
- <version>${policy.models.version}</version>
+ <groupId>org.onap.policy.models</groupId>
+ <artifactId>policy-models-decisions</artifactId>
+ <version>${policy.models.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java
index c36ca786d..36d0ba59c 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImpl.java
@@ -21,15 +21,15 @@
package org.onap.policy.controlloop.ophistory;
+import jakarta.persistence.EntityManager;
+import jakarta.persistence.EntityManagerFactory;
+import jakarta.persistence.Persistence;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.function.Consumer;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
@@ -312,10 +312,10 @@ public class OperationHistoryDataManagerImpl implements OperationHistoryDataMana
*/
private Properties toProperties(OperationHistoryDataManagerParams params) {
var props = new Properties();
- props.put("javax.persistence.jdbc.driver", params.getDriver());
- props.put("javax.persistence.jdbc.url", params.getUrl());
- props.put("javax.persistence.jdbc.user", params.getUserName());
- props.put("javax.persistence.jdbc.password", params.getPassword());
+ props.put("jakarta.persistence.jdbc.driver", params.getDriver());
+ props.put("jakarta.persistence.jdbc.url", params.getUrl());
+ props.put("jakarta.persistence.jdbc.user", params.getUserName());
+ props.put("jakarta.persistence.jdbc.password", params.getPassword());
props.put("hibernate.dialect", params.getDbHibernateDialect());
return props;
diff --git a/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml b/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml
index 115ec51ae..e55fda222 100644
--- a/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml
+++ b/controlloop/common/eventmanager/src/main/resources/META-INF/persistence.xml
@@ -19,13 +19,17 @@
limitations under the License.
============LICENSE_END=========================================================
-->
-<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
+<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
+ version="3.0">
<persistence-unit name="OperationsHistoryPU" transaction-type="RESOURCE_LOCAL">
+ <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<class>org.onap.policy.guard.OperationsHistory</class>
<properties>
- <property name="javax.persistence.schema-generation.database.action" value="create" />
+ <property name="jakarta.persistence.schema-generation.database.action" value="create" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MariaDBDialect" />
<property name="hibernate.show_sql" value="false" />
</properties>
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopExceptionTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopExceptionTest.java
index 198af71b2..758084701 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopExceptionTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ControlLoopExceptionTest.java
@@ -3,7 +3,8 @@
* eventmanager
* ================================================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-20201 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,13 +22,13 @@
package org.onap.policy.controlloop;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.test.ExceptionsTester;
-public class ControlLoopExceptionTest {
+class ControlLoopExceptionTest {
@Test
- public void testControlLoopException() {
+ void testControlLoopException() {
new ExceptionsTester().test(ControlLoopException.class);
}
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/drl/legacy/ControlLoopParamsTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/drl/legacy/ControlLoopParamsTest.java
index f636e08f6..a09ea8512 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/drl/legacy/ControlLoopParamsTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/drl/legacy/ControlLoopParamsTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,29 +21,28 @@
package org.onap.policy.controlloop.drl.legacy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import com.openpojo.reflection.PojoClass;
import com.openpojo.reflection.impl.PojoClassFactory;
-import com.openpojo.validation.Validator;
import com.openpojo.validation.ValidatorBuilder;
import com.openpojo.validation.test.impl.GetterTester;
import com.openpojo.validation.test.impl.SetterTester;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class ControlLoopParamsTest {
+
+class ControlLoopParamsTest {
private static final String CONTROL_LOOP_NAME = "c";
private static final String POLICY_NAME = "m";
private static final String POLICY_SCOPE = "s";
private static final String POLICY_VERSION = "v";
- private ControlLoopParams clp = new ControlLoopParams();
+ private final ControlLoopParams clp = new ControlLoopParams();
/**
* Prepare tests.
*/
- @Before
+ @BeforeEach
public void setUp() {
clp.setClosedLoopControlName(CONTROL_LOOP_NAME);
clp.setPolicyName(POLICY_NAME);
@@ -51,60 +51,60 @@ public class ControlLoopParamsTest {
}
@Test
- public void testPojo() {
- PojoClass controlLoopParams = PojoClassFactory.getPojoClass(ControlLoopParams.class);
- Validator validator = ValidatorBuilder.create()
+ void testPojo() {
+ var controlLoopParams = PojoClassFactory.getPojoClass(ControlLoopParams.class);
+ var validator = ValidatorBuilder.create()
.with(new SetterTester(), new GetterTester()).build();
validator.validate(controlLoopParams);
}
@Test
- public void getClosedLoopControlName() {
+ void getClosedLoopControlName() {
assertEquals(CONTROL_LOOP_NAME, clp.getClosedLoopControlName());
}
@Test
- public void getPolicyName() {
+ void getPolicyName() {
assertEquals(POLICY_NAME, clp.getPolicyName());
}
@Test
- public void getPolicyScope() {
+ void getPolicyScope() {
assertEquals(POLICY_SCOPE, clp.getPolicyScope());
}
@Test
- public void getPolicyVersion() {
+ void getPolicyVersion() {
assertEquals(POLICY_VERSION, clp.getPolicyVersion());
}
@Test
- public void setClosedLoopControlName() {
+ void setClosedLoopControlName() {
clp.setClosedLoopControlName(CONTROL_LOOP_NAME.toUpperCase());
assertEquals(CONTROL_LOOP_NAME.toUpperCase(), clp.getClosedLoopControlName());
}
@Test
- public void setPolicyName() {
+ void setPolicyName() {
clp.setPolicyName(POLICY_NAME.toUpperCase());
assertEquals(POLICY_NAME.toUpperCase(), clp.getPolicyName());
}
@Test
- public void setPolicyScope() {
+ void setPolicyScope() {
clp.setPolicyScope(POLICY_SCOPE.toUpperCase());
assertEquals(POLICY_SCOPE.toUpperCase(), clp.getPolicyScope());
}
@Test
- public void setPolicyVersion() {
+ void setPolicyVersion() {
clp.setPolicyVersion(POLICY_VERSION.toUpperCase());
assertEquals(POLICY_VERSION.toUpperCase(), clp.getPolicyVersion());
}
@Test
- public void testTwo() {
- ControlLoopParams other = new ControlLoopParams();
+ void testTwo() {
+ var other = new ControlLoopParams();
other.setClosedLoopControlName(CONTROL_LOOP_NAME);
other.setPolicyName(POLICY_NAME);
other.setPolicyScope(POLICY_SCOPE);
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithEventTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithEventTest.java
index ad01fee78..3b16f465b 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithEventTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithEventTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021, 2023 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,11 +24,12 @@ package org.onap.policy.controlloop.eventmanager;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -41,18 +43,14 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import org.drools.core.WorkingMemory;
import org.drools.core.common.InternalFactHandle;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.controlloop.ControlLoopEventStatus;
import org.onap.policy.controlloop.ControlLoopException;
-import org.onap.policy.controlloop.ControlLoopResponse;
import org.onap.policy.controlloop.ControlLoopTargetType;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.VirtualControlLoopNotification;
@@ -73,8 +71,7 @@ import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-@RunWith(MockitoJUnitRunner.class)
-public class ClEventManagerWithEventTest {
+class ClEventManagerWithEventTest {
private static final UUID REQ_ID = UUID.randomUUID();
private static final String CL_NAME = "my-closed-loop-name";
private static final String POLICY_NAME = "my-policy-name";
@@ -91,30 +88,18 @@ public class ClEventManagerWithEventTest {
private static final Coder yamlCoder = new StandardYamlCoder();
private static final String OUTCOME_MSG = "my outcome message";
- @Mock
- private PolicyEngine engineMgr;
- @Mock
- private WorkingMemory workMem;
- @Mock
- private InternalFactHandle factHandle;
- @Mock
- private Operator policyOperator;
- @Mock
- private Operation policyOperation;
- @Mock
- private Actor policyActor;
- @Mock
- private EventManagerServices services;
- @Mock
- private ActorService actors;
- @Mock
- private OperationHistoryDataManager dataMgr;
- @Mock
- private ExecutorService executor;
- @Mock
- private MyStep stepa;
- @Mock
- private MyStep stepb;
+ private final PolicyEngine engineMgr = mock(PolicyEngine.class);
+ private final WorkingMemory workMem = mock(WorkingMemory.class);
+ private final InternalFactHandle factHandle = mock(InternalFactHandle.class);
+ private final Operator policyOperator = mock(Operator.class);
+ private final Operation policyOperation = mock(Operation.class);
+ private final Actor policyActor = mock(Actor.class);
+ private final EventManagerServices services = mock(EventManagerServices.class);
+ private final ActorService actors = mock(ActorService.class);
+ private final OperationHistoryDataManager dataMgr = mock(OperationHistoryDataManager.class);
+ private final ExecutorService executor = mock(ExecutorService.class);
+ private final MyStep stepa = mock(MyStep.class);
+ private final MyStep stepb = mock(MyStep.class);
private List<LockImpl> locks;
private ToscaPolicy tosca;
@@ -125,7 +110,7 @@ public class ClEventManagerWithEventTest {
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() throws ControlLoopException, CoderException {
when(services.getActorService()).thenReturn(actors);
when(services.getDataManager()).thenReturn(dataMgr);
@@ -154,7 +139,7 @@ public class ClEventManagerWithEventTest {
}
@Test
- public void testConstructor() {
+ void testConstructor() {
assertEquals(POLICY_NAME, mgr.getPolicyName());
assertSame(event, mgr.getEvent());
@@ -168,7 +153,7 @@ public class ClEventManagerWithEventTest {
}
@Test
- public void testPopulateNotification() throws Exception {
+ void testPopulateNotification() throws Exception {
loadPolicy(EVENT_MGR_MULTI_YAML);
mgr = new MyManager(services, params, event, workMem);
@@ -228,7 +213,7 @@ public class ClEventManagerWithEventTest {
}
@Test
- public void testStoreInDataBase() throws ControlLoopException {
+ void testStoreInDataBase() throws ControlLoopException {
mgr.start();
OperationOutcome outcome = makeOutcome();
mgr.addToHistory(outcome);
@@ -240,10 +225,10 @@ public class ClEventManagerWithEventTest {
}
@Test
- public void testMakeControlLoopResponse() {
- final OperationOutcome outcome = new OperationOutcome();
+ void testMakeControlLoopResponse() {
+ final var outcome = new OperationOutcome();
- ControlLoopResponse resp = mgr.makeControlLoopResponse(outcome);
+ var resp = mgr.makeControlLoopResponse(outcome);
assertNotNull(resp);
assertEquals("DCAE", resp.getTarget());
assertEquals(event.getClosedLoopControlName(), resp.getClosedLoopControlName());
@@ -254,8 +239,8 @@ public class ClEventManagerWithEventTest {
}
@Test
- public void testOnNewEvent() {
- VirtualControlLoopEvent event2 = new VirtualControlLoopEvent(event);
+ void testOnNewEvent() {
+ var event2 = new VirtualControlLoopEvent(event);
assertEquals(NewEventStatus.FIRST_ONSET, mgr.onNewEvent(event2));
event2.setPayload("other payload");
@@ -274,7 +259,7 @@ public class ClEventManagerWithEventTest {
}
@Test
- public void testCheckEventSyntax() {
+ void testCheckEventSyntax() {
// initially, it's valid
assertThatCode(() -> mgr.checkEventSyntax(event)).doesNotThrowAnyException();
@@ -296,7 +281,7 @@ public class ClEventManagerWithEventTest {
}
@Test
- public void testValidateStatus() {
+ void testValidateStatus() {
event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
assertThatCode(() -> mgr.checkEventSyntax(event)).doesNotThrowAnyException();
@@ -309,7 +294,7 @@ public class ClEventManagerWithEventTest {
}
private void loadPolicy(String fileName) throws CoderException {
- ToscaServiceTemplate template =
+ var template =
yamlCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
tosca = template.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
@@ -317,14 +302,14 @@ public class ClEventManagerWithEventTest {
}
private OperationOutcome makeCompletedOutcome() {
- OperationOutcome outcome = makeOutcome();
+ var outcome = makeOutcome();
outcome.setEnd(outcome.getStart());
return outcome;
}
private OperationOutcome makeOutcome() {
- OperationOutcome outcome = new OperationOutcome();
+ var outcome = new OperationOutcome();
outcome.setActor(SIMPLE_ACTOR);
outcome.setOperation(SIMPLE_OPERATION);
outcome.setMessage(OUTCOME_MSG);
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithOutcomeTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithOutcomeTest.java
index 7534635d1..17e81044d 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithOutcomeTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithOutcomeTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021, 2023 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,13 +23,14 @@ package org.onap.policy.controlloop.eventmanager;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-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.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.time.Instant;
@@ -39,18 +41,13 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import org.drools.core.WorkingMemory;
import org.drools.core.common.InternalFactHandle;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.controlloop.ControlLoopException;
-import org.onap.policy.controlloop.ControlLoopResponse;
-import org.onap.policy.controlloop.VirtualControlLoopNotification;
import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
@@ -65,8 +62,7 @@ import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-@RunWith(MockitoJUnitRunner.class)
-public class ClEventManagerWithOutcomeTest {
+class ClEventManagerWithOutcomeTest {
private static final UUID REQ_ID = UUID.randomUUID();
private static final String CL_NAME = "my-closed-loop-name";
private static final String POLICY_NAME = "my-policy-name";
@@ -82,26 +78,16 @@ public class ClEventManagerWithOutcomeTest {
private static final Coder yamlCoder = new StandardYamlCoder();
private static final String OUTCOME_MSG = "my outcome message";
- @Mock
- private PolicyEngine engineMgr;
- @Mock
- private WorkingMemory workMem;
- @Mock
- private InternalFactHandle factHandle;
- @Mock
- private Operator policyOperator;
- @Mock
- private Operation policyOperation;
- @Mock
- private Actor policyActor;
- @Mock
- private EventManagerServices services;
- @Mock
- private ExecutorService executor;
- @Mock
- private MyStep stepa;
- @Mock
- private MyStep stepb;
+ private final PolicyEngine engineMgr = mock(PolicyEngine.class);
+ private final WorkingMemory workMem = mock(WorkingMemory.class);
+ private final InternalFactHandle factHandle = mock(InternalFactHandle.class);
+ private final Operator policyOperator = mock(Operator.class);
+ private final Operation policyOperation = mock(Operation.class);
+ private final Actor policyActor = mock(Actor.class);
+ private final EventManagerServices services = mock(EventManagerServices.class);
+ private final ExecutorService executor = mock(ExecutorService.class);
+ private final MyStep stepa = mock(MyStep.class);
+ private final MyStep stepb = mock(MyStep.class);
private List<LockImpl> locks;
private ToscaPolicy tosca;
@@ -111,7 +97,7 @@ public class ClEventManagerWithOutcomeTest {
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() throws ControlLoopException, CoderException {
when(workMem.getFactHandle(any())).thenReturn(factHandle);
@@ -129,7 +115,7 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testConstructor() {
+ void testConstructor() {
assertEquals(POLICY_NAME, mgr.getPolicyName());
// invalid
@@ -138,7 +124,7 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testLoadNextPolicy_testGetFullHistory_testGetPartialHistory() throws Exception {
+ void testLoadNextPolicy_testGetFullHistory_testGetPartialHistory() throws Exception {
loadPolicy(EVENT_MGR_MULTI_YAML);
mgr = new MyManager(services, params, REQ_ID, workMem);
@@ -148,7 +134,7 @@ public class ClEventManagerWithOutcomeTest {
assertNull(mgr.getFinalResult());
// add an outcome
- OperationOutcome outcome = makeOutcome();
+ var outcome = makeOutcome();
mgr.addToHistory(outcome);
// indicate success and load next policy
@@ -162,7 +148,7 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testExecuteStep() {
+ void testExecuteStep() {
mgr.bumpAttempts();
// no steps to execute
@@ -171,7 +157,7 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testBumpAttempts() {
+ void testBumpAttempts() {
assertEquals(0, mgr.getAttempts());
mgr.bumpAttempts();
@@ -180,8 +166,8 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testIsAbort() {
- OperationOutcome outcome = makeCompletedOutcome();
+ void testIsAbort() {
+ var outcome = makeCompletedOutcome();
outcome.setResult(OperationResult.FAILURE);
assertTrue(mgr.isAbort(outcome));
@@ -192,11 +178,11 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testAddToHistory() throws ControlLoopException {
+ void testAddToHistory() throws ControlLoopException {
mgr.start();
// add a "start" outcome
- OperationOutcome outcome = makeOutcome();
+ var outcome = makeOutcome();
mgr.addToHistory(outcome);
assertThat(mgr.getPartialHistory()).hasSize(1);
@@ -244,7 +230,7 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testMakeNotification() throws Exception {
+ void testMakeNotification() throws Exception {
loadPolicy(EVENT_MGR_MULTI_YAML);
mgr = new MyManager(services, params, REQ_ID, workMem);
@@ -258,7 +244,7 @@ public class ClEventManagerWithOutcomeTest {
mgr.addToHistory(makeCompletedOutcome());
// check notification while running
- VirtualControlLoopNotification notif = mgr.makeNotification();
+ var notif = mgr.makeNotification();
assertThat(notif.getMessage()).contains(SIMPLE_ACTOR);
assertThat(notif.getHistory()).hasSize(3);
@@ -296,13 +282,13 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testGetOperationMessage() throws ControlLoopException {
+ void testGetOperationMessage() throws ControlLoopException {
// no history yet
assertNull(mgr.getOperationMessage());
// add an outcome
mgr.start();
- OperationOutcome outcome = makeOutcome();
+ var outcome = makeOutcome();
mgr.addToHistory(outcome);
assertThat(mgr.getOperationMessage()).contains("actor=" + SIMPLE_ACTOR)
@@ -310,32 +296,31 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testMakeControlLoopResponse() {
- final OperationOutcome outcome = new OperationOutcome();
+ void testMakeControlLoopResponse() {
+ final var outcome = new OperationOutcome();
outcome.setActor(SIMPLE_ACTOR);
- ControlLoopResponse resp = mgr.makeControlLoopResponse(outcome);
+ var resp = mgr.makeControlLoopResponse(outcome);
assertNotNull(resp);
assertEquals(SIMPLE_ACTOR, resp.getFrom());
}
private void loadPolicy(String fileName) throws CoderException {
- ToscaServiceTemplate template =
- yamlCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
+ var template = yamlCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
tosca = template.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
params.setToscaPolicy(tosca);
}
private OperationOutcome makeCompletedOutcome() {
- OperationOutcome outcome = makeOutcome();
+ var outcome = makeOutcome();
outcome.setEnd(outcome.getStart());
return outcome;
}
private OperationOutcome makeOutcome() {
- OperationOutcome outcome = new OperationOutcome();
+ var outcome = new OperationOutcome();
outcome.setActor(SIMPLE_ACTOR);
outcome.setOperation(SIMPLE_OPERATION);
outcome.setMessage(OUTCOME_MSG);
@@ -363,7 +348,7 @@ public class ClEventManagerWithOutcomeTest {
@Override
protected void makeLock(String targetEntity, String requestId, int holdSec, LockCallback callback) {
- LockImpl lock = new LockImpl(LockState.ACTIVE, targetEntity, requestId, holdSec, callback);
+ var lock = new LockImpl(LockState.ACTIVE, targetEntity, requestId, holdSec, callback);
locks.add(lock);
callback.lockAvailable(lock);
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithStepsTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithStepsTest.java
index 76e8167f4..95d4046ce 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithStepsTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithStepsTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021, 2023 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,21 +25,21 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-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.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.time.Instant;
import java.util.ArrayList;
-import java.util.Deque;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
@@ -46,11 +47,8 @@ import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.atomic.AtomicReference;
import org.drools.core.WorkingMemory;
import org.drools.core.common.InternalFactHandle;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardYamlCoder;
@@ -73,8 +71,7 @@ import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-@RunWith(MockitoJUnitRunner.class)
-public class ClEventManagerWithStepsTest {
+class ClEventManagerWithStepsTest {
private static final UUID REQ_ID = UUID.randomUUID();
private static final String CL_NAME = "my-closed-loop-name";
private static final String POLICY_NAME = "my-policy-name";
@@ -91,28 +88,17 @@ public class ClEventManagerWithStepsTest {
private static final String OUTCOME_MSG = "my outcome message";
private static final String MY_SINK = "my-topic-sink";
- @Mock
- private PolicyEngine engineMgr;
- @Mock
- private WorkingMemory workMem;
- @Mock
- private InternalFactHandle factHandle;
- @Mock
- private Operator policyOperator;
- @Mock
- private Operation policyOperation;
- @Mock
- private Actor policyActor;
- @Mock
- private ExecutorService executor;
- @Mock
- private EventManagerServices services;
- @Mock
- private ActorService actors;
- @Mock
- private MyStep stepa;
- @Mock
- private MyStep stepb;
+ private final PolicyEngine engineMgr = mock(PolicyEngine.class);
+ private final WorkingMemory workMem = mock(WorkingMemory.class);
+ private final InternalFactHandle factHandle = mock(InternalFactHandle.class);
+ private final Operator policyOperator = mock(Operator.class);
+ private final Operation policyOperation = mock(Operation.class);
+ private final Actor policyActor = mock(Actor.class);
+ private final ExecutorService executor = mock(ExecutorService.class);
+ private final EventManagerServices services = mock(EventManagerServices.class);
+ private final ActorService actors = mock(ActorService.class);
+ private MyStep stepa = mock(MyStep.class);
+ private final MyStep stepb = mock(MyStep.class);
private List<LockImpl> locks;
private ToscaPolicy tosca;
@@ -122,7 +108,7 @@ public class ClEventManagerWithStepsTest {
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() throws ControlLoopException, CoderException {
when(services.getActorService()).thenReturn(actors);
@@ -142,7 +128,7 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testConstructor() {
+ void testConstructor() {
assertEquals(POLICY_NAME, mgr.getPolicyName());
// invalid
@@ -151,7 +137,7 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testDestroy_testGetSteps() {
+ void testDestroy_testGetSteps() {
// add some steps to the queue
mgr.getSteps().add(stepa);
mgr.getSteps().add(stepb);
@@ -167,8 +153,8 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testOnStart() throws ControlLoopException {
- OperationOutcome outcome = makeOutcome();
+ void testOnStart() throws ControlLoopException {
+ var outcome = makeOutcome();
mgr.start();
mgr.onStart(outcome);
@@ -180,8 +166,8 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testOnComplete() throws ControlLoopException {
- OperationOutcome outcome = makeCompletedOutcome();
+ void testOnComplete() throws ControlLoopException {
+ var outcome = makeCompletedOutcome();
mgr.start();
mgr.onComplete(outcome);
@@ -193,12 +179,12 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testToString() {
+ void testToString() {
assertNotNull(mgr.toString());
}
@Test
- public void testStart() throws ControlLoopException {
+ void testStart() throws ControlLoopException {
// start it
mgr.start();
@@ -211,7 +197,7 @@ public class ClEventManagerWithStepsTest {
* Tests start() when the manager is not in working memory.
*/
@Test
- public void testStartNotInWorkingMemory() throws ControlLoopException {
+ void testStartNotInWorkingMemory() throws ControlLoopException {
when(workMem.getFactHandle(any())).thenReturn(null);
assertThatCode(() -> mgr.start()).isInstanceOf(IllegalStateException.class)
@@ -222,10 +208,9 @@ public class ClEventManagerWithStepsTest {
* Tests start() when the manager is not active.
*/
@Test
- public void testStartInactive() throws Exception {
+ void testStartInactive() throws Exception {
// make an inactive manager by deserializing it
- RealManager mgr2 = Serializer.roundTrip(new RealManager(services, params, REQ_ID, workMem));
- mgr = mgr2;
+ mgr = Serializer.roundTrip(new RealManager(services, params, REQ_ID, workMem));
// cannot re-start
assertThatCode(() -> mgr.start()).isInstanceOf(IllegalStateException.class)
@@ -233,7 +218,7 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testAbort() {
+ void testAbort() {
mgr.abort(ClEventManagerWithSteps.State.DONE, OperationFinalResult.FINAL_FAILURE_GUARD, "some message");
assertEquals(ClEventManagerWithSteps.State.DONE, mgr.getState());
@@ -266,18 +251,18 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testLoadPolicy() throws ControlLoopException {
+ void testLoadPolicy() throws ControlLoopException {
// start() will invoke loadPolicy()
mgr.start();
assertNull(mgr.getFinalResult());
- MyStep step = mgr.getSteps().peek();
+ var step = mgr.getSteps().peek();
assertNotNull(step);
assertEquals("First", step.getActorName());
assertEquals("OperationA", step.getOperationName());
- ControlLoopOperationParams params2 = step.getParams();
+ var params2 = step.getParams();
assertSame(actors, params2.getActorService());
assertSame(REQ_ID, params2.getRequestId());
assertSame(ForkJoinPool.commonPool(), params2.getExecutor());
@@ -291,7 +276,7 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testLoadPreprocessorSteps() {
+ void testLoadPreprocessorSteps() {
stepa = new MyStep(mgr, ControlLoopOperationParams.builder().build()) {
@Override
protected Operation buildOperation() {
@@ -299,7 +284,7 @@ public class ClEventManagerWithStepsTest {
}
};
- Deque<MyStep> steps = mgr.getSteps();
+ var steps = mgr.getSteps();
steps.add(stepa);
steps.add(stepb);
@@ -320,7 +305,7 @@ public class ClEventManagerWithStepsTest {
* Tests loadPreprocessorSteps() when there are too many steps in the queue.
*/
@Test
- public void testLoadPreprocessorStepsTooManySteps() {
+ void testLoadPreprocessorStepsTooManySteps() {
stepa = new MyStep(mgr, ControlLoopOperationParams.builder().build()) {
@Override
protected Operation buildOperation() {
@@ -328,7 +313,7 @@ public class ClEventManagerWithStepsTest {
}
};
- Deque<MyStep> steps = mgr.getSteps();
+ var steps = mgr.getSteps();
// load up a bunch of steps
for (int nsteps = 0; nsteps < ClEventManagerWithSteps.MAX_STEPS; ++nsteps) {
@@ -353,7 +338,7 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testExecuteStep() {
+ void testExecuteStep() {
// no steps to execute
assertFalse(mgr.executeStep());
@@ -370,7 +355,7 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testNextStep() {
+ void testNextStep() {
mgr.getSteps().add(stepa);
mgr.nextStep();
@@ -379,7 +364,7 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testDeliver() {
+ void testDeliver() {
mgr.deliver(MY_SINK, null, "null notification", "null rule");
verify(engineMgr, never()).deliver(any(), any());
@@ -392,22 +377,21 @@ public class ClEventManagerWithStepsTest {
}
private void loadPolicy(String fileName) throws CoderException {
- ToscaServiceTemplate template =
- yamlCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
+ var template = yamlCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
tosca = template.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
params.setToscaPolicy(tosca);
}
private OperationOutcome makeCompletedOutcome() {
- OperationOutcome outcome = makeOutcome();
+ var outcome = makeOutcome();
outcome.setEnd(outcome.getStart());
return outcome;
}
private OperationOutcome makeOutcome() {
- OperationOutcome outcome = new OperationOutcome();
+ var outcome = new OperationOutcome();
outcome.setActor(SIMPLE_ACTOR);
outcome.setOperation(SIMPLE_OPERATION);
outcome.setMessage(OUTCOME_MSG);
@@ -435,7 +419,7 @@ public class ClEventManagerWithStepsTest {
@Override
protected void makeLock(String targetEntity, String requestId, int holdSec, LockCallback callback) {
- LockImpl lock = new LockImpl(LockState.ACTIVE, targetEntity, requestId, holdSec, callback);
+ var lock = new LockImpl(LockState.ACTIVE, targetEntity, requestId, holdSec, callback);
locks.add(lock);
callback.lockAvailable(lock);
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
index ece13611b..d83c3fe78 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,11 +23,12 @@ package org.onap.policy.controlloop.eventmanager;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -34,14 +36,10 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
-import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardYamlCoder;
@@ -59,8 +57,7 @@ import org.onap.policy.drools.core.lock.LockState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-@RunWith(MockitoJUnitRunner.class)
-public class ControlLoopEventManagerTest {
+class ControlLoopEventManagerTest {
private static final UUID REQ_ID = UUID.randomUUID();
private static final String EXPECTED_EXCEPTION = "expected exception";
private static final String CL_NAME = "my-closed-loop-name";
@@ -72,12 +69,9 @@ public class ControlLoopEventManagerTest {
private static final Coder yamlCoder = new StandardYamlCoder();
private static final String MY_KEY = "def";
- @Mock
- private ExecutorService executor;
- @Mock
- private EventManagerServices services;
- @Mock
- private OperationHistoryDataManager dataMgr;
+ private final ExecutorService executor = mock(ExecutorService.class);
+ private final EventManagerServices services = mock(EventManagerServices.class);
+ private final OperationHistoryDataManager dataMgr = mock(OperationHistoryDataManager.class);
private long preCreateTimeMs;
private List<LockImpl> locks;
@@ -88,7 +82,7 @@ public class ControlLoopEventManagerTest {
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() throws ControlLoopException, CoderException {
when(services.getDataManager()).thenReturn(dataMgr);
@@ -111,7 +105,7 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testConstructor() {
+ void testConstructor() {
assertEquals(POLICY_NAME, mgr.getPolicyName());
assertTrue(mgr.isActive());
@@ -124,7 +118,7 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testGetCreateCount() throws ControlLoopException {
+ void testGetCreateCount() throws ControlLoopException {
long original = ControlLoopEventManager.getCreateCount();
new MyManager(services, params, REQ_ID);
@@ -135,26 +129,26 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testIsActive() throws Exception {
+ void testIsActive() throws Exception {
mgr = new ControlLoopEventManager(services, params, REQ_ID);
assertTrue(mgr.isActive());
- ControlLoopEventManager mgr2 = Serializer.roundTrip(mgr);
+ var mgr2 = Serializer.roundTrip(mgr);
assertFalse(mgr2.isActive());
}
@Test
- public void testDestroy() throws IOException {
+ void testDestroy() throws IOException {
mgr.requestLock(LOCK1);
mgr.requestLock(LOCK2);
mgr.requestLock(LOCK1);
// ensure destroy() doesn't throw an exception if the object is deserialized
- ControlLoopEventManager mgr2 = Serializer.roundTrip(mgr);
+ var mgr2 = Serializer.roundTrip(mgr);
assertThatCode(() -> mgr2.destroy()).doesNotThrowAnyException();
// locks should not have been freed
- for (LockImpl lock : locks) {
+ for (var lock : locks) {
assertFalse(lock.isUnavailable());
}
@@ -162,24 +156,24 @@ public class ControlLoopEventManagerTest {
runExecutor();
- for (LockImpl lock : locks) {
+ for (var lock : locks) {
assertTrue(lock.isUnavailable());
}
}
@Test
- public void testDetmControlLoopTimeoutMs() throws Exception {
+ void testDetmControlLoopTimeoutMs() throws Exception {
long timeMs = 1200 * 1000L;
long end = mgr.getEndTimeMs();
assertThat(end).isGreaterThanOrEqualTo(preCreateTimeMs + timeMs).isLessThan(preCreateTimeMs + timeMs + 5000);
}
@Test
- public void testRequestLock() {
- final CompletableFuture<OperationOutcome> future1 = mgr.requestLock(LOCK1);
+ void testRequestLock() {
+ final var future1 = mgr.requestLock(LOCK1);
assertTrue(mgr.getOutcomes().isEmpty());
- final CompletableFuture<OperationOutcome> future2 = mgr.requestLock(LOCK2);
+ final var future2 = mgr.requestLock(LOCK2);
assertTrue(mgr.getOutcomes().isEmpty());
assertSame(future1, mgr.requestLock(LOCK1));
@@ -198,18 +192,18 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testReleaseLock() {
+ void testReleaseLock() {
mgr.requestLock(LOCK1);
mgr.requestLock(LOCK2);
// release one lock
- final CompletableFuture<OperationOutcome> future = mgr.releaseLock(LOCK1);
+ final var future = mgr.releaseLock(LOCK1);
// asynchronous, thus should not have executed yet
assertThat(future.isDone()).isFalse();
// asynchronous, thus everything should still be locked
- for (LockImpl lock : locks) {
+ for (var lock : locks) {
assertThat(lock.isUnavailable()).isFalse();
}
@@ -229,8 +223,8 @@ public class ControlLoopEventManagerTest {
* Tests releaseLock() when there is no lock.
*/
@Test
- public void testReleaseLockNotLocked() {
- final CompletableFuture<OperationOutcome> future = mgr.releaseLock(LOCK1);
+ void testReleaseLockNotLocked() {
+ final var future = mgr.releaseLock(LOCK1);
// lock didn't exist, so the request should already be complete
assertThat(future.isDone()).isTrue();
@@ -243,14 +237,14 @@ public class ControlLoopEventManagerTest {
* Tests releaseLock() when lock.free() throws an exception.
*/
@Test
- public void testReleaseLockException() throws ControlLoopException {
+ void testReleaseLockException() throws ControlLoopException {
mgr = new MyManager(services, params, REQ_ID) {
private static final long serialVersionUID = 1L;
@Override
protected void makeLock(String targetEntity, String requestId, int holdSec, LockCallback callback) {
- LockImpl lock = new LockImpl(LockState.ACTIVE, targetEntity, requestId, holdSec, callback) {
+ var lock = new LockImpl(LockState.ACTIVE, targetEntity, requestId, holdSec, callback) {
private static final long serialVersionUID = 1L;
@Override
@@ -267,7 +261,7 @@ public class ControlLoopEventManagerTest {
mgr.requestLock(LOCK1);
// release the lock
- final CompletableFuture<OperationOutcome> future = mgr.releaseLock(LOCK1);
+ final var future = mgr.releaseLock(LOCK1);
// asynchronous, thus should not have executed yet
assertThat(future.isDone()).isFalse();
@@ -279,7 +273,7 @@ public class ControlLoopEventManagerTest {
}
private void verifyLock(OperationResult result, String lockOperation) {
- OperationOutcome outcome = mgr.getOutcomes().poll();
+ var outcome = mgr.getOutcomes().poll();
assertNotNull(outcome);
assertEquals(ActorConstants.LOCK_ACTOR, outcome.getActor());
assertEquals(lockOperation, outcome.getOperation());
@@ -289,9 +283,9 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testOnStart() {
- OperationOutcome outcome1 = new OperationOutcome();
- OperationOutcome outcome2 = new OperationOutcome();
+ void testOnStart() {
+ var outcome1 = new OperationOutcome();
+ var outcome2 = new OperationOutcome();
mgr.onStart(outcome1);
mgr.onStart(outcome2);
@@ -302,9 +296,9 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testOnComplete() {
- OperationOutcome outcome1 = new OperationOutcome();
- OperationOutcome outcome2 = new OperationOutcome();
+ void testOnComplete() {
+ var outcome1 = new OperationOutcome();
+ var outcome2 = new OperationOutcome();
mgr.onComplete(outcome1);
mgr.onComplete(outcome2);
@@ -315,14 +309,14 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testContains_testGetProperty_testSetProperty_testRemoveProperty() {
+ void testContains_testGetProperty_testSetProperty_testRemoveProperty() {
mgr.setProperty("abc", "a string");
mgr.setProperty(MY_KEY, 100);
assertTrue(mgr.contains(MY_KEY));
assertFalse(mgr.contains("ghi"));
- String strValue = mgr.getProperty("abc");
+ var strValue = mgr.getProperty("abc");
assertEquals("a string", strValue);
int intValue = mgr.getProperty(MY_KEY);
@@ -336,7 +330,7 @@ public class ControlLoopEventManagerTest {
* Tests getDataManager() when not disabled.
*/
@Test
- public void testGetDataManagerNotDisabled() throws ControlLoopException {
+ void testGetDataManagerNotDisabled() throws ControlLoopException {
assertThat(mgr.getDataManager()).isSameAs(dataMgr);
}
@@ -344,7 +338,7 @@ public class ControlLoopEventManagerTest {
* Tests getDataManager() when guard.disabled=true.
*/
@Test
- public void testGetDataManagerDisabled() throws ControlLoopException {
+ void testGetDataManagerDisabled() throws ControlLoopException {
mgr = new MyManager(services, params, REQ_ID) {
private static final long serialVersionUID = 1L;
@@ -358,20 +352,19 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testToString() {
+ void testToString() {
assertNotNull(mgr.toString());
}
private void loadPolicy(String fileName) throws CoderException {
- ToscaServiceTemplate template =
- yamlCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
+ var template = yamlCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
tosca = template.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
params.setToscaPolicy(tosca);
}
private void runExecutor() {
- ArgumentCaptor<Runnable> runCaptor = ArgumentCaptor.forClass(Runnable.class);
+ var runCaptor = ArgumentCaptor.forClass(Runnable.class);
verify(executor).execute(runCaptor.capture());
runCaptor.getValue().run();
@@ -396,7 +389,7 @@ public class ControlLoopEventManagerTest {
@Override
protected void makeLock(String targetEntity, String requestId, int holdSec, LockCallback callback) {
- LockImpl lock = new LockImpl(LockState.ACTIVE, targetEntity, requestId, holdSec, callback);
+ var lock = new LockImpl(LockState.ACTIVE, targetEntity, requestId, holdSec, callback);
locks.add(lock);
callback.lockAvailable(lock);
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java
index a2f01344f..4af45e56c 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,24 +23,23 @@ package org.onap.policy.controlloop.eventmanager;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.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.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.controlloop.actorserviceprovider.ActorService;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerImpl;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerStub;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
-public class EventManagerServicesTest {
+class EventManagerServicesTest {
private static final String FILEPFX = "eventService/";
private static final IllegalArgumentException EXPECTED_EXCEPTION =
new IllegalArgumentException("expected exception");
@@ -49,29 +49,29 @@ public class EventManagerServicesTest {
/**
* Configures HTTP clients.
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
// start with a clean slate
HttpClientFactoryInstance.getClientFactory().destroy();
SystemPersistenceConstants.getManager().setConfigurationDir("src/test/resources");
- Properties props = SystemPersistenceConstants.getManager().getProperties("eventService/event-svc-http-client");
+ var props = SystemPersistenceConstants.getManager().getProperties("eventService/event-svc-http-client");
HttpClientFactoryInstance.getClientFactory().build(props);
}
- @AfterClass
+ @AfterAll
public static void teatDownBeforeClass() {
HttpClientFactoryInstance.getClientFactory().destroy();
}
- @After
+ @AfterEach
public void tearDown() {
closeDb();
}
@Test
- public void testEventManagerServices_testGetActorService() {
+ void testEventManagerServices_testGetActorService() {
// try with guard disabled - should use DB stub
services = new EventManagerServices(FILEPFX + "event-svc-guard-disabled");
assertTrue(services.getDataManager() instanceof OperationHistoryDataManagerStub);
@@ -84,13 +84,13 @@ public class EventManagerServicesTest {
}
@Test
- public void testStartActorService() {
+ void testStartActorService() {
// config file not found
assertThatIllegalStateException().isThrownBy(() -> new EventManagerServices("missing-config-file"));
}
@Test
- public void testIsGuardEnabled() {
+ void testIsGuardEnabled() {
// cannot check guard
services = new EventManagerServices(FILEPFX + "event-svc-no-guard-actor");
assertTrue(services.getDataManager() instanceof OperationHistoryDataManagerStub);
@@ -99,7 +99,7 @@ public class EventManagerServicesTest {
services = new EventManagerServices(FILEPFX + "event-svc-with-db") {
@Override
public ActorService getActorService() {
- ActorService svc = mock(ActorService.class);
+ var svc = mock(ActorService.class);
when(svc.getActor(any())).thenThrow(EXPECTED_EXCEPTION);
return svc;
}
@@ -108,7 +108,7 @@ public class EventManagerServicesTest {
}
@Test
- public void testMakeDataManager() {
+ void testMakeDataManager() {
assertThatThrownBy(() -> new EventManagerServices(FILEPFX + "event-svc-invalid-db"))
.isInstanceOf(IllegalArgumentException.class);
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockDataTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockDataTest.java
index 7b0213107..609de5705 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockDataTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockDataTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,65 +22,56 @@
package org.onap.policy.controlloop.eventmanager;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
-import java.time.Instant;
import java.util.UUID;
-import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.drools.core.lock.Lock;
-@RunWith(MockitoJUnitRunner.class)
-public class LockDataTest {
+class LockDataTest {
private static final String ENTITY = "my-entity";
private static final UUID REQ_ID = UUID.randomUUID();
- @Mock
- private Lock lock;
- @Mock
- private Consumer<OperationOutcome> callback1;
- @Mock
- private Consumer<OperationOutcome> callback2;
- @Mock
- private Consumer<OperationOutcome> callback3;
+ private final Lock lock = mock(Lock.class);
+ private final Consumer<OperationOutcome> callback1 = mock();
+ private final Consumer<OperationOutcome> callback2 = mock();
+ private final Consumer<OperationOutcome> callback3 = mock();
private LockData data;
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() {
data = new LockData(ENTITY, REQ_ID);
}
@Test
- public void testGetFuture() {
- CompletableFuture<OperationOutcome> future = data.getFuture();
+ void testGetFuture() {
+ var future = data.getFuture();
assertNotNull(future);
assertFalse(future.isDone());
}
@Test
- public void testAddUnavailableCallback() {
+ void testAddUnavailableCallback() {
data.addUnavailableCallback(callback1);
data.addUnavailableCallback(callback2);
@@ -96,7 +88,7 @@ public class LockDataTest {
* Tests addUnavailableCallback() when the lock never becomes available.
*/
@Test
- public void testAddUnavailableCallbackNeverAvailable() {
+ void testAddUnavailableCallbackNeverAvailable() {
data.addUnavailableCallback(callback1);
data.addUnavailableCallback(callback2);
@@ -109,7 +101,7 @@ public class LockDataTest {
}
@Test
- public void testFree() {
+ void testFree() {
// no lock yet
assertThatCode(() -> data.free()).doesNotThrowAnyException();
@@ -120,27 +112,27 @@ public class LockDataTest {
}
@Test
- public void testLockAvailable() throws Exception {
+ void testLockAvailable() throws Exception {
data.addUnavailableCallback(callback1);
data.addUnavailableCallback(callback2);
- CompletableFuture<OperationOutcome> future = data.getFuture();
+ var future = data.getFuture();
data.lockAvailable(lock);
assertSame(future, data.getFuture());
assertTrue(future.isDone());
- OperationOutcome outcome = future.get();
+ var outcome = future.get();
assertEquals(ActorConstants.LOCK_ACTOR, outcome.getActor());
assertEquals(ActorConstants.LOCK_OPERATION, outcome.getOperation());
assertEquals(ENTITY, outcome.getTarget());
assertEquals(OperationResult.SUCCESS, outcome.getResult());
assertEquals(ControlLoopOperation.SUCCESS_MSG, outcome.getMessage());
- Instant start = outcome.getStart();
+ var start = outcome.getStart();
assertNotNull(start);
- Instant end = outcome.getEnd();
+ var end = outcome.getEnd();
assertNotNull(end);
assertTrue(start.compareTo(end) <= 0);
@@ -149,7 +141,7 @@ public class LockDataTest {
}
@Test
- public void testLockUnavailable() throws Exception {
+ void testLockUnavailable() throws Exception {
data.addUnavailableCallback(callback1);
data.addUnavailableCallback(callback2);
data.addUnavailableCallback(callback3);
@@ -157,17 +149,17 @@ public class LockDataTest {
// arrange for callback2 to throw an exception
doThrow(new IllegalStateException("expected exception")).when(callback2).accept(any());
- CompletableFuture<OperationOutcome> future = data.getFuture();
+ var future = data.getFuture();
assertNotNull(future);
data.lockUnavailable(lock);
- CompletableFuture<OperationOutcome> future2 = data.getFuture();
+ var future2 = data.getFuture();
assertNotNull(future2);
assertNotSame(future, future2);
assertTrue(future.isDone());
- OperationOutcome outcome = future.get();
+ var outcome = future.get();
assertTrue(future2.isDone());
assertSame(outcome, future2.get());
@@ -178,10 +170,10 @@ public class LockDataTest {
assertEquals(OperationResult.FAILURE, outcome.getResult());
assertEquals(ControlLoopOperation.FAILED_MSG, outcome.getMessage());
- Instant start = outcome.getStart();
+ var start = outcome.getStart();
assertNotNull(start);
- Instant end = outcome.getEnd();
+ var end = outcome.getEnd();
assertNotNull(end);
assertTrue(start.compareTo(end) <= 0);
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/StepTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/StepTest.java
index 8037f0037..29c92a0e9 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/StepTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/StepTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,14 +23,15 @@ package org.onap.policy.controlloop.eventmanager;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.time.Instant;
@@ -43,11 +45,8 @@ import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.controlloop.ControlLoopTargetType;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actorserviceprovider.ActorService;
@@ -61,8 +60,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.drools.domain.models.operational.OperationalTarget;
-@RunWith(MockitoJUnitRunner.class)
-public class StepTest {
+class StepTest {
private static final UUID REQ_ID = UUID.randomUUID();
private static final String POLICY_ACTOR = "my-actor";
private static final String POLICY_OPERATION = "my-operation";
@@ -72,14 +70,10 @@ public class StepTest {
private static final long REMAINING_MS = 5000;
private static final String EXPECTED_EXCEPTION = "expected exception";
- @Mock
- private Operator policyOperator;
- @Mock
- private Operation policyOperation;
- @Mock
- private Actor policyActor;
- @Mock
- private ActorService actors;
+ private final Operator policyOperator = mock(Operator.class);
+ private final Operation policyOperation = mock(Operation.class);
+ private final Actor policyActor = mock(Actor.class);
+ private final ActorService actors = mock(ActorService.class);
private CompletableFuture<OperationOutcome> future;
private OperationalTarget target;
@@ -95,7 +89,7 @@ public class StepTest {
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() {
future = new CompletableFuture<>();
@@ -133,7 +127,7 @@ public class StepTest {
}
@Test
- public void testConstructor() {
+ void testConstructor() {
assertTrue(step.isPolicyStep());
assertSame(params, step.getParams());
assertNull(step.getParentStep());
@@ -150,12 +144,12 @@ public class StepTest {
}
@Test
- public void testConstructorWithOtherStep_testInitStartTime_testGetStartTimeRef() {
- Step step2 = new Step(step, "actorB", "operB");
+ void testConstructorWithOtherStep_testInitStartTime_testGetStartTimeRef() {
+ var step2 = new Step(step, "actorB", "operB");
assertFalse(step2.isPolicyStep());
assertSame(step, step2.getParentStep());
- ControlLoopOperationParams params2 = step2.getParams();
+ var params2 = step2.getParams();
assertEquals("actorB", params2.getActor());
assertEquals("operB", params2.getOperation());
assertNull(params2.getRetry());
@@ -173,7 +167,7 @@ public class StepTest {
step2.init();
step2.start(REMAINING_MS);
- Instant instant = startTime.get();
+ var instant = startTime.get();
assertNotNull(instant);
assertSame(instant, step2.getStartTime());
@@ -187,13 +181,13 @@ public class StepTest {
}
@Test
- public void testGetActorName_testGetOperationName() {
+ void testGetActorName_testGetOperationName() {
assertEquals(POLICY_ACTOR, step.getActorName());
assertEquals(POLICY_OPERATION, step.getOperationName());
}
@Test
- public void testIsInitialized_testInit_testGetOperation() {
+ void testIsInitialized_testInit_testGetOperation() {
assertFalse(step.isInitialized());
// verify it's unchanged
@@ -217,7 +211,7 @@ public class StepTest {
}
@Test
- public void testStart() {
+ void testStart() {
assertThatIllegalStateException().isThrownBy(() -> step.start(REMAINING_MS))
.withMessage("step has not been initialized");
@@ -236,14 +230,14 @@ public class StepTest {
* Tests start() when the operation.start() throws an exception.
*/
@Test
- public void testStartException() {
+ void testStartException() {
when(policyOperation.start()).thenThrow(new RuntimeException());
step.init();
assertTrue(step.start(REMAINING_MS));
// exception should be immediate
- OperationOutcome outcome = completions.poll();
+ var outcome = completions.poll();
assertNotNull(outcome);
assertNotEquals(OperationResult.SUCCESS, outcome.getResult());
@@ -255,14 +249,14 @@ public class StepTest {
* Tests start() when the operation throws an asynchronous exception.
*/
@Test
- public void testStartAsyncException() {
+ void testStartAsyncException() {
step.init();
step.start(REMAINING_MS);
future.completeExceptionally(new RuntimeException(EXPECTED_EXCEPTION));
// exception should be immediate
- OperationOutcome outcome = completions.poll();
+ var outcome = completions.poll();
assertNotNull(outcome);
assertNotEquals(OperationResult.SUCCESS, outcome.getResult());
@@ -274,7 +268,7 @@ public class StepTest {
* Tests handleException() when the exception is a CancellationException.
*/
@Test
- public void testHandleExceptionCancellationException() {
+ void testHandleExceptionCancellationException() {
step.init();
step.start(REMAINING_MS);
@@ -285,7 +279,7 @@ public class StepTest {
}
@Test
- public void testHandleExceptionCauseCancellationException() {
+ void testHandleExceptionCauseCancellationException() {
step.init();
step.start(REMAINING_MS);
@@ -296,7 +290,7 @@ public class StepTest {
}
@Test
- public void testHandleException() {
+ void testHandleException() {
when(policyOperation.start()).thenThrow(new RuntimeException());
step.init();
@@ -304,7 +298,7 @@ public class StepTest {
assertTrue(step.start(REMAINING_MS));
// exception should be immediate
- OperationOutcome outcome = completions.poll();
+ var outcome = completions.poll();
assertNotNull(outcome);
assertNotEquals(OperationResult.SUCCESS, outcome.getResult());
@@ -317,7 +311,7 @@ public class StepTest {
}
@Test
- public void testHandleTimeout() throws InterruptedException {
+ void testHandleTimeout() throws InterruptedException {
step.init();
long tstart = System.currentTimeMillis();
@@ -325,7 +319,7 @@ public class StepTest {
// give it a short timeout
step.start(100);
- OperationOutcome outcome = completions.poll(5, TimeUnit.SECONDS);
+ var outcome = completions.poll(5, TimeUnit.SECONDS);
assertNotNull(outcome);
// should not have timed out before 100ms
@@ -347,7 +341,7 @@ public class StepTest {
}
@Test
- public void testCancel() {
+ void testCancel() {
// should have no effect
step.cancel();
@@ -360,18 +354,18 @@ public class StepTest {
}
@Test
- public void testBuildOperation() {
+ void testBuildOperation() {
assertSame(policyOperation, step.buildOperation());
}
@Test
- public void testMakeOutcome() {
+ void testMakeOutcome() {
step.init();
assertEquals(MY_TARGET, step.makeOutcome().getTarget());
}
@Test
- public void testToString() {
+ void testToString() {
assertNotNull(step.toString());
}
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java
index a88014e27..22cfa643d 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerImplTest.java
@@ -23,8 +23,8 @@ package org.onap.policy.controlloop.ophistory;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.awaitility.Awaitility.await;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -32,6 +32,7 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import jakarta.persistence.EntityManagerFactory;
import java.time.Instant;
import java.util.Properties;
import java.util.UUID;
@@ -39,21 +40,16 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
-import javax.persistence.EntityManagerFactory;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerParams.OperationHistoryDataManagerParamsBuilder;
-@RunWith(MockitoJUnitRunner.class)
-public class OperationHistoryDataManagerImplTest {
+class OperationHistoryDataManagerImplTest {
private static final IllegalStateException EXPECTED_EXCEPTION = new IllegalStateException("expected exception");
private static final String MY_LOOP_NAME = "my-loop-name";
@@ -67,8 +63,7 @@ public class OperationHistoryDataManagerImplTest {
private static EntityManagerFactory emf;
- @Mock
- private Thread thread;
+ private Thread thread = mock(Thread.class);
private OperationHistoryDataManagerParams params;
private Consumer<EntityManagerFactory> threadFunction;
@@ -85,9 +80,9 @@ public class OperationHistoryDataManagerImplTest {
/**
* Sets up for all tests.
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() {
- OperationHistoryDataManagerParams params = makeBuilder().build();
+ var params = makeBuilder().build();
// capture the entity manager factory for re-use
new OperationHistoryDataManagerImpl(params) {
@@ -102,7 +97,7 @@ public class OperationHistoryDataManagerImplTest {
/**
* Restores the environment after all tests.
*/
- @AfterClass
+ @AfterAll
public static void tearDownAfterClass() {
emf.close();
}
@@ -110,7 +105,7 @@ public class OperationHistoryDataManagerImplTest {
/**
* Sets up for an individual test.
*/
- @Before
+ @BeforeEach
public void setUp() {
event = new VirtualControlLoopEvent();
event.setClosedLoopControlName(MY_LOOP_NAME);
@@ -135,13 +130,13 @@ public class OperationHistoryDataManagerImplTest {
mgr.start();
}
- @After
+ @AfterEach
public void tearDown() {
mgr.stop();
}
@Test
- public void testConstructor() {
+ void testConstructor() {
// use a thread and manager that haven't been started yet
thread = mock(Thread.class);
mgr = new PseudoThread();
@@ -161,7 +156,7 @@ public class OperationHistoryDataManagerImplTest {
}
@Test
- public void testStart() {
+ void testStart() {
// this should have no effect
mgr.start();
@@ -172,7 +167,7 @@ public class OperationHistoryDataManagerImplTest {
}
@Test
- public void testStore_testStop() throws InterruptedException {
+ void testStore_testStop() throws InterruptedException {
// store
mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation);
@@ -185,7 +180,7 @@ public class OperationHistoryDataManagerImplTest {
* Tests stop() when the manager isn't running.
*/
@Test
- public void testStopNotRunning() {
+ void testStopNotRunning() {
// use a manager that hasn't been started yet
mgr = new PseudoThread();
mgr.stop();
@@ -197,7 +192,7 @@ public class OperationHistoryDataManagerImplTest {
* Tests store() when it is already stopped.
*/
@Test
- public void testStoreAlreadyStopped() throws InterruptedException {
+ void testStoreAlreadyStopped() throws InterruptedException {
mgr.stop();
// store
@@ -210,7 +205,7 @@ public class OperationHistoryDataManagerImplTest {
* Tests store() when when the queue is full.
*/
@Test
- public void testStoreTooManyItems() throws InterruptedException {
+ void testStoreTooManyItems() throws InterruptedException {
final int nextra = 5;
for (int nitems = 0; nitems < MAX_QUEUE_LENGTH + nextra; ++nitems) {
mgr.store(REQ_ID, event.getClosedLoopControlName(), event, MY_ENTITY, operation);
@@ -222,7 +217,7 @@ public class OperationHistoryDataManagerImplTest {
}
@Test
- public void testRun() throws InterruptedException {
+ void testRun() throws InterruptedException {
// trigger thread shutdown when it completes this batch
when(emfSpy.createEntityManager()).thenAnswer(ans -> {
@@ -253,8 +248,8 @@ public class OperationHistoryDataManagerImplTest {
* Tests run() when the entity manager throws an exception.
*/
@Test
- public void testRunException() throws InterruptedException {
- AtomicInteger count = new AtomicInteger(0);
+ void testRunException() throws InterruptedException {
+ var count = new AtomicInteger(0);
when(emfSpy.createEntityManager()).thenAnswer(ans -> {
if (count.incrementAndGet() == 2) {
@@ -283,7 +278,7 @@ public class OperationHistoryDataManagerImplTest {
* Tests storeRemainingRecords() when the entity manager throws an exception.
*/
@Test
- public void testStoreRemainingRecordsException() throws InterruptedException {
+ void testStoreRemainingRecordsException() throws InterruptedException {
// arrange to throw an exception
when(emfSpy.createEntityManager()).thenThrow(EXPECTED_EXCEPTION);
@@ -293,7 +288,7 @@ public class OperationHistoryDataManagerImplTest {
}
@Test
- public void testStoreRecord() throws InterruptedException {
+ void testStoreRecord() throws InterruptedException {
/*
* Note: we change sub-request ID each time to guarantee that the records are
* unique.
@@ -334,7 +329,7 @@ public class OperationHistoryDataManagerImplTest {
* Tests storeRecord() when records are updated.
*/
@Test
- public void testStoreRecordUpdate() throws InterruptedException {
+ void testStoreRecordUpdate() throws InterruptedException {
/*
* Note: we do NOT change sub-request ID, so that records all refer to the same DB
* record.
@@ -376,7 +371,7 @@ public class OperationHistoryDataManagerImplTest {
return;
}
- Thread thread2 = new Thread(() -> {
+ var thread2 = new Thread(() -> {
threadFunction.accept(emfSpy);
finished.countDown();
});
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParamsTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParamsTest.java
index 97f306528..f0159aaff 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParamsTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerParamsTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,17 +22,16 @@
package org.onap.policy.controlloop.ophistory;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.function.Consumer;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.policy.common.parameters.ValidationResult;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerParams.OperationHistoryDataManagerParamsBuilder;
-public class OperationHistoryDataManagerParamsTest {
+class OperationHistoryDataManagerParamsTest {
private static final String CONTAINER = "my-container";
private static final int BATCH_SIZE = 10;
private static final int MAX_QUEUE_LENGTH = 20;
@@ -44,13 +44,13 @@ public class OperationHistoryDataManagerParamsTest {
private OperationHistoryDataManagerParams params;
- @Before
+ @BeforeEach
public void setUp() {
params = makeBuilder().build();
}
@Test
- public void test() {
+ void test() {
assertEquals(BATCH_SIZE, params.getBatchSize());
assertEquals(MAX_QUEUE_LENGTH, params.getMaxQueueLength());
assertEquals(MY_PASS, params.getPassword());
@@ -71,7 +71,7 @@ public class OperationHistoryDataManagerParamsTest {
}
@Test
- public void testValidate() {
+ void testValidate() {
assertTrue(params.validate(CONTAINER).isValid());
testValidateField("url", "null", params2 -> params2.setUrl(null));
@@ -103,14 +103,14 @@ public class OperationHistoryDataManagerParamsTest {
Consumer<OperationHistoryDataManagerParams> makeInvalid) {
// original params should be valid
- ValidationResult result = params.validate(CONTAINER);
- assertTrue(fieldName, result.isValid());
+ var result = params.validate(CONTAINER);
+ assertTrue(result.isValid());
// make invalid params
- OperationHistoryDataManagerParams params2 = makeBuilder().build();
+ var params2 = makeBuilder().build();
makeInvalid.accept(params2);
result = params2.validate(CONTAINER);
- assertFalse(fieldName, result.isValid());
+ assertFalse(result.isValid());
assertThat(result.getResult()).contains(CONTAINER).contains(fieldName).contains(expected);
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStubTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStubTest.java
index 4774af427..d4a5cfdd1 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStubTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/ophistory/OperationHistoryDataManagerStubTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,13 +23,13 @@ package org.onap.policy.controlloop.ophistory;
import static org.assertj.core.api.Assertions.assertThatCode;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class OperationHistoryDataManagerStubTest {
+class OperationHistoryDataManagerStubTest {
@Test
- public void test() {
- OperationHistoryDataManagerStub mgr = new OperationHistoryDataManagerStub();
+ void test() {
+ var mgr = new OperationHistoryDataManagerStub();
assertThatCode(() -> mgr.store(null, null, null, null, null)).doesNotThrowAnyException();
assertThatCode(() -> mgr.stop()).doesNotThrowAnyException();
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
index 0ca98720c..0ccaf105e 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,45 +22,42 @@
package org.onap.policy.controlloop.processor;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
-import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.controlloop.ControlLoopException;
-import org.onap.policy.controlloop.actorserviceprovider.OperationFinalResult;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
-import org.onap.policy.drools.domain.models.operational.Operation;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ControlLoopProcessorTest {
+class ControlLoopProcessorTest {
private static final Logger logger = LoggerFactory.getLogger(ControlLoopProcessorTest.class);
private static final StandardCoder coder = new StandardCoder();
@Test
- public void testControlLoopProcessor() throws IOException, ControlLoopException {
- String yamlString = Files.readString(new File("src/test/resources/test.yaml").toPath(), StandardCharsets.UTF_8);
+ void testControlLoopProcessor() throws IOException, ControlLoopException {
+ var yamlString = Files.readString(new File("src/test/resources/test.yaml").toPath(), StandardCharsets.UTF_8);
this.testSuccess(yamlString);
this.testFailure(yamlString);
}
private ToscaPolicy getPolicyFromResource(String resourcePath, String policyName) throws CoderException {
- String policyJson = ResourceUtils.getResourceAsString(resourcePath);
- ToscaServiceTemplate serviceTemplate = coder.decode(policyJson, ToscaServiceTemplate.class);
- ToscaPolicy policy = serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyName);
+ var policyJson = ResourceUtils.getResourceAsString(resourcePath);
+ var serviceTemplate = coder.decode(policyJson, ToscaServiceTemplate.class);
+ var policy = serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyName);
assertNotNull(policy);
/*
@@ -78,7 +76,7 @@ public class ControlLoopProcessorTest {
}
@Test
- public void testControlLoopFromToscaCompliant()
+ void testControlLoopFromToscaCompliant()
throws CoderException, ControlLoopException {
assertNotNull(
new ControlLoopProcessor(
@@ -101,28 +99,28 @@ public class ControlLoopProcessorTest {
}
@Test
- public void testControlLoopFromToscaCompliantBad() throws CoderException {
- ToscaPolicy toscaPolicy = getPolicyFromResource(
+ void testControlLoopFromToscaCompliantBad() throws CoderException {
+ var toscaPolicy = getPolicyFromResource(
"policies/vCPE.policy.operational.input.tosca.json", "operational.restart");
toscaPolicy.setVersion(null);
assertThatThrownBy(() -> new ControlLoopProcessor(toscaPolicy)).hasCauseInstanceOf(CoderException.class);
}
@Test
- public void testControlLoopProcessorBadYaml() throws IOException {
- InputStream is = new FileInputStream(new File("src/test/resources/string.yaml"));
- String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
+ void testControlLoopProcessorBadYaml() throws IOException {
+ var is = new FileInputStream(new File("src/test/resources/string.yaml"));
+ var yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
assertThatThrownBy(() -> new ControlLoopProcessor(yamlString))
.hasMessageEndingWith("Cannot decode yaml into ToscaServiceTemplate");
}
@Test
- public void testControlLoopProcessorBadTriggerYaml() throws IOException, ControlLoopException {
- String yamlString = Files.readString(new File("src/test/resources/badtriggerpolicy.yaml").toPath(),
+ void testControlLoopProcessorBadTriggerYaml() throws IOException, ControlLoopException {
+ var yamlString = Files.readString(new File("src/test/resources/badtriggerpolicy.yaml").toPath(),
StandardCharsets.UTF_8);
- ControlLoopProcessor clProcessor = new ControlLoopProcessor(yamlString);
+ var clProcessor = new ControlLoopProcessor(yamlString);
assertNull(clProcessor.getCurrentPolicy());
assertThatThrownBy(() -> clProcessor.nextPolicyForResult(OperationResult.SUCCESS))
@@ -130,27 +128,27 @@ public class ControlLoopProcessorTest {
}
@Test
- public void testControlLoopProcessorNoPolicyYaml() throws IOException, ControlLoopException {
- InputStream is = new FileInputStream(new File("src/test/resources/nopolicy.yaml"));
- String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
+ void testControlLoopProcessorNoPolicyYaml() throws IOException, ControlLoopException {
+ var is = new FileInputStream(new File("src/test/resources/nopolicy.yaml"));
+ var yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
- ControlLoopProcessor clProcessor = new ControlLoopProcessor(yamlString);
+ var clProcessor = new ControlLoopProcessor(yamlString);
assertThatThrownBy(clProcessor::getCurrentPolicy)
.hasMessage("There are no policies defined.");
}
@Test
- public void testControlLoopProcessorNextPolicyForResult() throws IOException, ControlLoopException {
- InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
- String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
+ void testControlLoopProcessorNextPolicyForResult() throws IOException, ControlLoopException {
+ var is = new FileInputStream(new File("src/test/resources/test.yaml"));
+ var yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
- for (OperationResult result : OperationResult.values()) {
+ for (var result : OperationResult.values()) {
checkResult(yamlString, result);
}
}
private void checkResult(String yamlString, OperationResult result) throws ControlLoopException {
- ControlLoopProcessor clProcessor = new ControlLoopProcessor(yamlString);
+ var clProcessor = new ControlLoopProcessor(yamlString);
clProcessor.getCurrentPolicy();
clProcessor.nextPolicyForResult(result);
}
@@ -162,15 +160,15 @@ public class ControlLoopProcessorTest {
* @throws ControlLoopException if an error occurs
*/
public void testSuccess(String yaml) throws ControlLoopException {
- ControlLoopProcessor processor = new ControlLoopProcessor(yaml);
+ var processor = new ControlLoopProcessor(yaml);
logger.debug("testSuccess: {}", processor.getCurrentPolicy());
while (true) {
- OperationFinalResult result = processor.checkIsCurrentPolicyFinal();
+ var result = processor.checkIsCurrentPolicyFinal();
if (result != null) {
logger.debug("{}", result);
break;
}
- Operation policy = processor.getCurrentPolicy();
+ var policy = processor.getCurrentPolicy();
assertNotNull(policy);
logger.debug("current policy is: {}", policy.getId());
processor.nextPolicyForResult(OperationResult.SUCCESS);
@@ -184,15 +182,15 @@ public class ControlLoopProcessorTest {
* @throws ControlLoopException if an error occurs
*/
public void testFailure(String yaml) throws ControlLoopException {
- ControlLoopProcessor processor = new ControlLoopProcessor(yaml);
+ var processor = new ControlLoopProcessor(yaml);
logger.debug("testFailure: {}", processor.getCurrentPolicy());
while (true) {
- OperationFinalResult result = processor.checkIsCurrentPolicyFinal();
+ var result = processor.checkIsCurrentPolicyFinal();
if (result != null) {
logger.debug("{}", result);
break;
}
- Operation policy = processor.getCurrentPolicy();
+ var policy = processor.getCurrentPolicy();
assertNotNull(policy);
logger.debug("current policy is: {}", policy.getId());
processor.nextPolicyForResult(OperationResult.FAILURE);
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java
index 9e29af511..55e980337 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,28 +21,28 @@
package org.onap.policy.controlloop.utils;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-public class ControlLoopUtilsTest {
+class ControlLoopUtilsTest {
@Test
- public void testToControlLoopParams() throws Exception {
- String policyJson =
+ void testToControlLoopParams() throws Exception {
+ var policyJson =
ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.tosca.json");
- ToscaServiceTemplate serviceTemplate = new StandardCoder().decode(policyJson, ToscaServiceTemplate.class);
- ToscaPolicy toscaPolicy =
+ var serviceTemplate = new StandardCoder().decode(policyJson, ToscaServiceTemplate.class);
+ var toscaPolicy =
serviceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get("operational.restart");
- ControlLoopParams params = ControlLoopUtils.toControlLoopParams(toscaPolicy);
+ var params = ControlLoopUtils.toControlLoopParams(toscaPolicy);
assertEquals("ControlLoop-vCPE-48f0c2c3-a172-4192-9ae3-052274181b6e", params.getClosedLoopControlName());
assertEquals(toscaPolicy.getName(), params.getPolicyName());
assertEquals(toscaPolicy.getVersion(), params.getPolicyVersion());