diff options
Diffstat (limited to 'plugins/plugins-event/plugins-event-protocol')
6 files changed, 130 insertions, 118 deletions
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"); } } |