aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmModelTest.java16
-rw-r--r--examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmUseCaseTest.java58
-rw-r--r--examples/examples-acm/src/main/java/org/onap/policy/apex/examples/acm/AcmTestServerDmaap.java4
-rw-r--r--examples/examples-acm/src/test/java/org/onap/policy/apex/examples/acm/TestApexAcmExample.java10
-rw-r--r--examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionConceptTest.java32
-rw-r--r--examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionModelTest.java19
-rw-r--r--examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionTslUseCaseTest.java63
-rw-r--r--examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnModelTest.java19
-rw-r--r--examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnTslUseCaseTest.java64
-rw-r--r--examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java18
-rw-r--r--examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpLogicTest.java119
-rw-r--r--examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelCliTest.java32
-rw-r--r--examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelTest.java24
-rw-r--r--examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java128
-rw-r--r--examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java10
-rw-r--r--examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java21
-rw-r--r--examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSim.java6
-rw-r--r--examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSimEndpoint.java83
-rw-r--r--examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeRunner.java4
-rw-r--r--examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeStandaloneRunner.java4
20 files changed, 354 insertions, 380 deletions
diff --git a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmModelTest.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmModelTest.java
index 04c5c7cd5..db313f888 100644
--- a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmModelTest.java
+++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmModelTest.java
@@ -22,15 +22,15 @@
package org.onap.policy.apex.examples.aadm;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
-public class AadmModelTest {
+class AadmModelTest {
private static final String VALID_MODEL_STRING = "***validation of model successful***";
TestApexModel<AxPolicyModel> testApexModel;
@@ -38,19 +38,19 @@ public class AadmModelTest {
/**
* Sets up embedded Derby database and the AADM model for the tests.
*/
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
testApexModel = new TestApexModel<>(AxPolicyModel.class, new TestAadmModelCreator());
}
@Test
- public void testModelValid() throws Exception {
+ void testModelValid() throws Exception {
final AxValidationResult result = testApexModel.testApexModelValid();
assertEquals(VALID_MODEL_STRING, result.toString());
}
@Test
- public void testModelWriteReadJson() throws Exception {
+ void testModelWriteReadJson() throws Exception {
testApexModel.testApexModelWriteReadJson();
}
}
diff --git a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmUseCaseTest.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmUseCaseTest.java
index 6412b7d30..a5efa9907 100644
--- a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmUseCaseTest.java
+++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmUseCaseTest.java
@@ -21,14 +21,14 @@
package org.onap.policy.apex.examples.aadm;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+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.assertTrue;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.context.ContextAlbum;
import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
@@ -49,14 +49,12 @@ import org.onap.policy.common.parameters.ParameterService;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
-// TODO: Auto-generated Javadoc
/**
* This class tests AADM use case.
*
* @author Sergey Sachkov (sergey.sachkov@ericsson.com)
- *
*/
-public class AadmUseCaseTest {
+class AadmUseCaseTest {
private static final XLogger logger = XLoggerFactory.getXLogger(AadmUseCaseTest.class);
private SchemaParameters schemaParameters;
@@ -66,8 +64,8 @@ public class AadmUseCaseTest {
/**
* Test AADM use case setup.
*/
- @Before
- public void beforeTest() {
+ @BeforeEach
+ void beforeTest() {
schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
@@ -95,8 +93,8 @@ public class AadmUseCaseTest {
/**
* After test.
*/
- @After
- public void afterTest() {
+ @AfterEach
+ void afterTest() {
ParameterService.deregister(engineParameters);
ParameterService.deregister(contextParameters.getDistributorParameters());
@@ -113,7 +111,7 @@ public class AadmUseCaseTest {
* @throws ApexException the apex exception
*/
@Test
- public void testAadmCase() throws ApexException {
+ void testAadmCase() throws ApexException {
final AxPolicyModel apexPolicyModel = new AadmDomainModelFactory().getAadmPolicyModel();
assertNotNull(apexPolicyModel);
final AxArtifactKey key = new AxArtifactKey("AADMApexEngine", "0.0.1");
@@ -153,7 +151,7 @@ public class AadmUseCaseTest {
apexEngine.handleEvent(event);
EnEvent result = listener.getResult();
assertProbe(result, event);
- logger.info("Receiving action event with {} action", result.get("ACTTASK"));
+ loginfoacttaskevent(result);
final ContextAlbum eNodeBStatusAlbum = apexEngine.getInternalContext().get("ENodeBStatusAlbum");
final ENodeBStatus eNodeBStatus = (ENodeBStatus) eNodeBStatusAlbum.get("123");
@@ -221,7 +219,7 @@ public class AadmUseCaseTest {
((ENodeBStatus) eNodeBStatusAlbum.get("123")).setDosCount(99);
// tcp correlation return positive dos
- logger.info("Receiving action event with {} action", result.get("ACTTASK"));
+ loginfoacttaskevent(result);
event = apexEngine.createEvent(axEvent.getKey());
event.put("IMSI", 123456L);
event.put("IMSI_IP", "101.111.121.131");
@@ -277,7 +275,7 @@ public class AadmUseCaseTest {
apexEngine.handleEvent(event);
result = listener.getResult();
assertProbeDone(result, event, 100, eNodeBStatusAlbum);
- logger.info("Receiving action event with {} action", result.get("ACTTASK"));
+ loginfoacttaskevent(result);
logger.info("Sending too many connections trigger ");
event = apexEngine.createEvent(axEvent.getKey());
@@ -307,7 +305,7 @@ public class AadmUseCaseTest {
assertProbe(result, event);
assertEquals(99, ((ENodeBStatus) eNodeBStatusAlbum.get("123")).getDosCount());
assertEquals(1, ((ENodeBStatus) eNodeBStatusAlbum.get("124")).getDosCount());
- logger.info("Receiving action event with {} action", result.get("ACTTASK"));
+ loginfoacttaskevent(result);
// End of user moving enodeB
((ENodeBStatus) eNodeBStatusAlbum.get("123")).setDosCount(101);
@@ -340,7 +338,7 @@ public class AadmUseCaseTest {
result = listener.getResult();
assertProbe(result, event);
assertEquals(102, ((ENodeBStatus) eNodeBStatusAlbum.get("123")).getDosCount());
- logger.info("Receiving action event with {} action", result.get("ACTTASK"));
+ loginfoacttaskevent(result);
logger.info("Sending too many connections trigger ");
event = apexEngine.createEvent(axEvent.getKey());
@@ -369,8 +367,8 @@ public class AadmUseCaseTest {
result = listener.getResult();
assertProbe(result, event);
assertEquals(102, ((ENodeBStatus) eNodeBStatusAlbum.get("123")).getDosCount());
- logger.info("Receiving action event with {} action", result.get("ACTTASK"));
- // End of user becomes non anomalous
+ loginfoacttaskevent(result);
+ // End of user becomes non-anomalous
apexEngine.handleEvent(result);
result = listener.getResult();
assertTrue(result.getName().startsWith("SAPCBlacklistSubscriberEvent"));
@@ -386,7 +384,7 @@ public class AadmUseCaseTest {
apexEngine.handleEvent(event);
result = listener.getResult();
assertTrue(result.getName().startsWith("SAPCBlacklistSubscriberEvent"));
- assertEquals("ExecutionIDs are different", event.getExecutionId(), result.getExecutionId());
+ assertEquals(event.getExecutionId(), result.getExecutionId(), "ExecutionIDs are different");
assertEquals(0L, result.get("IMSI"));
assertEquals("ServiceA", result.get("PROFILE"));
assertFalse((boolean) result.get("BLACKLIST_ON"));
@@ -397,7 +395,7 @@ public class AadmUseCaseTest {
private static void assertProbe(EnEvent result, EnEvent event) {
logger.info("Result name: {}", result.getName().startsWith("XSTREAM_AADM_ACT_EVENT"));
assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT"));
- assertEquals("ExecutionIDs are different", event.getExecutionId(), result.getExecutionId());
+ assertEquals(event.getExecutionId(), result.getExecutionId(), "ExecutionIDs are different");
assertEquals("probe", result.get("ACTTASK"));
assertTrue((boolean) result.get("TCP_ON"));
assertTrue((boolean) result.get("PROBE_ON"));
@@ -405,13 +403,21 @@ public class AadmUseCaseTest {
private static void assertProbeDone(EnEvent result, EnEvent event, int expected, ContextAlbum contextAlbum) {
assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT"));
- assertEquals("ExecutionIDs are different", event.getExecutionId(), result.getExecutionId());
+ assertEquals(event.getExecutionId(), result.getExecutionId(), "ExecutionIDs are different");
// DOS_IN_eNodeB set to be more than throughput so return act action
assertEquals("act", result.get("ACTTASK"));
// only one imsi was sent to process, so stop probe and tcp
assertFalse((boolean) result.get("TCP_ON"));
assertFalse((boolean) result.get("PROBE_ON"));
assertEquals(expected, ((ENodeBStatus) contextAlbum.get("123")).getDosCount());
+ loginfoacttaskevent(result);
+ }
+
+ /**
+ * Logs action from Result variable.
+ * @param result the result event
+ */
+ private static void loginfoacttaskevent(EnEvent result) {
logger.info("Receiving action event with {} action", result.get("ACTTASK"));
}
diff --git a/examples/examples-acm/src/main/java/org/onap/policy/apex/examples/acm/AcmTestServerDmaap.java b/examples/examples-acm/src/main/java/org/onap/policy/apex/examples/acm/AcmTestServerDmaap.java
index 9e8b1b71d..fb22d14ac 100644
--- a/examples/examples-acm/src/main/java/org/onap/policy/apex/examples/acm/AcmTestServerDmaap.java
+++ b/examples/examples-acm/src/main/java/org/onap/policy/apex/examples/acm/AcmTestServerDmaap.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation.
+ * Copyright (C) 2022-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.
@@ -55,7 +55,7 @@ public class AcmTestServerDmaap implements AutoCloseable {
}
@Override
- public void close() throws Exception {
+ public void close() {
if (restServer != null) {
restServer.stop();
restServer = null;
diff --git a/examples/examples-acm/src/test/java/org/onap/policy/apex/examples/acm/TestApexAcmExample.java b/examples/examples-acm/src/test/java/org/onap/policy/apex/examples/acm/TestApexAcmExample.java
index 9df25e678..be4bec096 100644
--- a/examples/examples-acm/src/test/java/org/onap/policy/apex/examples/acm/TestApexAcmExample.java
+++ b/examples/examples-acm/src/test/java/org/onap/policy/apex/examples/acm/TestApexAcmExample.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation.
+ * Copyright (C) 2022-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.
@@ -24,7 +24,7 @@ import static org.awaitility.Awaitility.await;
import jakarta.ws.rs.client.ClientBuilder;
import java.util.concurrent.TimeUnit;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaEditorMain;
import org.onap.policy.apex.service.engine.main.ApexMain;
@@ -32,10 +32,10 @@ import org.onap.policy.apex.service.engine.main.ApexMain;
* Test class to run an example policy for ACM interaction. Event received on
* message topic (dummy REST Endpoint here) and triggers a new message.
*/
-public class TestApexAcmExample {
+class TestApexAcmExample {
@Test
- public void testExample() {
+ void testExample() {
try (var dmmap = new AcmTestServerDmaap()) {
dmmap.validate();
@@ -68,7 +68,7 @@ public class TestApexAcmExample {
final var client = ClientBuilder.newClient();
final var apexMain = new ApexMain(apexArgs);
- await().atMost(5000, TimeUnit.MILLISECONDS).until(() -> apexMain.isAlive());
+ await().atMost(5000, TimeUnit.MILLISECONDS).until(apexMain::isAlive);
String getLoggedEventUrl = "http://localhost:3904/events/getLoggedEvent";
await().atMost(20000, TimeUnit.MILLISECONDS).until(() -> {
diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionConceptTest.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionConceptTest.java
index 1237537fd..384d6f912 100644
--- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionConceptTest.java
+++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionConceptTest.java
@@ -1,7 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (c) 2020 Nordix Foundation.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Copyright (c) 2020, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,21 +21,22 @@
package org.onap.policy.apex.examples.adaptive;
-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.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.assertTrue;
import java.util.LinkedList;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.examples.adaptive.concepts.AnomalyDetection;
-public class AnomalyDetectionConceptTest {
+class AnomalyDetectionConceptTest {
@Test
- public void testToString() {
+ void testToString() {
AnomalyDetection anomalyDetection = new AnomalyDetection();
List<Double> newAnomalyScores = new LinkedList<>();
newAnomalyScores.add((double) 55);
@@ -45,13 +45,13 @@ public class AnomalyDetectionConceptTest {
assertEquals(newAnomalyScores, anomalyDetection.getAnomalyScores());
assertTrue(anomalyDetection.checkSetAnomalyScores());
assertEquals(55, anomalyDetection.getFrequency());
- assertEquals(true, anomalyDetection.isFirstRound());
+ assertTrue(anomalyDetection.isFirstRound());
assertEquals("AnomalyDetection(firstRound=true, frequency=55, anomalyScores=[55.0], frequencyForecasted=null)",
anomalyDetection.toString());
}
@Test
- public void testHashCode() {
+ void testHashCode() {
AnomalyDetection detection = new AnomalyDetection();
AnomalyDetection compareDetection = new AnomalyDetection();
assertEquals(detection.hashCode(), compareDetection.hashCode());
@@ -65,7 +65,7 @@ public class AnomalyDetectionConceptTest {
}
@Test
- public void testEquals() {
+ void testEquals() {
AnomalyDetection anomalyDetection = new AnomalyDetection();
AnomalyDetection comparisonDetection = new AnomalyDetection();
assertEquals(anomalyDetection, comparisonDetection);
@@ -74,7 +74,7 @@ public class AnomalyDetectionConceptTest {
//Compare object to null
assertNotNull(anomalyDetection);
//compare object to string
- assertNotEquals(anomalyDetection, "test");
+ assertNotEquals("test", anomalyDetection);
// Anomaly Scores comparison
anomalyDetection.setAnomalyScores(null);
assertNotEquals(anomalyDetection, comparisonDetection);
@@ -105,7 +105,7 @@ public class AnomalyDetectionConceptTest {
}
@Test
- public void testCheckSets() {
+ void testCheckSets() {
AnomalyDetection anomalyDetection = new AnomalyDetection();
assertFalse(anomalyDetection.checkSetAnomalyScores());
List<Double> anomalyScores = new LinkedList<>();
@@ -116,7 +116,7 @@ public class AnomalyDetectionConceptTest {
assertTrue(anomalyDetection.checkSetAnomalyScores());
anomalyDetection.unsetAnomalyScores();
assertFalse(anomalyDetection.checkSetAnomalyScores());
- assertEquals(null, anomalyDetection.getFrequencyForecasted());
+ assertNull(anomalyDetection.getFrequencyForecasted());
assertFalse(anomalyDetection.checkSetFrequencyForecasted());
List<Double> frequencyForecasted = new LinkedList<>();
anomalyDetection.setFrequencyForecasted(frequencyForecasted);
diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionModelTest.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionModelTest.java
index 4f9c58cc6..fb5459b40 100644
--- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionModelTest.java
+++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionModelTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020,2022 Nordix Foundation.
+ * Modifications Copyright (C) 2020, 2022, 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,36 +21,35 @@
package org.onap.policy.apex.examples.adaptive;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
-public class AnomalyDetectionModelTest {
+class AnomalyDetectionModelTest {
private static final String VALID_MODEL_STRING = "***validation of model successful***";
TestApexModel<AxPolicyModel> testApexModel;
/**
* Sets up embedded Derby database and the Apex anomaly detection model for the tests.
- * @throws Exception exception to be thrown while setting up the database connection
*/
- @Before
- public void setup() throws Exception {
+ @BeforeEach
+ void setup() {
testApexModel = new TestApexModel<>(AxPolicyModel.class, new TestAnomalyDetectionModelCreator());
}
@Test
- public void testModelValid() throws Exception {
+ void testModelValid() throws Exception {
final AxValidationResult result = testApexModel.testApexModelValid();
assertEquals(VALID_MODEL_STRING, result.toString());
}
@Test
- public void testModelWriteReadJson() throws Exception {
+ void testModelWriteReadJson() throws Exception {
testApexModel.testApexModelWriteReadJson();
}
}
diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionTslUseCaseTest.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionTslUseCaseTest.java
index 5beab7724..e4d0c2640 100644
--- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionTslUseCaseTest.java
+++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AnomalyDetectionTslUseCaseTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 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,16 +22,15 @@
package org.onap.policy.apex.examples.adaptive;
import static org.awaitility.Awaitility.await;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.io.IOException;
import java.util.Random;
import java.util.concurrent.TimeUnit;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.ContextParameters;
@@ -53,13 +52,13 @@ import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
/**
- * This policy passes, and recieves a Double event context filed called "EVCDouble".<br>
+ * This policy passes, and receives a Double event context filed called "EVCDouble".<br>
* The policy tries to detect anomalies in the pattern of values for EVCDouble<br>
* See the 2 test cases below (1 short, 1 long)
*
* @author John Keeney (John.Keeney@ericsson.com)
*/
-public class AnomalyDetectionTslUseCaseTest {
+class AnomalyDetectionTslUseCaseTest {
private static final XLogger LOGGER = XLoggerFactory.getXLogger(AnomalyDetectionTslUseCaseTest.class);
private static final int MAXITERATIONS = 3660;
@@ -72,8 +71,8 @@ public class AnomalyDetectionTslUseCaseTest {
/**
* Before test.
*/
- @Before
- public void beforeTest() {
+ @BeforeEach
+ void beforeTest() {
schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
@@ -102,8 +101,8 @@ public class AnomalyDetectionTslUseCaseTest {
/**
* After test.
*/
- @After
- public void afterTest() {
+ @AfterEach
+ void afterTest() {
ParameterService.deregister(engineParameters);
ParameterService.deregister(contextParameters.getDistributorParameters());
@@ -118,12 +117,10 @@ public class AnomalyDetectionTslUseCaseTest {
* Test anomaly detection tsl.
*
* @throws ApexException the apex exception
- * @throws InterruptedException the interrupted exception
- * @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- // once through the long running test below
- public void testAnomalyDetectionTsl() throws ApexException, InterruptedException, IOException {
+ // once through the long-running test below
+ void testAnomalyDetectionTsl() throws ApexException {
final AxPolicyModel apexPolicyModel = new AdaptiveDomainModelFactory().getAnomalyDetectionPolicyModel();
assertNotNull(apexPolicyModel);
@@ -140,34 +137,32 @@ public class AnomalyDetectionTslUseCaseTest {
apexEngine1.updateModel(apexPolicyModel, false);
apexEngine1.start();
final EnEvent triggerEvent =
- apexEngine1.createEvent(new AxArtifactKey("AnomalyDetectionTriggerEvent", "0.0.1"));
+ apexEngine1.createEvent(new AxArtifactKey("AnomalyDetectionTriggerEvent", "0.0.1"));
final double rval = RAND.nextGaussian();
triggerEvent.put("Iteration", 0);
triggerEvent.put("MonitoredValue", rval);
- LOGGER.info("Triggering policy in Engine 1 with " + triggerEvent);
+ LOGGER.info("Triggering policy in Engine 1 with {}", triggerEvent);
apexEngine1.handleEvent(triggerEvent);
final EnEvent result = listener1.getResult();
LOGGER.info("Receiving action event {} ", result);
- assertEquals("ExecutionIDs are different", triggerEvent.getExecutionId(), result.getExecutionId());
+ assertEquals(triggerEvent.getExecutionId(), result.getExecutionId(), "ExecutionIDs are different");
triggerEvent.clear();
result.clear();
- await().atLeast(1, TimeUnit.MILLISECONDS).until(() -> result.isEmpty());
+ await().atLeast(1, TimeUnit.MILLISECONDS).until(result::isEmpty);
apexEngine1.stop();
}
/**
- * This policy passes, and recieves a Double event context filed called "EVCDouble"<br>
+ * This policy passes, and receives a Double event context filed called "EVCDouble"<br>
* The policy tries to detect anomalies in the pattern of values for EVCDouble <br>
* This test case generates a SineWave-like pattern for the parameter, repeating every 360 iterations. (These Period
* should probably be set using TaskParameters!) Every 361st value is a random number!, so should be identified as
* an Anomaly. The policy has 3 Decide Tasks, and the Decide TaskSelectionLogic picks one depending on the
* 'Anomaliness' of the input data. <br>
- * To plot the results grep debug results for the string "************", paste into excel and delete non-relevant
+ * To plot the results grep debug results for the string "************", paste into Excel and delete non-relevant
* columns<br>
*
* @throws ApexException the apex exception
- * @throws InterruptedException the interrupted exception
- * @throws IOException Signals that an I/O exception has occurred.
*/
// Test is disabled by default. uncomment below, or execute using the main() method
// @Test
@@ -175,7 +170,7 @@ public class AnomalyDetectionTslUseCaseTest {
// -Dtest=org.onap.policy.apex.core.engine.ml.TestAnomalyDetectionTslUseCase test | findstr /L /C:"Apex [main] DEBUG
// c.e.a.e.TaskSelectionExecutionLogging -
// TestAnomalyDetectionTSL_Policy0000DecideStateTaskSelectionLogic.getTask():"
- public void testAnomalyDetectionTslmain() throws ApexException, InterruptedException, IOException {
+ void testAnomalyDetectionTslMain() throws ApexException {
final AxPolicyModel apexPolicyModel = new AdaptiveDomainModelFactory().getAnomalyDetectionPolicyModel();
assertNotNull(apexPolicyModel);
@@ -197,23 +192,23 @@ public class AnomalyDetectionTslUseCaseTest {
apexEngine1.start();
final EnEvent triggerEvent =
- apexEngine1.createEvent(new AxArtifactKey("AnomalyDetectionTriggerEvent", "0.0.1"));
+ apexEngine1.createEvent(new AxArtifactKey("AnomalyDetectionTriggerEvent", "0.0.1"));
assertNotNull(triggerEvent);
for (int iteration = 0; iteration < MAXITERATIONS; iteration++) {
// Trigger the policy in engine 1
double value = (Math.sin(Math.toRadians(iteration))) + (RAND.nextGaussian() / 25.0);
- // lets make every 361st number a random value to perhaps flag as an anomaly
+ // let's make every 361st number a random value to perhaps flag as an anomaly
if (((iteration + 45) % 361) == 0) {
value = (RAND.nextGaussian() * 2.0);
}
triggerEvent.put("Iteration", iteration);
triggerEvent.put("MonitoredValue", value);
- LOGGER.info("Iteration " + iteration + ":\tTriggering policy in Engine 1 with " + triggerEvent);
+ LOGGER.info("Iteration {}:\tTriggering policy in Engine 1 with {}", iteration, triggerEvent);
apexEngine1.handleEvent(triggerEvent);
final EnEvent result = listener1.getResult();
- LOGGER.info("Iteration " + iteration + ":\tReceiving action event {} ", result);
+ LOGGER.info("Iteration {}:\tReceiving action event {} ", iteration, result);
triggerEvent.clear();
result.clear();
}
@@ -226,10 +221,8 @@ public class AnomalyDetectionTslUseCaseTest {
*
* @param args the arguments
* @throws ApexException the apex exception
- * @throws InterruptedException the interrupted exception
- * @throws IOException Signals that an I/O exception has occurred.
*/
- public static void main(final String[] args) throws ApexException, InterruptedException, IOException {
- new AnomalyDetectionTslUseCaseTest().testAnomalyDetectionTslmain();
+ public static void main(final String[] args) throws ApexException {
+ new AnomalyDetectionTslUseCaseTest().testAnomalyDetectionTslMain();
}
}
diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnModelTest.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnModelTest.java
index c69fa0678..c864de150 100644
--- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnModelTest.java
+++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnModelTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020,2022 Nordix Foundation.
+ * Modifications Copyright (C) 2020, 2022, 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,36 +21,35 @@
package org.onap.policy.apex.examples.adaptive;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
-public class AutoLearnModelTest {
+class AutoLearnModelTest {
private static final String VALID_MODEL_STRING = "***validation of model successful***";
TestApexModel<AxPolicyModel> testApexModel;
/**
* Sets up embedded Derby database and the Apex AutoLearn model for the tests.
- * @throws Exception exception to be thrown while setting up the database connection
*/
- @Before
- public void setup() throws Exception {
+ @BeforeEach
+ void setup() {
testApexModel = new TestApexModel<>(AxPolicyModel.class, new TestAutoLearnModelCreator());
}
@Test
- public void testModelValid() throws Exception {
+ void testModelValid() throws Exception {
final AxValidationResult result = testApexModel.testApexModelValid();
assertEquals(VALID_MODEL_STRING, result.toString());
}
@Test
- public void testModelWriteReadJson() throws Exception {
+ void testModelWriteReadJson() throws Exception {
testApexModel.testApexModelWriteReadJson();
}
}
diff --git a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnTslUseCaseTest.java b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnTslUseCaseTest.java
index 52d1b7ff8..bcb953a81 100644
--- a/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnTslUseCaseTest.java
+++ b/examples/examples-adaptive/src/test/java/org/onap/policy/apex/examples/adaptive/AutoLearnTslUseCaseTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 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,16 +22,15 @@
package org.onap.policy.apex.examples.adaptive;
import static org.awaitility.Awaitility.await;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.io.IOException;
import java.util.Random;
import java.util.concurrent.TimeUnit;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.ContextParameters;
@@ -52,34 +51,36 @@ import org.onap.policy.common.parameters.ParameterService;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
-// TODO: Auto-generated Javadoc
/**
* Test Auto learning in TSL.
*
* @author John Keeney (John.Keeney@ericsson.com)
*/
-public class AutoLearnTslUseCaseTest {
+class AutoLearnTslUseCaseTest {
private static final XLogger LOGGER = XLoggerFactory.getXLogger(AutoLearnTslUseCaseTest.class);
private static final int MAXITERATIONS = 1000;
private static final Random rand = new Random(System.currentTimeMillis());
+ private static final String RECEIVING_ACTION_EVENT = "Receiving action event {} ";
+ private static final String TRIGGER_MESSAGE = "Triggering policy in Engine 1 with {}";
private SchemaParameters schemaParameters;
private ContextParameters contextParameters;
private EngineParameters engineParameters;
+
/**
* Before test.
*/
- @Before
- public void beforeTest() {
+ @BeforeEach
+ void beforeTest() {
schemaParameters = new SchemaParameters();
-
+
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters());
ParameterService.register(schemaParameters);
-
+
contextParameters = new ContextParameters();
contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME);
@@ -91,7 +92,7 @@ public class AutoLearnTslUseCaseTest {
ParameterService.register(contextParameters.getDistributorParameters());
ParameterService.register(contextParameters.getLockManagerParameters());
ParameterService.register(contextParameters.getPersistorParameters());
-
+
engineParameters = new EngineParameters();
engineParameters.getExecutorParameterMap().put("MVEL", new MvelExecutorParameters());
engineParameters.getExecutorParameterMap().put("JAVA", new JavaExecutorParameters());
@@ -101,10 +102,10 @@ public class AutoLearnTslUseCaseTest {
/**
* After test.
*/
- @After
- public void afterTest() {
+ @AfterEach
+ void afterTest() {
ParameterService.deregister(engineParameters);
-
+
ParameterService.deregister(contextParameters.getDistributorParameters());
ParameterService.deregister(contextParameters.getLockManagerParameters());
ParameterService.deregister(contextParameters.getPersistorParameters());
@@ -117,12 +118,10 @@ public class AutoLearnTslUseCaseTest {
* Test auto learn tsl.
*
* @throws ApexException the apex exception
- * @throws InterruptedException the interrupted exception
- * @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- // once through the long running test below
- public void testAutoLearnTsl() throws ApexException, InterruptedException, IOException {
+ // once through the long-running test below
+ void testAutoLearnTsl() throws ApexException {
final AxPolicyModel apexPolicyModel = new AdaptiveDomainModelFactory().getAutoLearnPolicyModel();
assertNotNull(apexPolicyModel);
@@ -142,11 +141,12 @@ public class AutoLearnTslUseCaseTest {
final double rval = rand.nextGaussian();
triggerEvent.put("MonitoredValue", rval);
triggerEvent.put("LastMonitoredValue", 0D);
- LOGGER.info("Triggering policy in Engine 1 with " + triggerEvent);
+
+ LOGGER.info(TRIGGER_MESSAGE, triggerEvent);
apexEngine1.handleEvent(triggerEvent);
final EnEvent result = listener1.getResult();
- LOGGER.info("Receiving action event {} ", result);
- assertEquals("ExecutionIDs are different", triggerEvent.getExecutionId(), result.getExecutionId());
+ LOGGER.info(RECEIVING_ACTION_EVENT, result);
+ assertEquals(triggerEvent.getExecutionId(), result.getExecutionId(), "ExecutionIDs are different");
triggerEvent.clear();
result.clear();
await().atLeast(10, TimeUnit.MILLISECONDS).until(() -> triggerEvent.isEmpty() && result.isEmpty());
@@ -166,11 +166,9 @@ public class AutoLearnTslUseCaseTest {
* columns<br>
*
* @throws ApexException the apex exception
- * @throws InterruptedException the interrupted exception
- * @throws IOException Signals that an I/O exception has occurred.
*/
// @Test
- public void testAutoLearnTslMain() throws ApexException, InterruptedException, IOException {
+ void testAutoLearnTslMain() throws ApexException {
final double dwant = 50.0;
final double toleranceTileJump = 3.0;
@@ -209,10 +207,10 @@ public class AutoLearnTslUseCaseTest {
for (int iteration = 0; iteration < MAXITERATIONS; iteration++) {
// Trigger the policy in engine 1
- LOGGER.info("Triggering policy in Engine 1 with " + triggerEvent);
+ LOGGER.info(TRIGGER_MESSAGE, triggerEvent);
apexEngine1.handleEvent(triggerEvent);
final EnEvent result = listener1.getResult();
- LOGGER.info("Receiving action event {} ", result);
+ LOGGER.info(RECEIVING_ACTION_EVENT, result);
triggerEvent.clear();
double val = (Double) result.get("MonitoredValue");
@@ -230,7 +228,7 @@ public class AutoLearnTslUseCaseTest {
val = rval;
triggerEvent.put("MonitoredValue", val);
LOGGER.info("Iteration " + iteration + ": Average " + avval + " has become closer (" + distance
- + ") than " + toleranceTileJump + " to " + dwant + " so reseting val:\t\t\t\t\t\t\t\t" + val);
+ + ") than " + toleranceTileJump + " to " + dwant + " so reseting val:\t\t\t\t\t\t\t\t" + val);
avval = 0;
avcount = 0;
}
@@ -249,10 +247,8 @@ public class AutoLearnTslUseCaseTest {
*
* @param args the arguments
* @throws ApexException the apex exception
- * @throws InterruptedException the interrupted exception
- * @throws IOException Signals that an I/O exception has occurred.
*/
- public static void main(final String[] args) throws ApexException, InterruptedException, IOException {
+ public static void main(final String[] args) throws ApexException {
new AutoLearnTslUseCaseTest().testAutoLearnTslMain();
}
}
diff --git a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java
index d3c0c87b3..ee1744f0e 100644
--- a/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java
+++ b/examples/examples-grpc/src/test/java/org/onap/policy/apex/examples/grpc/TestApexGrpcExample.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020-2023 Nordix Foundation.
+ * Copyright (C) 2020-2024 Nordix Foundation.
* Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,7 +30,7 @@ import jakarta.ws.rs.core.Response;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaEditorMain;
import org.onap.policy.apex.service.engine.main.ApexMain;
@@ -40,9 +40,9 @@ import org.onap.policy.apex.service.engine.main.ApexMain;
* create/delete subscription gRPC request is triggered to the CDS (a dummy gRPC server here). Response received from
* CDS is used to send a final output Log event on POLICY_CL_MGT topic.
*/
-public class TestApexGrpcExample {
+class TestApexGrpcExample {
@Test
- public void testGrpcExample() throws Exception {
+ void testGrpcExample() throws Exception {
// @formatter:off
final String[] cliArgs = new String[] {
"-c",
@@ -74,13 +74,12 @@ public class TestApexGrpcExample {
final Client client = ClientBuilder.newClient();
final ApexMain apexMain = new ApexMain(apexArgs);
- await().atMost(5000, TimeUnit.MILLISECONDS).until(() -> apexMain.isAlive());
+ await().atMost(5000, TimeUnit.MILLISECONDS).until(apexMain::isAlive);
String getLoggedEventUrl = "http://localhost:54321/GrpcTestRestSim/sim/event/getLoggedEvent";
// wait for success response code to be received, until a timeout
- await().atMost(20000, TimeUnit.MILLISECONDS).until(() -> {
- return 200 == client.target(getLoggedEventUrl).request("application/json").get().getStatus();
- });
+ await().atMost(20000, TimeUnit.MILLISECONDS).until(() ->
+ 200 == client.target(getLoggedEventUrl).request("application/json").get().getStatus());
apexMain.shutdown();
Response response = client.target(getLoggedEventUrl).request("application/json").get();
sim.tearDown();
@@ -91,7 +90,6 @@ public class TestApexGrpcExample {
Files.readString(Paths.get("src/main/resources/examples/events/APEXgRPC/CDSResponseStatusEvent.json"))
.replaceAll("\r", "");
// Both LogEvent and CDSResponseStatusEvent are generated from the final state in the policy
- assertThat(responseEntity).contains(expectedStatusEvent);
- assertThat(responseEntity).contains(expectedLoggedOutputEvent);
+ assertThat(responseEntity).contains(expectedStatusEvent).contains(expectedLoggedOutputEvent);
}
} \ No newline at end of file
diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpLogicTest.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpLogicTest.java
index b3c35a310..19bdc8575 100644
--- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpLogicTest.java
+++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpLogicTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020, 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,15 +21,15 @@
package org.onap.policy.apex.examples.myfirstpolicy;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicy;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
@@ -40,15 +40,15 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
/**
* The Class TestMfpLogic.
*/
-public class MfpLogicTest {
+class MfpLogicTest {
private static final Map<String, String> LOGICEXTENSIONS = new LinkedHashMap<>();
/**
* Test setup.
*/
- @BeforeClass
- public static void testMfpUseCaseSetup() {
+ @BeforeAll
+ static void testMfpUseCaseSetup() {
LOGICEXTENSIONS.put("MVEL", "mvel");
LOGICEXTENSIONS.put("JAVASCRIPT", "js");
}
@@ -57,7 +57,7 @@ public class MfpLogicTest {
* Check logic for MyFirstPolicy#1.
*/
@Test
- public void testMfp1TaskLogic() {
+ void testMfp1TaskLogic() {
final AxPolicyModel apexPolicyModel = new MfpDomainModelFactory().getMfp1PolicyModel();
assertNotNull(apexPolicyModel);
@@ -65,16 +65,15 @@ public class MfpLogicTest {
logics.putAll(getTslLogics(apexPolicyModel));
logics.putAll(getTaskLogics(apexPolicyModel));
- for (final Entry<String, String> logicvalue : logics.entrySet()) {
- final String filename = "examples/models/MyFirstPolicy/1/" + logicvalue.getKey();
- final String logic = logicvalue.getValue();
- final String expectedlogic = ResourceUtils.getResourceAsString(filename);
- assertNotNull("File " + filename + " was not found. It should contain logic for PolicyModel "
- + apexPolicyModel.getKey(), expectedlogic);
- assertEquals(
- "The task in " + filename + " is not the same as the relevant logic in PolicyModel "
- + apexPolicyModel.getKey(),
- expectedlogic.replaceAll("\\s", ""), logic.replaceAll("\\s", ""));
+ for (final Entry<String, String> logicValue : logics.entrySet()) {
+ final String filename = "examples/models/MyFirstPolicy/1/" + logicValue.getKey();
+ final String logic = logicValue.getValue();
+ final String expectedLogic = ResourceUtils.getResourceAsString(filename);
+ assertNotNull(expectedLogic, "File " + filename + " was not found. It should contain logic for PolicyModel "
+ + apexPolicyModel.getKey());
+ assertEquals(expectedLogic.replaceAll("\\s", ""), logic.replaceAll("\\s", ""),
+ "The task in " + filename + " is not the same as the relevant logic in PolicyModel "
+ + apexPolicyModel.getKey());
}
}
@@ -82,7 +81,7 @@ public class MfpLogicTest {
* Check logic for MyFirstPolicyAlt#1.
*/
@Test
- public void testMfp1AltTaskLogic() {
+ void testMfp1AltTaskLogic() {
final AxPolicyModel apexPolicyModel = new MfpDomainModelFactory().getMfp1AltPolicyModel();
assertNotNull(apexPolicyModel);
@@ -90,16 +89,15 @@ public class MfpLogicTest {
logics.putAll(getTslLogics(apexPolicyModel));
logics.putAll(getTaskLogics(apexPolicyModel));
- for (final Entry<String, String> logicvalue : logics.entrySet()) {
- final String filename = "examples/models/MyFirstPolicy/1/" + logicvalue.getKey();
- final String logic = logicvalue.getValue();
- final String expectedlogic = ResourceUtils.getResourceAsString(filename);
- assertNotNull("File " + filename + " was not found. It should contain logic for PolicyModel "
- + apexPolicyModel.getKey(), expectedlogic);
- assertEquals(
- "The task in " + filename + " is not the same as the relevant logic in PolicyModel "
- + apexPolicyModel.getKey(),
- expectedlogic.replaceAll("\\s", ""), logic.replaceAll("\\s", ""));
+ for (final Entry<String, String> logicValue : logics.entrySet()) {
+ final String filename = "examples/models/MyFirstPolicy/1/" + logicValue.getKey();
+ final String logic = logicValue.getValue();
+ final String expectedLogic = ResourceUtils.getResourceAsString(filename);
+ assertNotNull(expectedLogic, "File " + filename + " was not found. It should contain logic for PolicyModel "
+ + apexPolicyModel.getKey());
+ assertEquals(expectedLogic.replaceAll("\\s", ""), logic.replaceAll("\\s", ""),
+ "The task in " + filename + " is not the same as the relevant logic in PolicyModel "
+ + apexPolicyModel.getKey());
}
}
@@ -107,7 +105,7 @@ public class MfpLogicTest {
* Check logic for MyFirstPolicy2.
*/
@Test
- public void testMfp2TaskLogic() {
+ void testMfp2TaskLogic() {
final AxPolicyModel apexPolicyModel = new MfpDomainModelFactory().getMfp2PolicyModel();
assertNotNull(apexPolicyModel);
@@ -115,16 +113,15 @@ public class MfpLogicTest {
logics.putAll(getTslLogics(apexPolicyModel));
logics.putAll(getTaskLogics(apexPolicyModel));
- for (final Entry<String, String> logicvalue : logics.entrySet()) {
- final String logic = logicvalue.getValue();
- final String filename = "examples/models/MyFirstPolicy/2/" + logicvalue.getKey();
- final String expectedlogic = ResourceUtils.getResourceAsString(filename);
- assertNotNull("File " + filename + " was not found. It should contain logic for PolicyModel "
- + apexPolicyModel.getKey(), expectedlogic);
- assertEquals(
- "The task in " + filename + " is not the same as the relevant logic in PolicyModel "
- + apexPolicyModel.getKey(),
- expectedlogic.replaceAll("\\s", ""), logic.replaceAll("\\s", ""));
+ for (final Entry<String, String> logicValue : logics.entrySet()) {
+ final String logic = logicValue.getValue();
+ final String filename = "examples/models/MyFirstPolicy/2/" + logicValue.getKey();
+ final String expectedLogic = ResourceUtils.getResourceAsString(filename);
+ assertNotNull(expectedLogic, "File " + filename + " was not found. It should contain logic for PolicyModel "
+ + apexPolicyModel.getKey());
+ assertEquals(expectedLogic.replaceAll("\\s", ""), logic.replaceAll("\\s", ""),
+ "The task in " + filename + " is not the same as the relevant logic in PolicyModel "
+ + apexPolicyModel.getKey());
}
}
@@ -136,20 +133,19 @@ public class MfpLogicTest {
*/
private Map<String, String> getTslLogics(final AxPolicyModel apexPolicyModel) {
final Map<String, String> ret = new LinkedHashMap<>();
- for (final Entry<AxArtifactKey, AxPolicy> policyentry : apexPolicyModel.getPolicies().getPolicyMap()
- .entrySet()) {
+ for (final Entry<AxArtifactKey, AxPolicy> policyentry :
+ apexPolicyModel.getPolicies().getPolicyMap().entrySet()) {
for (final Entry<String, AxState> statesentry : policyentry.getValue().getStateMap().entrySet()) {
final AxState state = statesentry.getValue();
- final String tsllogic = state.getTaskSelectionLogic().getLogic();
- final String tsllogicflavour = state.getTaskSelectionLogic().getLogicFlavour();
- if (tsllogic != null && tsllogic.trim().length() > 0) {
- assertNotNull(
- "Logic Type \"" + tsllogicflavour + "\" in state " + statesentry.getKey() + " in policy "
- + policyentry.getKey() + " is not supported in this test",
- LOGICEXTENSIONS.get(tsllogicflavour.toUpperCase()));
+ final String tslLogic = state.getTaskSelectionLogic().getLogic();
+ final String tslLogicFlavour = state.getTaskSelectionLogic().getLogicFlavour();
+ if (tslLogic != null && !tslLogic.trim().isEmpty()) {
+ assertNotNull(LOGICEXTENSIONS.get(tslLogicFlavour.toUpperCase()),
+ "Logic Type \"" + tslLogicFlavour + "\" in state " + statesentry.getKey() + " in policy "
+ + policyentry.getKey() + " is not supported in this test");
final String filename = policyentry.getKey().getName() + "_" + statesentry.getKey() + "TSL."
- + LOGICEXTENSIONS.get(tsllogicflavour.toUpperCase());
- ret.put(filename, tsllogic);
+ + LOGICEXTENSIONS.get(tslLogicFlavour.toUpperCase());
+ ret.put(filename, tslLogic);
}
}
}
@@ -166,15 +162,16 @@ public class MfpLogicTest {
final Map<String, String> ret = new LinkedHashMap<>();
for (final Entry<AxArtifactKey, AxTask> taskentry : apexPolicyModel.getTasks().getTaskMap().entrySet()) {
final AxTask task = taskentry.getValue();
- final String tasklogic = task.getTaskLogic().getLogic();
- final String tasklogicflavour = task.getTaskLogic().getLogicFlavour();
- assertTrue("No/Blank logic found in task " + taskentry.getKey(),
- (tasklogic != null && tasklogic.trim().length() > 0));
- assertNotNull("Logic Type \"" + tasklogicflavour + "\" in task " + taskentry.getKey()
- + " is not supported in this test", LOGICEXTENSIONS.get(tasklogicflavour.toUpperCase()));
+ final String taskLogic = task.getTaskLogic().getLogic();
+ final String taskLogicFlavour = task.getTaskLogic().getLogicFlavour();
+ assertTrue((taskLogic != null && !taskLogic.trim().isEmpty()),
+ "No/Blank logic found in task " + taskentry.getKey());
+ assertNotNull(LOGICEXTENSIONS.get(taskLogicFlavour.toUpperCase()),
+ "Logic Type \"" + taskLogicFlavour + "\" in task " + taskentry.getKey()
+ + " is not supported in this test");
final String filename =
- taskentry.getKey().getName() + "." + LOGICEXTENSIONS.get(tasklogicflavour.toUpperCase());
- ret.put(filename, tasklogic);
+ taskentry.getKey().getName() + "." + LOGICEXTENSIONS.get(taskLogicFlavour.toUpperCase());
+ ret.put(filename, taskLogic);
}
return ret;
}
diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelCliTest.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelCliTest.java
index 45281524c..cb3aa7666 100644
--- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelCliTest.java
+++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelCliTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020, 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,12 +21,12 @@
package org.onap.policy.apex.examples.myfirstpolicy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.File;
import java.io.IOException;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.auth.clieditor.ApexCommandLineEditorMain;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
@@ -36,17 +36,15 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
/**
* Test MyFirstPolicyModel CLI.
*/
-public class MfpModelCliTest {
+class MfpModelCliTest {
private static AxPolicyModel testApexModel1;
private static AxPolicyModel testApexModel2;
/**
- * Setup the test.
- *
- * @throws Exception if there is an error
+ * Set up the test.
*/
- @BeforeClass
- public static void setup() throws Exception {
+ @BeforeAll
+ static void setup() {
testApexModel1 = new TestMfpModelCreator.TestMfp1ModelCreator().getModel();
testApexModel2 = new TestMfpModelCreator.TestMfp2ModelCreator().getModel();
}
@@ -54,11 +52,11 @@ public class MfpModelCliTest {
/**
* Test CLI policy.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
* @throws ApexModelException ifd there is an Apex Error
*/
@Test
- public void testCliPolicy() throws IOException, ApexModelException {
+ void testCliPolicy() throws IOException, ApexModelException {
final File tempLogFile1 = File.createTempFile("TestMyFirstPolicy1CLI", ".log");
final File tempModelFile1 = File.createTempFile("TestMyFirstPolicy1CLI", ".json");
@@ -89,17 +87,19 @@ public class MfpModelCliTest {
final ApexModelReader<AxPolicyModel> reader = new ApexModelReader<>(AxPolicyModel.class);
AxPolicyModel generatedmodel = reader.read(TextFileUtils.getTextFileAsString(tempModelFile1.getAbsolutePath()));
- assertEquals("Model generated from the CLI (" + testApexModel1CliArgs[1] + ") into file "
+ assertEquals(testApexModel1, generatedmodel,
+ "Model generated from the CLI (" + testApexModel1CliArgs[1] + ") into file "
+ tempModelFile1.getAbsolutePath() + " is not the same as the test Model for "
- + testApexModel1.getKey(), testApexModel1, generatedmodel);
+ + testApexModel1.getKey());
tempLogFile1.delete();
tempModelFile1.delete();
generatedmodel = reader.read(TextFileUtils.getTextFileAsString(tempModelFile2.getAbsolutePath()));
- assertEquals("Model generated from the CLI (" + testApexModel2CliArgs[1] + ") into file "
+ assertEquals(testApexModel2, generatedmodel,
+ "Model generated from the CLI (" + testApexModel2CliArgs[1] + ") into file "
+ tempModelFile2.getAbsolutePath() + " is not the same as the test Model for "
- + testApexModel2.getKey(), testApexModel2, generatedmodel);
+ + testApexModel2.getKey());
tempLogFile2.delete();
tempModelFile2.delete();
diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelTest.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelTest.java
index 2472cb466..38db6510a 100644
--- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelTest.java
+++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpModelTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2022 Nordix Foundation.
+ * Modifications Copyright (C) 2022, 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,10 +21,10 @@
package org.onap.policy.apex.examples.myfirstpolicy;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
@@ -34,17 +34,15 @@ import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
*
* @author John Keeney (john.keeney@ericsson.com)
*/
-public class MfpModelTest {
+class MfpModelTest {
private static TestApexModel<AxPolicyModel> testApexModel1;
private static TestApexModel<AxPolicyModel> testApexModel2;
/**
* Setup.
- *
- * @throws Exception if there is an error
*/
- @BeforeClass
- public static void setup() throws Exception {
+ @BeforeAll
+ static void setup() {
testApexModel1 = new TestApexModel<>(AxPolicyModel.class, new TestMfpModelCreator.TestMfp1ModelCreator());
testApexModel2 = new TestApexModel<>(AxPolicyModel.class, new TestMfpModelCreator.TestMfp2ModelCreator());
}
@@ -55,12 +53,12 @@ public class MfpModelTest {
* @throws Exception if there is an error
*/
@Test
- public void testModelValid() throws Exception {
+ void testModelValid() throws Exception {
AxValidationResult result = testApexModel1.testApexModelValid();
- assertTrue("Model did not validate cleanly", result.isOk());
+ assertTrue(result.isOk(), "Model did not validate cleanly");
result = testApexModel2.testApexModelValid();
- assertTrue("Model did not validate cleanly", result.isOk());
+ assertTrue(result.isOk(), "Model did not validate cleanly");
}
/**
@@ -69,7 +67,7 @@ public class MfpModelTest {
* @throws Exception if there is an error
*/
@Test
- public void testModelWriteReadJson() throws Exception {
+ void testModelWriteReadJson() throws Exception {
testApexModel1.testApexModelWriteReadJson();
testApexModel2.testApexModelWriteReadJson();
}
diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java
index 8afe7d7cd..654823f15 100644
--- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java
+++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/MfpUseCaseTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 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,19 +21,18 @@
package org.onap.policy.apex.examples.myfirstpolicy;
-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.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
-import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.ContextParameters;
@@ -55,7 +54,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
/**
* Test MyFirstPolicy Use Case.
*/
-public class MfpUseCaseTest {
+class MfpUseCaseTest {
// CHECKSTYLE:OFF: MagicNumber
private static ApexEngineImpl apexEngine;
@@ -63,8 +62,8 @@ public class MfpUseCaseTest {
/**
* Test MFP use case setup.
*/
- @BeforeClass
- public static void testMfpUseCaseSetup() {
+ @BeforeAll
+ static void testMfpUseCaseSetup() {
final AxArtifactKey key = new AxArtifactKey("MyFirstPolicyApexEngine", "0.0.1");
apexEngine = (ApexEngineImpl) new ApexEngineFactory().createApexEngine(key);
}
@@ -76,8 +75,8 @@ public class MfpUseCaseTest {
/**
* Before test.
*/
- @BeforeClass
- public static void beforeTest() {
+ @BeforeAll
+ static void beforeTest() {
schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
@@ -106,8 +105,8 @@ public class MfpUseCaseTest {
/**
* After test.
*/
- @AfterClass
- public static void afterTest() {
+ @AfterAll
+ static void afterTest() {
ParameterService.deregister(engineParameters);
ParameterService.deregister(contextParameters.getDistributorParameters());
@@ -122,11 +121,9 @@ public class MfpUseCaseTest {
* Test MyFirstPolicy#1 use case.
*
* @throws ApexException if there is an Apex error
- * @throws InterruptedException if there is an Interruption.
- * @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testMfp1Case() throws ApexException, InterruptedException, IOException {
+ void testMfp1Case() throws ApexException {
final AxPolicyModel apexPolicyModel = new MfpDomainModelFactory().getMfp1PolicyModel();
assertNotNull(apexPolicyModel);
@@ -144,24 +141,22 @@ public class MfpUseCaseTest {
apexEngine.handleEvent(event);
EnEvent resultout = listener.getResult();
EnEvent resulexpected =
- fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_084106GMT.json");
+ fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_084106GMT.json");
assertEquals(resulexpected, resultout);
event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/1/EventIn_BoozeItem_201713GMT.json");
apexEngine.handleEvent(event);
resultout = listener.getResult();
resulexpected =
- fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_201713GMT.json");
- assertEquals(resulexpected, resultout);
- assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId());
+ fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_201713GMT.json");
+ assertHandledEventResult(resulexpected, resultout, event);
event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/1/EventIn_NonBoozeItem_101309GMT.json");
apexEngine.handleEvent(event);
resultout = listener.getResult();
resulexpected =
- fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_NonBoozeItem_101309GMT.json");
- assertEquals(resulexpected, resultout);
- assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId());
+ fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_NonBoozeItem_101309GMT.json");
+ assertHandledEventResult(resulexpected, resultout, event);
apexEngine.stop();
}
@@ -170,11 +165,9 @@ public class MfpUseCaseTest {
* Test MyFirstPolicy#1 use case.
*
* @throws ApexException if there is an Apex error
- * @throws InterruptedException if there is an Interruption.
- * @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testMfp1AltCase() throws ApexException, InterruptedException, IOException {
+ void testMfp1AltCase() throws ApexException {
final AxPolicyModel apexPolicyModel = new MfpDomainModelFactory().getMfp1AltPolicyModel();
assertNotNull(apexPolicyModel);
@@ -192,7 +185,7 @@ public class MfpUseCaseTest {
apexEngine.handleEvent(event);
EnEvent resultout = listener.getResult();
EnEvent resulexpected =
- fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_084106GMT.json");
+ fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_084106GMT.json");
resultout.put("message", "");
resulexpected.put("message", "");
assertEquals(resulexpected, resultout);
@@ -201,21 +194,19 @@ public class MfpUseCaseTest {
apexEngine.handleEvent(event);
resultout = listener.getResult();
resulexpected =
- fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_201713GMT.json");
+ fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_201713GMT.json");
resultout.put("message", "");
resulexpected.put("message", "");
- assertEquals(resulexpected, resultout);
- assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId());
+ assertHandledEventResult(resulexpected, resultout, event);
event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/1/EventIn_NonBoozeItem_101309GMT.json");
apexEngine.handleEvent(event);
resultout = listener.getResult();
resulexpected =
- fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_NonBoozeItem_101309GMT.json");
+ fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_NonBoozeItem_101309GMT.json");
resultout.put("message", "");
resulexpected.put("message", "");
- assertEquals(resulexpected, resultout);
- assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId());
+ assertHandledEventResult(resulexpected, resultout, event);
apexEngine.stop();
}
@@ -224,11 +215,9 @@ public class MfpUseCaseTest {
* Test MyFirstPolicy#2 use case.
*
* @throws ApexException if there is an Apex error
- * @throws InterruptedException if there is an Interruption.
- * @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testMfp2Case() throws ApexException, InterruptedException, IOException {
+ void testMfp2Case() throws ApexException {
final AxPolicyModel apexPolicyModel = new MfpDomainModelFactory().getMfp2PolicyModel();
assertNotNull(apexPolicyModel);
@@ -246,57 +235,56 @@ public class MfpUseCaseTest {
apexEngine.handleEvent(event);
EnEvent resultout = listener.getResult();
EnEvent resultexpected =
- fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_084106GMT.json");
- assertEquals(resultexpected, resultout);
- assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId());
+ fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_084106GMT.json");
+ assertHandledEventResult(resultexpected, resultout, event);
event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/1/EventIn_BoozeItem_201713GMT.json");
apexEngine.handleEvent(event);
resultout = listener.getResult();
resultexpected =
- fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_201713GMT.json");
- assertEquals(resultexpected, resultout);
- assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId());
+ fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_BoozeItem_201713GMT.json");
+ assertHandledEventResult(resultexpected, resultout, event);
event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/1/EventIn_NonBoozeItem_101309GMT.json");
apexEngine.handleEvent(event);
resultout = listener.getResult();
resultexpected =
- fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_NonBoozeItem_101309GMT.json");
- assertEquals(resultexpected, resultout);
- assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId());
+ fillResultEvent(axEventout, "examples/events/MyFirstPolicy/1/EventOut_NonBoozeItem_101309GMT.json");
+ assertHandledEventResult(resultexpected, resultout, event);
event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/2/EventIn_BoozeItem_101433CET_thurs.json");
apexEngine.handleEvent(event);
resultout = listener.getResult();
resultexpected =
- fillResultEvent(axEventout, "examples/events/MyFirstPolicy/2/EventOut_BoozeItem_101433CET_thurs.json");
- assertEquals(resultexpected, resultout);
- assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId());
+ fillResultEvent(axEventout, "examples/events/MyFirstPolicy/2/EventOut_BoozeItem_101433CET_thurs.json");
+ assertHandledEventResult(resultexpected, resultout, event);
event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/2/EventIn_BoozeItem_171937CET_sun.json");
apexEngine.handleEvent(event);
resultout = listener.getResult();
resultexpected =
- fillResultEvent(axEventout, "examples/events/MyFirstPolicy/2/EventOut_BoozeItem_171937CET_sun.json");
- assertEquals(resultexpected, resultout);
- assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId());
+ fillResultEvent(axEventout, "examples/events/MyFirstPolicy/2/EventOut_BoozeItem_171937CET_sun.json");
+ assertHandledEventResult(resultexpected, resultout, event);
event = fillTriggerEvent(axEventin, "examples/events/MyFirstPolicy/2/EventIn_NonBoozeItem_111309CET_mon.json");
apexEngine.handleEvent(event);
resultout = listener.getResult();
resultexpected =
- fillResultEvent(axEventout, "examples/events/MyFirstPolicy/2/EventOut_NonBoozeItem_111309CET_mon.json");
- assertEquals(resultexpected, resultout);
- assertEquals("ExecutionIDs are different", event.getExecutionId(), resultout.getExecutionId());
+ fillResultEvent(axEventout, "examples/events/MyFirstPolicy/2/EventOut_NonBoozeItem_111309CET_mon.json");
+ assertHandledEventResult(resultexpected, resultout, event);
apexEngine.stop();
}
+ private static void assertHandledEventResult(EnEvent resultexpected, EnEvent resultout, EnEvent event) {
+ assertEquals(resultexpected, resultout);
+ assertEquals(event.getExecutionId(), resultout.getExecutionId());
+ }
+
/**
* Fill trigger event for test.
*
- * @param event the event
+ * @param event the event
* @param inputFile the input file
* @return the filled event
*/
@@ -305,7 +293,7 @@ public class MfpUseCaseTest {
final GsonBuilder gb = new GsonBuilder();
gb.serializeNulls().enableComplexMapKeySerialization();
final JsonObject jsonObject =
- gb.create().fromJson(ResourceUtils.getResourceAsString(inputFile), JsonObject.class);
+ gb.create().fromJson(ResourceUtils.getResourceAsString(inputFile), JsonObject.class);
assertNotNull(jsonObject);
assertTrue(jsonObject.has("name"));
assertEquals(ret.getName(), jsonObject.get("name").getAsString());
@@ -319,16 +307,18 @@ public class MfpUseCaseTest {
if (reserved.contains(e.getKey())) {
continue;
}
- assertTrue("Event file " + inputFile + " has a field " + e.getKey() + " but this is not defined for "
- + event.getId(), (event.getParameterMap().containsKey(e.getKey())));
+ assertTrue((event.getParameterMap().containsKey(e.getKey())),
+ "Event file " + inputFile + " has a field " + e.getKey() + " but this is not defined for "
+ + event.getId());
if (jsonObject.get(e.getKey()).isJsonNull()) {
ret.put(e.getKey(), null);
}
}
for (final AxField field : event.getFields()) {
if (!field.getOptional()) {
- assertTrue("Event file " + inputFile + " is missing a mandatory field " + field.getKey().getLocalName()
- + " for " + event.getId(), jsonObject.has(field.getKey().getLocalName()));
+ assertTrue(jsonObject.has(field.getKey().getLocalName()),
+ "Event file " + inputFile + " is missing a mandatory field " + field.getKey().getLocalName()
+ + " for " + event.getId());
} else {
ret.put(field.getKey().getLocalName(), null);
}
@@ -363,7 +353,7 @@ public class MfpUseCaseTest {
/**
* Fill result event for test.
*
- * @param event the event
+ * @param event the event
* @param inputFile the input file
* @return the filled event
*/
@@ -372,7 +362,7 @@ public class MfpUseCaseTest {
final GsonBuilder gb = new GsonBuilder();
gb.serializeNulls().enableComplexMapKeySerialization();
final JsonObject jsonObject =
- gb.create().fromJson(ResourceUtils.getResourceAsString(inputFile), JsonObject.class);
+ gb.create().fromJson(ResourceUtils.getResourceAsString(inputFile), JsonObject.class);
assertNotNull(jsonObject);
assertTrue(jsonObject.has("name"));
assertEquals(ret.getName(), jsonObject.get("name").getAsString());
@@ -386,16 +376,18 @@ public class MfpUseCaseTest {
if (reserved.contains(e.getKey())) {
continue;
}
- assertTrue("Event file " + inputFile + " has a field " + e.getKey() + " but this is not defined for "
- + event.getId(), (event.getParameterMap().containsKey(e.getKey())));
+ assertTrue((event.getParameterMap().containsKey(e.getKey())),
+ "Event file " + inputFile + " has a field " + e.getKey() + " but this is not defined for "
+ + event.getId());
if (jsonObject.get(e.getKey()).isJsonNull()) {
ret.put(e.getKey(), null);
}
}
for (final AxField field : event.getFields()) {
if (!field.getOptional()) {
- assertTrue("Event file " + inputFile + " is missing a mandatory field " + field.getKey().getLocalName()
- + " for " + event.getId(), jsonObject.has(field.getKey().getLocalName()));
+ assertTrue(jsonObject.has(field.getKey().getLocalName()),
+ "Event file " + inputFile + " is missing a mandatory field " + field.getKey().getLocalName()
+ + " for " + event.getId());
} else {
ret.put(field.getKey().getLocalName(), null);
}
diff --git a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java
index 01c24d6de..14a75fa30 100644
--- a/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java
+++ b/examples/examples-myfirstpolicy/src/test/java/org/onap/policy/apex/examples/myfirstpolicy/TestSaleAuthListener.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -63,10 +63,10 @@ public class TestSaleAuthListener implements EnEventListener {
* {@inheritDoc}.
*/
@Override
- public void onEnEvent(final EnEvent saleauthEvent) {
- if (saleauthEvent != null) {
- System.out.println("SaleAuth event from engine:" + saleauthEvent.getName());
- resultEvents.add(saleauthEvent);
+ public void onEnEvent(final EnEvent saleAuthEvent) {
+ if (saleAuthEvent != null) {
+ System.out.println("SaleAuth event from engine:" + saleAuthEvent.getName());
+ resultEvents.add(saleAuthEvent);
}
}
}
diff --git a/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java b/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java
index 1f52e1115..a87bddaf0 100644
--- a/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java
+++ b/examples/examples-onap-bbs/src/test/java/org/onap/policy/apex/examples/bbs/WebClientTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 huawei. All rights reserved.
- * Modifications Copyright (C) 2019-2020, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 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.
@@ -21,7 +21,7 @@
package org.onap.policy.apex.examples.bbs;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -29,12 +29,11 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import javax.net.ssl.HttpsURLConnection;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
-// TODO javax libraries used here too. Ok, to keep? Liam's review ignored these.
-public class WebClientTest {
+class WebClientTest {
HttpsURLConnection mockedHttpsUrlConnection;
String sampleString = "Response Code :200";
@@ -44,8 +43,8 @@ public class WebClientTest {
*
* @throws IOException on I/O errors
*/
- @Before
- public void setupMockedRest() throws IOException {
+ @BeforeEach
+ void setupMockedRest() throws IOException {
mockedHttpsUrlConnection = mock(HttpsURLConnection.class);
InputStream inputStream = new ByteArrayInputStream(sampleString.getBytes());
when(mockedHttpsUrlConnection.getInputStream()).thenReturn(inputStream);
@@ -53,7 +52,7 @@ public class WebClientTest {
}
@Test
- public void testHttpsRequest() {
+ void testHttpsRequest() {
WebClient cl = new WebClient();
String result = cl
.httpRequest("https://some.random.url/data", "POST", null, "admin", "admin", "application/json");
@@ -61,7 +60,7 @@ public class WebClientTest {
}
@Test
- public void testHttpRequest() {
+ void testHttpRequest() {
WebClient cl = new WebClient();
String result = cl
.httpRequest("http://some.random.url/data", "GET", null, "admin", "admin", "application/json");
@@ -69,7 +68,7 @@ public class WebClientTest {
}
@Test
- public void testToPrettyString() {
+ void testToPrettyString() {
String xmlSample = "<input xmlns=\"org:onap:sdnc:northbound:generic-resource\">"
+ "<sdnc-request-header> <svc-action>update</svc-action> </sdnc-request-header></input>";
WebClient cl = new WebClient();
diff --git a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSim.java b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSim.java
index c20fd9294..f28791c8e 100644
--- a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSim.java
+++ b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSim.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019,2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 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.
@@ -39,7 +39,7 @@ public class OnapVCpeSim {
*/
public OnapVCpeSim(final String[] args) throws Exception {
server = HttpServletServerFactoryInstance.getServerFactory().build(
- "OnapVCpeSimEndpoint", false, args[0], Integer.valueOf(args[1]).intValue(), false, "/OnapVCpeSim", false,
+ "OnapVCpeSimEndpoint", false, args[0], Integer.parseInt(args[1]), false, "/OnapVCpeSim", false,
false);
server.addServletClass(null, OnapVCpeSimEndpoint.class.getName());
@@ -47,7 +47,7 @@ public class OnapVCpeSim {
server.start();
- if (!NetworkUtil.isTcpPortOpen(args[0], Integer.valueOf(args[1]).intValue(), 2000, 1L)) {
+ if (!NetworkUtil.isTcpPortOpen(args[0], Integer.parseInt(args[1]), 2000, 1L)) {
throw new IllegalStateException("port " + args[1] + " is still not in use");
}
}
diff --git a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSimEndpoint.java b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSimEndpoint.java
index 3e7962823..0af809a98 100644
--- a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSimEndpoint.java
+++ b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVCpeSimEndpoint.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020,2022-2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 2022-2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,8 +22,8 @@
package org.onap.policy.apex.domains.onap.vcpe;
-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 com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -67,7 +67,7 @@ public class OnapVCpeSimEndpoint {
private static final Random randomDelayInc = new Random();
private static final Gson gson = new GsonBuilder()
- .registerTypeAdapter(Instant.class, new InstantAsMillisTypeAdapter()).setPrettyPrinting().create();
+ .registerTypeAdapter(Instant.class, new InstantAsMillisTypeAdapter()).setPrettyPrinting().create();
private static final AtomicInteger nextVnfId = new AtomicInteger(0);
private static Boolean nextControlLoopMessageIsOnset = true;
@@ -82,7 +82,7 @@ public class OnapVCpeSimEndpoint {
public Response serviceGetStats() {
statMessagesReceived.incrementAndGet();
String returnString = "{\"GET\": " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived + ",\"POST\": "
- + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + "}";
+ + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + "}";
return Response.status(200).entity(prettifyJsonString(returnString)).build();
}
@@ -96,7 +96,7 @@ public class OnapVCpeSimEndpoint {
@Path("/pdp/api/getDecision")
@POST
public Response serviceGuardPostRequest(final String jsonString) {
- LOGGER.info("\n*** GUARD REQUEST START ***\n" + jsonString + "\n *** GUARD REQUEST END ***");
+ LOGGER.info("\n*** GUARD REQUEST START ***\n{}\n *** GUARD REQUEST END ***", jsonString);
String target = jsonString.substring(jsonString.indexOf("00000000"));
target = target.substring(0, target.indexOf('"'));
@@ -104,7 +104,7 @@ public class OnapVCpeSimEndpoint {
int thisGuardMessageNumber = guardMessagesReceived.incrementAndGet();
postMessagesReceived.incrementAndGet();
- String responseJsonString = null;
+ String responseJsonString;
if (thisGuardMessageNumber % 2 == 0) {
responseJsonString = "{\"decision\": \"PERMIT\", \"details\": \"Decision Permit. OK!\"}";
} else {
@@ -113,8 +113,7 @@ public class OnapVCpeSimEndpoint {
responseJsonString = prettifyJsonString(responseJsonString);
- LOGGER.info("\n*** GUARD RESPONSE START ***\n" + target + "\n" + responseJsonString
- + "\n*** GUARD RESPONSE END ***");
+ LOGGER.info("\n*** GUARD RESPONSE START ***\n{}\n{}\n*** GUARD RESPONSE END ***", target, responseJsonString);
return Response.status(200).entity(responseJsonString).build();
}
@@ -124,29 +123,29 @@ public class OnapVCpeSimEndpoint {
* http://localhost:54321/aai/v16/search/nodes-query?search-node-type=vserver&filter=vserver-name:EQUALS:
*
* @param searchNodeType the node type to search for
- * @param filter the filter to apply in the search
+ * @param filter the filter to apply in the search
* @return the response
* @throws IOException on I/O errors
*/
@Path("aai/v16/search/nodes-query")
@GET
public Response aaiNamedQuerySearchRequest(@QueryParam("search-node-type") final String searchNodeType,
- @QueryParam("filter") final String filter) throws IOException {
+ @QueryParam("filter") final String filter) throws IOException {
getMessagesReceived.incrementAndGet();
- LOGGER.info("\n*** AAI NODE QUERY GET START ***\nsearchNodeType=" + searchNodeType + "\nfilter=" + filter
- + "\n *** AAI REQUEST END ***");
+ LOGGER.info("\n*** AAI NODE QUERY GET START ***\nsearchNodeType={}\nfilter={}\n *** AAI REQUEST END ***",
+ searchNodeType, filter);
String adjustedVserverUuid =
- "b4fe00ac-1da6-4b00-ac0d-8e8300db" + String.format("%04d", nextVnfId.getAndIncrement());
+ "b4fe00ac-1da6-4b00-ac0d-8e8300db" + String.format("%04d", nextVnfId.getAndIncrement());
String responseJsonString =
- TextFileUtils.getTextFileAsString("src/test/resources/aai/SearchNodeTypeResponse.json")
- .replaceAll("b4fe00ac-1da6-4b00-ac0d-8e8300db0007", adjustedVserverUuid);
+ TextFileUtils.getTextFileAsString("src/test/resources/aai/SearchNodeTypeResponse.json")
+ .replaceAll("b4fe00ac-1da6-4b00-ac0d-8e8300db0007", adjustedVserverUuid);
responseJsonString = prettifyJsonString(responseJsonString);
- LOGGER.info("\n*** AAI RESPONSE START ***\n" + responseJsonString + "\n *** AAI RESPONSE END ***");
+ LOGGER.info("\n*** AAI RESPONSE START ***\n{}\n *** AAI RESPONSE END ***", responseJsonString);
return Response.status(200).entity(responseJsonString).build();
}
@@ -155,7 +154,7 @@ public class OnapVCpeSimEndpoint {
* AAI named query request on a particular resource.
* http://localhost:54321/OnapVCpeSim/sim/aai/v16/query?format=resource
*
- * @param format the format of the request
+ * @param format the format of the request
* @param jsonString the body of the request
* @return the response
* @throws IOException on I/O errors
@@ -163,22 +162,22 @@ public class OnapVCpeSimEndpoint {
@Path("aai/v16/query")
@PUT
public Response aaiNamedQueryResourceRequest(@QueryParam("format") final String format, final String jsonString)
- throws IOException {
+ throws IOException {
putMessagesReceived.incrementAndGet();
- LOGGER.info("\n*** AAI NODE RESOURE POST QUERY START ***\\nformat=" + format + "\njson=" + jsonString
- + "\n *** AAI REQUEST END ***");
+ LOGGER.info("\n*** AAI NODE RESOURCE POST QUERY START ***\\nformat={}\njson={}\n *** AAI REQUEST END ***",
+ format, jsonString);
int beginIndex =
- jsonString.indexOf("b4fe00ac-1da6-4b00-ac0d-8e8300db") + "b4fe00ac-1da6-4b00-ac0d-8e8300db".length();
+ jsonString.indexOf("b4fe00ac-1da6-4b00-ac0d-8e8300db") + "b4fe00ac-1da6-4b00-ac0d-8e8300db".length();
String nextVnfIdUrlEnding = jsonString.substring(beginIndex, beginIndex + 4);
String responseJsonString = TextFileUtils.getTextFileAsString("src/test/resources/aai/NodeQueryResponse.json")
- .replaceAll("bbb3cefd-01c8-413c-9bdd-2b92f9ca3d38",
- "00000000-0000-0000-0000-00000000" + nextVnfIdUrlEnding);
+ .replaceAll("bbb3cefd-01c8-413c-9bdd-2b92f9ca3d38",
+ "00000000-0000-0000-0000-00000000" + nextVnfIdUrlEnding);
responseJsonString = prettifyJsonString(responseJsonString);
- LOGGER.info("\n*** AAI RESPONSE START ***\n" + responseJsonString + "\n *** AAI RESPONSE END ***");
+ LOGGER.info("\n*** AAI RESPONSE START ***\n{}\n *** AAI RESPONSE END ***", responseJsonString);
return Response.status(200).entity(responseJsonString).build();
}
@@ -201,16 +200,16 @@ public class OnapVCpeSimEndpoint {
nextControlLoopMessageIsOnset = false;
String clOnsetEvent = TextFileUtils
- .getTextFileAsString("src/main/resources/examples/events/ONAPvCPEStandalone/CLOnsetEvent.json");
- LOGGER.info("\n*** CONTROL LOOP ONSET START ***\n" + clOnsetEvent + "\n *** CONTROL LOOP ONSET END ***");
+ .getTextFileAsString("src/main/resources/examples/events/ONAPvCPEStandalone/CLOnsetEvent.json");
+ LOGGER.info("\n*** CONTROL LOOP ONSET START ***\n{}\n *** CONTROL LOOP ONSET END ***", clOnsetEvent);
return Response.status(200).entity(clOnsetEvent).build();
} else {
nextControlLoopMessageIsOnset = true;
String clAbatedEvent = TextFileUtils
- .getTextFileAsString("src/main/resources/examples/events/ONAPvCPEStandalone/CLAbatedEvent.json");
- LOGGER.info("\n*** CONTROL LOOP ABATED START ***\n" + clAbatedEvent + "\n *** CONTROL LOOP ABATED END ***");
+ .getTextFileAsString("src/main/resources/examples/events/ONAPvCPEStandalone/CLAbatedEvent.json");
+ LOGGER.info("\n*** CONTROL LOOP ABATED START ***\n{}\n *** CONTROL LOOP ABATED END ***", clAbatedEvent);
return Response.status(200).entity(clAbatedEvent).build();
}
@@ -258,7 +257,7 @@ public class OnapVCpeSimEndpoint {
String logJsonString = prettifyJsonString(jsonString);
- LOGGER.info("\n*** POLICY LOG ENTRY START ***\n" + logJsonString + "\n *** POLICY LOG ENTRY END ***");
+ LOGGER.info("\n*** POLICY LOG ENTRY START ***\n{}\n *** POLICY LOG ENTRY END ***", logJsonString);
return Response.status(200).build();
}
@@ -276,7 +275,7 @@ public class OnapVCpeSimEndpoint {
String appcJsonString = prettifyJsonString(jsonString);
- LOGGER.info("\n*** CONTROLLER REQUEST START ***\n" + appcJsonString + "\n *** CONTROLLER REQUEST END ***");
+ LOGGER.info("\n*** CONTROLLER REQUEST START ***\n{}\n *** CONTROLLER REQUEST END ***", appcJsonString);
new AppcResponseCreator(appcResponseQueue, appcJsonString, 10000 + randomDelayInc.nextInt(10000));
@@ -296,7 +295,7 @@ public class OnapVCpeSimEndpoint {
String bwJsonString = prettifyJsonString(jsonString);
- LOGGER.info("\n*** BLACK WHITE LIST START ***\n" + bwJsonString + "\n *** BLACK WHITE LIST END ***");
+ LOGGER.info("\n*** BLACK WHITE LIST START ***\n{}\n *** BLACK WHITE LIST END ***", bwJsonString);
return Response.status(200).build();
}
@@ -314,10 +313,10 @@ public class OnapVCpeSimEndpoint {
final String nextEventName = "Event0" + rand.nextInt(2) + "00";
final String eventString = "{\n" + "\"nameSpace\": \"org.onap.policy.apex.sample.events\",\n" + "\"name\": \""
- + nextEventName + "\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_" + getMessagesReceived
- + "\",\n" + "\"target\": \"apex\",\n" + "\"TestSlogan\": \"Test slogan for External Event0\",\n"
- + "\"TestMatchCase\": " + nextMatchCase + ",\n" + "\"TestTimestamp\": " + System.currentTimeMillis()
- + ",\n" + "\"TestTemperature\": 9080.866\n" + "}";
+ + nextEventName + "\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_" + getMessagesReceived
+ + "\",\n" + "\"target\": \"apex\",\n" + "\"TestSlogan\": \"Test slogan for External Event0\",\n"
+ + "\"TestMatchCase\": " + nextMatchCase + ",\n" + "\"TestTimestamp\": " + System.currentTimeMillis()
+ + ",\n" + "\"TestTemperature\": 9080.866\n" + "}";
getMessagesReceived.incrementAndGet();
@@ -357,8 +356,7 @@ public class OnapVCpeSimEndpoint {
public Response servicePostRequest(final String jsonString) {
postMessagesReceived.incrementAndGet();
- @SuppressWarnings("unchecked")
- final Map<String, Object> jsonMap = gson.fromJson(jsonString, Map.class);
+ @SuppressWarnings("unchecked") final Map<String, Object> jsonMap = gson.fromJson(jsonString, Map.class);
assertTrue(jsonMap.containsKey("name"));
assertEquals("0.0.1", jsonMap.get("version"));
assertEquals("org.onap.policy.apex.sample.events", jsonMap.get("nameSpace"));
@@ -366,7 +364,7 @@ public class OnapVCpeSimEndpoint {
assertEquals("Outside", jsonMap.get("target"));
return Response.status(200).entity("{\"GET\": , " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived
- + ",\"POST\": , " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + "}").build();
+ + ",\"POST\": , " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + "}").build();
}
/**
@@ -392,8 +390,7 @@ public class OnapVCpeSimEndpoint {
public Response servicePutRequest(final String jsonString) {
putMessagesReceived.incrementAndGet();
- @SuppressWarnings("unchecked")
- final Map<String, Object> jsonMap = gson.fromJson(jsonString, Map.class);
+ @SuppressWarnings("unchecked") final Map<String, Object> jsonMap = gson.fromJson(jsonString, Map.class);
assertTrue(jsonMap.containsKey("name"));
assertEquals("0.0.1", jsonMap.get("version"));
assertEquals("org.onap.policy.apex.sample.events", jsonMap.get("nameSpace"));
@@ -401,10 +398,10 @@ public class OnapVCpeSimEndpoint {
assertEquals("Outside", jsonMap.get("target"));
return Response.status(200).entity("{\"GET\": , " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived
- + ",\"POST\": , " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + "}").build();
+ + ",\"POST\": , " + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + "}").build();
}
- private static final String prettifyJsonString(final String uglyJsonString) {
+ private static String prettifyJsonString(final String uglyJsonString) {
JsonElement je = JsonParser.parseString(uglyJsonString);
return gson.toJson(je);
}
diff --git a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeRunner.java b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeRunner.java
index 2c2cf5204..227467a79 100644
--- a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeRunner.java
+++ b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeRunner.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 2020, 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.
@@ -65,7 +65,7 @@ public class OnapVcpeRunner {
final ApexMain apexMain = new ApexMain(apexArgs);
- await().atMost(5000, TimeUnit.MILLISECONDS).until(() -> apexMain.isAlive());
+ await().atMost(5000, TimeUnit.MILLISECONDS).until(apexMain::isAlive);
// This test should be amended to start and shutdown the simulator as part of the test and not separately as
// is done in the gRPC test.
diff --git a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeStandaloneRunner.java b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeStandaloneRunner.java
index 61c2df700..9e4bece2d 100644
--- a/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeStandaloneRunner.java
+++ b/examples/examples-onap-vcpe/src/test/java/org/onap/policy/apex/domains/onap/vcpe/OnapVcpeStandaloneRunner.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
+ * Copyright (C) 2020, 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.
@@ -58,7 +58,7 @@ public class OnapVcpeStandaloneRunner {
// @formatter:on
final ApexMain apexMain = new ApexMain(apexArgs);
- await().atMost(5000, TimeUnit.MILLISECONDS).until(() -> apexMain.isAlive());
+ await().atMost(5000, TimeUnit.MILLISECONDS).until(apexMain::isAlive);
// This test should be amended to start and shutdown the simulator as part of the test and not separately as
// is done in the gRPC test.