summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java14
-rw-r--r--core/src/main/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutor.java4
-rw-r--r--core/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java4
-rw-r--r--core/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContext.java4
-rw-r--r--core/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContext.java4
-rw-r--r--core/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.java18
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/EngineParametersTest.java17
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/ExecutorParametersTest.java20
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/context/ApexInternalContextTest.java35
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java155
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummyEnEventListener.java7
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummyListener.java10
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java18
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySmExecutor.java6
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/event/DummyAxKey.java10
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java46
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/event/EnExceptionTest.java15
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/event/EnFieldTest.java26
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyFailingTaskExecutor.java6
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyStateFinalizerExecutor.java7
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskExecutor.java5
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskSelectExecutor.java2
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/StateExecutorTest.java34
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutorTest.java35
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutorTest.java54
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java88
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java35
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacadeTest.java41
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacadeTest.java38
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/context/DummyContextAlbum.java12
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContextTest.java32
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContextTest.java28
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContextTest.java32
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/exception/StateMachineRuntimeExceptionTest.java18
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImplTest.java (renamed from core/src/test/java/org/onap/policy/apex/core/engine/executor/impl/ExceutorFactoryImplTest.java)105
-rw-r--r--core/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTest.java24
-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/engine/main/ApexMain.java2
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImpl.java209
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/parameters/eventprotocol/EventProtocolParameters.java4
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexEventTest.java52
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexPeriodicEventGeneratorTest.java8
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java14
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java48
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java46
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventProtocolParametersTest.java (renamed from services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventProtocolPrametersTest.java)32
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonTaggedEventConsumerTest.java56
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/PeeredReferenceTest.java14
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/PluginFactoriesTest.java14
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/SynchronousEventCacheTest.java37
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactoryTest.java22
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactoryTest.java22
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProtocolFactoryTest.java20
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java36
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/ApexEventProtocolParametersTest.java12
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java20
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParametersTest.java14
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorConsumerTest.java22
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorProducerTest.java37
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParametersTest.java74
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/ApexFileEventConsumerTest.java36
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/HeaderDelimitedTextBlockReaderTest.java30
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockReaderFactoryTest.java18
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockTest.java14
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/producer/ApexFileEventProducerTest.java46
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java56
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java60
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java26
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java30
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ContextParameterTests.java54
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ExecutorParameterTests.java49
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java85
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java71
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java96
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java78
-rw-r--r--services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java421
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java35
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpMessageHandler.java6
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java22
-rw-r--r--services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java18
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java37
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterCommandLineArguments.java12
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterConstants.java9
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java39
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java41
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java59
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/exception/TestExceptions.java8
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java3
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java59
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java46
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.java32
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyStateFinalizerExecutor.java6
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskExecutor.java10
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskSelectExecutor.java10
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java58
-rw-r--r--services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/TestHealthCheckRestControllerV1.java37
-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
189 files changed, 3702 insertions, 3887 deletions
diff --git a/core/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java b/core/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java
index 35139bfe4..773923444 100644
--- a/core/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.java
+++ b/core/src/main/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImpl.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-2022 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -193,7 +193,8 @@ public class ApexEngineImpl implements ApexEngine {
}
private void updateTaskBasedOnStateOutput(AxPolicyModel apexPolicyModel, Set<AxArtifactKey> updatedTasks,
- AxState state, AxArtifactKey taskKey, AxStateTaskReference taskRef, AxTask task) {
+ AxState state, AxArtifactKey taskKey, AxStateTaskReference taskRef,
+ AxTask task) {
Map<String, AxEvent> outputEvents = new TreeMap<>();
AxStateOutput stateOutput = null;
if (AxStateTaskOutputType.LOGIC.equals(taskRef.getStateTaskOutputType())) {
@@ -279,14 +280,13 @@ public class ApexEngineImpl implements ApexEngine {
}
// Stop the engine if it is in state READY, if it is in state EXECUTING, wait for execution to finish
for (int increment = ApexEngineConstants.STOP_EXECUTION_WAIT_TIMEOUT; increment > 0;
- increment -= ApexEngineConstants.APEX_ENGINE_STOP_EXECUTION_WAIT_INCREMENT) {
+ increment -= ApexEngineConstants.APEX_ENGINE_STOP_EXECUTION_WAIT_INCREMENT) {
ThreadUtilities.sleep(ApexEngineConstants.APEX_ENGINE_STOP_EXECUTION_WAIT_INCREMENT);
synchronized (stateLockObj) {
switch (state) {
// Engine is OK to stop or has been stopped on return of an event
- case READY:
- case STOPPED:
+ case READY, STOPPED:
state = AxEngineState.STOPPED;
updateStatePrometheusMetric();
stateMachineHandler.stop();
@@ -388,7 +388,7 @@ public class ApexEngineImpl implements ApexEngine {
String message = "execute(): triggered by event " + incomingEvent.toString();
LOGGER.debug(message);
- // By default we return a null event on errors
+ // By default, we return a null event on errors
Collection<EnEvent> outgoingEvents = null;
try {
engineStats.executionEnter(incomingEvent.getKey());
@@ -406,7 +406,7 @@ public class ApexEngineImpl implements ApexEngine {
try {
synchronized (eventListeners) {
if (eventListeners.isEmpty()) {
- LOGGER.debug("handleEvent()<-{},{}, There is no listener registered to recieve outgoing event: {}",
+ LOGGER.debug("handleEvent()<-{},{}, There is no listener registered to receive outgoing event: {}",
key.getId(), state, outgoingEvents);
}
for (final EnEventListener axEventListener : eventListeners.values()) {
diff --git a/core/src/main/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutor.java b/core/src/main/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutor.java
index 6cbc04678..6b8dd43ec 100644
--- a/core/src/main/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutor.java
+++ b/core/src/main/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutor.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -129,7 +129,7 @@ public class StateMachineExecutor implements Executor<EnEvent, Collection<EnEven
public Collection<EnEvent> execute(final long executionId, final Properties executionProperties,
final EnEvent incomingEvent) throws StateMachineException, ContextException {
// Check if there are any states on the state machine
- if (stateExecutorMap.size() == 0) {
+ if (stateExecutorMap.isEmpty()) {
throw new StateMachineException("no states defined on state machine");
}
diff --git a/core/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java b/core/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java
index 12e350390..7cdca18d8 100644
--- a/core/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java
+++ b/core/src/main/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContext.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
@@ -86,7 +86,7 @@ public class StateFinalizerExecutionContext extends AbstractExecutionContext {
/**
* Logger for state finalizer execution, state finalizer logic can use this field to access and log to Apex logging.
*/
- public final XLogger logger = EXCEUTION_LOGGER;
+ public static final XLogger logger = EXCEUTION_LOGGER;
// CHECKSTYLE:ON: checkstyle:visibilityModifier
diff --git a/core/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContext.java b/core/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContext.java
index a54252e05..d5bb370bc 100644
--- a/core/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContext.java
+++ b/core/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContext.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.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
@@ -83,7 +83,7 @@ public class TaskExecutionContext extends AbstractExecutionContext {
/**
* Logger for task execution, task logic can use this field to access and log to Apex logging.
*/
- public final XLogger logger = EXECUTION_LOGGER;
+ public static final XLogger logger = EXECUTION_LOGGER;
// CHECKSTYLE:ON: checkstyle:VisibilityModifier
diff --git a/core/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContext.java b/core/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContext.java
index c79e907d9..62808dfb6 100644
--- a/core/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContext.java
+++ b/core/src/main/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContext.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.
* Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
@@ -73,7 +73,7 @@ public class TaskSelectionExecutionContext extends AbstractExecutionContext {
/**
* Logger for task selection execution, task selection logic can use this field to access and log to Apex logging.
*/
- public final XLogger logger = EXECUTION_LOGGER;
+ public static final XLogger logger = EXECUTION_LOGGER;
// CHECKSTYLE:ON: checkstyle:VisibilityModifier
diff --git a/core/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.java b/core/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.java
index 9dc841f48..53b041e36 100644
--- a/core/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.java
+++ b/core/src/main/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImpl.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");
@@ -157,21 +157,21 @@ public class ExecutorFactoryImpl implements ExecutorFactory {
}
// Get the class for the executor using reflection
- Class<? extends Object> executorPluginClass = null;
+ Class<?> executorPluginClass;
try {
executorPluginClass = Class.forName(executorClassName);
} catch (final ClassNotFoundException e) {
- LOGGER.error("Apex executor class not found for executor plugin \"" + executorClassName + "\"", e);
+ LOGGER.error("Apex executor class not found for executor plugin \"{}\"", executorClassName, e);
throw new StateMachineException(
"Apex executor class not found for executor plugin \"" + executorClassName + "\"", e);
}
// Check the class is an executor
if (!Executor.class.isAssignableFrom(executorPluginClass)) {
- LOGGER.error("Specified Apex executor plugin class \"{}\" does not implment the Executor interface",
+ LOGGER.error("Specified Apex executor plugin class \"{}\" does not implement the Executor interface",
executorClassName);
throw new StateMachineException("Specified Apex executor plugin class \"" + executorClassName
- + "\" does not implment the Executor interface");
+ + "\" does not implement the Executor interface");
}
return (Class<Executor<?, ?, ?, ?>>) executorPluginClass;
@@ -181,14 +181,14 @@ public class ExecutorFactoryImpl implements ExecutorFactory {
* Get an instance of an executor plugin class of the specified type and super type.
*
* @param logicFlavour The logic flavour of the logic
- * @param executorClass The sub-class of the executor type to be instantiated
+ * @param executorClass The subclass of the executor type to be instantiated
* @param executorSuperClass The super type of the class of executor to be instantiated
* @return The instantiated class
*/
private Executor<?, ?, ?, ?> createExecutor(final String logicFlavour,
final Class<Executor<?, ?, ?, ?>> executorClass,
final Class<? extends Executor<?, ?, ?, ?>> executorSuperClass) {
- // It's OK for an executor class not to be defined but it's not all right to try and create
+ // It's OK for an executor class not to be defined, but it's not all right to try and create
// a non-defined
// executor class
if (executorClass == null) {
@@ -199,7 +199,7 @@ public class ExecutorFactoryImpl implements ExecutorFactory {
}
// Create an executor for the specified logic flavour
- Object executorObject = null;
+ Executor<?, ?, ?, ?> executorObject;
try {
executorObject = executorClass.getDeclaredConstructor().newInstance();
} catch (final Exception e) {
@@ -218,6 +218,6 @@ public class ExecutorFactoryImpl implements ExecutorFactory {
throw new StateMachineRuntimeException(errorMessage);
}
- return (Executor<?, ?, ?, ?>) executorObject;
+ return executorObject;
}
}
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/EngineParametersTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/EngineParametersTest.java
index 5427c3515..33c9b3efb 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/EngineParametersTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/EngineParametersTest.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");
@@ -23,26 +23,25 @@
package org.onap.policy.apex.core.engine;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.context.parameters.ContextParameters;
import org.onap.policy.common.parameters.ParameterService;
/**
* Test the executor parameters.
- *
*/
-public class EngineParametersTest {
+class EngineParametersTest {
@Test
- public void test() {
+ void test() {
EngineParameters pars = new EngineParameters();
pars.setName("Name");
assertEquals("Name", pars.getName());
@@ -70,7 +69,7 @@ public class EngineParametersTest {
}
@Test
- public void test_invalid() {
+ void test_invalid() {
EngineParameters pars = new EngineParameters();
pars.setName("Name");
assertEquals("Name", pars.getName());
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/ExecutorParametersTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/ExecutorParametersTest.java
index 784580422..5e1ee81fd 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/ExecutorParametersTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/ExecutorParametersTest.java
@@ -1,7 +1,8 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 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.
@@ -22,20 +23,19 @@
package org.onap.policy.apex.core.engine;
import static org.assertj.core.api.Assertions.assertThat;
-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.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.ParameterService;
/**
* Test the executor parameters.
- *
*/
-public class ExecutorParametersTest {
+class ExecutorParametersTest {
@Test
- public void test() {
+ void test() {
ExecutorParameters pars = new ExecutorParameters();
pars.setName("Name");
assertEquals("Name", pars.getName());
@@ -47,8 +47,8 @@ public class ExecutorParametersTest {
assertEquals("some.task.selection.executor.plugin.class", pars.getTaskSelectionExecutorPluginClass());
assertEquals("ExecutorParameters [name=Name, taskExecutorPluginClass=some.task.executor.plugin.class, "
- + "taskSelectionExecutorPluginClass=some.task.selection.executor.plugin.class, "
- + "stateFinalizerExecutorPluginClass=some.state.finalizer.plugin.class]", pars.toString());
+ + "taskSelectionExecutorPluginClass=some.task.selection.executor.plugin.class, "
+ + "stateFinalizerExecutorPluginClass=some.state.finalizer.plugin.class]", pars.toString());
assertThat(pars.validate().getResult()).isNull();
assertTrue(pars.validate().isValid());
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/context/ApexInternalContextTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/context/ApexInternalContextTest.java
index 19828f6e2..e918deb12 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/context/ApexInternalContextTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/context/ApexInternalContextTest.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.
* ================================================================================
* 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,11 @@
package org.onap.policy.apex.core.engine.context;
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.ContextException;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.DistributorParameters;
@@ -42,20 +42,19 @@ import org.onap.policy.common.parameters.ParameterService;
/**
* Test the Apex engine internal context class.
*/
-public class ApexInternalContextTest {
+class ApexInternalContextTest {
private AxPolicyModel policyModel;
private AxPolicyModel newVersionPolicyModel;
private AxPolicyModel newPolicyModel;
private AxContextAlbum album;
- private AxContextAlbum newAlbum;
private AxPolicyModel incompatiblePolicyModel;
/**
* Initialize parameters.
*/
- @Before
- public void registerParameters() {
+ @BeforeEach
+ void registerParameters() {
ParameterService.register(new SchemaParameters());
ParameterService.register(new DistributorParameters());
ParameterService.register(new LockManagerParameters());
@@ -65,8 +64,8 @@ public class ApexInternalContextTest {
/**
* Create policy model.
*/
- @Before
- public void createPolicyModels() {
+ @BeforeEach
+ void createPolicyModels() {
AxArtifactKey modelKey = new AxArtifactKey("PolicyModel:0.0.1");
policyModel = new AxPolicyModel(modelKey);
@@ -109,7 +108,7 @@ public class ApexInternalContextTest {
newPolicyModel.getSchemas().getSchemasMap().put(newSchemaKey, newSchema);
AxArtifactKey newAlbumKey = new AxArtifactKey("NewAlbum:0.0.1");
- newAlbum = new AxContextAlbum(newAlbumKey, "Policy", true, newSchemaKey);
+ AxContextAlbum newAlbum = new AxContextAlbum(newAlbumKey, "Policy", true, newSchemaKey);
newPolicyModel.getAlbums().getAlbumsMap().put(newAlbumKey, newAlbum);
}
@@ -117,8 +116,8 @@ public class ApexInternalContextTest {
/**
* Deregister parameters.
*/
- @After
- public void deregisterParameters() {
+ @AfterEach
+ void deregisterParameters() {
ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.PERSISTENCE_GROUP_NAME);
@@ -126,7 +125,7 @@ public class ApexInternalContextTest {
}
@Test
- public void testAlbumInit() throws ContextException {
+ void testAlbumInit() throws ContextException {
assertThatThrownBy(() -> new ApexInternalContext(null))
.hasMessage("internal context update failed, supplied model is null");
ApexInternalContext context = new ApexInternalContext(policyModel);
@@ -140,17 +139,17 @@ public class ApexInternalContextTest {
assertEquals(album.getId(), context.get(albumKey.getName(), albumKey.getVersion()).getKey().getId());
assertEquals(album.getId(), context.getAll(albumKey.getName()).iterator().next().getKey().getId());
assertEquals(album.getId(),
- context.getAll(albumKey.getName(), albumKey.getVersion()).iterator().next().getKey().getId());
+ context.getAll(albumKey.getName(), albumKey.getVersion()).iterator().next().getKey().getId());
context.clear();
assertEquals(1, context.getContextAlbums().size());
assertEquals("ApexInternalContext [contextAlbums={AxArtifactKey:(name=Album,version=0.0.1)",
- context.toString().substring(0, 76));
+ context.toString().substring(0, 76));
}
@Test
- public void testAlbumUpdate() throws ContextException {
+ void testAlbumUpdate() throws ContextException {
ApexInternalContext context = new ApexInternalContext(policyModel);
assertThatThrownBy(() -> context.update(null, false))
.hasMessage("internal context update failed, supplied model is null");
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
index 8d7df45cd..a66f8c683 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2019-2021, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019-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");
@@ -24,25 +24,25 @@ package org.onap.policy.apex.core.engine.engine.impl;
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.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.assertTrue;
import io.prometheus.client.CollectorRegistry;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.DistributorParameters;
import org.onap.policy.apex.context.parameters.LockManagerParameters;
@@ -71,8 +71,8 @@ import org.onap.policy.common.parameters.ParameterService;
/**
* Test the engine implementation.
*/
-@RunWith(MockitoJUnitRunner.class)
-public class ApexEngineImplTest {
+@ExtendWith(MockitoExtension.class)
+class ApexEngineImplTest {
private static final String ENGINE_ID = "Engine:0.0.1";
private AxPolicyModel policyModel;
@@ -85,8 +85,8 @@ public class ApexEngineImplTest {
/**
* Set up services.
*/
- @BeforeClass
- public static void setup() {
+ @BeforeAll
+ static void setup() {
ParameterService.register(new SchemaParameters());
ParameterService.register(new DistributorParameters());
ParameterService.register(new LockManagerParameters());
@@ -97,17 +97,17 @@ public class ApexEngineImplTest {
/**
* Set up mocking.
*/
- @Before
- public void initializeMocking() throws ApexException {
- Mockito.doThrow(new StateMachineException("mocked state machine exception",
- new IOException("nexted exception"))).when(smHandlerMock).execute(Mockito.any());
+ @BeforeEach
+ void initializeMocking() throws ApexException {
+ Mockito.lenient().doThrow(new StateMachineException("mocked state machine exception",
+ new IOException("nexted exception"))).when(smHandlerMock).execute(Mockito.any());
}
/**
* Create policy models.
*/
- @Before
- public void createPolicyModels() {
+ @BeforeEach
+ void createPolicyModels() {
AxArtifactKey modelKey = new AxArtifactKey("PolicyModel:0.0.1");
policyModel = new AxPolicyModel(modelKey);
@@ -162,8 +162,8 @@ public class ApexEngineImplTest {
/**
* Clear registrations.
*/
- @AfterClass
- public static void teardown() {
+ @AfterAll
+ static void teardown() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
@@ -172,14 +172,14 @@ public class ApexEngineImplTest {
}
@Test
- public void testSanity() throws ApexException {
+ void testSanity() throws ApexException {
AxArtifactKey engineKey = new AxArtifactKey(ENGINE_ID);
ApexEngineImpl engine = (ApexEngineImpl) new ApexEngineFactory().createApexEngine(engineKey);
assertNotNull(engine);
assertEquals(engineKey, engine.getKey());
assertThatThrownBy(engine::start).hasMessage("start()<-Engine:0.0.1,STOPPED, cannot start engine, "
- + "engine has not been initialized, its model is not loaded");
+ + "engine has not been initialized, its model is not loaded");
assertThatThrownBy(engine::stop)
.hasMessage("stop()<-Engine:0.0.1,STOPPED, cannot stop engine, " + "engine is already stopped");
@@ -203,7 +203,7 @@ public class ApexEngineImplTest {
}
@Test
- public void testListener() throws ApexException {
+ void testListener() throws ApexException {
AxArtifactKey engineKey = new AxArtifactKey(ENGINE_ID);
ApexEngineImpl engine = (ApexEngineImpl) new ApexEngineFactory().createApexEngine(engineKey);
@@ -262,7 +262,7 @@ public class ApexEngineImplTest {
}
@Test
- public void testEventKey() throws ApexException {
+ void testEventKey() throws ApexException {
AxArtifactKey engineKey = new AxArtifactKey(ENGINE_ID);
ApexEngineImpl engine = (ApexEngineImpl) new ApexEngineFactory().createApexEngine(engineKey);
engine.updateModel(policyModel, false);
@@ -315,7 +315,7 @@ public class ApexEngineImplTest {
}
@Test
- public void testState() throws InterruptedException, ApexException {
+ void testState() throws ApexException {
AxArtifactKey engineKey = new AxArtifactKey(ENGINE_ID);
ApexEngineImpl engine = (ApexEngineImpl) new ApexEngineFactory().createApexEngine(engineKey);
assertNotNull(engine);
@@ -332,21 +332,13 @@ public class ApexEngineImplTest {
assertEquals(AxEngineState.READY, engine.getState());
checkAxEngineStateMetric(AxEngineState.READY);
- assertEquals(AxEngineState.READY, engine.getState());
- checkAxEngineStateMetric(AxEngineState.READY);
-
AxArtifactKey eventKey = new AxArtifactKey("Event:0.0.1");
EnEvent event = engine.createEvent(eventKey);
assertEquals(eventKey, event.getKey());
- // 1 second is less than the 3 second wait on engine stopping
+ // 1 second is less than the 3 seconds wait on engine stopping
slowListener.setWaitTime(1000);
- (new Thread() {
- @Override
- public void run() {
- engine.handleEvent(event);
- }
- }).start();
+ (new Thread(() -> engine.handleEvent(event))).start();
await().atLeast(50, TimeUnit.MILLISECONDS).until(() -> engine.getState().equals(AxEngineState.EXECUTING));
assertEquals(AxEngineState.EXECUTING, engine.getState());
checkAxEngineStateMetric(AxEngineState.EXECUTING);
@@ -362,14 +354,9 @@ public class ApexEngineImplTest {
assertEquals(AxEngineState.READY, engine.getState());
checkAxEngineStateMetric(AxEngineState.READY);
- // 4 seconds is more than the 3 second wait on engine stopping
+ // 4 seconds is more than the 3 seconds wait on engine stopping
slowListener.setWaitTime(4000);
- (new Thread() {
- @Override
- public void run() {
- engine.handleEvent(event);
- }
- }).start();
+ (new Thread(() -> engine.handleEvent(event))).start();
await().atLeast(50, TimeUnit.MILLISECONDS).until(() -> engine.getState().equals(AxEngineState.EXECUTING));
assertEquals(AxEngineState.EXECUTING, engine.getState());
@@ -384,8 +371,8 @@ public class ApexEngineImplTest {
}
@Test
- public void testStateMachineError() throws InterruptedException, IllegalArgumentException, IllegalAccessException,
- NoSuchFieldException, SecurityException, ApexException {
+ void testStateMachineError() throws IllegalArgumentException, IllegalAccessException,
+ NoSuchFieldException, SecurityException, ApexException {
AxArtifactKey engineKey = new AxArtifactKey(ENGINE_ID);
ApexEngineImpl engine = (ApexEngineImpl) new ApexEngineFactory().createApexEngine(engineKey);
@@ -404,9 +391,6 @@ public class ApexEngineImplTest {
assertEquals(AxEngineState.READY, engine.getState());
checkAxEngineStateMetric(AxEngineState.READY);
- assertEquals(AxEngineState.READY, engine.getState());
- checkAxEngineStateMetric(AxEngineState.READY);
-
AxArtifactKey eventKey = new AxArtifactKey("Event:0.0.1");
EnEvent event = engine.createEvent(eventKey);
assertEquals(eventKey, event.getKey());
@@ -419,9 +403,9 @@ public class ApexEngineImplTest {
assertEquals(AxEngineState.STOPPED, engine.getState());
checkAxEngineStateMetric(AxEngineState.STOPPED);
Mockito.doThrow(new StateMachineException("mocked state machine exception",
- new IOException("nexted exception"))).when(smHandlerMock).start();
+ new IOException("nexted exception"))).when(smHandlerMock).start();
assertThatThrownBy(engine::start).hasMessage("updateModel()<-Engine:0.0.1, error starting the engine state "
- + "machines \"Engine:0.0.1\"");
+ + "machines \"Engine:0.0.1\"");
assertEquals(AxEngineState.STOPPED, engine.getState());
checkAxEngineStateMetric(AxEngineState.STOPPED);
@@ -431,8 +415,8 @@ public class ApexEngineImplTest {
}
@Test
- public void testStateMachineHandler() throws InterruptedException, IllegalArgumentException, IllegalAccessException,
- NoSuchFieldException, SecurityException, ApexException {
+ void testStateMachineHandler() throws IllegalArgumentException, IllegalAccessException,
+ NoSuchFieldException, SecurityException, ApexException {
AxArtifactKey engineKey = new AxArtifactKey(ENGINE_ID);
ApexEngineImpl engine = (ApexEngineImpl) new ApexEngineFactory().createApexEngine(engineKey);
assertNotNull(engine);
@@ -450,10 +434,24 @@ public class ApexEngineImplTest {
EnEvent event = engine.createEvent(eventKey);
assertEquals(eventKey, event.getKey());
+ assertEngineStopStartState(engine, event);
+
+ HashMap<AxEvent, StateMachineExecutor>
+ smExMap = getAxEventStateMachineExecutorHashMap(engine);
+
+ assertEquals(1, smExMap.size());
+ DummySmExecutor dummyExecutor = new DummySmExecutor(null, event.getKey());
+ smExMap.put(event.getAxEvent(), dummyExecutor);
+ ApexInternalContext internalContext = new ApexInternalContext(policyModelWithStates);
+ assertThatThrownBy(() -> dummyExecutor.setContext(null, null, internalContext))
+ .isInstanceOf(NullPointerException.class);
+
engine.stop();
assertEquals(AxEngineState.STOPPED, engine.getState());
checkAxEngineStateMetric(AxEngineState.STOPPED);
+ assertThatThrownBy(engine::start).hasMessageContaining("updateModel()<-Engine:0.0.1, error starting the "
+ + "engine state machines \"Engine:0.0.1\"");
assertEquals(AxEngineState.STOPPED, engine.getState());
checkAxEngineStateMetric(AxEngineState.STOPPED);
@@ -461,14 +459,22 @@ public class ApexEngineImplTest {
assertEquals(AxEngineState.READY, engine.getState());
checkAxEngineStateMetric(AxEngineState.READY);
+ // Works, Dummy executor fakes event execution
+ assertTrue(engine.handleEvent(event));
assertEquals(AxEngineState.READY, engine.getState());
checkAxEngineStateMetric(AxEngineState.READY);
- // Can't work, state is not fully defined
- assertFalse(engine.handleEvent(event));
- assertEquals(AxEngineState.READY, engine.getState());
- checkAxEngineStateMetric(AxEngineState.READY);
+ engine.stop();
+ assertEquals(AxEngineState.STOPPED, engine.getState());
+ checkAxEngineStateMetric(AxEngineState.STOPPED);
+
+ engine.clear();
+ assertEquals(AxEngineState.STOPPED, engine.getState());
+ checkAxEngineStateMetric(AxEngineState.STOPPED);
+ }
+ private static HashMap<AxEvent, StateMachineExecutor> getAxEventStateMachineExecutorHashMap(ApexEngineImpl engine)
+ throws NoSuchFieldException, IllegalAccessException {
final Field smHandlerField = engine.getClass().getDeclaredField("stateMachineHandler");
smHandlerField.setAccessible(true);
StateMachineHandler smHandler = (StateMachineHandler) smHandlerField.get(engine);
@@ -477,45 +483,28 @@ public class ApexEngineImplTest {
smExecutorMapField.setAccessible(true);
@SuppressWarnings("unchecked")
HashMap<AxEvent, StateMachineExecutor> smExMap = (HashMap<AxEvent, StateMachineExecutor>) smExecutorMapField
- .get(smHandler);
-
- assertEquals(1, smExMap.size());
- DummySmExecutor dummyExecutor = new DummySmExecutor(null, event.getKey());
- smExMap.put(event.getAxEvent(), dummyExecutor);
- ApexInternalContext internalContext = new ApexInternalContext(policyModelWithStates);
- assertThatThrownBy(() -> dummyExecutor.setContext(null, null, internalContext))
- .isInstanceOf(NullPointerException.class);
+ .get(smHandler);
+ return smExMap;
+ }
+ private void assertEngineStopStartState(ApexEngineImpl engine, EnEvent event) throws ApexException {
engine.stop();
assertEquals(AxEngineState.STOPPED, engine.getState());
checkAxEngineStateMetric(AxEngineState.STOPPED);
- assertThatThrownBy(engine::start).hasMessageContaining("updateModel()<-Engine:0.0.1, error starting the "
- + "engine state machines \"Engine:0.0.1\"");
- assertEquals(AxEngineState.STOPPED, engine.getState());
- checkAxEngineStateMetric(AxEngineState.STOPPED);
-
engine.start();
assertEquals(AxEngineState.READY, engine.getState());
checkAxEngineStateMetric(AxEngineState.READY);
- // Works, Dummy executor fakes event execution
- assertTrue(engine.handleEvent(event));
+ // Can't work, state is not fully defined
+ assertFalse(engine.handleEvent(event));
assertEquals(AxEngineState.READY, engine.getState());
checkAxEngineStateMetric(AxEngineState.READY);
-
- engine.stop();
- assertEquals(AxEngineState.STOPPED, engine.getState());
- checkAxEngineStateMetric(AxEngineState.STOPPED);
-
- engine.clear();
- assertEquals(AxEngineState.STOPPED, engine.getState());
- checkAxEngineStateMetric(AxEngineState.STOPPED);
}
private void checkAxEngineStateMetric(AxEngineState state) {
Double stateMetric = CollectorRegistry.defaultRegistry
- .getSampleValue("pdpa_engine_state", new String[]{"engine_instance_id"}, new String[]{ENGINE_ID});
+ .getSampleValue("pdpa_engine_state", new String[] {"engine_instance_id"}, new String[] {ENGINE_ID});
assertEquals(stateMetric.intValue(), state.getStateIdentifier());
}
} \ No newline at end of file
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummyEnEventListener.java b/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummyEnEventListener.java
index b429295ad..2227379a6 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummyEnEventListener.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummyEnEventListener.java
@@ -5,15 +5,15 @@
* 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=========================================================
*/
@@ -26,7 +26,6 @@ import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
/**
* Dummy engine event listener for unit test.
- *
*/
public class DummyEnEventListener implements EnEventListener {
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummyListener.java b/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummyListener.java
index 6256ff498..565bb2348 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummyListener.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummyListener.java
@@ -1,19 +1,20 @@
/*-
* ============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=========================================================
*/
@@ -26,7 +27,6 @@ import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
/**
* Dummy engine event listener for unit test.
- *
*/
public class DummyListener implements EnEventListener {
@@ -34,7 +34,7 @@ public class DummyListener implements EnEventListener {
* {@inheritDoc}.
*/
@Override
- public void onEnEvent(EnEvent enEvent) throws ApexException {
+ public void onEnEvent(EnEvent enEvent) {
// Do nothing
}
}
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java b/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java
index e794a7d04..fdc698145 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. 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,15 +21,17 @@
package org.onap.policy.apex.core.engine.engine.impl;
+import lombok.Getter;
+import lombok.Setter;
import org.onap.policy.apex.core.engine.engine.EnEventListener;
import org.onap.policy.apex.core.engine.event.EnEvent;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
/**
* Dummy engine event listener for unit test.
* Thread.sleep is used to simulate a slow event listener.
- *
*/
+@Setter
+@Getter
public class DummySlowEnEventListener implements EnEventListener {
private long waitTime;
@@ -38,19 +40,11 @@ public class DummySlowEnEventListener implements EnEventListener {
* {@inheritDoc}.
*/
@Override
- public void onEnEvent(EnEvent enEvent) throws ApexException {
+ public void onEnEvent(EnEvent enEvent) {
try {
Thread.sleep(waitTime);
} catch (InterruptedException ie) {
//Do nothing
}
}
-
- public long getWaitTime() {
- return waitTime;
- }
-
- public void setWaitTime(long waitTime) {
- this.waitTime = waitTime;
- }
}
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySmExecutor.java b/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySmExecutor.java
index df4d9279e..719a20e82 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySmExecutor.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySmExecutor.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 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -42,7 +42,7 @@ public class DummySmExecutor extends StateMachineExecutor {
* Constructor.
*
* @param executorFactory the factory for executors
- * @param owner the owner key
+ * @param owner the owner key
*/
public DummySmExecutor(ExecutorFactory executorFactory, AxArtifactKey owner) {
super(executorFactory, owner);
@@ -66,7 +66,7 @@ public class DummySmExecutor extends StateMachineExecutor {
*/
@Override
public Collection<EnEvent> execute(final long executionId, final Properties executionProperties,
- final EnEvent incomingEvent) {
+ final EnEvent incomingEvent) {
return List.of(incomingEvent);
}
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/event/DummyAxKey.java b/core/src/test/java/org/onap/policy/apex/core/engine/event/DummyAxKey.java
index eafa7f419..a806bed37 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/event/DummyAxKey.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/event/DummyAxKey.java
@@ -1,25 +1,27 @@
/*-
* ============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.core.engine.event;
+import java.io.Serial;
import java.util.List;
import org.apache.commons.lang3.NotImplementedException;
import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
@@ -30,6 +32,8 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
* Dummy Key Class.
*/
public class DummyAxKey extends AxKey {
+
+ @Serial
private static final long serialVersionUID = 964899169013353800L;
/**
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java
index 49b4f80d2..18a7070bf 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020-2021 Nordix Foundation
+ * Modifications Copyright (C) 2020-2021, 2024 Nordix Foundation
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,18 +23,18 @@
package org.onap.policy.apex.core.engine.event;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-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.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.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
-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;
@@ -51,12 +51,12 @@ import org.onap.policy.common.parameters.ParameterService;
/**
* Test the engine event class.
*/
-public class EnEventTest {
+class EnEventTest {
/**
* Set up the services.
*/
- @Before
- public void setupServices() {
+ @BeforeEach
+ void setupServices() {
ModelService.registerModel(AxContextSchemas.class, new AxContextSchemas());
ModelService.registerModel(AxEvents.class, new AxEvents());
ParameterService.register(new SchemaParameters());
@@ -65,15 +65,15 @@ public class EnEventTest {
/**
* Tear down the services.
*/
- @After
- public void teardownServices() {
+ @AfterEach
+ void teardownServices() {
ModelService.deregisterModel(AxContextSchema.class);
ModelService.deregisterModel(AxEvents.class);
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
@Test
- public void testEnEvent() {
+ void testEnEvent() {
AxArtifactKey eventKey = new AxArtifactKey("Event:0.0.1");
assertThatThrownBy(() -> new EnEvent(eventKey))
.hasMessage("event definition is null or was not found in model service");
@@ -92,12 +92,12 @@ public class EnEventTest {
event.setExceptionMessage("Something happened");
assertEquals("Something happened", event.getExceptionMessage());
AxConcept[] usedArtifactStackArray =
- { eventKey };
+ {eventKey};
event.setUserArtifactStack(usedArtifactStackArray);
assertEquals(usedArtifactStackArray.length, event.getUserArtifactStack().length);
assertEquals("EnEvent [axEvent=AxEvent:(key=AxArtifactKey:(name=Event,version=0.0.1),nameSpace=a.name.space,"
- + "source=some source,target=some target,parameter={},toscaPolicyState=), "
- + "userArtifactStack=[AxArtifactKey:(name=Event,version=0.0.1)], map={}]", event.toString());
+ + "source=some source,target=some target,parameter={},toscaPolicyState=), "
+ + "userArtifactStack=[AxArtifactKey:(name=Event,version=0.0.1)], map={}]", event.toString());
assertThatThrownBy(() -> event.put(null, null))
.hasMessage("null keys are illegal on method parameter \"key\"");
assertThatThrownBy(() -> event.put("NonField", null))
@@ -105,7 +105,7 @@ public class EnEventTest {
}
@Test
- public void testAxEvent() {
+ void testAxEvent() {
AxArtifactKey eventKey = new AxArtifactKey("Event:0.0.1");
AxEvent axEvent = new AxEvent(eventKey, "a.name.space", "some source", "some target");
ModelService.getModel(AxEvents.class).getEventMap().put(eventKey, axEvent);
@@ -116,7 +116,7 @@ public class EnEventTest {
AxField axField = new AxField(fieldKey, fieldSchemaKey);
AxConcept[] usedArtifactStackArrayMultiple =
- { eventKey, fieldKey, new DummyAxKey() };
+ {eventKey, fieldKey, new DummyAxKey()};
event.setUserArtifactStack(usedArtifactStackArrayMultiple);
AxContextSchema schema = new AxContextSchema(fieldSchemaKey, "Java", "java.lang.Integer");
@@ -131,12 +131,12 @@ public class EnEventTest {
assertThatThrownBy(() -> event.put("MyField", "Hello"))
.hasMessage("Parent:0.0.1:MyParent:MyField: object \"Hello\" of class \"java.lang.String\" "
- + "not compatible with class \"java.lang.Integer\"");
+ + "not compatible with class \"java.lang.Integer\"");
event.put("MyField", 123);
assertEquals(123, event.get("MyField"));
- assertTrue(event.keySet().contains("MyField"));
- assertTrue(event.values().contains(123));
+ assertTrue(event.containsKey("MyField"));
+ assertTrue(event.containsValue(123));
assertEquals("MyField", event.entrySet().iterator().next().getKey());
event.putAll(event);
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/event/EnExceptionTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/event/EnExceptionTest.java
index 5ca49e479..554de6bfd 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/event/EnExceptionTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/event/EnExceptionTest.java
@@ -1,37 +1,38 @@
/*-
* ============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.core.engine.event;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test the event exception class.
*/
-public class EnExceptionTest {
+class EnExceptionTest {
@Test
- public void testEnException() {
+ void testEnException() {
EnException ene = new EnException("Message");
assertEquals("Message", ene.getMessage());
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/event/EnFieldTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/event/EnFieldTest.java
index dbe2fa3c8..d88f79b58 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/event/EnFieldTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/event/EnFieldTest.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.core.engine.event;
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 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;
@@ -42,12 +42,12 @@ import org.onap.policy.common.parameters.ParameterService;
/**
* Test the EnField class.
*/
-public class EnFieldTest {
+class EnFieldTest {
/**
* Set up the services.
*/
- @Before
- public void setupServices() {
+ @BeforeEach
+ void setupServices() {
AxContextSchemas schemas = new AxContextSchemas();
ModelService.registerModel(AxContextSchemas.class, schemas);
ParameterService.register(new SchemaParameters());
@@ -56,14 +56,14 @@ public class EnFieldTest {
/**
* Tear down the services.
*/
- @After
- public void teardownServices() {
+ @AfterEach
+ void teardownServices() {
ModelService.deregisterModel(AxContextSchemas.class);
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
}
@Test
- public void testEnField() {
+ void testEnField() {
AxReferenceKey fieldKey = new AxReferenceKey("Parent", "0.0.1", "MyParent", "MyField");
AxArtifactKey fieldSchemaKey = new AxArtifactKey("FieldSchema:0.0.1");
AxField axField = new AxField(fieldKey, fieldSchemaKey);
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyFailingTaskExecutor.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyFailingTaskExecutor.java
index 4d4fb639f..02fa41bc8 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyFailingTaskExecutor.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyFailingTaskExecutor.java
@@ -5,15 +5,15 @@
* 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=========================================================
*/
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyStateFinalizerExecutor.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyStateFinalizerExecutor.java
index e4e3ddf0d..a7b2a43d4 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyStateFinalizerExecutor.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyStateFinalizerExecutor.java
@@ -25,6 +25,7 @@ package org.onap.policy.apex.core.engine.executor;
import java.util.Map;
import java.util.Properties;
import lombok.NoArgsConstructor;
+import lombok.Setter;
import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
@@ -35,6 +36,7 @@ import org.onap.policy.apex.core.engine.executor.exception.StateMachineException
public class DummyStateFinalizerExecutor extends StateFinalizerExecutor {
private boolean override;
+ @Setter
private boolean returnBad;
public DummyStateFinalizerExecutor(final boolean override) {
@@ -46,7 +48,7 @@ public class DummyStateFinalizerExecutor extends StateFinalizerExecutor {
*/
@Override
public String execute(final long executionId, final Properties executionProperties,
- final Map<String, Object> newIncomingFields) throws StateMachineException, ContextException {
+ final Map<String, Object> newIncomingFields) throws StateMachineException, ContextException {
if (!override) {
super.execute(executionId, executionProperties, newIncomingFields);
@@ -59,7 +61,4 @@ public class DummyStateFinalizerExecutor extends StateFinalizerExecutor {
}
}
- public void setReturnBad(boolean returnBad) {
- this.returnBad = returnBad;
- }
}
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskExecutor.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskExecutor.java
index 8172eefcc..f7306c31e 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskExecutor.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskExecutor.java
@@ -54,8 +54,9 @@ public class DummyTaskExecutor extends TaskExecutor {
* {@inheritDoc}.
*/
@Override
- public Map<String, Map<String, Object>> execute(final long executionId, final Properties executionProperties,
- final Map<String, Object> newIncomingFields) throws StateMachineException, ContextException {
+ public Map<String, Map<String, Object>> execute(final long executionId, final Properties executionProperties,
+ final Map<String, Object> newIncomingFields)
+ throws StateMachineException, ContextException {
if (!override) {
super.execute(executionId, executionProperties, newIncomingFields);
}
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskSelectExecutor.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskSelectExecutor.java
index a5525ac83..bfee99fe1 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskSelectExecutor.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/DummyTaskSelectExecutor.java
@@ -54,7 +54,7 @@ public class DummyTaskSelectExecutor extends TaskSelectExecutor {
*/
@Override
public AxArtifactKey execute(final long executionId, final Properties executionProperties,
- final EnEvent newIncomingEvent) throws StateMachineException, ContextException {
+ final EnEvent newIncomingEvent) throws StateMachineException, ContextException {
if (!override) {
return super.execute(executionId, executionProperties, newIncomingEvent);
}
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateExecutorTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateExecutorTest.java
index fc1b339d2..f448514f1 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateExecutorTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateExecutorTest.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
* ================================================================================
* 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.core.engine.executor;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
-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;
import org.onap.policy.apex.core.engine.ExecutorParameters;
import org.onap.policy.apex.core.engine.context.ApexInternalContext;
import org.onap.policy.apex.core.engine.event.EnEvent;
@@ -39,8 +40,8 @@ import org.onap.policy.apex.model.policymodel.concepts.AxState;
/**
* Test task executor.
*/
-@RunWith(MockitoJUnitRunner.class)
-public class StateExecutorTest {
+@ExtendWith(MockitoExtension.class)
+class StateExecutorTest {
@Mock
private ApexInternalContext internalContextMock;
@@ -56,30 +57,29 @@ public class StateExecutorTest {
/**
* Set up mocking.
*/
- @Before
- public void startMocking() {
-
+ @BeforeEach
+ void startMocking() {
Mockito.doReturn(new AxReferenceKey("Policy:0.0.1:PolName:State0")).when(axStateMock).getKey();
}
@Test
- public void testStateExecutor() {
+ void testStateExecutor() {
StateExecutor executor = new StateExecutor(executorFactoryMock);
executor.setContext(null, axStateMock, internalContextMock);
assertEquals("Policy:0.0.1:PolName:State0", executor.getKey().getId());
- assertEquals(null, executor.getParent());
+ assertNull(executor.getParent());
assertEquals(internalContextMock, executor.getContext());
- assertEquals(null, executor.getNext());
- assertEquals(null, executor.getIncoming());
- assertEquals(null, executor.getOutgoing());
+ assertNull(executor.getNext());
+ assertNull(executor.getIncoming());
+ assertNull(executor.getOutgoing());
assertEquals(axStateMock, executor.getSubject());
executor.setParameters(new ExecutorParameters());
executor.setNext(nextExecutorMock);
assertEquals(nextExecutorMock, executor.getNext());
executor.setNext(null);
- assertEquals(null, executor.getNext());
+ assertNull(executor.getNext());
assertThatThrownBy(() -> executor.executePre(0, null, null))
.hasMessage("execution pre work not implemented on class");
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutorTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutorTest.java
index e140291b4..fff89de0d 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutorTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateFinalizerExecutorTest.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.
* ================================================================================
* 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,17 @@
package org.onap.policy.apex.core.engine.executor;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.Map;
import java.util.Properties;
-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;
import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.core.engine.ExecutorParameters;
import org.onap.policy.apex.core.engine.context.ApexInternalContext;
@@ -44,8 +45,8 @@ import org.onap.policy.apex.model.policymodel.concepts.AxStateFinalizerLogic;
/**
* Test task executor.
*/
-@RunWith(MockitoJUnitRunner.class)
-public class StateFinalizerExecutorTest {
+@ExtendWith(MockitoExtension.class)
+class StateFinalizerExecutorTest {
@Mock
private Executor<?, ?, ?, ?> parentMock;
@@ -64,8 +65,8 @@ public class StateFinalizerExecutorTest {
/**
* Set up mocking.
*/
- @Before
- public void startMocking() {
+ @BeforeEach
+ void startMocking() {
AxState state = new AxState();
state.getStateOutputs().put("ValidOutput", null);
@@ -76,24 +77,24 @@ public class StateFinalizerExecutorTest {
}
@Test
- public void testStateFinalizerExecutor() throws StateMachineException, ContextException {
+ void testStateFinalizerExecutor() throws StateMachineException, ContextException {
DummyStateFinalizerExecutor executor = new DummyStateFinalizerExecutor();
executor.setContext(parentMock, stateFinalizerLogicMock, internalContextMock);
assertEquals("State:0.0.1:StateName:StateSFL", executor.getKey().getId());
- assertEquals(null, executor.getExecutionContext());
+ assertNull(executor.getExecutionContext());
assertEquals(parentMock, executor.getParent());
assertEquals(internalContextMock, executor.getContext());
- assertEquals(null, executor.getNext());
- assertEquals(null, executor.getIncoming());
- assertEquals(null, executor.getOutgoing());
+ assertNull(executor.getNext());
+ assertNull(executor.getIncoming());
+ assertNull(executor.getOutgoing());
assertEquals(stateFinalizerLogicMock, executor.getSubject());
executor.setParameters(new ExecutorParameters());
executor.setNext(nextExecutorMock);
assertEquals(nextExecutorMock, executor.getNext());
executor.setNext(null);
- assertEquals(null, executor.getNext());
+ assertNull(executor.getNext());
assertThatThrownBy(executor::cleanUp)
.hasMessage("cleanUp() not implemented on class");
@@ -130,7 +131,7 @@ public class StateFinalizerExecutorTest {
executor.getExecutionContext().setSelectedStateOutputName("ThisOutputDoesNotExist");
assertThatThrownBy(() -> executor.executePost(true))
.hasMessage("execute-post: state finalizer logic \"null\" selected output state "
- + "\"ThisOutputDoesNotExist\" that does not exsist on state \"NULL:0.0.0:NULL:NULL\"");
+ + "\"ThisOutputDoesNotExist\" that does not exsist on state \"NULL:0.0.0:NULL:NULL\"");
executor.executePre(0, new Properties(), incomingEvent);
executor.getExecutionContext().setSelectedStateOutputName("ValidOutput");
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutorTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutorTest.java
index 14cc89ee8..4af2f3c74 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutorTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/StateMachineExecutorTest.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 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -24,21 +24,21 @@
package org.onap.policy.apex.core.engine.executor;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.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.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+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;
import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.context.parameters.SchemaParameters;
import org.onap.policy.apex.core.engine.ExecutorParameters;
@@ -66,8 +66,8 @@ import org.onap.policy.common.parameters.ParameterService;
/**
* Test task executor.
*/
-@RunWith(MockitoJUnitRunner.class)
-public class StateMachineExecutorTest {
+@ExtendWith(MockitoExtension.class)
+class StateMachineExecutorTest {
@Mock
private ApexInternalContext internalContextMock;
@@ -80,17 +80,15 @@ public class StateMachineExecutorTest {
@Mock
private EnEvent incomingEventMock;
- private AxPolicy axPolicy = new AxPolicy();
-
- private DummyTaskSelectExecutor dummyTsle;
+ private final AxPolicy axPolicy = new AxPolicy();
private DummyStateFinalizerExecutor dummySfle;
/**
* Set up mocking.
*/
- @Before
- public void startMocking() {
+ @BeforeEach
+ void startMocking() {
axPolicy.setKey(new AxArtifactKey("Policy:0.0.1"));
AxReferenceKey state0Key = new AxReferenceKey(axPolicy.getKey(), "state0");
@@ -128,8 +126,8 @@ public class StateMachineExecutorTest {
event0.getParameterMap().put("Event1Field0", event1Field0Definition);
event0.getParameterMap().put("UnusedField", event1Field0Definition);
- Mockito.doReturn(event0Key).when(incomingEventMock).getKey();
- Mockito.doReturn(event0).when(incomingEventMock).getAxEvent();
+ Mockito.lenient().doReturn(event0Key).when(incomingEventMock).getKey();
+ Mockito.lenient().doReturn(event0).when(incomingEventMock).getAxEvent();
state0.setTrigger(event0Key);
state1.setTrigger(event1Key);
@@ -169,26 +167,26 @@ public class StateMachineExecutorTest {
AxStateTaskReference str1 = new AxStateTaskReference(str1Key, AxStateTaskOutputType.LOGIC, sflKey);
state1.getTaskReferences().put(task1Key, str1);
- Mockito.doReturn(new DummyTaskExecutor(true)).when(executorFactoryMock).getTaskExecutor(Mockito.any(),
+ Mockito.lenient().doReturn(new DummyTaskExecutor(true)).when(executorFactoryMock).getTaskExecutor(Mockito.any(),
Mockito.any(), Mockito.any());
- dummyTsle = new DummyTaskSelectExecutor(true);
- Mockito.doReturn(dummyTsle).when(executorFactoryMock).getTaskSelectionExecutor(Mockito.any(),
+ DummyTaskSelectExecutor dummyTsle = new DummyTaskSelectExecutor(true);
+ Mockito.lenient().doReturn(dummyTsle).when(executorFactoryMock).getTaskSelectionExecutor(Mockito.any(),
Mockito.any(), Mockito.any());
dummySfle = new DummyStateFinalizerExecutor(true);
- Mockito.doReturn(dummySfle).when(executorFactoryMock).getStateFinalizerExecutor(Mockito.any(),
+ Mockito.lenient().doReturn(dummySfle).when(executorFactoryMock).getStateFinalizerExecutor(Mockito.any(),
Mockito.any(), Mockito.any());
}
- @After
- public void cleardown() {
+ @AfterEach
+ public void tearDown() {
ParameterService.clear();
ModelService.clear();
}
@Test
- public void testStateMachineExecutor() throws StateMachineException, ContextException {
+ void testStateMachineExecutor() throws StateMachineException, ContextException {
StateMachineExecutor executor =
new StateMachineExecutor(executorFactoryMock, new AxArtifactKey("OwnerKey:0.0.1"));
@@ -290,7 +288,7 @@ public class StateMachineExecutorTest {
}
@Test
- public void testStateOutput() throws StateMachineException {
+ void testStateOutput() throws StateMachineException {
final StateOutput output =
new StateOutput(axPolicy.getStateMap().get("State0").getStateOutputs().get("stateOutput0"));
assertNotNull(output);
@@ -326,7 +324,7 @@ public class StateMachineExecutorTest {
output.setEventFields(incomingFieldDefinitionMap, eventFieldMaps);
StateOutput outputCopy = new StateOutput(axPolicy.getStateMap().get("State0")
- .getStateOutputs().get("stateOutput0"));
+ .getStateOutputs().get("stateOutput0"));
EnEvent incomingEvent = new EnEvent(new AxArtifactKey("Event0:0.0.1"));
outputCopy.copyUnsetFields(incomingEvent);
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java
index 1c4ffe4fc..da64aed49 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskExecutorTest.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 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,9 +23,9 @@
package org.onap.policy.apex.core.engine.executor;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.ArrayList;
import java.util.HashMap;
@@ -34,12 +34,12 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
-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;
import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.core.engine.ExecutorParameters;
import org.onap.policy.apex.core.engine.TaskParameters;
@@ -56,10 +56,10 @@ import org.onap.policy.apex.model.policymodel.concepts.AxTaskLogic;
import org.onap.policy.apex.model.policymodel.concepts.AxTaskParameter;
/**
- * Test task excutor.
+ * Test task executor.
*/
-@RunWith(MockitoJUnitRunner.class)
-public class TaskExecutorTest {
+@ExtendWith(MockitoExtension.class)
+class TaskExecutorTest {
@Mock
private AxTask axTaskMock;
@@ -88,27 +88,25 @@ public class TaskExecutorTest {
@Mock
private AxTaskLogic taskLogicMock;
- private Map<String, AxField> inFieldMap;
private Map<String, AxField> outFieldMap;
private List<TaskParameters> taskParametersFromConfig;
- private Map<String, AxEvent> outEvents = new TreeMap<>();
+ private final Map<String, AxEvent> outEvents = new TreeMap<>();
/**
* Set up mocking.
*/
- @Before
- public void startMocking() {
+ @BeforeEach
+ void startMocking() {
AxArtifactKey task0Key = new AxArtifactKey("Task0:0.0.1");
- Mockito.doReturn(task0Key).when(axTaskMock).getKey();
- Mockito.doReturn(task0Key.getId()).when(axTaskMock).getId();
+ Mockito.lenient().doReturn(task0Key).when(axTaskMock).getKey();
+ Mockito.lenient().doReturn(task0Key.getId()).when(axTaskMock).getId();
- inFieldMap = Map.of("InField0", axInputFieldMock, "InField1", axOptionalInputFieldMock);
outFieldMap = new LinkedHashMap<>();
-
outFieldMap.put("OutField0", axOutputFieldMock);
outFieldMap.put("OutField1", axOptionalOutputFieldMock);
+ Map<String, AxField> inFieldMap = Map.of("InField0", axInputFieldMock, "InField1", axOptionalInputFieldMock);
AxEvent inEvent = new AxEvent();
inEvent.setParameterMap(inFieldMap);
AxEvent outEvent = new AxEvent(new AxArtifactKey("outputEvent:1.0.0"));
@@ -116,19 +114,19 @@ public class TaskExecutorTest {
outEvents.put(outEvent.getKey().getName(), outEvent);
AxArtifactKey schemaKey = new AxArtifactKey("Schema:0.0.1");
- Mockito.doReturn(schemaKey).when(axInputFieldMock).getSchema();
- Mockito.doReturn(schemaKey).when(axOptionalInputFieldMock).getSchema();
- Mockito.doReturn(schemaKey).when(axMissingOutputFieldMock).getSchema();
+ Mockito.lenient().doReturn(schemaKey).when(axInputFieldMock).getSchema();
+ Mockito.lenient().doReturn(schemaKey).when(axOptionalInputFieldMock).getSchema();
+ Mockito.lenient().doReturn(schemaKey).when(axMissingOutputFieldMock).getSchema();
- Mockito.doReturn(true).when(axOptionalInputFieldMock).getOptional();
- Mockito.doReturn(false).when(axMissingOutputFieldMock).getOptional();
+ Mockito.lenient().doReturn(true).when(axOptionalInputFieldMock).getOptional();
+ Mockito.lenient().doReturn(false).when(axMissingOutputFieldMock).getOptional();
- Mockito.doReturn(taskLogicMock).when(axTaskMock).getTaskLogic();
+ Mockito.lenient().doReturn(taskLogicMock).when(axTaskMock).getTaskLogic();
- Mockito.doReturn(inEvent).when(axTaskMock).getInputEvent();
- Mockito.doReturn(outEvents).when(axTaskMock).getOutputEvents();
+ Mockito.lenient().doReturn(inEvent).when(axTaskMock).getInputEvent();
+ Mockito.lenient().doReturn(outEvents).when(axTaskMock).getOutputEvents();
- Mockito.doReturn(new AxArtifactKey("Context:0.0.1")).when(internalContextMock).getKey();
+ Mockito.lenient().doReturn(new AxArtifactKey("Context:0.0.1")).when(internalContextMock).getKey();
Map<String, AxTaskParameter> taskParameters = new HashMap<>();
taskParameters.put("parameterKey2", new AxTaskParameter(new AxReferenceKey(), "parameterOriginalValue2"));
@@ -141,29 +139,29 @@ public class TaskExecutorTest {
}
@Test
- public void testTaskExecutor() throws StateMachineException, ContextException {
+ void testTaskExecutor() throws StateMachineException, ContextException {
final DummyTaskExecutor executor = new DummyTaskExecutor();
executor.setContext(null, axTaskMock, internalContextMock);
assertEquals("Task0:0.0.1", executor.getKey().getId());
- assertEquals(null, executor.getExecutionContext());
- assertEquals(null, executor.getParent());
+ assertNull(executor.getExecutionContext());
+ assertNull(executor.getParent());
assertEquals(internalContextMock, executor.getContext());
- assertEquals(null, executor.getNext());
- assertEquals(null, executor.getIncoming());
- assertEquals(null, executor.getOutgoing());
+ assertNull(executor.getNext());
+ assertNull(executor.getIncoming());
+ assertNull(executor.getOutgoing());
assertNotNull(executor.getSubject());
executor.setParameters(new ExecutorParameters());
executor.setNext(nextExecutorMock);
assertEquals(nextExecutorMock, executor.getNext());
executor.setNext(null);
- assertEquals(null, executor.getNext());
+ assertNull(executor.getNext());
- assertThatThrownBy(() -> executor.cleanUp()).hasMessageContaining("cleanUp() not implemented on class");
+ assertThatThrownBy(executor::cleanUp).hasMessageContaining("cleanUp() not implemented on class");
Mockito.doReturn(null).when(taskLogicMock).getLogic();
- assertThatThrownBy(() -> executor.prepare()).hasMessageContaining("task logic cannot be null.");
+ assertThatThrownBy(executor::prepare).hasMessageContaining("task logic cannot be null.");
Mockito.doReturn("some task logic").when(taskLogicMock).getLogic();
@@ -220,19 +218,19 @@ public class TaskExecutorTest {
}
@Test
- public void testTaskExecutorForTaskParameters() {
- DummyTaskExecutor executorForParmeterTest = new DummyTaskExecutor(false);
+ void testTaskExecutorForTaskParameters() {
+ DummyTaskExecutor executorForParameterTest = new DummyTaskExecutor(false);
- executorForParmeterTest.setContext(null, axTaskMock, internalContextMock);
- executorForParmeterTest.updateTaskParameters(taskParametersFromConfig);
- assertNotNull(executorForParmeterTest.getSubject().getTaskParameters());
+ executorForParameterTest.setContext(null, axTaskMock, internalContextMock);
+ executorForParameterTest.updateTaskParameters(taskParametersFromConfig);
+ assertNotNull(executorForParameterTest.getSubject().getTaskParameters());
// taskId matched, parameter value updated with the new value
assertEquals("parameterNewValue0",
- executorForParmeterTest.getSubject().getTaskParameters().get("parameterKey0").getTaskParameterValue());
+ executorForParameterTest.getSubject().getTaskParameters().get("parameterKey0").getTaskParameterValue());
// taskId mismatch, so the parameter is not updated in the task
- assertNull(executorForParmeterTest.getSubject().getTaskParameters().get("parameterKey1"));
+ assertNull(executorForParameterTest.getSubject().getTaskParameters().get("parameterKey1"));
// taskId is not available, so parameter is updated in the task
assertEquals("parameterNewValue2",
- executorForParmeterTest.getSubject().getTaskParameters().get("parameterKey2").getTaskParameterValue());
+ executorForParameterTest.getSubject().getTaskParameters().get("parameterKey2").getTaskParameterValue());
}
}
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java
index cf3c59fa9..6f0d74e66 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/TaskSelectExecutorTest.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.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,17 +22,18 @@
package org.onap.policy.apex.core.engine.executor;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
-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;
import org.onap.policy.apex.core.engine.ExecutorParameters;
import org.onap.policy.apex.core.engine.context.ApexInternalContext;
import org.onap.policy.apex.core.engine.event.EnEvent;
@@ -46,8 +47,8 @@ import org.onap.policy.apex.model.policymodel.concepts.AxTaskSelectionLogic;
/**
* Test task executor.
*/
-@RunWith(MockitoJUnitRunner.class)
-public class TaskSelectExecutorTest {
+@ExtendWith(MockitoExtension.class)
+class TaskSelectExecutorTest {
@Mock
private AxState axStateMock;
@@ -66,8 +67,8 @@ public class TaskSelectExecutorTest {
/**
* Set up mocking.
*/
- @Before
- public void startMocking() {
+ @BeforeEach
+ void startMocking() {
AxReferenceKey state0Key = new AxReferenceKey("State0Parent:0.0.1:Parent:State0");
Mockito.doReturn(state0Key).when(axStateMock).getKey();
@@ -82,24 +83,24 @@ public class TaskSelectExecutorTest {
}
@Test
- public void testTaskSelectionExecutor() throws StateMachineException {
+ void testTaskSelectionExecutor() throws StateMachineException {
DummyTaskSelectExecutor executor = new DummyTaskSelectExecutor();
executor.setContext(null, axStateMock, internalContextMock);
assertEquals("State0Parent:0.0.1:Parent:State0", executor.getKey().getId());
- assertEquals(null, executor.getExecutionContext());
- assertEquals(null, executor.getParent());
+ assertNull(executor.getExecutionContext());
+ assertNull(executor.getParent());
assertEquals(internalContextMock, executor.getContext());
- assertEquals(null, executor.getNext());
- assertEquals(null, executor.getIncoming());
- assertEquals(null, executor.getOutgoing());
+ assertNull(executor.getNext());
+ assertNull(executor.getIncoming());
+ assertNull(executor.getOutgoing());
assertEquals(axStateMock, executor.getSubject());
executor.setParameters(new ExecutorParameters());
executor.setNext(nextExecutorMock);
assertEquals(nextExecutorMock, executor.getNext());
executor.setNext(null);
- assertEquals(null, executor.getNext());
+ assertNull(executor.getNext());
assertThatThrownBy(executor::cleanUp)
.hasMessage("cleanUp() not implemented on class");
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacadeTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacadeTest.java
index 54013e943..6744534d7 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacadeTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxStateFacadeTest.java
@@ -1,37 +1,37 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* 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.core.engine.executor.context;
-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 java.util.LinkedHashMap;
import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.Mockito;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
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.service.ModelService;
@@ -42,8 +42,8 @@ import org.onap.policy.apex.model.policymodel.concepts.AxTasks;
/**
* Test the state facade.
*/
-@RunWith(MockitoJUnitRunner.class)
-public class AxStateFacadeTest {
+@ExtendWith(MockitoExtension.class)
+class AxStateFacadeTest {
@Mock
private AxState axStateMock;
@@ -53,32 +53,33 @@ public class AxStateFacadeTest {
/**
* Set up mocking.
*/
- @Before
- public void startMocking() {
+ @BeforeEach
+ void startMocking() {
AxReferenceKey stateKey = new AxReferenceKey("StateParent:0.0.1:ParentName:StateName");
Mockito.doReturn(stateKey).when(axStateMock).getKey();
AxArtifactKey task0Key = new AxArtifactKey("Task0:0.0.1");
Mockito.doReturn(task0Key).when(axStateMock).getDefaultTask();
-
- Map<AxArtifactKey, Object> taskReferences = new LinkedHashMap<>();;
+
+ Map<AxArtifactKey, Object> taskReferences = new LinkedHashMap<>();
+ ;
taskReferences.put(task0Key, null);
Mockito.doReturn(taskReferences).when(axStateMock).getTaskReferences();
AxTasks tasks = new AxTasks();
tasks.getTaskMap().put(task0Key, axTaskMock);
-
+
ModelService.registerModel(AxTasks.class, tasks);
Mockito.doReturn(task0Key).when(axTaskMock).getKey();
}
@Test
- public void testAxStateFacade() {
+ void testAxStateFacade() {
AxStateFacade stateFacade = new AxStateFacade(axStateMock);
-
+
assertEquals("StateName", stateFacade.getStateName());
assertEquals("StateParent:0.0.1:ParentName:StateName", stateFacade.getId());
-
+
assertEquals("Task0", stateFacade.getDefaultTaskKey().getName());
assertNull(stateFacade.getTaskKey(null));
assertEquals("Task0", stateFacade.getTaskKey("Task0").getName());
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacadeTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacadeTest.java
index 634b3b35c..8d17d9f87 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacadeTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/AxTaskFacadeTest.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 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,18 +23,18 @@
package org.onap.policy.apex.core.engine.executor.context;
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.Map;
import java.util.TreeMap;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+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;
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;
@@ -52,8 +52,8 @@ import org.onap.policy.common.parameters.ParameterService;
/**
* Test the state facade.
*/
-@RunWith(MockitoJUnitRunner.class)
-public class AxTaskFacadeTest {
+@ExtendWith(MockitoExtension.class)
+class AxTaskFacadeTest {
@Mock
private AxTask axTaskMock;
@@ -72,8 +72,8 @@ public class AxTaskFacadeTest {
/**
* Set up mocking.
*/
- @Before
- public void startMocking() {
+ @BeforeEach
+ void startMocking() {
AxContextSchemas schemas = new AxContextSchemas();
AxArtifactKey stringTypeKey = new AxArtifactKey("StringType:0.0.1");
@@ -108,14 +108,14 @@ public class AxTaskFacadeTest {
ParameterService.register(new SchemaParameters());
}
- @After
- public void teardown() {
+ @AfterEach
+ void teardown() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
ModelService.clear();
}
@Test
- public void testAxStateFacade() {
+ void testAxStateFacade() {
AxTaskFacade taskFacade = new AxTaskFacade(axTaskMock);
assertEquals("Task0", taskFacade.getTaskName());
@@ -123,18 +123,18 @@ public class AxTaskFacadeTest {
assertThatThrownBy(() -> taskFacade.getInFieldSchemaHelper("InFieldDoesntExist"))
.hasMessage("no incoming field with name \"InFieldDoesntExist\" " + "defined on task "
- + "\"Task0:0.0.1\"");
+ + "\"Task0:0.0.1\"");
assertThatThrownBy(() -> taskFacade.getOutFieldSchemaHelper("OutFieldDoesntExist"))
.hasMessage("no outgoing field with name \"OutFieldDoesntExist\" " + "defined on task "
- + "\"Task0:0.0.1\"");
+ + "\"Task0:0.0.1\"");
assertNotNull(taskFacade.getInFieldSchemaHelper("InField0"));
assertNotNull(taskFacade.getOutFieldSchemaHelper("OutField0"));
assertThatThrownBy(() -> taskFacade.getInFieldSchemaHelper("InFieldBad"))
.hasMessage("schema helper cannot be created for task field \"InFieldBad\" "
- + "with key \"null\" with schema \"null\"");
+ + "with key \"null\" with schema \"null\"");
assertThatThrownBy(() -> taskFacade.getOutFieldSchemaHelper("OutFieldBad"))
.hasMessage("schema helper cannot be created for task field \"OutFieldBad\" "
- + "with key \"null\" with schema \"null\"");
+ + "with key \"null\" with schema \"null\"");
}
}
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/DummyContextAlbum.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/DummyContextAlbum.java
index efb53a682..2570dde1d 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/DummyContextAlbum.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/DummyContextAlbum.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 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.
@@ -27,7 +28,6 @@ import java.util.Set;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.NotImplementedException;
import org.onap.policy.apex.context.ContextAlbum;
-import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.context.SchemaHelper;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
@@ -172,7 +172,7 @@ public class DummyContextAlbum implements ContextAlbum {
* {@inheritDoc}.
*/
@Override
- public void lockForReading(String key) throws ContextException {
+ public void lockForReading(String key) {
throw new NotImplementedException("Not implemented on dummy class");
}
@@ -180,7 +180,7 @@ public class DummyContextAlbum implements ContextAlbum {
* {@inheritDoc}.
*/
@Override
- public void lockForWriting(String key) throws ContextException {
+ public void lockForWriting(String key) {
throw new NotImplementedException("Not implemented on dummy class");
}
@@ -188,7 +188,7 @@ public class DummyContextAlbum implements ContextAlbum {
* {@inheritDoc}.
*/
@Override
- public void unlockForReading(String key) throws ContextException {
+ public void unlockForReading(String key) {
throw new NotImplementedException("Not implemented on dummy class");
}
@@ -196,7 +196,7 @@ public class DummyContextAlbum implements ContextAlbum {
* {@inheritDoc}.
*/
@Override
- public void unlockForWriting(String key) throws ContextException {
+ public void unlockForWriting(String key) {
throw new NotImplementedException("Not implemented on dummy class");
}
@@ -220,7 +220,7 @@ public class DummyContextAlbum implements ContextAlbum {
* {@inheritDoc}.
*/
@Override
- public void flush() throws ContextException {
+ public void flush() {
throw new NotImplementedException("Not implemented on dummy class");
}
}
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContextTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContextTest.java
index 9c6aa2f07..8c008ba2d 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContextTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/StateFinalizerExecutionContextTest.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
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,19 +22,19 @@
package org.onap.policy.apex.core.engine.executor.context;
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.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
-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;
import org.onap.policy.apex.context.ContextAlbum;
import org.onap.policy.apex.core.engine.context.ApexInternalContext;
import org.onap.policy.apex.core.engine.executor.StateFinalizerExecutor;
@@ -45,8 +45,8 @@ import org.onap.policy.apex.model.policymodel.concepts.AxState;
/**
* Test Task Execution Context.
*/
-@RunWith(MockitoJUnitRunner.class)
-public class StateFinalizerExecutionContextTest {
+@ExtendWith(MockitoExtension.class)
+class StateFinalizerExecutionContextTest {
@Mock
private StateFinalizerExecutor stateFinalizerExecutorMock;
@@ -62,8 +62,8 @@ public class StateFinalizerExecutionContextTest {
/**
* Set up mocking.
*/
- @Before
- public void startMocking() {
+ @BeforeEach
+ void startMocking() {
Set<AxArtifactKey> contextAlbumReferences = new LinkedHashSet<>();
contextAlbumReferences.add(new AxArtifactKey(("AlbumKey0:0.0.1")));
@@ -86,12 +86,12 @@ public class StateFinalizerExecutionContextTest {
}
@Test
- public void test() {
+ void test() {
final Map<String, Object> fields = new LinkedHashMap<>();
final Set<String> stateOutputNames = new LinkedHashSet<>();
StateFinalizerExecutionContext sfec = new StateFinalizerExecutionContext(stateFinalizerExecutorMock, 0, null,
- axStateMock, fields, stateOutputNames, internalContextMock);
+ axStateMock, fields, stateOutputNames, internalContextMock);
assertNotNull(sfec);
sfec.setMessage("SFEC Message");
@@ -103,8 +103,8 @@ public class StateFinalizerExecutionContextTest {
ContextAlbum contextAlbum = sfec.getContextAlbum("AlbumKey0");
assertEquals("AlbumKey0:0.0.1", contextAlbum.getKey().getId());
- assertThatThrownBy(() -> sfec.getContextAlbum("AlbumKeyNonExistant"))
- .hasMessage("cannot find definition of context album \"AlbumKeyNonExistant\" "
- + "on state \"Parent:0.0.1:ParentName:StateName\"");
+ assertThatThrownBy(() -> sfec.getContextAlbum("AlbumKeyNonExistent"))
+ .hasMessage("cannot find definition of context album \"AlbumKeyNonExistent\" "
+ + "on state \"Parent:0.0.1:ParentName:StateName\"");
}
}
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContextTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContextTest.java
index 7f813cc01..3b76249b7 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContextTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskExecutionContextTest.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 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,8 +23,8 @@
package org.onap.policy.apex.core.engine.executor.context;
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;
@@ -33,12 +33,12 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
-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;
import org.onap.policy.apex.context.ContextAlbum;
import org.onap.policy.apex.core.engine.context.ApexInternalContext;
import org.onap.policy.apex.core.engine.executor.TaskExecutor;
@@ -50,8 +50,8 @@ import org.onap.policy.apex.model.policymodel.concepts.AxTaskParameter;
/**
* Test Task Execution Context.
*/
-@RunWith(MockitoJUnitRunner.class)
-public class TaskExecutionContextTest {
+@ExtendWith(MockitoExtension.class)
+class TaskExecutionContextTest {
@Mock
private TaskExecutor taskExecutorMock;
@@ -67,8 +67,8 @@ public class TaskExecutionContextTest {
/**
* Set up mocking.
*/
- @Before
- public void startMocking() {
+ @BeforeEach
+ void startMocking() {
Set<AxArtifactKey> contextAlbumReferences = new LinkedHashSet<>();
contextAlbumReferences.add(new AxArtifactKey(("AlbumKey0:0.0.1")));
@@ -95,7 +95,7 @@ public class TaskExecutionContextTest {
}
@Test
- public void test() {
+ void test() {
final Map<String, Object> inFields = new LinkedHashMap<>();
final List<Map<String, Object>> outFieldsList = new LinkedList<>();
@@ -113,7 +113,7 @@ public class TaskExecutionContextTest {
assertEquals("parameterValue1", parameters.get("parameterKey1"));
assertEquals("parameterValue2", parameters.get("parameterKey2"));
- assertThatThrownBy(() -> tec.getContextAlbum("AlbumKeyNonExistant"))
- .hasMessageContaining("cannot find definition of context album \"AlbumKeyNonExistant\" on task \"null\"");
+ assertThatThrownBy(() -> tec.getContextAlbum("AlbumKeyNonExistent"))
+ .hasMessageContaining("cannot find definition of context album \"AlbumKeyNonExistent\" on task \"null\"");
}
}
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContextTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContextTest.java
index 84f4817e0..b21dae10b 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContextTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/context/TaskSelectionExecutionContextTest.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
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,19 +22,19 @@
package org.onap.policy.apex.core.engine.executor.context;
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.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
-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;
import org.onap.policy.apex.context.ContextAlbum;
import org.onap.policy.apex.core.engine.context.ApexInternalContext;
import org.onap.policy.apex.core.engine.event.EnEvent;
@@ -46,8 +46,8 @@ import org.onap.policy.apex.model.policymodel.concepts.AxState;
/**
* Test Task Execution Context.
*/
-@RunWith(MockitoJUnitRunner.class)
-public class TaskSelectionExecutionContextTest {
+@ExtendWith(MockitoExtension.class)
+class TaskSelectionExecutionContextTest {
@Mock
private TaskSelectExecutor taskSelectExecutorMock;
@@ -66,8 +66,8 @@ public class TaskSelectionExecutionContextTest {
/**
* Set up mocking.
*/
- @Before
- public void startMocking() {
+ @BeforeEach
+ void startMocking() {
Set<AxArtifactKey> contextAlbumReferences = new LinkedHashSet<>();
contextAlbumReferences.add(new AxArtifactKey(("AlbumKey0:0.0.1")));
@@ -90,11 +90,11 @@ public class TaskSelectionExecutionContextTest {
}
@Test
- public void test() {
+ void test() {
final AxArtifactKey outgoingEventKey = new AxArtifactKey("OutEvent:0.0.1");
TaskSelectionExecutionContext tsec = new TaskSelectionExecutionContext(taskSelectExecutorMock, 0, axStateMock,
- incomingEventMock, outgoingEventKey, internalContextMock);
+ incomingEventMock, outgoingEventKey, internalContextMock);
assertNotNull(tsec);
tsec.setMessage("TSEC Message");
@@ -103,8 +103,8 @@ public class TaskSelectionExecutionContextTest {
ContextAlbum contextAlbum = tsec.getContextAlbum("AlbumKey0");
assertEquals("AlbumKey0:0.0.1", contextAlbum.getKey().getId());
- assertThatThrownBy(() -> tsec.getContextAlbum("AlbumKeyNonExistant"))
- .hasMessage("cannot find definition of context album \"AlbumKeyNonExistant\" "
- + "on state \"Parent:0.0.1:ParentName:StateName\"");
+ assertThatThrownBy(() -> tsec.getContextAlbum("AlbumKeyNonExistent"))
+ .hasMessage("cannot find definition of context album \"AlbumKeyNonExistent\" "
+ + "on state \"Parent:0.0.1:ParentName:StateName\"");
}
}
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/exception/StateMachineRuntimeExceptionTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/exception/StateMachineRuntimeExceptionTest.java
index 84f330308..35687c18d 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/exception/StateMachineRuntimeExceptionTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/exception/StateMachineRuntimeExceptionTest.java
@@ -1,41 +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.core.engine.executor.exception;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Test state machine runtime exception.
- *
*/
-public class StateMachineRuntimeExceptionTest {
+class StateMachineRuntimeExceptionTest {
@Test
- public void testException() {
+ void testException() {
StateMachineRuntimeException smre = new StateMachineRuntimeException("Exception Message");
assertEquals("Exception Message", smre.getMessage());
-
+
smre = new StateMachineRuntimeException("Exception Message", new IOException());
assertEquals("Exception Message", smre.getMessage());
}
diff --git a/core/src/test/java/org/onap/policy/apex/core/engine/executor/impl/ExceutorFactoryImplTest.java b/core/src/test/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImplTest.java
index c8aa7eb08..f7020dd21 100644
--- a/core/src/test/java/org/onap/policy/apex/core/engine/executor/impl/ExceutorFactoryImplTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/engine/executor/impl/ExecutorFactoryImplTest.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.
* ================================================================================
* 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,16 @@
package org.onap.policy.apex.core.engine.executor.impl;
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 org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.AfterEach;
+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;
import org.onap.policy.apex.core.engine.EngineParameters;
import org.onap.policy.apex.core.engine.ExecutorParameters;
import org.onap.policy.apex.core.engine.context.ApexInternalContext;
@@ -46,10 +46,9 @@ import org.onap.policy.common.parameters.ParameterService;
/**
* Test the executor factory implementation.
- *
*/
-@RunWith(MockitoJUnitRunner.class)
-public class ExceutorFactoryImplTest {
+@ExtendWith(MockitoExtension.class)
+class ExecutorFactoryImplTest {
@Mock
private ApexInternalContext internalContextMock;
@@ -76,28 +75,28 @@ public class ExceutorFactoryImplTest {
/**
* Set up mocking.
*/
- @Before
- public void startMocking() {
+ @BeforeEach
+ void startMocking() {
- Mockito.doReturn(tslMock).when(stateMock).getTaskSelectionLogic();
- Mockito.doReturn("Dummy").when(tslMock).getLogicFlavour();
+ Mockito.lenient().doReturn(tslMock).when(stateMock).getTaskSelectionLogic();
+ Mockito.lenient().doReturn("Dummy").when(tslMock).getLogicFlavour();
- Mockito.doReturn(tlMock).when(taskMock).getTaskLogic();
- Mockito.doReturn("Dummy").when(tlMock).getLogicFlavour();
+ Mockito.lenient().doReturn(tlMock).when(taskMock).getTaskLogic();
+ Mockito.lenient().doReturn("Dummy").when(tlMock).getLogicFlavour();
- Mockito.doReturn("Dummy").when(sflMock).getLogicFlavour();
+ Mockito.lenient().doReturn("Dummy").when(sflMock).getLogicFlavour();
}
- @After
- public void clearPars() {
+ @AfterEach
+ void clearPars() {
ParameterService.clear();
}
@Test
- public void testExecutorFactoryImplGood() throws StateMachineException {
+ void testExecutorFactoryImplGood() throws StateMachineException {
setGoodPars();
- ExecutorFactoryImpl factory = null;
+ ExecutorFactoryImpl factory;
factory = new ExecutorFactoryImpl();
@@ -112,52 +111,52 @@ public class ExceutorFactoryImplTest {
}
@Test
- public void testExecutorFactoryImplNonExistant() {
- setNonExistantPars();
+ void testExecutorFactoryImplNonExistent() {
+ setNonExistentPars();
- assertThatThrownBy(() -> new ExecutorFactoryImpl())
+ assertThatThrownBy(ExecutorFactoryImpl::new)
.hasMessage("Apex executor class not found for executor plugin "
- + "\"org.onap.policy.apex.core.engine.executor.BadTaskExecutor\"");
+ + "\"org.onap.policy.apex.core.engine.executor.BadTaskExecutor\"");
executorPars.setTaskExecutorPluginClass(null);
- assertThatThrownBy(() -> new ExecutorFactoryImpl())
+ assertThatThrownBy(ExecutorFactoryImpl::new)
.hasMessage("Apex executor class not found for executor plugin "
- + "\"org.onap.policy.apex.core.engine.executor.BadTaskSelectExecutor\"");
+ + "\"org.onap.policy.apex.core.engine.executor.BadTaskSelectExecutor\"");
executorPars.setTaskExecutorPluginClass("org.onap.policy.apex.core.engine.executor.DummyTaskExecutor");
- assertThatThrownBy(() -> new ExecutorFactoryImpl())
+ assertThatThrownBy(ExecutorFactoryImpl::new)
.hasMessage("Apex executor class not found for executor plugin "
- + "\"org.onap.policy.apex.core.engine.executor.BadTaskSelectExecutor\"");
+ + "\"org.onap.policy.apex.core.engine.executor.BadTaskSelectExecutor\"");
executorPars.setTaskSelectionExecutorPluginClass(
- "org.onap.policy.apex.core.engine.executor.DummyTaskSelectExecutor");
+ "org.onap.policy.apex.core.engine.executor.DummyTaskSelectExecutor");
- assertThatThrownBy(() -> new ExecutorFactoryImpl())
+ assertThatThrownBy(ExecutorFactoryImpl::new)
.hasMessage("Apex executor class not found for executor plugin "
- + "\"org.onap.policy.apex.core.engine.executor.BadStateFinalizerExecutor\"");
+ + "\"org.onap.policy.apex.core.engine.executor.BadStateFinalizerExecutor\"");
}
@Test
- public void testExecutorFactoryImplBad() {
+ void testExecutorFactoryImplBad() {
setBadPars();
- assertThatThrownBy(() -> new ExecutorFactoryImpl())
+ assertThatThrownBy(ExecutorFactoryImpl::new)
.hasMessage("Specified Apex executor plugin class \"java.lang.String\" "
- + "does not implment the Executor interface");
+ + "does not implement the Executor interface");
executorPars.setTaskExecutorPluginClass("org.onap.policy.apex.core.engine.executor.DummyTaskExecutor");
- assertThatThrownBy(() -> new ExecutorFactoryImpl())
+ assertThatThrownBy(ExecutorFactoryImpl::new)
.hasMessage("Specified Apex executor plugin class \"java.lang.String\" "
- + "does not implment the Executor interface");
+ + "does not implement the Executor interface");
executorPars.setTaskSelectionExecutorPluginClass(
- "org.onap.policy.apex.core.engine.executor.DummyTaskSelectExecutor");
+ "org.onap.policy.apex.core.engine.executor.DummyTaskSelectExecutor");
- assertThatThrownBy(() -> new ExecutorFactoryImpl())
+ assertThatThrownBy(ExecutorFactoryImpl::new)
.hasMessage("Specified Apex executor plugin class \"java.lang.String\" "
- + "does not implment the Executor interface");
+ + "does not implement the Executor interface");
}
@Test
- public void testExecutorFactoryCreateErrors() throws StateMachineException {
+ void testExecutorFactoryCreateErrors() throws StateMachineException {
setGoodPars();
executorPars.setTaskExecutorPluginClass(null);
@@ -166,23 +165,23 @@ public class ExceutorFactoryImplTest {
assertThatThrownBy(() -> factory.getTaskExecutor(null, taskMock, internalContextMock))
.hasMessage("Executor plugin class not defined for \"Dummy\" executor of type "
- + "\"org.onap.policy.apex.core.engine.executor.TaskExecutor\"");
+ + "\"org.onap.policy.apex.core.engine.executor.TaskExecutor\"");
executorPars.setTaskExecutorPluginClass("org.onap.policy.apex.core.engine.executor.DummyFailingTaskExecutor");
ExecutorFactoryImpl factoryInitError = new ExecutorFactoryImpl();
assertThatThrownBy(() -> factoryInitError.getTaskExecutor(null, taskMock, internalContextMock))
.hasMessage("Instantiation error on \"Dummy\" executor of type "
- + "\"org.onap.policy.apex.core.engine.executor.DummyFailingTaskExecutor\"");
+ + "\"org.onap.policy.apex.core.engine.executor.DummyFailingTaskExecutor\"");
executorPars.setTaskExecutorPluginClass(
- "org.onap.policy.apex.core.engine.executor.DummyStateFinalizerExecutor");
+ "org.onap.policy.apex.core.engine.executor.DummyStateFinalizerExecutor");
ExecutorFactoryImpl factoryDummyError = new ExecutorFactoryImpl();
assertThatThrownBy(() -> factoryDummyError.getTaskExecutor(null, taskMock, internalContextMock))
.hasMessage("Executor on \"Dummy\" "
- + "of type \"class org.onap.policy.apex.core.engine.executor.DummyStateFinalizerExecutor\""
- + " is not an instance of \"org.onap.policy.apex.core.engine.executor.TaskExecutor\"");
+ + "of type \"class org.onap.policy.apex.core.engine.executor.DummyStateFinalizerExecutor\""
+ + " is not an instance of \"org.onap.policy.apex.core.engine.executor.TaskExecutor\"");
}
/**
@@ -192,9 +191,9 @@ public class ExceutorFactoryImplTest {
executorPars = new ExecutorParameters();
executorPars.setTaskExecutorPluginClass("org.onap.policy.apex.core.engine.executor.DummyTaskExecutor");
executorPars.setTaskSelectionExecutorPluginClass(
- "org.onap.policy.apex.core.engine.executor.DummyTaskSelectExecutor");
+ "org.onap.policy.apex.core.engine.executor.DummyTaskSelectExecutor");
executorPars.setStateFinalizerExecutorPluginClass(
- "org.onap.policy.apex.core.engine.executor.DummyStateFinalizerExecutor");
+ "org.onap.policy.apex.core.engine.executor.DummyStateFinalizerExecutor");
EngineParameters enginePars = new EngineParameters();
enginePars.getExecutorParameterMap().put("Dummy", executorPars);
@@ -204,15 +203,15 @@ public class ExceutorFactoryImplTest {
}
/**
- * Set up non existant parameters.
+ * Set up non existent parameters.
*/
- private void setNonExistantPars() {
+ private void setNonExistentPars() {
executorPars = new ExecutorParameters();
executorPars.setTaskExecutorPluginClass("org.onap.policy.apex.core.engine.executor.BadTaskExecutor");
executorPars.setTaskSelectionExecutorPluginClass(
- "org.onap.policy.apex.core.engine.executor.BadTaskSelectExecutor");
+ "org.onap.policy.apex.core.engine.executor.BadTaskSelectExecutor");
executorPars.setStateFinalizerExecutorPluginClass(
- "org.onap.policy.apex.core.engine.executor.BadStateFinalizerExecutor");
+ "org.onap.policy.apex.core.engine.executor.BadStateFinalizerExecutor");
EngineParameters enginePars = new EngineParameters();
enginePars.getExecutorParameterMap().put("Dummy", executorPars);
diff --git a/core/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTest.java b/core/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTest.java
index 35ad9386a..356b800a8 100644
--- a/core/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTest.java
+++ b/core/src/test/java/org/onap/policy/apex/core/infrastructure/threading/ThreadingTest.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.core.infrastructure.threading;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
import java.util.List;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -35,7 +35,7 @@ import org.slf4j.ext.XLoggerFactory;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class ThreadingTest {
+class ThreadingTest {
private static final String LOCAL_NAME = "localName";
// Logger for this class
@@ -45,18 +45,18 @@ public class ThreadingTest {
* Test thread factory initialization.
*/
@Test
- public void testThreadFactoryInitialization() {
+ void testThreadFactoryInitialization() {
final ApplicationThreadFactory objUnderTest = new ApplicationThreadFactory(LOCAL_NAME, 0);
- assertNotNull("Failed to create ApplicationThreadFactory threadFactory0", objUnderTest);
+ assertNotNull(objUnderTest, "Failed to create ApplicationThreadFactory threadFactory0");
logger.debug(objUnderTest.toString());
- assertTrue("Failed to name ApplicationThreadFactory threadFactory0",
- objUnderTest.getName().startsWith("Apex-" + LOCAL_NAME));
+ assertTrue(objUnderTest.getName().startsWith("Apex-" + LOCAL_NAME),
+ "Failed to name ApplicationThreadFactory threadFactory0");
final ApplicationThreadFactory objUnderTest1 = new ApplicationThreadFactory(LOCAL_NAME, 0);
- assertNotNull("Failed to create ApplicationThreadFactory threadFactory1", objUnderTest1);
+ assertNotNull(objUnderTest1, "Failed to create ApplicationThreadFactory threadFactory1");
logger.debug(objUnderTest1.toString());
- assertTrue("Failed to name ApplicationThreadFactory threadFactory1",
- objUnderTest1.getName().startsWith("Apex-" + LOCAL_NAME));
+ assertTrue(objUnderTest1.getName().startsWith("Apex-" + LOCAL_NAME),
+ "Failed to name ApplicationThreadFactory threadFactory1");
testThreadFactory(objUnderTest);
testThreadFactory(objUnderTest1);
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/engine/main/ApexMain.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java
index 7b14dc627..721960779 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/main/ApexMain.java
@@ -59,7 +59,7 @@ public class ApexMain {
@Getter
private ApexParameters apexParameters;
- private ApexParameterHandler apexParameterHandler = new ApexParameterHandler();
+ private final ApexParameterHandler apexParameterHandler = new ApexParameterHandler();
@Getter
@Setter(lombok.AccessLevel.PRIVATE)
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImpl.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImpl.java
index dcae42f2f..c0b752fb1 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImpl.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImpl.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. 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");
@@ -82,7 +82,7 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
// The Apex engine workers this engine service is handling
private final Map<AxArtifactKey, EngineWorker> engineWorkerMap = Collections
- .synchronizedMap(new LinkedHashMap<AxArtifactKey, EngineWorker>());
+ .synchronizedMap(new LinkedHashMap<>());
// Event queue for events being sent into the Apex engines, it used by all engines within a
// group.
@@ -99,13 +99,12 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
* This constructor instantiates engine workers and adds them to the set of engine workers to be managed. The
* constructor is private to prevent subclassing.
*
- * @param engineServiceKey the engine service key
- * @param threadCount the thread count, the number of engine workers to start
+ * @param engineServiceKey the engine service key
+ * @param threadCount the thread count, the number of engine workers to start
* @param periodicEventPeriod the period in milliseconds at which periodic events are generated
- * @throws ApexException on worker instantiation errors
*/
private EngineServiceImpl(final AxArtifactKey engineServiceKey, final int threadCount,
- final long periodicEventPeriod) {
+ final long periodicEventPeriod) {
LOGGER.entry(engineServiceKey, threadCount);
this.engineServiceKey = engineServiceKey;
@@ -114,7 +113,7 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
// Start engine workers
for (var engineCounter = 0; engineCounter < threadCount; engineCounter++) {
final var engineWorkerKey = new AxArtifactKey(engineServiceKey.getName() + '-' + engineCounter,
- engineServiceKey.getVersion());
+ engineServiceKey.getVersion());
engineWorkerMap.put(engineWorkerKey, new EngineWorker(engineWorkerKey, queue, atFactory));
LOGGER.info("Created apex engine {} .", engineWorkerKey.getId());
}
@@ -135,14 +134,12 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
*/
public static EngineServiceImpl create(final EngineServiceParameters config) throws ApexException {
if (config == null) {
- LOGGER.warn("Engine service configuration parameters is null");
- throw new ApexException("engine service configuration parameters are null");
+ logWarnAndThrowException("Engine service configuration parameters are null");
}
final ValidationResult validation = config.validate();
if (!validation.isValid()) {
- LOGGER.warn("Invalid engine service configuration parameters: {}" + validation.getResult());
- throw new ApexException("Invalid engine service configuration parameters: " + validation);
+ logWarnAndThrowException("Invalid engine service configuration parameters: " + validation);
}
final AxArtifactKey engineServiceKey = config.getEngineKey();
@@ -226,7 +223,7 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
*/
@Override
public AxArtifactKey getApexModelKey() {
- if (engineWorkerMap.size() == 0) {
+ if (engineWorkerMap.isEmpty()) {
return null;
}
@@ -234,32 +231,29 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
}
/**
- * Method to create model.
- *
- * @param incomingEngineServiceKey incoming engine service key
- * @param apexModelString apex model string
- * @return apexPolicyModel the policy model
- * @throws ApexException apex exception
- */
+ * Method to create model.
+ *
+ * @param incomingEngineServiceKey incoming engine service key
+ * @param apexModelString apex model string
+ * @return apexPolicyModel the policy model
+ * @throws ApexException apex exception
+ */
public static AxPolicyModel createModel(final AxArtifactKey incomingEngineServiceKey, final String apexModelString)
throws ApexException {
// Check if the engine service key specified is sane
if (incomingEngineServiceKey == null) {
- String message = ENGINE_KEY_NOT_SPECIFIED;
- LOGGER.warn(message);
- throw new ApexException(message);
+ throwEngineKeyNotSpecifiedException();
}
// Check if the Apex model specified is sane
- if (apexModelString == null || apexModelString.trim().length() == 0) {
+ if (apexModelString == null || apexModelString.trim().isEmpty()) {
String emptyModelMessage = "model for updating engine service with key "
- + incomingEngineServiceKey.getId() + " is empty";
- LOGGER.warn(emptyModelMessage);
- throw new ApexException(emptyModelMessage);
+ + incomingEngineServiceKey.getId() + " is empty";
+ logWarnAndThrowException(emptyModelMessage);
}
// Read the Apex model into memory using the Apex Model Reader
- AxPolicyModel apexPolicyModel = null;
+ AxPolicyModel apexPolicyModel;
try {
final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
apexPolicyModel = modelReader.read(new ByteArrayInputStream(apexModelString.getBytes()));
@@ -276,7 +270,7 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
*/
@Override
public void updateModel(final AxArtifactKey incomingEngineServiceKey, final String apexModelString,
- final boolean forceFlag) throws ApexException {
+ final boolean forceFlag) throws ApexException {
AxPolicyModel apexPolicyModel = createModel(incomingEngineServiceKey, apexModelString);
// Update the model
@@ -290,30 +284,26 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
*/
@Override
public void updateModel(final AxArtifactKey incomingEngineServiceKey, final AxPolicyModel apexModel,
- final boolean forceFlag) throws ApexException {
+ final boolean forceFlag) throws ApexException {
LOGGER.entry(incomingEngineServiceKey);
// Check if the engine service key specified is sane
if (incomingEngineServiceKey == null) {
- String message = ENGINE_KEY_NOT_SPECIFIED;
- LOGGER.warn(message);
- throw new ApexException(message);
+ throwEngineKeyNotSpecifiedException();
}
// Check if the Apex model specified is sane
if (apexModel == null) {
- LOGGER.warn("model for updating on engine service with key " + incomingEngineServiceKey.getId()
- + " is null");
- throw new ApexException("model for updating on engine service with key " + incomingEngineServiceKey.getId()
- + " is null");
+ String message = "model for updating on engine service with key " + incomingEngineServiceKey.getId()
+ + " is null";
+ logWarnAndThrowException(message);
}
// Check if the key on the update request is correct
if (!this.engineServiceKey.equals(incomingEngineServiceKey)) {
- LOGGER.warn("engine service key " + incomingEngineServiceKey.getId() + " does not match the key"
- + engineServiceKey.getId() + " of this engine service");
- throw new ApexException("engine service key " + incomingEngineServiceKey.getId() + " does not match the key"
- + engineServiceKey.getId() + " of this engine service");
+ String message = "engine service key " + incomingEngineServiceKey.getId() + " does not match the key"
+ + engineServiceKey.getId() + " of this engine service";
+ logWarnAndThrowException(message);
}
// Check model compatibility
@@ -334,12 +324,12 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
* Execute the model update on the engine instances.
*
* @param incomingEngineServiceKey the engine service key to update
- * @param apexModel the model to update the engines with
- * @param forceFlag if true, ignore compatibility problems
+ * @param apexModel the model to update the engines with
+ * @param forceFlag if true, ignore compatibility problems
* @throws ApexException on model update errors
*/
private void executeModelUpdate(final AxArtifactKey incomingEngineServiceKey, final AxPolicyModel apexModel,
- final boolean forceFlag) throws ApexException {
+ final boolean forceFlag) throws ApexException {
if (!isStopped()) {
stopEngines(incomingEngineServiceKey);
@@ -369,32 +359,32 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
final var notRunningEngineIdBuilder = new StringBuilder();
for (final Entry<AxArtifactKey, EngineWorker> engineWorkerEntry : engineWorkerMap.entrySet()) {
if (engineWorkerEntry.getValue().getState() != AxEngineState.READY
- && engineWorkerEntry.getValue().getState() != AxEngineState.EXECUTING) {
+ && engineWorkerEntry.getValue().getState() != AxEngineState.EXECUTING) {
notRunningEngineIdBuilder.append(engineWorkerEntry.getKey().getId());
notRunningEngineIdBuilder.append('(');
notRunningEngineIdBuilder.append(engineWorkerEntry.getValue().getState());
notRunningEngineIdBuilder.append(") ");
}
}
- if (notRunningEngineIdBuilder.length() > 0) {
+ if (!notRunningEngineIdBuilder.isEmpty()) {
final var errorString = "engine start error on model update on engine service with key "
- + incomingEngineServiceKey.getId() + ", engines not running are: "
- + notRunningEngineIdBuilder.toString().trim();
- LOGGER.warn(errorString);
- throw new ApexException(errorString);
+ + incomingEngineServiceKey.getId() + ", engines not running are: "
+ + notRunningEngineIdBuilder.toString().trim();
+ logWarnAndThrowException(errorString);
}
}
/**
* Stop engines for a model update.
+ *
* @param incomingEngineServiceKey the engine service key for the engines that are to be stopped
* @throws ApexException on errors stopping engines
*/
private void stopEngines(final AxArtifactKey incomingEngineServiceKey) throws ApexException {
// Stop all engines on this engine service
stop();
- final long stoptime = System.currentTimeMillis();
- while (!isStopped() && System.currentTimeMillis() - stoptime < MAX_STOP_WAIT_TIME) {
+ final long stopTime = System.currentTimeMillis();
+ while (!isStopped() && System.currentTimeMillis() - stopTime < MAX_STOP_WAIT_TIME) {
ThreadUtilities.sleep(ENGINE_SERVICE_STOP_START_WAIT_INTERVAL);
}
// Check if all engines are stopped
@@ -407,33 +397,33 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
notStoppedEngineIdBuilder.append(") ");
}
}
- if (notStoppedEngineIdBuilder.length() > 0) {
+ if (!notStoppedEngineIdBuilder.isEmpty()) {
final var errorString = "cannot update model on engine service with key "
- + incomingEngineServiceKey.getId() + ", engines not stopped after " + MAX_STOP_WAIT_TIME
- + "ms are: " + notStoppedEngineIdBuilder.toString().trim();
- LOGGER.warn(errorString);
- throw new ApexException(errorString);
+ + incomingEngineServiceKey.getId() + ", engines not stopped after " + MAX_STOP_WAIT_TIME
+ + "ms are: " + notStoppedEngineIdBuilder.toString().trim();
+ logWarnAndThrowException(errorString);
}
}
/**
* Issue compatibility warning or error message.
- * @param apexModel The model name
- * @param forceFlag true if we are forcing the update
+ *
+ * @param apexModel The model name
+ * @param forceFlag true if we are forcing the update
* @param currentModel the existing model that is loaded
* @throws ContextException on compatibility errors
*/
private void handleIncompatibility(final AxPolicyModel apexModel, final boolean forceFlag,
- final AxPolicyModel currentModel) throws ContextException {
+ final AxPolicyModel currentModel) throws ContextException {
if (forceFlag) {
- LOGGER.warn("apex model update forced, supplied model with key \"" + apexModel.getKey().getId()
- + "\" is not a compatible model update from the existing engine model with key \""
- + currentModel.getKey().getId() + "\"");
+ LOGGER.warn("apex model update forced, supplied model with key \"{}\" "
+ + "is not a compatible model update from the existing engine model with key \"{}\"",
+ apexModel.getKey().getId(), currentModel.getKey().getId());
} else {
throw new ContextException("apex model update failed, supplied model with key \""
- + apexModel.getKey().getId()
- + "\" is not a compatible model update from the existing engine model with key \""
- + currentModel.getKey().getId() + "\"");
+ + apexModel.getKey().getId()
+ + "\" is not a compatible model update from the existing engine model with key \""
+ + currentModel.getKey().getId() + "\"");
}
}
@@ -470,16 +460,12 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
LOGGER.entry(engineKey);
if (engineKey == null) {
- String message = ENGINE_KEY_NOT_SPECIFIED;
- LOGGER.warn(message);
- throw new ApexException(message);
+ throwEngineKeyNotSpecifiedException();
}
// Check if we have this key on our map
if (!engineWorkerMap.containsKey(engineKey)) {
- String message = ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX;
- LOGGER.warn(message);
- throw new ApexException(message);
+ throwEngineKeyPreambleNotFoundException(engineKey);
}
// Start the engine
@@ -523,15 +509,12 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
LOGGER.entry(engineKey);
if (engineKey == null) {
- String message = ENGINE_KEY_NOT_SPECIFIED;
- LOGGER.warn(message);
- throw new ApexException(message);
+ throwEngineKeyNotSpecifiedException();
}
// Check if we have this key on our map
if (!engineWorkerMap.containsKey(engineKey)) {
- LOGGER.warn(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
- throw new ApexException(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
+ throwEngineKeyPreambleNotFoundException(engineKey);
}
// Stop the engine
@@ -565,15 +548,12 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
LOGGER.entry(engineKey);
if (engineKey == null) {
- String message = ENGINE_KEY_NOT_SPECIFIED;
- LOGGER.warn(message);
- throw new ApexException(message);
+ throwEngineKeyNotSpecifiedException();
}
// Check if we have this key on our map
if (!engineWorkerMap.containsKey(engineKey)) {
- LOGGER.warn(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
- throw new ApexException(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
+ throwEngineKeyPreambleNotFoundException(engineKey);
}
// Clear the engine
@@ -606,14 +586,13 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
@Override
public boolean isStarted(final AxArtifactKey engineKey) {
if (engineKey == null) {
- String message = ENGINE_KEY_NOT_SPECIFIED;
- LOGGER.warn(message);
+ logWarningEngineKeyNotSpecified();
return false;
}
// Check if we have this key on our map
if (!engineWorkerMap.containsKey(engineKey)) {
- LOGGER.warn(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
+ logWarningEngineKeyPreambleNotFound(engineKey);
return false;
}
return engineWorkerMap.get(engineKey).isStarted();
@@ -641,14 +620,13 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
@Override
public boolean isStopped(final AxArtifactKey engineKey) {
if (engineKey == null) {
- String message = ENGINE_KEY_NOT_SPECIFIED;
- LOGGER.warn(message);
+ logWarningEngineKeyNotSpecified();
return true;
}
// Check if we have this key on our map
if (!engineWorkerMap.containsKey(engineKey)) {
- LOGGER.warn(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
+ logWarningEngineKeyPreambleNotFound(engineKey);
return true;
}
return engineWorkerMap.get(engineKey).isStopped();
@@ -661,13 +639,12 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
public void startPeriodicEvents(final long period) throws ApexException {
// Check if periodic events are already started
if (periodicEventGenerator != null) {
- String message = "Periodic event geneation already running on engine " + engineServiceKey.getId() + ", "
- + periodicEventGenerator.toString();
- LOGGER.warn(message);
- throw new ApexException(message);
+ String message = "Periodic event generation already running on engine " + engineServiceKey.getId() + ", "
+ + periodicEventGenerator.toString();
+ logWarnAndThrowException(message);
}
- // Set up periodic event execution, its a Java Timer/TimerTask
+ // Set up periodic event execution, it's a Java Timer/TimerTask
periodicEventGenerator = new ApexPeriodicEventGenerator(this.getEngineServiceEventInterface(), period);
// Record the periodic event period because it may have been set over the Web Socket admin
@@ -682,8 +659,8 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
public void stopPeriodicEvents() throws ApexException {
// Check if periodic events are already started
if (periodicEventGenerator == null) {
- LOGGER.warn("Periodic event geneation not running on engine " + engineServiceKey.getId());
- throw new ApexException("Periodic event geneation not running on engine " + engineServiceKey.getId());
+ String message = "Periodic event generation not running on engine " + engineServiceKey.getId();
+ logWarnAndThrowException(message);
}
// Stop periodic events
@@ -698,15 +675,12 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
@Override
public String getStatus(final AxArtifactKey engineKey) throws ApexException {
if (engineKey == null) {
- String message = ENGINE_KEY_NOT_SPECIFIED;
- LOGGER.warn(message);
- throw new ApexException(message);
+ throwEngineKeyNotSpecifiedException();
}
// Check if we have this key on our map
if (!engineWorkerMap.containsKey(engineKey)) {
- LOGGER.warn(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
- throw new ApexException(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
+ throwEngineKeyPreambleNotFoundException(engineKey);
}
// Return the information for this worker
return engineWorkerMap.get(engineKey).getStatus(engineKey);
@@ -714,7 +688,6 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
/**
* {@inheritDoc}.
- *
*/
@Override
public List<AxEngineModel> getEngineStats() {
@@ -731,15 +704,12 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
@Override
public String getRuntimeInfo(final AxArtifactKey engineKey) throws ApexException {
if (engineKey == null) {
- String message = ENGINE_KEY_NOT_SPECIFIED;
- LOGGER.warn(message);
- throw new ApexException(message);
+ throwEngineKeyNotSpecifiedException();
}
// Check if we have this key on our map
if (!engineWorkerMap.containsKey(engineKey)) {
- LOGGER.warn(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
- throw new ApexException(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
+ throwEngineKeyPreambleNotFoundException(engineKey);
}
// Return the information for this worker
@@ -752,14 +722,14 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
@Override
public void sendEvent(final ApexEvent event) {
if (event == null) {
- LOGGER.warn("Null events cannot be processed, in engine service " + engineServiceKey.getId());
+ LOGGER.warn("Null events cannot be processed, in engine service {}", engineServiceKey.getId());
return;
}
// Check if we have this key on our map
if (getState() == AxEngineState.STOPPED) {
- LOGGER.warn("event " + event.getName() + " not processed, no engines on engine service "
- + engineServiceKey.getId() + " are running");
+ LOGGER.warn("event {} not processed, no engines on engine service {} are running", event.getName(),
+ engineServiceKey.getId());
return;
}
@@ -770,4 +740,27 @@ public final class EngineServiceImpl implements EngineService, EngineServiceEven
// Add the incoming event to the queue, the next available worker will process it
queue.add(event);
}
+
+ private static void logWarningEngineKeyNotSpecified() {
+ LOGGER.warn(ENGINE_KEY_NOT_SPECIFIED);
+ }
+
+ private static void throwEngineKeyNotSpecifiedException() throws ApexException {
+ logWarningEngineKeyNotSpecified();
+ throw new ApexException(ENGINE_KEY_NOT_SPECIFIED);
+ }
+
+ private static void throwEngineKeyPreambleNotFoundException(AxArtifactKey engineKey) throws ApexException {
+ logWarningEngineKeyPreambleNotFound(engineKey);
+ throw new ApexException(ENGINE_KEY_PREAMBLE + engineKey.getId() + NOT_FOUND_SUFFIX);
+ }
+
+ private static void logWarningEngineKeyPreambleNotFound(AxArtifactKey engineKey) {
+ LOGGER.warn(ENGINE_KEY_PREAMBLE + "{}" + NOT_FOUND_SUFFIX, engineKey.getId());
+ }
+
+ private static void logWarnAndThrowException(String message) throws ApexException {
+ LOGGER.warn(message);
+ throw new ApexException(message);
+ }
}
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/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexEventTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexEventTest.java
index 0f17bf193..ae6aac660 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexEventTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexEventTest.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021. Nordix Foundation.
+ * Copyright (C) 2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,10 +28,10 @@ import java.util.Properties;
import java.util.Random;
import org.apache.commons.lang3.RandomStringUtils;
import org.assertj.core.api.Assertions;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
-public class ApexEventTest {
+class ApexEventTest {
private final Random random = new Random();
private ApexEvent apexEvent;
@@ -40,63 +40,63 @@ public class ApexEventTest {
*
* @throws Exception when object is created
*/
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
apexEvent =
new ApexEvent("name", "version", "namespace", "source", "target", "");
}
@Test
- public void invalidEventName() {
+ void invalidEventName() {
final String name = "++" + RandomStringUtils.randomAlphabetic(5);
Assertions.assertThatCode(() ->
- apexEvent = new ApexEvent(name, "version", "namespace", "source", "target", ""))
+ apexEvent = new ApexEvent(name, "version", "namespace", "source", "target", ""))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void invalidEventVersion() {
+ void invalidEventVersion() {
final String version = "++" + RandomStringUtils.randomAlphabetic(5);
Assertions.assertThatCode(() ->
- apexEvent = new ApexEvent("name", version, "namespace", "source", "target", ""))
+ apexEvent = new ApexEvent("name", version, "namespace", "source", "target", ""))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void invalidEventNamespace() {
+ void invalidEventNamespace() {
final String namespace = "++" + RandomStringUtils.randomAlphabetic(5);
Assertions.assertThatCode(() ->
- apexEvent = new ApexEvent("name", "version", namespace, "source", "target", ""))
+ apexEvent = new ApexEvent("name", "version", namespace, "source", "target", ""))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void invalidEventSource() {
+ void invalidEventSource() {
final String source = "++" + RandomStringUtils.randomAlphabetic(5);
Assertions.assertThatCode(() ->
- apexEvent = new ApexEvent("name", "version", "namespace", source, "target", ""))
+ apexEvent = new ApexEvent("name", "version", "namespace", source, "target", ""))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void invalidEventTarget() {
+ void invalidEventTarget() {
final String target = "++" + RandomStringUtils.randomAlphabetic(5);
Assertions.assertThatCode(() ->
- apexEvent = new ApexEvent("name", "version", "namespace", "source", target, ""))
+ apexEvent = new ApexEvent("name", "version", "namespace", "source", target, ""))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void invalidEventStatus() {
+ void invalidEventStatus() {
final String toscaPolicyState = "INVALID_STATUS";
Assertions.assertThatCode(() ->
- apexEvent = new ApexEvent("name", "version", "namespace", "source", "target", toscaPolicyState))
- .isInstanceOf(ApexEventException.class);
+ apexEvent = new ApexEvent("name", "version", "namespace", "source", "target", toscaPolicyState))
+ .isInstanceOf(ApexEventException.class);
}
@Test
- public void setExecutionId() {
+ void setExecutionId() {
final int executionId = random.nextInt();
apexEvent.setExecutionId(executionId);
final long actual = apexEvent.getExecutionId();
@@ -104,7 +104,7 @@ public class ApexEventTest {
}
@Test
- public void setExecutionProperties() {
+ void setExecutionProperties() {
final Properties properties = new Properties();
apexEvent.setExecutionProperties(properties);
final Properties actual = apexEvent.getExecutionProperties();
@@ -112,7 +112,7 @@ public class ApexEventTest {
}
@Test
- public void setExceptionMessage() {
+ void setExceptionMessage() {
final String message = RandomStringUtils.randomAlphabetic(25);
apexEvent.setExceptionMessage(message);
final String actual = apexEvent.getExceptionMessage();
@@ -120,7 +120,7 @@ public class ApexEventTest {
}
@Test
- public void put() {
+ void put() {
final String key = RandomStringUtils.randomAlphabetic(5);
final Object event = new Object();
apexEvent.put(key, event);
@@ -129,7 +129,7 @@ public class ApexEventTest {
}
@Test
- public void put2() {
+ void put2() {
final String key = "_#+@" + RandomStringUtils.randomAlphabetic(5);
final Object event = new Object();
apexEvent.put(key, event);
@@ -138,7 +138,7 @@ public class ApexEventTest {
}
@Test
- public void putAll() {
+ void putAll() {
final String key1 = RandomStringUtils.randomAlphabetic(5);
final String key2 = RandomStringUtils.randomAlphabetic(6);
final Object event1 = new Object();
@@ -152,7 +152,7 @@ public class ApexEventTest {
}
@Test
- public void putAllOneInvalidKey() {
+ void putAllOneInvalidKey() {
final String key1 = RandomStringUtils.randomAlphabetic(5);
final String key2 = "_#+@" + RandomStringUtils.randomAlphabetic(6);
final String key3 = RandomStringUtils.randomAlphabetic(7);
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexPeriodicEventGeneratorTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexPeriodicEventGeneratorTest.java
index ee72e6ea4..017941414 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexPeriodicEventGeneratorTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/ApexPeriodicEventGeneratorTest.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021. Nordix Foundation.
+ * Copyright (C) 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,16 +22,16 @@
package org.onap.policy.apex.service.engine.event;
import java.util.Random;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import org.onap.policy.apex.service.engine.runtime.EngineServiceEventInterface;
-public class ApexPeriodicEventGeneratorTest {
+class ApexPeriodicEventGeneratorTest {
private final Random random = new Random();
@Test
- public void run() throws ApexEventException {
+ void run() {
final EngineServiceEventInterface engineServiceEventInterface = Mockito.mock(EngineServiceEventInterface.class);
// don't want the timer to fire, so make it wait at least two seconds
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java
index 6e346a2a0..5b20b6fc5 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventConverterTest.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) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,7 +24,7 @@ package org.onap.policy.apex.service.engine.event;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.Apex2JsonEventConverter;
import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.JsonEventProtocolParameters;
import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters;
@@ -33,10 +33,10 @@ import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParame
* Test the JSON event converter corner cases.
*
*/
-public class JsonEventConverterTest {
- @SuppressWarnings("deprecation")
+class JsonEventConverterTest {
+
@Test
- public void testJsonEventConverter() {
+ void testJsonEventConverter() {
Apex2JsonEventConverter converter = new Apex2JsonEventConverter();
assertThatThrownBy(() -> converter.init(null))
@@ -52,11 +52,11 @@ public class JsonEventConverterTest {
.hasMessage("error converting event \"1\" to a string");
assertThatThrownBy(() -> converter.toApexEvent(null, "[{\"aKey\": 1},{\"aKey\": 2}]"))
.hasMessageStartingWith("Failed to unmarshal JSON event")
- .getCause().hasMessageStartingWith("event received without mandatory parameter \"name\" "
+ .cause().hasMessageContaining("event received without mandatory parameter \"name\" "
+ "on configuration or on event");
assertThatThrownBy(() -> converter.toApexEvent(null, "[1,2,3]"))
.hasMessageStartingWith("Failed to unmarshal JSON event")
- .getCause().hasMessageStartingWith("incoming event ([1,2,3]) is a JSON object array "
+ .cause().hasMessageContaining("incoming event ([1,2,3]) is a JSON object array "
+ "containing an invalid object 1.0");
assertThatThrownBy(() -> converter.fromApexEvent(null))
.hasMessage("event processing failed, Apex event is null");
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java
index 3bee638d8..076fd6e12 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerForPojoTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020,2022-2023 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.
@@ -22,15 +22,15 @@
package org.onap.policy.apex.service.engine.event;
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.io.ByteArrayInputStream;
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.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.SchemaParameters;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
@@ -52,19 +52,19 @@ import org.slf4j.ext.XLoggerFactory;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class JsonEventHandlerForPojoTest {
+class JsonEventHandlerForPojoTest {
private static final XLogger logger = XLoggerFactory.getXLogger(JsonEventHandlerForPojoTest.class);
/**
* Setup event model.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
* @throws ApexModelException the apex model exception
*/
- @BeforeClass
- public static void setupEventModel() throws IOException, ApexModelException {
+ @BeforeAll
+ static void setupEventModel() throws IOException, ApexModelException {
final String policyModelString =
- TextFileUtils.getTextFileAsString("src/test/resources/policymodels/PojoEventModel.json");
+ TextFileUtils.getTextFileAsString("src/test/resources/policymodels/PojoEventModel.json");
final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<AxPolicyModel>(AxPolicyModel.class);
modelReader.setValidate(false);
final AxPolicyModel apexPolicyModel = modelReader.read(new ByteArrayInputStream(policyModelString.getBytes()));
@@ -76,8 +76,8 @@ public class JsonEventHandlerForPojoTest {
/**
* Initialize default schema parameters.
*/
- @BeforeClass
- public static void initializeDefaultSchemaParameters() {
+ @BeforeAll
+ static void initializeDefaultSchemaParameters() {
ParameterService.clear();
final SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
@@ -87,8 +87,8 @@ public class JsonEventHandlerForPojoTest {
/**
* Teardown default schema parameters.
*/
- @AfterClass
- public static void teardownDefaultSchemaParameters() {
+ @AfterAll
+ static void teardownDefaultSchemaParameters() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
ModelService.clear();
}
@@ -97,10 +97,10 @@ public class JsonEventHandlerForPojoTest {
* Test POJO to apex event and back.
*
* @throws ApexException the apex exception
- * @throws IOException on IO exceptions
+ * @throws IOException on IO exceptions
*/
@Test
- public void testJsonPojoToApexEvent() throws ApexException, IOException {
+ void testJsonPojoToApexEvent() throws ApexException, IOException {
final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
assertNotNull(jsonEventConverter);
@@ -109,7 +109,7 @@ public class JsonEventHandlerForPojoTest {
jsonEventConverter.init(pars);
final String apexEventJsonStringIn =
- TextFileUtils.getTextFileAsString("src/test/resources/events/TestPojoEvent.json");
+ TextFileUtils.getTextFileAsString("src/test/resources/events/TestPojoEvent.json");
logger.debug("input event\n" + apexEventJsonStringIn);
@@ -148,10 +148,10 @@ public class JsonEventHandlerForPojoTest {
* Test POJO List to apex event and back.
*
* @throws ApexException the apex exception
- * @throws IOException on IO exceptions
+ * @throws IOException on IO exceptions
*/
@Test
- public void testJsonPojoListToApexEvent() throws ApexException, IOException {
+ void testJsonPojoListToApexEvent() throws ApexException, IOException {
final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
assertNotNull(jsonEventConverter);
@@ -160,7 +160,7 @@ public class JsonEventHandlerForPojoTest {
jsonEventConverter.init(pars);
final String apexEventJsonStringIn =
- TextFileUtils.getTextFileAsString("src/test/resources/events/TestPojoListEvent.json");
+ TextFileUtils.getTextFileAsString("src/test/resources/events/TestPojoListEvent.json");
logger.debug("input event\n" + apexEventJsonStringIn);
@@ -200,11 +200,11 @@ public class JsonEventHandlerForPojoTest {
* Test POJO event with bad configurations.
*
* @throws ApexException the apex exception
- * @throws IOException on IO exceptions
+ * @throws IOException on IO exceptions
*/
@SuppressWarnings("deprecation")
@Test
- public void testJsonBadPojoApexEvent() throws ApexException, IOException {
+ void testJsonBadPojoApexEvent() throws ApexException, IOException {
final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
assertNotNull(jsonEventConverter);
@@ -213,7 +213,7 @@ public class JsonEventHandlerForPojoTest {
jsonEventConverter.init(pars);
final String apexEventJsonStringIn =
- TextFileUtils.getTextFileAsString("src/test/resources/events/TestPojoEvent.json");
+ TextFileUtils.getTextFileAsString("src/test/resources/events/TestPojoEvent.json");
logger.debug("input event\n" + apexEventJsonStringIn);
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java
index a724b6da2..59b022a7c 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventHandlerTest.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.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,19 +23,19 @@
package org.onap.policy.apex.service.engine.event;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.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.ByteArrayInputStream;
import java.io.IOException;
import java.util.HashMap;
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.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.SchemaParameters;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
@@ -58,19 +58,19 @@ import org.slf4j.ext.XLoggerFactory;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class JsonEventHandlerTest {
+class JsonEventHandlerTest {
private static final XLogger logger = XLoggerFactory.getXLogger(JsonEventHandlerTest.class);
/**
* Setup event model.
*
- * @throws IOException Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
* @throws ApexModelException the apex model exception
*/
- @BeforeClass
- public static void setupEventModel() throws IOException, ApexModelException {
+ @BeforeAll
+ static void setupEventModel() throws IOException, ApexModelException {
final String policyModelString =
- TextFileUtils.getTextFileAsString("src/test/resources/policymodels/SmallModel.json");
+ TextFileUtils.getTextFileAsString("src/test/resources/policymodels/SmallModel.json");
final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<AxPolicyModel>(AxPolicyModel.class);
final AxPolicyModel apexPolicyModel = modelReader.read(new ByteArrayInputStream(policyModelString.getBytes()));
@@ -81,8 +81,8 @@ public class JsonEventHandlerTest {
/**
* Initialize default schema parameters.
*/
- @BeforeClass
- public static void initializeDefaultSchemaParameters() {
+ @BeforeAll
+ static void initializeDefaultSchemaParameters() {
ParameterService.clear();
final SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
@@ -92,8 +92,8 @@ public class JsonEventHandlerTest {
/**
* Teardown default schema parameters.
*/
- @AfterClass
- public static void teardownDefaultSchemaParameters() {
+ @AfterAll
+ static void teardownDefaultSchemaParameters() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
ModelService.clear();
}
@@ -104,7 +104,7 @@ public class JsonEventHandlerTest {
* @throws ApexException the apex exception
*/
@Test
- public void testJsontoApexEvent() throws ApexException {
+ void testJsontoApexEvent() throws ApexException {
final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
assertNotNull(jsonEventConverter);
jsonEventConverter.init(new JsonEventProtocolParameters());
@@ -138,7 +138,7 @@ public class JsonEventHandlerTest {
*/
@SuppressWarnings("deprecation")
@Test
- public void testJsontoApexBadEvent() throws ApexException {
+ void testJsontoApexBadEvent() throws ApexException {
final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
assertNotNull(jsonEventConverter);
jsonEventConverter.init(new JsonEventProtocolParameters());
@@ -222,7 +222,7 @@ public class JsonEventHandlerTest {
jsonEventConverter.toApexEvent(null, apexEventJsonStringIn);
}).hasMessageStartingWith("Failed to unmarshal JSON event")
.getCause().hasMessageStartingWith("error parsing BasicEvent:0.0.1 "
- + "event from Json. Field \"intPar\" is missing, but is mandatory.");
+ + "event from Json. Field \"intPar\" is missing, but is mandatory.");
apexEventJsonStringIn1 = SupportJsonEventGenerator.jsonEventNullFields();
event = jsonEventConverter.toApexEvent(null, apexEventJsonStringIn1).get(0);
assertEquals(null, event.get("TestSlogan"));
@@ -244,7 +244,7 @@ public class JsonEventHandlerTest {
* @throws ApexException the apex exception
*/
@Test
- public void testApexEventToJson() throws ApexException {
+ void testApexEventToJson() throws ApexException {
final Apex2JsonEventConverter jsonEventConverter = new Apex2JsonEventConverter();
jsonEventConverter.init(new JsonEventProtocolParameters());
assertNotNull(jsonEventConverter);
@@ -253,8 +253,8 @@ public class JsonEventHandlerTest {
basicEventMap.put("intPar", 12345);
final ApexEvent basicEvent =
- new ApexEvent("BasicEvent", "0.0.1", "org.onap.policy.apex.events", "test", "apex",
- AxToscaPolicyProcessingStatus.ENTRY.name());
+ new ApexEvent("BasicEvent", "0.0.1", "org.onap.policy.apex.events", "test", "apex",
+ AxToscaPolicyProcessingStatus.ENTRY.name());
basicEvent.putAll(basicEventMap);
final String apexEvent0000JsonString = (String) jsonEventConverter.fromApexEvent(basicEvent);
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventProtocolPrametersTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventProtocolParametersTest.java
index bf19d3f0b..fa93c3789 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventProtocolPrametersTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonEventProtocolParametersTest.java
@@ -1,41 +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.service.engine.event;
-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 org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.JsonEventProtocolParameters;
/**
* Test the JSON event parameters.
- *
*/
-public class JsonEventProtocolPrametersTest {
+class JsonEventProtocolParametersTest {
@Test
- public void testJsonParameters() {
+ void testJsonParameters() {
assertNotNull(new JsonEventProtocolParameters());
-
+
JsonEventProtocolParameters params = new JsonEventProtocolParameters();
params.setLabel("MyLabel");
@@ -44,22 +44,22 @@ public class JsonEventProtocolPrametersTest {
params.setEventProtocolPluginClass("MyPluginClass");
assertEquals("MyPluginClass", params.getEventProtocolPluginClass());
-
+
params.setNameAlias("MyNameAlias");
assertEquals("MyNameAlias", params.getNameAlias());
-
+
params.setVersionAlias("MyVersionAlias");
assertEquals("MyVersionAlias", params.getVersionAlias());
-
+
params.setNameSpaceAlias("MyNameSpaceAlias");
assertEquals("MyNameSpaceAlias", params.getNameSpaceAlias());
-
+
params.setSourceAlias("MySourceAlias");
assertEquals("MySourceAlias", params.getSourceAlias());
-
+
params.setTargetAlias("MyTargetAlias");
assertEquals("MyTargetAlias", params.getTargetAlias());
-
+
params.setPojoField("MyPojoField");
assertEquals("MyPojoField", params.getPojoField());
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonTaggedEventConsumerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonTaggedEventConsumerTest.java
index 3bdcf53d9..a7d77fb33 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonTaggedEventConsumerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/JsonTaggedEventConsumerTest.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.
@@ -21,15 +22,15 @@
package org.onap.policy.apex.service.engine.event;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.CharacterDelimitedTextBlockReader;
import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.TextBlock;
@@ -37,64 +38,61 @@ import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer
* Test JSON Tagged Event Consumer.
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class JsonTaggedEventConsumerTest {
+class JsonTaggedEventConsumerTest {
@Test
- public void testGarbageText() throws IOException {
- verifyNoEvent("testGarbageText", "hello there");
+ void testGarbageText() throws IOException {
+ verifyNoEvent("hello there");
}
@Test
- public void testPartialEvent() throws IOException {
- verifyNoEvent("testGarbageText", "\"TestTimestamp\": 1469781869268}");
+ void testPartialEvent() throws IOException {
+ verifyNoEvent("\"TestTimestamp\": 1469781869268}");
}
@Test
- public void testFullEvent() throws IOException {
- verifyMulti("testFullEvent", "{TestTimestamp\": 1469781869268}", "{TestTimestamp\": 1469781869268}");
+ void testFullEvent() throws IOException {
+ verifyMulti("{TestTimestamp\": 1469781869268}");
}
@Test
- public void testFullEventGarbageBefore() throws IOException {
- verifyMulti("testFullEventGarbageBefore", "Garbage{TestTimestamp\": 1469781869268}",
- "{TestTimestamp\": 1469781869268}");
+ void testFullEventGarbageBefore() throws IOException {
+ verifyMulti("Garbage{TestTimestamp\": 1469781869268}");
}
@Test
- public void testFullEventGarbageBeforeAfter() throws IOException {
- verifyMulti("testFullEventGarbageBeforeAfter", "Garbage{TestTimestamp\": 1469781869268}Rubbish",
- "{TestTimestamp\": 1469781869268}");
+ void testFullEventGarbageBeforeAfter() throws IOException {
+ verifyMulti("Garbage{TestTimestamp\": 1469781869268}Rubbish");
}
@Test
- public void testFullEventGarbageAfter() throws IOException {
- verifyMulti("testFullEventGarbageAfter", "{TestTimestamp\": 1469781869268}Rubbish",
- "{TestTimestamp\": 1469781869268}");
+ void testFullEventGarbageAfter() throws IOException {
+ verifyMulti("{TestTimestamp\": 1469781869268}Rubbish");
}
- private void verifyNoEvent(String testName, String input) throws IOException {
+ private void verifyNoEvent(String input) throws IOException {
final InputStream jsonInputStream = new ByteArrayInputStream(input.getBytes());
final CharacterDelimitedTextBlockReader taggedReader = new CharacterDelimitedTextBlockReader('{', '}');
taggedReader.init(jsonInputStream);
final TextBlock textBlock = taggedReader.readTextBlock();
- assertNull(testName, textBlock.getText());
- assertTrue(testName, textBlock.isEndOfText());
+ assertNull(textBlock.getText());
+ assertTrue(textBlock.isEndOfText());
}
- private void verifyMulti(String testName, String input, String expected) throws IOException {
+ private void verifyMulti(String input) throws IOException {
final InputStream jsonInputStream = new ByteArrayInputStream(input.getBytes());
final CharacterDelimitedTextBlockReader taggedReader = new CharacterDelimitedTextBlockReader('{', '}');
taggedReader.init(jsonInputStream);
TextBlock textBlock = taggedReader.readTextBlock();
- assertEquals(testName, expected, textBlock.getText());
- assertFalse(testName, textBlock.isEndOfText());
+ assertEquals("{TestTimestamp\": 1469781869268}", textBlock.getText());
+ assertFalse(textBlock.isEndOfText());
textBlock = taggedReader.readTextBlock();
- assertNull(testName, textBlock.getText());
- assertTrue(testName, textBlock.isEndOfText());
+ assertNull(textBlock.getText());
+ assertTrue(textBlock.isEndOfText());
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/PeeredReferenceTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/PeeredReferenceTest.java
index cadb5c8a1..1e9c4a586 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/PeeredReferenceTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/PeeredReferenceTest.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.
@@ -19,18 +19,18 @@
package org.onap.policy.apex.service.engine.event;
-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 org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.ApexFileEventConsumer;
import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.producer.ApexFileEventProducer;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
-public class PeeredReferenceTest {
+class PeeredReferenceTest {
@Test
- public void getPeeredConsumer() {
+ void getPeeredConsumer() {
final ApexFileEventConsumer eventConsumer = new ApexFileEventConsumer();
final ApexFileEventProducer eventProducer = new ApexFileEventProducer();
final EventHandlerPeeredMode peeredMode = EventHandlerPeeredMode.REQUESTOR;
@@ -43,7 +43,7 @@ public class PeeredReferenceTest {
}
@Test
- public void getPeeredProducer() {
+ void getPeeredProducer() {
final ApexEventConsumer eventConsumer = new ApexFileEventConsumer();
final ApexEventProducer eventProducer = new ApexFileEventProducer();
final EventHandlerPeeredMode peeredMode = EventHandlerPeeredMode.SYNCHRONOUS;
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/PluginFactoriesTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/PluginFactoriesTest.java
index 514b3b1e5..bf894dce5 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/PluginFactoriesTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/PluginFactoriesTest.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
* Modifications Copyright (C) 2020 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,10 +22,10 @@
package org.onap.policy.apex.service.engine.event;
-import static org.junit.Assert.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.util.Map.Entry;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.service.engine.event.impl.EventConsumerFactory;
import org.onap.policy.apex.service.engine.event.impl.EventProducerFactory;
import org.onap.policy.apex.service.engine.main.ApexCommandLineArguments;
@@ -35,13 +36,14 @@ import org.onap.policy.common.parameters.ParameterException;
/**
* Test Plugin Factories.
+ *
* @author Liam Fallon (liam.fallon@ericsson.com)
* @author John Keeney (john.keeney@ericsson.com)
*/
-public class PluginFactoriesTest {
+class PluginFactoriesTest {
@Test
- public void testEventConsumerFactory() throws ApexEventException, ParameterException {
+ void testEventConsumerFactory() throws ApexEventException, ParameterException {
final String[] args = {"-p", "src/test/resources/parameters/factoryGoodParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -49,13 +51,13 @@ public class PluginFactoriesTest {
for (final Entry<String, EventHandlerParameters> ce : parameters.getEventInputParameters().entrySet()) {
final ApexEventConsumer consumer = new EventConsumerFactory().createConsumer(
- parameters.getEngineServiceParameters().getName() + "_consumer_" + ce.getKey(), ce.getValue());
+ parameters.getEngineServiceParameters().getName() + "_consumer_" + ce.getKey(), ce.getValue());
assertNotNull(consumer);
}
for (final Entry<String, EventHandlerParameters> pe : parameters.getEventOutputParameters().entrySet()) {
final ApexEventProducer producer = new EventProducerFactory().createProducer(
- parameters.getEngineServiceParameters().getName() + "_producer_" + pe.getKey(), pe.getValue());
+ parameters.getEngineServiceParameters().getName() + "_producer_" + pe.getKey(), pe.getValue());
assertNotNull(producer);
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/SynchronousEventCacheTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/SynchronousEventCacheTest.java
index dd960b298..f8de7f561 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/SynchronousEventCacheTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/SynchronousEventCacheTest.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021. Nordix Foundation.
+ * Copyright (C) 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");
@@ -25,25 +25,26 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import java.util.Random;
-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.impl.eventrequestor.EventRequestorConsumer;
import org.onap.policy.apex.service.engine.event.impl.eventrequestor.EventRequestorProducer;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
-public class SynchronousEventCacheTest {
+class SynchronousEventCacheTest {
+
private final Random random = new Random();
private ApexEventConsumer consumer;
private ApexEventProducer producer;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
consumer = new EventRequestorConsumer();
producer = new EventRequestorProducer();
}
@Test
- public void removedCachedFromApexNotExists() {
+ void removedCachedFromApexNotExists() {
int timeout = random.nextInt(100);
int executionId = random.nextInt();
final SynchronousEventCache cache =
@@ -54,7 +55,7 @@ public class SynchronousEventCacheTest {
}
@Test
- public void removeCachedFromApex() {
+ void removeCachedFromApex() {
int timeout = random.nextInt(100);
int executionId = random.nextInt();
final SynchronousEventCache cache =
@@ -67,7 +68,7 @@ public class SynchronousEventCacheTest {
}
@Test
- public void removedCachedToApexNotExists() {
+ void removedCachedToApexNotExists() {
int timeout = random.nextInt(100);
int executionId = random.nextInt();
final SynchronousEventCache cache =
@@ -78,7 +79,7 @@ public class SynchronousEventCacheTest {
}
@Test
- public void removeCachedToApex() {
+ void removeCachedToApex() {
int timeout = random.nextInt(100);
int executionId = random.nextInt();
final SynchronousEventCache cache =
@@ -91,7 +92,7 @@ public class SynchronousEventCacheTest {
}
@Test
- public void apexExistsFromApexNo() {
+ void apexExistsFromApexNo() {
int executionId = random.nextInt();
final SynchronousEventCache cache =
new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer, producer, 0);
@@ -101,7 +102,7 @@ public class SynchronousEventCacheTest {
}
@Test
- public void apexExistsFromApexYes() {
+ void apexExistsFromApexYes() {
int executionId = random.nextInt();
final SynchronousEventCache cache =
new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer, producer, 0);
@@ -112,7 +113,7 @@ public class SynchronousEventCacheTest {
}
@Test
- public void apexExistsToApexNo() {
+ void apexExistsToApexNo() {
int executionId = random.nextInt();
final SynchronousEventCache cache =
new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer, producer, 0);
@@ -122,7 +123,7 @@ public class SynchronousEventCacheTest {
}
@Test
- public void apexExistsToApexYes() {
+ void apexExistsToApexYes() {
int executionId = random.nextInt();
final SynchronousEventCache cache =
new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer, producer, 0);
@@ -133,7 +134,7 @@ public class SynchronousEventCacheTest {
}
@Test
- public void addEventsFromApexDuplicatedExecutionId() {
+ void addEventsFromApexDuplicatedExecutionId() {
int timeout = random.nextInt(100);
int executionId = random.nextInt();
final SynchronousEventCache cache =
@@ -144,11 +145,11 @@ public class SynchronousEventCacheTest {
final var obj2 = new Object();
assertThatCode(() -> cache.cacheSynchronizedEventFromApex(executionId, obj2))
- .isInstanceOf(ApexEventRuntimeException.class);
+ .isInstanceOf(ApexEventRuntimeException.class);
}
@Test
- public void stop() {
+ void stop() {
int timeout = random.nextInt(100);
final SynchronousEventCache cache =
new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer, producer, timeout);
@@ -157,7 +158,7 @@ public class SynchronousEventCacheTest {
}
@Test
- public void stopNotEmpty() {
+ void stopNotEmpty() {
final SynchronousEventCache cache =
new SynchronousEventCache(EventHandlerPeeredMode.SYNCHRONOUS, consumer, producer, 2000);
assertThatCode(() -> {
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactoryTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactoryTest.java
index 976376e5a..5bff54225 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactoryTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventConsumerFactoryTest.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,27 +20,27 @@
package org.onap.policy.apex.service.engine.event.impl;
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.lang3.RandomStringUtils;
-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.ApexEventConsumer;
import org.onap.policy.apex.service.engine.event.ApexEventException;
import org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperCarrierTechnologyParameters;
import org.onap.policy.apex.service.parameters.carriertechnology.RestPluginCarrierTechnologyParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
-public class EventConsumerFactoryTest {
+class EventConsumerFactoryTest {
private EventConsumerFactory factory;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
factory = new EventConsumerFactory();
}
@Test
- public void createConsumerNoTechnologyParameter() {
+ void createConsumerNoTechnologyParameter() {
final String name = RandomStringUtils.randomAlphabetic(6);
final EventHandlerParameters parameters = new EventHandlerParameters();
@@ -49,7 +49,7 @@ public class EventConsumerFactoryTest {
}
@Test
- public void createConsumerNoConsumerPlugin() {
+ void createConsumerNoConsumerPlugin() {
final String name = RandomStringUtils.randomAlphabetic(6);
final EventHandlerParameters parameters = new EventHandlerParameters();
parameters.setCarrierTechnologyParameters(new RestPluginCarrierTechnologyParameters());
@@ -59,7 +59,7 @@ public class EventConsumerFactoryTest {
}
@Test
- public void createConsumerWrongPluginClassName() {
+ void createConsumerWrongPluginClassName() {
final String name = RandomStringUtils.randomAlphabetic(6);
final EventHandlerParameters parameters = new EventHandlerParameters();
final RestPluginCarrierTechnologyParameters technologyParameters =
@@ -72,7 +72,7 @@ public class EventConsumerFactoryTest {
}
@Test
- public void createConsumer() throws ApexEventException {
+ void createConsumer() throws ApexEventException {
final String name = RandomStringUtils.randomAlphabetic(6);
final EventHandlerParameters parameters = new EventHandlerParameters();
parameters.setCarrierTechnologyParameters(new SuperDooperCarrierTechnologyParameters());
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactoryTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactoryTest.java
index 7e3cb5478..edd050e26 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactoryTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProducerFactoryTest.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,27 +20,27 @@
package org.onap.policy.apex.service.engine.event.impl;
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.lang3.RandomStringUtils;
-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.parameters.dummyclasses.SuperDooperCarrierTechnologyParameters;
import org.onap.policy.apex.service.parameters.carriertechnology.RestPluginCarrierTechnologyParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
-public class EventProducerFactoryTest {
+class EventProducerFactoryTest {
private EventProducerFactory factory;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
factory = new EventProducerFactory();
}
@Test
- public void createConsumerNoTechnologyParameter() {
+ void createConsumerNoTechnologyParameter() {
final EventHandlerParameters parameters = new EventHandlerParameters();
final String name = RandomStringUtils.randomAlphabetic(4);
@@ -49,7 +49,7 @@ public class EventProducerFactoryTest {
}
@Test
- public void createConsumerNoConsumerPlugin() {
+ void createConsumerNoConsumerPlugin() {
final EventHandlerParameters parameters = new EventHandlerParameters();
final String name = RandomStringUtils.randomAlphabetic(4);
parameters.setCarrierTechnologyParameters(new RestPluginCarrierTechnologyParameters());
@@ -59,7 +59,7 @@ public class EventProducerFactoryTest {
}
@Test
- public void createConsumerWrongProducerPluginName() {
+ void createConsumerWrongProducerPluginName() {
final EventHandlerParameters parameters = new EventHandlerParameters();
final RestPluginCarrierTechnologyParameters technologyParameters =
new RestPluginCarrierTechnologyParameters();
@@ -72,7 +72,7 @@ public class EventProducerFactoryTest {
}
@Test
- public void createConsumer() throws ApexEventException {
+ void createConsumer() throws ApexEventException {
final EventHandlerParameters parameters = new EventHandlerParameters();
parameters.setCarrierTechnologyParameters(new SuperDooperCarrierTechnologyParameters());
final String name = RandomStringUtils.randomAlphabetic(4);
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProtocolFactoryTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProtocolFactoryTest.java
index 8ed3a9fec..9fd74e28f 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProtocolFactoryTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/EventProtocolFactoryTest.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,27 +20,27 @@
package org.onap.policy.apex.service.engine.event.impl;
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.lang3.RandomStringUtils;
-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.ApexEventProtocolConverter;
import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
import org.onap.policy.apex.service.engine.event.impl.apexprotocolplugin.ApexEventProtocolParameters;
import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.JsonEventProtocolParameters;
import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters;
-public class EventProtocolFactoryTest {
+class EventProtocolFactoryTest {
private EventProtocolFactory factory;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
factory = new EventProtocolFactory();
}
@Test
- public void createConsumerNoConsumerPlugin() {
+ void createConsumerNoConsumerPlugin() {
final EventProtocolParameters parameters = new ApexEventProtocolParameters();
parameters.setEventProtocolPluginClass("");
final String name = RandomStringUtils.randomAlphabetic(9);
@@ -50,7 +50,7 @@ public class EventProtocolFactoryTest {
}
@Test
- public void createConsumer2() {
+ void createConsumer2() {
final EventProtocolParameters parameters = new ApexEventProtocolParameters();
final String name = RandomStringUtils.randomAlphabetic(9);
parameters.setEventProtocolPluginClass("java.lang.Object");
@@ -60,7 +60,7 @@ public class EventProtocolFactoryTest {
}
@Test
- public void createConsumer() {
+ void createConsumer() {
final EventProtocolParameters parameters = new JsonEventProtocolParameters();
final String name = RandomStringUtils.randomAlphabetic(9);
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java
index 9a61f8739..210358fed 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/Apex2ApexEventConverterTest.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
+ * Copyright (C) 2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,55 +23,55 @@ package org.onap.policy.apex.service.engine.event.impl.apexprotocolplugin;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
import java.util.List;
import org.apache.commons.lang3.RandomStringUtils;
-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.AxToscaPolicyProcessingStatus;
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.ApexEventList;
import org.onap.policy.apex.service.engine.event.ApexEventRuntimeException;
-public class Apex2ApexEventConverterTest {
+class Apex2ApexEventConverterTest {
private Apex2ApexEventConverter converter;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
converter = new Apex2ApexEventConverter();
}
@Test
- public void initWithNull() {
+ void initWithNull() {
assertThatThrownBy(() -> converter.init(null))
.isInstanceOf(ApexEventRuntimeException.class);
}
@Test
- public void init() {
+ void init() {
assertThatNoException()
.isThrownBy(() -> converter.init(new ApexEventProtocolParameters()));
}
@Test
- public void toApexEventWithNull() {
+ void toApexEventWithNull() {
final String eventName = RandomStringUtils.randomAlphanumeric(5);
assertThatThrownBy(() -> converter.toApexEvent(eventName, null))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void toApexEventWithNonApexEvent() {
+ void toApexEventWithNonApexEvent() {
final String eventName = RandomStringUtils.randomAlphanumeric(5);
assertThatThrownBy(() -> converter.toApexEvent(eventName, new Object()))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void toApexEmptyEvent() throws ApexEventException {
+ void toApexEmptyEvent() throws ApexEventException {
final String eventName = RandomStringUtils.randomAlphanumeric(4);
final String name = RandomStringUtils.randomAlphanumeric(5);
final String version = RandomStringUtils.randomAlphanumeric(6);
@@ -86,7 +86,7 @@ public class Apex2ApexEventConverterTest {
}
@Test
- public void toApexEventWithApexAndOtherFields() throws ApexEventException {
+ void toApexEventWithApexAndOtherFields() throws ApexEventException {
final String eventName = RandomStringUtils.randomAlphanumeric(4);
final String name1 = RandomStringUtils.randomAlphanumeric(5);
final String version1 = RandomStringUtils.randomAlphanumeric(6);
@@ -105,7 +105,7 @@ public class Apex2ApexEventConverterTest {
}
@Test
- public void toApexEventWithApexAndList() throws ApexEventException {
+ void toApexEventWithApexAndList() throws ApexEventException {
final String eventName = RandomStringUtils.randomAlphanumeric(4);
final String name1 = RandomStringUtils.randomAlphanumeric(5);
final String version1 = RandomStringUtils.randomAlphanumeric(6);
@@ -135,7 +135,7 @@ public class Apex2ApexEventConverterTest {
}
@Test
- public void toApexEventWithApexAndListAndOtherFields() throws ApexEventException {
+ void toApexEventWithApexAndListAndOtherFields() throws ApexEventException {
final String eventName = RandomStringUtils.randomAlphanumeric(4);
final String name1 = RandomStringUtils.randomAlphanumeric(5);
final String version1 = RandomStringUtils.randomAlphanumeric(6);
@@ -166,13 +166,13 @@ public class Apex2ApexEventConverterTest {
}
@Test
- public void fromApexEventNull() {
+ void fromApexEventNull() {
assertThatThrownBy(() -> converter.fromApexEvent(null))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void fromApexEvent() throws ApexEventException {
+ void fromApexEvent() throws ApexEventException {
final String name1 = RandomStringUtils.randomAlphanumeric(5);
final String version1 = RandomStringUtils.randomAlphanumeric(6);
final String nameSpace1 = "a" + RandomStringUtils.randomAlphanumeric(7);
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/ApexEventProtocolParametersTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/ApexEventProtocolParametersTest.java
index 8b39b0a74..d0d3de2fb 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/ApexEventProtocolParametersTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/apexprotocolplugin/ApexEventProtocolParametersTest.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.
@@ -19,15 +19,15 @@
package org.onap.policy.apex.service.engine.event.impl.apexprotocolplugin;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import org.apache.commons.lang3.RandomStringUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class ApexEventProtocolParametersTest {
+class ApexEventProtocolParametersTest {
@Test
- public void testNoArgConstructor() {
+ void testNoArgConstructor() {
final ApexEventProtocolParameters apexEventProtocolParameters = new ApexEventProtocolParameters();
final String actual = apexEventProtocolParameters.getLabel();
final String pluginClass = apexEventProtocolParameters.getEventProtocolPluginClass();
@@ -37,7 +37,7 @@ public class ApexEventProtocolParametersTest {
}
@Test
- public void testConstructor() {
+ void testConstructor() {
final String expected = RandomStringUtils.randomAlphabetic(6);
final ApexEventProtocolParameters apexEventProtocolParameters = new ApexEventProtocolParameters(expected);
final String actual = apexEventProtocolParameters.getLabel();
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java
index 4d36b7be4..03b622a5e 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/enevent/ApexEvent2EnEventConverterTest.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
+ * Copyright (C) 2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,13 +21,13 @@
package org.onap.policy.apex.service.engine.event.impl.enevent;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import java.util.List;
import java.util.Random;
import org.apache.commons.lang3.RandomStringUtils;
-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.core.engine.event.EnEvent;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.model.basicmodel.concepts.AxToscaPolicyProcessingStatus;
@@ -36,24 +36,24 @@ 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;
-public class ApexEvent2EnEventConverterTest {
+class ApexEvent2EnEventConverterTest {
private ApexEvent2EnEventConverter converter;
private final Random random = new Random();
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
converter = new ApexEvent2EnEventConverter(null);
}
@Test
- public void toApexEventNull() {
+ void toApexEventNull() {
final String eventName = RandomStringUtils.randomAlphabetic(3);
assertThatThrownBy(() -> converter.toApexEvent(eventName, null))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void toApexEventWrongClass() throws ApexException {
+ void toApexEventWrongClass() throws ApexException {
final String eventName = RandomStringUtils.randomAlphabetic(3);
final String name = RandomStringUtils.randomAlphanumeric(5);
final String version = RandomStringUtils.randomAlphanumeric(6);
@@ -69,7 +69,7 @@ public class ApexEvent2EnEventConverterTest {
}
@Test
- public void toApex() throws ApexException {
+ void toApex() throws ApexException {
// prepare String values for events
final String name = RandomStringUtils.randomAlphabetic(5);
final String version = RandomStringUtils.randomAlphabetic(6);
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParametersTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParametersTest.java
index 878756383..63248045b 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParametersTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorCarrierTechnologyParametersTest.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
+ * Copyright (C) 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");
@@ -20,23 +20,23 @@
package org.onap.policy.apex.service.engine.event.impl.eventrequestor;
-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 org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.ValidationResult;
-public class EventRequestorCarrierTechnologyParametersTest {
+class EventRequestorCarrierTechnologyParametersTest {
@Test
- public void getName() {
+ void getName() {
final EventRequestorCarrierTechnologyParameters parameters = new EventRequestorCarrierTechnologyParameters();
final String actual = parameters.getName();
assertEquals(EventRequestorCarrierTechnologyParameters.EVENT_REQUESTOR_CARRIER_TECHNOLOGY_LABEL, actual);
}
@Test
- public void validate() {
+ void validate() {
final EventRequestorCarrierTechnologyParameters parameters = new EventRequestorCarrierTechnologyParameters();
final ValidationResult actual = parameters.validate();
assertNotNull(actual);
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorConsumerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorConsumerTest.java
index dd44da7dd..fc79d1dca 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorConsumerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorConsumerTest.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,11 +20,11 @@
package org.onap.policy.apex.service.engine.event.impl.eventrequestor;
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.commons.lang3.RandomStringUtils;
-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.impl.filecarrierplugin.consumer.ApexFileEventConsumer;
@@ -32,16 +32,16 @@ import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.producer
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
-public class EventRequestorConsumerTest {
+class EventRequestorConsumerTest {
private EventRequestorConsumer consumer;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
consumer = new EventRequestorConsumer();
}
@Test
- public void initNoCarrierTechnologyParameters() {
+ void initNoCarrierTechnologyParameters() {
final String consumerName = RandomStringUtils.randomAlphabetic(6);
final EventHandlerParameters eventHandlerParameters = new EventHandlerParameters();
@@ -50,7 +50,7 @@ public class EventRequestorConsumerTest {
}
@Test
- public void initNoPeered() {
+ void initNoPeered() {
final String consumerName = RandomStringUtils.randomAlphabetic(6);
final EventHandlerParameters eventHandlerParameters = new EventHandlerParameters();
eventHandlerParameters.setCarrierTechnologyParameters(new EventRequestorCarrierTechnologyParameters());
@@ -60,7 +60,7 @@ public class EventRequestorConsumerTest {
}
@Test
- public void getName() throws ApexEventException {
+ void getName() throws ApexEventException {
final String consumerName = RandomStringUtils.randomAlphabetic(6);
final EventHandlerParameters eventHandlerParameters = new EventHandlerParameters();
eventHandlerParameters.setCarrierTechnologyParameters(new EventRequestorCarrierTechnologyParameters());
@@ -73,7 +73,7 @@ public class EventRequestorConsumerTest {
}
@Test
- public void getSetPeeeredReference() {
+ void getSetPeeeredReference() {
final PeeredReference peeredReference =
new PeeredReference(EventHandlerPeeredMode.REQUESTOR, new ApexFileEventConsumer(),
new ApexFileEventProducer());
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorProducerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorProducerTest.java
index 5abf28ee6..0613efa5b 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorProducerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/eventrequestor/EventRequestorProducerTest.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
+ * Copyright (C) 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");
@@ -21,17 +21,17 @@
package org.onap.policy.apex.service.engine.event.impl.eventrequestor;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import java.util.Random;
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;
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.ApexEventRuntimeException;
@@ -41,8 +41,9 @@ import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerPeeredMode;
-@RunWith(MockitoJUnitRunner.class)
-public class EventRequestorProducerTest {
+@ExtendWith(MockitoExtension.class)
+class EventRequestorProducerTest {
+
private final Random random = new Random();
private EventRequestorProducer producer;
@@ -51,13 +52,13 @@ public class EventRequestorProducerTest {
@Mock
private EventRequestorConsumer apexConsumer;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
producer = new EventRequestorProducer();
}
@Test
- public void initWithEmptyParams() {
+ void initWithEmptyParams() {
final String producerName = RandomStringUtils.random(4);
final EventHandlerParameters eventHandlerParameters = new EventHandlerParameters();
@@ -66,7 +67,7 @@ public class EventRequestorProducerTest {
}
@Test
- public void initNotPeered() {
+ void initNotPeered() {
final String producerName = RandomStringUtils.random(4);
final EventHandlerParameters eventHandlerParameters = new EventHandlerParameters();
eventHandlerParameters.setCarrierTechnologyParameters(new EventRequestorCarrierTechnologyParameters());
@@ -76,7 +77,7 @@ public class EventRequestorProducerTest {
}
@Test
- public void getName() throws ApexEventException {
+ void getName() throws ApexEventException {
final String expected = RandomStringUtils.random(4);
final EventHandlerParameters eventHandlerParameters = new EventHandlerParameters();
eventHandlerParameters.setCarrierTechnologyParameters(new EventRequestorCarrierTechnologyParameters());
@@ -89,7 +90,7 @@ public class EventRequestorProducerTest {
}
@Test
- public void getSetPeeredReference() {
+ void getSetPeeredReference() {
final PeeredReference peeredReference = new PeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, apexConsumer,
apexProducer);
producer.setPeeredReference(EventHandlerPeeredMode.SYNCHRONOUS, peeredReference);
@@ -99,7 +100,7 @@ public class EventRequestorProducerTest {
}
@Test
- public void sendEventNoRequestor() {
+ void sendEventNoRequestor() {
final int id = random.nextInt(1000);
assertThatThrownBy(() -> producer.sendEvent(id, null, null, null))
@@ -107,7 +108,7 @@ public class EventRequestorProducerTest {
}
@Test
- public void sendEventNoEventRequestorConsumer() {
+ void sendEventNoEventRequestorConsumer() {
final int id = random.nextInt(1000);
final ApexFileEventConsumer fileEventConsumer = Mockito.mock(ApexFileEventConsumer.class);
@@ -122,7 +123,7 @@ public class EventRequestorProducerTest {
}
@Test
- public void sendEvent() {
+ void sendEvent() {
final int id = random.nextInt(1000);
final PeeredReference reference =
@@ -134,7 +135,7 @@ public class EventRequestorProducerTest {
}
@Test
- public void sendEventCached() {
+ void sendEventCached() {
final int id = random.nextInt(1000);
// Set event cache
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParametersTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParametersTest.java
index 26445c1fb..86bd7952f 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParametersTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParametersTest.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.
@@ -22,38 +22,40 @@ package org.onap.policy.apex.service.engine.event.impl.filecarrierplugin;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assume.assumeTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.io.File;
import java.io.IOException;
import java.net.URL;
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.common.parameters.ParameterRuntimeException;
import org.onap.policy.common.parameters.ValidationResult;
-public class FileCarrierTechnologyParametersTest {
+class FileCarrierTechnologyParametersTest {
+
private final Random random = new Random();
private static final String APEX_RELATIVE_FILE_ROOT = "APEX_RELATIVE_FILE_ROOT";
private final String defaultApesRelativeFileRoot = System.getProperty(APEX_RELATIVE_FILE_ROOT);
private FileCarrierTechnologyParameters parameters;
private File tempFile;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
parameters = new FileCarrierTechnologyParameters();
}
/**
* Cleaning after testing.
*/
- @After
- public void tearDown() {
+ @AfterEach
+ void tearDown() {
if (tempFile != null) {
- tempFile.delete();
+ assertTrue(tempFile.delete());
}
if (defaultApesRelativeFileRoot != null) {
System.setProperty(APEX_RELATIVE_FILE_ROOT, defaultApesRelativeFileRoot);
@@ -63,7 +65,7 @@ public class FileCarrierTechnologyParametersTest {
}
@Test
- public void getSetFileName() {
+ void getSetFileName() {
final String fileName = RandomStringUtils.random(10);
parameters.setFileName(fileName);
assertThat(parameters.getFileName())
@@ -71,86 +73,86 @@ public class FileCarrierTechnologyParametersTest {
}
@Test
- public void isStandardIo() {
+ void isStandardIo() {
assertThat(parameters.isStandardIo()).isFalse();
}
@Test
- public void isStandardError() {
+ void isStandardError() {
assertThat(parameters.isStandardError()).isFalse();
}
@Test
- public void isStreamingMode() {
+ void isStreamingMode() {
assertThat(parameters.isStreamingMode()).isFalse();
}
@Test
- public void setStandardIo() {
+ void setStandardIo() {
final boolean standardIo = random.nextBoolean();
parameters.setStandardIo(standardIo);
assertThat(parameters.isStandardIo()).isEqualTo(standardIo);
}
@Test
- public void setStandardError() {
+ void setStandardError() {
final boolean standardError = random.nextBoolean();
parameters.setStandardError(standardError);
assertThat(parameters.isStandardError()).isEqualTo(standardError);
}
@Test
- public void getStartDelay() {
+ void getStartDelay() {
assertThat(parameters.getStartDelay()).isZero();
}
@Test
- public void setStartDelay() {
+ void setStartDelay() {
final long delay = random.nextInt();
parameters.setStartDelay(delay);
assertThat(parameters.getStartDelay()).isEqualTo(delay);
}
@Test
- public void getLabel() {
+ void getLabel() {
final String label = RandomStringUtils.random(10);
parameters.setLabel(label);
assertThat(parameters.getLabel()).isEqualTo(label);
}
@Test
- public void setName() {
+ void setName() {
final String name = RandomStringUtils.random(10);
assertThatThrownBy(() -> parameters.setName(name)).isInstanceOf(ParameterRuntimeException.class);
}
@Test
- public void getName() {
+ void getName() {
final String label = RandomStringUtils.random(10);
parameters.setLabel(label);
assertThat(parameters.getName()).isEqualTo(label);
}
@Test
- public void getStreamingMode() {
+ void getStreamingMode() {
assertThat(parameters.isStreamingMode()).isFalse();
}
@Test
- public void setStreamingMode() {
+ void setStreamingMode() {
final boolean streamingMode = random.nextBoolean();
parameters.setStreamingMode(streamingMode);
assertThat(parameters.isStreamingMode()).isEqualTo(streamingMode);
}
@Test
- public void validateFileNameNull() {
+ void validateFileNameNull() {
final ValidationResult result = parameters.validate();
assertThat(result.isValid()).isFalse();
}
@Test
- public void validateFileNameAbsolutePath() throws IOException {
+ void validateFileNameAbsolutePath() throws IOException {
tempFile = File.createTempFile("test_", ".tmp");
parameters.setFileName(tempFile.getAbsolutePath());
final ValidationResult result = parameters.validate();
@@ -158,7 +160,7 @@ public class FileCarrierTechnologyParametersTest {
}
@Test
- public void validateFileNameAbsolutePathNotExisting() {
+ void validateFileNameAbsolutePathNotExisting() {
parameters.setFileName(RandomStringUtils.randomAlphabetic(5) + ".tmp");
System.setProperty(APEX_RELATIVE_FILE_ROOT, System.getProperty("user.home"));
final ValidationResult result = parameters.validate();
@@ -166,14 +168,14 @@ public class FileCarrierTechnologyParametersTest {
}
@Test
- public void validateDirectoryName() {
+ void validateDirectoryName() {
parameters.setFileName(System.getProperty("user.dir"));
final ValidationResult result = parameters.validate();
assertThat(result.isValid()).isFalse();
}
@Test
- public void validateParentNotDirectory() {
+ void validateParentNotDirectory() {
final URL resource = FileCarrierTechnologyParameters.class
.getResource("FileCarrierTechnologyParameters.class");
assumeTrue(resource != null && "file".equalsIgnoreCase(resource.getProtocol()));
@@ -186,7 +188,7 @@ public class FileCarrierTechnologyParametersTest {
}
@Test
- public void validateParentDoesNOtExists() {
+ void validateParentDoesNOtExists() {
final File fileParent = new File(System.getProperty("user.home"), RandomStringUtils.randomAlphabetic(6));
final String fileName = RandomStringUtils.randomAlphabetic(5);
final String absolutePath = new File(fileParent, fileName).getAbsolutePath();
@@ -196,27 +198,21 @@ public class FileCarrierTechnologyParametersTest {
}
@Test
- public void validateDirectorNoSystemVariableSet() {
- final ValidationResult result = parameters.validate();
- assertThat(result.isValid()).isFalse();
- }
-
- @Test
- public void validateStandardIo() {
+ void validateStandardIo() {
parameters.setStandardIo(true);
final ValidationResult result = parameters.validate();
assertThat(result.isValid()).isTrue();
}
@Test
- public void validateStandardError() {
+ void validateStandardError() {
parameters.setStandardError(true);
final ValidationResult result = parameters.validate();
assertThat(result.isValid()).isTrue();
}
@Test
- public void validateNegativeDelay() {
+ void validateNegativeDelay() {
final long delay = random.nextInt() * -1;
parameters.setStartDelay(delay);
final ValidationResult result = parameters.validate();
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/ApexFileEventConsumerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/ApexFileEventConsumerTest.java
index 91e705624..385cbbb8a 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/ApexFileEventConsumerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/ApexFileEventConsumerTest.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.
@@ -26,8 +26,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.File;
import org.apache.commons.lang3.RandomStringUtils;
-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.impl.filecarrierplugin.FileCarrierTechnologyParameters;
import org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperCarrierTechnologyParameters;
@@ -36,7 +36,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.eventprotocol.EventProtocolTextTokenDelimitedParameters;
-public class ApexFileEventConsumerTest {
+class ApexFileEventConsumerTest {
private ApexFileEventConsumer consumer;
private EventHandlerParameters handlerParameters;
private File tempFile;
@@ -46,8 +46,8 @@ public class ApexFileEventConsumerTest {
*
* @throws Exception while file cannot be created
*/
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
consumer = new ApexFileEventConsumer();
handlerParameters = new EventHandlerParameters();
tempFile = File.createTempFile("afec", ".tmp");
@@ -55,14 +55,14 @@ public class ApexFileEventConsumerTest {
}
@Test
- public void initNoConsumerParameters() {
+ void initNoConsumerParameters() {
final String name = RandomStringUtils.randomAlphanumeric(4);
assertThatThrownBy(() -> consumer.init(name, null, null))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void initWrongCarrier() {
+ void initWrongCarrier() {
final String name = RandomStringUtils.randomAlphanumeric(4);
final CarrierTechnologyParameters technologyParameters = new SuperDooperCarrierTechnologyParameters();
handlerParameters.setCarrierTechnologyParameters(technologyParameters);
@@ -72,32 +72,32 @@ public class ApexFileEventConsumerTest {
}
@Test
- public void initWithoutReceiver() {
+ void initWithoutReceiver() {
final String name = RandomStringUtils.randomAlphanumeric(4);
- final EventHandlerParameters handlerParameters = new EventHandlerParameters();
+ final EventHandlerParameters parameters = new EventHandlerParameters();
final FileCarrierTechnologyParameters technologyParameters = new FileCarrierTechnologyParameters();
technologyParameters.setFileName(tempFile.getAbsolutePath());
final EventProtocolTextTokenDelimitedParameters params = new SuperTokenDelimitedEventProtocolParameters();
- handlerParameters.setCarrierTechnologyParameters(technologyParameters);
- handlerParameters.setEventProtocolParameters(params);
+ parameters.setCarrierTechnologyParameters(technologyParameters);
+ parameters.setEventProtocolParameters(params);
- assertThatCode(() -> consumer.init(name, handlerParameters, null))
+ assertThatCode(() -> consumer.init(name, parameters, null))
.doesNotThrowAnyException();
}
@Test
- public void getName() throws ApexEventException {
+ void getName() throws ApexEventException {
final String name = RandomStringUtils.randomAlphabetic(5);
- final EventHandlerParameters handlerParameters = new EventHandlerParameters();
+ final EventHandlerParameters parameters = new EventHandlerParameters();
final FileCarrierTechnologyParameters technologyParameters = new FileCarrierTechnologyParameters();
technologyParameters.setFileName(tempFile.getAbsolutePath());
final EventProtocolTextTokenDelimitedParameters params = new SuperTokenDelimitedEventProtocolParameters();
- handlerParameters.setCarrierTechnologyParameters(technologyParameters);
- handlerParameters.setEventProtocolParameters(params);
+ parameters.setCarrierTechnologyParameters(technologyParameters);
+ parameters.setEventProtocolParameters(params);
- consumer.init(name, handlerParameters, null);
+ consumer.init(name, parameters, null);
assertThat(consumer.getName()).isEqualTo(name);
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/HeaderDelimitedTextBlockReaderTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/HeaderDelimitedTextBlockReaderTest.java
index 6c595072f..b230d52ab 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/HeaderDelimitedTextBlockReaderTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/HeaderDelimitedTextBlockReaderTest.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.
@@ -27,23 +27,23 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.apache.commons.lang3.RandomStringUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class HeaderDelimitedTextBlockReaderTest {
+class HeaderDelimitedTextBlockReaderTest {
@Test
- public void readTextBlockWithDelimeter() throws IOException {
+ void readTextBlockWithDelimiter() throws IOException {
final String startToken = RandomStringUtils.randomAlphabetic(5);
final String endToken = RandomStringUtils.randomAlphabetic(6);
- final boolean delimeter = true;
+ final boolean delimiter = true;
final String text = RandomStringUtils.randomAlphanumeric(20);
final String expected = startToken + text;
// Prepare the stream
final InputStream stream = new ByteArrayInputStream(expected.getBytes(StandardCharsets.UTF_8));
final HeaderDelimitedTextBlockReader reader =
- new HeaderDelimitedTextBlockReader(startToken, endToken, delimeter);
+ new HeaderDelimitedTextBlockReader(startToken, endToken, delimiter);
reader.init(stream);
final TextBlock textBlock = reader.readTextBlock();
@@ -51,10 +51,10 @@ public class HeaderDelimitedTextBlockReaderTest {
}
@Test
- public void readTextBlockWithEndTokenDelimeter() throws IOException {
+ void readTextBlockWithEndTokenDelimiter() throws IOException {
final String startToken = RandomStringUtils.randomAlphabetic(5);
final String endToken = RandomStringUtils.randomAlphabetic(6);
- final boolean delimeter = true;
+ final boolean delimiter = true;
final String text = RandomStringUtils.randomAlphanumeric(20);
final String input = startToken + "\n" + text + "\n" + endToken + "\n" + text;
final String expected = startToken + "\n" + text + "\n" + endToken;
@@ -62,7 +62,7 @@ public class HeaderDelimitedTextBlockReaderTest {
final InputStream stream = new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8));
final HeaderDelimitedTextBlockReader reader =
- new HeaderDelimitedTextBlockReader(startToken, endToken, delimeter);
+ new HeaderDelimitedTextBlockReader(startToken, endToken, delimiter);
reader.init(stream);
final TextBlock textBlock = reader.readTextBlock();
@@ -70,16 +70,16 @@ public class HeaderDelimitedTextBlockReaderTest {
}
@Test
- public void readTextBlockWithoutDelimeter() throws IOException {
+ void readTextBlockWithoutDelimiter() throws IOException {
final String startToken = RandomStringUtils.randomAlphabetic(5);
final String endToken = RandomStringUtils.randomAlphabetic(6);
- final boolean delimeter = false;
+ final boolean delimiter = false;
final String text = RandomStringUtils.randomAlphanumeric(20);
// Prepare the stream
final InputStream stream = new ByteArrayInputStream(text.getBytes(StandardCharsets.UTF_8));
final HeaderDelimitedTextBlockReader reader =
- new HeaderDelimitedTextBlockReader(startToken, endToken, delimeter);
+ new HeaderDelimitedTextBlockReader(startToken, endToken, delimiter);
reader.init(stream);
final TextBlock textBlock = reader.readTextBlock();
@@ -87,10 +87,10 @@ public class HeaderDelimitedTextBlockReaderTest {
}
@Test
- public void readTextBlockWithEndTokenWithoutDelimeter() throws IOException {
+ void readTextBlockWithEndTokenWithoutDelimiter() throws IOException {
final String startToken = RandomStringUtils.randomAlphabetic(5);
final String endToken = RandomStringUtils.randomAlphabetic(6);
- final boolean delimeter = false;
+ final boolean delimiter = false;
final String text = RandomStringUtils.randomAlphanumeric(20);
final String input = startToken + "\n" + text + "\n" + endToken + "\n" + text;
final String expected = startToken + "\n" + text + "\n" + endToken;
@@ -98,7 +98,7 @@ public class HeaderDelimitedTextBlockReaderTest {
final InputStream stream = new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8));
final HeaderDelimitedTextBlockReader reader =
- new HeaderDelimitedTextBlockReader(startToken, endToken, delimeter);
+ new HeaderDelimitedTextBlockReader(startToken, endToken, delimiter);
reader.init(stream);
final TextBlock textBlock = reader.readTextBlock();
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockReaderFactoryTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockReaderFactoryTest.java
index 4fa42a727..0072535fb 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockReaderFactoryTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockReaderFactoryTest.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.
@@ -26,24 +26,24 @@ import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.apache.commons.lang3.RandomStringUtils;
-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.impl.apexprotocolplugin.ApexEventProtocolParameters;
import org.onap.policy.apex.service.engine.event.impl.jsonprotocolplugin.JsonEventProtocolParameters;
import org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperTokenDelimitedEventProtocolParameters;
import org.onap.policy.apex.service.parameters.eventprotocol.EventProtocolParameters;
-public class TextBlockReaderFactoryTest {
+class TextBlockReaderFactoryTest {
private TextBlockReaderFactory factory;
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() {
factory = new TextBlockReaderFactory();
}
@Test
- public void getTaggedReaderTextCharDelimitedParametersParams() throws ApexEventException {
+ void getTaggedReaderTextCharDelimitedParametersParams() throws ApexEventException {
final String text = RandomStringUtils.randomAlphanumeric(22);
final InputStream inputStream = prepareInputStream(text);
final EventProtocolParameters parameters = new JsonEventProtocolParameters();
@@ -53,7 +53,7 @@ public class TextBlockReaderFactoryTest {
}
@Test
- public void getTaggedReaderTextTokenDelimitedParams() throws ApexEventException {
+ void getTaggedReaderTextTokenDelimitedParams() throws ApexEventException {
final String text = RandomStringUtils.randomAlphanumeric(22);
final InputStream inputStream = prepareInputStream(text);
new ApexEventProtocolParameters();
@@ -64,7 +64,7 @@ public class TextBlockReaderFactoryTest {
}
@Test
- public void getTaggedReaderNotSupportedParams() {
+ void getTaggedReaderNotSupportedParams() {
final String text = RandomStringUtils.randomAlphanumeric(22);
final InputStream inputStream = prepareInputStream(text);
final EventProtocolParameters parameters = new ApexEventProtocolParameters();
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockTest.java
index 4390c3f3a..ff12c8860 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/consumer/TextBlockTest.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.
@@ -19,17 +19,17 @@
package org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Random;
import org.apache.commons.lang3.RandomStringUtils;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class TextBlockTest {
+class TextBlockTest {
private final Random random = new Random();
@Test
- public void isEndOfText() {
+ void isEndOfText() {
final boolean endOfText = random.nextBoolean();
final TextBlock textBlock = new TextBlock(endOfText, null);
@@ -37,7 +37,7 @@ public class TextBlockTest {
}
@Test
- public void getText() {
+ void getText() {
final boolean endOfText = random.nextBoolean();
final String text = RandomStringUtils.randomAlphanumeric(8);
final TextBlock textBlock = new TextBlock(endOfText, text);
@@ -46,7 +46,7 @@ public class TextBlockTest {
}
@Test
- public void setText() {
+ void setText() {
final boolean endOfText = random.nextBoolean();
final String text = RandomStringUtils.randomAlphanumeric(8);
final TextBlock textBlock = new TextBlock(endOfText, null);
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/producer/ApexFileEventProducerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/producer/ApexFileEventProducerTest.java
index 1ac1cdd7c..89ffca74b 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/producer/ApexFileEventProducerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/producer/ApexFileEventProducerTest.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.
@@ -28,16 +28,16 @@ import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
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.ApexEventRuntimeException;
import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.FileCarrierTechnologyParameters;
import org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperDooperCarrierTechnologyParameters;
import org.onap.policy.apex.service.parameters.eventhandler.EventHandlerParameters;
-public class ApexFileEventProducerTest {
+class ApexFileEventProducerTest {
private final PrintStream out = System.out;
private final Random random = new Random();
private ApexFileEventProducer eventProducer;
@@ -47,27 +47,27 @@ public class ApexFileEventProducerTest {
/**
* Prepare for testing.
*/
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
eventProducer = new ApexFileEventProducer();
parameters = new EventHandlerParameters();
technologyParameters = new FileCarrierTechnologyParameters();
}
- @After
- public void tearDown() {
+ @AfterEach
+ void tearDown() {
System.setOut(out);
}
@Test
- public void initNullParams() {
+ void initNullParams() {
final String name = RandomStringUtils.randomAlphabetic(5);
assertThatThrownBy(() -> eventProducer.init(name, null))
.isInstanceOf(ApexEventException.class);
}
@Test
- public void initParamsInvalidCarrier() {
+ void initParamsInvalidCarrier() {
final String name = RandomStringUtils.randomAlphabetic(5);
parameters.setCarrierTechnologyParameters(new SuperDooperCarrierTechnologyParameters());
assertThatThrownBy(() -> eventProducer.init(name, parameters))
@@ -75,7 +75,7 @@ public class ApexFileEventProducerTest {
}
@Test
- public void initParamsWithStandardError() {
+ void initParamsWithStandardError() {
final String name = RandomStringUtils.randomAlphabetic(5);
technologyParameters.setStandardError(true);
@@ -86,7 +86,7 @@ public class ApexFileEventProducerTest {
}
@Test
- public void initParamsWithStandardIo() {
+ void initParamsWithStandardIo() {
final String name = RandomStringUtils.randomAlphabetic(5);
technologyParameters.setStandardIo(true);
@@ -96,7 +96,7 @@ public class ApexFileEventProducerTest {
}
@Test
- public void initParamsWithFileIsDirectory() {
+ void initParamsWithFileIsDirectory() {
final String name = RandomStringUtils.randomAlphabetic(5);
final String fileName = System.getProperty("user.dir");
@@ -108,24 +108,14 @@ public class ApexFileEventProducerTest {
}
@Test
- public void initParamsWithDelay() {
- final String name = RandomStringUtils.randomAlphabetic(5);
- technologyParameters.setStandardIo(true);
- parameters.setCarrierTechnologyParameters(technologyParameters);
-
- assertThatCode(() -> eventProducer.init(name, parameters))
- .doesNotThrowAnyException();
- }
-
- @Test
- public void sendEventWrongEvent() throws ApexEventException {
+ void sendEventWrongEvent() throws ApexEventException {
final long executionId = random.nextLong();
final String eventName = RandomStringUtils.randomAlphanumeric(4);
final String producerName = RandomStringUtils.randomAlphanumeric(5);
final Object event = new Object();
technologyParameters.setStandardIo(true);
- final EventHandlerParameters parameters = new EventHandlerParameters();
+ parameters = new EventHandlerParameters();
parameters.setCarrierTechnologyParameters(technologyParameters);
ApexFileEventProducer apexFileEventProducer = new ApexFileEventProducer();
@@ -135,7 +125,7 @@ public class ApexFileEventProducerTest {
}
@Test
- public void sendEvent() throws ApexEventException {
+ void sendEvent() throws ApexEventException {
// Prepare output stream to read data
final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
@@ -143,7 +133,7 @@ public class ApexFileEventProducerTest {
// Prepare producer
final String producerName = RandomStringUtils.randomAlphanumeric(5);
technologyParameters.setStandardIo(true);
- final EventHandlerParameters parameters = new EventHandlerParameters();
+ parameters = new EventHandlerParameters();
parameters.setCarrierTechnologyParameters(technologyParameters);
eventProducer.init(producerName, parameters);
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java
index b5b68c9fc..5232c3845 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexCommandLineArgumentsTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,11 +24,10 @@ package org.onap.policy.apex.service.engine.main;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.After;
-import org.junit.Test;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.cmd.CommandLineException;
/**
@@ -36,14 +35,15 @@ import org.onap.policy.common.utils.cmd.CommandLineException;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class ApexCommandLineArgumentsTest {
- @After
- public void clearRelativeFileRoot() {
+class ApexCommandLineArgumentsTest {
+
+ @AfterEach
+ void clearRelativeFileRoot() {
System.clearProperty("APEX_RELATIVE_FILE_ROOT");
}
@Test
- public void testCommandLineArguments() throws ApexException, CommandLineException {
+ void testCommandLineArguments() throws CommandLineException {
final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
final String[] args01 = {"-h"};
@@ -68,74 +68,74 @@ public class ApexCommandLineArgumentsTest {
}
@Test
- public void testCommandLineArgumentsExceptions() throws ApexException, CommandLineException {
+ void testCommandLineArgumentsExceptions() throws CommandLineException {
final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
final String[] args00 = {""};
apexArguments.parse(args00);
- assertThatThrownBy(() -> apexArguments.validateInputFiles())
- .hasMessage("Tosca Policy file was not specified as an argument");
+ assertThatThrownBy(apexArguments::validateInputFiles)
+ .hasMessage("Tosca Policy file was not specified as an argument");
final String[] args05 = {"-a"};
assertThatThrownBy(() -> apexArguments.parse(args05)).hasMessage("invalid command line arguments specified")
- .hasRootCauseMessage("Unrecognized option: -a");
+ .hasRootCauseMessage("Unrecognized option: -a");
final String[] args07 = {"-p", "goodbye", "-h", "aaa"};
assertThatThrownBy(() -> apexArguments.parse(args07))
- .hasMessage("too many command line arguments specified: [-p, goodbye, -h, aaa]");
+ .hasMessage("too many command line arguments specified: [-p, goodbye, -h, aaa]");
}
@Test
- public void testCommandLineFileParameters() throws ApexException, CommandLineException {
+ void testCommandLineFileParameters() throws CommandLineException {
final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
final String[] args02 = {"-p", "src/test/resources/parameters/goodParams.json"};
apexArguments.parse(args02);
- assertThatCode(() -> apexArguments.validateInputFiles()).doesNotThrowAnyException();
+ assertThatCode(apexArguments::validateInputFiles).doesNotThrowAnyException();
}
@Test
- public void testCommandLineFileParametersExceptions() throws ApexException, CommandLineException {
+ void testCommandLineFileParametersExceptions() {
final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
final String[] args00 = {"-c", "zooby"};
assertThatThrownBy(() -> apexArguments.parse(args00)).hasMessage("invalid command line arguments specified")
- .hasRootCauseMessage("Unrecognized option: -c");
+ .hasRootCauseMessage("Unrecognized option: -c");
final String[] args01 = {"-p"};
assertThatThrownBy(() -> apexArguments.parse(args01)).hasMessage("invalid command line arguments specified")
- .hasRootCauseMessage("Missing argument for option: p");
+ .hasRootCauseMessage("Missing argument for option: p");
final String[] args03 = {"-p", "src/test/resources/parameters/goodParams.json", "-m", "zooby"};
assertThatThrownBy(() -> apexArguments.parse(args03)).hasMessage("invalid command line arguments specified")
- .hasRootCauseMessage("Unrecognized option: -m");
+ .hasRootCauseMessage("Unrecognized option: -m");
}
@Test
- public void testCommandLineRelativeRootParameters() throws ApexException, CommandLineException {
+ void testCommandLineRelativeRootParameters() throws CommandLineException {
final ApexCommandLineArguments apexArguments = new ApexCommandLineArguments();
final String[] args00 = {"-p", "src/test/resources/parameters/goodParams.json", "-rfr", "zooby"};
apexArguments.parse(args00);
- assertThatThrownBy(() -> apexArguments.validateInputFiles())
- .hasMessageContaining("zooby\" does not exist or is not a directory");
+ assertThatThrownBy(apexArguments::validateInputFiles)
+ .hasMessageContaining("zooby\" does not exist or is not a directory");
final String[] args01 = {"-rfr"};
assertThatThrownBy(() -> apexArguments.parse(args01)).hasMessage("invalid command line arguments specified")
- .hasRootCauseMessage("Missing argument for option: rfr");
+ .hasRootCauseMessage("Missing argument for option: rfr");
final String[] args02 = {"-p", "src/test/resources/parameters/goodParams.json", "-rfr", "pom.xml"};
apexArguments.parse(args02);
- assertThatThrownBy(() -> apexArguments.validateInputFiles())
- .hasMessageContaining("pom.xml\" does not exist or is not a directory");
+ assertThatThrownBy(apexArguments::validateInputFiles)
+ .hasMessageContaining("pom.xml\" does not exist or is not a directory");
final String[] args03 = {"-p", "src/test/resources/parameters/goodParams.json", "-rfr", "target"};
apexArguments.parse(args03);
- assertThatCode(() -> apexArguments.validateInputFiles()).doesNotThrowAnyException();
+ assertThatCode(apexArguments::validateInputFiles).doesNotThrowAnyException();
final String[] args04 = {"-p", "parameters/goodParamsRelative.json", "-rfr", "src/test/resources"};
apexArguments.parse(args04);
- assertThatCode(() -> apexArguments.validateInputFiles()).doesNotThrowAnyException();
+ assertThatCode(apexArguments::validateInputFiles).doesNotThrowAnyException();
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
index 29a3e0f00..f09dfd785 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexMainTest.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -25,25 +25,25 @@ package org.onap.policy.apex.service.engine.main;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
-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.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.concurrent.TimeUnit;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+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.service.ModelService;
import org.onap.policy.common.parameters.ParameterService;
/**
* Test the ApexMain class.
*/
-public class ApexMainTest {
+class ApexMainTest {
+
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
private final PrintStream stdout = System.out;
private ApexMain apexMain1;
@@ -54,8 +54,8 @@ public class ApexMainTest {
*
* @throws Exception if an error occurs
*/
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
System.setOut(new PrintStream(outContent));
}
@@ -64,8 +64,8 @@ public class ApexMainTest {
*
* @throws Exception if an error occurs
*/
- @After
- public void teardown() throws Exception {
+ @AfterEach
+ void teardown() throws Exception {
if (null != apexMain1) {
apexMain1.shutdown();
}
@@ -76,46 +76,46 @@ public class ApexMainTest {
}
@Test
- public void testNullParameters() throws ApexException {
+ void testNullParameters() {
ApexMain.main(null);
await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
- .contains("Tosca Policy file was not specified as an argument"));
+ .contains("Tosca Policy file was not specified as an argument"));
assertThat(outContent.toString())
.contains("Tosca Policy file was not specified as an argument");
}
@Test
- public void testBadArguments() throws ApexException {
- String[] args = { "-whee" };
+ void testBadArguments() {
+ String[] args = {"-whee"};
apexMain1 = new ApexMain(args);
await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
- .contains("invalid command line arguments specified"));
+ .contains("invalid command line arguments specified"));
assertNotNull(apexMain1);
}
@Test
- public void testHelp() throws ApexException {
- String[] args = { "-h" };
+ void testHelp() {
+ String[] args = {"-h"};
apexMain1 = new ApexMain(args);
await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
- .contains("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
+ .contains("usage: org.onap.policy.apex.service.engine.main.ApexMain [options...]"));
assertNotNull(apexMain1);
}
@Test
- public void testBadParameters() throws ApexException {
- String[] args = { "-p", "src/test/resources/parameters/badParams.json" };
+ void testBadParameters() {
+ String[] args = {"-p", "src/test/resources/parameters/badParams.json"};
apexMain1 = new ApexMain(args);
await().atMost(200, TimeUnit.MILLISECONDS).until(() -> outContent.toString()
- .contains("item has status INVALID"));
+ .contains("item has status INVALID"));
assertNotNull(apexMain1);
}
@Test
- public void testCorrectParameters() throws ApexException {
+ void testCorrectParameters() {
String[] args = {"-p", "src/test/resources/parameters/correctParams.json"};
apexMain1 = new ApexMain(args);
@@ -126,7 +126,7 @@ public class ApexMainTest {
}
@Test
- public void testJavaProperties() throws ApexException {
+ void testJavaProperties() {
String[] args = {"-p", "src/test/resources/parameters/correctParamsJavaProperties.json"};
apexMain1 = new ApexMain(args);
@@ -139,7 +139,7 @@ public class ApexMainTest {
}
@Test
- public void testCorrectParametersWithMultiplePolicies() throws ApexException {
+ void testCorrectParametersWithMultiplePolicies() {
String[] args1 = {"-p", "src/test/resources/parameters/correctParams.json"};
String[] args2 = {"-p", "src/test/resources/parameters/correctParams2.json"};
apexMain1 = new ApexMain(args1);
@@ -156,7 +156,7 @@ public class ApexMainTest {
}
@Test
- public void testInCorrectParametersWithMultiplePolicies() throws ApexException {
+ void testInCorrectParametersWithMultiplePolicies() {
String[] args = {"-p", "src/test/resources/parameters/correctParams.json"};
apexMain1 = new ApexMain(args);
apexMain2 = new ApexMain(args);
@@ -168,7 +168,7 @@ public class ApexMainTest {
}
@Test
- public void testInvalidArgsWithMultiplePolicies() throws ApexException {
+ void testInvalidArgsWithMultiplePolicies() {
String[] args = {"-c", "file1", "-m", "file2"};
apexMain1 = new ApexMain(args);
assertFalse(apexMain1.isAlive());
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java
index 6213cae1f..59ebfe50d 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/main/ApexPolicyStatisticsManagerTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,27 +21,27 @@
package org.onap.policy.apex.service.engine.main;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import io.prometheus.client.CollectorRegistry;
-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.utils.resources.PrometheusUtils;
-public class ApexPolicyStatisticsManagerTest {
+class ApexPolicyStatisticsManagerTest {
private ApexPolicyStatisticsManager statisticsManager;
/**
* Starts the statisticsManager object for tests.
*/
- @Before
- public void setup() {
+ @BeforeEach
+ void setup() {
statisticsManager = new ApexPolicyStatisticsManager();
}
@Test
- public void testUpdatePolicyDeployCounter() {
+ void testUpdatePolicyDeployCounter() {
statisticsManager.updatePolicyDeployCounter(false);
assertDeploys(1, 0, 1);
@@ -52,7 +52,7 @@ public class ApexPolicyStatisticsManagerTest {
}
@Test
- public void testUpdatePolicyExecutedCounter() {
+ void testUpdatePolicyExecutedCounter() {
statisticsManager.updatePolicyExecutedCounter(true);
assertExecuted(1, 1, 0);
@@ -61,7 +61,7 @@ public class ApexPolicyStatisticsManagerTest {
}
@Test
- public void testUpdatePolicyUndeployCounter() {
+ void testUpdatePolicyUndeployCounter() {
statisticsManager.updatePolicyUndeployCounter(false);
assertUndeploys(1, 0, 1);
@@ -91,11 +91,11 @@ public class ApexPolicyStatisticsManagerTest {
private void checkDeploymentsMetrics(String operation) {
final var defaultRegistry = CollectorRegistry.defaultRegistry;
Double totalCount = defaultRegistry.getSampleValue("pdpa_policy_deployments_total",
- new String[]{"operation", "status"}, new String[]{operation, "TOTAL"});
+ new String[] {"operation", "status"}, new String[] {operation, "TOTAL"});
Double successCount = defaultRegistry.getSampleValue("pdpa_policy_deployments_total",
- new String[]{"operation", "status"}, new String[]{operation, "SUCCESS"});
+ new String[] {"operation", "status"}, new String[] {operation, "SUCCESS"});
Double failCount = defaultRegistry.getSampleValue("pdpa_policy_deployments_total",
- new String[]{"operation", "status"}, new String[]{operation, "FAIL"});
+ new String[] {"operation", "status"}, new String[] {operation, "FAIL"});
if (PrometheusUtils.DEPLOY_OPERATION.equals(operation)) {
assertEquals(totalCount.intValue(), statisticsManager.getPolicyDeployCount());
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java
index dd76374d8..20fea1ce7 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ApexParametersTest.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) 2020 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -25,13 +25,13 @@ package org.onap.policy.apex.service.engine.parameters;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.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 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;
@@ -40,10 +40,10 @@ import org.onap.policy.common.parameters.ParameterException;
/**
* Test the ApexParameters class.
*/
-public class ApexParametersTest {
+class ApexParametersTest {
@Test
- public void testJavaPropertiesOk() throws ParameterException {
+ void testJavaPropertiesOk() throws ParameterException {
final String[] args = {"-p", "src/test/resources/parameters/javaPropertiesOK.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -57,7 +57,7 @@ public class ApexParametersTest {
}
@Test
- public void testJavaPropertiesEmpty() throws ParameterException {
+ void testJavaPropertiesEmpty() throws ParameterException {
final String[] args = {"-p", "src/test/resources/parameters/javaPropertiesEmpty.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -67,7 +67,7 @@ public class ApexParametersTest {
}
@Test
- public void testJavaPropertiesBad() throws ParameterException {
+ void testJavaPropertiesBad() {
final String[] args = {"-p", "src/test/resources/parameters/javaPropertiesBad.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -80,7 +80,7 @@ public class ApexParametersTest {
}
@Test
- public void testPolicyModelFromMetadata() throws ParameterException {
+ void testPolicyModelFromMetadata() throws ParameterException {
// Policy Models provided only in metadata.
final String[] args = {"-p", "src/test/resources/parameters/policyModelFromMetadata.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -95,7 +95,7 @@ public class ApexParametersTest {
}
@Test
- public void testPolicyModelFromProperties() throws ParameterException {
+ void testPolicyModelFromProperties() throws ParameterException {
// Policy models provided in properties under EngineServiceParameters for backward compatibility
final String[] args = {"-p", "src/test/resources/parameters/policyModelFromProperties.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -110,7 +110,7 @@ public class ApexParametersTest {
}
@Test
- public void testPolicyModelFromPropertiesAndMetadata() throws ParameterException {
+ void testPolicyModelFromPropertiesAndMetadata() throws ParameterException {
// Policy models provided in both properties and in metadata. policyModels in metadata takes precedence
final String[] args = {"-p", "src/test/resources/parameters/policyModelMultiple.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -125,7 +125,7 @@ public class ApexParametersTest {
}
@Test
- public void testGettersSetters() {
+ void testGettersSetters() {
ApexParameters pars = new ApexParameters();
assertNotNull(pars);
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ContextParameterTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ContextParameterTests.java
index a55afbed4..2c02f14ca 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ContextParameterTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ContextParameterTests.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) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,9 +23,10 @@
package org.onap.policy.apex.service.engine.parameters;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
-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.engine.parameters.dummyclasses.SuperDooperDistributorParameters;
import org.onap.policy.apex.service.parameters.ApexParameterHandler;
@@ -37,10 +38,10 @@ import org.onap.policy.common.parameters.ParameterException;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class ContextParameterTests {
+class ContextParameterTests {
@Test
- public void testNoParamsTest() {
+ void testNoParamsTest() {
final String[] args = {"-p", "src/test/resources/parameters/serviceContextNoParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -51,18 +52,18 @@ public class ContextParameterTests {
}
@Test
- public void testBadParamsTest() {
+ void testBadParamsTest() {
final String[] args = {"-p", "src/test/resources/parameters/serviceContextBadParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("error reading parameters from \"src/test/resources/parameters/serviceContextBadParams.json\""
- + "\n(ParameterRuntimeException):failed to deserialize the parameters for "
- + "\"contextParameters\" to parameter class " + "\"hello\"\njava.lang.ClassNotFoundException: hello");
+ .hasMessageContaining("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceContextBadParams.json\"")
+ .hasMessageContaining("class " + "\"hello\"\njava.lang.ClassNotFoundException: hello");
}
@Test
- public void testBadPluginParamNameTest() {
+ void testBadPluginParamNameTest() {
final String[] args = {"-p", "src/test/resources/parameters/serviceContextBadPluginNameParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -74,19 +75,20 @@ public class ContextParameterTests {
}
@Test
- public void testBadClassParamTest() {
+ void testBadClassParamTest() {
final String[] args = {"-p", "src/test/resources/parameters/serviceContextBadClassParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments)).hasMessage(
- "error reading parameters from " + "\"src/test/resources/parameters/serviceContextBadClassParams.json\""
- + "\n(ParameterRuntimeException):failed to deserialize " + "the parameters for \"contextParameters\""
- + " to parameter class \"java.lang.Integer\"\ncom.google.gson.JsonSyntaxException: "
- + "java.lang.IllegalStateException: Expected NUMBER but was BEGIN_OBJECT at path $");
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessageContaining("error reading parameters from "
+ + "\"src/test/resources/parameters/serviceContextBadClassParams.json\"")
+ .hasMessageContaining("(ParameterRuntimeException):failed to deserialize the parameters for "
+ + "\"contextParameters\" to parameter class \"java.lang.Integer\"\ncom.google.gson.JsonSyntaxException"
+ + ": java.lang.IllegalStateException: Expected NUMBER but was BEGIN_OBJECT at path $");
}
@Test
- public void testBadPluginClassTest() {
+ void testBadPluginClassTest() {
final String[] args = {"-p", "src/test/resources/parameters/serviceContextBadPluginClassParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -102,7 +104,7 @@ public class ContextParameterTests {
}
@Test
- public void testOkFlushParamTest() throws ParameterException {
+ void testOkFlushParamTest() throws ParameterException {
final String[] args = {"-p", "src/test/resources/parameters/serviceContextOKFlushParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -115,7 +117,7 @@ public class ContextParameterTests {
}
@Test
- public void testOkDefaultParamTest() throws ParameterException {
+ void testOkDefaultParamTest() throws ParameterException {
final String[] args = {"-p", "src/test/resources/parameters/serviceContextOKDefaultParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -128,7 +130,7 @@ public class ContextParameterTests {
}
@Test
- public void testOkDistParamTest() throws ParameterException {
+ void testOkDistParamTest() throws ParameterException {
final String[] args = {"-p", "src/test/resources/parameters/serviceContextOKDistParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -142,7 +144,7 @@ public class ContextParameterTests {
}
@Test
- public void testOkFullDefaultParamTest() throws ParameterException {
+ void testOkFullDefaultParamTest() throws ParameterException {
final String[] args = {"-p", "src/test/resources/parameters/goodParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -164,7 +166,7 @@ public class ContextParameterTests {
}
@Test
- public void testOkFullParamTest() throws ParameterException {
+ void testOkFullParamTest() throws ParameterException {
final String[] args = {"-p", "src/test/resources/parameters/serviceContextOKFullParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -186,13 +188,13 @@ public class ContextParameterTests {
infinispanParameters.getClass().getName());
assertEquals("my/lovely/configFile.xml", infinispanParameters.getConfigFile());
assertEquals("holy/stone.xml", infinispanParameters.getJgroupsFile());
- assertEquals(false, infinispanParameters.isPreferIPv4Stack());
+ assertFalse(infinispanParameters.isPreferIPv4Stack());
assertEquals("fatherted", infinispanParameters.getJgroupsBindAddress());
}
@Test
- public void testBadClassDistParamTest() {
+ void testBadClassDistParamTest() {
final String[] args = {"-p", "src/test/resources/parameters/serviceContextBadClassDistParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -207,7 +209,7 @@ public class ContextParameterTests {
}
@Test
- public void testBadClassLockParamTest() {
+ void testBadClassLockParamTest() {
final String[] args = {"-p", "src/test/resources/parameters/serviceContextBadClassLockParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -222,7 +224,7 @@ public class ContextParameterTests {
}
@Test
- public void testBadClassPersistParamTest() {
+ void testBadClassPersistParamTest() {
final String[] args = {"-p", "src/test/resources/parameters/serviceContextBadClassPersistParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ExecutorParameterTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ExecutorParameterTests.java
index 92a7b7d54..ad1dc442d 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ExecutorParameterTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ExecutorParameterTests.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) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,10 +23,10 @@
package org.onap.policy.apex.service.engine.parameters;
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.Test;
+import org.junit.jupiter.api.AfterEach;
+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;
@@ -37,37 +37,38 @@ import org.onap.policy.common.parameters.ParameterException;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class ExecutorParameterTests {
- @After
- public void resetRelativeFileRoot() {
+class ExecutorParameterTests {
+
+ @AfterEach
+ void resetRelativeFileRoot() {
System.clearProperty("APEX_RELATIVE_FILE_ROOT");
}
@Test
- public void testNoParamsTest() throws ParameterException {
+ void testNoParamsTest() throws ParameterException {
final String[] args = {"-p", "src/test/resources/parameters/serviceExecutorNoParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
assertEquals(0,
- parameters.getEngineServiceParameters().getEngineParameters().getExecutorParameterMap().size());
+ parameters.getEngineServiceParameters().getEngineParameters().getExecutorParameterMap().size());
}
@Test
- public void testBadParamsTest() {
+ void testBadParamsTest() {
final String[] args = {"-p", "src/test/resources/parameters/serviceExecutorBadParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
.hasMessage("error reading parameters from "
- + "\"src/test/resources/parameters/serviceExecutorBadParams.json\"\n"
- + "(ParameterRuntimeException):value of \"executorParameters:ZOOBY\" entry is not "
- + "a parameter JSON object");
+ + "\"src/test/resources/parameters/serviceExecutorBadParams.json\"\n"
+ + "(ParameterRuntimeException):value of \"executorParameters:ZOOBY\" entry is not "
+ + "a parameter JSON object");
}
@Test
- public void testNoExecutorParamsTest() {
+ void testNoExecutorParamsTest() {
final String[] args = {"-p", "src/test/resources/parameters/serviceExecutorNoExecutorParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -79,7 +80,7 @@ public class ExecutorParameterTests {
}
@Test
- public void testEmptyParamsTest() {
+ void testEmptyParamsTest() {
final String[] args = {"-p", "src/test/resources/parameters/serviceExecutorEmptyParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -91,7 +92,7 @@ public class ExecutorParameterTests {
}
@Test
- public void testBadPluginParamNameTest() {
+ void testBadPluginParamNameTest() {
final String[] args = {"-p", "src/test/resources/parameters/serviceExecutorBadPluginNameParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -103,7 +104,7 @@ public class ExecutorParameterTests {
}
@Test
- public void testBadPluginParamObjectTest() {
+ void testBadPluginParamObjectTest() {
final String[] args = {"-p", "src/test/resources/parameters/serviceExecutorBadPluginValueObjectParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -115,7 +116,7 @@ public class ExecutorParameterTests {
}
@Test
- public void testBadPluginParamBlankTest() {
+ void testBadPluginParamBlankTest() {
final String[] args = {"-p", "src/test/resources/parameters/serviceExecutorBadPluginValueBlankParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -127,20 +128,20 @@ public class ExecutorParameterTests {
}
@Test
- public void testBadPluginParamValueTest() {
+ void testBadPluginParamValueTest() {
final String[] args = {"-p", "src/test/resources/parameters/serviceExecutorBadPluginValueParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
- .hasMessage("error reading parameters from"
- + " \"src/test/resources/parameters/serviceExecutorBadPluginValueParams.json\"\n"
- + "(ParameterRuntimeException):failed to deserialize the parameters "
+ .hasMessageContaining("error reading parameters from"
+ + " \"src/test/resources/parameters/serviceExecutorBadPluginValueParams.json\"\n")
+ .hasMessageContaining("(ParameterRuntimeException):failed to deserialize the parameters "
+ "for \"executorParameters:LOOBY\" to parameter class \"helloworld\"\n"
+ "java.lang.ClassNotFoundException: helloworld");
}
@Test
- public void testGoodParametersTest() throws ParameterException {
+ void testGoodParametersTest() throws ParameterException {
final String[] args = {"-p", "src/test/resources/parameters/goodParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -155,7 +156,7 @@ public class ExecutorParameterTests {
}
@Test
- public void testRelativeParametersTest() throws ParameterException {
+ void testRelativeParametersTest() throws ParameterException {
// @formatter:off
final String[] args = {
"-rfr",
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java
index e37da3540..7257855a3 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ParameterTests.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) 2020 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -24,13 +24,14 @@
package org.onap.policy.apex.service.engine.parameters;
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.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.file.NoSuchFileException;
import java.util.Arrays;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.ApexFileEventConsumer;
import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.producer.ApexFileEventProducer;
import org.onap.policy.apex.service.engine.main.ApexCommandLineArguments;
@@ -48,9 +49,9 @@ import org.onap.policy.common.parameters.ParameterException;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class ParameterTests {
+class ParameterTests {
@Test
- public void testInvalidParametersNoFileTest() throws ParameterException {
+ void testInvalidParametersNoFileTest() {
final String[] args = {"-p", "src/test/resources/parameters/invalidNoFile.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -59,7 +60,7 @@ public class ParameterTests {
}
@Test
- public void testInvalidParametersEmptyTest() {
+ void testInvalidParametersEmptyTest() {
final String[] args = {"-p", "src/test/resources/parameters/empty.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -68,7 +69,7 @@ public class ParameterTests {
}
@Test
- public void testInvalidParametersNoParamsTest() {
+ void testInvalidParametersNoParamsTest() {
final String[] args = {"-p", "src/test/resources/parameters/noParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -81,7 +82,7 @@ public class ParameterTests {
}
@Test
- public void testInvalidParametersBlankParamsTest() {
+ void testInvalidParametersBlankParamsTest() {
final String[] args = {"-p", "src/test/resources/parameters/blankParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -96,7 +97,7 @@ public class ParameterTests {
}
@Test
- public void testInvalidParametersTest() {
+ void testInvalidParametersTest() {
final String[] args = {"-p", "src/test/resources/parameters/badParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -109,15 +110,15 @@ public class ParameterTests {
.hasMessageContaining("\"instanceCount\" value \"-345\" INVALID, is below the minimum")
.hasMessageContaining("\"deploymentPort\" value \"65536\" INVALID, exceeds the maximum")
.hasMessageContaining("eventOutputParameters", "FirstProducer", "EventHandlerParameters",
- "FileCarrierTechnologyParameters")
+ "FileCarrierTechnologyParameters")
.hasMessageContaining("\"fileName\" value \"null\" INVALID, is blank")
.hasMessageContaining("eventInputParameters", "TheFileConsumer1", "EventHandlerParameters",
- "FileCarrierTechnologyParameters")
+ "FileCarrierTechnologyParameters")
.hasMessageContaining("\"fileName\" value \"null\" INVALID, is blank");
}
@Test
- public void testGoodParametersTest() throws ParameterException {
+ void testGoodParametersTest() throws ParameterException {
final String[] args = {"-p", "src/test/resources/parameters/goodParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -128,40 +129,40 @@ public class ParameterTests {
assertTrue(parameters.getEventOutputParameters().containsKey("FirstProducer"));
assertTrue(parameters.getEventOutputParameters().containsKey("MyOtherProducer"));
assertEquals("FILE", parameters.getEventOutputParameters().get("FirstProducer")
- .getCarrierTechnologyParameters().getLabel());
+ .getCarrierTechnologyParameters().getLabel());
assertEquals("FILE", parameters.getEventOutputParameters().get("MyOtherProducer")
- .getCarrierTechnologyParameters().getLabel());
+ .getCarrierTechnologyParameters().getLabel());
assertEquals(ApexFileEventProducer.class.getName(), parameters.getEventOutputParameters()
- .get("MyOtherProducer").getCarrierTechnologyParameters().getEventProducerPluginClass());
+ .get("MyOtherProducer").getCarrierTechnologyParameters().getEventProducerPluginClass());
assertEquals(ApexFileEventConsumer.class.getName(), parameters.getEventOutputParameters()
- .get("MyOtherProducer").getCarrierTechnologyParameters().getEventConsumerPluginClass());
+ .get("MyOtherProducer").getCarrierTechnologyParameters().getEventConsumerPluginClass());
assertEquals("JSON",
- parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters().getLabel());
+ parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters().getLabel());
assertEquals("JSON", parameters.getEventOutputParameters().get("MyOtherProducer")
- .getEventProtocolParameters().getLabel());
+ .getEventProtocolParameters().getLabel());
assertTrue(parameters.getEventInputParameters().containsKey("TheFileConsumer1"));
assertTrue(parameters.getEventInputParameters().containsKey("MySuperDooperConsumer1"));
assertEquals("FILE", parameters.getEventInputParameters().get("TheFileConsumer1")
- .getCarrierTechnologyParameters().getLabel());
+ .getCarrierTechnologyParameters().getLabel());
assertEquals("SUPER_DOOPER", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
- .getCarrierTechnologyParameters().getLabel());
+ .getCarrierTechnologyParameters().getLabel());
assertEquals("JSON", parameters.getEventInputParameters().get("TheFileConsumer1")
- .getEventProtocolParameters().getLabel());
+ .getEventProtocolParameters().getLabel());
assertEquals("SUPER_TOK_DEL", parameters.getEventInputParameters().get("MySuperDooperConsumer1")
- .getEventProtocolParameters().getLabel());
+ .getEventProtocolParameters().getLabel());
assertEquals(ApexFileEventProducer.class.getName(), parameters.getEventInputParameters()
- .get("TheFileConsumer1").getCarrierTechnologyParameters().getEventProducerPluginClass());
+ .get("TheFileConsumer1").getCarrierTechnologyParameters().getEventProducerPluginClass());
assertEquals(ApexFileEventConsumer.class.getName(), parameters.getEventInputParameters()
- .get("TheFileConsumer1").getCarrierTechnologyParameters().getEventConsumerPluginClass());
+ .get("TheFileConsumer1").getCarrierTechnologyParameters().getEventConsumerPluginClass());
assertEquals(SuperDooperEventProducer.class.getName(), parameters.getEventInputParameters()
- .get("MySuperDooperConsumer1").getCarrierTechnologyParameters().getEventProducerPluginClass());
+ .get("MySuperDooperConsumer1").getCarrierTechnologyParameters().getEventProducerPluginClass());
assertEquals(SuperDooperEventSubscriber.class.getName(), parameters.getEventInputParameters()
- .get("MySuperDooperConsumer1").getCarrierTechnologyParameters().getEventConsumerPluginClass());
+ .get("MySuperDooperConsumer1").getCarrierTechnologyParameters().getEventConsumerPluginClass());
}
@Test
- public void testSuperDooperParametersTest() throws ParameterException {
+ void testSuperDooperParametersTest() throws ParameterException {
final String[] args = {"-p", "src/test/resources/parameters/superDooperParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -174,23 +175,32 @@ public class ParameterTests {
assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
final CarrierTechnologyParameters prodCarrierTech =
- parameters.getEventOutputParameters().get("FirstProducer").getCarrierTechnologyParameters();
+ parameters.getEventOutputParameters().get("FirstProducer").getCarrierTechnologyParameters();
final EventProtocolParameters prodEventProt =
- parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters();
+ parameters.getEventOutputParameters().get("FirstProducer").getEventProtocolParameters();
final CarrierTechnologyParameters consCarrierTech =
- parameters.getEventInputParameters().get("MySuperDooperConsumer1").getCarrierTechnologyParameters();
+ parameters.getEventInputParameters().get("MySuperDooperConsumer1").getCarrierTechnologyParameters();
final EventProtocolParameters consEventProt =
- parameters.getEventInputParameters().get("MySuperDooperConsumer1").getEventProtocolParameters();
+ parameters.getEventInputParameters().get("MySuperDooperConsumer1").getEventProtocolParameters();
assertEquals("SUPER_DOOPER", prodCarrierTech.getLabel());
assertEquals("SUPER_TOK_DEL", prodEventProt.getLabel());
assertEquals("SUPER_DOOPER", consCarrierTech.getLabel());
assertEquals("JSON", consEventProt.getLabel());
- assertTrue(prodCarrierTech instanceof SuperDooperCarrierTechnologyParameters);
+ assertInstanceOf(SuperDooperCarrierTechnologyParameters.class, prodCarrierTech);
final SuperDooperCarrierTechnologyParameters superDooperParameters =
- (SuperDooperCarrierTechnologyParameters) prodCarrierTech;
+ (SuperDooperCarrierTechnologyParameters) prodCarrierTech;
+ assertFalse(superDooperParameters.isEnableAutoCommit());
+ assertEqualsOnFields(superDooperParameters);
+
+ final String[] consumerTopics = {"consumer-out-0", "consumer-out-1", "consumer-out-2"};
+ assertEquals(Arrays.asList(consumerTopics), superDooperParameters.getConsumerTopicList());
+
+ }
+
+ private static void assertEqualsOnFields(SuperDooperCarrierTechnologyParameters superDooperParameters) {
assertEquals("somehost:12345", superDooperParameters.getBootstrapServers());
assertEquals("0", superDooperParameters.getAcks());
assertEquals(25, superDooperParameters.getRetries());
@@ -198,7 +208,6 @@ public class ParameterTests {
assertEquals(21, superDooperParameters.getLingerTime());
assertEquals(50505050, superDooperParameters.getBufferMemory());
assertEquals("first-group-id", superDooperParameters.getGroupId());
- assertFalse(superDooperParameters.isEnableAutoCommit());
assertEquals(441, superDooperParameters.getAutoCommitTime());
assertEquals(987, superDooperParameters.getSessionTimeout());
assertEquals("producer-out", superDooperParameters.getProducerTopic());
@@ -207,9 +216,5 @@ public class ParameterTests {
assertEquals("some.value.serailizer", superDooperParameters.getValueSerializer());
assertEquals("some.key.deserailizer", superDooperParameters.getKeyDeserializer());
assertEquals("some.value.deserailizer", superDooperParameters.getValueDeserializer());
-
- final String[] consumerTopics = {"consumer-out-0", "consumer-out-1", "consumer-out-2"};
- assertEquals(Arrays.asList(consumerTopics), superDooperParameters.getConsumerTopicList());
-
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java
index 0b05eac63..1f9a0d349 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/ProducerConsumerTests.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) 2020 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -24,10 +24,11 @@
package org.onap.policy.apex.service.engine.parameters;
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.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.FileCarrierTechnologyParameters;
import org.onap.policy.apex.service.engine.main.ApexCommandLineArguments;
import org.onap.policy.apex.service.parameters.ApexParameterHandler;
@@ -39,9 +40,9 @@ import org.onap.policy.common.parameters.ParameterException;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class ProducerConsumerTests {
+class ProducerConsumerTests {
@Test
- public void testGoodParametersTest() throws ParameterException {
+ void testGoodParametersTest() throws ParameterException {
final String[] args = {"-p", "src/test/resources/parameters/goodParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -71,7 +72,7 @@ public class ProducerConsumerTests {
}
@Test
- public void testNoCarrierTechnology() {
+ void testNoCarrierTechnology() {
final String[] args = {"-p", "src/test/resources/parameters/prodConsNoCT.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -79,12 +80,12 @@ public class ProducerConsumerTests {
.hasMessageContaining("src/test/resources/parameters/prodConsNoCT.json")
.hasMessageContaining("ApexParameters")
.hasMessageContaining("eventInputParameters", "aConsumer", "EventHandlerParameters",
- "carrierTechnologyParameters")
+ "carrierTechnologyParameters")
.hasMessageContaining("is null");
}
@Test
- public void testNoEventProcol() {
+ void testNoEventProcol() {
final String[] args = {"-p", "src/test/resources/parameters/prodConsNoEP.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -92,15 +93,15 @@ public class ProducerConsumerTests {
.hasMessageContaining("src/test/resources/parameters/prodConsNoEP.json")
.hasMessageContaining("ApexParameters")
.hasMessageContaining("eventOutputParameters", "aProducer", "EventHandlerParameters",
- "eventProtocolParameters")
+ "eventProtocolParameters")
.hasMessageContaining("eventInputParameters", "aConsumer", "EventHandlerParameters",
- "FileCarrierTechnologyParameters", "fileName")
+ "FileCarrierTechnologyParameters", "fileName")
.hasMessageContaining("is null")
.hasMessageContaining("is blank");
}
@Test
- public void testNoCarrierTechnologyParClass() {
+ void testNoCarrierTechnologyParClass() {
final String[] args = {"-p", "src/test/resources/parameters/prodConsNoCTParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -111,7 +112,7 @@ public class ProducerConsumerTests {
}
@Test
- public void testMismatchCarrierTechnologyParClass() {
+ void testMismatchCarrierTechnologyParClass() {
final String[] args = {"-p", "src/test/resources/parameters/prodConsMismatchCTParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -124,14 +125,16 @@ public class ProducerConsumerTests {
}
@Test
- public void testWrongTypeCarrierTechnologyParClass() {
+ void testWrongTypeCarrierTechnologyParClass() {
final String[] args = {"-p", "src/test/resources/parameters/prodConsWrongTypeCTParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments)).hasMessage(
- "error reading parameters from " + "\"src/test/resources/parameters/prodConsWrongTypeCTParClass.json\"\n"
- + "(ParameterRuntimeException):could not create default parameters for carrier technology "
- + "\"SUPER_DOOPER\"\n" + "class org.onap.policy.apex.service.engine.parameters.dummyclasses."
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessageContaining(
+ "error reading parameters from " + "\"src/test/resources/parameters/prodConsWrongTypeCTParClass.json\"\n")
+ .hasMessageContaining("(ParameterRuntimeException):could not create default parameters for "
+ + "carrier technology \"SUPER_DOOPER\"\n"
+ + "class org.onap.policy.apex.service.engine.parameters.dummyclasses."
+ "SuperTokenDelimitedEventProtocolParameters cannot be cast to class "
+ "org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters (org.onap."
+ "policy.apex.service.engine.parameters.dummyclasses.SuperTokenDelimitedEventProtocolParameters "
@@ -140,7 +143,7 @@ public class ProducerConsumerTests {
}
@Test
- public void testOkFileNameCarrierTechnology() throws ParameterException {
+ void testOkFileNameCarrierTechnology() throws ParameterException {
final String[] args = {"-p", "src/test/resources/parameters/prodConsOKFileName.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -148,14 +151,14 @@ public class ProducerConsumerTests {
final FileCarrierTechnologyParameters fileParams = (FileCarrierTechnologyParameters) parameters
.getEventOutputParameters().get("aProducer").getCarrierTechnologyParameters();
assertTrue(fileParams.getFileName().endsWith("target/aaa.json"));
- assertEquals(false, fileParams.isStandardError());
- assertEquals(false, fileParams.isStandardIo());
- assertEquals(false, fileParams.isStreamingMode());
+ assertFalse(fileParams.isStandardError());
+ assertFalse(fileParams.isStandardIo());
+ assertFalse(fileParams.isStreamingMode());
}
@Test
- public void testBadFileNameCarrierTechnology() {
+ void testBadFileNameCarrierTechnology() {
final String[] args = {"-p", "src/test/resources/parameters/prodConsBadFileName.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -163,12 +166,12 @@ public class ProducerConsumerTests {
.hasMessageContaining("src/test/resources/parameters/prodConsBadFileName.json")
.hasMessageContaining("ApexParameters")
.hasMessageContaining("eventOutputParameters", "aProducer", "EventHandlerParameters",
- "FileCarrierTechnologyParameters", "fileName")
+ "FileCarrierTechnologyParameters", "fileName")
.hasMessageContaining("is blank");
}
@Test
- public void testBadEventProtocolParClass() {
+ void testBadEventProtocolParClass() {
final String[] args = {"-p", "src/test/resources/parameters/prodConsBadEPParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -181,7 +184,7 @@ public class ProducerConsumerTests {
}
@Test
- public void testNoEventProtocolParClass() {
+ void testNoEventProtocolParClass() {
final String[] args = {"-p", "src/test/resources/parameters/prodConsNoEPParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -192,7 +195,7 @@ public class ProducerConsumerTests {
}
@Test
- public void testMismatchEventProtocolParClass() {
+ void testMismatchEventProtocolParClass() {
final String[] args = {"-p", "src/test/resources/parameters/prodConsMismatchEPParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -206,17 +209,19 @@ public class ProducerConsumerTests {
}
@Test
- public void testWrongTypeEventProtocolParClass() {
+ void testWrongTypeEventProtocolParClass() {
final String[] args = {"-p", "src/test/resources/parameters/prodConsWrongTypeEPParClass.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
- assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments)).hasMessage(
- "error reading parameters from " + "\"src/test/resources/parameters/prodConsWrongTypeEPParClass.json\"\n"
- + "(ParameterRuntimeException):could not create default parameters for event protocol "
- + "\"SUPER_TOK_DEL\"\n" + "class org.onap.policy.apex.service.engine."
+ assertThatThrownBy(() -> new ApexParameterHandler().getParameters(arguments))
+ .hasMessageContaining("error reading parameters from "
+ + "\"src/test/resources/parameters/prodConsWrongTypeEPParClass.json\"\n")
+ .hasMessageContaining("(ParameterRuntimeException):could not create default parameters for event protocol "
+ + "\"SUPER_TOK_DEL\"\nclass org.onap.policy.apex.service.engine."
+ "parameters.dummyclasses.SuperDooperCarrierTechnologyParameters "
+ "cannot be cast to class org.onap.policy.apex.service."
- + "parameters.eventprotocol.EventProtocolParameters (org.onap.policy.apex.service.engine.parameters"
+ + "parameters.eventprotocol.EventProtocolParameters ")
+ .hasMessageContaining("org.onap.policy.apex.service.engine.parameters"
+ ".dummyclasses.SuperDooperCarrierTechnologyParameters and org.onap.policy.apex.service.parameters"
+ ".eventprotocol.EventProtocolParameters are in unnamed module of loader 'app')");
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java
index aaa98fd47..e9e989629 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/parameters/SyncParameterTests.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) 2020 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -24,11 +24,12 @@
package org.onap.policy.apex.service.engine.parameters;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Arrays;
-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.engine.parameters.dummyclasses.SuperDooperCarrierTechnologyParameters;
import org.onap.policy.apex.service.engine.parameters.dummyclasses.SuperTokenDelimitedEventProtocolParameters;
@@ -44,9 +45,10 @@ import org.onap.policy.common.parameters.ParameterException;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
-public class SyncParameterTests {
+class SyncParameterTests {
+
@Test
- public void testSyncBadNoSyncWithPeer() throws ParameterException {
+ void testSyncBadNoSyncWithPeer() {
final String[] args = {"-p", "src/test/resources/parameters/syncBadParamsNoSyncWithPeer.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -58,7 +60,7 @@ public class SyncParameterTests {
}
@Test
- public void testSyncBadNotSyncWithPeer() throws ParameterException {
+ void testSyncBadNotSyncWithPeer() {
final String[] args = {"-p", "src/test/resources/parameters/syncBadParamsNotSyncWithPeer.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -70,7 +72,7 @@ public class SyncParameterTests {
}
@Test
- public void testSyncBadSyncBadPeers() throws ParameterException {
+ void testSyncBadSyncBadPeers() {
final String[] args = {"-p", "src/test/resources/parameters/syncBadParamsBadPeers.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -85,7 +87,7 @@ public class SyncParameterTests {
}
@Test
- public void testSyncBadSyncInvalidTimeout() throws ParameterException {
+ void testSyncBadSyncInvalidTimeout() {
final String[] args = {"-p", "src/test/resources/parameters/syncBadParamsInvalidTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -103,7 +105,7 @@ public class SyncParameterTests {
}
@Test
- public void testSyncBadSyncBadTimeout() throws ParameterException {
+ void testSyncBadSyncBadTimeout() {
final String[] args = {"-p", "src/test/resources/parameters/syncBadParamsBadTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -115,7 +117,7 @@ public class SyncParameterTests {
}
@Test
- public void testSyncBadSyncUnpairedTimeout() throws ParameterException {
+ void testSyncBadSyncUnpairedTimeout() {
final String[] args = {"-p", "src/test/resources/parameters/syncBadParamsUnpairedTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -133,17 +135,17 @@ public class SyncParameterTests {
}
@Test
- public void testSyncGoodSyncGoodTimeoutProducer() throws ParameterException {
+ void testSyncGoodSyncGoodTimeoutProducer() throws ParameterException {
verifySyncGoodSyncGoodTimeout("src/test/resources/parameters/syncGoodParamsProducerTimeout.json");
}
@Test
- public void testSyncGoodSyncGoodTimeoutConsumer() throws ParameterException {
+ void testSyncGoodSyncGoodTimeoutConsumer() throws ParameterException {
verifySyncGoodSyncGoodTimeout("src/test/resources/parameters/syncGoodParamsConsumerTimeout.json");
}
@Test
- public void testSyncGoodSyncGoodTimeoutBoth() throws ParameterException {
+ void testSyncGoodSyncGoodTimeoutBoth() throws ParameterException {
verifySyncGoodSyncGoodTimeout("src/test/resources/parameters/syncGoodParamsBothTimeout.json");
}
@@ -152,18 +154,18 @@ public class SyncParameterTests {
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
final ApexParameters parameters = new ApexParameterHandler().getParameters(arguments);
- assertEquals(fileName, 12345, parameters.getEventInputParameters().get("SyncConsumer0")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(fileName, 1, parameters.getEventInputParameters().get("SyncConsumer1")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(fileName, 12345, parameters.getEventOutputParameters().get("SyncProducer0")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
- assertEquals(fileName, 1, parameters.getEventOutputParameters().get("SyncProducer1")
- .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(12345, parameters.getEventInputParameters().get("SyncConsumer0")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(1, parameters.getEventInputParameters().get("SyncConsumer1")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(12345, parameters.getEventOutputParameters().get("SyncProducer0")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
+ assertEquals(1, parameters.getEventOutputParameters().get("SyncProducer1")
+ .getPeerTimeout(EventHandlerPeeredMode.SYNCHRONOUS));
}
@Test
- public void testSyncUnusedConsumerPeers() throws ParameterException {
+ void testSyncUnusedConsumerPeers() {
final String[] args = {"-p", "src/test/resources/parameters/syncUnusedConsumerPeers.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -177,7 +179,7 @@ public class SyncParameterTests {
}
@Test
- public void testSyncMismatchedPeers() throws ParameterException {
+ void testSyncMismatchedPeers() {
final String[] args = {"-p", "src/test/resources/parameters/syncMismatchedPeers.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -195,7 +197,7 @@ public class SyncParameterTests {
}
@Test
- public void testSyncUnusedProducerPeers() throws ParameterException {
+ void testSyncUnusedProducerPeers() {
final String[] args = {"-p", "src/test/resources/parameters/syncUnusedProducerPeers.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -209,7 +211,7 @@ public class SyncParameterTests {
}
@Test
- public void testSyncMismatchedTimeout() throws ParameterException {
+ void testSyncMismatchedTimeout() {
final String[] args = {"-p", "src/test/resources/parameters/syncMismatchedTimeout.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -223,7 +225,7 @@ public class SyncParameterTests {
}
@Test
- public void testSyncGoodParametersTest() throws ParameterException {
+ void testSyncGoodParametersTest() throws ParameterException {
final String[] args = {"-p", "src/test/resources/parameters/syncGoodParams.json"};
final ApexCommandLineArguments arguments = new ApexCommandLineArguments(args);
@@ -236,21 +238,21 @@ public class SyncParameterTests {
assertEquals(65522, parameters.getEngineServiceParameters().getDeploymentPort());
final CarrierTechnologyParameters prodCT0 =
- parameters.getEventOutputParameters().get("SyncProducer0").getCarrierTechnologyParameters();
+ parameters.getEventOutputParameters().get("SyncProducer0").getCarrierTechnologyParameters();
final EventProtocolParameters prodEP0 =
- parameters.getEventOutputParameters().get("SyncProducer0").getEventProtocolParameters();
+ parameters.getEventOutputParameters().get("SyncProducer0").getEventProtocolParameters();
final CarrierTechnologyParameters consCT0 =
- parameters.getEventInputParameters().get("SyncConsumer0").getCarrierTechnologyParameters();
+ parameters.getEventInputParameters().get("SyncConsumer0").getCarrierTechnologyParameters();
final EventProtocolParameters consEP0 =
- parameters.getEventInputParameters().get("SyncConsumer0").getEventProtocolParameters();
+ parameters.getEventInputParameters().get("SyncConsumer0").getEventProtocolParameters();
final CarrierTechnologyParameters prodCT1 =
- parameters.getEventOutputParameters().get("SyncProducer1").getCarrierTechnologyParameters();
+ parameters.getEventOutputParameters().get("SyncProducer1").getCarrierTechnologyParameters();
final EventProtocolParameters prodEP1 =
- parameters.getEventOutputParameters().get("SyncProducer1").getEventProtocolParameters();
+ parameters.getEventOutputParameters().get("SyncProducer1").getEventProtocolParameters();
final CarrierTechnologyParameters consCT1 =
- parameters.getEventInputParameters().get("SyncConsumer1").getCarrierTechnologyParameters();
+ parameters.getEventInputParameters().get("SyncConsumer1").getCarrierTechnologyParameters();
final EventProtocolParameters consEP1 =
- parameters.getEventInputParameters().get("SyncConsumer1").getEventProtocolParameters();
+ parameters.getEventInputParameters().get("SyncConsumer1").getEventProtocolParameters();
assertEquals("FILE", prodCT0.getLabel());
assertEquals("JSON", prodEP0.getLabel());
@@ -261,11 +263,18 @@ public class SyncParameterTests {
assertEquals("SUPER_DOOPER", consCT1.getLabel());
assertEquals("SUPER_TOK_DEL", consEP1.getLabel());
- assertTrue(consCT1 instanceof SuperDooperCarrierTechnologyParameters);
- assertTrue(consEP1 instanceof SuperTokenDelimitedEventProtocolParameters);
+ assertInstanceOf(SuperDooperCarrierTechnologyParameters.class, consCT1);
+ assertInstanceOf(SuperTokenDelimitedEventProtocolParameters.class, consEP1);
final SuperDooperCarrierTechnologyParameters superDooperParameters =
- (SuperDooperCarrierTechnologyParameters) consCT1;
+ (SuperDooperCarrierTechnologyParameters) consCT1;
+ assertEqualsOnFields(superDooperParameters);
+
+ final String[] consumerTopics = {"apex-in"};
+ assertEquals(Arrays.asList(consumerTopics), superDooperParameters.getConsumerTopicList());
+ }
+
+ private static void assertEqualsOnFields(SuperDooperCarrierTechnologyParameters superDooperParameters) {
assertEquals("localhost:9092", superDooperParameters.getBootstrapServers());
assertEquals("all", superDooperParameters.getAcks());
assertEquals(0, superDooperParameters.getRetries());
@@ -279,15 +288,12 @@ public class SyncParameterTests {
assertEquals("apex-out", superDooperParameters.getProducerTopic());
assertEquals(100, superDooperParameters.getConsumerPollTime());
assertEquals("org.apache.superDooper.common.serialization.StringSerializer",
- superDooperParameters.getKeySerializer());
+ superDooperParameters.getKeySerializer());
assertEquals("org.apache.superDooper.common.serialization.StringSerializer",
- superDooperParameters.getValueSerializer());
+ superDooperParameters.getValueSerializer());
assertEquals("org.apache.superDooper.common.serialization.StringDeserializer",
- superDooperParameters.getKeyDeserializer());
+ superDooperParameters.getKeyDeserializer());
assertEquals("org.apache.superDooper.common.serialization.StringDeserializer",
- superDooperParameters.getValueDeserializer());
-
- final String[] consumerTopics = {"apex-in"};
- assertEquals(Arrays.asList(consumerTopics), superDooperParameters.getConsumerTopicList());
+ superDooperParameters.getValueDeserializer());
}
}
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java
index a903a885e..caba093ce 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.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) 2020-2022 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -24,17 +24,18 @@
package org.onap.policy.apex.service.engine.runtime.impl;
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.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+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 static org.junit.jupiter.api.Assertions.fail;
import java.io.ByteArrayInputStream;
import java.io.IOException;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.jetbrains.annotations.NotNull;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.ContextParameters;
import org.onap.policy.apex.context.parameters.DistributorParameters;
@@ -59,7 +60,7 @@ import org.onap.policy.common.utils.resources.TextFileUtils;
/**
* Test the engine service implementation.
*/
-public class EngineServiceImplTest {
+class EngineServiceImplTest {
private static String simpleModelString;
private static String differentModelString;
@@ -71,8 +72,8 @@ public class EngineServiceImplTest {
* @throws IOException on model reading errors
* @throws ApexModelException on model reading exceptions
*/
- @BeforeClass
- public static void readSimpleModel() throws IOException, ApexModelException {
+ @BeforeAll
+ static void readSimpleModel() throws IOException, ApexModelException {
simpleModelString = TextFileUtils.getTextFileAsString("src/test/resources/policymodels/SmallModel.json");
differentModelString =
@@ -85,8 +86,8 @@ public class EngineServiceImplTest {
/**
* Initialize default parameters.
*/
- @BeforeClass
- public static void initializeDefaultParameters() {
+ @BeforeAll
+ static void initializeDefaultParameters() {
ParameterService.clear();
final SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
@@ -110,30 +111,29 @@ public class EngineServiceImplTest {
final EngineParameters engineParameters = new EngineParameters();
engineParameters.setName(EngineParameterConstants.MAIN_GROUP_NAME);
+ ExecutorParameters jsExecutorParameters = getExecutorParameters("JAVASCRIPT");
+ engineParameters.getExecutorParameterMap().put("JAVASCRIPT", jsExecutorParameters);
+ getExecutorParameters("MVEL");
+ engineParameters.getExecutorParameterMap().put("MVEL", jsExecutorParameters);
+ ParameterService.register(engineParameters);
+ }
+
+ private static @NotNull ExecutorParameters getExecutorParameters(String lang) {
ExecutorParameters jsExecutorParameters = new ExecutorParameters();
- jsExecutorParameters.setName("JAVASCRIPT");
+ jsExecutorParameters.setName(lang);
jsExecutorParameters
.setTaskSelectionExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTse");
jsExecutorParameters.setTaskExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTe");
jsExecutorParameters
.setStateFinalizerExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummySfe");
- engineParameters.getExecutorParameterMap().put("JAVASCRIPT", jsExecutorParameters);
- ExecutorParameters mvvelExecutorParameters = new ExecutorParameters();
- mvvelExecutorParameters.setName("MVEL");
- mvvelExecutorParameters
- .setTaskSelectionExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTse");
- mvvelExecutorParameters.setTaskExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTe");
- mvvelExecutorParameters
- .setStateFinalizerExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummySfe");
- engineParameters.getExecutorParameterMap().put("MVEL", jsExecutorParameters);
- ParameterService.register(engineParameters);
+ return jsExecutorParameters;
}
/**
* Teardown default parameters.
*/
- @AfterClass
- public static void teardownDefaultParameters() {
+ @AfterAll
+ static void teardownDefaultParameters() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
@@ -154,9 +154,9 @@ public class EngineServiceImplTest {
}
@Test
- public void testEngineServiceImplSanity() throws ApexException {
+ void testEngineServiceImplSanity() throws ApexException {
assertThatThrownBy(() -> EngineServiceImpl.create(null)).isInstanceOf(ApexException.class)
- .hasMessage("engine service configuration parameters are null");
+ .hasMessage("Engine service configuration parameters are null");
EngineServiceParameters invalidConfig = new EngineServiceParameters();
invalidConfig.setInstanceCount(0);
@@ -212,7 +212,7 @@ public class EngineServiceImplTest {
}
@Test
- public void testEngineServiceExceptions() throws ApexException {
+ void testEngineServiceExceptions() throws ApexException {
EngineServiceParameters config = makeConfig();
EngineServiceImpl esImpl = EngineServiceImpl.create(config);
assertThatThrownBy(() -> esImpl.start(null)).isInstanceOf(ApexException.class)
@@ -225,7 +225,7 @@ public class EngineServiceImplTest {
.isInstanceOf(ApexException.class).hasMessage("start()<-Engine-0:0.0.1,STOPPED, cannot start engine, "
+ "engine has not been initialized, its model is not loaded");
- assertThatThrownBy(() -> esImpl.startAll()).isInstanceOf(ApexException.class)
+ assertThatThrownBy(esImpl::startAll).isInstanceOf(ApexException.class)
.hasMessage("start()<-Engine-0:0.0.1,STOPPED, cannot start engine, "
+ "engine has not been initialized, its model is not loaded");
@@ -244,13 +244,13 @@ public class EngineServiceImplTest {
esImpl.startPeriodicEvents(100000);
assertThatThrownBy(() -> esImpl.startPeriodicEvents(100000)).isInstanceOf(ApexException.class)
- .hasMessage("Periodic event geneation already running on engine Engine:0.0.1, ApexPeriodicEventGenerator "
+ .hasMessage("Periodic event generation already running on engine Engine:0.0.1, ApexPeriodicEventGenerator "
+ "[period=100000, firstEventTime=0, lastEventTime=0, eventCount=0]");
esImpl.stopPeriodicEvents();
- assertThatThrownBy(() -> esImpl.stopPeriodicEvents()).isInstanceOf(ApexException.class)
- .hasMessage("Periodic event geneation not running on engine Engine:0.0.1");
+ assertThatThrownBy(esImpl::stopPeriodicEvents).isInstanceOf(ApexException.class)
+ .hasMessage("Periodic event generation not running on engine Engine:0.0.1");
assertThatThrownBy(() -> esImpl.clear(null)).isInstanceOf(ApexException.class)
.hasMessage("engine key must be specified and may not be null");
@@ -296,7 +296,7 @@ public class EngineServiceImplTest {
}
@Test
- public void testApexImplModelWIthModel() throws ApexException {
+ void testApexImplModelWIthModel() throws ApexException {
EngineServiceParameters config = makeConfig();
EngineServiceImpl esImpl = EngineServiceImpl.create(config);
assertEquals("Engine:0.0.1", esImpl.getKey().getId());
@@ -387,6 +387,10 @@ public class EngineServiceImplTest {
fail("test should not throw an exception");
}
+ assertPeriodicEvents(esImpl);
+ }
+
+ private static void assertPeriodicEvents(EngineServiceImpl esImpl) throws ApexException {
esImpl.startPeriodicEvents(100000);
esImpl.stop();
esImpl.startAll();
@@ -397,7 +401,7 @@ public class EngineServiceImplTest {
esImpl.startPeriodicEvents(100000);
fail("test should throw an exception");
} catch (ApexException apEx) {
- assertEquals("Periodic event geneation already running on engine Engine:0.0.1, ApexPeriodicEventGenerator "
+ assertEquals("Periodic event generation already running on engine Engine:0.0.1, ApexPeriodicEventGenerator "
+ "[period=100000, firstEventTime=0, lastEventTime=0, eventCount=0]", apEx.getMessage());
}
@@ -406,7 +410,7 @@ public class EngineServiceImplTest {
esImpl.stopPeriodicEvents();
fail("test should throw an exception");
} catch (ApexException apEx) {
- assertEquals("Periodic event geneation not running on engine Engine:0.0.1", apEx.getMessage());
+ assertEquals("Periodic event generation not running on engine Engine:0.0.1", apEx.getMessage());
}
try {
diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java
index b23b3d4e6..0716e0ad3 100644
--- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java
+++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.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-2022 Bell Canada Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,21 +22,23 @@
package org.onap.policy.apex.service.engine.runtime.impl;
-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.Assert.fail;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+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.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.jetbrains.annotations.NotNull;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.context.parameters.ContextParameterConstants;
import org.onap.policy.apex.context.parameters.ContextParameters;
import org.onap.policy.apex.context.parameters.DistributorParameters;
@@ -63,7 +65,7 @@ import org.onap.policy.common.utils.services.Registry;
/**
* Test the engine worker class.
*/
-public class EngineWorkerTest {
+class EngineWorkerTest {
private final ApplicationThreadFactory atFactory = new ApplicationThreadFactory("apex-engine-service", 512);
private static String simpleModelString;
@@ -73,15 +75,15 @@ public class EngineWorkerTest {
/**
* Read the models into strings.
*
- * @throws IOException on model reading errors
+ * @throws IOException on model reading errors
* @throws ApexModelException on model reading exceptions
*/
- @BeforeClass
- public static void readSimpleModel() throws IOException, ApexModelException {
+ @BeforeAll
+ static void readSimpleModel() throws IOException, ApexModelException {
simpleModelString = TextFileUtils.getTextFileAsString("src/test/resources/policymodels/SmallModel.json");
differentModelString =
- TextFileUtils.getTextFileAsString("src/test/resources/policymodels/SmallModelDifferent.json");
+ TextFileUtils.getTextFileAsString("src/test/resources/policymodels/SmallModelDifferent.json");
final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
simpleModel = modelReader.read(new ByteArrayInputStream(simpleModelString.getBytes()));
@@ -90,8 +92,8 @@ public class EngineWorkerTest {
/**
* Initialize default parameters.
*/
- @BeforeClass
- public static void initializeDefaultParameters() {
+ @BeforeAll
+ static void initializeDefaultParameters() {
ParameterService.clear();
final SchemaParameters schemaParameters = new SchemaParameters();
schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME);
@@ -115,31 +117,30 @@ public class EngineWorkerTest {
final EngineParameters engineParameters = new EngineParameters();
engineParameters.setName(EngineParameterConstants.MAIN_GROUP_NAME);
- ExecutorParameters jsExecutorParameters = new ExecutorParameters();
- jsExecutorParameters.setName("JAVASCRIPT");
- jsExecutorParameters
- .setTaskSelectionExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTse");
- jsExecutorParameters.setTaskExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTe");
- jsExecutorParameters
- .setStateFinalizerExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummySfe");
+ ExecutorParameters jsExecutorParameters = getExecutorParameters("JAVASCRIPT");
engineParameters.getExecutorParameterMap().put("JAVASCRIPT", jsExecutorParameters);
- ExecutorParameters mvvelExecutorParameters = new ExecutorParameters();
- mvvelExecutorParameters.setName("MVEL");
- mvvelExecutorParameters
- .setTaskSelectionExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTse");
- mvvelExecutorParameters.setTaskExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTe");
- mvvelExecutorParameters
- .setStateFinalizerExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummySfe");
+ getExecutorParameters("MVEL");
engineParameters.getExecutorParameterMap().put("MVEL", jsExecutorParameters);
ParameterService.register(engineParameters);
}
+ private static @NotNull ExecutorParameters getExecutorParameters(String lang) {
+ ExecutorParameters jsExecutorParameters = new ExecutorParameters();
+ jsExecutorParameters.setName(lang);
+ jsExecutorParameters
+ .setTaskSelectionExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTse");
+ jsExecutorParameters.setTaskExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummyTe");
+ jsExecutorParameters
+ .setStateFinalizerExecutorPluginClass("org.onap.policy.apex.service.engine.runtime.impl.DummySfe");
+ return jsExecutorParameters;
+ }
+
/**
* Teardown default parameters.
*/
- @AfterClass
- public static void teardownDefaultParameters() {
+ @AfterAll
+ static void teardownDefaultParameters() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME);
ParameterService.deregister(ContextParameterConstants.LOCKING_GROUP_NAME);
@@ -148,192 +149,59 @@ public class EngineWorkerTest {
ParameterService.deregister(EngineParameterConstants.MAIN_GROUP_NAME);
}
- @After
- public void cleardownTest() {
+ @AfterEach
+ void clearDownTest() {
ModelService.clear();
}
@Test
- public void testEngineWorker() {
+ void testEngineWorker() {
BlockingQueue<ApexEvent> eventQueue = new LinkedBlockingQueue<>();
EngineWorker worker = new EngineWorker(new AxArtifactKey("Worker", "0.0.1"), eventQueue, atFactory);
- try {
- worker.registerActionListener(null, null);
- fail("test should throw an exception");
- } catch (Exception apEx) {
- assertEquals("addEventListener()<-Worker:0.0.1,STOPPED, listenerName is null", apEx.getMessage());
- }
+ assertThatThrownBy(() -> worker.registerActionListener(null, null))
+ .hasMessageContaining("addEventListener()<-Worker:0.0.1,STOPPED, listenerName is null");
worker.registerActionListener("DummyListener", null);
- try {
- worker.registerActionListener(null, new DummyApexEventListener());
- fail("test should throw an exception");
- } catch (Exception apEx) {
- assertEquals("addEventListener()<-Worker:0.0.1,STOPPED, listenerName is null", apEx.getMessage());
- }
+ assertThatThrownBy(() -> worker.registerActionListener(null, new DummyApexEventListener()))
+ .hasMessageContaining("addEventListener()<-Worker:0.0.1,STOPPED, listenerName is null");
worker.registerActionListener("DummyListener", new DummyApexEventListener());
- try {
- worker.deregisterActionListener(null);
- fail("test should throw an exception");
- } catch (Exception apEx) {
- assertEquals("removeEventListener()<-Worker:0.0.1,STOPPED, listenerName is null", apEx.getMessage());
- }
+ assertThatThrownBy(() -> worker.deregisterActionListener(null))
+ .hasMessageContaining("removeEventListener()<-Worker:0.0.1,STOPPED, listenerName is null");
worker.deregisterActionListener("DummyListener");
- try {
- worker.getEngineServiceEventInterface();
- fail("test should throw an exception");
- } catch (Exception apEx) {
- assertEquals("getEngineServiceEventInterface() call is not allowed on an Apex Engine Worker",
- apEx.getMessage());
- }
-
- try {
- worker.startPeriodicEvents(100000);
- fail("test should throw an exception");
- } catch (Exception apEx) {
- assertEquals("startPeriodicEvents() call is not allowed on an Apex Engine Worker", apEx.getMessage());
- }
-
- try {
- worker.stopPeriodicEvents();
- fail("test should throw an exception");
- } catch (Exception apEx) {
- assertEquals("stopPeriodicEvents() call is not allowed on an Apex Engine Worker", apEx.getMessage());
- }
+ assertThatThrownBy(worker::getEngineServiceEventInterface)
+ .hasMessageContaining("getEngineServiceEventInterface() call is not allowed on an Apex Engine Worker");
+
+ assertThatThrownBy(() -> worker.startPeriodicEvents(100000))
+ .hasMessageContaining("startPeriodicEvents() call is not allowed on an Apex Engine Worker");
+
+ assertThatThrownBy(worker::stopPeriodicEvents)
+ .hasMessageContaining("stopPeriodicEvents() call is not allowed on an Apex Engine Worker");
assertEquals("Worker:0.0.1", worker.getEngineKeys().iterator().next().getId());
assertNull(worker.getApexModelKey());
- String runtimeInfo = worker.getRuntimeInfo(worker.getEngineKeys().iterator().next());
- assertEquals("{\"TimeStamp\":", runtimeInfo.replaceAll("\\s+", "").substring(0, 13));
+ assertEngineWorkerStartStop(worker);
- assertEquals(AxEngineState.STOPPED, worker.getState());
+ assertThatThrownBy(() -> worker.clear(new AxArtifactKey("DummyKey", "0.0.1")))
+ .hasMessageContaining("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine");
- assertEquals("{\"TimeStamp\":", runtimeInfo.replaceAll("\\s+", "").substring(0, 13));
+ assertDoesNotThrow(() -> worker.clear(worker.getEngineKeys().iterator().next()));
+ assertDoesNotThrow(() -> worker.clear());
- assertFalse(worker.isStarted());
- assertFalse(worker.isStarted(null));
- assertFalse(worker.isStarted(new AxArtifactKey("DummyKey", "0.0.1")));
- assertFalse(worker.isStarted(worker.getEngineKeys().iterator().next()));
- assertTrue(worker.isStopped());
- assertTrue(worker.isStopped(null));
- assertTrue(worker.isStopped(new AxArtifactKey("DummyKey", "0.0.1")));
- assertTrue(worker.isStopped(worker.getEngineKeys().iterator().next()));
-
- try {
- worker.start(new AxArtifactKey("DummyKey", "0.0.1"));
- fail("test should throw an exception");
- } catch (ApexException apEx) {
- assertEquals("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine",
- apEx.getMessage());
- }
-
- try {
- worker.start(worker.getEngineKeys().iterator().next());
- fail("test should throw an exception");
- } catch (ApexException apEx) {
- assertEquals("start()<-Worker:0.0.1,STOPPED, cannot start engine, engine has not been initialized, "
- + "its model is not loaded", apEx.getMessage());
- }
-
- try {
- worker.startAll();
- fail("test should throw an exception");
- } catch (ApexException apEx) {
- assertEquals("start()<-Worker:0.0.1,STOPPED, cannot start engine, "
- + "engine has not been initialized, its model is not loaded", apEx.getMessage());
- }
-
- try {
- worker.stop(new AxArtifactKey("DummyKey", "0.0.1"));
- fail("test should throw an exception");
- } catch (ApexException apEx) {
- assertEquals("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine",
- apEx.getMessage());
- }
-
- try {
- worker.stop(worker.getEngineKeys().iterator().next());
- } catch (ApexException apEx) {
- fail("test should not throw an exception");
- }
-
- try {
- worker.stop();
- } catch (ApexException apEx) {
- fail("test should not throw an exception");
- }
-
- try {
- worker.clear(new AxArtifactKey("DummyKey", "0.0.1"));
- fail("test should throw an exception");
- } catch (ApexException apEx) {
- assertEquals("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine",
- apEx.getMessage());
- }
-
- try {
- worker.clear(worker.getEngineKeys().iterator().next());
- } catch (ApexException apEx) {
- fail("test should not throw an exception");
- }
-
- try {
- worker.clear();
- } catch (ApexException apEx) {
- fail("test should not throw an exception");
- }
-
- try {
- worker.updateModel(new AxArtifactKey("DummyKey", "0.0.1"), "", true);
- fail("test should throw an exception");
- } catch (ApexException apEx) {
- assertEquals("failed to unmarshal the apex model on engine DummyKey:0.0.1", apEx.getMessage());
- }
-
- try {
- worker.updateModel(new AxArtifactKey("DummyKey", "0.0.1"), "I am not an Apex model", true);
- fail("test should throw an exception");
- } catch (ApexException apEx) {
- assertEquals("failed to unmarshal the apex model on engine DummyKey:0.0.1", apEx.getMessage());
- }
-
- try {
- worker.updateModel(new AxArtifactKey("DummyKey", "0.0.1"), simpleModelString, true);
- fail("test should throw an exception");
- } catch (ApexException apEx) {
- assertEquals("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine",
- apEx.getMessage());
- }
-
- try {
- worker.updateModel(new AxArtifactKey("DummyKey", "0.0.1"), (AxPolicyModel) null, true);
- fail("test should throw an exception");
- } catch (ApexException apEx) {
- assertEquals("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine",
- apEx.getMessage());
- }
-
- try {
- worker.updateModel(new AxArtifactKey("DummyKey", "0.0.1"), simpleModel, true);
- fail("test should throw an exception");
- } catch (ApexException apEx) {
- assertEquals("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine",
- apEx.getMessage());
- }
+ assertUpdateEngineModel(worker);
}
@Test
- public void testApexImplModelWIthModel() throws ApexException {
+ void testApexImplModelWIthModel() throws ApexException {
Registry.newRegistry();
Registry.register(ApexPolicyStatisticsManager.REG_APEX_PDP_POLICY_COUNTER, new ApexPolicyStatisticsManager());
BlockingQueue<ApexEvent> eventQueue = new LinkedBlockingQueue<>();
@@ -341,34 +209,18 @@ public class EngineWorkerTest {
EngineWorker worker = new EngineWorker(new AxArtifactKey("Worker", "0.0.1"), eventQueue, atFactory);
assertEquals("Worker:0.0.1", worker.getKey().getId());
- try {
- worker.updateModel(worker.getKey(), simpleModelString, false);
- } catch (ApexException apEx) {
- fail("test should not throw an exception");
- }
+ assertDoesNotThrow(() -> worker.updateModel(worker.getKey(), simpleModelString, false));
eventQueue.add(new ApexEvent("SomeEvent", "0.0.1", "the.event.namespace", "EventSource", "EventTarget", ""));
- try {
- worker.updateModel(worker.getKey(), differentModelString, false);
- fail("test should throw an exception");
- } catch (ApexException apEx) {
- assertEquals("apex model update failed, supplied model with key \"SmallModelDifferent:0.0.1\" is not a "
- + "compatible model update " + "from the existing engine model with key \"SmallModel:0.0.1\"",
- apEx.getMessage());
- }
-
- try {
- worker.updateModel(worker.getKey(), differentModelString, true);
- } catch (ApexException apEx) {
- fail("test should not throw an exception");
- }
-
- try {
- worker.updateModel(worker.getKey(), simpleModelString, true);
- } catch (ApexException apEx) {
- fail("test should not throw an exception");
- }
+ assertThatThrownBy(() -> worker.updateModel(worker.getKey(), differentModelString, false))
+ .hasMessageContaining("apex model update failed, supplied model with key "
+ + "\"SmallModelDifferent:0.0.1\" is not a compatible model update "
+ + "from the existing engine model with key \"SmallModel:0.0.1\"");
+
+ assertDoesNotThrow(() -> worker.updateModel(worker.getKey(), differentModelString, true));
+
+ assertDoesNotThrow(() -> worker.updateModel(worker.getKey(), simpleModelString, true));
String runtimeInfo = worker.getRuntimeInfo(worker.getEngineKeys().iterator().next());
assertEquals("{\"TimeStamp\":", runtimeInfo.replaceAll("\\s+", "").substring(0, 13));
@@ -379,6 +231,7 @@ public class EngineWorkerTest {
assertEquals(AxEngineState.READY, worker.getState());
String status = worker.getStatus(worker.getEngineKeys().iterator().next());
+ assertNotNull(status);
assertEquals("{\"timestamp\":", status.replaceAll("\\s+", "").substring(0, 13));
assertTrue(worker.isStarted());
@@ -386,74 +239,92 @@ public class EngineWorkerTest {
assertFalse(worker.isStopped());
assertFalse(worker.isStopped(worker.getEngineKeys().iterator().next()));
- try {
- worker.start(worker.getEngineKeys().iterator().next());
- fail("test should throw an exception");
- } catch (ApexException apEx) {
- assertEquals("apex engine for engine key Worker:0.0.1 is already running with state READY",
- apEx.getMessage());
- }
-
- try {
- worker.startAll();
- fail("test should throw an exception");
- } catch (ApexException apEx) {
- assertEquals("apex engine for engine key Worker:0.0.1 is already running with state READY",
- apEx.getMessage());
- }
-
- try {
- worker.stop(worker.getEngineKeys().iterator().next());
- } catch (ApexException apEx) {
- fail("test should not throw an exception");
- }
-
- try {
- worker.start(worker.getEngineKeys().iterator().next());
- } catch (ApexException apEx) {
- fail("test should not throw an exception");
- }
-
- try {
- worker.stop();
- } catch (ApexException apEx) {
- fail("test should not throw an exception");
- }
-
- try {
- worker.startAll();
- } catch (ApexException apEx) {
- fail("test should not throw an exception");
- }
+ assertWorkerStartStopWithModel(worker);
+ }
+
+ private static void assertUpdateEngineModel(EngineWorker worker) {
+ assertThatThrownBy(() -> worker.updateModel(new AxArtifactKey("DummyKey", "0.0.1"), "", true))
+ .hasMessageContaining("failed to unmarshal the apex model on engine DummyKey:0.0.1");
+
+ assertThatThrownBy(
+ () -> worker.updateModel(new AxArtifactKey("DummyKey", "0.0.1"), "I am not an Apex model", true))
+ .hasMessageContaining("failed to unmarshal the apex model on engine DummyKey:0.0.1");
+
+ assertThatThrownBy(() -> worker.updateModel(new AxArtifactKey("DummyKey", "0.0.1"), simpleModelString, true))
+ .hasMessageContaining("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine");
+
+ assertThatThrownBy(
+ () -> worker.updateModel(new AxArtifactKey("DummyKey", "0.0.1"), (AxPolicyModel) null, true))
+ .hasMessageContaining("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine");
+
+ assertThatThrownBy(() -> worker.updateModel(new AxArtifactKey("DummyKey", "0.0.1"), simpleModel, true))
+ .hasMessageContaining("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine");
+ }
+
+ private static void assertEngineWorkerStartStop(EngineWorker worker) {
+ String runtimeInfo = worker.getRuntimeInfo(worker.getEngineKeys().iterator().next());
+ assertEquals("{\"TimeStamp\":", runtimeInfo.replaceAll("\\s+", "").substring(0, 13));
+
+ assertEquals(AxEngineState.STOPPED, worker.getState());
+
+ assertEquals("{\"TimeStamp\":", runtimeInfo.replaceAll("\\s+", "").substring(0, 13));
+
+ assertFalse(worker.isStarted());
+ assertFalse(worker.isStarted(null));
+ assertFalse(worker.isStarted(new AxArtifactKey("DummyKey", "0.0.1")));
+ assertFalse(worker.isStarted(worker.getEngineKeys().iterator().next()));
+ assertTrue(worker.isStopped());
+ assertTrue(worker.isStopped(null));
+ assertTrue(worker.isStopped(new AxArtifactKey("DummyKey", "0.0.1")));
+ assertTrue(worker.isStopped(worker.getEngineKeys().iterator().next()));
+
+ assertThatThrownBy(() -> worker.start(new AxArtifactKey("DummyKey", "0.0.1")))
+ .hasMessageContaining("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine");
+
+ assertThatThrownBy(() -> worker.start(worker.getEngineKeys().iterator().next()))
+ .hasMessageContaining(
+ "start()<-Worker:0.0.1,STOPPED, cannot start engine, engine has not been initialized, "
+ + "its model is not loaded");
+
+ assertThatThrownBy(worker::startAll).hasMessageContaining(
+ "start()<-Worker:0.0.1,STOPPED, cannot start engine, engine has not been initialized, its "
+ + "model is not loaded");
+
+ assertThatThrownBy(() -> worker.stop(new AxArtifactKey("DummyKey", "0.0.1")))
+ .hasMessageContaining("engine key DummyKey:0.0.1 does not match the keyWorker:0.0.1 of this engine");
+
+ assertDoesNotThrow(() -> worker.stop(worker.getEngineKeys().iterator().next()));
+
+ assertDoesNotThrow(() -> worker.stop());
+ }
+
+ private static void assertWorkerStartStopWithModel(EngineWorker worker) throws ApexException {
+ assertThatThrownBy(() -> worker.start(worker.getEngineKeys().iterator().next()))
+ .hasMessageContaining("apex engine for engine key Worker:0.0.1 is already running with state READY");
+
+ assertThatThrownBy(worker::startAll)
+ .hasMessageContaining("apex engine for engine key Worker:0.0.1 is already running with state READY");
+
+ assertDoesNotThrow(() -> worker.stop(worker.getEngineKeys().iterator().next()));
+ assertDoesNotThrow(() -> worker.start(worker.getEngineKeys().iterator().next()));
+ assertDoesNotThrow(() -> worker.stop());
+ assertDoesNotThrow(worker::startAll);
worker.stop();
worker.startAll();
- try {
- worker.clear(worker.getEngineKeys().iterator().next());
- fail("test should throw an exception");
- } catch (ApexException apEx) {
- assertEquals("clear()<-Worker:0.0.1,READY, cannot clear engine, engine is not stopped", apEx.getMessage());
- }
-
- try {
- worker.stop(worker.getEngineKeys().iterator().next());
- worker.clear(worker.getEngineKeys().iterator().next());
- } catch (ApexException apEx) {
- fail("test should not throw an exception");
- }
-
- try {
- worker.clear();
- } catch (ApexException apEx) {
- fail("test should not throw an exception");
- }
+ assertThatThrownBy(() -> worker.clear(worker.getEngineKeys().iterator().next()))
+ .hasMessageContaining("clear()<-Worker:0.0.1,READY, cannot clear engine, engine is not stopped");
+
+ assertDoesNotThrow(() -> worker.stop(worker.getEngineKeys().iterator().next()));
+ assertDoesNotThrow(() -> worker.clear(worker.getEngineKeys().iterator().next()));
+ assertDoesNotThrow(() -> worker.clear());
assertNotNull(worker.getApexModelKey());
final ApexPolicyStatisticsManager policyCounter = ApexPolicyStatisticsManager.getInstanceFromRegistry();
assertNotNull(policyCounter);
assertEquals(policyCounter.getPolicyExecutedCount(),
- policyCounter.getPolicyExecutedFailCount() + policyCounter.getPolicyExecutedSuccessCount());
+ policyCounter.getPolicyExecutedFailCount() + policyCounter.getPolicyExecutedSuccessCount());
}
}
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
index 2030b3b65..49bde831f 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/ApexEngineHandler.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -74,7 +74,7 @@ public class ApexEngineHandler {
private static final Logger LOGGER = LoggerFactory.getLogger(ApexEngineHandler.class);
- private Map<ToscaConceptIdentifier, ApexMain> apexMainMap = new LinkedHashMap<>();
+ private final Map<ToscaConceptIdentifier, ApexMain> apexMainMap = new LinkedHashMap<>();
/**
* Constructs the object. Extracts the config and model files from each policy and instantiates the apex engine.
@@ -95,12 +95,13 @@ public class ApexEngineHandler {
* @param polsToUndeploy list of policies to undeploy which will be modified to remove policies not running
* @throws ApexStarterException if the apex engine instantiation failed using the policies passed
*/
- public void updateApexEngine(List<ToscaPolicy> polsToDeploy, List<ToscaConceptIdentifier> polsToUndeploy)
+ public void updateApexEngine(final List<ToscaPolicy> polsToDeploy,
+ final List<ToscaConceptIdentifier> polsToUndeploy)
throws ApexStarterException {
Set<ToscaConceptIdentifier> runningPolicies = new HashSet<>(getRunningPolicies());
- List<ToscaPolicy> policiesToDeploy = polsToDeploy;
+ List<ToscaPolicy> policiesToDeploy = new ArrayList<>(polsToDeploy);
policiesToDeploy.removeIf(p -> runningPolicies.contains(p.getIdentifier()));
- List<ToscaConceptIdentifier> policiesToUnDeploy = polsToUndeploy;
+ List<ToscaConceptIdentifier> policiesToUnDeploy = new ArrayList<>(polsToUndeploy);
policiesToUnDeploy.removeIf(p -> !runningPolicies.contains(p));
Map<ToscaConceptIdentifier, ApexMain> undeployedPoliciesMainMap = new LinkedHashMap<>();
policiesToUnDeploy.forEach(policyId -> {
@@ -179,19 +180,19 @@ public class ApexEngineHandler {
List<String> schemaParamKeysToRetain, ApexMain main) {
ApexParameters existingParameters = ParameterService.get(ApexParameterConstants.MAIN_GROUP_NAME);
List<String> eventInputParamKeysToRemove = main.getApexParameters().getEventInputParameters().keySet().stream()
- .filter(key -> !inputParamKeysToRetain.contains(key)).collect(Collectors.toList());
+ .filter(key -> !inputParamKeysToRetain.contains(key)).toList();
List<String> eventOutputParamKeysToRemove = main.getApexParameters().getEventOutputParameters().keySet()
- .stream().filter(key -> !outputParamKeysToRetain.contains(key)).collect(Collectors.toList());
+ .stream().filter(key -> !outputParamKeysToRetain.contains(key)).toList();
eventInputParamKeysToRemove.forEach(existingParameters.getEventInputParameters()::remove);
eventOutputParamKeysToRemove.forEach(existingParameters.getEventOutputParameters()::remove);
var engineParameters = main.getApexParameters().getEngineServiceParameters().getEngineParameters();
final List<TaskParameters> taskParametersToRemove = engineParameters.getTaskParameters().stream()
- .filter(taskParameter -> !taskParametersToRetain.contains(taskParameter)).collect(Collectors.toList());
+ .filter(taskParameter -> !taskParametersToRetain.contains(taskParameter)).toList();
final List<String> executorParamKeysToRemove = engineParameters.getExecutorParameterMap().keySet().stream()
- .filter(key -> !executorParamKeysToRetain.contains(key)).collect(Collectors.toList());
+ .filter(key -> !executorParamKeysToRetain.contains(key)).toList();
final List<String> schemaParamKeysToRemove =
engineParameters.getContextParameters().getSchemaParameters().getSchemaHelperParameterMap().keySet()
- .stream().filter(key -> !schemaParamKeysToRetain.contains(key)).collect(Collectors.toList());
+ .stream().filter(key -> !schemaParamKeysToRetain.contains(key)).toList();
var aggregatedEngineParameters = existingParameters.getEngineServiceParameters().getEngineParameters();
aggregatedEngineParameters.getTaskParameters().removeAll(taskParametersToRemove);
executorParamKeysToRemove.forEach(aggregatedEngineParameters.getExecutorParameterMap()::remove);
@@ -205,17 +206,17 @@ public class ApexEngineHandler {
Map<AxArtifactKey, AxPolicy> policyMapToRetain, ApexMain main) {
final AxPolicyModel policyModel = main.getActivator().getPolicyModel();
final List<AxArtifactKey> keyInfoKeystoRemove = policyModel.getKeyInformation().getKeyInfoMap().keySet()
- .stream().filter(key -> !keyInfoMapToRetain.containsKey(key)).collect(Collectors.toList());
+ .stream().filter(key -> !keyInfoMapToRetain.containsKey(key)).toList();
final List<AxArtifactKey> schemaKeystoRemove = policyModel.getSchemas().getSchemasMap().keySet().stream()
- .filter(key -> !schemaMapToRetain.containsKey(key)).collect(Collectors.toList());
+ .filter(key -> !schemaMapToRetain.containsKey(key)).toList();
final List<AxArtifactKey> eventKeystoRemove = policyModel.getEvents().getEventMap().keySet().stream()
- .filter(key -> !eventMapToRetain.containsKey(key)).collect(Collectors.toList());
+ .filter(key -> !eventMapToRetain.containsKey(key)).toList();
final List<AxArtifactKey> albumKeystoRemove = policyModel.getAlbums().getAlbumsMap().keySet().stream()
- .filter(key -> !albumMapToRetain.containsKey(key)).collect(Collectors.toList());
+ .filter(key -> !albumMapToRetain.containsKey(key)).toList();
final List<AxArtifactKey> taskKeystoRemove = policyModel.getTasks().getTaskMap().keySet().stream()
- .filter(key -> !taskMapToRetain.containsKey(key)).collect(Collectors.toList());
+ .filter(key -> !taskMapToRetain.containsKey(key)).toList();
final List<AxArtifactKey> policyKeystoRemove = policyModel.getPolicies().getPolicyMap().keySet().stream()
- .filter(key -> !policyMapToRetain.containsKey(key)).collect(Collectors.toList());
+ .filter(key -> !policyMapToRetain.containsKey(key)).toList();
final Map<AxArtifactKey, AxKeyInfo> keyInfoMap = ModelService.getModel(AxKeyInformation.class).getKeyInfoMap();
final Map<AxArtifactKey, AxContextSchema> schemasMap =
@@ -274,7 +275,7 @@ public class ApexEngineHandler {
ModelService.clear();
ParameterService.clear();
throw new ApexStarterException("Apex Engine failed to start.");
- } else if (failedPoliciesMainMap.size() > 0) {
+ } else if (!failedPoliciesMainMap.isEmpty()) {
updateModelAndParameterServices(failedPoliciesMainMap);
if (failedPoliciesMainMap.size() == policies.size()) {
throw new ApexStarterException("Updating the APEX engine with new policies failed.");
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpMessageHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpMessageHandler.java
index 328bb3003..d3f428174 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpMessageHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpMessageHandler.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2023 Bell Canada. All rights reserved.
* ================================================================================
@@ -122,8 +122,8 @@ public class PdpMessageHandler {
*
* @return PdpResponseDetails
*/
- public PdpResponseDetails createPdpResonseDetails(final String requestId, final PdpResponseStatus status,
- final String responseMessage) {
+ public PdpResponseDetails createPdpResponseDetails(final String requestId, final PdpResponseStatus status,
+ final String responseMessage) {
final var pdpResponseDetails = new PdpResponseDetails();
pdpResponseDetails.setResponseTo(requestId);
pdpResponseDetails.setResponseStatus(status);
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java
index af3e93b6a..4d3de3293 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpStateChangeMessageHandler.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
* ================================================================================
@@ -93,13 +93,13 @@ public class PdpStateChangeMessageHandler {
final PdpStatus pdpStatusContext, final PdpMessageHandler pdpMessageHandler) {
PdpResponseDetails pdpResponseDetails = null;
if (pdpStatusContext.getState().equals(PdpState.ACTIVE)) {
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Pdp already in active state");
} else {
final List<ToscaPolicy> policies = Registry.get(ApexStarterConstants.REG_APEX_TOSCA_POLICY_LIST);
if (policies.isEmpty()) {
pdpStatusContext.setState(PdpState.ACTIVE);
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "State changed to active. No policies found.");
} else {
pdpResponseDetails = startApexEngine(pdpStateChangeMsg, pdpStatusContext, pdpMessageHandler, policies);
@@ -130,7 +130,7 @@ public class PdpStateChangeMessageHandler {
if (new HashSet<>(runningPolicies)
.equals(new HashSet<>(pdpMessageHandler.getToscaPolicyIdentifiers(policies)))) {
pdpResponseDetails =
- pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ pdpMessageHandler.createPdpResponseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Apex engine started. State changed to active.");
} else {
var message = new StringBuilder(
@@ -139,18 +139,18 @@ public class PdpStateChangeMessageHandler {
message.append(policy.getName()).append(":").append(policy.getVersion()).append(" ");
}
message.append(". Other policies failed execution. Please see the logs for more details.");
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(
pdpStateChangeMsg.getRequestId(), PdpResponseStatus.SUCCESS, message.toString());
}
pdpStatusContext.setState(PdpState.ACTIVE);
updateDeploymentCounts(runningPolicies, policies);
} else {
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.FAIL, "Apex engine failed to start. State cannot be changed to active.");
}
} catch (final ApexStarterException e) {
LOGGER.error("Pdp State Change failed.", e);
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.FAIL, "Apex engine service running failed. " + e.getMessage());
}
return pdpResponseDetails;
@@ -168,7 +168,7 @@ public class PdpStateChangeMessageHandler {
final PdpStatus pdpStatusContext, final PdpMessageHandler pdpMessageHandler) {
PdpResponseDetails pdpResponseDetails = null;
if (pdpStatusContext.getState().equals(PdpState.PASSIVE)) {
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Pdp already in passive state");
} else {
ApexEngineHandler apexEngineHandler = null;
@@ -181,12 +181,12 @@ public class PdpStateChangeMessageHandler {
if (null != apexEngineHandler && apexEngineHandler.isApexEngineRunning()) {
apexEngineHandler.shutdown();
}
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Apex pdp state changed from Active to Passive.");
pdpStatusContext.setState(PdpState.PASSIVE);
} catch (final Exception e) {
LOGGER.error("Stopping apex engine failed. State cannot be changed to Passive.", e);
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpStateChangeMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpStateChangeMsg.getRequestId(),
PdpResponseStatus.FAIL,
"Stopping apex engine failed. State cannot be changed to Passive." + e.getMessage());
}
@@ -206,7 +206,7 @@ public class PdpStateChangeMessageHandler {
return;
}
var policiesToDeploy = policies.stream()
- .map(ToscaWithTypeAndObjectProperties::getIdentifier).collect(Collectors.toList());
+ .map(ToscaWithTypeAndObjectProperties::getIdentifier).toList();
var policiesSuccessfullyDeployed = new ArrayList<>(policiesToDeploy);
policiesSuccessfullyDeployed.retainAll(runningPolicies);
diff --git a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
index b8e361e1e..f6567f06e 100644
--- a/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
+++ b/services/services-onappf/src/main/java/org/onap/policy/apex/services/onappf/handler/PdpUpdateMessageHandler.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -66,7 +66,7 @@ public class PdpUpdateMessageHandler {
if (pdpUpdateMsg.appliesTo(pdpStatusContext.getName(), pdpStatusContext.getPdpGroup(),
pdpStatusContext.getPdpSubgroup())) {
if (checkIfAlreadyHandled(pdpUpdateMsg, pdpStatusContext)) {
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Pdp already updated");
} else {
pdpResponseDetails = handlePdpUpdate(pdpUpdateMsg, pdpMessageHandler, pdpStatusContext);
@@ -128,7 +128,7 @@ public class PdpUpdateMessageHandler {
}
}
if (null == pdpResponseDetails) {
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Pdp update successful.");
}
return pdpResponseDetails;
@@ -170,11 +170,11 @@ public class PdpUpdateMessageHandler {
try {
apexEngineHandler.shutdown();
runningPolicies = apexEngineHandler.getRunningPolicies();
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, "Pdp update successful. No policies are running.");
} catch (final ApexStarterException e) {
LOGGER.error("Pdp update failed as the policies couldn't be undeployed.", e);
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.FAIL, "Pdp update failed as the policies couldn't be undeployed.");
}
updateDeploymentCounts(runningPolicies, pdpUpdateMsg);
@@ -200,12 +200,12 @@ public class PdpUpdateMessageHandler {
populateResponseForEngineInitiation(pdpUpdateMsg, pdpMessageHandler, apexEngineHandler);
runningPolicies = apexEngineHandler.getRunningPolicies();
} else {
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.FAIL, "Apex engine failed to start.");
}
} catch (final ApexStarterException e) {
LOGGER.error("Apex engine service running failed. ", e);
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.FAIL, "Apex engine service running failed. " + e.getMessage());
}
updateDeploymentCounts(runningPolicies, pdpUpdateMsg);
@@ -234,7 +234,7 @@ public class PdpUpdateMessageHandler {
message.append(policy.getName()).append(":").append(policy.getVersion()).append(" ");
}
}
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, message.toString());
} else {
var message =
@@ -243,7 +243,7 @@ public class PdpUpdateMessageHandler {
message.append(policy.getName()).append(":").append(policy.getVersion()).append(" ");
}
message.append(". Other policies failed execution. Please see the logs for more details.");
- pdpResponseDetails = pdpMessageHandler.createPdpResonseDetails(pdpUpdateMsg.getRequestId(),
+ pdpResponseDetails = pdpMessageHandler.createPdpResponseDetails(pdpUpdateMsg.getRequestId(),
PdpResponseStatus.SUCCESS, message.toString());
}
return pdpResponseDetails;
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java
index 77ffa5317..793549b14 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterActivator.java
@@ -1,8 +1,7 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019, 2024 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
-
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,15 +22,15 @@
package org.onap.policy.apex.services.onappf;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
-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.assertTrue;
-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.services.onappf.exception.ApexStarterException;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterGroup;
import org.onap.policy.apex.services.onappf.parameters.ApexStarterParameterHandler;
@@ -44,7 +43,7 @@ import org.onap.policy.models.pdp.concepts.PdpStatus;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestApexStarterActivator {
+class TestApexStarterActivator {
private ApexStarterActivator activator;
@@ -53,12 +52,12 @@ public class TestApexStarterActivator {
*
* @throws Exception if an error occurs
*/
- @Before
- public void setUp() throws Exception {
+ @BeforeEach
+ void setUp() throws Exception {
Registry.newRegistry();
- final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParametersNoop.json"};
+ final String[] apexStarterConfigParameters = {"-c", "src/test/resources/ApexStarterConfigParametersNoop.json"};
final ApexStarterCommandLineArguments arguments =
- new ApexStarterCommandLineArguments(apexStarterConfigParameters);
+ new ApexStarterCommandLineArguments(apexStarterConfigParameters);
final ApexStarterParameterGroup parGroup = new ApexStarterParameterHandler().getParameters(arguments);
activator = new ApexStarterActivator(parGroup);
}
@@ -68,15 +67,15 @@ public class TestApexStarterActivator {
*
* @throws Exception if an error occurs
*/
- @After
- public void teardown() throws Exception {
+ @AfterEach
+ void teardown() throws Exception {
if (activator != null && activator.isAlive()) {
activator.terminate();
}
}
@Test
- public void testApexStarterActivator() throws ApexStarterException {
+ void testApexStarterActivator() throws ApexStarterException {
assertFalse(activator.isAlive());
activator.initialize();
assertTrue(activator.isAlive());
@@ -93,7 +92,7 @@ public class TestApexStarterActivator {
}
@Test
- public void testTerminate() throws Exception {
+ void testTerminate() throws Exception {
activator.initialize();
activator.terminate();
assertFalse(activator.isAlive());
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterCommandLineArguments.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterCommandLineArguments.java
index e564d38e4..c5ebd50ea 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterCommandLineArguments.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterCommandLineArguments.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,11 +21,11 @@
package org.onap.policy.apex.services.onappf;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class TestApexStarterCommandLineArguments {
+class TestApexStarterCommandLineArguments {
/**
* Test method for {@link org.onap.policy.apex.services.onappf.ApexStarterCommandLineArguments
@@ -33,7 +33,7 @@ public class TestApexStarterCommandLineArguments {
* Assert custom option was added to options object from super.
*/
@Test
- public void testCommandLineHasPropertyFileOption() {
+ void testCommandLineHasPropertyFileOption() {
String[] args = {"-p", "someFile.json"};
ApexStarterCommandLineArguments sut = new ApexStarterCommandLineArguments(args);
assertEquals("someFile.json", sut.getPropertyFilePath());
@@ -44,7 +44,7 @@ public class TestApexStarterCommandLineArguments {
* Assert method consults version.txt from Apex module.
*/
@Test
- public void testVersion() {
+ void testVersion() {
String[] args = {"-v"};
ApexStarterCommandLineArguments sut = new ApexStarterCommandLineArguments(args);
assertThat(sut.version()).startsWith("ONAP Policy Framework Apex Starter Service");
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterConstants.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterConstants.java
index f1a2a089c..4c13b5709 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterConstants.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterConstants.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019,2023 Nordix Foundation.
+ * Copyright (C) 2019, 2023-2024 Nordix Foundation.
* Modifications Copyright (C) 2020 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,16 +24,17 @@ package org.onap.policy.apex.services.onappf;
import static org.assertj.core.api.Assertions.assertThatCode;
import java.lang.reflect.Constructor;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
/**
* Class to perform unit test of {@link ApexStarterConstants}}.
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestApexStarterConstants {
+class TestApexStarterConstants {
+
@Test
- public void test() throws Exception {
+ void test() {
// verify that constructor does not throw an exception
assertThatCode(() -> {
Constructor<ApexStarterConstants> c = ApexStarterConstants.class.getDeclaredConstructor();
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java
index f24329c29..e34a1cd04 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/TestApexStarterMain.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2020, 2024 Nordix Foundation.
* Modifications Copyright (C) 2020 Nordix Foundation
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
@@ -24,13 +24,13 @@ package org.onap.policy.apex.services.onappf;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.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 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.main.ApexPolicyStatisticsManager;
import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
import org.onap.policy.apex.services.onappf.exception.ApexStarterRunTimeException;
@@ -39,18 +39,17 @@ import org.onap.policy.common.utils.resources.MessageConstants;
import org.onap.policy.common.utils.services.Registry;
/**
- * Class to perform unit test of {@link ApexStarterMain}}.
+ * Class to perform unit test of {@link ApexStarterMain}.
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestApexStarterMain {
- private ApexStarterMain apexStarter;
+class TestApexStarterMain {
/**
* Set up.
*/
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
Registry.newRegistry();
}
@@ -59,8 +58,8 @@ public class TestApexStarterMain {
*
* @throws Exception if an error occurs
*/
- @After
- public void tearDown() throws Exception {
+ @AfterEach
+ void tearDown() throws Exception {
// shut down activator
final ApexStarterActivator activator =
Registry.getOrDefault(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class, null);
@@ -70,9 +69,9 @@ public class TestApexStarterMain {
}
@Test
- public void testApexStarter() throws ApexStarterException {
+ void testApexStarter() throws ApexStarterException {
final String[] apexStarterConfigParameters = {"-c", "src/test/resources/ApexStarterConfigParametersNoop.json"};
- apexStarter = new ApexStarterMain(apexStarterConfigParameters);
+ ApexStarterMain apexStarter = new ApexStarterMain(apexStarterConfigParameters);
assertTrue(apexStarter.getParameters().isValid());
assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, apexStarter.getParameters().getName());
@@ -84,7 +83,7 @@ public class TestApexStarterMain {
}
@Test
- public void testApexStarter_NoArguments() {
+ void testApexStarter_NoArguments() {
final String[] apexStarterConfigParameters = {};
assertThatThrownBy(() -> new ApexStarterMain(apexStarterConfigParameters))
.isInstanceOf(ApexStarterRunTimeException.class)
@@ -92,7 +91,7 @@ public class TestApexStarterMain {
}
@Test
- public void testApexStarter_InvalidArguments() {
+ void testApexStarter_InvalidArguments() {
final String[] apexStarterConfigParameters = {"src/test/resources/ApexStarterConfigParameters.json"};
assertThatThrownBy(() -> new ApexStarterMain(apexStarterConfigParameters))
.isInstanceOf(ApexStarterRunTimeException.class)
@@ -100,13 +99,13 @@ public class TestApexStarterMain {
}
@Test
- public void testApexStarter_Help() {
+ void testApexStarter_Help() {
final String[] apexStarterConfigParameters = {"-h"};
assertThatCode(() -> ApexStarterMain.main(apexStarterConfigParameters)).doesNotThrowAnyException();
}
@Test
- public void testApexStarter_InvalidParameters() {
+ void testApexStarter_InvalidParameters() {
final String[] apexStarterConfigParameters =
{"-c", "src/test/resources/ApexStarterConfigParameters_InvalidName.json"};
assertThatThrownBy(() -> new ApexStarterMain(apexStarterConfigParameters))
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
index dda98db94..7bff64652 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpStateChangeListener.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
* ================================================================================
@@ -23,20 +23,19 @@
package org.onap.policy.apex.services.onappf.comm;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
-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.main.ApexPolicyStatisticsManager;
import org.onap.policy.apex.services.onappf.ApexStarterActivator;
import org.onap.policy.apex.services.onappf.ApexStarterCommandLineArguments;
@@ -60,25 +59,23 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestPdpStateChangeListener {
+class TestPdpStateChangeListener {
private PdpUpdateListener pdpUpdateMessageListener;
private PdpStateChangeListener pdpStateChangeListener;
private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
private static final String TOPIC = "my-topic";
private ApexStarterActivator activator;
private ApexEngineHandler apexEngineHandler;
- private PrintStream stdout = System.out;
+ private final PrintStream stdout = System.out;
/**
* Method for setup before each test.
*
* @throws ApexStarterException if some error occurs while starting up the apex starter
- * @throws FileNotFoundException if the file is missing
- * @throws IOException if IO exception occurs
* @throws CommandLineException if any parsing of args has errors
*/
- @Before
- public void setUp() throws ApexStarterException, FileNotFoundException, IOException, CommandLineException {
+ @BeforeEach
+ void setUp() throws ApexStarterException, CommandLineException {
pdpUpdateMessageListener = new PdpUpdateListener();
pdpStateChangeListener = new PdpStateChangeListener();
Registry.newRegistry();
@@ -108,8 +105,8 @@ public class TestPdpStateChangeListener {
*
* @throws Exception if an error occurs
*/
- @After
- public void teardown() throws Exception {
+ @AfterEach
+ void teardown() throws Exception {
System.setOut(stdout);
apexEngineHandler =
Registry.getOrDefault(ApexStarterConstants.REG_APEX_ENGINE_HANDLER, ApexEngineHandler.class, null);
@@ -123,7 +120,7 @@ public class TestPdpStateChangeListener {
}
@Test
- public void testPdpStateChangeMessageListener_passivetopassive() {
+ void testPdpStateChangeMessageListener_passiveToPassive() {
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null,
TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(),
@@ -136,7 +133,7 @@ public class TestPdpStateChangeListener {
}
@Test
- public void testPdpStateChangeMessageListener_activetoactive() {
+ void testPdpStateChangeMessageListener_activeToActive() {
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null,
TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(),
@@ -150,7 +147,7 @@ public class TestPdpStateChangeListener {
}
@Test
- public void testPdpStateChangeMessageListener() throws InterruptedException, CoderException {
+ void testPdpStateChangeMessageListener() throws CoderException {
OutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
@@ -180,11 +177,11 @@ public class TestPdpStateChangeListener {
apexEngineHandler =
Registry.getOrDefault(ApexStarterConstants.REG_APEX_ENGINE_HANDLER, ApexEngineHandler.class, null);
assertNotNull(apexEngineHandler);
- assertTrue(apexEngineHandler.getEngineStats().size() > 0);
+ assertFalse(apexEngineHandler.getEngineStats().isEmpty());
}
@Test
- public void testPdpStateChangeMessageListener_activetopassive() throws InterruptedException, CoderException {
+ void testPdpStateChangeMessageListener_activeToPassive() throws CoderException {
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
final ToscaPolicy toscaPolicy =
TestListenerUtils.createToscaPolicy("apex_policy_name", "1.0", "src/test/resources/dummyProperties.json");
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
index 3716e043f..56889cf72 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/comm/TestPdpUpdateListener.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2024 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2020-2021 Bell Canada. All rights reserved.
* ================================================================================
@@ -23,21 +23,19 @@
package org.onap.policy.apex.services.onappf.comm;
import static org.assertj.core.api.Assertions.assertThat;
-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.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
-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.main.ApexPolicyStatisticsManager;
import org.onap.policy.apex.services.onappf.ApexStarterActivator;
import org.onap.policy.apex.services.onappf.ApexStarterCommandLineArguments;
@@ -62,25 +60,23 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestPdpUpdateListener {
+class TestPdpUpdateListener {
private PdpUpdateListener pdpUpdateMessageListener;
private PdpStateChangeListener pdpStateChangeListener;
private static final CommInfrastructure INFRA = CommInfrastructure.NOOP;
private static final String TOPIC = "my-topic";
private ApexStarterActivator activator;
private ApexEngineHandler apexEngineHandler;
- private PrintStream stdout = System.out;
+ private final PrintStream stdout = System.out;
/**
* Method for setup before each test.
*
* @throws ApexStarterException if some error occurs while starting up the apex starter
- * @throws FileNotFoundException if the file is missing
- * @throws IOException if IO exception occurs
* @throws CommandLineException if any parsing of args has errors
*/
- @Before
- public void setUp() throws ApexStarterException, FileNotFoundException, IOException, CommandLineException {
+ @BeforeEach
+ void setUp() throws ApexStarterException, CommandLineException {
Registry.newRegistry();
final String[] apexStarterConfigParameters = {"-c", "src/test/resources/ApexStarterConfigParametersNoop.json"};
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
@@ -103,7 +99,7 @@ public class TestPdpUpdateListener {
pdpUpdateMessageListener = new PdpUpdateListener();
pdpStateChangeListener = new PdpStateChangeListener();
Registry.register(ApexPolicyStatisticsManager.REG_APEX_PDP_POLICY_COUNTER,
- new ApexPolicyStatisticsManager());
+ new ApexPolicyStatisticsManager());
}
/**
@@ -111,8 +107,8 @@ public class TestPdpUpdateListener {
*
* @throws Exception if an error occurs
*/
- @After
- public void teardown() throws Exception {
+ @AfterEach
+ void teardown() throws Exception {
System.setOut(stdout);
apexEngineHandler =
Registry.getOrDefault(ApexStarterConstants.REG_APEX_ENGINE_HANDLER, ApexEngineHandler.class, null);
@@ -126,29 +122,29 @@ public class TestPdpUpdateListener {
}
@Test
- public void testPdpUpdateMssageListener() throws CoderException {
+ void testPdpUpdateMessageListener() throws CoderException {
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
final ToscaPolicy toscaPolicy =
TestListenerUtils.createToscaPolicy("apex policy name", "1.0", "src/test/resources/dummyProperties.json");
final List<ToscaPolicy> toscaPolicies = new ArrayList<ToscaPolicy>();
toscaPolicies.add(toscaPolicy);
final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies,
- new LinkedList<>());
+ new LinkedList<>());
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
assertEquals(pdpStatus.getPdpGroup(), pdpUpdateMsg.getPdpGroup());
assertEquals(pdpStatus.getPdpSubgroup(), pdpUpdateMsg.getPdpSubgroup());
assertEquals(pdpStatus.getPolicies(),
- new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed()));
+ new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed()));
}
@Test
- public void testPdpUpdateMssageListener_success() throws InterruptedException, CoderException {
+ void testPdpUpdateMessageListener_success() throws CoderException {
OutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null,
TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(),
- new ArrayList<>()));
+ new ArrayList<>()));
PdpStateChange pdpStateChangeMsg =
TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName());
pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg);
@@ -157,22 +153,22 @@ public class TestPdpUpdateListener {
final List<ToscaPolicy> toscaPolicies = new ArrayList<ToscaPolicy>();
toscaPolicies.add(toscaPolicy);
final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies,
- new LinkedList<>());
+ new LinkedList<>());
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
final String outString = outContent.toString();
assertEquals(pdpStatus.getPdpGroup(), pdpUpdateMsg.getPdpGroup());
assertEquals(pdpStatus.getPdpSubgroup(), pdpUpdateMsg.getPdpSubgroup());
assertEquals(pdpStatus.getPolicies(),
- new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed()));
+ new PdpMessageHandler().getToscaPolicyIdentifiers(pdpUpdateMsg.getPoliciesToBeDeployed()));
assertThat(outString).contains("Apex engine started. Deployed policies are: apex_policy_name:1.0");
}
@Test
- public void testPdpUpdateMssageListener_undeploy() throws InterruptedException, CoderException {
+ void testPdpUpdateMessageListener_undeploy() throws CoderException {
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null,
TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(),
- new ArrayList<>()));
+ new ArrayList<>()));
PdpStateChange pdpStateChangeMsg =
TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName());
pdpStateChangeListener.onTopicEvent(INFRA, TOPIC, null, pdpStateChangeMsg);
@@ -181,21 +177,20 @@ public class TestPdpUpdateListener {
final List<ToscaPolicy> toscaPolicies = new ArrayList<ToscaPolicy>();
toscaPolicies.add(toscaPolicy);
final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies,
- new ArrayList<>());
+ new ArrayList<>());
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
OutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null,
TestListenerUtils.createPdpUpdateMsg(pdpStatus, new ArrayList<>(),
- toscaPolicies.stream().map(ToscaPolicy::getIdentifier)
+ toscaPolicies.stream().map(ToscaPolicy::getIdentifier)
.collect(Collectors.toList())));
final String outString = outContent.toString();
assertThat(outString).contains("Pdp update successful. No policies are running.");
}
@Test
- public void testPdpUpdateMssageListener_multi_policy_duplicate()
- throws InterruptedException, ApexStarterException, CoderException {
+ void testPdpUpdateMessageListener_multi_policy_duplicate() throws CoderException {
OutputStream outContent = new ByteArrayOutputStream();
System.setOut(new PrintStream(outContent));
final PdpStatus pdpStatus = Registry.get(ApexStarterConstants.REG_PDP_STATUS_OBJECT);
@@ -207,7 +202,7 @@ public class TestPdpUpdateListener {
toscaPolicies.add(toscaPolicy);
toscaPolicies.add(toscaPolicy2);
final PdpUpdate pdpUpdateMsg = TestListenerUtils.createPdpUpdateMsg(pdpStatus, toscaPolicies,
- new LinkedList<>());
+ new LinkedList<>());
pdpUpdateMessageListener.onTopicEvent(INFRA, TOPIC, null, pdpUpdateMsg);
PdpStateChange pdpStateChangeMsg =
TestListenerUtils.createPdpStateChangeMsg(PdpState.ACTIVE, "pdpGroup", "pdpSubgroup", pdpStatus.getName());
@@ -215,6 +210,6 @@ public class TestPdpUpdateListener {
final String outString = outContent.toString();
assertTrue(outString.contains(
"Apex engine started. But, only the following polices are running - apex_policy_name:1.0 . "
- + "Other policies failed execution. Please see the logs for more details."));
+ + "Other policies failed execution. Please see the logs for more details."));
}
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/exception/TestExceptions.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/exception/TestExceptions.java
index 7ccb850b1..da1568d33 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/exception/TestExceptions.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/exception/TestExceptions.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,7 +20,7 @@
package org.onap.policy.apex.services.onappf.exception;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.utils.test.ExceptionsTester;
/**
@@ -28,10 +28,10 @@ import org.onap.policy.common.utils.test.ExceptionsTester;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestExceptions {
+class TestExceptions {
@Test
- public void test() {
+ void test() {
new ExceptionsTester().test(ApexStarterException.class);
new ExceptionsTester().test(ApexStarterRunTimeException.class);
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java
index f227acc6c..099663af9 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/CommonTestData.java
@@ -86,7 +86,7 @@ public class CommonTestData {
* Converts the contents of a map to a parameter class.
*
* @param source property map
- * @param clazz class of object to be created from the map
+ * @param clazz class of object to be created from the map
* @return a new object represented by the map
*/
public <T extends ParameterGroup> T toObject(final Map<String, Object> source, final Class<T> clazz) {
@@ -102,7 +102,6 @@ public class CommonTestData {
* Returns a property map for a ApexStarterParameterGroup map for test cases.
*
* @param name name of the parameters
- *
* @return a property map suitable for constructing an object
*/
public Map<String, Object> getApexStarterParameterGroupMap(final String name) {
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java
index c44964921..bd063d06a 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterGroup.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,12 +22,13 @@
package org.onap.policy.apex.services.onappf.parameters;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.parameters.RestServerParameters;
import org.onap.policy.common.endpoints.parameters.TopicParameterGroup;
import org.onap.policy.common.parameters.ValidationResult;
@@ -37,23 +38,23 @@ import org.onap.policy.common.parameters.ValidationResult;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestApexStarterParameterGroup {
+class TestApexStarterParameterGroup {
CommonTestData commonTestData = new CommonTestData();
@Test
- public void testApexStarterParameterGroup_Named() {
+ void testApexStarterParameterGroup_Named() {
final ApexStarterParameterGroup apexStarterParameters = new ApexStarterParameterGroup("my-name");
assertEquals("my-name", apexStarterParameters.getName());
}
@Test
- public void testApexStarterParameterGroup() {
+ void testApexStarterParameterGroup() {
final ApexStarterParameterGroup apexStarterParameters = commonTestData.toObject(
- commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME),
- ApexStarterParameterGroup.class);
+ commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME),
+ ApexStarterParameterGroup.class);
final RestServerParameters restServerParameters = apexStarterParameters.getRestServerParameters();
final PdpStatusParameters pdpStatusParameters = apexStarterParameters.getPdpStatusParameters();
- final TopicParameterGroup topicParameterGroup = apexStarterParameters.getTopicParameterGroup();
+ final TopicParameterGroup topicParameterGroup = apexStarterParameters.getTopicParameterGroup();
final ValidationResult validationResult = apexStarterParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(CommonTestData.APEX_STARTER_GROUP_NAME, apexStarterParameters.getName());
@@ -72,19 +73,19 @@ public class TestApexStarterParameterGroup {
}
@Test
- public void testApexStarterParameterGroup_NullName() {
+ void testApexStarterParameterGroup_NullName() {
final ApexStarterParameterGroup apexStarterParameters = commonTestData
- .toObject(commonTestData.getApexStarterParameterGroupMap(null), ApexStarterParameterGroup.class);
+ .toObject(commonTestData.getApexStarterParameterGroupMap(null), ApexStarterParameterGroup.class);
final ValidationResult validationResult = apexStarterParameters.validate();
assertFalse(validationResult.isValid());
- assertEquals(null, apexStarterParameters.getName());
+ assertNull(apexStarterParameters.getName());
assertTrue(validationResult.getResult().contains("is null"));
}
@Test
- public void testApexStarterParameterGroup_EmptyName() {
+ void testApexStarterParameterGroup_EmptyName() {
final ApexStarterParameterGroup apexStarterParameters = commonTestData
- .toObject(commonTestData.getApexStarterParameterGroupMap(""), ApexStarterParameterGroup.class);
+ .toObject(commonTestData.getApexStarterParameterGroupMap(""), ApexStarterParameterGroup.class);
final ValidationResult validationResult = apexStarterParameters.validate();
assertThat(validationResult.getResult()).contains("\"name\" value \"\" INVALID, is blank");
assertFalse(validationResult.isValid());
@@ -92,10 +93,10 @@ public class TestApexStarterParameterGroup {
}
@Test
- public void testApexStarterParameterGroup_SetName() {
+ void testApexStarterParameterGroup_SetName() {
final ApexStarterParameterGroup apexStarterParameters = commonTestData.toObject(
- commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME),
- ApexStarterParameterGroup.class);
+ commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME),
+ ApexStarterParameterGroup.class);
apexStarterParameters.setName("ApexStarterNewGroup");
final ValidationResult validationResult = apexStarterParameters.validate();
assertTrue(validationResult.isValid());
@@ -103,26 +104,26 @@ public class TestApexStarterParameterGroup {
}
@Test
- public void testApexStarterParameterGroup_EmptyPdpStatusParameters() {
+ void testApexStarterParameterGroup_EmptyPdpStatusParameters() {
final Map<String, Object> map =
- commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
+ commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
map.put("pdpStatusParameters", commonTestData.getPdpStatusParametersMap(true));
final ApexStarterParameterGroup apexStarterParameters =
- commonTestData.toObject(map, ApexStarterParameterGroup.class);
+ commonTestData.toObject(map, ApexStarterParameterGroup.class);
final ValidationResult validationResult = apexStarterParameters.validate();
assertThat(validationResult.getResult())
- .contains("\"ApexStarterParameterGroup\" INVALID, item has status INVALID");
+ .contains("\"ApexStarterParameterGroup\" INVALID, item has status INVALID");
assertFalse(validationResult.isValid());
}
@Test
- public void testApexStarterParameterGroupp_EmptyRestServerParameters() {
+ void testApexStarterParameterGroupp_EmptyRestServerParameters() {
final Map<String, Object> map =
- commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
+ commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
map.put("restServerParameters", commonTestData.getRestServerParametersMap(true));
final ApexStarterParameterGroup apexStarterParameters =
- commonTestData.toObject(map, ApexStarterParameterGroup.class);
+ commonTestData.toObject(map, ApexStarterParameterGroup.class);
final ValidationResult validationResult = apexStarterParameters.validate();
assertThat(validationResult.getResult()).contains("\"RestServerParameters\" INVALID, item has status INVALID");
assertFalse(validationResult.isValid());
@@ -130,13 +131,13 @@ public class TestApexStarterParameterGroup {
@Test
- public void testApexStarterParameterGroupp_EmptyTopicParameters() {
+ void testApexStarterParameterGroup_EmptyTopicParameters() {
final Map<String, Object> map =
- commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
+ commonTestData.getApexStarterParameterGroupMap(CommonTestData.APEX_STARTER_GROUP_NAME);
map.put("topicParameterGroup", commonTestData.getTopicParametersMap(true));
final ApexStarterParameterGroup apexStarterParameters =
- commonTestData.toObject(map, ApexStarterParameterGroup.class);
+ commonTestData.toObject(map, ApexStarterParameterGroup.class);
final ValidationResult validationResult = apexStarterParameters.validate();
assertThat(validationResult.getResult()).contains("\"TopicParameterGroup\" INVALID, item has status INVALID");
assertFalse(validationResult.isValid());
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
index 90c2ef743..0f97203b4 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestApexStarterParameterHandler.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021 Nordix Foundation.
+ * 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,11 +22,11 @@
package org.onap.policy.apex.services.onappf.parameters;
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.FileNotFoundException;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.apex.services.onappf.ApexStarterCommandLineArguments;
import org.onap.policy.apex.services.onappf.exception.ApexStarterException;
import org.onap.policy.common.utils.cmd.CommandLineException;
@@ -37,11 +37,11 @@ import org.onap.policy.common.utils.coder.CoderException;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestApexStarterParameterHandler {
+class TestApexStarterParameterHandler {
@Test
- public void testParameterHandlerNoParameterFile() throws ApexStarterException, CommandLineException {
- final String[] emptyArgumentString = { "-c", "src/test/resources/NoParametersFile.json" };
+ void testParameterHandlerNoParameterFile() throws CommandLineException {
+ final String[] emptyArgumentString = {"-c", "src/test/resources/NoParametersFile.json"};
final ApexStarterCommandLineArguments emptyArguments = new ApexStarterCommandLineArguments();
emptyArguments.parse(emptyArgumentString);
@@ -52,8 +52,8 @@ public class TestApexStarterParameterHandler {
}
@Test
- public void testParameterHandlerEmptyParameters() throws ApexStarterException, CommandLineException {
- final String[] noArgumentString = { "-c", "src/test/resources/NoParameters.json" };
+ void testParameterHandlerEmptyParameters() throws CommandLineException {
+ final String[] noArgumentString = {"-c", "src/test/resources/NoParameters.json"};
final ApexStarterCommandLineArguments noArguments = new ApexStarterCommandLineArguments();
noArguments.parse(noArgumentString);
@@ -63,8 +63,8 @@ public class TestApexStarterParameterHandler {
}
@Test
- public void testParameterHandlerInvalidParameters() throws ApexStarterException, CommandLineException {
- final String[] invalidArgumentString = { "-c", "src/test/resources/InvalidParameters.json" };
+ void testParameterHandlerInvalidParameters() throws CommandLineException {
+ final String[] invalidArgumentString = {"-c", "src/test/resources/InvalidParameters.json"};
final ApexStarterCommandLineArguments invalidArguments = new ApexStarterCommandLineArguments();
invalidArguments.parse(invalidArgumentString);
@@ -75,8 +75,8 @@ public class TestApexStarterParameterHandler {
}
@Test
- public void testParameterHandlerNoParameters() throws ApexStarterException, CommandLineException {
- final String[] noArgumentString = { "-c", "src/test/resources/EmptyConfigParameters.json" };
+ void testParameterHandlerNoParameters() throws CommandLineException {
+ final String[] noArgumentString = {"-c", "src/test/resources/EmptyConfigParameters.json"};
final ApexStarterCommandLineArguments noArguments = new ApexStarterCommandLineArguments();
noArguments.parse(noArgumentString);
@@ -86,8 +86,8 @@ public class TestApexStarterParameterHandler {
}
@Test
- public void testApexStarterParameterGroup() throws ApexStarterException, CommandLineException {
- final String[] apexStarterConfigParameters = { "-c", "src/test/resources/ApexStarterConfigParameters.json" };
+ void testApexStarterParameterGroup() throws ApexStarterException, CommandLineException {
+ final String[] apexStarterConfigParameters = {"-c", "src/test/resources/ApexStarterConfigParameters.json"};
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
arguments.parse(apexStarterConfigParameters);
@@ -98,9 +98,9 @@ public class TestApexStarterParameterHandler {
}
@Test
- public void testApexStarterParameterGroup_InvalidName() throws ApexStarterException, CommandLineException {
+ void testApexStarterParameterGroup_InvalidName() throws CommandLineException {
final String[] apexStarterConfigParameters =
- { "-c", "src/test/resources/ApexStarterConfigParameters_InvalidName.json" };
+ {"-c", "src/test/resources/ApexStarterConfigParameters_InvalidName.json"};
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
arguments.parse(apexStarterConfigParameters);
@@ -110,24 +110,24 @@ public class TestApexStarterParameterHandler {
}
@Test
- public void testApexStarterVersion() throws ApexStarterException, CommandLineException {
- final String[] apexStarterConfigParameters = { "-v" };
+ void testApexStarterVersion() throws CommandLineException {
+ final String[] apexStarterConfigParameters = {"-v"};
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
final String version = arguments.parse(apexStarterConfigParameters);
assertTrue(version.startsWith("ONAP Policy Framework Apex Starter Service"));
}
@Test
- public void testApexStarterHelp() throws ApexStarterException, CommandLineException {
- final String[] apexStarterConfigParameters = { "-h" };
+ void testApexStarterHelp() throws CommandLineException {
+ final String[] apexStarterConfigParameters = {"-h"};
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
final String help = arguments.parse(apexStarterConfigParameters);
assertTrue(help.startsWith("usage:"));
}
@Test
- public void testApexStarterInvalidOption() throws ApexStarterException {
- final String[] apexStarterConfigParameters = { "-d" };
+ void testApexStarterInvalidOption() {
+ final String[] apexStarterConfigParameters = {"-d"};
final ApexStarterCommandLineArguments arguments = new ApexStarterCommandLineArguments();
assertThatThrownBy(() -> arguments.parse(apexStarterConfigParameters))
.hasMessageStartingWith("invalid command line arguments specified");
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.java
index 765bb70a9..7b65ac71e 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/TestPdpStatusParameters.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,13 +22,13 @@
package org.onap.policy.apex.services.onappf.parameters;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.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.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Map;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.parameters.ValidationResult;
/**
@@ -36,13 +36,13 @@ import org.onap.policy.common.parameters.ValidationResult;
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestPdpStatusParameters {
- private static CommonTestData testData = new CommonTestData();
+class TestPdpStatusParameters {
+ private static final CommonTestData testData = new CommonTestData();
@Test
- public void test() throws Exception {
+ void test() {
final PdpStatusParameters pdpStatusParameters =
- testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
+ testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
final ValidationResult validationResult = pdpStatusParameters.validate();
assertTrue(validationResult.isValid());
assertEquals(CommonTestData.TIME_INTERVAL, pdpStatusParameters.getTimeIntervalMs());
@@ -53,31 +53,31 @@ public class TestPdpStatusParameters {
}
@Test
- public void testValidate() throws Exception {
+ void testValidate() {
final PdpStatusParameters pdpStatusParameters =
- testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
+ testData.toObject(testData.getPdpStatusParametersMap(false), PdpStatusParameters.class);
final ValidationResult result = pdpStatusParameters.validate();
assertNull(result.getResult());
assertTrue(result.isValid());
}
@Test
- public void testPdpStatusParameters_nullPdpGroup() throws Exception {
+ void testPdpStatusParameters_nullPdpGroup() {
Map<String, Object> pdpStatusParametersMap = testData.getPdpStatusParametersMap(false);
pdpStatusParametersMap.remove("pdpGroup");
final PdpStatusParameters pdpStatusParameters =
- testData.toObject(pdpStatusParametersMap, PdpStatusParameters.class);
+ testData.toObject(pdpStatusParametersMap, PdpStatusParameters.class);
final ValidationResult validationResult = pdpStatusParameters.validate();
assertFalse(validationResult.isValid());
assertThat(validationResult.getResult()).contains("\"pdpGroup\" value \"null\" INVALID");
}
@Test
- public void testPdpStatusParameters_emptyPdpGroup() throws Exception {
+ void testPdpStatusParameters_emptyPdpGroup() {
Map<String, Object> pdpStatusParametersMap = testData.getPdpStatusParametersMap(false);
pdpStatusParametersMap.put("pdpGroup", "");
final PdpStatusParameters pdpStatusParameters =
- testData.toObject(pdpStatusParametersMap, PdpStatusParameters.class);
+ testData.toObject(pdpStatusParametersMap, PdpStatusParameters.class);
final ValidationResult validationResult = pdpStatusParameters.validate();
assertFalse(validationResult.isValid());
assertThat(validationResult.getResult()).contains("\"pdpGroup\" value \"\" INVALID");
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyStateFinalizerExecutor.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyStateFinalizerExecutor.java
index 2342542e4..b89333668 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyStateFinalizerExecutor.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyStateFinalizerExecutor.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");
@@ -24,9 +24,7 @@ package org.onap.policy.apex.services.onappf.parameters.dummyclasses;
import java.util.Map;
import java.util.Properties;
-import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.core.engine.executor.StateFinalizerExecutor;
-import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
/**
* Dummy state finalizer executor for testing.
@@ -35,7 +33,7 @@ public class DummyStateFinalizerExecutor extends StateFinalizerExecutor {
@Override
public String execute(final long executionId, final Properties executorProperties,
- final Map<String, Object> newIncomingFields) throws StateMachineException, ContextException {
+ final Map<String, Object> newIncomingFields) {
return "stateOutput0";
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskExecutor.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskExecutor.java
index eac2ec3ba..85999d74c 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskExecutor.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskExecutor.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 Bell Canada. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -25,10 +25,8 @@ package org.onap.policy.apex.services.onappf.parameters.dummyclasses;
import java.util.Map;
import java.util.Properties;
-import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.core.engine.event.EnEvent;
import org.onap.policy.apex.core.engine.executor.TaskExecutor;
-import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.onap.policy.apex.model.policymodel.concepts.AxTask;
@@ -38,13 +36,13 @@ import org.onap.policy.apex.model.policymodel.concepts.AxTask;
public class DummyTaskExecutor extends TaskExecutor {
@Override
- public void prepare() throws StateMachineException {
+ public void prepare() {
// Not used
}
@Override
public Map<String, Map<String, Object>> execute(final long executionId, final Properties executorProperties,
- final Map<String, Object> newIncomingFields) throws StateMachineException, ContextException {
+ final Map<String, Object> newIncomingFields) {
AxArtifactKey event0Key = new AxArtifactKey("Event0:0.0.1");
return Map.of(event0Key.getName(), new EnEvent(event0Key));
@@ -57,7 +55,7 @@ public class DummyTaskExecutor extends TaskExecutor {
}
@Override
- public void cleanUp() throws StateMachineException {
+ public void cleanUp() {
// Not used
}
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskSelectExecutor.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskSelectExecutor.java
index 5a6a98f4e..d51f2c4b0 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskSelectExecutor.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/parameters/dummyclasses/DummyTaskSelectExecutor.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");
@@ -23,10 +23,8 @@
package org.onap.policy.apex.services.onappf.parameters.dummyclasses;
import java.util.Properties;
-import org.onap.policy.apex.context.ContextException;
import org.onap.policy.apex.core.engine.event.EnEvent;
import org.onap.policy.apex.core.engine.executor.TaskSelectExecutor;
-import org.onap.policy.apex.core.engine.executor.exception.StateMachineException;
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
/**
@@ -35,19 +33,19 @@ import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
public class DummyTaskSelectExecutor extends TaskSelectExecutor {
@Override
- public void prepare() throws StateMachineException {
+ public void prepare() {
// Not used
}
@Override
public AxArtifactKey execute(final long executionId, final Properties executorProperties,
- final EnEvent newIncomingEvent) throws StateMachineException, ContextException {
+ final EnEvent newIncomingEvent) {
return new AxArtifactKey("task:0.0.1");
}
@Override
- public void cleanUp() throws StateMachineException {
+ public void cleanUp() {
// Not used
}
}
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java
index 24835d70c..3279c27ab 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/CommonApexStarterRestServer.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019,2023 Nordix Foundation.
+ * Copyright (C) 2019, 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,8 +21,9 @@
package org.onap.policy.apex.services.onappf.rest;
-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.assertTrue;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
@@ -39,10 +40,10 @@ import java.util.function.Function;
import javax.net.ssl.SSLContext;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
+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.onap.policy.apex.services.onappf.ApexStarterActivator;
import org.onap.policy.apex.services.onappf.ApexStarterConstants;
import org.onap.policy.apex.services.onappf.ApexStarterMain;
@@ -59,7 +60,7 @@ import org.slf4j.LoggerFactory;
import org.springframework.test.util.ReflectionTestUtils;
/**
- * Class to perform unit test of {@link ApexStarterRestServer}.
+ * Class to perform unit test to check REST endpoints.
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
@@ -67,9 +68,8 @@ public class CommonApexStarterRestServer {
private static final Logger LOGGER = LoggerFactory.getLogger(CommonApexStarterRestServer.class);
- private static Coder coder = new StandardCoder();
+ private static final Coder coder = new StandardCoder();
- public static final String NOT_ALIVE = "not alive";
public static final String ALIVE = "alive";
public static final String SELF = "self";
public static final String ENDPOINT_PREFIX = "policy/apex-pdp/v1/";
@@ -86,7 +86,7 @@ public class CommonApexStarterRestServer {
*
* @throws Exception if an error occurs
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
port = NetworkUtil.allocPort();
@@ -100,7 +100,7 @@ public class CommonApexStarterRestServer {
/**
* Stops Main.
*/
- @AfterClass
+ @AfterAll
public static void teardownAfterClass() {
try {
stopMain();
@@ -115,7 +115,7 @@ public class CommonApexStarterRestServer {
*
* @throws Exception if an error occurs
*/
- @Before
+ @BeforeEach
public void setUp() throws Exception {
// restart, if not currently running
if (main == null) {
@@ -123,13 +123,13 @@ public class CommonApexStarterRestServer {
}
activatorWasAlive =
- Registry.get(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class).isAlive();
+ Registry.get(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class).isAlive();
}
/**
* Restores the activator's "alive" state.
*/
- @After
+ @AfterEach
public void tearDown() {
markActivator(activatorWasAlive);
}
@@ -154,10 +154,10 @@ public class CommonApexStarterRestServer {
*/
private static void makeConfigFile() throws Exception {
final Map<String, Object> config =
- new CommonTestData().getApexStarterParameterGroupMap("ApexStarterParameterGroup");
+ new CommonTestData().getApexStarterParameterGroupMap("ApexStarterParameterGroup");
- @SuppressWarnings("unchecked")
- final Map<String, Object> restParams = (Map<String, Object>) config.get("restServerParameters");
+ @SuppressWarnings("unchecked") final Map<String, Object> restParams =
+ (Map<String, Object>) config.get("restServerParameters");
restParams.put("port", port);
final File file = new File("src/test/resources/TestConfigParams.json");
@@ -184,7 +184,7 @@ public class CommonApexStarterRestServer {
systemProps.put("javax.net.ssl.keyStorePassword", SelfSignedKeyStore.KEYSTORE_PASSWORD);
System.setProperties(systemProps);
- final String[] apexStarterConfigParameters = { "-c", "src/test/resources/TestConfigParams.json" };
+ final String[] apexStarterConfigParameters = {"-c", "src/test/resources/TestConfigParams.json"};
main = new ApexStarterMain(apexStarterConfigParameters);
@@ -196,7 +196,7 @@ public class CommonApexStarterRestServer {
/**
* Stops the "Main".
*
- * @throws Exception if an error occurs
+ * @throws ApexStarterException if an error occurs
*/
private static void stopMain() throws ApexStarterException {
if (main != null) {
@@ -209,8 +209,10 @@ public class CommonApexStarterRestServer {
private void markActivator(final boolean wasAlive) {
final Object manager = ReflectionTestUtils.getField(
- Registry.get(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class), "manager");
+ Registry.get(ApexStarterConstants.REG_APEX_STARTER_ACTIVATOR, ApexStarterActivator.class), "manager");
+ assertNotNull(manager);
AtomicBoolean running = (AtomicBoolean) ReflectionTestUtils.getField(manager, "running");
+ assertNotNull(running);
running.set(wasAlive);
}
@@ -218,13 +220,13 @@ public class CommonApexStarterRestServer {
* Verifies that unauthorized requests fail.
*
* @param endpoint the target end point
- * @param sender function that sends the requests to the target
+ * @param sender function that sends the requests to the target
* @throws Exception if an error occurs
*/
- protected void checkUnauthRequest(final String endpoint, final Function<Invocation.Builder, Response> sender)
- throws Exception {
+ protected void checkUnauthorizedRequest(final String endpoint, final Function<Invocation.Builder, Response> sender)
+ throws Exception {
assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(),
- sender.apply(sendNoAuthRequest(endpoint)).getStatus());
+ sender.apply(sendNoAuthRequest(endpoint)).getStatus());
}
/**
@@ -253,16 +255,16 @@ public class CommonApexStarterRestServer {
* Sends a request to a fully qualified endpoint.
*
* @param fullyQualifiedEndpoint the fully qualified target endpoint
- * @param includeAuth if authorization header should be included
+ * @param includeAuth if authorization header should be included
* @return a request builder
* @throws Exception if an error occurs
*/
protected Invocation.Builder sendFqeRequest(final String fullyQualifiedEndpoint, final boolean includeAuth)
- throws Exception {
+ throws Exception {
final SSLContext sc = SSLContext.getInstance("TLSv1.2");
sc.init(null, NetworkUtil.getAlwaysTrustingManager(), new SecureRandom());
final ClientBuilder clientBuilder =
- ClientBuilder.newBuilder().sslContext(sc).hostnameVerifier((host, session) -> true);
+ ClientBuilder.newBuilder().sslContext(sc).hostnameVerifier((host, session) -> true);
final Client client = clientBuilder.build();
client.property(ClientProperties.METAINF_SERVICES_LOOKUP_DISABLE, "true");
diff --git a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/TestHealthCheckRestControllerV1.java b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/TestHealthCheckRestControllerV1.java
index a49fb5070..a63824a0e 100644
--- a/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/TestHealthCheckRestControllerV1.java
+++ b/services/services-onappf/src/test/java/org/onap/policy/apex/services/onappf/rest/TestHealthCheckRestControllerV1.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019, 2023 Nordix Foundation.
+ * Copyright (C) 2019, 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");
@@ -22,44 +22,39 @@
package org.onap.policy.apex.services.onappf.rest;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import jakarta.ws.rs.client.Invocation;
-import org.junit.Ignore;
-import org.junit.Test;
+import jakarta.ws.rs.client.SyncInvoker;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.report.HealthCheckReport;
/**
- * Class to perform unit test of {@link ApexStarterRestServer}.
+ * Class to perform unit test of {@link HealthCheckRestControllerV1}.
*
* @author Ajith Sreekumar (ajith.sreekumar@est.tech)
*/
-public class TestHealthCheckRestControllerV1 extends CommonApexStarterRestServer {
+class TestHealthCheckRestControllerV1 extends CommonApexStarterRestServer {
private static final String HEALTHCHECK_ENDPOINT = "healthcheck";
- @Ignore
@Test
- public void testSwagger() throws Exception {
- super.testSwagger(HEALTHCHECK_ENDPOINT);
- }
-
- @Test
- public void testHealthCheckSuccess() throws Exception {
+ void testHealthCheckSuccess() throws Exception {
final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT);
final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
- validateHealthCheckReport(SELF, true, 200, ALIVE, report);
+ validateHealthCheckReport(report);
// verify it fails when no authorization info is included
- checkUnauthRequest(HEALTHCHECK_ENDPOINT, req -> req.get());
+ checkUnauthorizedRequest(HEALTHCHECK_ENDPOINT, SyncInvoker::get);
}
- private void validateHealthCheckReport(final String url, final boolean healthy, final int code,
- final String message, final HealthCheckReport report) {
+ private void validateHealthCheckReport(final HealthCheckReport report) {
assertThat(report.getName()).isNotBlank();
- assertEquals(url, report.getUrl());
- assertEquals(healthy, report.isHealthy());
- assertEquals(code, report.getCode());
- assertEquals(message, report.getMessage());
+ assertEquals(CommonApexStarterRestServer.SELF, report.getUrl());
+ assertTrue(report.isHealthy());
+ assertEquals(200, report.getCode());
+ assertEquals(CommonApexStarterRestServer.ALIVE, report.getMessage());
}
}
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[]