summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java109
-rw-r--r--auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/DummyStErrorListener.java24
-rw-r--r--auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTest.java56
-rw-r--r--auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportKeyInfoGetter.java5
-rw-r--r--auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java12
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java56
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorEventsContextTest.java60
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java68
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java28
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.java33
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.java33
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.java42
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java56
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java44
-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
-rw-r--r--plugins/plugins-context/plugins-context-persistence/pom.xml34
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaAaiTest.java33
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaArrayTest.java44
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaEnumTest.java36
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaFixedTest.java43
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperBadSchemasTest.java35
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperMarshalTest.java71
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperUnmarshalTest.java71
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaMapTest.java94
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaRecordTest.java60
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/HealthCheckSchemaTest.java41
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/src/test/java/org/onap/policy/apex/plugins/context/schema/json/CommonTestData.java13
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/src/test/java/org/onap/policy/apex/plugins/context/schema/json/JsonSchemaHelperMarshalTest.java19
-rw-r--r--plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/src/test/java/org/onap/policy/apex/plugins/context/schema/json/JsonSchemaHelperUnmarshalTest.java32
-rw-r--r--plugins/plugins-context/pom.xml2
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumerTest.java61
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducerTest.java46
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java32
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java102
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java16
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java77
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java67
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java37
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java421
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumerTest.java (renamed from plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java)54
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java83
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java53
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestTest.java12
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java46
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java48
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java59
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java63
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/SupportRestRequestorEndpoint.java20
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/AccessControlFilterTest.java20
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumerTest.java110
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducerTest.java74
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java29
-rw-r--r--plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java2
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/pom.xml16
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverterTest.java57
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverterTest.java38
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/JmsObjectEventProtocolParametersTest.java14
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java26
-rw-r--r--plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java97
-rw-r--r--plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaExecutorParametersTest.java21
-rw-r--r--plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutorTest.java27
-rw-r--r--plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutorTest.java25
-rw-r--r--plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutorTest.java31
-rw-r--r--plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorFullApexTest.java26
-rw-r--r--plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorParametersTest.java16
-rw-r--r--plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorTest.java14
-rw-r--r--plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java49
-rw-r--r--plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java54
-rw-r--r--plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java31
-rw-r--r--plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyExecutorParametersTest.java16
-rw-r--r--plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyStateFinalizerExecutorTest.java34
-rw-r--r--plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutorTest.java34
-rw-r--r--plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskSelectExecutorTest.java34
-rw-r--r--plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelExecutorParametersTest.java16
-rw-r--r--plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutorTest.java35
-rw-r--r--plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutorTest.java25
-rw-r--r--plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutorTest.java25
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java38
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParameters.java4
-rw-r--r--tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/KeyInfoGetterTest.java31
-rw-r--r--tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/SchemaUtilsTest.java40
-rw-r--r--tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2CliTest.java32
-rw-r--r--tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2event/Model2EventSchemaTest.java43
-rw-r--r--tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2event/Model2EventTest.java50
-rw-r--r--tools/simple-wsclient/src/test/java/org/onap/policy/apex/tools/simple/wsclient/WsClientTest.java35
-rw-r--r--tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/CliParserTest.java18
-rw-r--r--tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/ConsoleTest.java35
-rw-r--r--tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/OutputFileTest.java35
-rw-r--r--tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleAppVersionTest.java18
-rw-r--r--tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleCliParserTest.java18
109 files changed, 2317 insertions, 2361 deletions
diff --git a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java
index f0cb1d879..1b44f66e7 100644
--- a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java
+++ b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd.
- * Modifications Copyright (C) 2020,2022 Nordix Foundation
+ * Modifications Copyright (C) 2020, 2022, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -24,7 +24,7 @@
package org.onap.policy.apex.auth.clicodegen;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.File;
import java.io.FileInputStream;
@@ -36,7 +36,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
@@ -60,13 +60,13 @@ import org.stringtemplate.v4.ST;
/**
* Test CLI code generation.
*/
-public class CodeGeneratorCliEditorTest {
+class CodeGeneratorCliEditorTest {
private SupportKeyInfoGetter kig;
private File outFile = null;
@Test
- public void test() throws IOException, ApexModelException {
+ void test() throws IOException, ApexModelException {
final CodeGeneratorCliEditor codeGen = new CodeGeneratorCliEditor();
outFile = File.createTempFile("ApexTestGenerated", ".apex");
@@ -76,8 +76,7 @@ public class CodeGeneratorCliEditorTest {
modelReader.setValidate(false);
AxPolicyModel apexPolicyModel = null;
- apexPolicyModel = modelReader
- .read(new FileInputStream(new File("src/test/resources/models/TestPolicyModel.json")));
+ apexPolicyModel = modelReader.read(new FileInputStream("src/test/resources/models/TestPolicyModel.json"));
assertEquals(0, generateCli(codeGen, apexPolicyModel));
}
@@ -85,9 +84,9 @@ public class CodeGeneratorCliEditorTest {
/**
* Generate the CLI from the model.
*
- * @param codeGen the code generator
+ * @param codeGen the code generator
* @param policyModel the policy model
- * @throws IOException on generation exceptions
+ * @throws IOException on generation exceptions
*/
private int generateCli(final CodeGeneratorCliEditor codeGen, final AxPolicyModel policyModel) throws IOException {
kig = new SupportKeyInfoGetter(policyModel);
@@ -102,7 +101,7 @@ public class CodeGeneratorCliEditorTest {
final AxArtifactKey key = s.getKey();
codeGen.addSchemaDeclaration(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key),
- s.getSchemaFlavour(), s.getSchema());
+ s.getSchemaFlavour(), s.getSchema());
}
// 2: tasks
@@ -123,16 +122,16 @@ public class CodeGeneratorCliEditorTest {
final List<ST> fields = getParametersForEvent(codeGen, e);
codeGen.addEventDeclaration(
- EventDeclaration.builder()
- .name(kig.getName(key))
- .version(kig.getVersion(key))
- .uuid(kig.getUuid(key))
- .description(kig.getDesc(key))
- .nameSpace(e.getNameSpace())
- .source(e.getSource())
- .target(e.getTarget())
- .fields(fields)
- .build());
+ EventDeclaration.builder()
+ .name(kig.getName(key))
+ .version(kig.getVersion(key))
+ .uuid(kig.getUuid(key))
+ .description(kig.getDesc(key))
+ .nameSpace(e.getNameSpace())
+ .source(e.getSource())
+ .target(e.getTarget())
+ .fields(fields)
+ .build());
}
// 4: context albums
@@ -140,16 +139,16 @@ public class CodeGeneratorCliEditorTest {
final AxArtifactKey key = a.getKey();
codeGen.addContextAlbumDeclaration(
- CodeGenCliEditor.builder()
- .name(kig.getName(key))
- .version(kig.getVersion(key))
- .uuid(kig.getUuid(key))
- .description(kig.getDesc(key))
- .scope(a.getScope())
- .writable(a.isWritable())
- .schemaName(kig.getName(a.getItemSchema()))
- .schemaVersion(kig.getVersion(a.getItemSchema()))
- .build());
+ CodeGenCliEditor.builder()
+ .name(kig.getName(key))
+ .version(kig.getVersion(key))
+ .uuid(kig.getUuid(key))
+ .description(kig.getDesc(key))
+ .scope(a.getScope())
+ .writable(a.isWritable())
+ .schemaName(kig.getName(a.getItemSchema()))
+ .schemaVersion(kig.getVersion(a.getItemSchema()))
+ .build());
}
// 5: policies
@@ -157,7 +156,7 @@ public class CodeGeneratorCliEditorTest {
final AxArtifactKey key = p.getKey();
final List<ST> states = getStatesForPolicy(codeGen, p);
codeGen.addPolicyDefinition(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key),
- p.getTemplate(), p.getFirstState(), states);
+ p.getTemplate(), p.getFirstState(), states);
}
final String out = codeGen.getModel().render();
@@ -172,7 +171,7 @@ public class CodeGeneratorCliEditorTest {
/**
* Gets the parameters for event.
*
- * @param cg the code generator
+ * @param cg the code generator
* @param event the event
* @return the parameters for event
*/
@@ -183,7 +182,7 @@ public class CodeGeneratorCliEditorTest {
final AxReferenceKey fkey = f.getKey();
final ST val = cg.createEventFieldDefinition(kig.getPName(fkey), kig.getPVersion(fkey), kig.getLName(fkey),
- kig.getName(f.getSchema()), kig.getVersion(f.getSchema()), f.getOptional());
+ kig.getName(f.getSchema()), kig.getVersion(f.getSchema()), f.getOptional());
ret.add(val);
}
@@ -193,7 +192,7 @@ public class CodeGeneratorCliEditorTest {
/**
* Gets the context references for task.
*
- * @param cg the code generator
+ * @param cg the code generator
* @param task the task
* @return the context references for task
*/
@@ -204,7 +203,7 @@ public class CodeGeneratorCliEditorTest {
for (final AxArtifactKey ckey : ctxs) {
final ST val = cg.createTaskDefinitionContextRef(kig.getName(tkey), kig.getVersion(tkey), kig.getName(ckey),
- kig.getVersion(ckey));
+ kig.getVersion(ckey));
ret.add(val);
}
@@ -214,7 +213,7 @@ public class CodeGeneratorCliEditorTest {
/**
* Gets the parameters for task.
*
- * @param cg the code generator
+ * @param cg the code generator
* @param task the task
* @return the parameters for task
*/
@@ -225,7 +224,7 @@ public class CodeGeneratorCliEditorTest {
final AxReferenceKey pkey = p.getKey();
final ST val = cg.createTaskDefinitionParameters(kig.getPName(pkey), kig.getPVersion(pkey),
- kig.getLName(pkey), p.getTaskParameterValue());
+ kig.getLName(pkey), p.getTaskParameterValue());
ret.add(val);
}
@@ -235,7 +234,7 @@ public class CodeGeneratorCliEditorTest {
/**
* Gets the logic for task.
*
- * @param cg the code generator
+ * @param cg the code generator
* @param task the task
* @return the logic for task
*/
@@ -249,7 +248,7 @@ public class CodeGeneratorCliEditorTest {
/**
* Gets the states for policy.
*
- * @param cg the code generator
+ * @param cg the code generator
* @param pol the policy
* @return the states for policy
*/
@@ -265,13 +264,13 @@ public class CodeGeneratorCliEditorTest {
final List<ST> ctxRefs = getCtxtRefsForState(cg, st);
final ST val = cg.createPolicyStateDef(PolicyStateDef.builder()
- .policyName(kig.getPName(skey)).version(kig.getPVersion(skey))
- .stateName(kig.getLName(skey)).triggerName(kig.getName(st.getTrigger()))
- .triggerVersion(kig.getVersion(st.getTrigger()))
- .defaultTask(kig.getName(st.getDefaultTask()))
- .defaultTaskVersion(kig.getVersion(st.getDefaultTask())).outputs(outputs)
- .tasks(tasks).tsLogic(tsLogic).finalizerLogics(finalizerLogics)
- .ctxRefs(ctxRefs).build());
+ .policyName(kig.getPName(skey)).version(kig.getPVersion(skey))
+ .stateName(kig.getLName(skey)).triggerName(kig.getName(st.getTrigger()))
+ .triggerVersion(kig.getVersion(st.getTrigger()))
+ .defaultTask(kig.getName(st.getDefaultTask()))
+ .defaultTaskVersion(kig.getVersion(st.getDefaultTask())).outputs(outputs)
+ .tasks(tasks).tsLogic(tsLogic).finalizerLogics(finalizerLogics)
+ .ctxRefs(ctxRefs).build());
ret.add(val);
}
@@ -293,7 +292,7 @@ public class CodeGeneratorCliEditorTest {
final AxReferenceKey finkey = fin.getKey();
final ST val = cg.createPolicyStateDefFinalizerLogic(kig.getPName(skey), kig.getPVersion(skey),
- kig.getLName(skey), kig.getLName(finkey), fin.getLogicFlavour(), fin.getLogic());
+ kig.getLName(skey), kig.getLName(finkey), fin.getLogicFlavour(), fin.getLogic());
ret.add(val);
}
@@ -314,7 +313,7 @@ public class CodeGeneratorCliEditorTest {
for (final AxArtifactKey ctx : ctxs) {
final ST val = cg.createPolicyStateDefContextRef(kig.getPName(skey), kig.getPVersion(skey),
- kig.getLName(skey), kig.getName(ctx), kig.getVersion(ctx));
+ kig.getLName(skey), kig.getName(ctx), kig.getVersion(ctx));
ret.add(val);
}
@@ -333,7 +332,7 @@ public class CodeGeneratorCliEditorTest {
if (st.checkSetTaskSelectionLogic()) {
final AxTaskSelectionLogic tsl = st.getTaskSelectionLogic();
final ST val = cg.createPolicyStateDefTaskSelLogic(kig.getPName(skey), kig.getPVersion(skey),
- kig.getLName(skey), tsl.getLogicFlavour(), tsl.getLogic());
+ kig.getLName(skey), tsl.getLogicFlavour(), tsl.getLogic());
return Collections.singletonList(val);
} else {
return Collections.emptyList();
@@ -357,12 +356,12 @@ public class CodeGeneratorCliEditorTest {
final AxReferenceKey trkey = tr.getKey();
final ST val = cg.createPolicyStateTask(PolicyStateTask.builder()
- .policyName(kig.getPName(skey)).version(kig.getPVersion(skey))
- .stateName(kig.getLName(skey)).taskLocalName(kig.getLName(trkey))
- .taskName(kig.getName(tkey)).taskVersion(kig.getVersion(tkey))
- .outputType(tr.getStateTaskOutputType().name())
- .outputName(kig.getLName(tr.getOutput()))
- .build());
+ .policyName(kig.getPName(skey)).version(kig.getPVersion(skey))
+ .stateName(kig.getLName(skey)).taskLocalName(kig.getLName(trkey))
+ .taskName(kig.getName(tkey)).taskVersion(kig.getVersion(tkey))
+ .outputType(tr.getStateTaskOutputType().name())
+ .outputName(kig.getLName(tr.getOutput()))
+ .build());
ret.add(val);
}
diff --git a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/DummyStErrorListener.java b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/DummyStErrorListener.java
index 572b40e74..be3ec8642 100644
--- a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/DummyStErrorListener.java
+++ b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/DummyStErrorListener.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,7 +35,9 @@ import org.stringtemplate.v4.misc.STMessage;
*/
public class DummyStErrorListener implements STErrorListener {
- /** Counts errors of the listener. */
+ /**
+ * Counts errors of the listener.
+ */
@Getter(AccessLevel.PROTECTED)
@Setter(AccessLevel.PROTECTED)
private int errorCount;
@@ -44,10 +47,7 @@ public class DummyStErrorListener implements STErrorListener {
*/
@Override
public void IOError(final STMessage msg) {
- switch (msg.error) {
- default:
- this.registerErrors(msg);
- }
+ this.registerErrors(msg);
}
/**
@@ -55,10 +55,7 @@ public class DummyStErrorListener implements STErrorListener {
*/
@Override
public void compileTimeError(final STMessage msg) {
- switch (msg.error) {
- default:
- this.registerErrors(msg);
- }
+ this.registerErrors(msg);
}
/**
@@ -66,10 +63,7 @@ public class DummyStErrorListener implements STErrorListener {
*/
@Override
public void internalError(final STMessage msg) {
- switch (msg.error) {
- default:
- this.registerErrors(msg);
- }
+ this.registerErrors(msg);
}
/**
@@ -78,9 +72,7 @@ public class DummyStErrorListener implements STErrorListener {
@Override
public void runTimeError(final STMessage msg) {
switch (msg.error) {
- case NO_SUCH_PROPERTY:
- case ARGUMENT_COUNT_MISMATCH:
- case ANON_ARGUMENT_MISMATCH:
+ case NO_SUCH_PROPERTY, ARGUMENT_COUNT_MISMATCH, ANON_ARGUMENT_MISMATCH:
break;
default:
this.registerErrors(msg);
diff --git a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTest.java b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTest.java
index e6c43692f..e45a44296 100644
--- a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTest.java
+++ b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2021-2022 Nordix Foundation
+ * Modifications Copyright (C) 2021-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,7 +21,7 @@
package org.onap.policy.apex.auth.clicodegen;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import java.util.LinkedHashMap;
@@ -29,7 +29,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.stringtemplate.v4.STGroup;
import org.stringtemplate.v4.STGroupFile;
@@ -38,7 +38,7 @@ import org.stringtemplate.v4.STGroupFile;
*
* @author Sven van der Meer (sven.van.der.meer@ericsson.com)
*/
-public class SupportGenerationTest {
+class SupportGenerationTest {
/**
* Get the chunks for the codegen.
@@ -51,44 +51,46 @@ public class SupportGenerationTest {
final Map<String, List<String>> chunks = new LinkedHashMap<>();
chunks.put("/policyModel",
- Arrays.asList("name", "version", "uuid", "description", "declarations", "definitions"));
+ Arrays.asList("name", "version", "uuid", "description", "declarations", "definitions"));
chunks.put("/schemaDecl", Arrays.asList("name", "version", "uuid", "description", "flavour", "schema"));
chunks.put("/ctxAlbumDecl", Arrays.asList("name", "version", "uuid", "description", "scope", "writable",
- "schemaName", "schemaVersion"));
+ "schemaName", "schemaVersion"));
chunks.put("/eventDecl",
- Arrays.asList("name", "version", "uuid", "description", "nameSpace", "source", "target", "fields"));
+ Arrays.asList("name", "version", "uuid", "description", "nameSpace", "source", "target", "fields"));
chunks.put("/eventDefField",
- Arrays.asList("eventName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion", "optional"));
+ Arrays.asList("eventName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion", "optional"));
chunks.put("/taskDecl",
- Arrays.asList("name", "version", "uuid", "description", "infields", "outfields", "logic"));
+ Arrays.asList("name", "version", "uuid", "description", "infields", "outfields", "logic"));
chunks.put("/taskDefInputFields",
- Arrays.asList("taskName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion"));
+ Arrays.asList("taskName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion"));
chunks.put("/taskDefOutputFields",
- Arrays.asList("taskName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion"));
+ Arrays.asList("taskName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion"));
chunks.put("/taskDefLogic", Arrays.asList("taskName", "version", "flavour", "logic"));
chunks.put("/taskDefParameter", Arrays.asList("name", "version", "parName", "defaultValue"));
chunks.put("/taskDefCtxRef", Arrays.asList("name", "version", "albumName", "albumVersion"));
chunks.put("/policyDef", Arrays.asList("name", "version", "uuid", "description", "template", "firstState"));
chunks.put("/policyStateDef", Arrays.asList("policyName", "version", "stateName", "triggerName",
- "triggerVersion", "defaultTask", "defaultTaskVersion", "outputs", "tasks"));
+ "triggerVersion", "defaultTask", "defaultTaskVersion", "outputs", "tasks"));
chunks.put("/policyStateOutput", Arrays.asList("policyName", "version", "stateName", "outputName", "eventName",
- "eventVersion", "nextState"));
+ "eventVersion", "nextState"));
chunks.put("/policyStateTaskSelectionLogic",
- Arrays.asList("name", "version", "stateName", "logicFlavour", "logic"));
+ Arrays.asList("name", "version", "stateName", "logicFlavour", "logic"));
chunks.put("/policyStateTask", Arrays.asList("policyName", "version", "stateName", "taskLocalName", "taskName",
- "taskVersion", "outputType", "outputName"));
+ "taskVersion", "outputType", "outputName"));
chunks.put("/policyStateFinalizerLogic",
- Arrays.asList("name", "version", "stateName", "finalizerLogicName", "logicFlavour", "logic"));
+ Arrays.asList("name", "version", "stateName", "finalizerLogicName", "logicFlavour", "logic"));
chunks.put("/policyStateContextRef",
- Arrays.asList("name", "version", "stateName", "albumName", "albumVersion"));
+ Arrays.asList("name", "version", "stateName", "albumName", "albumVersion"));
return chunks;
// CHECKSTYLE:ON: LineLength
}
- /** Test STG load. */
+ /**
+ * Test STG load.
+ */
@Test
- public void testGenerationLoad() {
+ void testGenerationLoad() {
final DummyStErrorListener errListener = new DummyStErrorListener();
final STGroupFile stg = new STGroupFile(CodeGeneratorCliEditor.STG_FILE);
stg.setListener(errListener);
@@ -97,16 +99,18 @@ public class SupportGenerationTest {
assertEquals(0, errListener.getErrorCount());
}
- /** Test STG chunks. */
+ /**
+ * Test STG chunks.
+ */
@Test
- public void testGenerationChunks() {
+ void testGenerationChunks() {
final DummyStErrorListener errListener = new DummyStErrorListener();
final STGroupFile stg = new STGroupFile(CodeGeneratorCliEditor.STG_FILE);
stg.setListener(errListener);
stg.getTemplateNames(); // dummy to compile group and get errors
final Map<String, List<String>> chunks = getCodeGenChunks();
- String error = "";
+ StringBuilder error = new StringBuilder();
final Set<String> definedNames = stg.getTemplateNames();
for (final STGroup group : stg.getImportedGroups()) {
definedNames.addAll(group.getTemplateNames());
@@ -115,15 +119,15 @@ public class SupportGenerationTest {
for (final String required : requiredNames) {
if (!definedNames.contains(required)) {
- error += " - target STG does not define template for <" + required + ">\n";
+ error.append(" - target STG does not define template for <").append(required).append(">\n");
} else {
final Set<String> definedParams = ((stg.getInstanceOf(required).getAttributes() == null)
- ? new TreeSet<String>() : stg.getInstanceOf(required).getAttributes().keySet());
+ ? new TreeSet<>() : stg.getInstanceOf(required).getAttributes().keySet());
final List<String> requiredParams = chunks.get(required);
for (final String reqArg : requiredParams) {
if (!definedParams.contains(reqArg)) {
- error += " - target STG with template <" + required + "> does not define argument <" + reqArg
- + ">\n";
+ error.append(" - target STG with template <").append(required)
+ .append("> does not define argument <").append(reqArg).append(">\n");
}
}
}
diff --git a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportKeyInfoGetter.java b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportKeyInfoGetter.java
index 567991666..1d24c1f51 100644
--- a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportKeyInfoGetter.java
+++ b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportKeyInfoGetter.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,7 +36,9 @@ import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
@AllArgsConstructor
public class SupportKeyInfoGetter {
- /** The policy model for the getters. */
+ /**
+ * The policy model for the getters.
+ */
private final AxPolicyModel model;
/**
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java
index 5f7bad116..6797ff4e4 100644
--- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java
+++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2022 Nordix Foundation.
+ * Copyright (C) 2019-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.
@@ -37,14 +37,12 @@ import org.slf4j.LoggerFactory;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
+@Getter
public class ApexCliToscaEditorMain {
private static final Logger LOGGER = LoggerFactory.getLogger(ApexCliToscaEditorMain.class);
- @Getter
private boolean failure;
- private ApexCliToscaParameters parameters;
- private ApexCommandLineEditorMain apexCliEditor;
/**
* Instantiates the Apex CLI Tosca editor.
@@ -56,7 +54,7 @@ public class ApexCliToscaEditorMain {
LOGGER.info("Starting Apex CLI Tosca editor with arguments - {}", argumentString);
final var parser = new ApexCliToscaParameterParser();
- parameters = parser.parse(args);
+ ApexCliToscaParameters parameters = parser.parse(args);
if (parameters.isHelpSet()) {
CliUtils.help(ApexCliToscaEditorMain.class.getName(), parser.getOptions());
return;
@@ -78,7 +76,7 @@ public class ApexCliToscaEditorMain {
cliArgsList.add(policyModelFilePath);
String[] cliArgs = cliArgsList.toArray(new String[cliArgsList.size()]);
- apexCliEditor = new ApexCommandLineEditorMain(cliArgs);
+ ApexCommandLineEditorMain apexCliEditor = new ApexCommandLineEditorMain(cliArgs);
if (apexCliEditor.getErrorCount() == 0) {
LOGGER.info("Apex CLI editor completed execution. Creating the ToscaPolicy using the tosca template"
+ "skeleton file, config file, and policy model created.");
@@ -90,7 +88,7 @@ public class ApexCliToscaEditorMain {
} catch (IOException | CoderException e) {
failure = true;
LOGGER.error("Failed to create the Tosca template using the generated policy model,"
- + "apex config file and the tosca template skeleton file. " + e);
+ + "apex config file and the tosca template skeleton file. {}", e.getMessage());
}
} else {
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java
index 7c3e4cb01..5028abd31 100644
--- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (c) 2020-2021 Nordix Foundation.
+ * Copyright (c) 2020-2021, 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,26 +22,26 @@
package org.onap.policy.apex.auth.clieditor;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.List;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class CommandLineCommandTest {
+class CommandLineCommandTest {
CommandLineCommand commandLineCommand = null;
- @Before
- public void initializeCommandLineCommand() {
+ @BeforeEach
+ void initializeCommandLineCommand() {
commandLineCommand = new CommandLineCommand();
}
@Test
- public void testCommandLine() {
+ void testCommandLine() {
commandLineCommand.setName("TestName");
commandLineCommand.setDescription("testDescription");
commandLineCommand.setSystemCommand(true);
@@ -50,40 +50,40 @@ public class CommandLineCommandTest {
assertEquals("TestName", commandLineCommand.getName());
assertEquals(
"CommandLineCommand(name=TestName, keywordlist=[], argumentList=[], apiMethod=, systemCommand=true,"
- + " description=testDescription)", commandLineCommand.toString());
+ + " description=testDescription)", commandLineCommand.toString());
}
- @Test(expected = CommandLineException.class)
- public void testInvalidApiClassName() {
- commandLineCommand.getApiClassName();
+ @Test
+ void testInvalidApiClassName() {
+ assertThrows(CommandLineException.class, () -> commandLineCommand.getApiClassName());
}
@Test
- public void testGetValidApiClassName() {
+ void testGetValidApiClassName() {
commandLineCommand.setApiMethod("Java.Get");
assertEquals("Java", commandLineCommand.getApiClassName());
}
- @Test(expected = CommandLineException.class)
- public void testInvalidApiMethodName() {
- commandLineCommand.getApiMethodName();
+ @Test
+ void testInvalidApiMethodName() {
+ assertThrows(CommandLineException.class, () -> commandLineCommand.getApiMethodName());
}
@Test()
- public void testInvalidApiMethod() {
+ void testInvalidApiMethod() {
commandLineCommand.setApiMethod("fail.");
assertEquals("fail.", commandLineCommand.getApiMethod());
assertThrows(CommandLineException.class, () -> commandLineCommand.getApiMethodName());
}
@Test
- public void testValidApiMethodName() {
+ void testValidApiMethodName() {
commandLineCommand.setApiMethod("Java.Get");
assertEquals("Get", commandLineCommand.getApiMethodName());
}
@Test
- public void testGetHelp() {
+ void testGetHelp() {
List<String> keywordList = commandLineCommand.getKeywordlist();
List<CommandLineArgument> argumentList = commandLineCommand.getArgumentList();
assertEquals("{}: ", commandLineCommand.getHelp());
@@ -94,8 +94,7 @@ public class CommandLineCommandTest {
}
@Test
- public void testCompareTo() {
- assertEquals(0, commandLineCommand.compareTo(commandLineCommand));
+ void testCompareTo() {
CommandLineCommand otherCommand = new CommandLineCommand();
otherCommand.setSystemCommand(true);
assertThat(commandLineCommand).isNotEqualByComparingTo(otherCommand);
@@ -104,7 +103,7 @@ public class CommandLineCommandTest {
}
@Test
- public void testCompareKeywordList() {
+ void testCompareKeywordList() {
CommandLineCommand otherCommand = new CommandLineCommand();
otherCommand.getKeywordlist().add("test");
assertThat(commandLineCommand).isNotEqualByComparingTo(otherCommand);
@@ -117,7 +116,7 @@ public class CommandLineCommandTest {
}
@Test
- public void testHashCode() {
+ void testHashCode() {
CommandLineCommand otherCommand = new CommandLineCommand();
assertEquals(commandLineCommand.hashCode(), otherCommand.hashCode());
commandLineCommand.getKeywordlist().add("Test");
@@ -128,10 +127,9 @@ public class CommandLineCommandTest {
}
@Test
- public void testEquals() {
+ void testEquals() {
assertNotEquals(commandLineCommand, new Object());
- assertEquals(commandLineCommand, commandLineCommand);
- assertNotEquals(commandLineCommand, null);
+ assertNotEquals(null, commandLineCommand);
CommandLineCommand otherCommand = new CommandLineCommand();
assertEquals(commandLineCommand, otherCommand);
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorEventsContextTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorEventsContextTest.java
index d5d288d04..437ae0fbb 100644
--- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorEventsContextTest.java
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorEventsContextTest.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 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,22 +23,20 @@
package org.onap.policy.apex.auth.clieditor;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
import org.onap.policy.common.utils.resources.TextFileUtils;
/**
* The Class TestCLIEditorEventsContext.
*/
-public class CommandLineEditorEventsContextTest {
+class CommandLineEditorEventsContextTest {
// CHECKSTYLE:OFF: MagicNumber
private static final Path SRC_MAIN_FOLDER = Paths.get("src/main/resources/");
@@ -56,20 +54,19 @@ public class CommandLineEditorEventsContextTest {
private static final String JSON_FILE = FILE_NAME + ".json";
private static final String LOG_FILE = FILE_NAME + ".log";
- @Rule
- public TemporaryFolder temporaryFolder = new TemporaryFolder();
+ @TempDir
+ static Path temporaryFolder;
/**
* Test java context model.
*
* @throws IOException Signals that an I/O exception has occurred.
- * @throws ApexModelException if an Apex error happens
*/
@Test
- public void testJavaContextModel() throws IOException, ApexModelException {
+ void testJavaContextModel() throws IOException {
- final File tempLogFile = temporaryFolder.newFile(LOG_FILE);
- final File tempModelFile = temporaryFolder.newFile(JSON_FILE);
+ final File tempLogFile = temporaryFolder.resolve(LOG_FILE).toFile();
+ final File tempModelFile = temporaryFolder.resolve(JSON_FILE).toFile();
final String[] cliArgs = new String[] {"-c", APEX_JAVA_POLICY_FILE.toString(), "-l",
tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()};
@@ -81,7 +78,7 @@ public class CommandLineEditorEventsContextTest {
final String logString = TextFileUtils.getTextFileAsString(tempLogFile.getCanonicalPath());
final String modelString = TextFileUtils.getTextFileAsString(tempModelFile.getCanonicalPath());
- // As a sanity check, count the number of non white space characters in log and model files
+ // As a sanity check, count the number of non-white space characters in log and model files
final int logCharCount = logString.replaceAll(SPACES, EMPTY_STRING).length();
final int modelCharCount = modelString.replaceAll(SPACES, EMPTY_STRING).length();
@@ -93,13 +90,12 @@ public class CommandLineEditorEventsContextTest {
* Test avro context model.
*
* @throws IOException Signals that an I/O exception has occurred.
- * @throws ApexModelException if an Apex error happens
*/
@Test
- public void testAvroContextModel() throws IOException, ApexModelException {
+ void testAvroContextModel() throws IOException {
- final File tempLogFile = temporaryFolder.newFile(LOG_FILE);
- final File tempModelFile = temporaryFolder.newFile(JSON_FILE);
+ final File tempLogFile = temporaryFolder.resolve(LOG_FILE).toFile();
+ final File tempModelFile = temporaryFolder.resolve(JSON_FILE).toFile();
final String[] cliArgs = new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l",
tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()};
@@ -111,7 +107,7 @@ public class CommandLineEditorEventsContextTest {
final String logString = TextFileUtils.getTextFileAsString(tempLogFile.getCanonicalPath());
final String modelString = TextFileUtils.getTextFileAsString(tempModelFile.getCanonicalPath());
- // As a sanity check, count the number of non white space characters in log and model files
+ // As a sanity check, count the number of non-white space characters in log and model files
final int logCharCount = logString.replaceAll(SPACES, EMPTY_STRING).length();
final int modelCharCount = modelString.replaceAll(SPACES, EMPTY_STRING).length();
@@ -121,18 +117,18 @@ public class CommandLineEditorEventsContextTest {
}
@Test
- public void test_emptyMetadataCommandFileWithEmptyJsonTag_errorcountGreaterThanOne() throws IOException {
+ void test_emptyMetadataCommandFileWithEmptyJsonTag_errorCountGreaterThanOne() {
- final File tempLogFile = temporaryFolder.newFile(LOG_FILE);
- final File tempModelFile = temporaryFolder.newFile(JSON_FILE);
+ final File tempLogFile = temporaryFolder.resolve(LOG_FILE).toFile();
+ final File tempModelFile = temporaryFolder.resolve(JSON_FILE).toFile();
final String modelFile = SRC_TEST_FOLDER.resolve("model").resolve("empty_commands.json").toString();
final String apexPropertiesLocation =
- SRC_MAIN_FOLDER.resolve("etc/editor").resolve("ApexModelProperties.json").toString();
+ SRC_MAIN_FOLDER.resolve("etc/editor").resolve("ApexModelProperties.json").toString();
final String[] cliArgs =
- new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", tempLogFile.getAbsolutePath(), "-o",
- tempModelFile.getAbsolutePath(), "-m", modelFile, "-a", apexPropertiesLocation};
+ new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", tempLogFile.getAbsolutePath(), "-o",
+ tempModelFile.getAbsolutePath(), "-m", modelFile, "-a", apexPropertiesLocation};
final ApexCommandLineEditorMain objUnderTest = new ApexCommandLineEditorMain(cliArgs);
assertEquals(1, objUnderTest.getErrorCount());
@@ -140,19 +136,19 @@ public class CommandLineEditorEventsContextTest {
}
@Test
- public void test_emptyMetadataCommandFile_errorcountGreaterThanOne() throws IOException {
+ void test_emptyMetadataCommandFile_errorCountGreaterThanOne() {
- final File tempLogFile = temporaryFolder.newFile(LOG_FILE);
- final File tempModelFile = temporaryFolder.newFile(JSON_FILE);
+ final File tempLogFile = temporaryFolder.resolve(LOG_FILE).toFile();
+ final File tempModelFile = temporaryFolder.resolve(JSON_FILE).toFile();
- final File modelFile = temporaryFolder.newFile("empty_commands.json");
+ final File modelFile = temporaryFolder.resolve("empty_commands.json").toFile();
final String apexPropertiesLocation =
- SRC_MAIN_FOLDER.resolve("etc/editor").resolve("ApexModelProperties.json").toString();
+ SRC_MAIN_FOLDER.resolve("etc/editor").resolve("ApexModelProperties.json").toString();
final String[] cliArgs =
- new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", tempLogFile.getAbsolutePath(), "-o",
- tempModelFile.getAbsolutePath(), "-m", modelFile.getAbsolutePath(), "-a", apexPropertiesLocation};
+ new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", tempLogFile.getAbsolutePath(), "-o",
+ tempModelFile.getAbsolutePath(), "-m", modelFile.getAbsolutePath(), "-a", apexPropertiesLocation};
final ApexCommandLineEditorMain objUnderTest = new ApexCommandLineEditorMain(cliArgs);
assertEquals(1, objUnderTest.getErrorCount());
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java
index e49422996..dfdb4c2a3 100644
--- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020,2022 Nordix Foundation.
+ * Modifications Copyright (C) 2019-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,16 +21,15 @@
package org.onap.policy.apex.auth.clieditor;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
-import org.junit.Test;
-import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.resources.TextFileUtils;
/**
@@ -38,17 +37,16 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class CommandLineEditorOptionsTest {
+class CommandLineEditorOptionsTest {
// CHECKSTYLE:OFF: MagicNumber
/**
* Test script options log model.
*
* @throws IOException Signals that an I/O exception has occurred.
- * @throws ApexModelException if there is an Apex error
*/
@Test
- public void testScriptOptionsLogModel() throws IOException, ApexModelException {
+ void testScriptOptionsLogModel() throws IOException {
final File tempLogFile = File.createTempFile("ShellPolicyModel", ".log");
final File tempModelFile = File.createTempFile("ShellPolicyModel", ".json");
@@ -62,25 +60,24 @@ public class CommandLineEditorOptionsTest {
final String logString = TextFileUtils.getTextFileAsString(tempLogFile.getCanonicalPath());
final String modelString = TextFileUtils.getTextFileAsString(tempModelFile.getCanonicalPath());
- // As a sanity check, count the number of non white space characters in log and model files
+ // As a sanity check, count the number of non-white space characters in log and model files
final int logCharCount = logString.replaceAll("\\s+", "").length();
final int modelCharCount = modelString.replaceAll("\\s+", "").length();
assertEquals(1204, logCharCount);
assertEquals(2904, modelCharCount);
- tempLogFile.delete();
- tempModelFile.delete();
+ assertTrue(tempLogFile.delete());
+ assertTrue(tempModelFile.delete());
}
/**
* Test script options no log no model spec.
*
* @throws IOException Signals that an I/O exception has occurred.
- * @throws ApexModelException if there is an Apex error
*/
@Test
- public void testScriptOptionsNoLogNoModelSpec() throws IOException, ApexModelException {
+ void testScriptOptionsNoLogNoModelSpec() throws IOException {
final File tempLogFile = File.createTempFile("ShellPolicyModel", ".log");
final File tempModelFile = File.createTempFile("ShellPolicyModel", ".json");
@@ -101,18 +98,17 @@ public class CommandLineEditorOptionsTest {
assertEquals(0, logCharCount);
assertEquals(0, modelCharCount);
- tempLogFile.delete();
- tempModelFile.delete();
+ assertTrue(tempLogFile.delete());
+ assertTrue(tempModelFile.delete());
}
/**
* Test script options log no model spec.
*
* @throws IOException Signals that an I/O exception has occurred.
- * @throws ApexModelException if there is an Apex error
*/
@Test
- public void testScriptOptionsLogNoModelSpec() throws IOException, ApexModelException {
+ void testScriptOptionsLogNoModelSpec() throws IOException {
final File tempLogFile = File.createTempFile("ShellPolicyModel", ".log");
final File tempModelFile = File.createTempFile("ShellPolicyModel", ".json");
@@ -133,18 +129,17 @@ public class CommandLineEditorOptionsTest {
assertEquals(1204, logCharCount);
assertEquals(0, modelCharCount);
- tempLogFile.delete();
- tempModelFile.delete();
+ assertTrue(tempLogFile.delete());
+ assertTrue(tempModelFile.delete());
}
/**
* Test script options no log model spec.
*
* @throws IOException Signals that an I/O exception has occurred.
- * @throws ApexModelException if there is an Apex error
*/
@Test
- public void testScriptOptionsNoLogModelSpec() throws IOException, ApexModelException {
+ void testScriptOptionsNoLogModelSpec() throws IOException {
final File tempLogFile = File.createTempFile("ShellPolicyModel", ".log");
final File tempModelFile = File.createTempFile("ShellPolicyModel", ".json");
@@ -165,20 +160,17 @@ public class CommandLineEditorOptionsTest {
assertEquals(0, logCharCount);
assertEquals(2904, modelCharCount);
- tempLogFile.delete();
- tempModelFile.delete();
+ assertTrue(tempLogFile.delete());
+ assertTrue(tempModelFile.delete());
}
/**
* Test script options no log no model no spec.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws ApexModelException if there is an Apex error
*/
@Test
- public void testScriptOptionsNoLogNoModelNoSpec() throws IOException, ApexModelException {
+ void testScriptOptionsNoLogNoModelNoSpec() {
final String[] cliArgs =
- new String[] {"-c", "src/main/resources/examples/scripts/ShellPolicyModel.apex", "-nl", "-nm"};
+ new String[] {"-c", "src/main/resources/examples/scripts/ShellPolicyModel.apex", "-nl", "-nm"};
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -195,12 +187,9 @@ public class CommandLineEditorOptionsTest {
/**
* Test script options log model no spec.
- *
- * @throws IOException Signals that an I/O exception has occurred.
- * @throws ApexModelException if there is an Apex error
*/
@Test
- public void testScriptOptionsLogModelNoSpec() throws IOException, ApexModelException {
+ void testScriptOptionsLogModelNoSpec() {
final String[] cliArgs = new String[] {"-c", "src/main/resources/examples/scripts/ShellPolicyModel.apex"};
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -223,10 +212,9 @@ public class CommandLineEditorOptionsTest {
* Test script options input output model.
*
* @throws IOException Signals that an I/O exception has occurred.
- * @throws ApexModelException if there is an Apex error
*/
@Test
- public void testScriptOptionsInputOutputModel() throws IOException, ApexModelException {
+ void testScriptOptionsInputOutputModel() throws IOException {
final File tempLogFileIn = File.createTempFile("ShellPolicyModelIn", ".log");
final File tempLogFileOut = File.createTempFile("ShellPolicyModelOut", ".log");
final File tempModelFileIn = File.createTempFile("ShellPolicyModelIn", ".json");
@@ -243,7 +231,7 @@ public class CommandLineEditorOptionsTest {
final String tempLogFileInString = TextFileUtils.getTextFileAsString(tempLogFileIn.getCanonicalPath());
final String tempModelFileInString = TextFileUtils.getTextFileAsString(tempModelFileIn.getCanonicalPath());
- // As a sanity check, count the number of non white space characters in log and model files
+ // As a sanity check, count the number of non-white space characters in log and model files
final int tempLogFileInCharCount = tempLogFileInString.replaceAll("\\s+", "").length();
final int tempModelFileInCharCount = tempModelFileInString.replaceAll("\\s+", "").length();
@@ -268,9 +256,9 @@ public class CommandLineEditorOptionsTest {
assertEquals(1154, tempLogFileOutCharCount);
assertEquals(3336, tempModelFileOutCharCount);
- tempLogFileIn.delete();
- tempModelFileIn.delete();
- tempLogFileOut.delete();
- tempModelFileOut.delete();
+ assertTrue(tempLogFileIn.delete());
+ assertTrue(tempModelFileIn.delete());
+ assertTrue(tempLogFileOut.delete());
+ assertTrue(tempModelFileOut.delete());
}
}
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java
index d2b3a812f..395f4c6bf 100644
--- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020,2022 Nordix Foundation.
+ * Modifications Copyright (C) 2019-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,15 +21,15 @@
package org.onap.policy.apex.auth.clieditor;
-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 java.io.File;
import java.io.IOException;
import java.net.URL;
-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.model.basicmodel.concepts.AxValidationResult;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelException;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
@@ -41,7 +41,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class CommandLineEditorScriptingTest {
+class CommandLineEditorScriptingTest {
private File tempModelFile;
private File tempLogFile;
@@ -55,7 +55,7 @@ public class CommandLineEditorScriptingTest {
*
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Before
+ @BeforeEach
public void initialiseArgs() throws IOException {
tempModelFile = File.createTempFile("SampleLBPolicyMap", ".json");
tempLogFile = File.createTempFile("SampleLBPolicyMap", ".log");
@@ -70,10 +70,10 @@ public class CommandLineEditorScriptingTest {
/**
* Removes the generated files.
*/
- @After
+ @AfterEach
public void removeGeneratedFiles() {
- tempModelFile.delete();
- tempLogFile.delete();
+ assertTrue(tempModelFile.delete());
+ assertTrue(tempLogFile.delete());
}
/**
@@ -83,7 +83,7 @@ public class CommandLineEditorScriptingTest {
* @throws ApexModelException if there is an Apex error
*/
@Test
- public void testSamplePolicyScript() throws IOException, ApexModelException {
+ void testSamplePolicyScript() throws IOException, ApexModelException {
final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(samplePolicyArgs);
assertEquals(0, cliEditor.getErrorCount());
@@ -118,8 +118,8 @@ public class CommandLineEditorScriptingTest {
* @throws ApexModelException if there is an Apex error
*/
@Test
- public void testSampleMapPolicyScript() throws IOException, ApexModelException {
- tempModelFile.delete();
+ void testSampleMapPolicyScript() throws IOException, ApexModelException {
+ assertTrue(tempModelFile.delete());
final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(samplePolicyMapArgs);
assertEquals(0, cliEditor.getErrorCount());
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.java
index ab9b900af..6984b6701 100644
--- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.java
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.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,15 +21,16 @@
package org.onap.policy.apex.auth.clieditor;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+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.File;
import java.io.IOException;
import java.net.URL;
-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.model.basicmodel.handling.ApexModelException;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
@@ -38,7 +39,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
/**
* The Class TestContextAlbums.
*/
-public class ContextAlbumsTest {
+class ContextAlbumsTest {
private String[] logicBlockArgs;
private File tempModelFile;
@@ -48,30 +49,30 @@ public class ContextAlbumsTest {
*
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Before
- public void createTempFiles() throws IOException {
+ @BeforeEach
+ void createTempFiles() throws IOException {
tempModelFile = File.createTempFile("TestPolicyModel", ".json");
logicBlockArgs = new String[] {"-c", "src/test/resources/scripts/ContextAlbums.apex", "-o",
- tempModelFile.getAbsolutePath(), "-nl"};
+ tempModelFile.getAbsolutePath(), "-nl"};
}
/**
* Removes the generated models.
*/
- @After
- public void removeGeneratedModels() {
- tempModelFile.delete();
+ @AfterEach
+ void removeGeneratedModels() {
+ assertTrue(tempModelFile.delete());
}
/**
* Test logic block.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
* @throws ApexModelException if there is an Apex error
*/
@Test
- public void testLogicBlock() throws IOException, ApexModelException {
+ void testLogicBlock() throws IOException, ApexModelException {
final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(logicBlockArgs);
assertEquals(1, cliEditor.getErrorCount());
@@ -84,7 +85,7 @@ public class ContextAlbumsTest {
assertNotNull(writtenModel);
final URL compareModelUrl =
- ResourceUtils.getLocalFile("src/test/resources/compare/ContextAlbumsModel_Compare.json");
+ ResourceUtils.getLocalFile("src/test/resources/compare/ContextAlbumsModel_Compare.json");
final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream());
// Ignore key info UUIDs
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.java
index 9896ab9ee..d407e5a4e 100644
--- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.java
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.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,15 +21,16 @@
package org.onap.policy.apex.auth.clieditor;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.nio.file.Paths;
-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.model.basicmodel.handling.ApexModelException;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
@@ -39,7 +40,7 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
/**
* Test FileMacro in the CLI.
*/
-public class FileMacroTest {
+class FileMacroTest {
private String[] fileMacroArgs;
private File tempModelFile;
@@ -50,8 +51,8 @@ public class FileMacroTest {
*
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Before
- public void createTempFiles() throws IOException {
+ @BeforeEach
+ void createTempFiles() throws IOException {
tempModelFile = File.createTempFile("TestPolicyModel", ".json");
tempLogFile = File.createTempFile("TestPolicyModel", ".log");
@@ -62,19 +63,19 @@ public class FileMacroTest {
/**
* Removes the generated models.
*/
- @After
- public void removeGeneratedModels() {
- tempModelFile.delete();
+ @AfterEach
+ void removeGeneratedModels() {
+ assertTrue(tempModelFile.delete());
}
/**
* Test logic block macro in CLI scripts.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
* @throws ApexModelException if there is an Apex error
*/
@Test
- public void testLogicBlock() throws IOException, ApexModelException {
+ void testLogicBlock() throws IOException, ApexModelException {
final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(fileMacroArgs);
// We expect eight errors
assertEquals(8, cliEditor.getErrorCount());
@@ -87,7 +88,7 @@ public class FileMacroTest {
final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream());
final URL compareModelUrl =
- ResourceUtils.getLocalFile("src/test/resources/compare/FileMacroModel_Compare.json");
+ ResourceUtils.getLocalFile("src/test/resources/compare/FileMacroModel_Compare.json");
final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream());
// Ignore key info UUIDs
@@ -100,11 +101,11 @@ public class FileMacroTest {
final File outputLogFile = new File(tempLogFile.getCanonicalPath());
final String outputLogString = TextFileUtils.getTextFileAsString(outputLogFile.getCanonicalPath())
- .replace(Paths.get("").toAbsolutePath().toString() + File.separator, "").replaceAll("\\s+", "");
+ .replace(Paths.get("").toAbsolutePath() + File.separator, "").replaceAll("\\s+", "");
// We compare the log to what we expect to get
final String outputLogCompareString = TextFileUtils
- .getTextFileAsString("src/test/resources/compare/FileMacro_Compare.log").replaceAll("\\s+", "");
+ .getTextFileAsString("src/test/resources/compare/FileMacro_Compare.log").replaceAll("\\s+", "");
// Check what we got is what we expected to get
assertEquals(outputLogCompareString, outputLogString);
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.java
index 077f354f6..e30780ca0 100644
--- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.java
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.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,24 +21,24 @@
package org.onap.policy.apex.auth.clieditor;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.IOException;
import java.net.URL;
-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.model.basicmodel.handling.ApexModelException;
import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
import org.onap.policy.common.utils.resources.ResourceUtils;
-// TODO: Auto-generated Javadoc
/**
* The Class TestLogicBlock.
*/
-public class LogicBlockTest {
+class LogicBlockTest {
private String[] logicBlockArgs;
private String[] avroSchemaArgs;
@@ -50,35 +50,35 @@ public class LogicBlockTest {
*
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Before
- public void createTempFiles() throws IOException {
+ @BeforeEach
+ void createTempFiles() throws IOException {
tempLogicModelFile = File.createTempFile("TestLogicPolicyModel", ".json");
tempAvroModelFile = File.createTempFile("TestAvroPolicyModel", ".json");
logicBlockArgs = new String[] {"-c", "src/test/resources/scripts/LogicBlock.apex", "-o",
- tempLogicModelFile.getCanonicalPath(), "-if", "true", "-nl"};
+ tempLogicModelFile.getCanonicalPath(), "-if", "true", "-nl"};
avroSchemaArgs = new String[] {"-c", "src/test/resources/scripts/AvroSchema.apex", "-o",
- tempAvroModelFile.getCanonicalPath(), "-nl"};
+ tempAvroModelFile.getCanonicalPath(), "-nl"};
}
/**
* Removes the temp files.
*/
- @After
- public void removeTempFiles() {
- tempLogicModelFile.delete();
- tempAvroModelFile.delete();
+ @AfterEach
+ void removeTempFiles() {
+ assertTrue(tempLogicModelFile.delete());
+ assertTrue(tempAvroModelFile.delete());
}
/**
* Test logic block.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
* @throws ApexModelException if there is an Apex error
*/
@Test
- public void testLogicBlock() throws IOException, ApexModelException {
+ void testLogicBlock() throws IOException, ApexModelException {
new ApexCommandLineEditorMain(logicBlockArgs);
// Read the file from disk
@@ -89,7 +89,7 @@ public class LogicBlockTest {
final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream());
final URL compareModelUrl =
- ResourceUtils.getLocalFile("src/test/resources/compare/LogicBlockModel_Compare.json");
+ ResourceUtils.getLocalFile("src/test/resources/compare/LogicBlockModel_Compare.json");
final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream());
// Ignore key info UUIDs
@@ -102,11 +102,11 @@ public class LogicBlockTest {
/**
* Test avro schema.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
* @throws ApexModelException if there is an Apex error
*/
@Test
- public void testAvroSchema() throws IOException, ApexModelException {
+ void testAvroSchema() throws IOException, ApexModelException {
new ApexCommandLineEditorMain(avroSchemaArgs);
// Read the file from disk
@@ -117,7 +117,7 @@ public class LogicBlockTest {
final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream());
final URL compareModelUrl =
- ResourceUtils.getLocalFile("src/test/resources/compare/AvroSchemaModel_Compare.json");
+ ResourceUtils.getLocalFile("src/test/resources/compare/AvroSchemaModel_Compare.json");
final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream());
// Ignore key info UUIDs
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java
index 51659c2ea..9399b821b 100644
--- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019,2022 Nordix Foundation.
+ * Copyright (C) 2019, 2022, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,17 +22,17 @@
package org.onap.policy.apex.auth.clieditor.tosca;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
-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.common.utils.resources.TextFileUtils;
/**
@@ -40,7 +40,7 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class ApexCliToscaEditorTest {
+class ApexCliToscaEditorTest {
private File tempOutputToscaFile;
private File tempLogFile;
@@ -52,7 +52,7 @@ public class ApexCliToscaEditorTest {
*
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Before
+ @BeforeEach
public void initialiseArgs() throws IOException {
tempOutputToscaFile = File.createTempFile("ToscaPolicyOutput", ".json");
@@ -64,21 +64,21 @@ public class ApexCliToscaEditorTest {
"-t", CommonTestData.INPUT_TOSCA_TEMPLATE_FILE_NAME,
"-ot", tempOutputToscaFile.getAbsolutePath(),
"-l", tempLogFile.getAbsolutePath()
- };
+ };
}
/**
* Removes the generated files.
*/
- @After
+ @AfterEach
public void removeGeneratedFiles() {
- tempOutputToscaFile.delete();
- tempLogFile.delete();
- tempNodeTemplateFile.delete();
+ assertTrue(tempOutputToscaFile.delete());
+ assertTrue(tempLogFile.delete());
+ assertTrue(tempNodeTemplateFile.delete());
}
@Test
- public void testApexCliToscaParameterParser() {
+ void testApexCliToscaParameterParser() {
ApexCliToscaParameters params = new ApexCliToscaParameterParser().parse(sampleArgs);
assertEquals(CommonTestData.APEX_CONFIG_FILE_NAME, params.getApexConfigFileName());
assertEquals(CommonTestData.COMMAND_FILE_NAME, params.getCommandFileName());
@@ -88,7 +88,7 @@ public class ApexCliToscaEditorTest {
}
@Test
- public void testApexCliTosca_success() throws IOException {
+ void testApexCliTosca_success() throws IOException {
final ApexCliToscaEditorMain cliEditor = new ApexCliToscaEditorMain(sampleArgs);
@@ -101,24 +101,26 @@ public class ApexCliToscaEditorTest {
}
@Test
- public void testApexCliTosca_no_args() {
+ void testApexCliTosca_no_args() {
String[] noArgs = new String[] {};
assertThatThrownBy(() -> new ApexCliToscaEditorMain(noArgs)).hasMessage("Insufficient arguments provided.");
}
@Test
- public void testApexCliTosca_missing_commandfile() {
- String[] sampleArgs = new String[] {
- "-ac", CommonTestData.APEX_CONFIG_FILE_NAME,
- "-t", CommonTestData.INPUT_TOSCA_TEMPLATE_FILE_NAME,
- "-ot", tempOutputToscaFile.getAbsolutePath(),
- "-l", tempLogFile.getAbsolutePath()
+ void testApexCliTosca_missing_commandFile() {
+ assertThatThrownBy(() -> {
+ String[] sampleArgs = new String[] {
+ "-ac", CommonTestData.APEX_CONFIG_FILE_NAME,
+ "-t", CommonTestData.INPUT_TOSCA_TEMPLATE_FILE_NAME,
+ "-ot", tempOutputToscaFile.getAbsolutePath(),
+ "-l", tempLogFile.getAbsolutePath()
};
- assertThatThrownBy(() -> new ApexCliToscaEditorMain(sampleArgs)).hasMessage("Insufficient arguments provided.");
+ new ApexCliToscaEditorMain(sampleArgs);
+ }).hasMessage("Insufficient arguments provided.");
}
@Test
- public void testGenerateToscaPolicyMetadataSet() throws Exception {
+ void testGenerateToscaPolicyMetadataSet() throws Exception {
// @formatter:off
final String[] cliArgs = new String[] {
"-c", CommonTestData.COMMAND_FILE_NAME,
@@ -135,9 +137,9 @@ public class ApexCliToscaEditorTest {
assertTrue(tempOutputToscaFile.length() > 0);
assertTrue(Files.lines(Paths.get(tempOutputToscaFile.toString()))
- .noneMatch(l -> l.contains("policy_type_impl")));
+ .noneMatch(l -> l.contains("policy_type_impl")));
assertTrue(tempNodeTemplateFile.length() > 0);
assertTrue(Files.lines(Paths.get(tempNodeTemplateFile.toString()))
- .anyMatch(l -> l.contains("policyModel")));
+ .anyMatch(l -> l.contains("policyModel")));
}
}
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java
index ba3ab7627..eb1fabec5 100644
--- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019,2022 Nordix Foundation.
+ * Copyright (C) 2019, 2022, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,17 +22,17 @@
package org.onap.policy.apex.auth.clieditor.utils;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
-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.auth.clieditor.tosca.ApexCliToscaParameterParser;
import org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaParameters;
import org.onap.policy.apex.auth.clieditor.tosca.CommonTestData;
@@ -44,7 +44,7 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class CliUtilsTest {
+class CliUtilsTest {
private File tempOutputToscaFile;
private File tempLogFile;
@@ -56,7 +56,7 @@ public class CliUtilsTest {
*
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Before
+ @BeforeEach
public void initialiseArgs() throws IOException {
tempOutputToscaFile = File.createTempFile("ToscaPolicyOutput", ".json");
@@ -70,14 +70,14 @@ public class CliUtilsTest {
/**
* Removes the generated files.
*/
- @After
+ @AfterEach
public void removeGeneratedFiles() {
- tempOutputToscaFile.delete();
- tempLogFile.delete();
+ assertTrue(tempOutputToscaFile.delete());
+ assertTrue(tempLogFile.delete());
}
@Test
- public void testCreateToscaServiceTemplate() throws IOException, CoderException {
+ void testCreateToscaServiceTemplate() throws IOException, CoderException {
ApexCliToscaParameters params = new ApexCliToscaParameterParser().parse(sampleArgs);
CliUtils.createToscaPolicy(params, policyModelFilePath, null);
String outputTosca = TextFileUtils.getTextFileAsString(tempOutputToscaFile.getAbsolutePath());
@@ -87,43 +87,43 @@ public class CliUtilsTest {
}
@Test
- public void testValidateReadableFile_validfile() {
+ void testValidateReadableFile_validFile() {
CliUtils.validateReadableFile("Apex Config File", CommonTestData.APEX_CONFIG_FILE_NAME);
}
@Test
- public void testValidateReadableFile_invalidfile() {
+ void testValidateReadableFile_invalidFile() {
String invalidFileName = "src/test/resources/tosca/ApexConfigxyz.json";
assertThatThrownBy(() -> CliUtils.validateReadableFile("Apex Config File", invalidFileName))
.hasMessage("File " + invalidFileName + " of type Apex Config File does not exist");
}
@Test
- public void testValidateWritableFile_validfile() {
+ void testValidateWritableFile_validFile() {
CliUtils.validateWritableFile("Output Tosca Policy File", tempOutputToscaFile.getAbsolutePath());
}
@Test
- public void testValidateWritableFile_invalidfile() {
+ void testValidateWritableFile_invalidFile() {
String invalidFileName = "src/test/resources/tosca";
assertThatThrownBy(() -> CliUtils.validateWritableFile("Output Tosca Policy File", invalidFileName))
.hasMessage("File " + invalidFileName + " of type Output Tosca Policy File is not a normal file");
}
@Test
- public void testValidateWritableDirectory_validdirectory() {
+ void testValidateWritableDirectory_validDirectory() {
CliUtils.validateWritableDirectory("Working Directory", "src/test/resources/tosca");
}
@Test
- public void testValidateWritableDirectory_invaliddirectory() {
+ void testValidateWritableDirectory_invalidDirectory() {
assertThatThrownBy(() -> CliUtils.validateWritableDirectory("Working Directory",
CommonTestData.APEX_CONFIG_FILE_NAME)).hasMessage("directory " + CommonTestData.APEX_CONFIG_FILE_NAME
- + " of type Working Directory is not a directory");
+ + " of type Working Directory is not a directory");
}
@Test
- public void testGenerateArgumentsForCliEditor_success() {
+ void testGenerateArgumentsForCliEditor_success() {
ApexCliToscaParameters params = new ApexCliToscaParameterParser().parse(sampleArgs);
Properties optionVariableMap = new Properties();
optionVariableMap.setProperty("c", "commandFileName");
@@ -137,7 +137,7 @@ public class CliUtilsTest {
}
@Test
- public void testGenerateArgumentsForCliEditor_invalidvariable() {
+ void testGenerateArgumentsForCliEditor_invalidVariable() {
ApexCliToscaParameters params = new ApexCliToscaParameterParser().parse(sampleArgs);
Properties optionVariableMap = new Properties();
optionVariableMap.setProperty("c", "invalidFileName");
@@ -147,7 +147,7 @@ public class CliUtilsTest {
}
@Test
- public void testGenerateArgumentsForCliEditor_missingoption() {
+ void testGenerateArgumentsForCliEditor_missingOption() {
ApexCliToscaParameters params = new ApexCliToscaParameterParser().parse(sampleArgs);
Properties optionVariableMap = new Properties();
List<String> cliArgsList =
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.
diff --git a/plugins/plugins-context/plugins-context-persistence/pom.xml b/plugins/plugins-context/plugins-context-persistence/pom.xml
deleted file mode 100644
index 9d95195e7..000000000
--- a/plugins/plugins-context/plugins-context-persistence/pom.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- Copyright (C) 2016-2018 Ericsson. All rights reserved.
- ================================================================================
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-
- SPDX-License-Identifier: Apache-2.0
- ============LICENSE_END=========================================================
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.policy.apex-pdp.plugins.plugins-context</groupId>
- <artifactId>plugins-context</artifactId>
- <version>4.0.0-SNAPSHOT</version>
- </parent>
-
- <groupId>org.onap.policy.apex-pdp.plugins.plugins-context.plugins-context-persistence</groupId>
- <artifactId>plugins-context-persistence</artifactId>
- <packaging>pom</packaging>
-
- <name>${project.artifactId}</name>
- <description>Plugins for 3pps that persist context</description>
-</project>
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaAaiTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaAaiTest.java
index 9051f3688..93bbe2054 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaAaiTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaAaiTest.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,14 +21,14 @@
package org.onap.policy.apex.plugins.context.schema.avro;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.avro.generic.GenericData.Array;
import org.apache.avro.generic.GenericRecord;
-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.SchemaHelper;
import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
@@ -45,9 +45,8 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
* The Class TestAvroSchemaAai.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
- * @version
*/
-public class AvroSchemaAaiTest {
+class AvroSchemaAaiTest {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
private String aaiInventoryResponseSchema;
@@ -57,20 +56,20 @@ public class AvroSchemaAaiTest {
*
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Before
- public void initTest() throws IOException {
+ @BeforeEach
+ void initTest() throws IOException {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
ModelService.registerModel(AxContextSchemas.class, schemas);
aaiInventoryResponseSchema =
- TextFileUtils.getTextFileAsString("src/test/resources/avsc/AAIInventoryResponseItemType.avsc");
+ TextFileUtils.getTextFileAsString("src/test/resources/avsc/AAIInventoryResponseItemType.avsc");
}
/**
* Inits the context.
*/
- @Before
- public void initContext() {
+ @BeforeEach
+ void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaParameters.getSchemaHelperParameterMap().put("AVRO", new AvroSchemaHelperParameters());
@@ -81,8 +80,8 @@ public class AvroSchemaAaiTest {
/**
* Clear context.
*/
- @After
- public void clearContext() {
+ @AfterEach
+ void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
@@ -92,9 +91,9 @@ public class AvroSchemaAaiTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testAaiResponsePolicy() throws IOException {
+ void testAaiResponsePolicy() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", aaiInventoryResponseSchema);
+ new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", aaiInventoryResponseSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -105,7 +104,7 @@ public class AvroSchemaAaiTest {
final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/AAIResponse4Policy.json");
final Array<?> newArrayFull = (Array<?>) schemaHelper.createNewInstance(inString);
final String vnfName = ((GenericRecord) ((GenericRecord) newArrayFull.get(0)).get("generic_DasH_vnf"))
- .get("vnf_DasH_name").toString();
+ .get("vnf_DasH_name").toString();
assertEquals("ZRDM2MMEX39", vnfName);
}
}
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaArrayTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaArrayTest.java
index 8d7041c60..f2dd5b5e3 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaArrayTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaArrayTest.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,13 +21,13 @@
package org.onap.policy.apex.plugins.context.schema.avro;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.avro.generic.GenericData.Array;
-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.SchemaHelper;
import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
@@ -40,14 +40,12 @@ import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.utils.resources.TextFileUtils;
-// TODO: Auto-generated Javadoc
/**
* The Class TestAvroSchemaArray.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
- * @version
*/
-public class AvroSchemaArrayTest {
+class AvroSchemaArrayTest {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
private String longArraySchema;
@@ -58,8 +56,8 @@ public class AvroSchemaArrayTest {
*
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Before
- public void initTest() throws IOException {
+ @BeforeEach
+ void initTest() throws IOException {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
ModelService.registerModel(AxContextSchemas.class, schemas);
longArraySchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/ArrayExampleLong.avsc");
@@ -69,8 +67,8 @@ public class AvroSchemaArrayTest {
/**
* Inits the context.
*/
- @Before
- public void initContext() {
+ @BeforeEach
+ void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaParameters.getSchemaHelperParameterMap().put("AVRO", new AvroSchemaHelperParameters());
@@ -81,8 +79,8 @@ public class AvroSchemaArrayTest {
/**
* Clear context.
*/
- @After
- public void clearContext() {
+ @AfterEach
+ void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
@@ -92,9 +90,9 @@ public class AvroSchemaArrayTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testArrayInit() throws IOException {
+ void testArrayInit() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", addressArraySchema);
+ new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", addressArraySchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -103,10 +101,10 @@ public class AvroSchemaArrayTest {
assertEquals(0, newArrayEmpty.size());
final String inString =
- TextFileUtils.getTextFileAsString("src/test/resources/data/ArrayExampleAddressFull.json");
+ TextFileUtils.getTextFileAsString("src/test/resources/data/ArrayExampleAddressFull.json");
final Array<?> newArrayFull = (Array<?>) schemaHelper.createNewInstance(inString);
assertEquals("{\"streetaddress\": \"1600 Pennsylvania Avenue\", \"city\": \"Washington DC\"}",
- newArrayFull.get(0).toString());
+ newArrayFull.get(0).toString());
}
/**
@@ -115,9 +113,9 @@ public class AvroSchemaArrayTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testLongArrayUnmarshalMarshal() throws IOException {
+ void testLongArrayUnmarshalMarshal() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "AVRO", longArraySchema);
+ new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "AVRO", longArraySchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -132,9 +130,9 @@ public class AvroSchemaArrayTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testAddressArrayUnmarshalMarshal() throws IOException {
+ void testAddressArrayUnmarshalMarshal() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "AVRO", addressArraySchema);
+ new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "AVRO", addressArraySchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -147,7 +145,7 @@ public class AvroSchemaArrayTest {
* Test unmarshal marshal.
*
* @param schemaHelper the schema helper
- * @param fileName the file name
+ * @param fileName the file name
* @throws IOException Signals that an I/O exception has occurred.
*/
private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaEnumTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaEnumTest.java
index d3cd7a482..43d68f223 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaEnumTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaEnumTest.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 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,13 +23,13 @@
package org.onap.policy.apex.plugins.context.schema.avro;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.avro.generic.GenericData.EnumSymbol;
-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.SchemaHelper;
import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
@@ -42,14 +42,12 @@ import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
import org.onap.policy.common.parameters.ParameterService;
import org.onap.policy.common.utils.resources.TextFileUtils;
-// TODO: Auto-generated Javadoc
/**
* The Class TestAvroSchemaEnum.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
- * @version
*/
-public class AvroSchemaEnumTest {
+class AvroSchemaEnumTest {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
private String enumSchema;
@@ -59,8 +57,8 @@ public class AvroSchemaEnumTest {
*
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Before
- public void initTest() throws IOException {
+ @BeforeEach
+ void initTest() throws IOException {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
ModelService.registerModel(AxContextSchemas.class, schemas);
enumSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/EnumSchema.avsc");
@@ -69,8 +67,8 @@ public class AvroSchemaEnumTest {
/**
* Inits the context.
*/
- @Before
- public void initContext() {
+ @BeforeEach
+ void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaParameters.getSchemaHelperParameterMap().put("AVRO", new AvroSchemaHelperParameters());
@@ -81,8 +79,8 @@ public class AvroSchemaEnumTest {
/**
* Clear context.
*/
- @After
- public void clearContext() {
+ @AfterEach
+ void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
@@ -92,9 +90,9 @@ public class AvroSchemaEnumTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testEnumInit() throws IOException {
+ void testEnumInit() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", enumSchema);
+ new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", enumSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -112,9 +110,9 @@ public class AvroSchemaEnumTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testEnumUnmarshalMarshal() throws IOException {
+ void testEnumUnmarshalMarshal() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "AVRO", enumSchema);
+ new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "AVRO", enumSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -135,7 +133,7 @@ public class AvroSchemaEnumTest {
* Test unmarshal marshal.
*
* @param schemaHelper the schema helper
- * @param fileName the file name
+ * @param fileName the file name
* @throws IOException Signals that an I/O exception has occurred.
*/
private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaFixedTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaFixedTest.java
index 93797fba1..ba04226c7 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaFixedTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaFixedTest.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.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,14 +23,14 @@
package org.onap.policy.apex.plugins.context.schema.avro;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import org.apache.avro.generic.GenericData.Fixed;
-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.SchemaHelper;
import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
@@ -47,9 +47,8 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
* The Class TestAvroSchemaFixed.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
- * @version
*/
-public class AvroSchemaFixedTest {
+class AvroSchemaFixedTest {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
private String fixedSchema;
@@ -59,8 +58,8 @@ public class AvroSchemaFixedTest {
*
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Before
- public void initTest() throws IOException {
+ @BeforeEach
+ void initTest() throws IOException {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
ModelService.registerModel(AxContextSchemas.class, schemas);
fixedSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/FixedSchema.avsc");
@@ -69,8 +68,8 @@ public class AvroSchemaFixedTest {
/**
* Inits the context.
*/
- @Before
- public void initContext() {
+ @BeforeEach
+ void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaParameters.getSchemaHelperParameterMap().put("AVRO", new AvroSchemaHelperParameters());
@@ -81,8 +80,8 @@ public class AvroSchemaFixedTest {
/**
* Clear context.
*/
- @After
- public void clearContext() {
+ @AfterEach
+ void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
@@ -92,17 +91,17 @@ public class AvroSchemaFixedTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testFixedInit() throws IOException {
+ void testFixedInit() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", fixedSchema);
+ new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", fixedSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
- assertThatThrownBy(() -> schemaHelper.createNewInstance())
+ assertThatThrownBy(schemaHelper::createNewInstance)
.hasMessage("AvroTest:0.0.1: could not create an instance "
- + "of class \"org.apache.avro.generic.GenericData$Fixed\" "
- + "using the default constructor \"Fixed()\"");
+ + "of class \"org.apache.avro.generic.GenericData$Fixed\" "
+ + "using the default constructor \"Fixed()\"");
final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/FixedExampleGood.json");
final Fixed newFixedFull = (Fixed) schemaHelper.createNewInstance(inString);
assertTrue(newFixedFull.toString().startsWith("[48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65"));
@@ -115,9 +114,9 @@ public class AvroSchemaFixedTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testFixedUnmarshalMarshal() throws IOException {
+ void testFixedUnmarshalMarshal() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "AVRO", fixedSchema);
+ new AxContextSchema(new AxArtifactKey("AvroArray", "0.0.1"), "AVRO", fixedSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -140,7 +139,7 @@ public class AvroSchemaFixedTest {
* Test unmarshal marshal.
*
* @param schemaHelper the schema helper
- * @param fileName the file name
+ * @param fileName the file name
* @throws IOException Signals that an I/O exception has occurred.
*/
private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperBadSchemasTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperBadSchemasTest.java
index 5bbaf97fa..fd9d5b6e5 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperBadSchemasTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperBadSchemasTest.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.
@@ -23,9 +23,9 @@ package org.onap.policy.apex.plugins.context.schema.avro;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-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.SchemaHelperFactory;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.SchemaParameters;
@@ -40,17 +40,16 @@ import org.onap.policy.common.parameters.ParameterService;
* The Class TestAvroSchemaHelperBadSchemas.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
- * @version
*/
-public class AvroSchemaHelperBadSchemasTest {
+class AvroSchemaHelperBadSchemasTest {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
/**
* Inits the test.
*/
- @Before
- public void initTest() {
+ @BeforeEach
+ void initTest() {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
ModelService.registerModel(AxContextSchemas.class, schemas);
}
@@ -58,20 +57,20 @@ public class AvroSchemaHelperBadSchemasTest {
/**
* Inits the context.
*/
- @Before
- public void initContext() {
+ @BeforeEach
+ void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaParameters.getSchemaHelperParameterMap().put("AVRO", new AvroSchemaHelperParameters());
ParameterService.register(schemaParameters);
-
+
}
/**
* Clear context.
*/
- @After
- public void clearContext() {
+ @AfterEach
+ void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
@@ -79,7 +78,7 @@ public class AvroSchemaHelperBadSchemasTest {
* Bad schema test.
*/
@Test
- public void badSchemaTest() {
+ void badSchemaTest() {
final AxContextSchema avroBadSchema0 = new AxContextSchema(new AxArtifactKey("AvroBad0", "0.0.1"), "AVRO", "}");
schemas.getSchemasMap().put(avroBadSchema0.getKey(), avroBadSchema0);
@@ -91,25 +90,25 @@ public class AvroSchemaHelperBadSchemasTest {
assertThatThrownBy(() -> new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema1.getKey()))
.hasMessageStartingWith("AvroTest:0.0.1: avro context schema \"AvroBad1:0.0.1\" schema is invalid");
final AxContextSchema avroBadSchema2 =
- new AxContextSchema(new AxArtifactKey("AvroBad2", "0.0.1"), "AVRO", "{}");
+ new AxContextSchema(new AxArtifactKey("AvroBad2", "0.0.1"), "AVRO", "{}");
schemas.getSchemasMap().put(avroBadSchema2.getKey(), avroBadSchema2);
assertThatThrownBy(() -> new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema2.getKey()))
.hasMessageStartingWith("AvroTest:0.0.1: avro context schema \"AvroBad2:0.0.1\" schema is invalid");
final AxContextSchema avroBadSchema3 =
- new AxContextSchema(new AxArtifactKey("AvroBad3", "0.0.1"), "AVRO", "{zooby}");
+ new AxContextSchema(new AxArtifactKey("AvroBad3", "0.0.1"), "AVRO", "{zooby}");
schemas.getSchemasMap().put(avroBadSchema3.getKey(), avroBadSchema3);
assertThatThrownBy(() -> new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema3.getKey()))
.hasMessageStartingWith("AvroTest:0.0.1: avro context schema \"AvroBad3:0.0.1\" schema is invalid");
final AxContextSchema avroBadSchema4 =
- new AxContextSchema(new AxArtifactKey("AvroBad4", "0.0.1"), "AVRO", "{\"zooby\"}");
+ new AxContextSchema(new AxArtifactKey("AvroBad4", "0.0.1"), "AVRO", "{\"zooby\"}");
schemas.getSchemasMap().put(avroBadSchema4.getKey(), avroBadSchema4);
assertThatThrownBy(() -> new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema4.getKey()))
.hasMessageStartingWith("AvroTest:0.0.1: avro context schema \"AvroBad4:0.0.1\" schema is invalid");
final AxContextSchema avroBadSchema5 =
- new AxContextSchema(new AxArtifactKey("AvroBad5", "0.0.1"), "AVRO", "{\"type\": \"zooby\"}");
+ new AxContextSchema(new AxArtifactKey("AvroBad5", "0.0.1"), "AVRO", "{\"type\": \"zooby\"}");
schemas.getSchemasMap().put(avroBadSchema5.getKey(), avroBadSchema5);
assertThatThrownBy(() -> new SchemaHelperFactory().createSchemaHelper(testKey, avroBadSchema5.getKey()))
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperMarshalTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperMarshalTest.java
index 06848c9a9..4cb5c9dd3 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperMarshalTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperMarshalTest.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.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,11 +23,11 @@
package org.onap.policy.apex.plugins.context.schema.avro;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-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.SchemaHelper;
import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
@@ -43,17 +43,16 @@ import org.onap.policy.common.parameters.ParameterService;
* The Class TestAvroSchemaHelperMarshal.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
- * @version
*/
-public class AvroSchemaHelperMarshalTest {
+class AvroSchemaHelperMarshalTest {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
/**
* Inits the test.
*/
- @Before
- public void initTest() {
+ @BeforeEach
+ void initTest() {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
ModelService.registerModel(AxContextSchemas.class, schemas);
}
@@ -61,8 +60,8 @@ public class AvroSchemaHelperMarshalTest {
/**
* Inits the context.
*/
- @Before
- public void initContext() {
+ @BeforeEach
+ void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaParameters.getSchemaHelperParameterMap().put("AVRO", new AvroSchemaHelperParameters());
@@ -73,8 +72,8 @@ public class AvroSchemaHelperMarshalTest {
/**
* Clear context.
*/
- @After
- public void clearContext() {
+ @AfterEach
+ void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
@@ -82,13 +81,13 @@ public class AvroSchemaHelperMarshalTest {
* Test null marshal.
*/
@Test
- public void testNullMarshal() {
+ void testNullMarshal() {
final AxContextSchema avroNullSchema =
- new AxContextSchema(new AxArtifactKey("AvroNull", "0.0.1"), "AVRO", "{\"type\": \"null\"}");
+ new AxContextSchema(new AxArtifactKey("AvroNull", "0.0.1"), "AVRO", "{\"type\": \"null\"}");
schemas.getSchemasMap().put(avroNullSchema.getKey(), avroNullSchema);
final SchemaHelper schemaHelper0 =
- new SchemaHelperFactory().createSchemaHelper(testKey, avroNullSchema.getKey());
+ new SchemaHelperFactory().createSchemaHelper(testKey, avroNullSchema.getKey());
assertEquals("null", schemaHelper0.marshal2String(null));
assertEquals("null", schemaHelper0.marshal2String(123));
@@ -99,13 +98,13 @@ public class AvroSchemaHelperMarshalTest {
* Test boolean marshal.
*/
@Test
- public void testBooleanMarshal() {
+ void testBooleanMarshal() {
final AxContextSchema avroBooleanSchema =
- new AxContextSchema(new AxArtifactKey("AvroBoolean", "0.0.1"), "AVRO", "{\"type\": \"boolean\"}");
+ new AxContextSchema(new AxArtifactKey("AvroBoolean", "0.0.1"), "AVRO", "{\"type\": \"boolean\"}");
schemas.getSchemasMap().put(avroBooleanSchema.getKey(), avroBooleanSchema);
final SchemaHelper schemaHelper1 =
- new SchemaHelperFactory().createSchemaHelper(testKey, avroBooleanSchema.getKey());
+ new SchemaHelperFactory().createSchemaHelper(testKey, avroBooleanSchema.getKey());
assertEquals("true", schemaHelper1.marshal2String(true));
assertEquals("false", schemaHelper1.marshal2String(false));
@@ -119,13 +118,13 @@ public class AvroSchemaHelperMarshalTest {
* Test int marshal.
*/
@Test
- public void testIntMarshal() {
+ void testIntMarshal() {
final AxContextSchema avroIntSchema =
- new AxContextSchema(new AxArtifactKey("AvroInt", "0.0.1"), "AVRO", "{\"type\": \"int\"}");
+ new AxContextSchema(new AxArtifactKey("AvroInt", "0.0.1"), "AVRO", "{\"type\": \"int\"}");
schemas.getSchemasMap().put(avroIntSchema.getKey(), avroIntSchema);
final SchemaHelper schemaHelper2 =
- new SchemaHelperFactory().createSchemaHelper(testKey, avroIntSchema.getKey());
+ new SchemaHelperFactory().createSchemaHelper(testKey, avroIntSchema.getKey());
assertEquals("0", schemaHelper2.marshal2String(0));
assertEquals("1", schemaHelper2.marshal2String(1));
@@ -144,13 +143,13 @@ public class AvroSchemaHelperMarshalTest {
* Test long marshal.
*/
@Test
- public void testLongMarshal() {
+ void testLongMarshal() {
final AxContextSchema avroLongSchema =
- new AxContextSchema(new AxArtifactKey("AvroLong", "0.0.1"), "AVRO", "{\"type\": \"long\"}");
+ new AxContextSchema(new AxArtifactKey("AvroLong", "0.0.1"), "AVRO", "{\"type\": \"long\"}");
schemas.getSchemasMap().put(avroLongSchema.getKey(), avroLongSchema);
final SchemaHelper schemaHelper3 =
- new SchemaHelperFactory().createSchemaHelper(testKey, avroLongSchema.getKey());
+ new SchemaHelperFactory().createSchemaHelper(testKey, avroLongSchema.getKey());
assertEquals("0", schemaHelper3.marshal2String(0L));
assertEquals("1", schemaHelper3.marshal2String(1L));
@@ -167,13 +166,13 @@ public class AvroSchemaHelperMarshalTest {
* Test float marshal.
*/
@Test
- public void testFloatMarshal() {
+ void testFloatMarshal() {
final AxContextSchema avroFloatSchema =
- new AxContextSchema(new AxArtifactKey("AvroFloat", "0.0.1"), "AVRO", "{\"type\": \"float\"}");
+ new AxContextSchema(new AxArtifactKey("AvroFloat", "0.0.1"), "AVRO", "{\"type\": \"float\"}");
schemas.getSchemasMap().put(avroFloatSchema.getKey(), avroFloatSchema);
final SchemaHelper schemaHelper4 =
- new SchemaHelperFactory().createSchemaHelper(testKey, avroFloatSchema.getKey());
+ new SchemaHelperFactory().createSchemaHelper(testKey, avroFloatSchema.getKey());
assertEquals("0.0", schemaHelper4.marshal2String(0F));
assertEquals("1.0", schemaHelper4.marshal2String(1F));
@@ -194,13 +193,13 @@ public class AvroSchemaHelperMarshalTest {
* Test double marshal.
*/
@Test
- public void testDoubleMarshal() {
+ void testDoubleMarshal() {
final AxContextSchema avroDoubleSchema =
- new AxContextSchema(new AxArtifactKey("AvroDouble", "0.0.1"), "AVRO", "{\"type\": \"double\"}");
+ new AxContextSchema(new AxArtifactKey("AvroDouble", "0.0.1"), "AVRO", "{\"type\": \"double\"}");
schemas.getSchemasMap().put(avroDoubleSchema.getKey(), avroDoubleSchema);
final SchemaHelper schemaHelper5 =
- new SchemaHelperFactory().createSchemaHelper(testKey, avroDoubleSchema.getKey());
+ new SchemaHelperFactory().createSchemaHelper(testKey, avroDoubleSchema.getKey());
assertEquals("0.0", schemaHelper5.marshal2String(0D));
assertEquals("1.0", schemaHelper5.marshal2String(1D));
@@ -221,13 +220,13 @@ public class AvroSchemaHelperMarshalTest {
* Test string marshal.
*/
@Test
- public void testStringMarshal() {
+ void testStringMarshal() {
final AxContextSchema avroStringSchema =
- new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "AVRO", "{\"type\": \"string\"}");
+ new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "AVRO", "{\"type\": \"string\"}");
schemas.getSchemasMap().put(avroStringSchema.getKey(), avroStringSchema);
final SchemaHelper schemaHelper7 =
- new SchemaHelperFactory().createSchemaHelper(testKey, avroStringSchema.getKey());
+ new SchemaHelperFactory().createSchemaHelper(testKey, avroStringSchema.getKey());
assertEquals("\"0\"", schemaHelper7.marshal2String("0"));
assertEquals("\"1\"", schemaHelper7.marshal2String("1"));
@@ -247,9 +246,9 @@ public class AvroSchemaHelperMarshalTest {
* Test bytes marshal.
*/
@Test
- public void testBytesMarshal() {
+ void testBytesMarshal() {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "AVRO", "{\"type\": \"bytes\"}");
+ new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "AVRO", "{\"type\": \"bytes\"}");
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperUnmarshalTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperUnmarshalTest.java
index 23ac9a855..7dd1e1aca 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperUnmarshalTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaHelperUnmarshalTest.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.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,12 +23,12 @@
package org.onap.policy.apex.plugins.context.schema.avro;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.avro.util.Utf8;
-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.SchemaHelper;
import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
@@ -44,17 +44,16 @@ import org.onap.policy.common.parameters.ParameterService;
* The Class TestAvroSchemaHelperUnmarshal.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
- * @version
*/
-public class AvroSchemaHelperUnmarshalTest {
+class AvroSchemaHelperUnmarshalTest {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
/**
* Inits the test.
*/
- @Before
- public void initTest() {
+ @BeforeEach
+ void initTest() {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
ModelService.registerModel(AxContextSchemas.class, schemas);
}
@@ -62,8 +61,8 @@ public class AvroSchemaHelperUnmarshalTest {
/**
* Inits the context.
*/
- @Before
- public void initContext() {
+ @BeforeEach
+ void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaParameters.getSchemaHelperParameterMap().put("AVRO", new AvroSchemaHelperParameters());
@@ -74,8 +73,8 @@ public class AvroSchemaHelperUnmarshalTest {
/**
* Clear context.
*/
- @After
- public void clearContext() {
+ @AfterEach
+ void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
@@ -83,13 +82,13 @@ public class AvroSchemaHelperUnmarshalTest {
* Test null unmarshal.
*/
@Test
- public void testNullUnmarshal() {
+ void testNullUnmarshal() {
final AxContextSchema avroNullSchema = new AxContextSchema(new AxArtifactKey("AvroNull", "0.0.1"), "AVRO",
- "{\"type\": \"null\"}");
+ "{\"type\": \"null\"}");
schemas.getSchemasMap().put(avroNullSchema.getKey(), avroNullSchema);
final SchemaHelper schemaHelper0 = new SchemaHelperFactory().createSchemaHelper(testKey,
- avroNullSchema.getKey());
+ avroNullSchema.getKey());
assertThatThrownBy(schemaHelper0::createNewInstance)
.hasMessage("AvroTest:0.0.1: could not create an instance, schema class for the schema is null");
@@ -103,13 +102,13 @@ public class AvroSchemaHelperUnmarshalTest {
* Test boolean unmarshal.
*/
@Test
- public void testBooleanUnmarshal() {
+ void testBooleanUnmarshal() {
final AxContextSchema avroBooleanSchema = new AxContextSchema(new AxArtifactKey("AvroBoolean", "0.0.1"), "AVRO",
- "{\"type\": \"boolean\"}");
+ "{\"type\": \"boolean\"}");
schemas.getSchemasMap().put(avroBooleanSchema.getKey(), avroBooleanSchema);
final SchemaHelper schemaHelper1 = new SchemaHelperFactory().createSchemaHelper(testKey,
- avroBooleanSchema.getKey());
+ avroBooleanSchema.getKey());
assertThatThrownBy(schemaHelper1::createNewInstance)
.hasMessage("AvroTest:0.0.1: could not create an instance of class \"java.lang.Boolean\" "
@@ -128,13 +127,13 @@ public class AvroSchemaHelperUnmarshalTest {
* Test int unmarshal.
*/
@Test
- public void testIntUnmarshal() {
+ void testIntUnmarshal() {
final AxContextSchema avroIntSchema = new AxContextSchema(new AxArtifactKey("AvroInt", "0.0.1"), "AVRO",
- "{\"type\": \"int\"}");
+ "{\"type\": \"int\"}");
schemas.getSchemasMap().put(avroIntSchema.getKey(), avroIntSchema);
final SchemaHelper schemaHelper2 = new SchemaHelperFactory().createSchemaHelper(testKey,
- avroIntSchema.getKey());
+ avroIntSchema.getKey());
assertThatThrownBy(schemaHelper2::createNewInstance)
.hasMessage("AvroTest:0.0.1: could not create an instance of class \"java.lang.Integer\" "
@@ -160,13 +159,13 @@ public class AvroSchemaHelperUnmarshalTest {
* Test long unmarshal.
*/
@Test
- public void testLongUnmarshal() {
+ void testLongUnmarshal() {
final AxContextSchema avroLongSchema = new AxContextSchema(new AxArtifactKey("AvroLong", "0.0.1"), "AVRO",
- "{\"type\": \"long\"}");
+ "{\"type\": \"long\"}");
schemas.getSchemasMap().put(avroLongSchema.getKey(), avroLongSchema);
final SchemaHelper schemaHelper3 = new SchemaHelperFactory().createSchemaHelper(testKey,
- avroLongSchema.getKey());
+ avroLongSchema.getKey());
assertThatThrownBy(schemaHelper3::createNewInstance)
.hasMessage("AvroTest:0.0.1: could not create an instance of class \"java.lang.Long\" "
@@ -194,13 +193,13 @@ public class AvroSchemaHelperUnmarshalTest {
* Test float unmarshal.
*/
@Test
- public void testFloatUnmarshal() {
+ void testFloatUnmarshal() {
final AxContextSchema avroFloatSchema = new AxContextSchema(new AxArtifactKey("AvroFloat", "0.0.1"), "AVRO",
- "{\"type\": \"float\"}");
+ "{\"type\": \"float\"}");
schemas.getSchemasMap().put(avroFloatSchema.getKey(), avroFloatSchema);
final SchemaHelper schemaHelper4 = new SchemaHelperFactory().createSchemaHelper(testKey,
- avroFloatSchema.getKey());
+ avroFloatSchema.getKey());
assertThatThrownBy(schemaHelper4::createNewInstance)
.hasMessage("AvroTest:0.0.1: could not create an instance of class \"java.lang.Float\" "
@@ -226,13 +225,13 @@ public class AvroSchemaHelperUnmarshalTest {
* Test double unmarshal.
*/
@Test
- public void testDoubleUnmarshal() {
+ void testDoubleUnmarshal() {
final AxContextSchema avroDoubleSchema = new AxContextSchema(new AxArtifactKey("AvroDouble", "0.0.1"), "AVRO",
- "{\"type\": \"double\"}");
+ "{\"type\": \"double\"}");
schemas.getSchemasMap().put(avroDoubleSchema.getKey(), avroDoubleSchema);
final SchemaHelper schemaHelper5 = new SchemaHelperFactory().createSchemaHelper(testKey,
- avroDoubleSchema.getKey());
+ avroDoubleSchema.getKey());
assertThatThrownBy(schemaHelper5::createNewInstance)
.hasMessage("AvroTest:0.0.1: could not create an instance of class \"java.lang.Double\" "
@@ -258,13 +257,13 @@ public class AvroSchemaHelperUnmarshalTest {
* Test string unmarshal.
*/
@Test
- public void testStringUnmarshal() {
+ void testStringUnmarshal() {
final AxContextSchema avroStringSchema = new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "AVRO",
- "{\"type\": \"string\"}");
+ "{\"type\": \"string\"}");
schemas.getSchemasMap().put(avroStringSchema.getKey(), avroStringSchema);
final SchemaHelper schemaHelper7 = new SchemaHelperFactory().createSchemaHelper(testKey,
- avroStringSchema.getKey());
+ avroStringSchema.getKey());
assertEquals("", schemaHelper7.createNewInstance(""));
assertEquals("1.2345E06", schemaHelper7.createNewInstance("1.2345E06"));
@@ -288,9 +287,9 @@ public class AvroSchemaHelperUnmarshalTest {
* Test bytes unmarshal.
*/
@Test
- public void testBytesUnmarshal() {
+ void testBytesUnmarshal() {
final AxContextSchema avroSchema = new AxContextSchema(new AxArtifactKey("AvroString", "0.0.1"), "AVRO",
- "{\"type\": \"bytes\"}");
+ "{\"type\": \"bytes\"}");
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaMapTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaMapTest.java
index a3e85ed91..2411b0bb2 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaMapTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaMapTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020-2021,2023 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2021, 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,18 +22,19 @@
package org.onap.policy.apex.plugins.context.schema.avro;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.util.Utf8;
-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.ContextRuntimeException;
import org.onap.policy.apex.context.SchemaHelper;
import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory;
@@ -51,9 +52,8 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
* The Class TestAvroSchemaMap.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
- * @version
*/
-public class AvroSchemaMapTest {
+class AvroSchemaMapTest {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
private String longMapSchema;
@@ -65,21 +65,21 @@ public class AvroSchemaMapTest {
*
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Before
- public void initTest() throws IOException {
+ @BeforeEach
+ void initTest() throws IOException {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
ModelService.registerModel(AxContextSchemas.class, schemas);
longMapSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/MapExampleLong.avsc");
addressMapSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/MapExampleAddress.avsc");
addressMapSchemaInvalidFields =
- TextFileUtils.getTextFileAsString("src/test/resources/avsc/MapExampleAddressInvalidFields.avsc");
+ TextFileUtils.getTextFileAsString("src/test/resources/avsc/MapExampleAddressInvalidFields.avsc");
}
/**
* Inits the context.
*/
- @Before
- public void initContext() {
+ @BeforeEach
+ void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaParameters.getSchemaHelperParameterMap().put("AVRO", new AvroSchemaHelperParameters());
@@ -89,8 +89,8 @@ public class AvroSchemaMapTest {
/**
* Clear context.
*/
- @After
- public void clearContext() {
+ @AfterEach
+ void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
@@ -100,15 +100,15 @@ public class AvroSchemaMapTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testValidSubstitutions() throws IOException {
+ void testValidSubstitutions() throws IOException {
final String subst1 = "{\"type\":\"record\",\"name\":\"Subst1\","
- + "\"fields\":[{\"name\": \"A_DasH_B\",\"type\":\"string\"}]}";
+ + "\"fields\":[{\"name\": \"A_DasH_B\",\"type\":\"string\"}]}";
final AxContextSchema avroSubstSchema1 = new AxContextSchema(
- new AxArtifactKey("AvroSubst1", "0.0.1"), "AVRO", subst1);
+ new AxArtifactKey("AvroSubst1", "0.0.1"), "AVRO", subst1);
schemas.getSchemasMap().put(avroSubstSchema1.getKey(), avroSubstSchema1);
SchemaHelper schemaHelperSubst1 = new SchemaHelperFactory()
- .createSchemaHelper(testKey, avroSubstSchema1.getKey());
+ .createSchemaHelper(testKey, avroSubstSchema1.getKey());
final GenericRecord subst1A = (GenericRecord) schemaHelperSubst1.unmarshal("{\"A-B\":\"foo\"}");
assertEquals(new Utf8("foo"), subst1A.get("A_DasH_B"));
assertThatThrownBy(() -> subst1A.get("A-B")).hasMessage("Not a valid schema field: A-B");
@@ -119,13 +119,13 @@ public class AvroSchemaMapTest {
assertEquals("Expected string. Got VALUE_NUMBER_INT", exception1.getCause().getMessage());
final String subst2 = "{\"type\":\"record\",\"name\":\"Subst2\","
- + "\"fields\":[{\"name\": \"C_DoT_D\",\"type\":\"int\"}]}";
+ + "\"fields\":[{\"name\": \"C_DoT_D\",\"type\":\"int\"}]}";
final AxContextSchema avroSubstSchema2 = new AxContextSchema(
- new AxArtifactKey("AvroSubst2", "0.0.1"), "AVRO", subst2);
+ new AxArtifactKey("AvroSubst2", "0.0.1"), "AVRO", subst2);
schemas.getSchemasMap().put(avroSubstSchema2.getKey(), avroSubstSchema2);
final SchemaHelper schemaHelperSubst2 = new SchemaHelperFactory()
- .createSchemaHelper(testKey, avroSubstSchema2.getKey());
+ .createSchemaHelper(testKey, avroSubstSchema2.getKey());
final GenericRecord subst2A = (GenericRecord) schemaHelperSubst2.unmarshal("{\"C.D\":123}");
assertEquals(123, subst2A.get("C_DoT_D"));
assertThatThrownBy(() -> subst2A.get("C.D")).hasMessage("Not a valid schema field: C.D");
@@ -136,13 +136,13 @@ public class AvroSchemaMapTest {
assertEquals("Expected int. Got VALUE_STRING", exception2.getCause().getMessage());
final String subst3 = "{\"type\":\"record\",\"name\":\"Subst3\","
- + "\"fields\":[{\"name\": \"E_ColoN_F\",\"type\":\"boolean\"}]}";
+ + "\"fields\":[{\"name\": \"E_ColoN_F\",\"type\":\"boolean\"}]}";
final AxContextSchema avroSubstSchema3 = new AxContextSchema(
- new AxArtifactKey("AvroSubst3", "0.0.1"), "AVRO", subst3);
+ new AxArtifactKey("AvroSubst3", "0.0.1"), "AVRO", subst3);
schemas.getSchemasMap().put(avroSubstSchema3.getKey(), avroSubstSchema3);
final SchemaHelper schemaHelperSubst3 = new SchemaHelperFactory()
- .createSchemaHelper(testKey, avroSubstSchema3.getKey());
+ .createSchemaHelper(testKey, avroSubstSchema3.getKey());
final GenericRecord subst3A = (GenericRecord) schemaHelperSubst3.unmarshal("{\"E:F\":true}");
assertEquals(true, subst3A.get("E_ColoN_F"));
assertThatThrownBy(() -> subst3A.get("E:F")).hasMessage("Not a valid schema field: E:F");
@@ -159,11 +159,11 @@ public class AvroSchemaMapTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testInValidSubstitutions() throws IOException {
+ void testInValidSubstitutions() throws IOException {
final String fail1 = "{\"type\":\"record\",\"name\":\"Fail1\","
- + "\"fields\":[{\"name\": \"A-B\",\"type\":\"string\"}]}";
+ + "\"fields\":[{\"name\": \"A-B\",\"type\":\"string\"}]}";
final AxContextSchema avroFailSchema1 = new AxContextSchema(
- new AxArtifactKey("AvroFail1", "0.0.1"), "AVRO", fail1);
+ new AxArtifactKey("AvroFail1", "0.0.1"), "AVRO", fail1);
schemas.getSchemasMap().put(avroFailSchema1.getKey(), avroFailSchema1);
SchemaHelperFactory sh = new SchemaHelperFactory();
@@ -174,9 +174,9 @@ public class AvroSchemaMapTest {
assertEquals("Illegal character in: A-B", exception1.getCause().getMessage());
final String fail2 = "{\"type\":\"record\",\"name\":\"Fail2\","
- + "\"fields\":[{\"name\": \"C.D\",\"type\":\"int\"}]}";
+ + "\"fields\":[{\"name\": \"C.D\",\"type\":\"int\"}]}";
final AxContextSchema avroFailSchema2 = new AxContextSchema(
- new AxArtifactKey("AvroFail2", "0.0.1"), "AVRO", fail2);
+ new AxArtifactKey("AvroFail2", "0.0.1"), "AVRO", fail2);
schemas.getSchemasMap().put(avroFailSchema2.getKey(), avroFailSchema2);
AxArtifactKey ak2 = avroFailSchema2.getKey();
@@ -186,9 +186,9 @@ public class AvroSchemaMapTest {
assertEquals("Illegal character in: C.D", exception2.getCause().getMessage());
final String fail3 = "{\"type\":\"record\",\"name\":\"Fail3\","
- + "\"fields\":[{\"name\": \"E:F\",\"type\":\"boolean\"}]}";
+ + "\"fields\":[{\"name\": \"E:F\",\"type\":\"boolean\"}]}";
final AxContextSchema avroFailSchema3 = new AxContextSchema(
- new AxArtifactKey("AvroFail3", "0.0.1"), "AVRO", fail3);
+ new AxArtifactKey("AvroFail3", "0.0.1"), "AVRO", fail3);
schemas.getSchemasMap().put(avroFailSchema3.getKey(), avroFailSchema3);
AxArtifactKey ak3 = avroFailSchema3.getKey();
final Throwable exception3 = assertThrows(ContextRuntimeException.class,
@@ -203,9 +203,9 @@ public class AvroSchemaMapTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testMapInit() throws IOException {
+ void testMapInit() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", addressMapSchema);
+ new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", addressMapSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -217,7 +217,7 @@ public class AvroSchemaMapTest {
final HashMap<?, ?> newMapFull = (HashMap<?, ?>) schemaHelper.createNewInstance(inString);
assertEquals("{\"streetaddress\": \"221 B Baker St.\", \"city\": \"London\"}",
- newMapFull.get(new Utf8("address2")).toString());
+ newMapFull.get(new Utf8("address2")).toString());
}
/**
@@ -226,9 +226,9 @@ public class AvroSchemaMapTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testLongMapUnmarshalMarshal() throws IOException {
+ void testLongMapUnmarshalMarshal() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroMap", "0.0.1"), "AVRO", longMapSchema);
+ new AxContextSchema(new AxArtifactKey("AvroMap", "0.0.1"), "AVRO", longMapSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -243,9 +243,9 @@ public class AvroSchemaMapTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testAddressMapUnmarshalMarshal() throws IOException {
+ void testAddressMapUnmarshalMarshal() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroMap", "0.0.1"), "AVRO", addressMapSchema);
+ new AxContextSchema(new AxArtifactKey("AvroMap", "0.0.1"), "AVRO", addressMapSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -260,9 +260,9 @@ public class AvroSchemaMapTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testSubRecordCreateRecord() throws IOException {
+ void testSubRecordCreateRecord() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroMap", "0.0.1"), "AVRO", addressMapSchema);
+ new AxContextSchema(new AxArtifactKey("AvroMap", "0.0.1"), "AVRO", addressMapSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -278,9 +278,9 @@ public class AvroSchemaMapTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testAddressMapUnmarshalMarshalInvalidFields() throws IOException {
+ void testAddressMapUnmarshalMarshalInvalidFields() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroMap", "0.0.1"), "AVRO", addressMapSchemaInvalidFields);
+ new AxContextSchema(new AxArtifactKey("AvroMap", "0.0.1"), "AVRO", addressMapSchemaInvalidFields);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -290,7 +290,7 @@ public class AvroSchemaMapTest {
String vals = TextFileUtils.getTextFileAsString("src/test/resources/data/MapExampleAddressInvalidFields.json");
final HashMap<?, ?> newMapFull = (HashMap<?, ?>) schemaHelper.createNewInstance(vals);
final String expect = "{\"street_DasH_address\": \"Wayne Manor\", \"the_DoT_city\": \"Gotham City\", "
- + "\"the_ColoN_code\": \"BatCave7\"}";
+ + "\"the_ColoN_code\": \"BatCave7\"}";
assertEquals(expect, newMapFull.get(new Utf8("address_DoT_3")).toString());
}
@@ -298,7 +298,7 @@ public class AvroSchemaMapTest {
* Test unmarshal marshal.
*
* @param schemaHelper the schema helper
- * @param fileName the file name
+ * @param fileName the file name
* @throws IOException Signals that an I/O exception has occurred.
*/
private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
@@ -311,7 +311,7 @@ public class AvroSchemaMapTest {
TextFileUtils.putStringAsFile(outString, tempOutFile);
final String decodeEncodeInString = TextFileUtils.getTextFileAsString(fileName);
- tempOutFile.delete();
+ assertTrue(tempOutFile.delete());
final HashMap<?, ?> secondDecodedMap = (HashMap<?, ?>) schemaHelper.unmarshal(decodeEncodeInString);
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaRecordTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaRecordTest.java
index 3a81584f0..a2a8bdd61 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaRecordTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/AvroSchemaRecordTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020,2023 Nordix Foundation.
+ * Modifications Copyright (C) 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.
@@ -22,14 +22,15 @@
package org.onap.policy.apex.plugins.context.schema.avro;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.io.IOException;
import org.apache.avro.generic.GenericRecord;
-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.SchemaHelper;
import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
@@ -46,9 +47,8 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
* The Class TestAvroSchemaRecord.
*
* @author Liam Fallon (liam.fallon@ericsson.com)
- * @version
*/
-public class AvroSchemaRecordTest {
+class AvroSchemaRecordTest {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
private String recordSchema;
@@ -61,22 +61,22 @@ public class AvroSchemaRecordTest {
*
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Before
- public void initTest() throws IOException {
+ @BeforeEach
+ void initTest() throws IOException {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
ModelService.registerModel(AxContextSchemas.class, schemas);
recordSchema = TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExample.avsc");
recordSchemaVpn = TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExampleVPN.avsc");
recordSchemaVpnReuse = TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExampleVPNReuse.avsc");
recordSchemaInvalidFields =
- TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExampleInvalidFields.avsc");
+ TextFileUtils.getTextFileAsString("src/test/resources/avsc/RecordExampleInvalidFields.avsc");
}
/**
* Inits the context.
*/
- @Before
- public void initContext() {
+ @BeforeEach
+ void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaParameters.getSchemaHelperParameterMap().put("AVRO", new AvroSchemaHelperParameters());
@@ -87,8 +87,8 @@ public class AvroSchemaRecordTest {
/**
* Clear context.
*/
- @After
- public void clearContext() {
+ @AfterEach
+ void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
@@ -98,15 +98,15 @@ public class AvroSchemaRecordTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testRecordInit() throws IOException {
+ void testRecordInit() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", recordSchema);
+ new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", recordSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
final GenericRecord newRecordEmpty = (GenericRecord) schemaHelper.createNewInstance();
- assertEquals(null, newRecordEmpty.get("passwordHash"));
+ assertNull(newRecordEmpty.get("passwordHash"));
final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/RecordExampleFull.json");
final GenericRecord newRecordFull = (GenericRecord) schemaHelper.createNewInstance(inString);
@@ -119,9 +119,9 @@ public class AvroSchemaRecordTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testRecordUnmarshalMarshal() throws IOException {
+ void testRecordUnmarshalMarshal() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", recordSchema);
+ new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", recordSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -133,12 +133,11 @@ public class AvroSchemaRecordTest {
/**
* Test record create.
*
- * @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testRecordCreateRecord() throws IOException {
+ void testRecordCreateRecord() {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", recordSchema);
+ new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", recordSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -159,9 +158,9 @@ public class AvroSchemaRecordTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testRecordUnmarshalMarshalInvalid() throws IOException {
+ void testRecordUnmarshalMarshalInvalid() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", recordSchemaInvalidFields);
+ new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", recordSchemaInvalidFields);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -175,9 +174,9 @@ public class AvroSchemaRecordTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testVpnRecordUnmarshalMarshal() throws IOException {
+ void testVpnRecordUnmarshalMarshal() throws IOException {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", recordSchemaVpn);
+ new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", recordSchemaVpn);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
@@ -188,12 +187,11 @@ public class AvroSchemaRecordTest {
/**
* Test VPN record reuse.
*
- * @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testVpnRecordReuse() throws IOException {
+ void testVpnRecordReuse() {
final AxContextSchema avroSchema =
- new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", recordSchemaVpnReuse);
+ new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", recordSchemaVpnReuse);
assertNotNull(avroSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
@@ -205,7 +203,7 @@ public class AvroSchemaRecordTest {
* Test unmarshal marshal.
*
* @param schemaHelper the schema helper
- * @param fileName the file name
+ * @param fileName the file name
* @throws IOException Signals that an I/O exception has occurred.
*/
private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/HealthCheckSchemaTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/HealthCheckSchemaTest.java
index 4691927eb..390381e1b 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/HealthCheckSchemaTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-avro/src/test/java/org/onap/policy/apex/plugins/context/schema/avro/HealthCheckSchemaTest.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,16 +21,16 @@
package org.onap.policy.apex.plugins.context.schema.avro;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
import org.apache.avro.Schema;
import org.apache.avro.generic.GenericData;
import org.apache.avro.generic.GenericData.Record;
import org.apache.avro.generic.GenericRecord;
-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.SchemaHelper;
import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
@@ -48,7 +48,7 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class HealthCheckSchemaTest {
+class HealthCheckSchemaTest {
private final AxKey testKey = new AxArtifactKey("AvroTest", "0.0.1");
private AxContextSchemas schemas;
private String healthCheckSchema;
@@ -58,8 +58,8 @@ public class HealthCheckSchemaTest {
*
* @throws IOException Signals that an I/O exception has occurred.
*/
- @Before
- public void initTest() throws IOException {
+ @BeforeEach
+ void initTest() throws IOException {
schemas = new AxContextSchemas(new AxArtifactKey("AvroSchemas", "0.0.1"));
ModelService.registerModel(AxContextSchemas.class, schemas);
@@ -69,8 +69,8 @@ public class HealthCheckSchemaTest {
/**
* Inits the context.
*/
- @Before
- public void initContext() {
+ @BeforeEach
+ void initContext() {
SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaParameters.getSchemaHelperParameterMap().put("AVRO", new AvroSchemaHelperParameters());
@@ -81,8 +81,8 @@ public class HealthCheckSchemaTest {
/**
* Clear context.
*/
- @After
- public void clearContext() {
+ @AfterEach
+ void clearContext() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
@@ -92,14 +92,14 @@ public class HealthCheckSchemaTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testHealthCheck() throws IOException {
+ void testHealthCheck() throws IOException {
final AxContextSchema avroSchema =
new AxContextSchema(new AxArtifactKey("AvroRecord", "0.0.1"), "AVRO", healthCheckSchema);
schemas.getSchemasMap().put(avroSchema.getKey(), avroSchema);
final SchemaHelper schemaHelper = new SchemaHelperFactory().createSchemaHelper(testKey, avroSchema.getKey());
- testUnmarshalMarshal(schemaHelper, "src/test/resources/data/HealthCheckEvent.json");
+ testUnmarshalMarshal(schemaHelper);
final GenericRecord healthCheckRecord = (Record) schemaHelper.createNewInstance();
final Schema healthCheckRecordSchema = healthCheckRecord.getSchema();
@@ -107,7 +107,7 @@ public class HealthCheckSchemaTest {
final GenericRecord inputRecord = new GenericData.Record(healthCheckRecordSchema.getField("input").schema());
final Schema inputRecordRecordSchema = inputRecord.getSchema();
- final GenericRecord actionIndentifiersRecord =
+ final GenericRecord actionIdentifiersRecord =
new GenericData.Record(inputRecordRecordSchema.getField("action_DasH_identifiers").schema());
final GenericRecord commonHeaderRecord =
@@ -118,7 +118,7 @@ public class HealthCheckSchemaTest {
new GenericData.Record(commonHeaderRecordSchema.getField("flags").schema());
healthCheckRecord.put("input", inputRecord);
- inputRecord.put("action_DasH_identifiers", actionIndentifiersRecord);
+ inputRecord.put("action_DasH_identifiers", actionIdentifiersRecord);
inputRecord.put("common_DasH_header", commonHeaderRecord);
commonHeaderRecord.put("flags", commonHeaderFlagsRecord);
@@ -126,7 +126,7 @@ public class HealthCheckSchemaTest {
inputRecord.put("payload", "{\"host-ip-address\":\"131.160.203.125\",\"input.url\":\"131.160.203.125/afr\","
+ "\"request-action-type\":\"GET\",\"request-action\":\"AFR\"}");
- actionIndentifiersRecord.put("vnf_DasH_id", "49414df5-3482-4fd8-9952-c463dff2770b");
+ actionIdentifiersRecord.put("vnf_DasH_id", "49414df5-3482-4fd8-9952-c463dff2770b");
commonHeaderRecord.put("request_DasH_id", "afr-request3");
commonHeaderRecord.put("originator_DasH_id", "AFR");
@@ -140,18 +140,17 @@ public class HealthCheckSchemaTest {
final String eventString = TextFileUtils.getTextFileAsString("src/test/resources/data/HealthCheckEvent.json");
final String outString = schemaHelper.marshal2String(healthCheckRecord);
- assertEquals(eventString.toString().replaceAll("\\s+", ""), outString.replaceAll("\\s+", ""));
+ assertEquals(eventString.replaceAll("\\s+", ""), outString.replaceAll("\\s+", ""));
}
/**
* Test unmarshal marshal.
*
* @param schemaHelper the schema helper
- * @param fileName the file name
* @throws IOException Signals that an I/O exception has occurred.
*/
- private void testUnmarshalMarshal(final SchemaHelper schemaHelper, final String fileName) throws IOException {
- final String inString = TextFileUtils.getTextFileAsString(fileName);
+ private void testUnmarshalMarshal(final SchemaHelper schemaHelper) throws IOException {
+ final String inString = TextFileUtils.getTextFileAsString("src/test/resources/data/HealthCheckEvent.json");
final GenericRecord decodedObject = (GenericRecord) schemaHelper.unmarshal(inString);
final String outString = schemaHelper.marshal2String(decodedObject);
assertEquals(inString.replaceAll("\\s+", ""), outString.replaceAll("\\s+", ""));
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/src/test/java/org/onap/policy/apex/plugins/context/schema/json/CommonTestData.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/src/test/java/org/onap/policy/apex/plugins/context/schema/json/CommonTestData.java
index ce03678c9..7a7daa2bd 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/src/test/java/org/onap/policy/apex/plugins/context/schema/json/CommonTestData.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/src/test/java/org/onap/policy/apex/plugins/context/schema/json/CommonTestData.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,9 +22,9 @@
package org.onap.policy.apex.plugins.context.schema.json;
import java.io.IOException;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.BeforeClass;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
import org.onap.policy.apex.context.SchemaHelper;
import org.onap.policy.apex.context.impl.schema.SchemaHelperFactory;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
@@ -62,7 +63,7 @@ public class CommonTestData {
/**
* Setup before all tests.
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws IOException {
COMMONHEADERTYPE_DRAFT04 =
TextFileUtils.getTextFileAsString("src/test/resources/schema/commonHeaderType_draft04.json");
@@ -81,7 +82,7 @@ public class CommonTestData {
/**
* Setup before test.
*/
- @Before
+ @BeforeEach
public void setUp() {
schemas = new AxContextSchemas(new AxArtifactKey("JsonSchema", VERSION));
ModelService.registerModel(AxContextSchemas.class, schemas);
@@ -95,7 +96,7 @@ public class CommonTestData {
/**
* Teardown after test.
*/
- @After
+ @AfterEach
public void tearDown() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
ModelService.clear();
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/src/test/java/org/onap/policy/apex/plugins/context/schema/json/JsonSchemaHelperMarshalTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/src/test/java/org/onap/policy/apex/plugins/context/schema/json/JsonSchemaHelperMarshalTest.java
index 15458199a..b129330ce 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/src/test/java/org/onap/policy/apex/plugins/context/schema/json/JsonSchemaHelperMarshalTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/src/test/java/org/onap/policy/apex/plugins/context/schema/json/JsonSchemaHelperMarshalTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,16 +29,16 @@ import com.google.gson.JsonObject;
import com.worldturner.medeia.api.ValidationFailedException;
import java.util.ArrayList;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.coder.CoderException;
-public class JsonSchemaHelperMarshalTest extends CommonTestData {
+class JsonSchemaHelperMarshalTest extends CommonTestData {
/**
* Test Boolean.
*/
@Test
- public void testBooleanMarshal() {
+ void testBooleanMarshal() {
var schemaHelper = createSchema(BOOLEAN_SCHEMA);
assertThat(schemaHelper.marshal2String(Boolean.TRUE)).isEqualTo("true");
}
@@ -46,7 +47,7 @@ public class JsonSchemaHelperMarshalTest extends CommonTestData {
* Test null.
*/
@Test
- public void testNullMarshal() {
+ void testNullMarshal() {
var schemaHelper = createSchema(NULL_SCHEMA);
assertThat(schemaHelper.marshal2String(null)).isEqualTo("null");
}
@@ -57,7 +58,7 @@ public class JsonSchemaHelperMarshalTest extends CommonTestData {
* @throws CoderException the coder exception
*/
@Test
- public void testArrayMarshal() throws CoderException {
+ void testArrayMarshal() throws CoderException {
var schemaHelper = createSchema(MEASUREMENTGROUPS_TYPE);
var object = coder.decode(MEASUREMENTGROUPS, Object.class);
assertThat(object).isInstanceOf(ArrayList.class);
@@ -73,7 +74,7 @@ public class JsonSchemaHelperMarshalTest extends CommonTestData {
* @throws CoderException the coderException
*/
@Test
- public void testObjectSchemaDraft04_valid() throws CoderException {
+ void testObjectSchemaDraft04_valid() throws CoderException {
var dataAsObject = coder.decode(COMMONHEADER, Map.class);
var dataReturned = validateAndMarshal(COMMONHEADERTYPE_DRAFT04, dataAsObject, true);
assertThat(dataReturned).isEqualTo(COMMONHEADER);
@@ -85,7 +86,7 @@ public class JsonSchemaHelperMarshalTest extends CommonTestData {
* @throws CoderException the coderException
*/
@Test
- public void testObjectSchemaDraft07_valid() throws CoderException {
+ void testObjectSchemaDraft07_valid() throws CoderException {
var dataAsObject = coder.decode(COMMONHEADER, Map.class);
var dataReturned = validateAndMarshal(COMMONHEADERTYPE_DRAFT07, dataAsObject, true);
assertThat(dataReturned).isEqualTo(COMMONHEADER);
@@ -98,7 +99,7 @@ public class JsonSchemaHelperMarshalTest extends CommonTestData {
* @throws CoderException the coderException
*/
@Test
- public void testObjectSchema_fieldMissing() throws CoderException {
+ void testObjectSchema_fieldMissing() throws CoderException {
var dataAsObject = coder.decode(COMMONHEADER, Map.class);
dataAsObject.remove(TEST_ID);
assertThatThrownBy(() -> validateAndMarshal(COMMONHEADERTYPE_DRAFT07, dataAsObject, true))
@@ -112,7 +113,7 @@ public class JsonSchemaHelperMarshalTest extends CommonTestData {
* @throws CoderException the coderException
*/
@Test
- public void testObjectSchema_OptionalField() throws CoderException {
+ void testObjectSchema_OptionalField() throws CoderException {
var dataAsObject = coder.decode(COMMONHEADER, Map.class);
var dataAsjsonObject = coder.decode(COMMONHEADER, JsonObject.class);
dataAsObject.remove(TEST_ID);
diff --git a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/src/test/java/org/onap/policy/apex/plugins/context/schema/json/JsonSchemaHelperUnmarshalTest.java b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/src/test/java/org/onap/policy/apex/plugins/context/schema/json/JsonSchemaHelperUnmarshalTest.java
index 11c8638de..d0059f26f 100644
--- a/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/src/test/java/org/onap/policy/apex/plugins/context/schema/json/JsonSchemaHelperUnmarshalTest.java
+++ b/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/src/test/java/org/onap/policy/apex/plugins/context/schema/json/JsonSchemaHelperUnmarshalTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,19 +28,19 @@ import com.google.gson.JsonObject;
import com.worldturner.medeia.api.ValidationFailedException;
import java.util.ArrayList;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.context.ContextRuntimeException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema;
import org.onap.policy.common.utils.coder.CoderException;
-public class JsonSchemaHelperUnmarshalTest extends CommonTestData {
+class JsonSchemaHelperUnmarshalTest extends CommonTestData {
/**
* Test Boolean.
*/
@Test
- public void testBooleanUnmarshal() {
+ void testBooleanUnmarshal() {
var schemaHelper = createSchema(BOOLEAN_SCHEMA);
assertThat(schemaHelper.createNewInstance(BOOLEAN_DATA)).isInstanceOf(Boolean.class).isEqualTo(Boolean.TRUE);
}
@@ -48,30 +49,31 @@ public class JsonSchemaHelperUnmarshalTest extends CommonTestData {
* Test null.
*/
@Test
- public void testNullUnmarshal() {
+ void testNullUnmarshal() {
var schemaHelper = createSchema(NULL_SCHEMA);
- assertThat(schemaHelper.createNewInstance(NULL_DATA)).isEqualTo(null);
+ assertThat(schemaHelper.createNewInstance(NULL_DATA)).isNull();
}
/**
* Test Array.
*/
@Test
- public void testArrayUnmarshal() {
+ void testArrayUnmarshal() {
var schemaHelper = createSchema(MEASUREMENTGROUPS_TYPE);
var obj = schemaHelper.createNewInstance(MEASUREMENTGROUPS);
assertThat(obj).isInstanceOf(ArrayList.class);
}
/**
- * Test invlaid schema.
+ * Test invalid schema.
*/
@Test
- public void testSchemaInvalid() {
+ void testSchemaInvalid() {
String schemaDef = "{\"type\": \"object\"}";
final AxContextSchema jsonSchema =
new AxContextSchema(new AxArtifactKey("JsonObject", VERSION), JSON, schemaDef);
- assertThatThrownBy(() -> new JsonSchemaHelper().init(testKey, jsonSchema))
+ var jsonSchemaHelper = new JsonSchemaHelper();
+ assertThatThrownBy(() -> jsonSchemaHelper.init(testKey, jsonSchema))
.isInstanceOf(ContextRuntimeException.class).hasMessageContaining("schema is invalid");
}
@@ -81,7 +83,7 @@ public class JsonSchemaHelperUnmarshalTest extends CommonTestData {
* @throws CoderException the coderException
*/
@Test
- public void testObjectSchemaDraft04_valid() throws CoderException {
+ void testObjectSchemaDraft04_valid() throws CoderException {
var dataAsObject = coder.decode(COMMONHEADER, Map.class);
var dataReturned = validateAndUnmarshal(COMMONHEADERTYPE_DRAFT04, COMMONHEADER);
assertThat(dataReturned).isEqualTo(dataAsObject);
@@ -93,7 +95,7 @@ public class JsonSchemaHelperUnmarshalTest extends CommonTestData {
* @throws CoderException the coderException
*/
@Test
- public void testObjectSchemaDraft07_valid() throws CoderException {
+ void testObjectSchemaDraft07_valid() throws CoderException {
var dataAsObject = coder.decode(COMMONHEADER, Map.class);
var dataReturned = validateAndUnmarshal(COMMONHEADERTYPE_DRAFT07, COMMONHEADER);
assertThat(dataReturned).isEqualTo(dataAsObject);
@@ -105,7 +107,7 @@ public class JsonSchemaHelperUnmarshalTest extends CommonTestData {
* @throws CoderException the coderException
*/
@Test
- public void testObjectSchemaDraft07_invalid() throws CoderException {
+ void testObjectSchemaDraft07_invalid() throws CoderException {
var dataAsObject = coder.decode(COMMONHEADER, JsonObject.class);
dataAsObject.addProperty("requestId", "abcd");
assertThatThrownBy(() -> validateAndUnmarshal(COMMONHEADERTYPE_DRAFT07, dataAsObject))
@@ -119,7 +121,7 @@ public class JsonSchemaHelperUnmarshalTest extends CommonTestData {
* @throws CoderException the coderException
*/
@Test
- public void testCreateNewInstanceInvalid() throws CoderException {
+ void testCreateNewInstanceInvalid() throws CoderException {
var dataAsObject = coder.decode(COMMONHEADER, Map.class);
assertThatThrownBy(() -> validateAndUnmarshal(COMMONHEADERTYPE_DRAFT07, dataAsObject))
.isInstanceOf(ContextRuntimeException.class).hasMessageContaining("not an instance of JsonObject");
@@ -131,7 +133,7 @@ public class JsonSchemaHelperUnmarshalTest extends CommonTestData {
* @throws CoderException the coderException
*/
@Test
- public void testObjectSchema_fieldMissing() throws CoderException {
+ void testObjectSchema_fieldMissing() throws CoderException {
var dataAsObject = coder.decode(COMMONHEADER, JsonObject.class);
dataAsObject.remove(TEST_ID);
assertThatThrownBy(() -> validateAndUnmarshal(COMMONHEADERTYPE_DRAFT07, dataAsObject))
@@ -145,7 +147,7 @@ public class JsonSchemaHelperUnmarshalTest extends CommonTestData {
* @throws CoderException the coderException
*/
@Test
- public void testObjectSchema_OptionalField() throws CoderException {
+ void testObjectSchema_OptionalField() throws CoderException {
var dataAsObject = coder.decode(COMMONHEADER, Map.class);
var dataAsjsonObject = coder.decode(COMMONHEADER, JsonObject.class);
dataAsObject.remove(TEST_ID);
diff --git a/plugins/plugins-context/pom.xml b/plugins/plugins-context/pom.xml
index 94a303b65..98195f77b 100644
--- a/plugins/plugins-context/pom.xml
+++ b/plugins/plugins-context/pom.xml
@@ -1,6 +1,7 @@
<!--
============LICENSE_START=======================================================
Copyright (C) 2018 Ericsson. All rights reserved.
+ Modifications Copyright (C) 2024 Nordix Foundation.
================================================================================
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -44,6 +45,5 @@
<module>plugins-context-schema</module>
<module>plugins-context-distribution</module>
<module>plugins-context-locking</module>
- <module>plugins-context-persistence</module>
</modules>
</project>
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumerTest.java
index bd4103f92..fd447a205 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcConsumerTest.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.
@@ -21,59 +21,59 @@
package org.onap.policy.apex.plugins.event.carrier.grpc;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import org.assertj.core.api.Assertions;
-import org.junit.Before;
-import org.junit.Test;
+import org.jetbrains.annotations.NotNull;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
import org.onap.policy.apex.service.engine.event.PeeredReference;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
-public class ApexGrpcConsumerTest {
+class ApexGrpcConsumerTest {
private static final String CONSUMER_NAME = "TestApexGrpcConsumer";
private ApexGrpcConsumer grpcConsumer = null;
private ApexGrpcProducer grpcProducer = null;
private EventHandlerParameters consumerParameters = null;
- private ApexEventReceiver incomingEventReceiver = null;
+ private final ApexEventReceiver incomingEventReceiver = null;
/**
* Set up testing.
- *
- * @throws ApexEventException on test set up errors.
*/
- @Before
- public void setUp() throws ApexEventException {
+ @BeforeEach
+ void setUp() {
grpcConsumer = new ApexGrpcConsumer();
grpcProducer = new ApexGrpcProducer();
}
@Test
- public void testInit() {
- consumerParameters = populateConsumerParameters(true, true);
+ void testInit() {
+ consumerParameters = populateConsumerParameters(true);
Assertions.assertThatCode(() -> grpcConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver))
.doesNotThrowAnyException();
}
@Test
- public void testInit_invalidPeeredMode() {
- consumerParameters = populateConsumerParameters(true, false);
+ void testInit_invalidPeeredMode() {
+ consumerParameters = populateConsumerParameters(false);
assertThatThrownBy(() -> grpcConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver))
.hasMessageContaining(
"gRPC consumer (" + CONSUMER_NAME + ") must run in peered requestor mode with a gRPC producer");
}
@Test
- public void testGetName() {
- assertEquals(null, new ApexGrpcConsumer().getName());
+ void testGetName() {
+ assertNull(new ApexGrpcConsumer().getName());
}
@Test
- public void testPeeredReference() throws ApexEventException {
- consumerParameters = populateConsumerParameters(true, true);
+ void testPeeredReference() throws ApexEventException {
+ consumerParameters = populateConsumerParameters(true);
grpcConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR,
new PeeredReference(EventHandlerPeeredMode.REQUESTOR, grpcConsumer, grpcProducer));
grpcConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver);
@@ -83,19 +83,10 @@ public class ApexGrpcConsumerTest {
assertEquals(grpcProducer, peeredReference.getPeeredProducer());
}
- private EventHandlerParameters populateConsumerParameters(boolean isConsumer, boolean isPeeredMode) {
+ private EventHandlerParameters populateConsumerParameters(boolean isPeeredMode) {
consumerParameters = new EventHandlerParameters();
- GrpcCarrierTechnologyParameters params = new GrpcCarrierTechnologyParameters();
- params.setLabel("GRPC");
- params.setEventProducerPluginClass(ApexGrpcProducer.class.getName());
- params.setEventConsumerPluginClass(ApexGrpcConsumer.class.getName());
- if (!isConsumer) {
- params.setHost("hostname");
- params.setPort(3214);
- params.setUsername("dummyUser");
- params.setPassword("dummyPassword");
- params.setTimeout(1);
- }
+ GrpcCarrierTechnologyParameters params =
+ getGrpcCarrierTechnologyParameters();
consumerParameters.setCarrierTechnologyParameters(params);
if (isPeeredMode) {
consumerParameters.setPeeredMode(EventHandlerPeeredMode.REQUESTOR, true);
@@ -103,4 +94,12 @@ public class ApexGrpcConsumerTest {
}
return consumerParameters;
}
+
+ private static @NotNull GrpcCarrierTechnologyParameters getGrpcCarrierTechnologyParameters() {
+ GrpcCarrierTechnologyParameters params = new GrpcCarrierTechnologyParameters();
+ params.setLabel("GRPC");
+ params.setEventProducerPluginClass(ApexGrpcProducer.class.getName());
+ params.setEventConsumerPluginClass(ApexGrpcConsumer.class.getName());
+ return params;
+ }
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducerTest.java
index 31be69e3a..7411737fe 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/ApexGrpcProducerTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
+ * Copyright (C) 2020, 2024 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -22,61 +22,61 @@
package org.onap.policy.apex.plugins.event.carrier.grpc;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.Mockito.spy;
import java.nio.file.Files;
import java.nio.file.Paths;
import org.assertj.core.api.Assertions;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
import org.onap.policy.cds.client.CdsProcessorGrpcClient;
-@RunWith(MockitoJUnitRunner.class)
-public class ApexGrpcProducerTest {
+@ExtendWith(MockitoExtension.class)
+class ApexGrpcProducerTest {
private static final String PRODUCER_NAME = "TestApexGrpcProducer";
private static final String HOST = "localhost";
@Mock
private CdsProcessorGrpcClient grpcClient;
- private ApexGrpcProducer apexGrpcProducer = spy(new ApexGrpcProducer());
+ private final ApexGrpcProducer apexGrpcProducer = spy(new ApexGrpcProducer());
@Mock
private EventHandlerParameters eventHandlerParameters;
/**
* Set up testing.
- *
- * @throws ApexEventException on test set up errors.
*/
- @Before
- public void setUp() throws ApexEventException {
- populateEventHandlerParameters(HOST, 5);
+ @BeforeEach
+ void setUp() {
+ populateEventHandlerParameters();
}
- @Test(expected = ApexEventException.class)
- public void testInit_fail() throws ApexEventException {
- apexGrpcProducer.init(PRODUCER_NAME, new EventHandlerParameters());
+ @Test
+ void testInit_fail() {
+ assertThrows(ApexEventException.class,
+ () -> apexGrpcProducer.init(PRODUCER_NAME, new EventHandlerParameters()));
}
@Test
- public void testInit_pass() {
+ void testInit_pass() {
// should not throw an exception
Assertions.assertThatCode(() -> apexGrpcProducer.init(PRODUCER_NAME, eventHandlerParameters))
.doesNotThrowAnyException();
}
@Test
- public void testStop() throws ApexEventException {
+ void testStop() throws ApexEventException {
apexGrpcProducer.init(PRODUCER_NAME, eventHandlerParameters);
// should not throw an exception
- Assertions.assertThatCode(() -> apexGrpcProducer.stop()).doesNotThrowAnyException();
+ Assertions.assertThatCode(apexGrpcProducer::stop).doesNotThrowAnyException();
}
@Test
- public void testSendEvent() throws ApexEventException {
+ void testSendEvent() throws ApexEventException {
apexGrpcProducer.init(PRODUCER_NAME, eventHandlerParameters);
Assertions
.assertThatCode(() -> apexGrpcProducer.sendEvent(123, null, "grpcEvent",
@@ -84,17 +84,17 @@ public class ApexGrpcProducerTest {
.doesNotThrowAnyException();
}
- private void populateEventHandlerParameters(String host, int timeout) {
+ private void populateEventHandlerParameters() {
eventHandlerParameters = new EventHandlerParameters();
GrpcCarrierTechnologyParameters params = new GrpcCarrierTechnologyParameters();
params.setLabel("GRPC");
params.setEventProducerPluginClass(ApexGrpcProducer.class.getName());
params.setEventConsumerPluginClass(ApexGrpcConsumer.class.getName());
- params.setHost(host);
+ params.setHost(ApexGrpcProducerTest.HOST);
params.setPort(3214);
params.setUsername("dummyUser");
params.setPassword("dummyPassword");
- params.setTimeout(timeout);
+ params.setTimeout(5);
eventHandlerParameters.setCarrierTechnologyParameters(params);
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java
index 7c79e95b6..22643fedd 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-grpc/src/test/java/org/onap/policy/apex/plugins/event/carrier/grpc/GrpcCarrierTechnologyParametersTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * 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,16 +22,15 @@
package org.onap.policy.apex.plugins.event.carrier.grpc;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import org.assertj.core.api.Assertions;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.policy.apex.service.engine.event.ApexEventException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.ValidationResult;
-public class GrpcCarrierTechnologyParametersTest {
+class GrpcCarrierTechnologyParametersTest {
private static final String USERNAME = "username";
private static final String PASSWORD = "password";
@@ -39,23 +38,26 @@ public class GrpcCarrierTechnologyParametersTest {
private GrpcCarrierTechnologyParameters params;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
params = new GrpcCarrierTechnologyParameters();
}
@Test
- public void testGrpcCarrierTechnologyParameters_invalid_producer_params() throws ApexEventException {
+ void testGrpcCarrierTechnologyParameters_invalid_producer_params() {
ValidationResult result = params.validate();
assertTrue(result.isValid());
assertThatThrownBy(() -> params.validateGrpcParameters(true))
- .hasMessage("Issues in specifying gRPC Producer parameters:\ntimeout should have a positive value.\n"
- + "port range should be between 1024 and 65535\n" + "host should be specified.\n"
- + "username should be specified.\n" + "password should be specified.\n");
+ .hasMessageContaining("Issues in specifying gRPC Producer parameters")
+ .hasMessageContaining("timeout should have a positive value")
+ .hasMessageContaining("port range should be between 1024 and 65535")
+ .hasMessageContaining("host should be specified")
+ .hasMessageContaining("username should be specified")
+ .hasMessageContaining("password should be specified");
}
@Test
- public void testGrpcCarrierTechnologyParameters_valid() {
+ void testGrpcCarrierTechnologyParameters_valid() {
assertEquals("GRPC", params.getName());
assertEquals(ApexGrpcConsumer.class.getName(), params.getEventConsumerPluginClass());
assertEquals(ApexGrpcProducer.class.getName(), params.getEventProducerPluginClass());
@@ -71,7 +73,7 @@ public class GrpcCarrierTechnologyParametersTest {
}
@Test
- public void testGrpcCarrierTechnologyParameters_invalid_values() {
+ void testGrpcCarrierTechnologyParameters_invalid_values() {
params.setHost(HOST);
params.setPassword(PASSWORD);
params.setTimeout(1000);
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java
index ab1155641..5ea2fab05 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsConsumerTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Samsung. All rights reserved.
- * Modifications Copyright (C) 2019-2021, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021, 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,8 +23,8 @@ package org.onap.policy.apex.plugins.event.carrier.jms;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import jakarta.jms.Connection;
import jakarta.jms.ConnectionFactory;
@@ -34,8 +34,9 @@ import jakarta.jms.Topic;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.naming.NamingException;
-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.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import org.onap.policy.apex.service.engine.event.ApexEventException;
@@ -47,7 +48,7 @@ import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnolo
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
-public class ApexJmsConsumerTest {
+class ApexJmsConsumerTest {
private static final String CONSUMER_NAME = "TestApexJmsConsumer";
private ApexJmsConsumer apexJmsConsumer = null;
@@ -56,38 +57,36 @@ public class ApexJmsConsumerTest {
private ApexEventProducer apexJmsProducer = null;
private JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null;
+ AutoCloseable closeable;
+
/**
* Set up testing.
*/
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
apexJmsConsumer = Mockito.spy(new ApexJmsConsumer());
consumerParameters = new EventHandlerParameters();
apexJmsProducer = new ApexJmsProducer();
}
@Test
- public void testInitWithNonJmsCarrierTechnologyParameters() {
+ void testInitWithNonJmsCarrierTechnologyParameters() {
consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {
});
- assertThatThrownBy(
- () -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver)
- )
+ assertThatThrownBy(() -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void testInitWithJmsCarrierTechnologyParameters() {
+ void testInitWithJmsCarrierTechnologyParameters() {
jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters);
- assertThatThrownBy(
- () -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver)
- )
+ assertThatThrownBy(() -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void testInitNoConnectionFactory() throws NamingException {
+ void testInitNoConnectionFactory() throws NamingException {
jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters);
@@ -95,14 +94,12 @@ public class ApexJmsConsumerTest {
Mockito.doReturn(null).when(context).lookup(jmsCarrierTechnologyParameters.getConnectionFactory());
Mockito.doReturn(context).when(apexJmsConsumer).getInitialContext();
- assertThatThrownBy(
- () -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver)
- )
+ assertThatThrownBy(() -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void testInitNoConsumerTopic() throws NamingException {
+ void testInitNoConsumerTopic() throws NamingException {
jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters);
@@ -113,14 +110,12 @@ public class ApexJmsConsumerTest {
Mockito.doReturn(null).when(context).lookup(jmsCarrierTechnologyParameters.getConsumerTopic());
Mockito.doReturn(context).when(apexJmsConsumer).getInitialContext();
- assertThatThrownBy(
- () -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver)
- )
+ assertThatThrownBy(() -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void testInitNoConnection() throws NamingException, JMSException {
+ void testInitNoConnection() throws NamingException, JMSException {
jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters);
@@ -130,21 +125,18 @@ public class ApexJmsConsumerTest {
Mockito.doReturn(connectionFactory).when(context).lookup(jmsCarrierTechnologyParameters.getConnectionFactory());
Mockito.doReturn(topic).when(context).lookup(jmsCarrierTechnologyParameters.getConsumerTopic());
- Mockito.doThrow(JMSException.class)
- .when(connectionFactory)
+ closeable = Mockito.doThrow(JMSException.class).when(connectionFactory)
.createConnection(jmsCarrierTechnologyParameters.getSecurityPrincipal(),
jmsCarrierTechnologyParameters.getSecurityCredentials());
Mockito.doReturn(context).when(apexJmsConsumer).getInitialContext();
- assertThatThrownBy(
- () -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver)
- )
+ assertThatThrownBy(() -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void testInitConnectionError() throws NamingException, JMSException {
+ void testInitConnectionError() throws NamingException, JMSException {
jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters);
@@ -155,21 +147,18 @@ public class ApexJmsConsumerTest {
Mockito.doReturn(connectionFactory).when(context).lookup(jmsCarrierTechnologyParameters.getConnectionFactory());
Mockito.doReturn(topic).when(context).lookup(jmsCarrierTechnologyParameters.getConsumerTopic());
- Mockito.doReturn(connection)
- .when(connectionFactory)
+ closeable = Mockito.doReturn(connection).when(connectionFactory)
.createConnection(jmsCarrierTechnologyParameters.getSecurityPrincipal(),
jmsCarrierTechnologyParameters.getSecurityCredentials());
Mockito.doThrow(JMSException.class).when(connection).start();
Mockito.doReturn(context).when(apexJmsConsumer).getInitialContext();
- assertThatThrownBy(
- () -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver)
- )
+ assertThatThrownBy(() -> apexJmsConsumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void testInit() throws NamingException, JMSException, ApexEventException {
+ void testInit() throws NamingException, JMSException, ApexEventException {
jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters);
@@ -180,8 +169,7 @@ public class ApexJmsConsumerTest {
Mockito.doReturn(connectionFactory).when(context).lookup(jmsCarrierTechnologyParameters.getConnectionFactory());
Mockito.doReturn(topic).when(context).lookup(jmsCarrierTechnologyParameters.getConsumerTopic());
- Mockito.doReturn(connection)
- .when(connectionFactory)
+ closeable = Mockito.doReturn(connection).when(connectionFactory)
.createConnection(jmsCarrierTechnologyParameters.getSecurityPrincipal(),
jmsCarrierTechnologyParameters.getSecurityCredentials());
Mockito.doNothing().when(connection).start();
@@ -193,22 +181,22 @@ public class ApexJmsConsumerTest {
}
@Test
- public void testStart() {
+ void testStart() {
assertThatCode(apexJmsConsumer::start).doesNotThrowAnyException();
}
@Test
- public void testGetName() {
+ void testGetName() {
assertNull(apexJmsConsumer.getName());
}
@Test
- public void testGetPeeredReference() {
+ void testGetPeeredReference() {
assertNull(apexJmsConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
}
@Test
- public void testSetPeeredReference() {
+ void testSetPeeredReference() {
PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR,
apexJmsConsumer, apexJmsProducer);
apexJmsConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference);
@@ -216,19 +204,19 @@ public class ApexJmsConsumerTest {
}
@Test
- public void testRun() {
+ void testRun() {
assertThatThrownBy(apexJmsConsumer::run).isInstanceOf(ApexEventRuntimeException.class);
}
@Test
- public void testOnMessageUninitialized() {
+ void testOnMessageUninitialized() {
Message jmsMessage = null;
assertThatThrownBy(() -> apexJmsConsumer.onMessage(jmsMessage))
.isInstanceOf(ApexEventRuntimeException.class);
}
@Test
- public void testOnMessage() throws JMSException, NamingException, ApexEventException {
+ void testOnMessage() throws JMSException, NamingException, ApexEventException {
// prepare ApexJmsConsumer
jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters);
@@ -242,8 +230,7 @@ public class ApexJmsConsumerTest {
Mockito.doReturn(connectionFactory).when(context).lookup(jmsCarrierTechnologyParameters.getConnectionFactory());
Mockito.doReturn(topic).when(context).lookup(jmsCarrierTechnologyParameters.getConsumerTopic());
- Mockito.doReturn(connection)
- .when(connectionFactory)
+ closeable = Mockito.doReturn(connection).when(connectionFactory)
.createConnection(jmsCarrierTechnologyParameters.getSecurityPrincipal(),
jmsCarrierTechnologyParameters.getSecurityCredentials());
Mockito.doNothing().when(connection).start();
@@ -260,7 +247,7 @@ public class ApexJmsConsumerTest {
}
@Test
- public void testConnectionError() throws NamingException, JMSException, ApexEventException {
+ void testConnectionError() throws NamingException, JMSException, ApexEventException {
// prepare ApexJmsConsumer
jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters);
@@ -272,8 +259,7 @@ public class ApexJmsConsumerTest {
Mockito.doReturn(connectionFactory).when(context).lookup(jmsCarrierTechnologyParameters.getConnectionFactory());
Mockito.doReturn(topic).when(context).lookup(jmsCarrierTechnologyParameters.getConsumerTopic());
- Mockito.doReturn(connection)
- .when(connectionFactory)
+ closeable = Mockito.doReturn(connection).when(connectionFactory)
.createConnection(jmsCarrierTechnologyParameters.getSecurityPrincipal(),
jmsCarrierTechnologyParameters.getSecurityCredentials());
Mockito.doNothing().when(connection).start();
@@ -290,7 +276,7 @@ public class ApexJmsConsumerTest {
}
@Test
- public void testStop() throws NamingException, JMSException, ApexEventException {
+ void testStop() throws NamingException, JMSException, ApexEventException {
// prepare ApexJmsConsumer
jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
consumerParameters.setCarrierTechnologyParameters(jmsCarrierTechnologyParameters);
@@ -302,8 +288,7 @@ public class ApexJmsConsumerTest {
Mockito.doReturn(connectionFactory).when(context).lookup(jmsCarrierTechnologyParameters.getConnectionFactory());
Mockito.doReturn(topic).when(context).lookup(jmsCarrierTechnologyParameters.getConsumerTopic());
- Mockito.doReturn(connection)
- .when(connectionFactory)
+ closeable = Mockito.doReturn(connection).when(connectionFactory)
.createConnection(jmsCarrierTechnologyParameters.getSecurityPrincipal(),
jmsCarrierTechnologyParameters.getSecurityCredentials());
Mockito.doNothing().when(connection).start();
@@ -321,7 +306,14 @@ public class ApexJmsConsumerTest {
}
@Test
- public void testStopNoJmsProperties() {
+ void testStopNoJmsProperties() {
assertThatThrownBy(apexJmsConsumer::stop).isInstanceOf(NullPointerException.class);
}
+
+ @AfterEach
+ void after() throws Exception {
+ if (closeable != null) {
+ closeable.close();
+ }
+ }
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java
index ffc5c5b1e..35130648f 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/ApexJmsProducerTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Samsung. All rights reserved.
- * Modifications Copyright (C) 2019-2021, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021, 2023-2024 Nordix Foundation.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,8 +25,8 @@ package org.onap.policy.apex.plugins.event.carrier.jms;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import jakarta.jms.Connection;
import jakarta.jms.ConnectionFactory;
@@ -43,9 +43,9 @@ import java.util.Random;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.apache.commons.lang3.RandomStringUtils;
-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.mockito.Mockito;
import org.onap.policy.apex.service.engine.event.ApexEvent;
import org.onap.policy.apex.service.engine.event.ApexEventException;
@@ -71,14 +71,14 @@ public class ApexJmsProducerTest {
* Set up testing.
*
*/
- @Before
+ @BeforeEach
public void setUp() {
apexJmsConsumer = new ApexJmsConsumer();
producerParameters = new EventHandlerParameters();
apexJmsProducer = Mockito.spy(new ApexJmsProducer());
}
- @After
+ @AfterEach
public void tearDown() {
// restore system.out
System.setOut(out);
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java
index 36f2e31ce..e8c223482 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-jms/src/test/java/org/onap/policy/apex/plugins/event/carrier/jms/JmsCarrierTechnologyParametersTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Samsung. All rights reserved.
- * Modifications Copyright (C) 2019,2021 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2021, 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,32 +22,31 @@
package org.onap.policy.apex.plugins.event.carrier.jms;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.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.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Properties;
import javax.naming.Context;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.ParameterRuntimeException;
import org.onap.policy.common.parameters.ValidationResult;
-public class JmsCarrierTechnologyParametersTest {
+class JmsCarrierTechnologyParametersTest {
JmsCarrierTechnologyParameters jmsCarrierTechnologyParameters = null;
- Properties jmsProducerProperties = null;
- Properties jmsConsumerProperties = null;
ValidationResult result = null;
- public static final String JMS_CARRIER_TECHNOLOGY_LABEL = "JMS";
+ static final String JMS_CARRIER_TECHNOLOGY_LABEL = "JMS";
- public static final String JMS_EVENT_PRODUCER_PLUGIN_CLASS = ApexJmsProducer.class.getName();
+ static final String JMS_EVENT_PRODUCER_PLUGIN_CLASS = ApexJmsProducer.class.getName();
- public static final String JMS_EVENT_CONSUMER_PLUGIN_CLASS = ApexJmsConsumer.class.getName();
+ static final String JMS_EVENT_CONSUMER_PLUGIN_CLASS = ApexJmsConsumer.class.getName();
private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
private static final String DEFAULT_INITIAL_CTXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
@@ -61,13 +60,13 @@ public class JmsCarrierTechnologyParametersTest {
*
* @throws Exception on test set up errors.
*/
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
jmsCarrierTechnologyParameters = new JmsCarrierTechnologyParameters();
}
@Test
- public void testValidate() {
+ void testValidate() {
result = jmsCarrierTechnologyParameters.validate();
assertNotNull(result);
assertFalse(result.getStatus().isValid());
@@ -82,12 +81,12 @@ public class JmsCarrierTechnologyParametersTest {
}
@Test
- public void testJmsCarrierTechnologyParameters() {
+ void testJmsCarrierTechnologyParameters() {
assertNotNull(jmsCarrierTechnologyParameters);
}
@Test
- public void testGetJmsProducerProperties() {
+ void testGetJmsProducerProperties() {
Properties producerProperties = jmsCarrierTechnologyParameters.getJmsProducerProperties();
assertNotNull(producerProperties);
@@ -117,7 +116,7 @@ public class JmsCarrierTechnologyParametersTest {
}
@Test
- public void testGetJmsConsumerProperties() {
+ void testGetJmsConsumerProperties() {
Properties consumerProperties = jmsCarrierTechnologyParameters.getJmsConsumerProperties();
assertNotNull(consumerProperties);
assertNull(consumerProperties.get(Context.SECURITY_CREDENTIALS));
@@ -128,24 +127,24 @@ public class JmsCarrierTechnologyParametersTest {
}
@Test
- public void testEqualityOfJmsConsumerAndProducerProperties() {
+ void testEqualityOfJmsConsumerAndProducerProperties() {
assertEquals(jmsCarrierTechnologyParameters.getJmsProducerProperties(),
- jmsCarrierTechnologyParameters.getJmsConsumerProperties());
+ jmsCarrierTechnologyParameters.getJmsConsumerProperties());
}
@Test
- public void testGetConnectionFactory() {
+ void testGetConnectionFactory() {
assertEquals(DEFAULT_CONNECTION_FACTORY, jmsCarrierTechnologyParameters.getConnectionFactory());
}
@Test
- public void testSetConnectionFactory() {
+ void testSetConnectionFactory() {
jmsCarrierTechnologyParameters.setConnectionFactory("QueueConnectionFactory");
assertNotEquals(DEFAULT_CONNECTION_FACTORY, jmsCarrierTechnologyParameters.getConnectionFactory());
}
@Test
- public void testSetConsumerTopic() {
+ void testSetConsumerTopic() {
assertEquals(DEFAULT_CONSUMER_TOPIC, jmsCarrierTechnologyParameters.getConsumerTopic());
jmsCarrierTechnologyParameters.setConsumerTopic(null);
result = jmsCarrierTechnologyParameters.validate();
@@ -153,28 +152,28 @@ public class JmsCarrierTechnologyParametersTest {
}
@Test
- public void testSetConsumerWaitTime() {
+ void testSetConsumerWaitTime() {
assertEquals(DEFAULT_CONSUMER_WAIT_TIME, jmsCarrierTechnologyParameters.getConsumerWaitTime());
jmsCarrierTechnologyParameters.setConsumerWaitTime(-1);
assertNotEquals(DEFAULT_CONSUMER_WAIT_TIME, jmsCarrierTechnologyParameters.getConsumerWaitTime());
}
@Test
- public void testSetEventConsumerPluginClass() {
+ void testSetEventConsumerPluginClass() {
assertEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventConsumerPluginClass());
jmsCarrierTechnologyParameters.setEventConsumerPluginClass("TestEventConsumerPluginClass");
assertNotEquals(JMS_EVENT_CONSUMER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventConsumerPluginClass());
}
@Test
- public void testSetEventProducerPluginClass() {
+ void testSetEventProducerPluginClass() {
assertEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventProducerPluginClass());
jmsCarrierTechnologyParameters.setEventProducerPluginClass("TestEventProducerPluginClass");
assertNotEquals(JMS_EVENT_PRODUCER_PLUGIN_CLASS, jmsCarrierTechnologyParameters.getEventProducerPluginClass());
}
@Test
- public void testSetLabel() {
+ void testSetLabel() {
assertEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
jmsCarrierTechnologyParameters.setLabel("TestLable");
assertNotEquals(JMS_CARRIER_TECHNOLOGY_LABEL, jmsCarrierTechnologyParameters.getLabel());
@@ -182,14 +181,14 @@ public class JmsCarrierTechnologyParametersTest {
}
@Test
- public void testSetObjectMessageSending() {
+ void testSetObjectMessageSending() {
assertTrue(jmsCarrierTechnologyParameters.isObjectMessageSending());
jmsCarrierTechnologyParameters.setObjectMessageSending(!DEFAULT_TO_OBJECT_MSG_SENDING);
assertFalse(jmsCarrierTechnologyParameters.isObjectMessageSending());
}
@Test
- public void testSetProducerTopic() {
+ void testSetProducerTopic() {
assertEquals(DEFAULT_PRODUCER_TOPIC, jmsCarrierTechnologyParameters.getProducerTopic());
jmsCarrierTechnologyParameters.setProducerTopic("");
result = jmsCarrierTechnologyParameters.validate();
@@ -197,7 +196,7 @@ public class JmsCarrierTechnologyParametersTest {
}
@Test
- public void testSetProviderUrl() {
+ void testSetProviderUrl() {
assertNull(jmsCarrierTechnologyParameters.getProviderUrl());
jmsCarrierTechnologyParameters.setProviderUrl(null);
result = jmsCarrierTechnologyParameters.validate();
@@ -205,7 +204,7 @@ public class JmsCarrierTechnologyParametersTest {
}
@Test
- public void testSetSecurityCredentials() {
+ void testSetSecurityCredentials() {
assertNull(jmsCarrierTechnologyParameters.getSecurityCredentials());
jmsCarrierTechnologyParameters.setSecurityCredentials("");
result = jmsCarrierTechnologyParameters.validate();
@@ -213,7 +212,7 @@ public class JmsCarrierTechnologyParametersTest {
}
@Test
- public void testSetSecurityPrincipal() {
+ void testSetSecurityPrincipal() {
assertNull(jmsCarrierTechnologyParameters.getSecurityPrincipal());
jmsCarrierTechnologyParameters.setSecurityPrincipal(null);
result = jmsCarrierTechnologyParameters.validate();
@@ -221,7 +220,7 @@ public class JmsCarrierTechnologyParametersTest {
}
@Test
- public void testSetInitialContextFactory() {
+ void testSetInitialContextFactory() {
assertEquals(DEFAULT_INITIAL_CTXT_FACTORY, jmsCarrierTechnologyParameters.getInitialContextFactory());
@@ -233,8 +232,8 @@ public class JmsCarrierTechnologyParametersTest {
assertNotEquals(DEFAULT_INITIAL_CTXT_FACTORY, jmsCarrierTechnologyParameters.getInitialContextFactory());
}
- @Test(expected = ParameterRuntimeException.class)
- public void testSetName() {
- jmsCarrierTechnologyParameters.setName("TestName");
+ @Test
+ void testSetName() {
+ assertThrows(ParameterRuntimeException.class, () -> jmsCarrierTechnologyParameters.setName("TestName"));
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java
index 1ef3550e4..f1e420bf0 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaConsumerTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Samsung. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020, 2024 Nordix Foundation
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,12 +23,13 @@
package org.onap.policy.apex.plugins.event.carrier.kafka;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-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.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.event.ApexEventProducer;
import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
@@ -37,7 +38,7 @@ import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnolo
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
-public class ApexKafkaConsumerTest {
+class ApexKafkaConsumerTest {
ApexKafkaConsumer apexKafkaConsumer = null;
ApexKafkaConsumer apexKafkaConsumer2 = null;
EventHandlerParameters consumerParameters = null;
@@ -51,13 +52,14 @@ public class ApexKafkaConsumerTest {
*
* @throws ApexEventException on test set up errors.
*/
- @Before
- public void setUp() throws ApexEventException {
+ @BeforeEach
+ void setUp() throws ApexEventException {
apexKafkaConsumer = new ApexKafkaConsumer();
consumerParameters = new EventHandlerParameters();
apexKafkaProducer = new ApexKafkaProducer();
consumerParameters
- .setCarrierTechnologyParameters(new KafkaCarrierTechnologyParameters() {});
+ .setCarrierTechnologyParameters(new KafkaCarrierTechnologyParameters() {
+ });
apexKafkaConsumer.init("TestApexKafkaConsumer", consumerParameters, incomingEventReceiver);
apexKafkaConsumer2 = new ApexKafkaConsumer();
@@ -65,63 +67,66 @@ public class ApexKafkaConsumerTest {
kafkaParameters = new KafkaCarrierTechnologyParameters();
String[][] kafkaProperties = {
{"value.deserializer", "io.confluent.kafka.serializers.KafkaAvroDeserializer"},
- {"schema.registry.url", "[http://test-registory:8080]"}
+ {"schema.registry.url", "[https://test-registory:8080]"}
};
kafkaParameters.setKafkaProperties(kafkaProperties);
consumerParameters2
- .setCarrierTechnologyParameters(kafkaParameters);
+ .setCarrierTechnologyParameters(kafkaParameters);
apexKafkaConsumer2.init("TestApexKafkaConsumer2", consumerParameters2, incomingEventReceiver);
}
@Test
- public void testStart() {
+ void testStart() {
assertThatCode(apexKafkaConsumer::start).doesNotThrowAnyException();
assertThatCode(apexKafkaConsumer2::start).doesNotThrowAnyException();
}
@Test
- public void testGetName() {
+ void testGetName() {
assertEquals("TestApexKafkaConsumer", apexKafkaConsumer.getName());
assertEquals("TestApexKafkaConsumer2", apexKafkaConsumer2.getName());
}
@Test
- public void testGetPeeredReference() {
+ void testGetPeeredReference() {
assertNull(apexKafkaConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
assertNull(apexKafkaConsumer2.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
}
@Test
- public void testSetPeeredReference() {
+ void testSetPeeredReference() {
PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR,
- apexKafkaConsumer, apexKafkaProducer);
+ apexKafkaConsumer, apexKafkaProducer);
apexKafkaConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference);
assertNotNull(apexKafkaConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
PeeredReference peeredReference2 = new PeeredReference(EventHandlerPeeredMode.REQUESTOR,
- apexKafkaConsumer2, apexKafkaProducer);
+ apexKafkaConsumer2, apexKafkaProducer);
apexKafkaConsumer2.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference2);
assertNotNull(apexKafkaConsumer2.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
}
- @Test(expected = java.lang.NullPointerException.class)
- public void testRun() {
- apexKafkaConsumer.run();
- apexKafkaConsumer2.run();
+ @Test
+ void testRun() {
+ assertThrows(NullPointerException.class, () -> apexKafkaConsumer.run());
+ assertThrows(NullPointerException.class, () -> apexKafkaConsumer2.run());
}
- @Test(expected = java.lang.NullPointerException.class)
- public void testStop() {
- apexKafkaConsumer.stop();
- apexKafkaConsumer2.stop();
+ @Test
+ void testStop() {
+ assertThrows(NullPointerException.class, () -> apexKafkaConsumer.stop());
+ assertThrows(NullPointerException.class, () -> apexKafkaConsumer2.stop());
}
- @Test(expected = ApexEventException.class)
- public void testInitWithNonKafkaCarrierTechnologyParameters() throws ApexEventException {
- consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {});
- apexKafkaConsumer.init("TestApexKafkaConsumer", consumerParameters, incomingEventReceiver);
- apexKafkaConsumer2.init("TestApexKafkaConsumer2", consumerParameters, incomingEventReceiver);
+ @Test
+ void testInitWithNonKafkaCarrierTechnologyParameters() {
+ consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {
+ });
+ assertThrows(ApexEventException.class, () ->
+ apexKafkaConsumer.init("TestApexKafkaConsumer", consumerParameters, incomingEventReceiver));
+ assertThrows(ApexEventException.class, () ->
+ apexKafkaConsumer2.init("TestApexKafkaConsumer2", consumerParameters, incomingEventReceiver));
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java
index 7300474c7..f5606eb57 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/ApexKafkaProducerTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Samsung. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,19 +21,20 @@
package org.onap.policy.apex.plugins.event.carrier.kafka;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-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.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.event.PeeredReference;
import org.onap.policy.apex.service.engine.event.SynchronousEventCache;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
-public class ApexKafkaProducerTest {
+class ApexKafkaProducerTest {
ApexKafkaProducer apexKafkaProducer = null;
ApexKafkaConsumer apexKafkaConsumer = null;
EventHandlerParameters producerParameters = null;
@@ -43,37 +45,38 @@ public class ApexKafkaProducerTest {
/**
* Set up testing.
*/
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
apexKafkaProducer = new ApexKafkaProducer();
apexKafkaConsumer = new ApexKafkaConsumer();
producerParameters = new EventHandlerParameters();
}
- @Test(expected = ApexEventException.class)
- public void testInit() throws ApexEventException {
- apexKafkaProducer.init("TestApexKafkaProducer", producerParameters);
+ @Test
+ void testInit() {
+ assertThrows(ApexEventException.class,
+ () -> apexKafkaProducer.init("TestApexKafkaProducer", producerParameters));
}
@Test
- public void testGetName() {
+ void testGetName() {
assertNull(apexKafkaProducer.getName());
}
@Test
- public void testGetPeeredReference() {
+ void testGetPeeredReference() {
assertNull(apexKafkaProducer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
}
@Test
- public void testWithProperValues() throws ApexEventException {
+ void testWithProperValues() throws ApexEventException {
producerParameters
- .setCarrierTechnologyParameters(new KafkaCarrierTechnologyParameters() {});
+ .setCarrierTechnologyParameters(new KafkaCarrierTechnologyParameters() { });
synchronousEventCache = new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS,
- apexKafkaConsumer, apexKafkaProducer, DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT);
+ apexKafkaConsumer, apexKafkaProducer, DEFAULT_SYNCHRONOUS_EVENT_TIMEOUT);
apexKafkaProducer.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS,
- synchronousEventCache);
+ synchronousEventCache);
apexKafkaProducer.init("TestApexKafkaProducer", producerParameters);
assertEquals("TestApexKafkaProducer", apexKafkaProducer.getName());
assertNotNull(apexKafkaProducer.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java
index 6b0f7d920..11bafc9b1 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-kafka/src/test/java/org/onap/policy/apex/plugins/event/carrier/kafka/KafkaCarrierTechnologyParametersTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Samsung. All rights reserved.
- * Modifications Copyright (C) 2019,2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2023-2024 Nordix Foundation.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,17 +22,18 @@
package org.onap.policy.apex.plugins.event.carrier.kafka;
-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 static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Properties;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class KafkaCarrierTechnologyParametersTest {
+class KafkaCarrierTechnologyParametersTest {
@Test
- public void testKafkaCarrierTechnologyParameters() {
+ void testKafkaCarrierTechnologyParameters() {
KafkaCarrierTechnologyParameters kafkaCarrierTechnologyParameters = new KafkaCarrierTechnologyParameters();
assertNotNull(kafkaCarrierTechnologyParameters);
@@ -40,17 +41,17 @@ public class KafkaCarrierTechnologyParametersTest {
}
@Test
- public void testGetKafkaProducerProperties() {
+ void testGetKafkaProducerProperties() {
KafkaCarrierTechnologyParameters kafkaCarrierTechnologyParameters = new KafkaCarrierTechnologyParameters();
Properties kafkaProducerProperties = kafkaCarrierTechnologyParameters.getKafkaProducerProperties();
assertNotNull(kafkaProducerProperties);
assertEquals("localhost:9092", kafkaProducerProperties.get("bootstrap.servers"));
assertEquals("1", kafkaProducerProperties.get("linger.ms"));
- assertEquals(null, kafkaProducerProperties.get("group.id"));
- assertEquals(null, kafkaProducerProperties.get("Property0"));
- assertEquals(null, kafkaProducerProperties.get("Property1"));
- assertEquals(null, kafkaProducerProperties.get("Property2"));
+ assertNull(kafkaProducerProperties.get("group.id"));
+ assertNull(kafkaProducerProperties.get("Property0"));
+ assertNull(kafkaProducerProperties.get("Property1"));
+ assertNull(kafkaProducerProperties.get("Property2"));
// @formatter:off
String[][] kafkaProperties = {
@@ -68,24 +69,24 @@ public class KafkaCarrierTechnologyParametersTest {
assertNotNull(kafkaProducerProperties);
assertEquals("localhost:9092", kafkaProducerProperties.get("bootstrap.servers"));
assertEquals("1", kafkaProducerProperties.get("linger.ms"));
- assertEquals(null, kafkaProducerProperties.get("group.id"));
+ assertNull(kafkaProducerProperties.get("group.id"));
assertEquals("Value0", kafkaProducerProperties.get("Property0"));
assertEquals("Value1", kafkaProducerProperties.get("Property1"));
- assertEquals(null, kafkaProducerProperties.get("Property2"));
+ assertNull(kafkaProducerProperties.get("Property2"));
}
@Test
- public void testGetKafkaConsumerProperties() {
+ void testGetKafkaConsumerProperties() {
KafkaCarrierTechnologyParameters kafkaCarrierTechnologyParameters = new KafkaCarrierTechnologyParameters();
Properties kafkaConsumerProperties = kafkaCarrierTechnologyParameters.getKafkaConsumerProperties();
assertNotNull(kafkaConsumerProperties);
assertEquals("localhost:9092", kafkaConsumerProperties.get("bootstrap.servers"));
assertEquals("default-group-id", kafkaConsumerProperties.get("group.id"));
- assertEquals(null, kafkaConsumerProperties.get("linger.ms"));
- assertEquals(null, kafkaConsumerProperties.get("Property0"));
- assertEquals(null, kafkaConsumerProperties.get("Property1"));
- assertEquals(null, kafkaConsumerProperties.get("Property2"));
+ assertNull(kafkaConsumerProperties.get("linger.ms"));
+ assertNull(kafkaConsumerProperties.get("Property0"));
+ assertNull(kafkaConsumerProperties.get("Property1"));
+ assertNull(kafkaConsumerProperties.get("Property2"));
// @formatter:off
String[][] kafkaProperties = {
@@ -103,204 +104,30 @@ public class KafkaCarrierTechnologyParametersTest {
assertNotNull(kafkaConsumerProperties);
assertEquals("localhost:9092", kafkaConsumerProperties.get("bootstrap.servers"));
assertEquals("default-group-id", kafkaConsumerProperties.get("group.id"));
- assertEquals(null, kafkaConsumerProperties.get("linger.ms"));
+ assertNull(kafkaConsumerProperties.get("linger.ms"));
assertEquals("Value0", kafkaConsumerProperties.get("Property0"));
assertEquals("Value1", kafkaConsumerProperties.get("Property1"));
- assertEquals(null, kafkaConsumerProperties.get("Property2"));
+ assertNull(kafkaConsumerProperties.get("Property2"));
}
@Test
- public void testValidate() {
+ void testValidate() {
KafkaCarrierTechnologyParameters kafkaCarrierTechnologyParameters = new KafkaCarrierTechnologyParameters();
assertNotNull(kafkaCarrierTechnologyParameters);
assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
- String origStringValue = kafkaCarrierTechnologyParameters.getBootstrapServers();
- kafkaCarrierTechnologyParameters.setBootstrapServers(" ");
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setBootstrapServers(origStringValue);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- origStringValue = kafkaCarrierTechnologyParameters.getAcks();
- kafkaCarrierTechnologyParameters.setAcks(" ");
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setAcks(origStringValue);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- origStringValue = kafkaCarrierTechnologyParameters.getGroupId();
- kafkaCarrierTechnologyParameters.setGroupId(" ");
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setGroupId(origStringValue);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- origStringValue = kafkaCarrierTechnologyParameters.getProducerTopic();
- kafkaCarrierTechnologyParameters.setProducerTopic(" ");
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setProducerTopic(origStringValue);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- int origIntValue = kafkaCarrierTechnologyParameters.getRetries();
- kafkaCarrierTechnologyParameters.setRetries(-1);
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setRetries(origIntValue);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- origIntValue = kafkaCarrierTechnologyParameters.getBatchSize();
- kafkaCarrierTechnologyParameters.setBatchSize(-1);
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setBatchSize(origIntValue);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- origIntValue = kafkaCarrierTechnologyParameters.getLingerTime();
- kafkaCarrierTechnologyParameters.setLingerTime(-1);
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setLingerTime(origIntValue);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- long origLongValue = kafkaCarrierTechnologyParameters.getBufferMemory();
- kafkaCarrierTechnologyParameters.setBufferMemory(-1);
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setBufferMemory(origLongValue);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- origIntValue = kafkaCarrierTechnologyParameters.getAutoCommitTime();
- kafkaCarrierTechnologyParameters.setAutoCommitTime(-1);
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setAutoCommitTime(origIntValue);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- origIntValue = kafkaCarrierTechnologyParameters.getSessionTimeout();
- kafkaCarrierTechnologyParameters.setSessionTimeout(-1);
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setSessionTimeout(origIntValue);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- origIntValue = kafkaCarrierTechnologyParameters.getConsumerPollTime();
- kafkaCarrierTechnologyParameters.setConsumerPollTime(-1);
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setConsumerPollTime(origIntValue);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- origStringValue = kafkaCarrierTechnologyParameters.getKeySerializer();
- kafkaCarrierTechnologyParameters.setKeySerializer(" ");
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setKeySerializer(origStringValue);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- origStringValue = kafkaCarrierTechnologyParameters.getValueSerializer();
- kafkaCarrierTechnologyParameters.setValueSerializer(" ");
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setValueSerializer(origStringValue);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- origStringValue = kafkaCarrierTechnologyParameters.getKeyDeserializer();
- kafkaCarrierTechnologyParameters.setKeyDeserializer(" ");
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setKeyDeserializer(origStringValue);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- origStringValue = kafkaCarrierTechnologyParameters.getValueDeserializer();
- kafkaCarrierTechnologyParameters.setValueDeserializer(" ");
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setValueDeserializer(origStringValue);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- String[] origConsumerTopcList = kafkaCarrierTechnologyParameters.getConsumerTopicList();
- kafkaCarrierTechnologyParameters.setConsumerTopicList(null);
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setConsumerTopicList(origConsumerTopcList);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- kafkaCarrierTechnologyParameters.setConsumerTopicList(new String[0]);
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setConsumerTopicList(origConsumerTopcList);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- String[] blankStringList = { null, "" };
- kafkaCarrierTechnologyParameters.setConsumerTopicList(blankStringList);
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setConsumerTopicList(origConsumerTopcList);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- String[][] origKafkaProperties = kafkaCarrierTechnologyParameters.getKafkaProperties();
- kafkaCarrierTechnologyParameters.setKafkaProperties(null);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setKafkaProperties(origKafkaProperties);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
+ assertValidateStringProperties(kafkaCarrierTechnologyParameters);
- kafkaCarrierTechnologyParameters.setKafkaProperties(new String[0][0]);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setKafkaProperties(origKafkaProperties);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
+ assertValidateNumberProperties(kafkaCarrierTechnologyParameters);
- // @formatter:offkafkaCarrierTechnologyParameters
- String[][] kafkaProperties0 = {
- {
- null, "Value0"
- }
- };
- // @formatter:on
+ assertValidateTopicList(kafkaCarrierTechnologyParameters);
- kafkaCarrierTechnologyParameters.setKafkaProperties(kafkaProperties0);
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setKafkaProperties(origKafkaProperties);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- // @formatter:off
- String[][] kafkaProperties1 = {
- {
- "Property1", null
- }
- };
- // @formatter:on
-
- kafkaCarrierTechnologyParameters.setKafkaProperties(kafkaProperties1);
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setKafkaProperties(origKafkaProperties);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- // @formatter:off
- String[][] kafkaProperties2 = {
- {
- "Property1", null
- }
- };
- // @formatter:on
-
- kafkaCarrierTechnologyParameters.setKafkaProperties(kafkaProperties2);
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
-
- // @formatter:off
- String[][] kafkaPropertiesWithEmptyValue = {
- {
- "Property1", ""
- }
- };
- // @formatter:on
-
- kafkaCarrierTechnologyParameters.setKafkaProperties(kafkaPropertiesWithEmptyValue);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- kafkaCarrierTechnologyParameters.setKafkaProperties(origKafkaProperties);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
-
- // @formatter:off
- String[][] kafkaProperties3 = {
- {
- "Property1", "Value0", "Value1"
- }
- };
- // @formatter:on
-
- kafkaCarrierTechnologyParameters.setKafkaProperties(kafkaProperties3);
- assertFalse(kafkaCarrierTechnologyParameters.validate().isValid());
- kafkaCarrierTechnologyParameters.setKafkaProperties(origKafkaProperties);
- assertTrue(kafkaCarrierTechnologyParameters.validate().isValid());
+ assertValidateKafkaProperties(kafkaCarrierTechnologyParameters);
}
@Test
- public void testExplicitImplicit() {
+ void testExplicitImplicit() {
KafkaCarrierTechnologyParameters kafkaCtp = new KafkaCarrierTechnologyParameters();
assertNotNull(kafkaCtp);
@@ -378,4 +205,194 @@ public class KafkaCarrierTechnologyParametersTest {
kafkaCtp.setKafkaProperties(kafkaProperties3);
assertEquals("localhost:7777", kafkaCtp.getKafkaConsumerProperties().get("bootstrap.servers"));
}
+
+ private static void assertValidateStringProperties(KafkaCarrierTechnologyParameters kafkaParameters) {
+ String origStringValue = kafkaParameters.getBootstrapServers();
+ kafkaParameters.setBootstrapServers(" ");
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setBootstrapServers(origStringValue);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ origStringValue = kafkaParameters.getAcks();
+ kafkaParameters.setAcks(" ");
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setAcks(origStringValue);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ origStringValue = kafkaParameters.getGroupId();
+ kafkaParameters.setGroupId(" ");
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setGroupId(origStringValue);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ origStringValue = kafkaParameters.getProducerTopic();
+ kafkaParameters.setProducerTopic(" ");
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setProducerTopic(origStringValue);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ origStringValue = kafkaParameters.getKeySerializer();
+ kafkaParameters.setKeySerializer(" ");
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setKeySerializer(origStringValue);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ origStringValue = kafkaParameters.getValueSerializer();
+ kafkaParameters.setValueSerializer(" ");
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setValueSerializer(origStringValue);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ origStringValue = kafkaParameters.getKeyDeserializer();
+ kafkaParameters.setKeyDeserializer(" ");
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setKeyDeserializer(origStringValue);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ origStringValue = kafkaParameters.getValueDeserializer();
+ kafkaParameters.setValueDeserializer(" ");
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setValueDeserializer(origStringValue);
+ assertTrue(kafkaParameters.validate().isValid());
+ }
+
+ private static void assertValidateTopicList(KafkaCarrierTechnologyParameters kafkaParameters) {
+ String[] origConsumerTopicList = kafkaParameters.getConsumerTopicList();
+ kafkaParameters.setConsumerTopicList(null);
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setConsumerTopicList(origConsumerTopicList);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ kafkaParameters.setConsumerTopicList(new String[0]);
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setConsumerTopicList(origConsumerTopicList);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ String[] blankStringList = { null, "" };
+ kafkaParameters.setConsumerTopicList(blankStringList);
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setConsumerTopicList(origConsumerTopicList);
+ assertTrue(kafkaParameters.validate().isValid());
+ }
+
+ private static void assertValidateNumberProperties(KafkaCarrierTechnologyParameters kafkaParameters) {
+ int origIntValue = kafkaParameters.getRetries();
+ kafkaParameters.setRetries(-1);
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setRetries(origIntValue);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ origIntValue = kafkaParameters.getBatchSize();
+ kafkaParameters.setBatchSize(-1);
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setBatchSize(origIntValue);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ origIntValue = kafkaParameters.getLingerTime();
+ kafkaParameters.setLingerTime(-1);
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setLingerTime(origIntValue);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ long origLongValue = kafkaParameters.getBufferMemory();
+ kafkaParameters.setBufferMemory(-1);
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setBufferMemory(origLongValue);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ origIntValue = kafkaParameters.getAutoCommitTime();
+ kafkaParameters.setAutoCommitTime(-1);
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setAutoCommitTime(origIntValue);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ origIntValue = kafkaParameters.getSessionTimeout();
+ kafkaParameters.setSessionTimeout(-1);
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setSessionTimeout(origIntValue);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ origIntValue = kafkaParameters.getConsumerPollTime();
+ kafkaParameters.setConsumerPollTime(-1);
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setConsumerPollTime(origIntValue);
+ assertTrue(kafkaParameters.validate().isValid());
+ }
+
+ private static void assertValidateKafkaProperties(KafkaCarrierTechnologyParameters kafkaParameters) {
+ String[][] origKafkaProperties = kafkaParameters.getKafkaProperties();
+ kafkaParameters.setKafkaProperties(null);
+ assertTrue(kafkaParameters.validate().isValid());
+ kafkaParameters.setKafkaProperties(origKafkaProperties);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ kafkaParameters.setKafkaProperties(new String[0][0]);
+ assertTrue(kafkaParameters.validate().isValid());
+ kafkaParameters.setKafkaProperties(origKafkaProperties);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ // @formatter:off
+ String[][] kafkaProperties0 = {
+ {
+ null, "Value0"
+ }
+ };
+ // @formatter:on
+
+ kafkaParameters.setKafkaProperties(kafkaProperties0);
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setKafkaProperties(origKafkaProperties);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ // @formatter:off
+ String[][] kafkaProperties1 = {
+ {
+ "Property1", null
+ }
+ };
+ // @formatter:on
+
+ kafkaParameters.setKafkaProperties(kafkaProperties1);
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setKafkaProperties(origKafkaProperties);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ // @formatter:off
+ String[][] kafkaProperties2 = {
+ {
+ "Property1", null
+ }
+ };
+ // @formatter:on
+
+ kafkaParameters.setKafkaProperties(kafkaProperties2);
+ assertFalse(kafkaParameters.validate().isValid());
+
+ // @formatter:off
+ String[][] kafkaPropertiesWithEmptyValue = {
+ {
+ "Property1", ""
+ }
+ };
+ // @formatter:on
+
+ kafkaParameters.setKafkaProperties(kafkaPropertiesWithEmptyValue);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ kafkaParameters.setKafkaProperties(origKafkaProperties);
+ assertTrue(kafkaParameters.validate().isValid());
+
+ // @formatter:off
+ String[][] kafkaProperties3 = {
+ {
+ "Property1", "Value0", "Value1"
+ }
+ };
+ // @formatter:on
+
+ kafkaParameters.setKafkaProperties(kafkaProperties3);
+ assertFalse(kafkaParameters.validate().isValid());
+ kafkaParameters.setKafkaProperties(origKafkaProperties);
+ assertTrue(kafkaParameters.validate().isValid());
+ }
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumerTest.java
index 61155c8cf..b3a6bca06 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConusmerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientConsumerTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 2023-2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,9 +24,10 @@ package org.onap.policy.apex.plugins.event.carrier.restclient;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.Invocation.Builder;
@@ -35,22 +36,23 @@ import jakarta.ws.rs.core.Response;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.concurrent.TimeUnit;
-import org.junit.After;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Order;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
/**
- * This class tests the ApexRestClientConusmer class.
- *
+ * This class tests the ApexRestClientConsumer class.
*/
-@RunWith(MockitoJUnitRunner.class)
-public class ApexRestClientConusmerTest {
+@ExtendWith(MockitoExtension.class)
+class ApexRestClientConsumerTest {
private final PrintStream stdout = System.out;
@Mock
@@ -65,13 +67,13 @@ public class ApexRestClientConusmerTest {
@Mock
private Response responseMock;
- @After
- public void after() {
+ @AfterEach
+ void after() {
System.setOut(stdout);
}
@Test
- public void testApexRestClientConsumerErrors() throws ApexEventException {
+ void testApexRestClientConsumerErrors() throws ApexEventException {
ApexRestClientConsumer arcc = new ApexRestClientConsumer();
assertNotNull(arcc);
@@ -99,7 +101,7 @@ public class ApexRestClientConusmerTest {
assertEquals("RestClientConsumer", arcc.getName());
arcc.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null);
- assertEquals(null, arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertNull(arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
rcctp.setUrl("http://some.place.that.does.not/exist");
Mockito.doReturn(builderMock).when(targetMock).request("application/json");
@@ -120,7 +122,7 @@ public class ApexRestClientConusmerTest {
}
@Test
- public void testApexRestClientConsumerHttpError() throws ApexEventException {
+ void testApexRestClientConsumerHttpError() throws ApexEventException {
ApexRestClientConsumer arcc = new ApexRestClientConsumer();
assertNotNull(arcc);
@@ -139,7 +141,7 @@ public class ApexRestClientConusmerTest {
assertEquals("RestClientConsumer", arcc.getName());
arcc.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null);
- assertEquals(null, arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertNull(arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
Mockito.doReturn(Response.Status.BAD_REQUEST.getStatusCode()).when(responseMock).getStatus();
Mockito.doReturn(responseMock).when(builderMock).get();
@@ -159,7 +161,7 @@ public class ApexRestClientConusmerTest {
}
@Test
- public void testApexRestClientConsumerJsonError() throws ApexEventException {
+ void testApexRestClientConsumerJsonError() throws ApexEventException {
ApexRestClientConsumer arcc = new ApexRestClientConsumer();
assertNotNull(arcc);
@@ -175,7 +177,7 @@ public class ApexRestClientConusmerTest {
arcc.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null);
- assertEquals(null, arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertNull(arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
rcctp.setUrl("http://some.place.that.does.not/exist");
Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus();
@@ -197,7 +199,7 @@ public class ApexRestClientConusmerTest {
}
@Test
- public void testApexRestClientConsumerJsonEmpty() throws ApexEventException {
+ void testApexRestClientConsumerJsonEmpty() throws ApexEventException {
ApexRestClientConsumer arcc = new ApexRestClientConsumer();
assertNotNull(arcc);
@@ -214,7 +216,7 @@ public class ApexRestClientConusmerTest {
arcc.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null);
- assertEquals(null, arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertNull(arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
rcctp.setUrl("http://some.place.that.does.not/exist");
Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus();
@@ -242,7 +244,7 @@ public class ApexRestClientConusmerTest {
}
@Test
- public void testApexRestClientConsumerJsonOk() throws ApexEventException {
+ void testApexRestClientConsumerJsonOk() throws ApexEventException {
ApexRestClientConsumer arcc = new ApexRestClientConsumer();
assertNotNull(arcc);
@@ -259,7 +261,7 @@ public class ApexRestClientConusmerTest {
arcc.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null);
- assertEquals(null, arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertNull(arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
rcctp.setUrl("http://some.place.that.does.not/exist");
Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus();
@@ -278,7 +280,7 @@ public class ApexRestClientConusmerTest {
}
@Test
- public void testApexRestClientConsumerInvalidStatusCode() throws ApexEventException {
+ void testApexRestClientConsumerInvalidStatusCode() throws ApexEventException {
ApexRestClientConsumer arcc = new ApexRestClientConsumer();
assertNotNull(arcc);
@@ -295,7 +297,7 @@ public class ApexRestClientConusmerTest {
arcc.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null);
- assertEquals(null, arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertNull(arcc.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
rcctp.setUrl("http://some.place.that.does.not/exist");
Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus();
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java
index cc5ebbb9f..ec454af00 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/ApexRestClientProducerTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 2023-2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,19 +23,23 @@
package org.onap.policy.apex.plugins.event.carrier.restclient;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.Invocation.Builder;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.Response;
import java.util.Properties;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.policy.apex.service.engine.event.ApexEventConsumer;
import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.event.SynchronousEventCache;
@@ -47,8 +51,8 @@ import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMo
* Test the ApexRestClientProducer class.
*
*/
-@RunWith(MockitoJUnitRunner.class)
-public class ApexRestClientProducerTest {
+@ExtendWith(MockitoExtension.class)
+class ApexRestClientProducerTest {
@Mock
private Client httpClientMock;
@@ -61,8 +65,10 @@ public class ApexRestClientProducerTest {
@Mock
private Response responseMock;
+ AutoCloseable closeable;
+
@Test
- public void testApexRestClientProducerErrors() throws ApexEventException {
+ void testApexRestClientProducerErrors() throws ApexEventException {
ApexRestClientProducer arcp = new ApexRestClientProducer();
assertNotNull(arcp);
@@ -84,7 +90,7 @@ public class ApexRestClientProducerTest {
assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.POST, rcctp.getHttpMethod());
assertEquals("RestClientConsumer", arcp.getName());
arcp.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null);
- assertEquals(null, arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertNull(arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
arcp.stop();
rcctp.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.POST);
@@ -92,7 +98,7 @@ public class ApexRestClientProducerTest {
assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.POST, rcctp.getHttpMethod());
assertEquals("RestClientConsumer", arcp.getName());
arcp.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null);
- assertEquals(null, arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertNull(arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
arcp.stop();
rcctp.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.PUT);
@@ -100,12 +106,12 @@ public class ApexRestClientProducerTest {
assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.PUT, rcctp.getHttpMethod());
assertEquals("RestClientConsumer", arcp.getName());
arcp.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, null);
- assertEquals(null, arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertNull(arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
arcp.stop();
}
@Test
- public void testApexRestClientProducerPutEvent() throws ApexEventException {
+ void testApexRestClientProducerPutEvent() throws ApexEventException {
ApexRestClientProducer arcp = new ApexRestClientProducer();
assertNotNull(arcp);
@@ -120,7 +126,7 @@ public class ApexRestClientProducerTest {
rcctp.setUrl("http://some.place.that.does.not/exist");
Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus();
- Mockito.doReturn(responseMock).when(builderMock).put(Mockito.any());
+ closeable = Mockito.doReturn(responseMock).when(builderMock).put(Mockito.any());
Mockito.doReturn(builderMock).when(targetMock).request("application/json");
Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any());
Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl());
@@ -131,7 +137,7 @@ public class ApexRestClientProducerTest {
}
@Test
- public void testApexRestClientProducerPostEventFail() throws ApexEventException {
+ void testApexRestClientProducerPostEventFail() throws ApexEventException {
ApexRestClientProducer arcp = new ApexRestClientProducer();
assertNotNull(arcp);
@@ -160,7 +166,7 @@ public class ApexRestClientProducerTest {
}
@Test
- public void testApexRestClientProducerPostEventOK() throws ApexEventException {
+ void testApexRestClientProducerPostEventOK() throws ApexEventException {
ApexRestClientProducer arcp = new ApexRestClientProducer();
assertNotNull(arcp);
@@ -179,7 +185,7 @@ public class ApexRestClientProducerTest {
properties.put("tag", "exist");
properties.put("key", "that");
Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus();
- Mockito.doReturn(responseMock).when(builderMock).put(Mockito.any());
+ closeable = Mockito.doReturn(responseMock).when(builderMock).put(Mockito.any());
Mockito.doReturn(builderMock).when(targetMock).request("application/json");
Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any());
Mockito.doReturn(targetMock).when(httpClientMock).target("http://some.place.that.does.not/exist");
@@ -190,7 +196,7 @@ public class ApexRestClientProducerTest {
}
@Test
- public void testApexRestClientProducerPostEventAccepted() throws ApexEventException {
+ void testApexRestClientProducerPostEventAccepted() throws ApexEventException {
ApexRestClientProducer arcp = new ApexRestClientProducer();
assertNotNull(arcp);
@@ -219,7 +225,7 @@ public class ApexRestClientProducerTest {
}
@Test
- public void testApexRestClientProducerPostEventCache() throws ApexEventException {
+ void testApexRestClientProducerPostEventCache() throws ApexEventException {
ApexRestClientProducer arcp = new ApexRestClientProducer();
assertNotNull(arcp);
@@ -251,39 +257,7 @@ public class ApexRestClientProducerTest {
}
@Test
- public void testApexRestClientProducerPostEventCacheTrace() throws ApexEventException {
- ApexRestClientProducer arcp = new ApexRestClientProducer();
- assertNotNull(arcp);
-
- EventHandlerParameters producerParameters = new EventHandlerParameters();
- RestClientCarrierTechnologyParameters rcctp = new RestClientCarrierTechnologyParameters();
- producerParameters.setCarrierTechnologyParameters(rcctp);
-
- rcctp.setHttpMethod(RestClientCarrierTechnologyParameters.HttpMethod.POST);
-
- ApexEventConsumer consumer = new ApexFileEventConsumer();
- SynchronousEventCache cache =
- new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer, arcp, 1000);
- arcp.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, cache);
- assertEquals(cache, arcp.getPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS));
- arcp.init("RestClientConsumer", producerParameters);
- assertEquals(RestClientCarrierTechnologyParameters.HttpMethod.POST, rcctp.getHttpMethod());
- assertEquals("RestClientConsumer", arcp.getName());
-
- rcctp.setUrl("http://some.place.that.does.not/exist");
- Mockito.doReturn(Response.Status.OK.getStatusCode()).when(responseMock).getStatus();
- Mockito.doReturn(responseMock).when(builderMock).post(Mockito.any());
- Mockito.doReturn(builderMock).when(targetMock).request("application/json");
- Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any());
- Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl());
- arcp.setClient(httpClientMock);
-
- arcp.sendEvent(123, null, "EventName", "This is an Event");
- arcp.stop();
- }
-
- @Test
- public void testApexRestClientProducerHttpError() throws ApexEventException {
+ void testApexRestClientProducerHttpError() throws ApexEventException {
ApexRestClientProducer arcp = new ApexRestClientProducer();
assertNotNull(arcp);
@@ -298,7 +272,7 @@ public class ApexRestClientProducerTest {
rcctp.setUrl("http://some.place.that.does.not/exist");
Mockito.doReturn(Response.Status.BAD_REQUEST.getStatusCode()).when(responseMock).getStatus();
- Mockito.doReturn(responseMock).when(builderMock).post(Mockito.any());
+ closeable = Mockito.doReturn(responseMock).when(builderMock).post(Mockito.any());
Mockito.doReturn(builderMock).when(targetMock).request("application/json");
Mockito.doReturn(builderMock).when(builderMock).headers(Mockito.any());
Mockito.doReturn(targetMock).when(httpClientMock).target(rcctp.getUrl());
@@ -308,4 +282,11 @@ public class ApexRestClientProducerTest {
.hasMessageContaining("send of event to URL \"http://some.place.that.does.not/exist\" using HTTP \"POST\" "
+ "failed with status code 400");
}
+
+ @AfterEach
+ void after() throws Exception {
+ if (closeable != null) {
+ closeable.close();
+ }
+ }
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java
index 58d265a97..4539c5181 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restclient/src/test/java/org/onap/policy/apex/plugins/event/carrier/restclient/RestClientCarrierTechnologyParametersTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 2024 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -25,12 +25,13 @@ package org.onap.policy.apex.plugins.event.carrier.restclient;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.service.engine.main.ApexCommandLineArguments;
import org.onap.policy.apex.service.parameters.ApexParameterHandler;
import org.onap.policy.apex.service.parameters.ApexParameters;
@@ -39,10 +40,10 @@ import org.onap.policy.common.parameters.ParameterException;
/**
* Test REST client carrier technology parameters.
*/
-public class RestClientCarrierTechnologyParametersTest {
+class RestClientCarrierTechnologyParametersTest {
@Test
- public void testRestClientCarrierTechnologyParametersBadList() {
+ void testRestClientCarrierTechnologyParametersBadList() {
ApexCommandLineArguments arguments = new ApexCommandLineArguments();
arguments.setToscaPolicyFilePath("src/test/resources/prodcons/RESTClientWithHTTPHeaderBadList.json");
arguments.setRelativeFileRoot(".");
@@ -55,7 +56,7 @@ public class RestClientCarrierTechnologyParametersTest {
}
@Test
- public void testRestClientCarrierTechnologyParametersNotKvPairs() {
+ void testRestClientCarrierTechnologyParametersNotKvPairs() {
ApexCommandLineArguments arguments = new ApexCommandLineArguments();
arguments.setToscaPolicyFilePath("src/test/resources/prodcons/RESTClientWithHTTPHeaderNotKvPairs.json");
arguments.setRelativeFileRoot(".");
@@ -67,7 +68,7 @@ public class RestClientCarrierTechnologyParametersTest {
}
@Test
- public void testRestClientCarrierTechnologyParametersNulls() {
+ void testRestClientCarrierTechnologyParametersNulls() {
ApexCommandLineArguments arguments = new ApexCommandLineArguments();
arguments.setToscaPolicyFilePath("src/test/resources/prodcons/RESTClientWithHTTPHeaderNulls.json");
arguments.setRelativeFileRoot(".");
@@ -79,7 +80,7 @@ public class RestClientCarrierTechnologyParametersTest {
}
@Test
- public void testRestClientCarrierTechnologyParameterFilterInvalid() {
+ void testRestClientCarrierTechnologyParameterFilterInvalid() {
ApexCommandLineArguments arguments = new ApexCommandLineArguments();
arguments.setToscaPolicyFilePath("src/test/resources/prodcons/RESTClientWithHTTPFilterInvalid.json");
arguments.setRelativeFileRoot(".");
@@ -92,7 +93,7 @@ public class RestClientCarrierTechnologyParametersTest {
}
@Test
- public void testRestClientCarrierTechnologyParametersOk() throws ParameterException {
+ void testRestClientCarrierTechnologyParametersOk() throws ParameterException {
ApexCommandLineArguments arguments = new ApexCommandLineArguments();
arguments.setToscaPolicyFilePath("src/test/resources/prodcons/RESTClientWithHTTPHeaderOK.json");
arguments.setRelativeFileRoot(".");
@@ -111,11 +112,11 @@ public class RestClientCarrierTechnologyParametersTest {
assertEquals("fff", rrctp1.getHttpHeadersAsMultivaluedMap().get("eee").get(0));
rrctp1.setHttpHeaders(null);
- assertEquals(null, rrctp1.getHttpHeadersAsMultivaluedMap());
+ assertNull(rrctp1.getHttpHeadersAsMultivaluedMap());
}
@Test
- public void testRestClientCarrierTechnologyHttpCodeFilterOk() throws ParameterException {
+ void testRestClientCarrierTechnologyHttpCodeFilterOk() throws ParameterException {
ApexCommandLineArguments arguments = new ApexCommandLineArguments();
arguments.setToscaPolicyFilePath("src/test/resources/prodcons/RESTClientWithHTTPHeaderOK.json");
arguments.setRelativeFileRoot(".");
@@ -128,7 +129,7 @@ public class RestClientCarrierTechnologyParametersTest {
}
@Test
- public void testGettersAndSetters() {
+ void testGettersAndSetters() {
RestClientCarrierTechnologyParameters rrctp = new RestClientCarrierTechnologyParameters();
rrctp.setUrl("http://some.where");
@@ -168,7 +169,7 @@ public class RestClientCarrierTechnologyParametersTest {
}
@Test
- public void testUrlValidation() {
+ void testUrlValidation() {
RestClientCarrierTechnologyParameters rrctp = new RestClientCarrierTechnologyParameters();
rrctp.setUrl("http://some.where.no.tag.in.url");
@@ -186,29 +187,27 @@ public class RestClientCarrierTechnologyParametersTest {
assertEquals("ccc", rrctp.getHttpHeaders()[1][0]);
assertEquals("ddd", rrctp.getHttpHeaders()[1][1]);
- assertEquals(true, rrctp.validate().isValid());
+ assertTrue(rrctp.validate().isValid());
rrctp.setUrl("http://{place}.{that}/is{that}.{one}");
- assertEquals(true, rrctp.validate().isValid());
+ assertTrue(rrctp.validate().isValid());
Set<String> keymap = rrctp.getKeysFromUrl();
- assertEquals(true, keymap.contains("place"));
- assertEquals(true, keymap.contains("that"));
- assertEquals(true, keymap.contains("one"));
+ assertTrue(keymap.contains("place") && keymap.contains("that") && keymap.contains("one"));
rrctp.setUrl("http://{place.{that}/{is}.{not}/{what}.{exist}");
- assertEquals(false, rrctp.validate().isValid());
+ assertFalse(rrctp.validate().isValid());
rrctp.setUrl("http://{place}.{that}/{is}.{not}/{what}.{exist");
- assertEquals(false, rrctp.validate().isValid());
+ assertFalse(rrctp.validate().isValid());
rrctp.setUrl("http://place.that/is.not/what.{exist");
- assertEquals(false, rrctp.validate().isValid());
+ assertFalse(rrctp.validate().isValid());
rrctp.setUrl("http://place}.{that}/{is}.{not}/{what}.{exist}");
- assertEquals(false, rrctp.validate().isValid());
+ assertFalse(rrctp.validate().isValid());
rrctp.setUrl("http://{place}.{that}/is}.{not}/{what}.{exist}");
- assertEquals(false, rrctp.validate().isValid());
+ assertFalse(rrctp.validate().isValid());
rrctp.setUrl("http://{place}.{that}/{}.{not}/{what}.{exist}");
- assertEquals(false, rrctp.validate().isValid());
+ assertFalse(rrctp.validate().isValid());
rrctp.setUrl("http://{place}.{that}/{ }.{not}/{what}.{exist}");
- assertEquals(false, rrctp.validate().isValid());
+ assertFalse(rrctp.validate().isValid());
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestTest.java
index d7b418a78..fe779eb89 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 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,18 +22,18 @@
package org.onap.policy.apex.plugins.event.carrier.restrequestor;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Properties;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test the ApexRestRequest class.
*/
-public class ApexRestRequestTest {
+class ApexRestRequestTest {
@Test
- public void testApexRestRequest() {
+ void testApexRestRequest() {
final String eventName = "EventName";
final String eventString = "The Event String";
@@ -50,6 +50,6 @@ public class ApexRestRequestTest {
assertEquals(1234567, rr.getTimestamp());
assertEquals("ApexRestRequest(executionId=1, eventName=EventName, event=The Event String, timestamp=1234567)",
- rr.toString());
+ rr.toString());
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java
index e72fa9030..47f90454c 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorConsumerTest.java
@@ -23,13 +23,13 @@ package org.onap.policy.apex.plugins.event.carrier.restrequestor;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.awaitility.Awaitility.await;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
@@ -38,45 +38,40 @@ import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMo
/**
* Test the ApexRestRequestorConsumer class.
- *
*/
-public class ApexRestRequestorConsumerTest {
+class ApexRestRequestorConsumerTest {
// String constants
private static final String CONSUMER_NAME = "ConsumerName";
private static final String EVENT_NAME = "EventName";
private static final String EVENT_BODY = "Event body";
@Test
- public void testApexRestRequestorConsumerSetup() throws ApexEventException {
+ void testApexRestRequestorConsumerSetup() throws ApexEventException {
ApexRestRequestorConsumer consumer = new ApexRestRequestorConsumer();
assertNotNull(consumer);
EventHandlerParameters consumerParameters = new EventHandlerParameters();
ApexEventReceiver incomingEventReceiver = null;
- assertThatThrownBy(() -> {
- consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver);
- }).hasMessage("specified consumer properties are not applicable to REST Requestor consumer (ConsumerName)");
+ assertThatThrownBy(() -> consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver))
+ .hasMessage("specified consumer properties are not applicable to REST Requestor consumer (ConsumerName)");
RestRequestorCarrierTechnologyParameters rrctp = new RestRequestorCarrierTechnologyParameters();
consumerParameters.setCarrierTechnologyParameters(rrctp);
- assertThatThrownBy(() -> {
- consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver);
- }).hasMessage("REST Requestor consumer (ConsumerName) must run in peered requestor mode "
- + "with a REST Requestor producer");
+ assertThatThrownBy(() -> consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver))
+ .hasMessage("REST Requestor consumer (ConsumerName) must run in peered requestor mode "
+ + "with a REST Requestor producer");
consumerParameters.setPeeredMode(EventHandlerPeeredMode.REQUESTOR, true);
rrctp.setHttpMethod(null);
- assertThatThrownBy(() -> {
- consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver);
- }).hasMessage("no URL has been specified on REST Requestor consumer (ConsumerName)");
+ assertThatThrownBy(() -> consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver))
+ .hasMessage("no URL has been specified on REST Requestor consumer (ConsumerName)");
rrctp.setHttpMethod(RestRequestorCarrierTechnologyParameters.HttpMethod.GET);
rrctp.setUrl("ZZZZ");
- assertThatThrownBy(() -> {
- consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver);
- }).hasMessage("invalid URL has been specified on REST Requestor consumer (ConsumerName)");
+ assertThatThrownBy(() -> consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver))
+ .hasMessage("invalid URL has been specified on REST Requestor consumer (ConsumerName)");
rrctp.setHttpMethod(RestRequestorCarrierTechnologyParameters.HttpMethod.GET);
rrctp.setUrl("http://www.onap.org");
@@ -85,9 +80,8 @@ public class ApexRestRequestorConsumerTest {
consumer.init(CONSUMER_NAME, consumerParameters, incomingEventReceiver);
- assertThatThrownBy(() -> {
- consumer.processRestRequest(null);
- }).hasMessage("could not queue request \"null\" on REST Requestor consumer (ConsumerName)");
+ assertThatThrownBy(() -> consumer.processRestRequest(null))
+ .hasMessage("could not queue request \"null\" on REST Requestor consumer (ConsumerName)");
assertEquals(CONSUMER_NAME, consumer.getName());
assertEquals(0, consumer.getEventsReceived());
@@ -95,7 +89,7 @@ public class ApexRestRequestorConsumerTest {
}
@Test
- public void testApexRestRequestorConsumerRequest() throws ApexEventException {
+ void testApexRestRequestorConsumerRequest() throws ApexEventException {
ApexRestRequestorConsumer consumer = new ApexRestRequestorConsumer();
assertNotNull(consumer);
@@ -119,7 +113,7 @@ public class ApexRestRequestorConsumerTest {
}
@Test
- public void testApexRestRequestorConsumerUrlUpdate() throws ApexEventException {
+ void testApexRestRequestorConsumerUrlUpdate() throws ApexEventException {
ApexRestRequestorConsumer consumer = new ApexRestRequestorConsumer();
assertNotNull(consumer);
@@ -145,7 +139,7 @@ public class ApexRestRequestorConsumerTest {
}
@Test
- public void testApexRestRequestorConsumerUrlUpdateError() throws ApexEventException {
+ void testApexRestRequestorConsumerUrlUpdateError() throws ApexEventException {
ApexRestRequestorConsumer consumer = new ApexRestRequestorConsumer();
assertNotNull(consumer);
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java
index 450a21f01..0e57a31e9 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/ApexRestRequestorProducerTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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.
@@ -22,11 +22,12 @@
package org.onap.policy.apex.plugins.event.carrier.restrequestor;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.fail;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.service.engine.event.ApexEventConsumer;
import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.event.PeeredReference;
@@ -38,33 +39,30 @@ import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMo
/**
* Test the ApexRestRequestorProducer class.
*/
-public class ApexRestRequestorProducerTest {
+class ApexRestRequestorProducerTest {
// String constants
private static final String PRODUCER_NAME = "ProducerName";
@Test
- public void testApexRestRequestorProducerMethods() throws ApexEventException {
+ void testApexRestRequestorProducerMethods() throws ApexEventException {
ApexRestRequestorProducer producer = new ApexRestRequestorProducer();
assertNotNull(producer);
EventHandlerParameters producerParameters = new EventHandlerParameters();
- assertThatThrownBy(() -> {
- producer.init(PRODUCER_NAME, producerParameters);
- }).hasMessage("specified producer properties are not applicable to REST requestor producer (ProducerName)");
+ assertThatThrownBy(() -> producer.init(PRODUCER_NAME, producerParameters))
+ .hasMessage("specified producer properties are not applicable to REST requestor producer (ProducerName)");
RestRequestorCarrierTechnologyParameters rrctp = new RestRequestorCarrierTechnologyParameters();
producerParameters.setCarrierTechnologyParameters(rrctp);
- assertThatThrownBy(() -> {
- producer.init(PRODUCER_NAME, producerParameters);
- }).hasMessage("REST Requestor producer (ProducerName) must run in peered requestor mode "
- + "with a REST Requestor consumer");
+ assertThatThrownBy(() -> producer.init(PRODUCER_NAME, producerParameters))
+ .hasMessage("REST Requestor producer (ProducerName) must run in peered requestor mode "
+ + "with a REST Requestor consumer");
producerParameters.setPeeredMode(EventHandlerPeeredMode.REQUESTOR, true);
rrctp.setUrl("ZZZZ");
- assertThatThrownBy(() -> {
- producer.init(PRODUCER_NAME, producerParameters);
- }).hasMessage("URL may not be specified on REST Requestor producer (ProducerName)");
+ assertThatThrownBy(() -> producer.init(PRODUCER_NAME, producerParameters))
+ .hasMessage("URL may not be specified on REST Requestor producer (ProducerName)");
rrctp.setUrl(null);
rrctp.setHttpMethod(RestRequestorCarrierTechnologyParameters.HttpMethod.GET);
@@ -80,11 +78,11 @@ public class ApexRestRequestorProducerTest {
assertEquals(PRODUCER_NAME, producer.getName());
assertEquals(0, producer.getEventsSent());
- assertEquals(null, producer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
+ assertNull(producer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
}
@Test
- public void testApexRestRequestorProducerRequest() throws ApexEventException {
+ void testApexRestRequestorProducerRequest() throws ApexEventException {
EventHandlerParameters producerParameters = new EventHandlerParameters();
RestRequestorCarrierTechnologyParameters rrctp = new RestRequestorCarrierTechnologyParameters();
@@ -100,9 +98,8 @@ public class ApexRestRequestorProducerTest {
String eventName = "EventName";
String event = "This is the event";
- assertThatThrownBy(() -> {
- producer.sendEvent(12345, null, eventName, event);
- }).hasMessage("send of event failed, REST response consumer is not defined\n" + "This is the event");
+ assertThatThrownBy(() -> producer.sendEvent(12345, null, eventName, event))
+ .hasMessage("send of event failed, REST response consumer is not defined\n" + "This is the event");
ApexEventConsumer consumer = new ApexFileEventConsumer();
SynchronousEventCache eventCache =
@@ -111,9 +108,8 @@ public class ApexRestRequestorProducerTest {
PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR, consumer, producer);
producer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR, peeredReference);
- assertThatThrownBy(() -> {
- producer.sendEvent(12345, null, eventName, event);
- }).hasMessage("send of event failed, REST response consumer "
- + "is not an instance of ApexRestRequestorConsumer\n" + "This is the event");
+ assertThatThrownBy(() -> producer.sendEvent(12345, null, eventName, event))
+ .hasMessage("send of event failed, REST response consumer "
+ + "is not an instance of ApexRestRequestorConsumer\n" + "This is the event");
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java
index f17721bdc..d953cf8ce 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorCarrierTechnologyParametersTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 2024 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -24,12 +24,13 @@
package org.onap.policy.apex.plugins.event.carrier.restrequestor;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Set;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.service.engine.main.ApexCommandLineArguments;
import org.onap.policy.apex.service.parameters.ApexParameterHandler;
import org.onap.policy.apex.service.parameters.ApexParameters;
@@ -38,24 +39,24 @@ import org.onap.policy.common.parameters.ParameterException;
/**
* Test REST Requestor carrier technology parameters.
*/
-public class RestRequestorCarrierTechnologyParametersTest {
+class RestRequestorCarrierTechnologyParametersTest {
@Test
- public void testRestRequestorCarrierTechnologyParametersBadList() {
+ void testRestRequestorCarrierTechnologyParametersBadList() {
verifyException("src/test/resources/prodcons/RESTRequestorWithHTTPHeaderBadList.json",
- "item \"entry 2\" value \"null\" INVALID, is null");
+ "item \"entry 2\" value \"null\" INVALID, is null");
}
@Test
- public void testRestRequestorCarrierTechnologyParametersNotKvPairs() {
+ void testRestRequestorCarrierTechnologyParametersNotKvPairs() {
verifyException("src/test/resources/prodcons/RESTRequestorWithHTTPHeaderNotKvPairs.json",
- "item \"entry 0\" value \"[aaa, bbb, ccc]\" INVALID, must have one key");
+ "item \"entry 0\" value \"[aaa, bbb, ccc]\" INVALID, must have one key");
}
@Test
- public void testRestRequestorCarrierTechnologyParametersNulls() {
+ void testRestRequestorCarrierTechnologyParametersNulls() {
verifyException("src/test/resources/prodcons/RESTRequestorWithHTTPHeaderNulls.json",
- "\"key\"");
+ "\"key\"");
}
private void verifyException(String fileName, String expectedMsg) {
@@ -64,11 +65,11 @@ public class RestRequestorCarrierTechnologyParametersTest {
arguments.setRelativeFileRoot(".");
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments)).describedAs(fileName)
- .hasMessageContaining(expectedMsg);
+ .hasMessageContaining(expectedMsg);
}
@Test
- public void testRestRequestorCarrierTechnologyParametersOk() throws ParameterException {
+ void testRestRequestorCarrierTechnologyParametersOk() throws ParameterException {
ApexCommandLineArguments arguments = new ApexCommandLineArguments();
arguments.setToscaPolicyFilePath("src/test/resources/prodcons/RESTRequestorWithHTTPHeaderOK.json");
arguments.setRelativeFileRoot(".");
@@ -88,7 +89,7 @@ public class RestRequestorCarrierTechnologyParametersTest {
}
@Test
- public void testRestClientCarrierTechnologyParameterFilterInvalid() {
+ void testRestClientCarrierTechnologyParameterFilterInvalid() {
ApexCommandLineArguments arguments = new ApexCommandLineArguments();
arguments.setToscaPolicyFilePath("src/test/resources/prodcons/RESTClientWithHTTPFilterInvalid.json");
arguments.setRelativeFileRoot(".");
@@ -103,11 +104,11 @@ public class RestRequestorCarrierTechnologyParametersTest {
}
@Test
- public void testGettersAndSetters() {
+ void testGettersAndSetters() {
RestRequestorCarrierTechnologyParameters rrctp = new RestRequestorCarrierTechnologyParameters();
rrctp.setHttpHeaders(null);
- assertEquals(null, rrctp.getHttpHeadersAsMultivaluedMap());
+ assertNull(rrctp.getHttpHeadersAsMultivaluedMap());
rrctp.setUrl("http://some.where");
assertEquals("http://some.where", rrctp.getUrl());
@@ -146,7 +147,7 @@ public class RestRequestorCarrierTechnologyParametersTest {
}
@Test
- public void testUrlValidation() {
+ void testUrlValidation() {
RestRequestorCarrierTechnologyParameters rrctp = new RestRequestorCarrierTechnologyParameters();
rrctp.setUrl("http://some.where.no.tag.in.url");
@@ -164,30 +165,28 @@ public class RestRequestorCarrierTechnologyParametersTest {
assertEquals("ccc", rrctp.getHttpHeaders()[1][0]);
assertEquals("ddd", rrctp.getHttpHeaders()[1][1]);
- assertEquals(true, rrctp.validate().isValid());
+ assertTrue(rrctp.validate().isValid());
rrctp.setUrl("http://{place}.{that}/is{that}.{one}");
- assertEquals(true, rrctp.validate().isValid());
+ assertTrue(rrctp.validate().isValid());
Set<String> keymap = rrctp.getKeysFromUrl();
- assertEquals(true, keymap.contains("place"));
- assertEquals(true, keymap.contains("that"));
- assertEquals(true, keymap.contains("one"));
+ assertTrue(keymap.contains("place") && keymap.contains("that") && keymap.contains("one"));
rrctp.setUrl("http://{place.{that}/{is}.{not}/{what}.{exist}");
- assertEquals(false, rrctp.validate().isValid());
+ assertFalse(rrctp.validate().isValid());
rrctp.setUrl("http://{place}.{that}/{is}.{not}/{what}.{exist");
- assertEquals(false, rrctp.validate().isValid());
+ assertFalse(rrctp.validate().isValid());
rrctp.setUrl("http://place.that/is.not/what.{exist");
- assertEquals(false, rrctp.validate().isValid());
+ assertFalse(rrctp.validate().isValid());
rrctp.setUrl("http://place}.{that}/{is}.{not}/{what}.{exist}");
- assertEquals(false, rrctp.validate().isValid());
+ assertFalse(rrctp.validate().isValid());
rrctp.setUrl("http://{place}.{that}/is}.{not}/{what}.{exist}");
- assertEquals(false, rrctp.validate().isValid());
+ assertFalse(rrctp.validate().isValid());
rrctp.setUrl("http://{place}.{that}/{}.{not}/{what}.{exist}");
- assertEquals(false, rrctp.validate().isValid());
+ assertFalse(rrctp.validate().isValid());
rrctp.setUrl("http://{place}.{that}/{ }.{not}/{what}.{exist}");
- assertEquals(false, rrctp.validate().isValid());
+ assertFalse(rrctp.validate().isValid());
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java
index 257e533c4..3fe836485 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/RestRequestorTest.java
@@ -24,7 +24,7 @@ package org.onap.policy.apex.plugins.event.carrier.restrequestor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.Gson;
import jakarta.ws.rs.client.Client;
@@ -34,11 +34,11 @@ import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.Map;
import java.util.concurrent.TimeUnit;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.service.engine.main.ApexMain;
@@ -50,12 +50,12 @@ import org.onap.policy.common.utils.network.NetworkUtil;
/**
* The Class TestRestRequestor.
*/
-public class RestRequestorTest {
+class RestRequestorTest {
private static final int PORT = 32801;
private static HttpServletServer server;
- private ByteArrayOutputStream outContent = new ByteArrayOutputStream();
- private ByteArrayOutputStream errContent = new ByteArrayOutputStream();
+ private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
+ private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
private final PrintStream stdout = System.out;
private final PrintStream stderr = System.err;
@@ -65,8 +65,8 @@ public class RestRequestorTest {
*
* @throws Exception the exception
*/
- @BeforeClass
- public static void setUp() throws Exception {
+ @BeforeAll
+ static void setUp() throws Exception {
server = HttpServletServerFactoryInstance.getServerFactory().build(null, false, null, PORT, false,
"/TestRESTRequestor", false, false);
@@ -82,10 +82,9 @@ public class RestRequestorTest {
/**
* Tear down.
- *
*/
- @AfterClass
- public static void tearDown() {
+ @AfterAll
+ static void tearDown() {
if (server != null) {
server.stop();
}
@@ -94,8 +93,8 @@ public class RestRequestorTest {
/**
* Before test.
*/
- @Before
- public void beforeTest() {
+ @BeforeEach
+ void beforeTest() {
SupportRestRequestorEndpoint.resetCounters();
System.setOut(new PrintStream(outContent));
System.setErr(new PrintStream(errContent));
@@ -104,8 +103,8 @@ public class RestRequestorTest {
/**
* After test.
*/
- @After
- public void afterTest() {
+ @AfterEach
+ void afterTest() {
System.setOut(stdout);
System.setErr(stderr);
}
@@ -114,10 +113,10 @@ public class RestRequestorTest {
* Test rest requestor get.
*
* @throws MessagingException the messaging exception
- * @throws Exception an exception
+ * @throws Exception an exception
*/
@Test
- public void testRestRequestorGet() throws Exception {
+ void testRestRequestorGet() throws Exception {
final Client client = ClientBuilder.newClient();
final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGet.json"};
@@ -139,7 +138,7 @@ public class RestRequestorTest {
* @throws ApexException the apex exception
*/
@Test
- public void testRestRequestorGetEmpty() throws ApexException {
+ void testRestRequestorGetEmpty() throws ApexException {
final Client client = ClientBuilder.newClient();
final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGetEmpty.json"};
@@ -149,7 +148,7 @@ public class RestRequestorTest {
Response response = null;
// Wait for the required amount of events to be received or for 10 seconds
- double getsSoFar = 0.0;
+ double getsSoFar;
for (int i = 0; i < 40; i++) {
response = client.target("http://localhost:32801/TestRESTRequestor/apex/event/Stats")
.request("application/json").get();
@@ -160,8 +159,8 @@ public class RestRequestorTest {
final String responseString = response.readEntity(String.class);
- @SuppressWarnings("unchecked")
- final Map<String, Object> jsonMap = new Gson().fromJson(responseString, Map.class);
+ @SuppressWarnings("unchecked") final Map<String, Object> jsonMap =
+ new Gson().fromJson(responseString, Map.class);
getsSoFar = Double.parseDouble(jsonMap.get("GET").toString());
if (getsSoFar >= 50.0) {
@@ -183,7 +182,7 @@ public class RestRequestorTest {
* @throws ApexException the apex exception
*/
@Test
- public void testRestRequestorPut() throws ApexException {
+ void testRestRequestorPut() throws ApexException {
final Client client = ClientBuilder.newClient();
final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FilePut.json"};
@@ -205,7 +204,7 @@ public class RestRequestorTest {
* @throws ApexException the apex exception
*/
@Test
- public void testRestRequestorPost() throws ApexException {
+ void testRestRequestorPost() throws ApexException {
final Client client = ClientBuilder.newClient();
final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FilePost.json"};
@@ -227,7 +226,7 @@ public class RestRequestorTest {
* @throws ApexException the apex exception
*/
@Test
- public void testRestRequestorDelete() throws ApexException {
+ void testRestRequestorDelete() throws ApexException {
final Client client = ClientBuilder.newClient();
final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileDelete.json"};
@@ -250,7 +249,7 @@ public class RestRequestorTest {
* @throws ApexException the apex exception
*/
@Test
- public void testRestRequestorMultiInputs() throws ApexException {
+ void testRestRequestorMultiInputs() throws ApexException {
final Client client = ClientBuilder.newClient();
final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGetMulti.json"};
@@ -272,7 +271,7 @@ public class RestRequestorTest {
* @throws ApexException the apex exception
*/
@Test
- public void testRestRequestorProducerAlone() throws ApexException {
+ void testRestRequestorProducerAlone() throws ApexException {
final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGetProducerAlone.json"};
@@ -291,7 +290,7 @@ public class RestRequestorTest {
* @throws ApexException the apex exception
*/
@Test
- public void testRestRequestorConsumerAlone() throws ApexException {
+ void testRestRequestorConsumerAlone() throws ApexException {
final String[] args = {"src/test/resources/prodcons/File2RESTRequest2FileGetConsumerAlone.json"};
ApexMain apexMain = new ApexMain(args);
apexMain.shutdown();
@@ -307,8 +306,8 @@ public class RestRequestorTest {
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
final String responseString = response.readEntity(String.class);
- @SuppressWarnings("unchecked")
- final Map<String, Object> jsonMap = new Gson().fromJson(responseString, Map.class);
+ @SuppressWarnings("unchecked") final Map<String, Object> jsonMap =
+ new Gson().fromJson(responseString, Map.class);
return Double.parseDouble(jsonMap.get(statToGet).toString());
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/SupportRestRequestorEndpoint.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/SupportRestRequestorEndpoint.java
index b05c24333..f82add13f 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/SupportRestRequestorEndpoint.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restrequestor/src/test/java/org/onap/policy/apex/plugins/event/carrier/restrequestor/SupportRestRequestorEndpoint.java
@@ -46,9 +46,9 @@ public class SupportRestRequestorEndpoint {
private static int getMessagesReceived = 0;
private static int deleteMessagesReceived = 0;
- private static String EVENT_STRING = "{\n" + "\"nameSpace\": \"org.onap.policy.apex.events\",\n"
- + "\"name\": \"ResponseEvent\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_"
- + getMessagesReceived + "\",\n" + "\"target\": \"apex\",\n" + "\"intPar\": 9080\n" + "}";
+ private static final String EVENT_STRING = "{\n" + "\"nameSpace\": \"org.onap.policy.apex.events\",\n"
+ + "\"name\": \"ResponseEvent\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_"
+ + getMessagesReceived + "\",\n" + "\"target\": \"apex\",\n" + "\"intPar\": 9080\n" + "}";
/**
* Reset counters.
@@ -73,10 +73,10 @@ public class SupportRestRequestorEndpoint {
statMessagesReceived++;
}
return Response.status(200)
- .entity("{\"GET\": " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived + ",\"POST\": "
- + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + ",\"DELETE\": "
- + deleteMessagesReceived + "}")
- .build();
+ .entity("{\"GET\": " + getMessagesReceived + ",\"STAT\": " + statMessagesReceived + ",\"POST\": "
+ + postMessagesReceived + ",\"PUT\": " + putMessagesReceived + ",\"DELETE\": "
+ + deleteMessagesReceived + "}")
+ .build();
}
/**
@@ -129,8 +129,7 @@ public class SupportRestRequestorEndpoint {
postMessagesReceived++;
}
- @SuppressWarnings("unchecked")
- final Map<String, Object> jsonMap = new Gson().fromJson(jsonString, Map.class);
+ @SuppressWarnings("unchecked") final Map<String, Object> jsonMap = new Gson().fromJson(jsonString, Map.class);
assertTrue(jsonMap.containsKey("name"));
assertEquals("0.0.1", jsonMap.get("version"));
assertEquals("org.onap.policy.apex.events", jsonMap.get("nameSpace"));
@@ -165,8 +164,7 @@ public class SupportRestRequestorEndpoint {
putMessagesReceived++;
}
- @SuppressWarnings("unchecked")
- final Map<String, Object> jsonMap = new Gson().fromJson(jsonString, Map.class);
+ @SuppressWarnings("unchecked") final Map<String, Object> jsonMap = new Gson().fromJson(jsonString, Map.class);
assertTrue(jsonMap.containsKey("name"));
assertEquals("0.0.1", jsonMap.get("version"));
assertEquals("org.onap.policy.apex.events", jsonMap.get("nameSpace"));
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/AccessControlFilterTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/AccessControlFilterTest.java
index 1ec0d52bb..b2e158f1a 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/AccessControlFilterTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/AccessControlFilterTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021, 2023 Nordix Foundation.
+ * Copyright (C) 2021, 2023-2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,7 @@
package org.onap.policy.apex.plugins.event.carrier.restserver;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.container.ContainerResponseContext;
@@ -29,16 +29,16 @@ import jakarta.ws.rs.core.MultivaluedHashMap;
import jakarta.ws.rs.core.MultivaluedMap;
import java.io.IOException;
import org.apache.commons.lang3.RandomStringUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
-@RunWith(MockitoJUnitRunner.class)
-public class AccessControlFilterTest {
+@ExtendWith(MockitoExtension.class)
+class AccessControlFilterTest {
private AccessControlFilter acf;
@@ -47,13 +47,13 @@ public class AccessControlFilterTest {
@Mock
private ContainerResponseContext responseContext;
- @Before
+ @BeforeEach
public void beforeEach() {
acf = new AccessControlFilter();
}
@Test
- public void filterAddToExisting() throws IOException {
+ void filterAddToExisting() throws IOException {
// prepare mocks
final String origin = RandomStringUtils.randomAlphanumeric(14, 16);
final MultivaluedHashMap<String, Object> map = new MultivaluedHashMap<>();
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumerTest.java
index 5f7cb257b..291a97c70 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerConsumerTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Samsung. All rights reserved.
- * Modifications Copyright (C) 2019-2021, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021, 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,84 +21,84 @@
package org.onap.policy.apex.plugins.event.carrier.restserver;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import jakarta.ws.rs.core.Response;
import java.io.IOException;
import java.lang.reflect.Field;
-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.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
import org.onap.policy.apex.service.engine.event.ApexPluginsEventConsumer;
import org.onap.policy.apex.service.engine.event.PeeredReference;
-import org.onap.policy.apex.service.engine.event.SynchronousEventCache;
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
import org.onap.policy.common.endpoints.http.server.HttpServletServer;
import org.onap.policy.common.utils.network.NetworkUtil;
-public class ApexRestServerConsumerTest {
+class ApexRestServerConsumerTest {
ApexRestServerConsumer apexRestServerConsumer = null;
EventHandlerParameters consumerParameters = null;
ApexEventReceiver incomingEventReceiver = null;
ApexRestServerProducer apexRestServerProducer = null;
RestServerCarrierTechnologyParameters restServerCarrierTechnologyParameters = null;
- SynchronousEventCache synchronousEventCache = null;
+
+ AutoCloseable closeable;
/**
* Set up testing.
- *
- * @throws Exception on test set up errors.
*/
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
apexRestServerConsumer = new ApexRestServerConsumer();
consumerParameters = new EventHandlerParameters();
apexRestServerProducer = new ApexRestServerProducer();
apexRestServerConsumer.start();
}
- @After
- public void tearDown() {
+ @AfterEach
+ void tearDown() {
apexRestServerConsumer.stop();
}
- @Test(expected = ApexEventException.class)
- public void testInitWithNonWebSocketCarrierTechnologyParameters() throws ApexEventException {
- consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {});
- apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters,
- incomingEventReceiver);
+ @Test
+ void testInitWithNonWebSocketCarrierTechnologyParameters() {
+ consumerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {
+ });
+ assertThrows(ApexEventException.class, () ->
+ apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters, incomingEventReceiver));
}
- @Test(expected = ApexEventException.class)
- public void testInitWithWebSocketCarrierTechnologyParameters() throws ApexEventException {
+ @Test
+ void testInitWithWebSocketCarrierTechnologyParameters() {
restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
consumerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters);
- apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters,
- incomingEventReceiver);
+ assertThrows(ApexEventException.class, () ->
+ apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters, incomingEventReceiver));
}
- @Test(expected = ApexEventException.class)
- public void testInitWithSynchronousMode() throws ApexEventException, SecurityException, IllegalArgumentException {
+ @Test
+ void testInitWithSynchronousMode() throws SecurityException, IllegalArgumentException {
restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
restServerCarrierTechnologyParameters.setStandalone(true);
consumerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters);
consumerParameters.setPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS, true);
- apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters,
- incomingEventReceiver);
+
+ assertThrows(ApexEventException.class, () -> apexRestServerConsumer.init("TestApexRestServerConsumer",
+ consumerParameters, incomingEventReceiver));
}
- @Test(expected = IllegalArgumentException.class)
- public void testInitWithSynchronousModeAndProperValues()
- throws ApexEventException, SecurityException, IllegalArgumentException {
+ @Test
+ void testInitWithSynchronousModeAndProperValues() throws SecurityException, IllegalArgumentException {
restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
@@ -109,12 +109,14 @@ public class ApexRestServerConsumerTest {
consumerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters);
consumerParameters.setPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS, true);
- apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters,
- incomingEventReceiver);
+
+ assertThrows(IllegalArgumentException.class,
+ () -> apexRestServerConsumer.init("TestApexRestServerConsumer", consumerParameters,
+ incomingEventReceiver));
}
@Test
- public void testInitAndStop() throws ApexEventException, IOException {
+ void testInitAndStop() throws ApexEventException, IOException {
restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
restServerCarrierTechnologyParameters.setStandalone(true);
@@ -138,39 +140,39 @@ public class ApexRestServerConsumerTest {
}
@Test
- public void testGetName() {
+ void testGetName() {
assertNull(apexRestServerConsumer.getName());
}
@Test
- public void testGetPeeredReference() {
+ void testGetPeeredReference() {
assertNull(apexRestServerConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
}
@Test
- public void testSetPeeredReference() {
+ void testSetPeeredReference() {
PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR,
- apexRestServerConsumer, apexRestServerProducer);
+ apexRestServerConsumer, apexRestServerProducer);
apexRestServerConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR,
- peeredReference);
+ peeredReference);
assertNotNull(apexRestServerConsumer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
}
@Test
- public void testReceiveEvent() throws ApexEventException {
+ void testReceiveEvent() {
Response response = apexRestServerConsumer.receiveEvent("");
assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus());
+ response.close();
}
- @Test(expected = NullPointerException.class)
- public void testReceiveEventWithNonDefaultValues()
- throws ApexEventException, NoSuchFieldException, SecurityException,
- IllegalArgumentException, IllegalAccessException {
+ @Test
+ void testReceiveEventWithNonDefaultValues() throws NoSuchFieldException, SecurityException,
+ IllegalArgumentException, IllegalAccessException {
PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR,
- apexRestServerConsumer, apexRestServerProducer);
+ apexRestServerConsumer, apexRestServerProducer);
apexRestServerConsumer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR,
- peeredReference);
+ peeredReference);
ApexEventReceiver apexEventReceiver = new SupportApexEventReceiver();
@@ -178,8 +180,14 @@ public class ApexRestServerConsumerTest {
Field field = ApexPluginsEventConsumer.class.getDeclaredField("name");
field.setAccessible(true);
field.set(apexRestServerConsumer, "TestApexRestServerConsumer");
+ assertThrows(NullPointerException.class, () ->
+ closeable = apexRestServerConsumer.receiveEvent("TestApexRestServerConsumer"));
+ }
- apexRestServerConsumer.receiveEvent("TestApexRestServerConsumer");
-
+ @AfterEach
+ void after() throws Exception {
+ if (closeable != null) {
+ closeable.close();
+ }
}
}
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducerTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducerTest.java
index 34992ff1d..435af0996 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducerTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/ApexRestServerProducerTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Samsung. All rights reserved.
- * Modifications Copyright (C) 2019-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021, 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,34 +21,32 @@
package org.onap.policy.apex.plugins.event.carrier.restserver;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import java.lang.reflect.Field;
import java.util.Random;
import org.apache.commons.lang3.RandomStringUtils;
-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.service.engine.event.ApexEventException;
-import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
import org.onap.policy.apex.service.engine.event.PeeredReference;
import org.onap.policy.apex.service.engine.event.SynchronousEventCache;
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
-public class ApexRestServerProducerTest {
+class ApexRestServerProducerTest {
ApexRestServerProducer apexRestServerProducer = null;
EventHandlerParameters producerParameters = null;
- ApexEventReceiver incomingEventReceiver = null;
ApexRestServerConsumer apexRestServerConsumer = null;
RestServerCarrierTechnologyParameters restServerCarrierTechnologyParameters = null;
- SynchronousEventCache synchronousEventCache = null;
Random random = new Random();
/**
@@ -56,35 +54,38 @@ public class ApexRestServerProducerTest {
*
* @throws Exception on test set up errors.
*/
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
apexRestServerConsumer = new ApexRestServerConsumer();
producerParameters = new EventHandlerParameters();
apexRestServerProducer = new ApexRestServerProducer();
}
- @After
- public void tearDown() {
+ @AfterEach
+ void tearDown() {
apexRestServerProducer.stop();
}
- @Test(expected = ApexEventException.class)
- public void testInitWithNonWebSocketCarrierTechnologyParameters() throws ApexEventException {
- producerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {});
- apexRestServerProducer.init("TestApexRestServerProducer", producerParameters);
+ @Test
+ void testInitWithNonWebSocketCarrierTechnologyParameters() {
+ producerParameters.setCarrierTechnologyParameters(new CarrierTechnologyParameters() {
+ });
+ assertThrows(ApexEventException.class, () ->
+ apexRestServerProducer.init("TestApexRestServerProducer", producerParameters));
}
- @Test(expected = ApexEventException.class)
- public void testInitWithWebSocketCarrierTechnologyParameters() throws ApexEventException {
+ @Test
+ void testInitWithWebSocketCarrierTechnologyParameters() {
restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
producerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters);
- apexRestServerProducer.init("TestApexRestServerProducer", producerParameters);
+ assertThrows(ApexEventException.class, () ->
+ apexRestServerProducer.init("TestApexRestServerProducer", producerParameters));
}
- @Test(expected = ApexEventException.class)
- public void testInitWithNonDefaultValue() throws ApexEventException, NoSuchFieldException,
- SecurityException, IllegalArgumentException, IllegalAccessException {
+ @Test
+ void testInitWithNonDefaultValue() throws NoSuchFieldException,
+ SecurityException, IllegalArgumentException, IllegalAccessException {
restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("host");
field.setAccessible(true);
@@ -93,11 +94,12 @@ public class ApexRestServerProducerTest {
field.setAccessible(true);
field.set(restServerCarrierTechnologyParameters, 65535);
producerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters);
- apexRestServerProducer.init("TestApexRestServerProducer", producerParameters);
+ assertThrows(ApexEventException.class, () ->
+ apexRestServerProducer.init("TestApexRestServerProducer", producerParameters));
}
@Test
- public void testInitWithSynchronousMode() throws ApexEventException {
+ void testInitWithSynchronousMode() throws ApexEventException {
restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
producerParameters.setCarrierTechnologyParameters(restServerCarrierTechnologyParameters);
producerParameters.setPeeredMode(EventHandlerPeeredMode.SYNCHRONOUS, true);
@@ -106,26 +108,26 @@ public class ApexRestServerProducerTest {
}
@Test
- public void testGetName() {
+ void testGetName() {
assertNull(apexRestServerProducer.getName());
}
@Test
- public void testGetPeeredReference() {
+ void testGetPeeredReference() {
assertNull(apexRestServerProducer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
}
@Test
- public void testSetPeeredReference() {
+ void testSetPeeredReference() {
PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.REQUESTOR,
- apexRestServerConsumer, apexRestServerProducer);
+ apexRestServerConsumer, apexRestServerProducer);
apexRestServerProducer.setPeeredReference(EventHandlerPeeredMode.REQUESTOR,
- peeredReference);
+ peeredReference);
assertNotNull(apexRestServerProducer.getPeeredReference(EventHandlerPeeredMode.REQUESTOR));
}
@Test
- public void testSendEventNotExistingEventToApex() {
+ void testSendEventNotExistingEventToApex() {
final long executionId = random.nextLong();
final String eventName = RandomStringUtils.randomAlphabetic(7);
final Object event = new Object();
@@ -143,7 +145,7 @@ public class ApexRestServerProducerTest {
}
@Test
- public void testSendEvent() {
+ void testSendEvent() {
final long executionId = random.nextLong();
final String eventName = RandomStringUtils.randomAlphabetic(7);
final Object expected = new Object();
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java
index ef78d3211..ab7a54cdd 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/RestServerCarrierTechnologyParametersTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Samsung. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,16 +23,16 @@
package org.onap.policy.apex.plugins.event.carrier.restserver;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+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 java.lang.reflect.Field;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.ValidationResult;
-public class RestServerCarrierTechnologyParametersTest {
+class RestServerCarrierTechnologyParametersTest {
RestServerCarrierTechnologyParameters restServerCarrierTechnologyParameters = null;
ValidationResult result = null;
@@ -40,28 +40,27 @@ public class RestServerCarrierTechnologyParametersTest {
/**
* Set up testing.
*
- * @throws Exception on test set up errors.
*/
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
restServerCarrierTechnologyParameters = new RestServerCarrierTechnologyParameters();
}
@Test
- public void testRestServerCarrierTechnologyParameters() {
+ void testRestServerCarrierTechnologyParameters() {
assertNotNull(restServerCarrierTechnologyParameters);
assertFalse(restServerCarrierTechnologyParameters.isStandalone());
}
@Test
- public void testValidate() {
+ void testValidate() {
result = restServerCarrierTechnologyParameters.validate();
assertNotNull(result);
assertTrue(result.isValid());
}
@Test
- public void testValidateWithNonDefaultValues() throws NoSuchFieldException, SecurityException,
+ void testValidateWithNonDefaultValues() throws NoSuchFieldException, SecurityException,
IllegalArgumentException, IllegalAccessException {
Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("standalone");
@@ -89,7 +88,7 @@ public class RestServerCarrierTechnologyParametersTest {
}
@Test
- public void testValidateWithValidValues() throws NoSuchFieldException, SecurityException,
+ void testValidateWithValidValues() throws NoSuchFieldException, SecurityException,
IllegalArgumentException, IllegalAccessException {
Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("standalone");
@@ -119,7 +118,7 @@ public class RestServerCarrierTechnologyParametersTest {
}
@Test
- public void testValidateWithInvalidValues() throws NoSuchFieldException, SecurityException,
+ void testValidateWithInvalidValues() throws NoSuchFieldException, SecurityException,
IllegalArgumentException, IllegalAccessException {
Field field = RestServerCarrierTechnologyParameters.class.getDeclaredField("standalone");
diff --git a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java
index 773ecafb2..b10eecf21 100644
--- a/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java
+++ b/plugins/plugins-event/plugins-event-carrier/plugins-event-carrier-restserver/src/test/java/org/onap/policy/apex/plugins/event/carrier/restserver/SupportApexEventReceiver.java
@@ -27,7 +27,7 @@ import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.event.ApexEventReceiver;
/**
- * Support Apex event reveiver for unit test.
+ * Support Apex event receiver for unit test.
*
*/
@Getter
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/pom.xml b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/pom.xml
index 5f643c04a..2ca3cf24d 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/pom.xml
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/pom.xml
@@ -21,6 +21,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-protocol</groupId>
+ <artifactId>plugins-event-protocol</artifactId>
+ <version>4.0.0-SNAPSHOT</version>
+ </parent>
+
<artifactId>plugins-event-protocol-jms</artifactId>
<name>${project.artifactId}</name>
<description>[${project.parent.artifactId}] Plugins for handling events that are being transported as JMS messages
@@ -33,10 +39,10 @@
<version>${version.activemq}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>jakarta.jms</groupId>
+ <artifactId>jakarta.jms-api</artifactId>
+ <version>${version.jms}</version>
+ </dependency>
</dependencies>
- <parent>
- <groupId>org.onap.policy.apex-pdp.plugins.plugins-event.plugins-event-protocol</groupId>
- <artifactId>plugins-event-protocol</artifactId>
- <version>4.0.0-SNAPSHOT</version>
- </parent>
</project> \ No newline at end of file
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverterTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverterTest.java
index 701326f71..c828f789a 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverterTest.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsObjectEventConverterTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021, 2023 Nordix Foundation.
+ * Copyright (C) 2021, 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,9 +22,9 @@ package org.onap.policy.apex.plugins.event.protocol.jms;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import jakarta.jms.JMSException;
import jakarta.jms.ObjectMessage;
@@ -33,39 +33,39 @@ import java.io.PrintStream;
import java.util.List;
import org.apache.activemq.command.ActiveMQObjectMessage;
import org.apache.commons.lang3.RandomStringUtils;
-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.service.engine.event.ApexEvent;
import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
import org.onap.policy.apex.service.engine.event.impl.apexprotocolplugin.ApexEventProtocolParameters;
-public class Apex2JmsObjectEventConverterTest {
+class Apex2JmsObjectEventConverterTest {
private Apex2JmsObjectEventConverter converter;
private final PrintStream orgOutBuffer = System.out;
private ByteArrayOutputStream testOutStream;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
converter = new Apex2JmsObjectEventConverter();
testOutStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(testOutStream));
}
- @After
- public void tearDown() {
+ @AfterEach
+ void tearDown() {
System.setOut(orgOutBuffer);
}
@Test
- public void initNull() {
+ void initNull() {
assertThatThrownBy(() -> converter.init(null))
.isInstanceOf(NullPointerException.class);
}
@Test
- public void initWrongClass() {
+ void initWrongClass() {
converter.init(new ApexEventProtocolParameters());
final String actual = testOutStream.toString();
assertThat(actual).contains("specified Event Protocol Parameters properties of typ");
@@ -73,7 +73,7 @@ public class Apex2JmsObjectEventConverterTest {
}
@Test
- public void init() {
+ void init() {
final JmsObjectEventProtocolParameters parameters = new JmsObjectEventProtocolParameters();
converter.init(parameters);
final JmsObjectEventProtocolParameters actual = converter.getEventProtocolParameters();
@@ -81,7 +81,7 @@ public class Apex2JmsObjectEventConverterTest {
}
@Test
- public void toApexEventNull() {
+ void toApexEventNull() {
final JmsObjectEventProtocolParameters parameters = new JmsObjectEventProtocolParameters();
converter.init(parameters);
final String eventName = RandomStringUtils.randomAlphabetic(4);
@@ -90,7 +90,7 @@ public class Apex2JmsObjectEventConverterTest {
}
@Test
- public void toApexEventObject() {
+ void toApexEventObject() {
final JmsObjectEventProtocolParameters parameters = new JmsObjectEventProtocolParameters();
converter.init(parameters);
final String eventName = RandomStringUtils.randomAlphabetic(4);
@@ -99,31 +99,31 @@ public class Apex2JmsObjectEventConverterTest {
}
@Test
- public void toApexEventNoParams() {
+ void toApexEventNoParams() {
final String eventName = RandomStringUtils.randomAlphabetic(4);
- ObjectMessage object = new ActiveMQObjectMessage();
+ ObjectMessage object = (ObjectMessage) new ActiveMQObjectMessage();
assertThatThrownBy(() -> converter.toApexEvent(eventName, object))
.isInstanceOf(ApexEventRuntimeException.class);
}
@Test
- public void toApexEventIncomingObjectIsNull() {
+ void toApexEventIncomingObjectIsNull() {
final JmsObjectEventProtocolParameters parameters = new JmsObjectEventProtocolParameters();
converter.init(parameters);
final String eventName = RandomStringUtils.randomAlphabetic(4);
- ObjectMessage object = new ActiveMQObjectMessage();
+ ObjectMessage object = (ObjectMessage) new ActiveMQObjectMessage();
assertThatThrownBy(() -> converter.toApexEvent(eventName, object))
.isInstanceOf(NullPointerException.class);
}
@Test
- public void toApexEvent() throws ApexEventException, JMSException {
+ void toApexEvent() throws ApexEventException, JMSException {
final JmsObjectEventProtocolParameters parameters = new JmsObjectEventProtocolParameters();
converter.init(parameters);
final String eventName = RandomStringUtils.randomAlphabetic(4);
- final ObjectMessage object = new ActiveMQObjectMessage();
+ final ObjectMessage object = (ObjectMessage) new ActiveMQObjectMessage();
final String value = RandomStringUtils.randomAlphabetic(3);
object.setObject(value);
@@ -145,13 +145,12 @@ public class Apex2JmsObjectEventConverterTest {
}
@Test
- public void fromApexEventNull() {
- assertThatThrownBy(() -> converter.fromApexEvent(null))
- .isInstanceOf(ApexEventException.class);
+ void fromApexEventNull() {
+ assertThatThrownBy(() -> converter.fromApexEvent(null)).isInstanceOf(ApexEventException.class);
}
@Test
- public void fromApexEventEmptyEvent() throws ApexEventException {
+ void fromApexEventEmptyEvent() throws ApexEventException {
final ApexEvent apexEvent = new ApexEvent(
"a" + RandomStringUtils.randomAlphabetic(3),
"a" + RandomStringUtils.randomAlphabetic(3),
@@ -163,7 +162,7 @@ public class Apex2JmsObjectEventConverterTest {
}
@Test
- public void fromApexEventMultipleEvents() throws ApexEventException {
+ void fromApexEventMultipleEvents() throws ApexEventException {
final ApexEvent apexEvent = new ApexEvent(
"a" + RandomStringUtils.randomAlphabetic(3),
"a" + RandomStringUtils.randomAlphabetic(4),
@@ -176,7 +175,7 @@ public class Apex2JmsObjectEventConverterTest {
}
@Test
- public void fromApexEventSingleEvent() throws ApexEventException {
+ void fromApexEventSingleEvent() throws ApexEventException {
final ApexEvent apexEvent = new ApexEvent(
"a" + RandomStringUtils.randomAlphabetic(3),
"a" + RandomStringUtils.randomAlphabetic(3),
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverterTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverterTest.java
index 9f68b49df..a2ff9d02f 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverterTest.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/Apex2JmsTextEventConverterTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021, 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,14 @@
package org.onap.policy.apex.plugins.event.protocol.jms;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
-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.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.SchemaParameters;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
@@ -45,40 +44,41 @@ import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer
import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.JsonEventProtocolParameters;
import org.onap.policy.common.parameters.ParameterService;
-public class Apex2JmsTextEventConverterTest {
+class Apex2JmsTextEventConverterTest {
private Apex2JmsTextEventConverter converter;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
converter = new Apex2JmsTextEventConverter();
ModelService.registerModel(AxContextSchemas.class, new AxContextSchemas());
ModelService.registerModel(AxEvents.class, new AxEvents());
ParameterService.register(new SchemaParameters());
}
- @After
- public void tearDown() {
+ @AfterEach
+ void tearDown() {
ModelService.deregisterModel(AxContextSchema.class);
ModelService.deregisterModel(AxEvents.class);
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
@Test
- public void toApexEventNull() {
+ void toApexEventNull() {
final String eventName = RandomStringUtils.randomAlphabetic(4);
assertThatThrownBy(() -> converter.toApexEvent(eventName, null))
.isInstanceOf(ApexEventRuntimeException.class);
}
@Test
- public void toApexEventObject() {
+ void toApexEventObject() {
final String eventName = RandomStringUtils.randomAlphabetic(4);
- assertThatThrownBy(() -> converter.toApexEvent(eventName, new Object()))
- .isInstanceOf(ApexEventRuntimeException.class);
+ var object = new Object();
+ assertThatThrownBy(() -> converter.toApexEvent(eventName, object)).isInstanceOf(
+ ApexEventRuntimeException.class);
}
@Test
- public void toApexEventJsonString() throws ApexEventException {
+ void toApexEventJsonString() throws ApexEventException {
final String eventName = RandomStringUtils.randomAlphabetic(4);
final String eventVersion = "0.0.1";
final String source = RandomStringUtils.randomAlphabetic(5);
@@ -113,12 +113,12 @@ public class Apex2JmsTextEventConverterTest {
}
@Test
- public void fromApexNull() {
+ void fromApexNull() {
assertThatThrownBy(() -> converter.fromApexEvent(null)).isInstanceOf(ApexEventException.class);
}
@Test
- public void fromApex() throws ApexEventException {
+ void fromApex() throws ApexEventException {
final String name = RandomStringUtils.randomAlphabetic(4);
final String version = "0.2.3";
final String nameSpace = "a.name.space";
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/JmsObjectEventProtocolParametersTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/JmsObjectEventProtocolParametersTest.java
index 8baa9d5b1..1f480a654 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/JmsObjectEventProtocolParametersTest.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-jms/src/main/test/org/onap/policy/apex/plugins/event/protocol/jms/JmsObjectEventProtocolParametersTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,15 +20,15 @@
package org.onap.policy.apex.plugins.event.protocol.jms;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.jupiter.api.Test;
-import org.junit.Test;
-public class JmsObjectEventProtocolParametersTest {
+class JmsObjectEventProtocolParametersTest {
@Test
- public void getIncomingEventVersion() {
+ void getIncomingEventVersion() {
final JmsObjectEventProtocolParameters jmsObjectEventProtocolParameters =
new JmsObjectEventProtocolParameters();
final String actual = jmsObjectEventProtocolParameters.getIncomingEventVersion();
@@ -36,7 +36,7 @@ public class JmsObjectEventProtocolParametersTest {
}
@Test
- public void getIncomingEventSource() {
+ void getIncomingEventSource() {
final JmsObjectEventProtocolParameters jmsObjectEventProtocolParameters =
new JmsObjectEventProtocolParameters();
final String actual = jmsObjectEventProtocolParameters.getIncomingEventSource();
@@ -44,7 +44,7 @@ public class JmsObjectEventProtocolParametersTest {
}
@Test
- public void getIncomingEventTarget() {
+ void getIncomingEventTarget() {
final JmsObjectEventProtocolParameters jmsObjectEventProtocolParameters =
new JmsObjectEventProtocolParameters();
final String actual = jmsObjectEventProtocolParameters.getIncomingEventTarget();
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java
index 2fbae65e4..b0da163f8 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlEventProtocolTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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.
@@ -22,16 +22,15 @@
package org.onap.policy.apex.plugins.event.protocol.yaml;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
-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.SchemaParameters;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
@@ -52,15 +51,14 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
/**
* The Class TestYamlEventProtocol.
*/
-public class YamlEventProtocolTest {
+class YamlEventProtocolTest {
/**
* Register test events and schemas.
*
- * @throws IOException Signals that an I/O exception has occurred.
*/
- @BeforeClass
- public static void registerTestEventsAndSchemas() throws IOException {
+ @BeforeAll
+ static void registerTestEventsAndSchemas() {
SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters());
ParameterService.register(schemaParameters, true);
@@ -201,8 +199,8 @@ public class YamlEventProtocolTest {
/**
* Unregister test events and schemas.
*/
- @AfterClass
- public static void unregisterTestEventsAndSchemas() {
+ @AfterAll
+ static void unregisterTestEventsAndSchemas() {
ModelService.clear();
ParameterService.clear();
}
@@ -214,7 +212,7 @@ public class YamlEventProtocolTest {
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
- public void testYamlProcessing() throws ApexEventException, IOException {
+ void testYamlProcessing() throws ApexEventException, IOException {
assertThatThrownBy(() -> testYamlDecodeEncode("TestEvent0", 1, 0, "Empty0"))
.hasMessage("event processing failed, event is null");
testYamlDecodeEncode("TestEvent0", 1, 0, "Empty1");
@@ -252,7 +250,7 @@ public class YamlEventProtocolTest {
converter.init(parameters);
String filePath = "src/test/resources/yaml_in/" + fileName + ".yaml";
- FileInputStream fileInputStream = new FileInputStream(new File(filePath));
+ FileInputStream fileInputStream = new FileInputStream(filePath);
HeaderDelimitedTextBlockReader reader = new HeaderDelimitedTextBlockReader(parameters);
reader.init(fileInputStream);
diff --git a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java
index fdab1d8c1..7332f341e 100644
--- a/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java
+++ b/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src/test/java/org/onap/policy/apex/plugins/event/protocol/yaml/YamlPluginStabilityTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020,2023 Nordix Foundation
+ * Modifications Copyright (C) 2020, 2023-2024 Nordix Foundation
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
@@ -24,14 +24,15 @@
package org.onap.policy.apex.plugins.event.protocol.yaml;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.io.IOException;
import java.util.List;
-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.SchemaParameters;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
@@ -50,16 +51,14 @@ import org.onap.policy.common.parameters.ParameterService;
/**
* The Class TestYamlPluginStability.
*/
-public class YamlPluginStabilityTest {
+class YamlPluginStabilityTest {
static AxEvent testEvent;
/**
* Register test events and schemas.
- *
- * @throws IOException Signals that an I/O exception has occurred.
*/
- @BeforeClass
- public static void registerTestEventsAndSchemas() throws IOException {
+ @BeforeAll
+ static void registerTestEventsAndSchemas() {
SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters());
ParameterService.register(schemaParameters);
@@ -67,15 +66,15 @@ public class YamlPluginStabilityTest {
AxContextSchemas schemas = new AxContextSchemas();
AxContextSchema simpleIntSchema = new AxContextSchema(new AxArtifactKey("SimpleIntSchema", "0.0.1"), "JAVA",
- "java.lang.Integer");
+ "java.lang.Integer");
schemas.getSchemasMap().put(simpleIntSchema.getKey(), simpleIntSchema);
AxContextSchema simpleDoubleSchema = new AxContextSchema(new AxArtifactKey("SimpleDoubleSchema", "0.0.1"),
- "JAVA", "java.lang.Double");
+ "JAVA", "java.lang.Double");
schemas.getSchemasMap().put(simpleDoubleSchema.getKey(), simpleDoubleSchema);
AxContextSchema simpleStringSchema = new AxContextSchema(new AxArtifactKey("SimpleStringSchema", "0.0.1"),
- "JAVA", "java.lang.String");
+ "JAVA", "java.lang.String");
schemas.getSchemasMap().put(simpleStringSchema.getKey(), simpleStringSchema);
ModelService.registerModel(AxContextSchemas.class, schemas);
@@ -86,10 +85,10 @@ public class YamlPluginStabilityTest {
AxField teField0 = new AxField(new AxReferenceKey(testEvent.getKey(), "intValue"), simpleIntSchema.getKey());
testEvent.getParameterMap().put("intValue", teField0);
AxField teField1 = new AxField(new AxReferenceKey(testEvent.getKey(), "doubleValue"),
- simpleDoubleSchema.getKey());
+ simpleDoubleSchema.getKey());
testEvent.getParameterMap().put("doubleValue", teField1);
AxField teField2 = new AxField(new AxReferenceKey(testEvent.getKey(), "stringValue"),
- simpleStringSchema.getKey(), true);
+ simpleStringSchema.getKey(), true);
testEvent.getParameterMap().put("stringValue", teField2);
AxEvents events = new AxEvents();
@@ -101,8 +100,8 @@ public class YamlPluginStabilityTest {
/**
* Unregister test events and schemas.
*/
- @AfterClass
- public static void unregisterTestEventsAndSchemas() {
+ @AfterAll
+ static void unregisterTestEventsAndSchemas() {
ModelService.clear();
ParameterService.clear();
}
@@ -112,9 +111,8 @@ public class YamlPluginStabilityTest {
*
* @throws ApexEventException the apex event exception
*/
- @SuppressWarnings("deprecation")
@Test
- public void testStability() throws ApexEventException {
+ void testStability() throws ApexEventException {
Apex2YamlEventConverter converter = new Apex2YamlEventConverter();
assertThatThrownBy(() -> converter.init(null))
@@ -122,20 +120,20 @@ public class YamlPluginStabilityTest {
YamlEventProtocolParameters pars = new YamlEventProtocolParameters();
converter.init(pars);
- assertThatThrownBy(() -> converter.toApexEvent("NonExistantEvent", ""))
+ assertThatThrownBy(() -> converter.toApexEvent("NonExistentEvent", ""))
.hasMessageContaining("Failed to unmarshal YAML event")
- .getCause().hasMessageStartingWith("an event definition for an event named \"NonExistantEvent\"");
+ .cause().hasMessageStartingWith("an event definition for an event named \"NonExistentEvent\"");
assertThatThrownBy(() -> converter.toApexEvent("TestEvent", null))
.hasMessage("event processing failed, event is null");
assertThatThrownBy(() -> converter.toApexEvent("TestEvent", 1))
.hasMessage("error converting event \"1\" to a string");
assertThatThrownBy(() -> converter.toApexEvent("TestEvent", ""))
- .getCause().hasMessageContaining("Field \"doubleValue\" is missing");
+ .cause().hasMessageContaining("Field \"doubleValue\" is missing");
assertThatThrownBy(() -> converter.fromApexEvent(null))
.hasMessage("event processing failed, Apex event is null");
ApexEvent apexEvent = new ApexEvent(testEvent.getKey().getName(), testEvent.getKey().getVersion(),
- testEvent.getNameSpace(), testEvent.getSource(), testEvent.getTarget(),
- testEvent.getToscaPolicyState());
+ testEvent.getNameSpace(), testEvent.getSource(), testEvent.getTarget(),
+ testEvent.getToscaPolicyState());
apexEvent.put("doubleValue", 123.45);
apexEvent.put("intValue", 123);
apexEvent.put("stringValue", "123.45");
@@ -149,15 +147,15 @@ public class YamlPluginStabilityTest {
.hasMessageContaining("error parsing TestEvent:0.0.1 event to Json. Field \"intValue\" is missing");
assertThatThrownBy(() -> converter.toApexEvent(null, ""))
.hasMessageStartingWith("Failed to unmarshal YAML event")
- .getCause().hasMessageStartingWith("event received without mandatory parameter \"name\"");
+ .cause().hasMessageStartingWith("event received without mandatory parameter \"name\"");
pars.setNameAlias("TheNameField");
assertThatThrownBy(() -> converter.toApexEvent(null, ""))
.hasMessageStartingWith("Failed to unmarshal YAML event")
- .getCause().hasMessageStartingWith("event received without mandatory parameter \"name\"");
+ .cause().hasMessageStartingWith("event received without mandatory parameter \"name\"");
apexEvent.put("intValue", 123);
apexEvent.remove("stringValue");
- yamlString = (String) converter.fromApexEvent(apexEvent);
+ assertNotNull(converter.fromApexEvent(apexEvent));
apexEvent.put("stringValue", "123.45");
String yamlInputString = "doubleValue: 123.45\n" + "intValue: 123";
@@ -165,60 +163,71 @@ public class YamlPluginStabilityTest {
List<ApexEvent> eventList = converter.toApexEvent("TestEvent", yamlInputString);
assertEquals(123.45, eventList.get(0).get("doubleValue"));
- yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: null";
+ yamlInputString = "doubleValue: 123.45\nintValue: 123\nstringValue: null";
eventList = converter.toApexEvent("TestEvent", yamlInputString);
- assertEquals(null, eventList.get(0).get("stringValue"));
+ assertNull(eventList.get(0).get("stringValue"));
- yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: TestEvent";
+ yamlInputString = "doubleValue: 123.45\nintValue: 123\nstringValue: TestEvent";
pars.setNameAlias("stringValue");
eventList = converter.toApexEvent(null, yamlInputString);
assertEquals("TestEvent", eventList.get(0).get("stringValue"));
- yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: SomeOtherEvent";
+ yamlInputString = "doubleValue: 123.45\nintValue: 123\nstringValue: SomeOtherEvent";
eventList = converter.toApexEvent("TestEvent", yamlInputString);
assertEquals("SomeOtherEvent", eventList.get(0).get("stringValue"));
- yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: 0.0.1";
+ yamlInputString = "doubleValue: 123.45\nintValue: 123\nstringValue: 0.0.1";
pars.setNameAlias(null);
pars.setVersionAlias("stringValue");
eventList = converter.toApexEvent("TestEvent", yamlInputString);
assertEquals("0.0.1", eventList.get(0).get("stringValue"));
- yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: org.some.other.namespace";
+ yamlInputString = "doubleValue: 123.45\nintValue: 123\nstringValue: org.some.other.namespace";
pars.setVersionAlias(null);
pars.setNameSpaceAlias("stringValue");
final String yamlInputStringCopy = yamlInputString;
assertThatThrownBy(() -> converter.toApexEvent("TestEvent", yamlInputStringCopy))
.hasMessageStartingWith("Failed to unmarshal YAML event")
- .getCause().hasMessageStartingWith("namespace \"org.some.other.namespace\" on event");
- yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n"
- + "stringValue: org.onap.policy.apex.plugins.event.protocol.yaml";
+ .cause().hasMessageStartingWith("namespace \"org.some.other.namespace\" on event");
+
+ yamlInputString = """
+ doubleValue: 123.45
+ intValue: 123
+ stringValue: \
+ org.onap.policy.apex.plugins.event.protocol.yaml""";
eventList = converter.toApexEvent("TestEvent", yamlInputString);
assertEquals("org.onap.policy.apex.plugins.event.protocol.yaml", eventList.get(0).getNameSpace());
- yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: MySource";
+ yamlInputString = """
+ doubleValue: 123.45
+ intValue: 123
+ stringValue: MySource""";
pars.setNameSpaceAlias(null);
pars.setSourceAlias("stringValue");
eventList = converter.toApexEvent("TestEvent", yamlInputString);
assertEquals("MySource", eventList.get(0).getSource());
- yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: MyTarget";
+ yamlInputString = """
+ doubleValue: 123.45
+ intValue: 123
+ stringValue: MyTarget""";
pars.setSourceAlias(null);
pars.setTargetAlias("stringValue");
eventList = converter.toApexEvent("TestEvent", yamlInputString);
assertEquals("MyTarget", eventList.get(0).getTarget());
pars.setTargetAlias(null);
- yamlInputString = "doubleValue: 123.45\n" + "intValue: 123\n" + "stringValue: MyString";
pars.setSourceAlias(null);
pars.setTargetAlias("intValue");
assertThatThrownBy(() -> converter.toApexEvent("TestEvent", yamlInputStringCopy))
.hasMessageStartingWith("Failed to unmarshal YAML event")
- .getCause().hasMessageStartingWith("field \"target\" with type \"java.lang.Integer\"");
+ .cause().hasMessageStartingWith("field \"target\" with type \"java.lang.Integer\"");
pars.setTargetAlias(null);
- assertThatThrownBy(() -> converter.toApexEvent("TestEvent", "doubleValue: 123.45\n" + "intValue: ~\n"
- + "stringValue: MyString")).getCause().hasMessageStartingWith("mandatory field \"intValue\" is missing");
+ assertThatThrownBy(() -> converter.toApexEvent("TestEvent", """
+ doubleValue: 123.45
+ intValue: ~
+ stringValue: MyString""")).cause().hasMessageStartingWith("mandatory field \"intValue\" is missing");
}
}
diff --git a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaExecutorParametersTest.java b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaExecutorParametersTest.java
index 1e1dbf7ed..f9c56ab82 100644
--- a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaExecutorParametersTest.java
+++ b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaExecutorParametersTest.java
@@ -1,36 +1,41 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.plugins.executor.java;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test the JavaExecutorParameters class.
*/
-public class JavaExecutorParametersTest {
+class JavaExecutorParametersTest {
@Test
- public void testJavaExecutorParameters() {
- assertNotNull(new JavaExecutorParameters());
+ void testJavaExecutorParameters() {
+ var executorType = "Java";
+ var javaExecutor = new JavaExecutorParameters();
+ assertTrue(javaExecutor.getTaskExecutorPluginClass().contains(executorType));
+ assertTrue(javaExecutor.getTaskSelectionExecutorPluginClass().contains(executorType));
+ assertTrue(javaExecutor.getStateFinalizerExecutorPluginClass().contains(executorType));
}
}
diff --git a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutorTest.java b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutorTest.java
index a1c296436..884530436 100644
--- a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaStateFinalizerExecutorTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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.
@@ -22,13 +22,13 @@
package org.onap.policy.apex.plugins.executor.java;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Properties;
-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.ContextException;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.DistributorParameters;
@@ -50,14 +50,13 @@ import org.onap.policy.common.parameters.ParameterService;
/**
* Test the JavaStateFinalizerExecutor class.
- *
*/
-public class JavaStateFinalizerExecutorTest {
+class JavaStateFinalizerExecutorTest {
/**
* Initiate Parameters.
*/
- @Before
- public void initiateParameters() {
+ @BeforeEach
+ void initiateParameters() {
ParameterService.register(new DistributorParameters());
ParameterService.register(new LockManagerParameters());
ParameterService.register(new PersistorParameters());
@@ -67,8 +66,8 @@ public class JavaStateFinalizerExecutorTest {
/**
* Clear down Parameters.
*/
- @After
- public void clearParameters() {
+ @AfterEach
+ void clearParameters() {
ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
@@ -76,7 +75,7 @@ public class JavaStateFinalizerExecutorTest {
}
@Test
- public void testJavaStateFinalizerExecutor() throws StateMachineException, ContextException {
+ void testJavaStateFinalizerExecutor() throws StateMachineException, ContextException {
JavaStateFinalizerExecutor jsfe = new JavaStateFinalizerExecutor();
assertNotNull(jsfe);
@@ -111,7 +110,7 @@ public class JavaStateFinalizerExecutorTest {
assertThatThrownBy(() -> {
jsfe.execute(-1, new Properties(), event);
}).hasMessage("execute-post: state finalizer logic execution failure on state "
- + "\"NULL:0.0.0:NULL:NULL\" on finalizer logic NULL:0.0.0:NULL:NULL");
+ + "\"NULL:0.0.0:NULL:NULL\" on finalizer logic NULL:0.0.0:NULL:NULL");
state.getStateOutputs().put("SelectedOutputIsMe", null);
jsfe.prepare();
diff --git a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutorTest.java b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutorTest.java
index 96bc6bb3d..3fbaf8b16 100644
--- a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskExecutorTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * Modifications Copyright (C) 2020, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,16 +23,16 @@
package org.onap.policy.apex.plugins.executor.java;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
-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.ContextException;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.DistributorParameters;
@@ -47,14 +47,13 @@ import org.onap.policy.common.parameters.ParameterService;
/**
* Test the JavaTaskExecutor class.
- *
*/
-public class JavaTaskExecutorTest {
+class JavaTaskExecutorTest {
/**
* Initiate Parameters.
*/
- @Before
- public void initiateParameters() {
+ @BeforeEach
+ void initiateParameters() {
ParameterService.register(new DistributorParameters());
ParameterService.register(new LockManagerParameters());
ParameterService.register(new PersistorParameters());
@@ -63,15 +62,15 @@ public class JavaTaskExecutorTest {
/**
* Clear Parameters.
*/
- @After
- public void clearParameters() {
+ @AfterEach
+ void clearParameters() {
ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
}
@Test
- public void testJavaTaskExecutor() throws ContextException, StateMachineException {
+ void testJavaTaskExecutor() throws ContextException, StateMachineException {
JavaTaskExecutor jte = new JavaTaskExecutor();
assertNotNull(jte);
diff --git a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutorTest.java b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutorTest.java
index 61acecd9b..feb4cc6fd 100644
--- a/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-java/src/test/java/org/onap/policy/apex/plugins/executor/java/JavaTaskSelectExecutorTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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.
@@ -22,13 +22,13 @@
package org.onap.policy.apex.plugins.executor.java;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Properties;
-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.ContextException;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.DistributorParameters;
@@ -47,12 +47,12 @@ import org.onap.policy.common.parameters.ParameterService;
* Test the JavaTaskSelectExecutor class.
*
*/
-public class JavaTaskSelectExecutorTest {
+class JavaTaskSelectExecutorTest {
/**
* Initiate Parameters.
*/
- @Before
- public void initiateParameters() {
+ @BeforeEach
+ void initiateParameters() {
ParameterService.register(new DistributorParameters());
ParameterService.register(new LockManagerParameters());
ParameterService.register(new PersistorParameters());
@@ -61,22 +61,22 @@ public class JavaTaskSelectExecutorTest {
/**
* Clear Parameters.
*/
- @After
- public void clearParameters() {
+ @AfterEach
+ void clearParameters() {
ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
}
@Test
- public void testJavaTaskSelectExecutor() throws StateMachineException, ContextException {
+ void testJavaTaskSelectExecutor() throws StateMachineException, ContextException {
JavaTaskSelectExecutor jtse = new JavaTaskSelectExecutor();
assertNotNull(jtse);
assertThatThrownBy(jtse::prepare)
.isInstanceOf(java.lang.NullPointerException.class);
AxState state = new AxState();
- ApexInternalContext internalContext = null;
+ ApexInternalContext internalContext;
internalContext = new ApexInternalContext(new AxPolicyModel());
jtse.setContext(null, state, internalContext);
@@ -96,9 +96,8 @@ public class JavaTaskSelectExecutorTest {
.setLogic("org.onap.policy.apex.plugins.executor.java.DummyJavaTaskSelectionLogic");
jtse.prepare();
- assertThatThrownBy(() -> {
- jtse.execute(-1, new Properties(), event);
- }).hasMessage("execute-post: task selection logic failed on state \"NULL:0.0.0:NULL:NULL\"");
+ assertThatThrownBy(() -> jtse.execute(-1, new Properties(), event))
+ .hasMessage("execute-post: task selection logic failed on state \"NULL:0.0.0:NULL:NULL\"");
jtse.prepare();
AxArtifactKey taskKey = jtse.execute(0, new Properties(), event);
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorFullApexTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorFullApexTest.java
index 394126bc4..61422d1d5 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorFullApexTest.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorFullApexTest.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.
@@ -21,21 +21,21 @@
package org.onap.policy.apex.plugins.executor.javascript;
import static org.awaitility.Awaitility.await;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.apache.commons.lang3.StringUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.service.engine.main.ApexMain;
import org.onap.policy.common.utils.resources.TextFileUtils;
-public class JavascriptExecutorFullApexTest {
+class JavascriptExecutorFullApexTest {
@Test
- public void testFullApexPolicy() throws ApexException {
+ void testFullApexPolicy() throws ApexException {
final String[] args = {"src/test/resources/prodcons/File2File.json"};
final File outFile0 = new File("src/test/resources/events/EventsOut0.json");
@@ -46,19 +46,17 @@ public class JavascriptExecutorFullApexTest {
final ApexMain apexMain = new ApexMain(args);
assertNotNull(apexMain);
- await().atMost(10, TimeUnit.SECONDS).until(() -> outFile0.exists());
- await().atMost(10, TimeUnit.SECONDS).until(() -> outFile1.exists());
+ await().atMost(10, TimeUnit.SECONDS).until(outFile0::exists);
+ await().atMost(10, TimeUnit.SECONDS).until(outFile1::exists);
- await().atMost(10, TimeUnit.SECONDS).until(() -> fileHasOccurencesOf(outFile0, "BasicEventOut0", 50));
- await().atMost(10, TimeUnit.SECONDS).until(() -> fileHasOccurencesOf(outFile1, "BasicEventOut1", 50));
+ await().atMost(10, TimeUnit.SECONDS).until(() -> fileHasOccurrencesOf(outFile0, "BasicEventOut0"));
+ await().atMost(10, TimeUnit.SECONDS).until(() -> fileHasOccurrencesOf(outFile1, "BasicEventOut1"));
apexMain.shutdown();
}
- private boolean fileHasOccurencesOf(final File file, final String token, final int occurenceCount)
- throws IOException {
-
- return occurenceCount == StringUtils.countMatches(TextFileUtils.getTextFileAsString(file.getAbsolutePath()),
- token);
+ private boolean fileHasOccurrencesOf(final File file, final String token)
+ throws IOException {
+ return 50 == StringUtils.countMatches(TextFileUtils.getTextFileAsString(file.getAbsolutePath()), token);
}
}
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorParametersTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorParametersTest.java
index 5b23584d0..adc7dbb00 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorParametersTest.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorParametersTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,17 +20,21 @@
package org.onap.policy.apex.plugins.executor.javascript;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test the JavaExecutorParameters class.
*/
-public class JavascriptExecutorParametersTest {
+class JavascriptExecutorParametersTest {
@Test
- public void testJavascriptExecutorParameters() {
- assertNotNull(new JavascriptExecutorParameters());
+ void testJavascriptExecutorParameters() {
+ var executorType = "Javascript";
+ var javascriptExecutor = new JavascriptExecutorParameters();
+ assertTrue(javascriptExecutor.getStateFinalizerExecutorPluginClass().contains(executorType));
+ assertTrue(javascriptExecutor.getTaskExecutorPluginClass().contains(executorType));
+ assertTrue(javascriptExecutor.getTaskSelectionExecutorPluginClass().contains(executorType));
}
}
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorTest.java
index 20ba1291f..083ec521a 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptExecutorTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation. All rights reserved.
+ * Copyright (C) 2020, 2024 Nordix Foundation. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,21 +23,21 @@ package org.onap.policy.apex.plugins.executor.javascript;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
-public class JavascriptExecutorTest {
+class JavascriptExecutorTest {
@Test
- public void testReturnOK() throws StateMachineException {
+ void testReturnOK() throws StateMachineException {
JavascriptExecutor executor = new JavascriptExecutor(
new AxArtifactKey("TestTask:0.0.1"), "true;");
assertThatCode(() -> executor.execute(new Object())).doesNotThrowAnyException();
}
@Test
- public void testReturnNonBoolean() throws StateMachineException {
+ void testReturnNonBoolean() throws StateMachineException {
JavascriptExecutor executor = new JavascriptExecutor(
new AxArtifactKey("TestTask:0.0.1"), "var a = 1; a;");
assertThatThrownBy(() -> executor.execute(new Object()))
@@ -45,14 +45,14 @@ public class JavascriptExecutorTest {
}
@Test
- public void testBlankLogic() {
+ void testBlankLogic() {
assertThatThrownBy(() -> new JavascriptExecutor(
new AxArtifactKey("TestTask:0.0.1"), " "))
.hasMessageContaining("no logic specified for TestTask:0.0.1");
}
@Test
- public void testCompileFailed() {
+ void testCompileFailed() {
assertThatThrownBy(() -> new JavascriptExecutor(
new AxArtifactKey("TestTask:0.0.1"), "return boolean;"))
.hasMessageContaining("logic failed to compile for TestTask:0.0.1");
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java
index 2a10e70ca..ff7301541 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptStateFinalizerExecutorTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * 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,12 +21,12 @@
package org.onap.policy.apex.plugins.executor.javascript;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Properties;
-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.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.DistributorParameters;
import org.onap.policy.apex.context.parameters.LockManagerParameters;
@@ -46,14 +46,13 @@ import org.onap.policy.common.parameters.ParameterService;
/**
* Test the JavascriptStateFinalizerExecutor class.
- *
*/
-public class JavascriptStateFinalizerExecutorTest {
+class JavascriptStateFinalizerExecutorTest {
/**
* Initiate Parameters.
*/
- @Before
- public void initiateParameters() {
+ @BeforeEach
+ void initiateParameters() {
ParameterService.register(new DistributorParameters());
ParameterService.register(new LockManagerParameters());
ParameterService.register(new PersistorParameters());
@@ -63,8 +62,8 @@ public class JavascriptStateFinalizerExecutorTest {
/**
* Clear down Parameters.
*/
- @After
- public void clearParameters() {
+ @AfterEach
+ void clearParameters() {
ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
@@ -72,12 +71,10 @@ public class JavascriptStateFinalizerExecutorTest {
}
@Test
- public void testJavaStateFinalizerExecutor() throws Exception {
+ void testJavaStateFinalizerExecutor() throws Exception {
JavascriptStateFinalizerExecutor jsfe = new JavascriptStateFinalizerExecutor();
- assertThatThrownBy(() -> {
- jsfe.prepare();
- }).isInstanceOf(java.lang.NullPointerException.class);
+ assertThatThrownBy(jsfe::prepare).isInstanceOf(java.lang.NullPointerException.class);
ApexInternalContext internalContext = new ApexInternalContext(new AxPolicyModel());
StateExecutor parentStateExcutor = new StateExecutor(new ExecutorFactoryImpl());
@@ -88,9 +85,7 @@ public class JavascriptStateFinalizerExecutorTest {
jsfe.setContext(parentStateExcutor, stateFinalizerLogic, internalContext);
stateFinalizerLogic.setLogic("return false");
- assertThatThrownBy(() -> {
- jsfe.prepare();
- }).hasMessage("logic failed to compile for NULL:0.0.0:NULL:NULL "
+ assertThatThrownBy(jsfe::prepare).hasMessage("logic failed to compile for NULL:0.0.0:NULL:NULL "
+ "with message: invalid return (NULL:0.0.0:NULL:NULL#1)");
stateFinalizerLogic.setLogic("java.lang.String");
@@ -98,11 +93,19 @@ public class JavascriptStateFinalizerExecutorTest {
AxEvent axEvent = new AxEvent(new AxArtifactKey("Event", "0.0.1"));
EnEvent event = new EnEvent(axEvent);
- stateFinalizerLogic.setLogic("if(executor.executionId==-1)" + "{\r\n"
- + "var returnValueType = java.lang.Boolean;" + "var returnValue = new returnValueType(false); }\n"
- + "else{\n" + "executor.setSelectedStateOutputName(\"SelectedOutputIsMe\");\n"
- + "var returnValueType = java.lang.Boolean;\n" + "\n"
- + "var returnValue = new returnValueType(true);} true;");
+ var logic = """
+ if(executor.executionId==-1)
+ {
+ var returnValueType = java.lang.Boolean;
+ var returnValue = new returnValueType(false);
+ }
+ else
+ {
+ executor.setSelectedStateOutputName("SelectedOutputIsMe");
+ var returnValueType = java.lang.Boolean;
+ var returnValue = new returnValueType(true);
+ } true;""";
+ stateFinalizerLogic.setLogic(logic);
assertThatThrownBy(() -> {
jsfe.prepare();
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java
index 215491d4e..0dd630a2c 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskExecutorTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2020, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
@@ -23,17 +23,17 @@
package org.onap.policy.apex.plugins.executor.javascript;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
-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.ContextAlbum;
import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.context.Distributor;
@@ -58,17 +58,16 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
/**
* Test the JavaTaskExecutor class.
- *
*/
-public class JavascriptTaskExecutorTest {
+class JavascriptTaskExecutorTest {
/**
- * Set ups everything for the test.
+ * Set-ups everything for the test.
*/
- @BeforeClass
- public static void prepareForTest() {
+ @BeforeAll
+ static void prepareForTest() {
final ContextParameters contextParameters = new ContextParameters();
contextParameters.getLockManagerParameters()
- .setPluginClass("org.onap.policy.apex.context.impl.locking.jvmlocal.JvmLocalLockManager");
+ .setPluginClass("org.onap.policy.apex.context.impl.locking.jvmlocal.JvmLocalLockManager");
contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME);
contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
@@ -90,8 +89,8 @@ public class JavascriptTaskExecutorTest {
/**
* Clear down the test data.
*/
- @AfterClass
- public static void cleanUpAfterTest() {
+ @AfterAll
+ static void cleanUpAfterTest() {
ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
@@ -101,12 +100,10 @@ public class JavascriptTaskExecutorTest {
}
@Test
- public void testJavascriptTaskExecutor() throws Exception {
+ void testJavascriptTaskExecutor() throws Exception {
JavascriptTaskExecutor jte = new JavascriptTaskExecutor();
- assertThatThrownBy(() -> {
- jte.prepare();
- }).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(jte::prepare).isInstanceOf(NullPointerException.class);
AxTask task = new AxTask(new AxArtifactKey("TestTask:0.0.1"));
final ApexInternalContext internalContext = new ApexInternalContext(new AxPolicyModel());
@@ -115,17 +112,14 @@ public class JavascriptTaskExecutorTest {
task.getTaskLogic().setLogic("return boolean;");
- assertThatThrownBy(() -> {
- jte.prepare();
- }).hasMessage("logic failed to compile for TestTask:0.0.1 with message: invalid return (TestTask:0.0.1#1)");
+ assertThatThrownBy(jte::prepare)
+ .hasMessage("logic failed to compile for TestTask:0.0.1 with message: invalid return (TestTask:0.0.1#1)");
task.getTaskLogic().setLogic("var x = 5;");
jte.prepare();
Properties props = new Properties();
- assertThatThrownBy(() -> {
- jte.execute(-1, props, null);
- }).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> jte.execute(-1, props, null)).isInstanceOf(NullPointerException.class);
jte.cleanUp();
task.setInputEvent(new AxEvent());
task.setOutputEvents(new TreeMap<>());
@@ -149,14 +143,12 @@ public class JavascriptTaskExecutorTest {
}
@Test
- public void testJavascriptTaskExecutorLogic() throws Exception {
+ void testJavascriptTaskExecutorLogic() throws Exception {
JavascriptTaskExecutor jte = new JavascriptTaskExecutor();
assertNotNull(jte);
- assertThatThrownBy(() -> {
- jte.prepare();
- }).isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(jte::prepare).isInstanceOf(NullPointerException.class);
AxTask task = new AxTask(new AxArtifactKey("TestTask:0.0.1"));
@@ -199,16 +191,16 @@ public class JavascriptTaskExecutorTest {
private ContextAlbum createTestContextAlbum() throws ContextException {
AxContextSchemas schemas = new AxContextSchemas();
AxContextSchema simpleStringSchema =
- new AxContextSchema(new AxArtifactKey("SimpleStringSchema", "0.0.1"), "JAVA", "java.lang.String");
+ new AxContextSchema(new AxArtifactKey("SimpleStringSchema", "0.0.1"), "JAVA", "java.lang.String");
schemas.getSchemasMap().put(simpleStringSchema.getKey(), simpleStringSchema);
ModelService.registerModel(AxContextSchemas.class, schemas);
AxContextAlbum axContextAlbum = new AxContextAlbum(new AxArtifactKey("TestContextAlbum", "0.0.1"), "Policy",
- true, AxArtifactKey.getNullKey());
+ true, AxArtifactKey.getNullKey());
axContextAlbum.setItemSchema(simpleStringSchema.getKey());
Distributor distributor = new JvmLocalDistributor();
distributor.init(axContextAlbum.getKey());
- return new ContextAlbumImpl(axContextAlbum, distributor, new LinkedHashMap<String, Object>());
+ return new ContextAlbumImpl(axContextAlbum, distributor, new LinkedHashMap<>());
}
}
diff --git a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java
index d2bb852b6..7e7f61622 100644
--- a/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-javascript/src/test/java/org/onap/policy/apex/plugins/executor/javascript/JavascriptTaskSelectExecutorTest.java
@@ -22,13 +22,13 @@
package org.onap.policy.apex.plugins.executor.javascript;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
import java.util.Properties;
-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.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.DistributorParameters;
import org.onap.policy.apex.context.parameters.LockManagerParameters;
@@ -43,14 +43,13 @@ import org.onap.policy.common.parameters.ParameterService;
/**
* Test the JavaTaskSelectExecutor class.
- *
*/
-public class JavascriptTaskSelectExecutorTest {
+class JavascriptTaskSelectExecutorTest {
/**
* Initiate Parameters.
*/
- @Before
- public void initiateParameters() {
+ @BeforeEach
+ void initiateParameters() {
ParameterService.register(new DistributorParameters());
ParameterService.register(new LockManagerParameters());
ParameterService.register(new PersistorParameters());
@@ -59,15 +58,15 @@ public class JavascriptTaskSelectExecutorTest {
/**
* Clear Parameters.
*/
- @After
- public void clearParameters() {
+ @AfterEach
+ void clearParameters() {
ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
}
@Test
- public void testJavascriptTaskSelectExecutor() throws Exception {
+ void testJavascriptTaskSelectExecutor() throws Exception {
JavascriptTaskSelectExecutor jtse = new JavascriptTaskSelectExecutor();
assertThatThrownBy(() -> {
@@ -79,9 +78,7 @@ public class JavascriptTaskSelectExecutorTest {
ApexInternalContext internalContext = new ApexInternalContext(new AxPolicyModel());
jtse.setContext(null, state, internalContext);
- assertThatThrownBy(() -> {
- jtse.prepare();
- }).hasMessage("no logic specified for NULL:0.0.0:NULL:NULL");
+ assertThatThrownBy(jtse::prepare).hasMessage("no logic specified for NULL:0.0.0:NULL:NULL");
state.getTaskSelectionLogic().setLogic("java.lang.String");
jtse.prepare();
@@ -92,9 +89,7 @@ public class JavascriptTaskSelectExecutorTest {
AxEvent axEvent = new AxEvent(new AxArtifactKey("Event", "0.0.1"));
EnEvent event = new EnEvent(axEvent);
- assertThatThrownBy(() -> {
- jtse.execute(-1, new Properties(), event);
- }).hasMessage(
+ assertThatThrownBy(() -> jtse.execute(-1, new Properties(), event)).hasMessage(
"execute: logic for NULL:0.0.0:NULL:NULL returned a non-boolean value [JavaClass java.lang.String]");
state.getTaskSelectionLogic().setLogic("var x=1;\n" + "false; ");
diff --git a/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyExecutorParametersTest.java b/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyExecutorParametersTest.java
index 4cfd7a19c..c6e0b3a67 100644
--- a/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyExecutorParametersTest.java
+++ b/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyExecutorParametersTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,16 +20,20 @@
package org.onap.policy.apex.plugins.executor.jruby;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test the JrubyExecutorParameters class.
*/
-public class JrubyExecutorParametersTest {
+class JrubyExecutorParametersTest {
@Test
- public void testJrubyExecutorParameters() {
- assertNotNull(new JrubyExecutorParameters());
+ void testJrubyExecutorParameters() {
+ var executorType = "Jruby";
+ var jrubyExecutor = new JrubyExecutorParameters();
+ assertTrue(jrubyExecutor.getTaskExecutorPluginClass().contains(executorType));
+ assertTrue(jrubyExecutor.getTaskSelectionExecutorPluginClass().contains(executorType));
+ assertTrue(jrubyExecutor.getStateFinalizerExecutorPluginClass().contains(executorType));
}
}
diff --git a/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyStateFinalizerExecutorTest.java b/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyStateFinalizerExecutorTest.java
index eca9a45cd..a750a0bfe 100644
--- a/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyStateFinalizerExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyStateFinalizerExecutorTest.java
@@ -1,7 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * 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,14 +21,14 @@
package org.onap.policy.apex.plugins.executor.jruby;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.lang.reflect.Field;
import java.util.Properties;
-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.ContextException;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.DistributorParameters;
@@ -53,12 +52,12 @@ import org.onap.policy.common.parameters.ParameterService;
* Test the JrubyStateFinalizerExecutor class.
*
*/
-public class JrubyStateFinalizerExecutorTest {
+class JrubyStateFinalizerExecutorTest {
/**
* Initiate Parameters.
*/
- @Before
- public void initiateParameters() {
+ @BeforeEach
+ void initiateParameters() {
ParameterService.register(new DistributorParameters());
ParameterService.register(new LockManagerParameters());
ParameterService.register(new PersistorParameters());
@@ -68,8 +67,8 @@ public class JrubyStateFinalizerExecutorTest {
/**
* Clear down Parameters.
*/
- @After
- public void clearParameters() {
+ @AfterEach
+ void clearParameters() {
ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
@@ -77,7 +76,7 @@ public class JrubyStateFinalizerExecutorTest {
}
@Test
- public void testJrubyStateFinalizerExecutor() throws StateMachineException, ContextException,
+ void testJrubyStateFinalizerExecutor() throws StateMachineException, ContextException,
NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
JrubyStateFinalizerExecutor jsfe = new JrubyStateFinalizerExecutor();
assertNotNull(jsfe);
@@ -105,8 +104,13 @@ public class JrubyStateFinalizerExecutorTest {
+ "NULL:0.0.0:NULL:NULL\" on finalizer logic NULL:0.0.0:NULL:NULL");
AxEvent axEvent = new AxEvent(new AxArtifactKey("Event", "0.0.1"));
- final String jrubyLogic = "if executor.executionId == -1" + "\n return false" + "\n else "
- + "\n executor.setSelectedStateOutputName(\"SelectedOutputIsMe\")" + "\n return true" + "\n end";
+ final String jrubyLogic = """
+ if executor.executionId == -1
+ return false
+ else
+ executor.setSelectedStateOutputName("SelectedOutputIsMe")
+ return true
+ end""";
stateFinalizerLogic.setLogic(jrubyLogic);
EnEvent event = new EnEvent(axEvent);
diff --git a/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutorTest.java b/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutorTest.java
index 0cc476425..2092c8fb2 100644
--- a/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskExecutorTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2020, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,17 +22,17 @@
package org.onap.policy.apex.plugins.executor.jruby;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
-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.ContextException;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.DistributorParameters;
@@ -49,12 +49,12 @@ import org.onap.policy.common.parameters.ParameterService;
* Test the JrubyTaskExecutor class.
*
*/
-public class JrubyTaskExecutorTest {
+class JrubyTaskExecutorTest {
/**
* Initiate Parameters.
*/
- @Before
- public void initiateParameters() {
+ @BeforeEach
+ void initiateParameters() {
ParameterService.register(new DistributorParameters());
ParameterService.register(new LockManagerParameters());
ParameterService.register(new PersistorParameters());
@@ -63,15 +63,15 @@ public class JrubyTaskExecutorTest {
/**
* Clear Parameters.
*/
- @After
- public void clearParameters() {
+ @AfterEach
+ void clearParameters() {
ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
}
@Test
- public void testJrubyTaskExecutor() throws StateMachineException, ContextException,
+ void testJrubyTaskExecutor() throws StateMachineException, ContextException,
IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
// Run test twice to check for incorrect shutdown activity
jrubyExecutorTest();
@@ -91,7 +91,7 @@ public class JrubyTaskExecutorTest {
fieldContainer.set(jte, null);
assertThatThrownBy(jte::prepare).isInstanceOf(java.lang.NullPointerException.class);
AxTask task = new AxTask();
- ApexInternalContext internalContext = null;
+ ApexInternalContext internalContext;
internalContext = new ApexInternalContext(new AxPolicyModel());
task.setInputEvent(new AxEvent());
task.setOutputEvents(new TreeMap<>());
@@ -102,8 +102,12 @@ public class JrubyTaskExecutorTest {
Map<String, Object> incomingParameters = new HashMap<>();
assertThatThrownBy(() -> jte.execute(-1, new Properties(), incomingParameters))
.hasMessage("execute-post: task logic execution failure on task \"NULL\" in model NULL:0.0.0");
- final String jrubyLogic = "if executor.executionId == -1" + "\n return false" + "\n else " + "\n return true"
- + "\n end";
+ final String jrubyLogic = """
+ if executor.executionId == -1
+ return false
+ else
+ return true
+ end""";
task.getTaskLogic().setLogic(jrubyLogic);
jte.prepare();
Map<String, Map<String, Object>> returnMap = jte.execute(0, new Properties(), incomingParameters);
diff --git a/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskSelectExecutorTest.java b/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskSelectExecutorTest.java
index 59d1be4b4..c7b96fde1 100644
--- a/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskSelectExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-jruby/src/test/java/org/onap/policy/apex/plugins/executor/jruby/JrubyTaskSelectExecutorTest.java
@@ -1,7 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * 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,14 +21,14 @@
package org.onap.policy.apex.plugins.executor.jruby;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.lang.reflect.Field;
import java.util.Properties;
-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.ContextException;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.DistributorParameters;
@@ -46,14 +45,13 @@ import org.onap.policy.common.parameters.ParameterService;
/**
* Test the JrubyTaskSelectExecutor class.
- *
*/
-public class JrubyTaskSelectExecutorTest {
+class JrubyTaskSelectExecutorTest {
/**
* Initiate Parameters.
*/
- @Before
- public void initiateParameters() {
+ @BeforeEach
+ void initiateParameters() {
ParameterService.register(new DistributorParameters());
ParameterService.register(new LockManagerParameters());
ParameterService.register(new PersistorParameters());
@@ -62,15 +60,15 @@ public class JrubyTaskSelectExecutorTest {
/**
* Clear Parameters.
*/
- @After
- public void clearParameters() {
+ @AfterEach
+ void clearParameters() {
ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
}
@Test
- public void testJrubyTaskSelectExecutor() throws StateMachineException, ContextException,
+ void testJrubyTaskSelectExecutor() throws StateMachineException, ContextException,
NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
JrubyTaskSelectExecutor jtse = new JrubyTaskSelectExecutor();
assertNotNull(jtse);
@@ -93,8 +91,12 @@ public class JrubyTaskSelectExecutorTest {
EnEvent event = new EnEvent(axEvent);
assertThatThrownBy(() -> jtse.execute(-1, new Properties(), event))
.hasMessage("execute-post: task selection logic failed on state \"NULL:0.0.0:NULL:NULL\"");
- final String jrubyLogic =
- "if executor.executionId == -1" + "\n return false" + "\n else " + "\n return true" + "\n end";
+ final String jrubyLogic = """
+ if executor.executionId == -1
+ return false
+ else
+ return true
+ end""";
state.getTaskSelectionLogic().setLogic(jrubyLogic);
jtse.prepare();
diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelExecutorParametersTest.java b/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelExecutorParametersTest.java
index 81dc037ae..2d3f51fb1 100644
--- a/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelExecutorParametersTest.java
+++ b/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelExecutorParametersTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019, 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,17 +20,21 @@
package org.onap.policy.apex.plugins.executor.mvel;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test the MvelExecutorParameters class.
*/
-public class MvelExecutorParametersTest {
+class MvelExecutorParametersTest {
@Test
- public void testJavaExecutorParameters() {
- assertNotNull(new MvelExecutorParameters());
+ void testMvelExecutorParameters() {
+ var executorType = "Mvel";
+ var mvelExecutor = new MvelExecutorParameters();
+ assertTrue(mvelExecutor.getStateFinalizerExecutorPluginClass().contains(executorType));
+ assertTrue(mvelExecutor.getTaskExecutorPluginClass().contains(executorType));
+ assertTrue(mvelExecutor.getTaskSelectionExecutorPluginClass().contains(executorType));
}
}
diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutorTest.java b/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutorTest.java
index 4dd400bbc..fbd789d96 100644
--- a/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelStateFinalizerExecutorTest.java
@@ -1,7 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * 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,13 +21,13 @@
package org.onap.policy.apex.plugins.executor.mvel;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Properties;
-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.ContextException;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.DistributorParameters;
@@ -52,12 +51,12 @@ import org.onap.policy.common.parameters.ParameterService;
* Test the MvelStateFinalizerExecutor class.
*
*/
-public class MvelStateFinalizerExecutorTest {
+class MvelStateFinalizerExecutorTest {
/**
* Initiate Parameters.
*/
- @Before
- public void initiateParameters() {
+ @BeforeEach
+ void initiateParameters() {
ParameterService.register(new DistributorParameters());
ParameterService.register(new LockManagerParameters());
ParameterService.register(new PersistorParameters());
@@ -67,8 +66,8 @@ public class MvelStateFinalizerExecutorTest {
/**
* Clear down Parameters.
*/
- @After
- public void clearParameters() {
+ @AfterEach
+ void clearParameters() {
ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
@@ -76,22 +75,22 @@ public class MvelStateFinalizerExecutorTest {
}
@Test
- public void testJavaStateFinalizerExecutor() throws StateMachineException, ContextException {
+ void testJavaStateFinalizerExecutor() throws StateMachineException, ContextException {
MvelStateFinalizerExecutor msfe = new MvelStateFinalizerExecutor();
assertNotNull(msfe);
assertThatThrownBy(msfe::prepare).isInstanceOf(java.lang.NullPointerException.class);
- ApexInternalContext internalContext = null;
+ ApexInternalContext internalContext;
internalContext = new ApexInternalContext(new AxPolicyModel());
- StateExecutor parentStateExcutor = null;
+ StateExecutor parentStateExecutor;
- parentStateExcutor = new StateExecutor(new ExecutorFactoryImpl());
+ parentStateExecutor = new StateExecutor(new ExecutorFactoryImpl());
AxState state = new AxState();
- parentStateExcutor.setContext(null, state, internalContext);
+ parentStateExecutor.setContext(null, state, internalContext);
AxStateFinalizerLogic stateFinalizerLogic = new AxStateFinalizerLogic();
- msfe.setContext(parentStateExcutor, stateFinalizerLogic, internalContext);
+ msfe.setContext(parentStateExecutor, stateFinalizerLogic, internalContext);
stateFinalizerLogic.setLogic("x > 1 2 ()");
assertThatThrownBy(msfe::prepare).hasMessage("failed to compile MVEL code for state NULL:0.0.0:NULL:NULL");
diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutorTest.java b/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutorTest.java
index 3d59c4b21..f6dd7d824 100644
--- a/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskExecutorTest.java
@@ -1,7 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * Copyright (C) 2019-2020, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,16 +22,16 @@
package org.onap.policy.apex.plugins.executor.mvel;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
-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.ContextException;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.DistributorParameters;
@@ -49,12 +48,12 @@ import org.onap.policy.common.parameters.ParameterService;
* Test the MvelTaskExecutor class.
*
*/
-public class MvelTaskExecutorTest {
+class MvelTaskExecutorTest {
/**
* Initiate Parameters.
*/
- @Before
- public void initiateParameters() {
+ @BeforeEach
+ void initiateParameters() {
ParameterService.register(new DistributorParameters());
ParameterService.register(new LockManagerParameters());
ParameterService.register(new PersistorParameters());
@@ -63,15 +62,15 @@ public class MvelTaskExecutorTest {
/**
* Clear Parameters.
*/
- @After
- public void clearParameters() {
+ @AfterEach
+ void clearParameters() {
ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
}
@Test
- public void testMvelTaskExecutor() throws StateMachineException, ContextException {
+ void testMvelTaskExecutor() throws StateMachineException, ContextException {
MvelTaskExecutor mte = new MvelTaskExecutor();
assertNotNull(mte);
diff --git a/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutorTest.java b/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutorTest.java
index d81c3d13b..4a25730cc 100644
--- a/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutorTest.java
+++ b/plugins/plugins-executor/plugins-executor-mvel/src/test/java/org/onap/policy/apex/plugins/executor/mvel/MvelTaskSelectExecutorTest.java
@@ -1,7 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2020 Nordix Foundation
+ * 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,13 +21,13 @@
package org.onap.policy.apex.plugins.executor.mvel;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Properties;
-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.ContextException;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.DistributorParameters;
@@ -47,12 +46,12 @@ import org.onap.policy.common.parameters.ParameterService;
* Test the MvelTaskSelectExecutor class.
*
*/
-public class MvelTaskSelectExecutorTest {
+class MvelTaskSelectExecutorTest {
/**
* Initiate Parameters.
*/
- @Before
- public void initiateParameters() {
+ @BeforeEach
+ void initiateParameters() {
ParameterService.register(new DistributorParameters());
ParameterService.register(new LockManagerParameters());
ParameterService.register(new PersistorParameters());
@@ -61,15 +60,15 @@ public class MvelTaskSelectExecutorTest {
/**
* Clear Parameters.
*/
- @After
- public void clearParameters() {
+ @AfterEach
+ void clearParameters() {
ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
}
@Test
- public void testJavaTaskSelectExecutor() throws StateMachineException, ContextException {
+ void testJavaTaskSelectExecutor() throws StateMachineException, ContextException {
MvelTaskSelectExecutor mtse = new MvelTaskSelectExecutor();
assertNotNull(mtse);
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java
index a8f13bbf6..ee814e245 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/ApexEvent.java
@@ -1,8 +1,9 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,6 +24,7 @@
package org.onap.policy.apex.service.engine.event;
import com.google.common.base.Strings;
+import java.io.Serial;
import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
@@ -50,6 +52,8 @@ import org.slf4j.LoggerFactory;
@ToString
@EqualsAndHashCode(callSuper = false)
public class ApexEvent extends HashMap<String, Object> implements Serializable {
+
+ @Serial
private static final long serialVersionUID = -4451918242101961685L;
// Get a reference to the logger
@@ -59,7 +63,7 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable {
private static final String EVENT_PREAMBLE = "event \"";
// Holds the next identifier for event execution.
- private static AtomicLong nextExecutionID = new AtomicLong(0L);
+ private static final AtomicLong nextExecutionID = new AtomicLong(0L);
/**
* The name of the Apex event, a mandatory field. All Apex events must have a name so that the
@@ -131,7 +135,7 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable {
private final String nameSpace;
private final String source;
private final String target;
- private final String toscaPolicyState;
+ private String toscaPolicyState;
// An identifier for the current event execution. The default value here will always be unique
// in a single JVM
@@ -154,6 +158,7 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable {
* @param nameSpace the name space (java package) of the event
* @param source the source of the event
* @param target the target of the event
+ * @param toscaPolicyState Policy state
* @throws ApexEventException thrown on validation errors on event names and versions
*/
public ApexEvent(final String name, final String version, final String nameSpace, final String source,
@@ -167,10 +172,29 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable {
}
/**
+ * Instantiates a new apex event.
+ *
+ * @param name the name of the event
+ * @param version the version of the event
+ * @param nameSpace the name space (java package) of the event
+ * @param source the source of the event
+ * @param target the target of the event
+ * @throws ApexEventException thrown on validation errors on event names and versions
+ */
+ public ApexEvent(final String name, final String version, final String nameSpace, final String source,
+ final String target) throws ApexEventException {
+ this.name = validateField(NAME_HEADER_FIELD, name, NAME_REGEXP);
+ this.version = validateField(VERSION_HEADER_FIELD, version, VERSION_REGEXP);
+ this.nameSpace = validateField(NAMESPACE_HEADER_FIELD, nameSpace, NAMESPACE_REGEXP);
+ this.source = validateField(SOURCE_HEADER_FIELD, source, SOURCE_REGEXP);
+ this.target = validateField(TARGET_HEADER_FIELD, target, TARGET_REGEXP);
+ }
+
+ /**
* Private utility to get the next candidate value for a Execution ID. This value will always be
* unique in a single JVM
*
- * @return the next candidate value for a Execution ID
+ * @return the next candidate value for an Execution ID
*/
private static synchronized long getNextExecutionId() {
return nextExecutionID.getAndIncrement();
@@ -249,7 +273,7 @@ public class ApexEvent extends HashMap<String, Object> implements Serializable {
* {@inheritDoc}.
*/
@Override
- public void putAll(final Map<? extends String, ? extends Object> incomingMap) {
+ public void putAll(final Map<? extends String, ?> incomingMap) {
// Check the keys are valid
try {
for (final String key : incomingMap.keySet()) {
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParameters.java
index fe59486f3..194e13bfe 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParameters.java
@@ -66,9 +66,9 @@ public abstract class EventProtocolParameters extends ParameterGroupImpl {
}
/**
- * Sets the event event protocol plugin class.
+ * Sets the event protocol plugin class.
*
- * @param eventProtocolPluginClass the event event protocol plugin class
+ * @param eventProtocolPluginClass the event protocol plugin class
*/
public void setEventProtocolPluginClass(final String eventProtocolPluginClass) {
this.eventProtocolPluginClass = eventProtocolPluginClass.replaceAll("\\s+", "");
diff --git a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/KeyInfoGetterTest.java b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/KeyInfoGetterTest.java
index e6ecefd12..3ba316f8a 100644
--- a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/KeyInfoGetterTest.java
+++ b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/KeyInfoGetterTest.java
@@ -1,29 +1,30 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
package org.onap.policy.apex.tools.model.generator;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
import org.onap.policy.apex.model.policymodel.concepts.AxState;
@@ -32,10 +33,10 @@ import org.onap.policy.apex.testsuites.integration.common.model.SampleDomainMode
/**
* Test the Key Info Getter.
*/
-public class KeyInfoGetterTest {
+class KeyInfoGetterTest {
@Test
- public void testKeyInfoGetter() {
+ void testKeyInfoGetter() {
AxPolicyModel sampleModel = new SampleDomainModelFactory().getSamplePolicyModel("JAVASCRIPT");
KeyInfoGetter kiGetter = new KeyInfoGetter(sampleModel);
@@ -50,22 +51,22 @@ public class KeyInfoGetterTest {
assertNull(kiGetter.getDesc(null));
assertNull(kiGetter.getDesc(new AxArtifactKey()));
assertEquals("Generated description for concept referred to by key " + "\"SamplePolicyModelJAVASCRIPT:0.0.1\"",
- kiGetter.getDesc(sampleModel.getKey()));
-
+ kiGetter.getDesc(sampleModel.getKey()));
+
assertNull(kiGetter.getVersion(null));
assertEquals("0.0.1", kiGetter.getVersion(sampleModel.getKey()));
-
+
AxState matchState = sampleModel.getPolicies().get("Policy0").getStateMap().get("Match");
-
+
assertNull(kiGetter.getLName(null));
assertEquals("Match", kiGetter.getLName(matchState.getKey()));
-
+
assertNull(kiGetter.getPName(null));
assertEquals("Policy0", kiGetter.getPName(matchState.getKey()));
-
+
assertNull(kiGetter.getPVersion(null));
assertEquals("0.0.1", kiGetter.getPVersion(matchState.getKey()));
-
+
assertNull(kiGetter.getPlName(null));
assertEquals("NULL", kiGetter.getPlName(matchState.getKey()));
}
diff --git a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/SchemaUtilsTest.java b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/SchemaUtilsTest.java
index a195411f3..f4f0997af 100644
--- a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/SchemaUtilsTest.java
+++ b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/SchemaUtilsTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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.
@@ -22,7 +22,7 @@
package org.onap.policy.apex.tools.model.generator;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -31,8 +31,8 @@ import java.util.List;
import java.util.Map;
import org.apache.avro.Schema;
import org.apache.avro.Schema.Field;
-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.context.impl.schema.SchemaHelperFactory;
import org.onap.policy.apex.context.impl.schema.java.JavaSchemaHelperParameters;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
@@ -63,10 +63,10 @@ public class SchemaUtilsTest {
/**
* Read the models into strings.
*
- * @throws IOException on model reading errors
+ * @throws IOException on model reading errors
* @throws ApexModelException on model reading exceptions
*/
- @BeforeClass
+ @BeforeAll
public static void readSimpleModel() throws IOException, ApexModelException {
String avroModelString = TextFileUtils.getTextFileAsString("src/test/resources/vpnsla.json");
@@ -75,18 +75,17 @@ public class SchemaUtilsTest {
}
@Test
- public void testSchemaUtilsErrors() {
+ void testSchemaUtilsErrors() {
AxEvent event = avroModel.getEvents().get("CustomerContextEventIn");
+ String modelClassName = "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas";
assertThatThrownBy(() -> SchemaUtils.getEventSchema(event))
- .hasMessage("Model for org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas"
- + " not found in model service");
+ .hasMessage("Model for " + modelClassName + " not found in model service");
assertThatThrownBy(() -> {
Map<String, Schema> preexistingParamSchemas = new LinkedHashMap<>();
SchemaUtils.getEventParameterSchema(event.getParameterMap().get("links"), preexistingParamSchemas);
- }).hasMessage("Model for org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas"
- + " not found in model service");
+ }).hasMessage("Model for " + modelClassName + " not found in model service");
List<Field> skeletonFields = SchemaUtils.getSkeletonEventSchemaFields();
assertEquals(5, skeletonFields.size());
@@ -95,16 +94,15 @@ public class SchemaUtilsTest {
AxArtifactKey topoNodesKey = new AxArtifactKey("albumTopoNodes", "0.0.1");
assertThatThrownBy(() -> {
AvroSchemaHelper schemaHelper = (AvroSchemaHelper) new SchemaHelperFactory()
- .createSchemaHelper(topoNodesKey, avroCtxtSchema.getKey());
+ .createSchemaHelper(topoNodesKey, avroCtxtSchema.getKey());
Map<String, Schema> schemaMap = new LinkedHashMap<>();
SchemaUtils.processSubSchemas(schemaHelper.getAvroSchema(), schemaMap);
- }).hasMessage("Model for org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas"
- + " not found in model service");
+ }).hasMessage("Model for " + modelClassName + " not found in model service");
}
@Test
- public void testSchemaUtils() throws ApexEventException {
+ void testSchemaUtils() throws ApexEventException {
ParameterService.clear();
final SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
@@ -117,11 +115,11 @@ public class SchemaUtilsTest {
Schema eventSchema = SchemaUtils.getEventSchema(event);
assertEquals("{\"type\":\"record\",\"name\":\"CustomerContextEventIn\"",
- eventSchema.toString().substring(0, 48));
+ eventSchema.toString().substring(0, 48));
Map<String, Schema> preexistingParamSchemas = new LinkedHashMap<>();
Schema epSchema =
- SchemaUtils.getEventParameterSchema(event.getParameterMap().get("links"), preexistingParamSchemas);
+ SchemaUtils.getEventParameterSchema(event.getParameterMap().get("links"), preexistingParamSchemas);
assertEquals("\"string\"", epSchema.toString());
AxContextSchema avroCtxtSchema = avroModel.getSchemas().get("ctxtTopologyNodesDecl");
@@ -131,7 +129,7 @@ public class SchemaUtilsTest {
assertThatThrownBy(() -> {
AvroSchemaHelper schemaHelper = (AvroSchemaHelper) new SchemaHelperFactory()
- .createSchemaHelper(topoNodesKey, avroCtxtSchema.getKey());
+ .createSchemaHelper(topoNodesKey, avroCtxtSchema.getKey());
Map<String, Schema> schemaMap = new LinkedHashMap<>();
SchemaUtils.processSubSchemas(schemaHelper.getAvroSchema(), schemaMap);
@@ -140,20 +138,20 @@ public class SchemaUtilsTest {
schemaParameters.getSchemaHelperParameterMap().put("Avro", new AvroSchemaHelperParameters());
AvroSchemaHelper schemaHelper =
- (AvroSchemaHelper) new SchemaHelperFactory().createSchemaHelper(topoNodesKey, avroCtxtSchema.getKey());
+ (AvroSchemaHelper) new SchemaHelperFactory().createSchemaHelper(topoNodesKey, avroCtxtSchema.getKey());
Map<String, Schema> schemaMap = new LinkedHashMap<>();
SchemaUtils.processSubSchemas(schemaHelper.getAvroSchema(), schemaMap);
eventSchema = SchemaUtils.getEventSchema(event);
assertEquals("{\"type\":\"record\",\"name\":\"CustomerContextEventIn\"",
- eventSchema.toString().substring(0, 48));
+ eventSchema.toString().substring(0, 48));
epSchema = SchemaUtils.getEventParameterSchema(event.getParameterMap().get("links"), preexistingParamSchemas);
assertEquals("\"string\"", epSchema.toString());
AxInputField inField =
- new AxInputField(new AxReferenceKey("FieldParent", "0.0.1", "Field"), avroCtxtSchema.getKey(), false);
+ new AxInputField(new AxReferenceKey("FieldParent", "0.0.1", "Field"), avroCtxtSchema.getKey(), false);
Schema ep2Schema = SchemaUtils.getEventParameterSchema(inField, preexistingParamSchemas);
assertEquals("{\"type\":\"record\",\"name\":\"TopologyNodes\"", ep2Schema.toString().substring(0, 39));
diff --git a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2CliTest.java b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2CliTest.java
index b27c16842..41be1d3dd 100644
--- a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2CliTest.java
+++ b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2cli/Model2CliTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020,2022 Nordix Foundation.
+ * Modifications Copyright (C) 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");
@@ -24,27 +24,27 @@ package org.onap.policy.apex.tools.model.generator.model2cli;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test the Model2Cli utility.
*/
-public class Model2CliTest {
+class Model2CliTest {
@Test
- public void testModel2Cli() {
+ void testModel2Cli() {
final String[] cliArgs = {"-h"};
assertThatCode(() -> Model2CliMain.main(cliArgs)).doesNotThrowAnyException();
}
@Test
- public void testModel2CliNoOptions() {
+ void testModel2CliNoOptions() {
final String[] cliArgs = new String[] {};
final String outputString = runModel2Cli(cliArgs);
@@ -53,22 +53,22 @@ public class Model2CliTest {
}
@Test
- public void testModel2CliBadOptions() {
+ void testModel2CliBadOptions() {
assertThat(runModel2Cli(new String[] {"-zabbu"})).contains("usage: gen-model2cli");
}
@Test
- public void testModel2CliHelp() {
+ void testModel2CliHelp() {
assertThat(runModel2Cli(new String[] {"-h"})).contains("usage: gen-model2cli");
}
@Test
- public void testModel2CliVersion() {
+ void testModel2CliVersion() {
assertThat(runModel2Cli(new String[] {"-v"})).contains("gen-model2cli").doesNotContain("usage:");
}
@Test
- public void testModel2CliOverwrite() throws IOException {
+ void testModel2CliOverwrite() throws IOException {
File tempFile = File.createTempFile("AvroModel", ".apex");
tempFile.deleteOnExit();
@@ -80,32 +80,32 @@ public class Model2CliTest {
}
@Test
- public void testModel2CliAadm() throws IOException {
+ void testModel2CliAadm() throws IOException {
testModel2CliModel("target/examples/models/AADM", "AADMPolicyModel");
}
@Test
- public void testModel2CliAnomaly() throws IOException {
+ void testModel2CliAnomaly() throws IOException {
testModel2CliModel("target/examples/models/Adaptive", "AnomalyDetectionPolicyModel");
}
@Test
- public void testModel2CliAutoLearn() throws IOException {
+ void testModel2CliAutoLearn() throws IOException {
testModel2CliModel("target/examples/models/Adaptive", "AutoLearnPolicyModel");
}
@Test
- public void testModel2CliJms() throws IOException {
+ void testModel2CliJms() throws IOException {
testModel2CliModel("target/examples/models/JMS", "JMSTestModel");
}
@Test
- public void testModel2CliMfp() throws IOException {
+ void testModel2CliMfp() throws IOException {
testModel2CliModel("target/examples/models/MyFirstPolicy/2", "MyFirstPolicyModel_0.0.1");
}
@Test
- public void testModel2CliSample() throws IOException {
+ void testModel2CliSample() throws IOException {
testModel2CliModel("target/examples/models/SampleDomain", "SamplePolicyModelJAVASCRIPT");
}
diff --git a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2event/Model2EventSchemaTest.java b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2event/Model2EventSchemaTest.java
index 9c7eccd0f..9ffbd3ca4 100644
--- a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2event/Model2EventSchemaTest.java
+++ b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2event/Model2EventSchemaTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019, 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,15 +22,15 @@
package org.onap.policy.apex.tools.model.generator.model2event;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Arrays;
import org.apache.avro.Schema;
import org.apache.avro.Schema.Field;
import org.apache.avro.Schema.Type;
-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.SchemaParameters;
@@ -42,17 +42,20 @@ import org.stringtemplate.v4.STGroupFile;
/**
* Test the Model2EventSchema.
*/
-public class Model2EventSchemaTest {
+class Model2EventSchemaTest {
String modelFile = "src/test/resources/blankSchema.json";
String type = "stimuli";
- /** The name of the application. */
- public static final String APP_NAME = "gen-model2eventSchema";
/**
- * Set ups parameterService for the test.
+ * The name of the application.
*/
- @BeforeClass
- public static void prepareForTest() {
+ private static final String APP_NAME = "gen-model2eventSchema";
+
+ /**
+ * Set-ups parameterService for the test.
+ */
+ @BeforeAll
+ static void prepareForTest() {
final SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters());
@@ -62,7 +65,7 @@ public class Model2EventSchemaTest {
}
@Test
- public void testEventSchemaBadModelFile() {
+ void testEventSchemaBadModelFile() {
Model2JsonEventSchema app = new Model2JsonEventSchema(modelFile, type, APP_NAME);
assertThatCode(() -> {
int ret = app.runApp();
@@ -72,7 +75,7 @@ public class Model2EventSchemaTest {
}
@Test
- public void testEventSchemaBadType() {
+ void testEventSchemaBadType() {
modelFile = "src/test/resources/SmallModel.json";
type = "default";
Model2JsonEventSchema app = new Model2JsonEventSchema(modelFile, type, APP_NAME);
@@ -83,19 +86,19 @@ public class Model2EventSchemaTest {
}
@Test
- public void testEventSchemaStimuli() throws ApexException {
+ void testEventSchemaStimuli() throws ApexException {
modelFile = "src/test/resources/SmallModel.json";
String[] types = {"stimuli", "response", "internal"};
- for (String type2: types) {
+ for (String type2 : types) {
type = type2;
Model2JsonEventSchema app = new Model2JsonEventSchema(modelFile, type, APP_NAME);
- assertEquals(type, 0, app.runApp());
+ assertEquals(0, app.runApp(), type);
}
}
@Test
- public void testEventSchemaNotSimpleType() {
+ void testEventSchemaNotSimpleType() {
modelFile = "src/test/resources/ExecutionPropertiesRestTestPolicyModel.json";
type = "internal";
Model2JsonEventSchema app = new Model2JsonEventSchema(modelFile, type, APP_NAME);
@@ -103,7 +106,7 @@ public class Model2EventSchemaTest {
Field stringField = new Field("string", Schema.create(Type.STRING), null, null);
Field enumField =
- new Field("enum", Schema.createEnum("my_enum", "doc", null, Arrays.asList("a", "b", "c")), null, null);
+ new Field("enum", Schema.createEnum("my_enum", "doc", null, Arrays.asList("a", "b", "c")), null, null);
Schema schema = Schema.createRecord("my_record", "doc", "mytest", false);
schema.setFields(Arrays.asList(stringField, enumField));
Schema arrayOut = Schema.createArray(schema);
@@ -115,8 +118,8 @@ public class Model2EventSchemaTest {
}).doesNotThrowAnyException();
}
- @AfterClass
- public static void cleanTest() {
+ @AfterAll
+ static void cleanTest() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
ModelService.clear();
}
diff --git a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2event/Model2EventTest.java b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2event/Model2EventTest.java
index c9180607e..93bb6e9e8 100644
--- a/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2event/Model2EventTest.java
+++ b/tools/model-generator/src/test/java/org/onap/policy/apex/tools/model/generator/model2event/Model2EventTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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");
@@ -24,31 +24,27 @@ package org.onap.policy.apex.tools.model.generator.model2event;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test the Model2Event utility.
*/
-public class Model2EventTest {
+class Model2EventTest {
@Test
- public void testModel2Event() {
- final String[] EventArgs =
- { "-h" };
-
+ void testModel2Event() {
+ final String[] EventArgs = {"-h"};
assertThatCode(() -> Model2EventMain.main(EventArgs)).doesNotThrowAnyException();
-
}
@Test
- public void testModel2EventNoOptions() {
- final String[] EventArgs = new String[]
- {};
+ void testModel2EventNoOptions() {
+ final String[] EventArgs = new String[] {};
final String outputString = runModel2Event(EventArgs);
@@ -56,24 +52,24 @@ public class Model2EventTest {
}
@Test
- public void testModel2EventBadOptions() {
+ void testModel2EventBadOptions() {
assertThat(runModel2Event(new String[] {"-zabbu"})).contains("usage: gen-model2event");
}
@Test
- public void testModel2EventHelp() {
+ void testModel2EventHelp() {
assertThat(runModel2Event(new String[] {"-h"})).contains("usage: gen-model2event");
}
@Test
- public void testModel2EventVersion() {
+ void testModel2EventVersion() {
assertThat(runModel2Event(new String[] {"-v"})).contains("gen-model2event").doesNotContain("usage:");
}
@Test
- public void testModel2EventNoType() {
+ void testModel2EventNoType() {
final String[] EventArgs =
- { "-m", "src/test/resources/models/AvroModel.json" };
+ {"-m", "src/test/resources/models/AvroModel.json"};
final String outputString = runModel2Event(EventArgs);
@@ -81,9 +77,9 @@ public class Model2EventTest {
}
@Test
- public void testModel2EventBadType() {
+ void testModel2EventBadType() {
final String[] EventArgs =
- { "-m", "src/test/resources/models/AvroModel.json", "-t", "Zooby" };
+ {"-m", "src/test/resources/models/AvroModel.json", "-t", "Zooby"};
final String outputString = runModel2Event(EventArgs);
@@ -91,27 +87,27 @@ public class Model2EventTest {
}
@Test
- public void testModel2EventAadm() throws IOException {
+ void testModel2EventAadm() throws IOException {
testModel2EventModel("AADMPolicyModel");
}
@Test
- public void testModel2EventAnomaly() throws IOException {
+ void testModel2EventAnomaly() throws IOException {
testModel2EventModel("AnomalyDetectionPolicyModel");
}
@Test
- public void testModel2EventAutoLearn() throws IOException {
+ void testModel2EventAutoLearn() throws IOException {
testModel2EventModel("AutoLearnPolicyModel");
}
@Test
- public void testModel2EventMfp() throws IOException {
+ void testModel2EventMfp() throws IOException {
testModel2EventModel("MyFirstPolicyModel");
}
@Test
- public void testModel2EventSample() throws IOException {
+ void testModel2EventSample() throws IOException {
testModel2EventModel("SamplePolicyModelJAVASCRIPT");
}
@@ -143,17 +139,17 @@ public class Model2EventTest {
tempFile.deleteOnExit();
final String[] eventArgs0 =
- { "-m", "src/test/resources/models/" + modelName + ".json", "-t", "stimuli" };
+ {"-m", "src/test/resources/models/" + modelName + ".json", "-t", "stimuli"};
final String outputString0 = runModel2Event(eventArgs0);
assertTrue(outputString0.contains("type: stimuli"));
- final String[] eventArgs1 = {"-m", "src/test/resources/models/" + modelName + ".json", "-t", "response" };
+ final String[] eventArgs1 = {"-m", "src/test/resources/models/" + modelName + ".json", "-t", "response"};
final String outputString1 = runModel2Event(eventArgs1);
assertTrue(outputString1.contains("type: response"));
- final String[] eventArgs2 = {"-m", "src/test/resources/models/" + modelName + ".json", "-t", "internal" };
+ final String[] eventArgs2 = {"-m", "src/test/resources/models/" + modelName + ".json", "-t", "internal"};
final String outputString2 = runModel2Event(eventArgs2);
assertTrue(outputString2.contains("type: internal"));
diff --git a/tools/simple-wsclient/src/test/java/org/onap/policy/apex/tools/simple/wsclient/WsClientTest.java b/tools/simple-wsclient/src/test/java/org/onap/policy/apex/tools/simple/wsclient/WsClientTest.java
index e3e775af4..2c618c6a7 100644
--- a/tools/simple-wsclient/src/test/java/org/onap/policy/apex/tools/simple/wsclient/WsClientTest.java
+++ b/tools/simple-wsclient/src/test/java/org/onap/policy/apex/tools/simple/wsclient/WsClientTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 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");
@@ -29,70 +29,71 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test the WsClient utility.
*/
-public class WsClientTest {
+class WsClientTest {
+
@Test
- public void testWsClient() {
+ void testWsClient() {
final String[] EventArgs =
- { "-h" };
+ {"-h"};
assertThatCode(() -> WsClientMain.main(EventArgs)).doesNotThrowAnyException();
}
@Test
- public void testWsClientNoOptions() {
+ void testWsClientNoOptions() {
assertThat(runWsClient(new String[] {})).contains("ws-client: starting simple event echo");
}
@Test
- public void testWsClientBadOptions() {
+ void testWsClientBadOptions() {
assertThat(runWsClient(new String[] {"-zabbu"})).contains("usage: ws-client");
}
@Test
- public void testWsClientHelp() {
+ void testWsClientHelp() {
assertThat(runWsClient(new String[] {"-h"})).contains("usage: ws-client");
}
@Test
- public void testWsClientVersion() {
+ void testWsClientVersion() {
assertThat(runWsClient(new String[] {"-v"})).contains("ws-client").doesNotContain("usage:");
}
@Test
- public void testWsClientNoServerArg() {
+ void testWsClientNoServerArg() {
assertThat(runWsClient(new String[] {"-s"})).contains("ws-client");
}
@Test
- public void testWsClientNoPortArg() {
+ void testWsClientNoPortArg() {
assertThat(runWsClient(new String[] {"-p"})).contains("usage: ws-client");
}
@Test
- public void testWsClientBadPortArg() {
+ void testWsClientBadPortArg() {
assertThat(runWsClient(new String[] {"-p", "hello"})).contains("ws-client");
}
@Test
- public void testWsClientBadServerArg() {
+ void testWsClientBadServerArg() {
assertThat(runWsClient(new String[] {"-s", "asdsadadasd:asdasdsadasd"})).contains("ws-client");
}
@Test
- public void testWsClientConsole() {
+ void testWsClientConsole() {
assertThat(runWsClient(new String[] {"-c", "-s", "AServerThatDoesntExist", "-p", "99999999"}))
- .contains("terminate the application typing");
+ .contains("terminate the application typing");
}
@Test
- public void testWsClientEcho() {
+ void testWsClientEcho() {
assertThat(runWsClient(new String[] {"-s", "AServerThatDoesntExist", "-p", "99999999"})).contains(
- "Once started, the application will simply print out all received events to standard out");
+ "Once started, the application will simply print out all received events to standard out");
}
/**
diff --git a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/CliParserTest.java b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/CliParserTest.java
index 80980bb34..62dd1c2db 100644
--- a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/CliParserTest.java
+++ b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/CliParserTest.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.
@@ -23,10 +23,10 @@ package org.onap.policy.apex.tools.common;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.apache.commons.cli.Option;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -36,13 +36,15 @@ import org.slf4j.ext.XLoggerFactory;
*
* @author Sven van der Meer (sven.van.der.meer@ericsson.com)
*/
-public class CliParserTest {
+class CliParserTest {
private static final XLogger LOGGER = XLoggerFactory.getXLogger(CliParserTest.class);
- /** Testapp version. */
+ /**
+ * Test app version.
+ */
@Test
- public void testappVersion() {
+ void testAppVersion() {
final CliParser cli = new CliParser();
assertNotNull(cli);
LOGGER.info(cli.getAppVersion());
@@ -52,7 +54,7 @@ public class CliParserTest {
* testAddAndGetOptionException.
*/
@Test
- public void testAddAndGetOptionException() {
+ void testAddAndGetOptionException() {
final CliParser cli = new CliParser();
assertThatThrownBy(() -> {
cli.addOption(null);
@@ -63,7 +65,7 @@ public class CliParserTest {
* testParseAndGetCli.
*/
@Test
- public void testParseAndGetCli() {
+ void testParseAndGetCli() {
final CliParser cli = new CliParser();
final Option option = new Option("g", "Good option.");
cli.addOption(option);
diff --git a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/ConsoleTest.java b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/ConsoleTest.java
index aefa92b9c..70c8d1e4d 100644
--- a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/ConsoleTest.java
+++ b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/ConsoleTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019, 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,31 +24,30 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
-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;
/**
* Tests for {@link Console}.
- *
*/
-public class ConsoleTest {
+class ConsoleTest {
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
private final PrintStream originalErr = System.err;
- @Before
+ @BeforeEach
public void setUpStreams() {
System.setErr(new PrintStream(errContent));
}
- @After
+ @AfterEach
public void restoreStreams() {
System.setErr(originalErr);
}
@Test
- public void testConsole() {
+ void testConsole() {
Console.CONSOLE.setAppName(null);
Console.CONSOLE.info("");
Console.CONSOLE.error("");
@@ -61,23 +60,23 @@ public class ConsoleTest {
Console.CONSOLE.setAppName("");
Console.CONSOLE.set(Console.TYPE_DEBUG, Console.TYPE_ERROR, Console.TYPE_INFO, Console.TYPE_PROGRESS,
- Console.TYPE_WARNING, Console.TYPE_TRACE, Console.TYPE_STACKTRACE);
+ Console.TYPE_WARNING, Console.TYPE_TRACE, Console.TYPE_STACKTRACE);
Console.CONSOLE.configure(Console.CONFIG_COLLECT_WARNINGS);
logMessage();
assertThat(errContent.toString().trim()).contains("debug: debug message.")
- .contains("error: error message.").contains("info message.").contains("progress: progress message.")
- .contains("warning: warn message.").contains("trace: trace message.")
- .contains("exception message: Exception message.");
+ .contains("error: error message.").contains("info message.").contains("progress: progress message.")
+ .contains("warning: warn message.").contains("trace: trace message.")
+ .contains("exception message: Exception message.");
reset();
Console.CONSOLE.setAppName("ConsoleTest");
Console.CONSOLE.configure(Console.CONFIG_COLLECT_ERRORS);
logMessage();
assertThat(errContent.toString().trim())
- .contains("ConsoleTest: debug: debug message.").contains("ConsoleTest: error: error message.")
- .contains("ConsoleTest: info message.").contains("ConsoleTest: progress: progress message.")
- .contains("ConsoleTest: warning: warn message.").contains("ConsoleTest: trace: trace message.")
- .contains("ConsoleTest: exception message: Exception message.");
+ .contains("ConsoleTest: debug: debug message.").contains("ConsoleTest: error: error message.")
+ .contains("ConsoleTest: info message.").contains("ConsoleTest: progress: progress message.")
+ .contains("ConsoleTest: warning: warn message.").contains("ConsoleTest: trace: trace message.")
+ .contains("ConsoleTest: exception message: Exception message.");
reset();
Console.CONSOLE.deActivate(Console.TYPE_DEBUG);
@@ -94,7 +93,7 @@ public class ConsoleTest {
Console.CONSOLE.setAppName(null);
Console.CONSOLE.stacktrace(new Exception("Exception message.", new Throwable("test stacktrace!")));
assertThat(errContent.toString()).contains("exception message: Exception message.")
- .contains("exception cause: java.lang.Throwable: test stacktrace!");
+ .contains("exception cause: java.lang.Throwable: test stacktrace!");
reset();
}
diff --git a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/OutputFileTest.java b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/OutputFileTest.java
index abc01b5e3..decbb4395 100644
--- a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/OutputFileTest.java
+++ b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/OutputFileTest.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.
@@ -20,32 +20,33 @@
package org.onap.policy.apex.tools.common;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
import java.nio.file.FileSystems;
import java.nio.file.Path;
-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;
-public class OutputFileTest {
+class OutputFileTest {
final String testFileName = "testing.txt";
final Path fp = FileSystems.getDefault().getPath(testFileName);
File file = fp.toFile();
- @Before
- public void beforeSetUp() {
+ @BeforeEach
+ void beforeSetUp() {
if (file.exists()) {
- file.delete();
+ assertTrue(file.delete());
}
}
@Test
- public void testToWriter() {
+ void testToWriter() {
OutputFile testFile = new OutputFile(testFileName, false);
testFile.validate();
file.setReadable(false);
@@ -56,7 +57,7 @@ public class OutputFileTest {
}
@Test
- public void testValidate() {
+ void testValidate() {
OutputFile testFile = new OutputFile(testFileName, true);
assertNull(testFile.validate());
file.setReadable(false);
@@ -68,7 +69,7 @@ public class OutputFileTest {
}
@Test
- public void testToOutputStream() {
+ void testToOutputStream() {
OutputFile testFile = new OutputFile(testFileName, true);
assertNotNull(testFile.toOutputStream());
file.setReadable(false);
@@ -76,10 +77,10 @@ public class OutputFileTest {
assertNull(testFile.toOutputStream());
}
- @After
- public void testDown() {
+ @AfterEach
+ void testDown() {
if (file.exists()) {
- file.delete();
+ assertTrue(file.delete());
}
}
}
diff --git a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleAppVersionTest.java b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleAppVersionTest.java
index 1dc8d53ef..f817dc152 100644
--- a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleAppVersionTest.java
+++ b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleAppVersionTest.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,7 +21,7 @@
package org.onap.policy.apex.tools.common.docs;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
////
//// NOTE: This file contains tags for ASCIIDOC
@@ -30,7 +30,7 @@ import static org.junit.Assert.assertNotNull;
////// end::**
////
import org.apache.commons.cli.CommandLine;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.tools.common.CliOptions;
import org.onap.policy.apex.tools.common.CliParser;
import org.slf4j.ext.XLogger;
@@ -41,14 +41,16 @@ import org.slf4j.ext.XLoggerFactory;
*
* @author Sven van der Meer (sven.van.der.meer@ericsson.com)
*/
-public class ExampleAppVersionTest {
+class ExampleAppVersionTest {
private static final XLogger LOGGER = XLoggerFactory.getXLogger(ExampleAppVersionTest.class);
- /** Test example app version. */
+ /**
+ * Test example app version.
+ */
@Test
- public void testExampleAppVersion() {
- final String[] args = new String[] { "-v" };
+ void testExampleAppVersion() {
+ final String[] args = new String[] {"-v"};
// tag::setupParser[]
final CliParser cli = new CliParser();
@@ -60,7 +62,7 @@ public class ExampleAppVersionTest {
// tag::processCliVersion[]
// version is an exit option, print version and exit
if (cmd.hasOption('v') || cmd.hasOption("version")) {
- LOGGER.info("myApp" + " " + cli.getAppVersion());
+ LOGGER.info("myApp {}", cli.getAppVersion());
return;
}
// end::processCliVersion[]
diff --git a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleCliParserTest.java b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleCliParserTest.java
index c653cd0b2..0be41d685 100644
--- a/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleCliParserTest.java
+++ b/tools/tools-common/src/test/java/org/onap/policy/apex/tools/common/docs/ExampleCliParserTest.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,7 +21,7 @@
package org.onap.policy.apex.tools.common.docs;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
////
////NOTE: This file contains tags for ASCIIDOC
@@ -33,7 +33,7 @@ import static org.junit.Assert.assertNotNull;
////
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.HelpFormatter;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
//tag::import[]
import org.onap.policy.apex.tools.common.CliOptions;
import org.onap.policy.apex.tools.common.CliParser;
@@ -46,7 +46,7 @@ import org.slf4j.ext.XLoggerFactory;
*
* @author Sven van der Meer (sven.van.der.meer@ericsson.com)
*/
-public class ExampleCliParserTest {
+class ExampleCliParserTest {
private static final XLogger LOGGER = XLoggerFactory.getXLogger(ExampleCliParserTest.class);
@@ -54,8 +54,8 @@ public class ExampleCliParserTest {
* Test example parser.
*/
@Test
- public void testExampleParser() {
- final String[] args = new String[] { "-h" };
+ void testExampleParser() {
+ final String[] args = new String[] {"-h"};
// tag::setApp[]
final String appName = "test-app";
@@ -79,7 +79,7 @@ public class ExampleCliParserTest {
// help is an exit option, print usage and exit
if (cmd.hasOption('h') || cmd.hasOption("help")) {
final HelpFormatter formatter = new HelpFormatter();
- LOGGER.info(appName + " v" + cli.getAppVersion() + " - " + appDescription);
+ LOGGER.info(appName + " v{} - " + appDescription, cli.getAppVersion());
formatter.printHelp(appName, cli.getOptions());
return;
}
@@ -88,7 +88,7 @@ public class ExampleCliParserTest {
// tag::processCliVersion[]
// version is an exit option, print version and exit
if (cmd.hasOption('v') || cmd.hasOption("version")) {
- LOGGER.info(appName + " " + cli.getAppVersion());
+ LOGGER.info(appName + " {}", cli.getAppVersion());
return;
}
// end::processCliVersion[]
@@ -106,7 +106,7 @@ public class ExampleCliParserTest {
// tag::someStartPrint[]
LOGGER.info(appName + ": starting");
- LOGGER.info(" --> model file: " + modelFile);
+ LOGGER.info(" --> model file: {}", modelFile);
// end::someStartPrint[]
// tag::yourApp[]