aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/plugins-context/plugins-context-schema/plugins-context-schema-json/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-context/plugins-context-schema/plugins-context-schema-json/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-context/plugins-context-schema/plugins-context-schema-json/src')
-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
3 files changed, 34 insertions, 30 deletions
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);