summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.xacml/src
diff options
context:
space:
mode:
authorwaynedunican <wayne.dunican@est.tech>2024-06-13 09:19:14 +0100
committerwaynedunican <wayne.dunican@est.tech>2024-06-20 12:24:23 +0100
commit9e8684c88435734cb2e142208436cec647cde887 (patch)
treeb06334cdf8309d36ceba948797ff071d14a2e82d /models-interactions/model-actors/actor.xacml/src
parent8236c8bab1a27bd721586550f8ba879abcba3239 (diff)
Convert models to JUnit 5
Review for models-actors Issue-ID: POLICY-5042 Change-Id: Ica07b9fbda1eca24a8a432d57a2d9af52c84625d Signed-off-by: waynedunican <wayne.dunican@est.tech>
Diffstat (limited to 'models-interactions/model-actors/actor.xacml/src')
-rw-r--r--models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/ConfigureOperationTest.java46
-rw-r--r--models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionConfigTest.java27
-rw-r--r--models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionOperationTest.java58
-rw-r--r--models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionOperatorTest.java34
-rw-r--r--models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionParamsTest.java27
-rw-r--r--models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/GuardOperationTest.java57
-rw-r--r--models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/XacmlActorParamsTest.java25
-rw-r--r--models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/XacmlActorTest.java16
8 files changed, 150 insertions, 140 deletions
diff --git a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/ConfigureOperationTest.java b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/ConfigureOperationTest.java
index 9559a1d47..3dba20162 100644
--- a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/ConfigureOperationTest.java
+++ b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/ConfigureOperationTest.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023, 2024 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,21 +22,21 @@
package org.onap.policy.controlloop.actor.xacml;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import java.util.Map;
import java.util.function.Consumer;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
@@ -46,8 +46,8 @@ import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.models.decisions.concepts.DecisionRequest;
import org.onap.policy.models.decisions.concepts.DecisionResponse;
-@RunWith(MockitoJUnitRunner.class)
-public class ConfigureOperationTest extends BasicHttpOperation {
+@ExtendWith(MockitoExtension.class)
+ class ConfigureOperationTest extends BasicHttpOperation {
@Mock
private Consumer<OperationOutcome> started;
@@ -60,8 +60,8 @@ public class ConfigureOperationTest extends BasicHttpOperation {
/**
* Starts the simulator.
*/
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
+ @BeforeAll
+ static void setUpBeforeClass() throws Exception {
org.onap.policy.simulators.Util.buildXacmlSim();
BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("policy/pdpx/v1/")
@@ -70,8 +70,8 @@ public class ConfigureOperationTest extends BasicHttpOperation {
HttpClientFactoryInstance.getClientFactory().build(clientParams);
}
- @AfterClass
- public static void tearDownAfterClass() {
+ @AfterAll
+ static void tearDownAfterClass() {
HttpClientFactoryInstance.getClientFactory().destroy();
HttpServletServerFactoryInstance.getServerFactory().destroy();
}
@@ -79,8 +79,8 @@ public class ConfigureOperationTest extends BasicHttpOperation {
/**
* Sets up.
*/
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
super.setUpBasic();
operConfig = mock(DecisionConfig.class);
@@ -102,7 +102,7 @@ public class ConfigureOperationTest extends BasicHttpOperation {
}
@Test
- public void testConstructor() {
+ void testConstructor() {
assertEquals(DEFAULT_ACTOR, oper.getActorName());
assertEquals(DEFAULT_OPERATION, oper.getName());
}
@@ -111,7 +111,7 @@ public class ConfigureOperationTest extends BasicHttpOperation {
* Tests "success" case with simulator.
*/
@Test
- public void testSuccess() throws Exception {
+ void testSuccess() throws Exception {
DecisionParams opParams =
DecisionParams.builder().clientName(MY_CLIENT).path("decision").action("configure").build();
config = new DecisionConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
@@ -124,7 +124,7 @@ public class ConfigureOperationTest extends BasicHttpOperation {
assertEquals(OperationResult.SUCCESS, outcome.getResult());
DecisionResponse response = outcome.getResponse();
- assertTrue(response instanceof DecisionResponse);
+ assertInstanceOf(DecisionResponse.class, response);
assertNotNull(response.getPolicies());
assertThat(response.getPolicies()).containsKey("test-policy");
}
@@ -133,7 +133,7 @@ public class ConfigureOperationTest extends BasicHttpOperation {
* Tests "failure" case with simulator.
*/
@Test
- public void testFailure() throws Exception {
+ void testFailure() throws Exception {
DecisionParams opParams =
DecisionParams.builder().clientName(MY_CLIENT).path("decision").action("configure").build();
config = new DecisionConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
@@ -146,7 +146,7 @@ public class ConfigureOperationTest extends BasicHttpOperation {
assertEquals(OperationResult.FAILURE, outcome.getResult());
DecisionResponse response = outcome.getResponse();
- assertTrue(response instanceof DecisionResponse);
+ assertInstanceOf(DecisionResponse.class, response);
assertNotNull(response.getPolicies());
assertThat(response.getPolicies()).isEmpty();
}
diff --git a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionConfigTest.java b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionConfigTest.java
index dbb4f6857..526840d46 100644
--- a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionConfigTest.java
+++ b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionConfigTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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,24 +21,24 @@
package org.onap.policy.controlloop.actor.xacml;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;
import java.util.concurrent.Executor;
-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.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.policy.common.endpoints.http.client.HttpClient;
import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
import org.onap.policy.models.decisions.concepts.DecisionRequest;
-@RunWith(MockitoJUnitRunner.class)
-public class DecisionConfigTest {
+@ExtendWith(MockitoExtension.class)
+ class DecisionConfigTest {
private static final String MY_CLIENT = "my-client";
private static final String PATH = "my-path";
private static final int TIMEOUT = 10;
@@ -59,8 +60,8 @@ public class DecisionConfigTest {
/**
* Sets up.
*/
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
when(factory.get(MY_CLIENT)).thenReturn(client);
params = DecisionParams.builder().onapName(ONAP_NAME).onapComponent(ONAP_COMP).onapInstance(ONAP_INST)
@@ -69,7 +70,7 @@ public class DecisionConfigTest {
}
@Test
- public void test() {
+ void test() {
DecisionRequest expected = new DecisionRequest();
expected.setOnapComponent(ONAP_COMP);
expected.setOnapInstance(ONAP_INST);
diff --git a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionOperationTest.java b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionOperationTest.java
index 49dbd166f..ee9d28c57 100644
--- a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionOperationTest.java
+++ b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionOperationTest.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023, 2024 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 +22,12 @@
package org.onap.policy.controlloop.actor.xacml;
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.assertNotNull;
-import static org.junit.Assert.assertNull;
-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.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+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.never;
@@ -37,13 +38,14 @@ import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
@@ -57,8 +59,8 @@ import org.onap.policy.models.decisions.concepts.DecisionRequest;
import org.onap.policy.models.decisions.concepts.DecisionResponse;
import org.onap.policy.simulators.XacmlSimulatorJaxRs;
-@RunWith(MockitoJUnitRunner.class)
-public class DecisionOperationTest extends BasicHttpOperation {
+@ExtendWith(MockitoExtension.class)
+ class DecisionOperationTest extends BasicHttpOperation {
private static final List<String> PROPERTY_NAMES = List.of("prop-A", "prop-B");
@Mock
@@ -72,8 +74,8 @@ public class DecisionOperationTest extends BasicHttpOperation {
/**
* Starts the simulator.
*/
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
+ @BeforeAll
+ static void setUpBeforeClass() throws Exception {
org.onap.policy.simulators.Util.buildXacmlSim();
BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("policy/pdpx/v1/")
@@ -82,8 +84,8 @@ public class DecisionOperationTest extends BasicHttpOperation {
HttpClientFactoryInstance.getClientFactory().build(clientParams);
}
- @AfterClass
- public static void tearDownAfterClass() {
+ @AfterAll
+ static void tearDownAfterClass() {
HttpClientFactoryInstance.getClientFactory().destroy();
HttpServletServerFactoryInstance.getServerFactory().destroy();
}
@@ -91,12 +93,12 @@ public class DecisionOperationTest extends BasicHttpOperation {
/**
* Sets up.
*/
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
super.setUpBasic();
guardConfig = mock(DecisionConfig.class);
- when(guardConfig.makeRequest()).thenAnswer(args -> {
+ Mockito.lenient().when(guardConfig.makeRequest()).thenAnswer(args -> {
DecisionRequest req = new DecisionRequest();
req.setAction("guard");
req.setOnapComponent("my-onap-component");
@@ -117,7 +119,7 @@ public class DecisionOperationTest extends BasicHttpOperation {
* Tests with simulator.
*/
@Test
- public void testSimulator() throws Exception {
+ void testSimulator() throws Exception {
DecisionParams opParams = DecisionParams.builder().clientName(MY_CLIENT).path("decision").build();
config = new DecisionConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
@@ -127,22 +129,22 @@ public class DecisionOperationTest extends BasicHttpOperation {
outcome = oper.start().get();
assertEquals(OperationResult.FAILURE, outcome.getResult());
- assertTrue(outcome.getResponse() instanceof DecisionResponse);
+ assertInstanceOf(DecisionResponse.class, outcome.getResponse());
}
@Test
- public void testConstructor() {
+ void testConstructor() {
assertEquals(DEFAULT_ACTOR, oper.getActorName());
assertEquals(DEFAULT_OPERATION, oper.getName());
}
@Test
- public void testGetPropertyNames() {
+ void testGetPropertyNames() {
assertThat(oper.getPropertyNames()).isEqualTo(PROPERTY_NAMES);
}
@Test
- public void testStartOperationAsync() throws Exception {
+ void testStartOperationAsync() throws Exception {
CompletableFuture<OperationOutcome> future2 = oper.start();
executor.runAll(100);
assertFalse(future2.isDone());
@@ -169,7 +171,7 @@ public class DecisionOperationTest extends BasicHttpOperation {
* Tests startOperationAsync() when the guard is disabled.
*/
@Test
- public void testStartOperationAsyncDisabled() throws Exception {
+ void testStartOperationAsyncDisabled() throws Exception {
// indicate that it's disabled
when(guardConfig.isDisabled()).thenReturn(true);
@@ -192,7 +194,7 @@ public class DecisionOperationTest extends BasicHttpOperation {
private class MyOper extends DecisionOperation {
- public MyOper(ControlLoopOperationParams params, HttpConfig config) {
+ MyOper(ControlLoopOperationParams params, HttpConfig config) {
super(params, config, PROPERTY_NAMES);
}
diff --git a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionOperatorTest.java b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionOperatorTest.java
index ab8535ae4..31308f7f9 100644
--- a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionOperatorTest.java
+++ b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionOperatorTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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,23 +22,24 @@
package org.onap.policy.controlloop.actor.xacml;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-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.assertInstanceOf;
import static org.mockito.Mockito.when;
import java.util.Map;
-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.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.policy.common.endpoints.http.client.HttpClient;
import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
import org.onap.policy.controlloop.actorserviceprovider.Util;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
-@RunWith(MockitoJUnitRunner.class)
-public class DecisionOperatorTest {
+@ExtendWith(MockitoExtension.class)
+ class DecisionOperatorTest {
private static final String ACTOR = "my-actor";
private static final String OPERATION = "my-name";
private static final String CLIENT = "my-client";
@@ -54,15 +56,15 @@ public class DecisionOperatorTest {
@Mock
private HttpClientFactory factory;
-
+ @InjectMocks
private DecisionOperator oper;
/**
* Initializes fields, including {@link #oper}, and resets the static fields used by
* the REST server.
*/
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
when(factory.get(CLIENT)).thenReturn(client);
oper = new MyOperator();
@@ -73,19 +75,19 @@ public class DecisionOperatorTest {
Map<String, Object> paramMap = Util.translateToMap(OPERATION, params);
oper.configure(paramMap);
- assertTrue(oper.makeConfiguration(paramMap) instanceof DecisionConfig);
+ assertInstanceOf(DecisionConfig.class, oper.makeConfiguration(paramMap));
}
@Test
- public void testConstructor() {
+ void testConstructor() {
assertEquals(ACTOR, oper.getActorName());
assertEquals(OPERATION, oper.getName());
assertEquals(ACTOR + "." + OPERATION, oper.getFullName());
}
@Test
- public void testDoConfigure_testGetters() {
- assertTrue(oper.getCurrentConfig() instanceof DecisionConfig);
+ void testDoConfigure_testGetters() {
+ assertInstanceOf(DecisionConfig.class, oper.getCurrentConfig());
// test invalid parameters
Map<String, Object> paramMap2 = Util.translateToMap(OPERATION, DecisionParams.builder().build());
@@ -94,7 +96,7 @@ public class DecisionOperatorTest {
private class MyOperator extends DecisionOperator {
- public MyOperator() {
+ MyOperator() {
super(ACTOR, OPERATION, null);
}
diff --git a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionParamsTest.java b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionParamsTest.java
index 658ae4f2e..141e86f08 100644
--- a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionParamsTest.java
+++ b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/DecisionParamsTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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,18 +22,18 @@
package org.onap.policy.controlloop.actor.xacml;
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.Function;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.controlloop.actor.xacml.DecisionParams.DecisionParamsBuilder;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams.HttpParamsBuilder;
-public class DecisionParamsTest {
+class DecisionParamsTest {
private static final String CONTAINER = "my-container";
private static final String CLIENT = "my-client";
private static final String PATH = "my-path";
@@ -44,20 +45,20 @@ public class DecisionParamsTest {
private DecisionParams params;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
params = DecisionParams.builder().onapName(ONAP_NAME).onapComponent(ONAP_COMP).onapInstance(ONAP_INST)
.action(MY_ACTION).clientName(CLIENT).path(PATH).timeoutSec(TIMEOUT).build();
}
@Test
- public void testIsDisabled() {
+ void testIsDisabled() {
// disabled by default
assertFalse(params.isDisabled());
}
@Test
- public void testValidate() {
+ void testValidate() {
assertTrue(params.validate(CONTAINER).isValid());
testValidateField("onapName", "null", bldr -> bldr.onapName(null));
@@ -70,7 +71,7 @@ public class DecisionParamsTest {
}
@Test
- public void testBuilder_testToBuilder() {
+ void testBuilder_testToBuilder() {
assertEquals(CLIENT, params.getClientName());
assertEquals(ONAP_NAME, params.getOnapName());
@@ -86,11 +87,11 @@ public class DecisionParamsTest {
// original params should be valid
ValidationResult result = params.validate(CONTAINER);
- assertTrue(fieldName, result.isValid());
+ assertTrue(result.isValid(), fieldName);
// make invalid params
result = makeInvalid.apply(params.toBuilder()).build().validate(CONTAINER);
- assertFalse(fieldName, result.isValid());
+ assertFalse(result.isValid(), fieldName);
assertThat(result.getResult()).contains(fieldName).contains(expected);
}
}
diff --git a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/GuardOperationTest.java b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/GuardOperationTest.java
index 05f64baa7..a4187b523 100644
--- a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/GuardOperationTest.java
+++ b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/GuardOperationTest.java
@@ -3,7 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023, 2024 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,23 +23,24 @@ package org.onap.policy.controlloop.actor.xacml;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
-import static org.junit.Assert.assertEquals;
-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.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Map;
import java.util.TreeMap;
import java.util.function.Consumer;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
@@ -51,8 +52,8 @@ import org.onap.policy.models.decisions.concepts.DecisionRequest;
import org.onap.policy.models.decisions.concepts.DecisionResponse;
import org.onap.policy.simulators.XacmlSimulatorJaxRs;
-@RunWith(MockitoJUnitRunner.class)
-public class GuardOperationTest extends BasicHttpOperation {
+@ExtendWith(MockitoExtension.class)
+ class GuardOperationTest extends BasicHttpOperation {
@Mock
private Consumer<OperationOutcome> started;
@@ -65,8 +66,8 @@ public class GuardOperationTest extends BasicHttpOperation {
/**
* Starts the simulator.
*/
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
+ @BeforeAll
+ static void setUpBeforeClass() throws Exception {
org.onap.policy.simulators.Util.buildXacmlSim();
BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("policy/pdpx/v1/")
@@ -75,8 +76,8 @@ public class GuardOperationTest extends BasicHttpOperation {
HttpClientFactoryInstance.getClientFactory().build(clientParams);
}
- @AfterClass
- public static void tearDownAfterClass() {
+ @AfterAll
+ static void tearDownAfterClass() {
HttpClientFactoryInstance.getClientFactory().destroy();
HttpServletServerFactoryInstance.getServerFactory().destroy();
}
@@ -84,12 +85,12 @@ public class GuardOperationTest extends BasicHttpOperation {
/**
* Sets up.
*/
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
super.setUpBasic();
guardConfig = mock(DecisionConfig.class);
- when(guardConfig.makeRequest()).thenAnswer(args -> {
+ Mockito.lenient().when(guardConfig.makeRequest()).thenAnswer(args -> {
DecisionRequest req = new DecisionRequest();
req.setAction("guard");
req.setOnapComponent("my-onap-component");
@@ -110,7 +111,7 @@ public class GuardOperationTest extends BasicHttpOperation {
* Tests "success" case with simulator.
*/
@Test
- public void testSuccess() throws Exception {
+ void testSuccess() throws Exception {
DecisionParams opParams =
DecisionParams.builder().clientName(MY_CLIENT).path("decision").action("guard").build();
config = new DecisionConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
@@ -120,14 +121,14 @@ public class GuardOperationTest extends BasicHttpOperation {
outcome = oper.start().get();
assertEquals(OperationResult.SUCCESS, outcome.getResult());
- assertTrue(outcome.getResponse() instanceof DecisionResponse);
+ assertInstanceOf(DecisionResponse.class, outcome.getResponse());
}
/**
* Tests "failure" case with simulator.
*/
@Test
- public void testFailure() throws Exception {
+ void testFailure() throws Exception {
DecisionParams opParams =
DecisionParams.builder().clientName(MY_CLIENT).path("decision").action("guard").build();
config = new DecisionConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
@@ -138,22 +139,22 @@ public class GuardOperationTest extends BasicHttpOperation {
outcome = oper.start().get();
assertEquals(OperationResult.FAILURE, outcome.getResult());
- assertTrue(outcome.getResponse() instanceof DecisionResponse);
+ assertInstanceOf(DecisionResponse.class, outcome.getResponse());
}
@Test
- public void testConstructor() {
+ void testConstructor() {
assertEquals(DEFAULT_ACTOR, oper.getActorName());
assertEquals(DEFAULT_OPERATION, oper.getName());
}
@Test
- public void testGetPropertyNames() {
+ void testGetPropertyNames() {
assertThat(oper.getPropertyNames()).isEmpty();
}
@Test
- public void testMakeRequest() throws CoderException {
+ void testMakeRequest() throws CoderException {
oper.generateSubRequestId(2);
verifyPayload("makeReqStd.json", makePayload());
@@ -182,7 +183,7 @@ public class GuardOperationTest extends BasicHttpOperation {
}
@Test
- public void testPostProcessResponse() {
+ void testPostProcessResponse() {
DecisionResponse response = new DecisionResponse();
// null status
diff --git a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/XacmlActorParamsTest.java b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/XacmlActorParamsTest.java
index 4a08871d8..26549e8db 100644
--- a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/XacmlActorParamsTest.java
+++ b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/XacmlActorParamsTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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,20 +22,20 @@
package org.onap.policy.controlloop.actor.xacml;
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.Map;
import java.util.TreeMap;
import java.util.function.Consumer;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.controlloop.actorserviceprovider.Util;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ActorParams;
-public class XacmlActorParamsTest {
+class XacmlActorParamsTest {
private static final String CONTAINER = "my-container";
private static final String CLIENT = "my-client";
private static final int TIMEOUT = 10;
@@ -55,8 +56,8 @@ public class XacmlActorParamsTest {
* Initializes {@link #operations} with two items and {@link params} with a fully
* populated object.
*/
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
operations = new TreeMap<>();
operations.put(PATH1, Map.of("path", URI1));
operations.put(PATH2, Map.of("path", URI2));
@@ -65,13 +66,13 @@ public class XacmlActorParamsTest {
}
@Test
- public void testIsDisabled() {
+ void testIsDisabled() {
// disabled by default
assertFalse(params.isDisabled());
}
@Test
- public void testValidate() {
+ void testValidate() {
assertTrue(params.validate(CONTAINER).isValid());
// only a few fields are required
@@ -90,13 +91,13 @@ public class XacmlActorParamsTest {
// original params should be valid
ValidationResult result = params.validate(CONTAINER);
- assertTrue(fieldName, result.isValid());
+ assertTrue(result.isValid(), fieldName);
// make invalid params
XacmlActorParams params2 = makeXacmlActorParams();
makeInvalid.accept(params2);
result = params2.validate(CONTAINER);
- assertFalse(fieldName, result.isValid());
+ assertFalse(result.isValid(), fieldName);
assertThat(result.getResult()).contains(CONTAINER).contains(fieldName).contains(expected);
}
diff --git a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/XacmlActorTest.java b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/XacmlActorTest.java
index 5c32f92bc..3f0e52860 100644
--- a/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/XacmlActorTest.java
+++ b/models-interactions/model-actors/actor.xacml/src/test/java/org/onap/policy/controlloop/actor/xacml/XacmlActorTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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,18 +21,19 @@
package org.onap.policy.controlloop.actor.xacml;
-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.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
import java.util.stream.Collectors;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.controlloop.actor.test.BasicActor;
-public class XacmlActorTest extends BasicActor {
+class XacmlActorTest extends BasicActor {
@Test
- public void test() {
+ void test() {
final XacmlActor prov = new XacmlActor();
// verify that it has the operators we expect
@@ -44,7 +46,7 @@ public class XacmlActorTest extends BasicActor {
// verify that it all plugs into the ActorService
verifyActorService(XacmlActor.NAME, "service.yaml");
- assertTrue(prov.getOperator(GuardOperation.NAME) instanceof DecisionOperator);
- assertTrue(prov.getOperator(ConfigureOperation.NAME) instanceof DecisionOperator);
+ assertInstanceOf(DecisionOperator.class, prov.getOperator(GuardOperation.NAME));
+ assertInstanceOf(DecisionOperator.class, prov.getOperator(ConfigureOperation.NAME));
}
}