/*-
* ============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;
/**
* 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);
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()));
}
/*-
* ============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.
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;
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;
/**
* 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");
}
@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());
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);
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");
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);
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));
/*-
* ============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");
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);
}
@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();
}
@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");
}
/*-
* ============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");
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;
/**
* 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());
}
@Test
- public void testEventSchemaBadModelFile() {
+ void testEventSchemaBadModelFile() {
Model2JsonEventSchema app = new Model2JsonEventSchema(modelFile, type, APP_NAME);
assertThatCode(() -> {
int ret = app.runApp();
}
@Test
- public void testEventSchemaBadType() {
+ void testEventSchemaBadType() {
modelFile = "src/test/resources/SmallModel.json";
type = "default";
Model2JsonEventSchema app = new Model2JsonEventSchema(modelFile, type, APP_NAME);
}
@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);
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);
}).doesNotThrowAnyException();
}
- @AfterClass
- public static void cleanTest() {
+ @AfterAll
+ static void cleanTest() {
ParameterService.deregister(ContextParameterConstants.SCHEMA_GROUP_NAME);
ModelService.clear();
}
/*-
* ============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");
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);
}
@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);
}
@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);
}
@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");
}
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"));
/*-
* ============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");
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");
}
/**
/*-
* ============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.
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;
*
* @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());
* testAddAndGetOptionException.
*/
@Test
- public void testAddAndGetOptionException() {
+ void testAddAndGetOptionException() {
final CliParser cli = new CliParser();
assertThatThrownBy(() -> {
cli.addOption(null);
* testParseAndGetCli.
*/
@Test
- public void testParseAndGetCli() {
+ void testParseAndGetCli() {
final CliParser cli = new CliParser();
final Option option = new Option("g", "Good option.");
cli.addOption(option);
/*-
* ============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.
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("");
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);
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();
}
/*-
* ============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.
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);
}
@Test
- public void testValidate() {
+ void testValidate() {
OutputFile testFile = new OutputFile(testFileName, true);
assertNull(testFile.validate());
file.setReadable(false);
}
@Test
- public void testToOutputStream() {
+ void testToOutputStream() {
OutputFile testFile = new OutputFile(testFileName, true);
assertNotNull(testFile.toOutputStream());
file.setReadable(false);
assertNull(testFile.toOutputStream());
}
- @After
- public void testDown() {
+ @AfterEach
+ void testDown() {
if (file.exists()) {
- file.delete();
+ assertTrue(file.delete());
}
}
}
/*-
* ============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.
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
////// 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;
*
* @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();
// 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[]
/*-
* ============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.
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
////
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;
*
* @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);
* 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";
// 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;
}
// 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[]
// tag::someStartPrint[]
LOGGER.info(appName + ": starting");
- LOGGER.info(" --> model file: " + modelFile);
+ LOGGER.info(" --> model file: {}", modelFile);
// end::someStartPrint[]
// tag::yourApp[]