aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src
diff options
context:
space:
mode:
authoradheli.tavares <adheli.tavares@est.tech>2024-06-17 15:31:12 +0100
committeradheli.tavares <adheli.tavares@est.tech>2024-06-17 16:05:42 +0100
commitfe6bb57982677177f85daa5f893868556b18e63c (patch)
tree54a2f6f5a3e31469c4ea703a777399fb30fc9cfc /plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src
parente9b746340711ddfccee7ac0f669ace626b1b3d46 (diff)
Convert junit4 to junit5
- plugins module Issue-ID: POLICY-5041 Change-Id: Iebff0a2e6898a5dfe9679662dd2be4c5067a4008 Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'plugins/plugins-event/plugins-event-protocol/plugins-event-protocol-yaml/src')
-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
2 files changed, 65 insertions, 58 deletions
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");
}
}