diff options
Diffstat (limited to 'auth/cli-editor')
10 files changed, 208 insertions, 224 deletions
diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java index 5f7bad116..6797ff4e4 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2022 Nordix Foundation. + * Copyright (C) 2019-2022, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,14 +37,12 @@ import org.slf4j.LoggerFactory; * * @author Ajith Sreekumar (ajith.sreekumar@est.tech) */ +@Getter public class ApexCliToscaEditorMain { private static final Logger LOGGER = LoggerFactory.getLogger(ApexCliToscaEditorMain.class); - @Getter private boolean failure; - private ApexCliToscaParameters parameters; - private ApexCommandLineEditorMain apexCliEditor; /** * Instantiates the Apex CLI Tosca editor. @@ -56,7 +54,7 @@ public class ApexCliToscaEditorMain { LOGGER.info("Starting Apex CLI Tosca editor with arguments - {}", argumentString); final var parser = new ApexCliToscaParameterParser(); - parameters = parser.parse(args); + ApexCliToscaParameters parameters = parser.parse(args); if (parameters.isHelpSet()) { CliUtils.help(ApexCliToscaEditorMain.class.getName(), parser.getOptions()); return; @@ -78,7 +76,7 @@ public class ApexCliToscaEditorMain { cliArgsList.add(policyModelFilePath); String[] cliArgs = cliArgsList.toArray(new String[cliArgsList.size()]); - apexCliEditor = new ApexCommandLineEditorMain(cliArgs); + ApexCommandLineEditorMain apexCliEditor = new ApexCommandLineEditorMain(cliArgs); if (apexCliEditor.getErrorCount() == 0) { LOGGER.info("Apex CLI editor completed execution. Creating the ToscaPolicy using the tosca template" + "skeleton file, config file, and policy model created."); @@ -90,7 +88,7 @@ public class ApexCliToscaEditorMain { } catch (IOException | CoderException e) { failure = true; LOGGER.error("Failed to create the Tosca template using the generated policy model," - + "apex config file and the tosca template skeleton file. " + e); + + "apex config file and the tosca template skeleton file. {}", e.getMessage()); } } else { diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java index 7c3e4cb01..5028abd31 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (c) 2020-2021 Nordix Foundation. + * Copyright (c) 2020-2021, 2024 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,26 +22,26 @@ package org.onap.policy.apex.auth.clieditor; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class CommandLineCommandTest { +class CommandLineCommandTest { CommandLineCommand commandLineCommand = null; - @Before - public void initializeCommandLineCommand() { + @BeforeEach + void initializeCommandLineCommand() { commandLineCommand = new CommandLineCommand(); } @Test - public void testCommandLine() { + void testCommandLine() { commandLineCommand.setName("TestName"); commandLineCommand.setDescription("testDescription"); commandLineCommand.setSystemCommand(true); @@ -50,40 +50,40 @@ public class CommandLineCommandTest { assertEquals("TestName", commandLineCommand.getName()); assertEquals( "CommandLineCommand(name=TestName, keywordlist=[], argumentList=[], apiMethod=, systemCommand=true," - + " description=testDescription)", commandLineCommand.toString()); + + " description=testDescription)", commandLineCommand.toString()); } - @Test(expected = CommandLineException.class) - public void testInvalidApiClassName() { - commandLineCommand.getApiClassName(); + @Test + void testInvalidApiClassName() { + assertThrows(CommandLineException.class, () -> commandLineCommand.getApiClassName()); } @Test - public void testGetValidApiClassName() { + void testGetValidApiClassName() { commandLineCommand.setApiMethod("Java.Get"); assertEquals("Java", commandLineCommand.getApiClassName()); } - @Test(expected = CommandLineException.class) - public void testInvalidApiMethodName() { - commandLineCommand.getApiMethodName(); + @Test + void testInvalidApiMethodName() { + assertThrows(CommandLineException.class, () -> commandLineCommand.getApiMethodName()); } @Test() - public void testInvalidApiMethod() { + void testInvalidApiMethod() { commandLineCommand.setApiMethod("fail."); assertEquals("fail.", commandLineCommand.getApiMethod()); assertThrows(CommandLineException.class, () -> commandLineCommand.getApiMethodName()); } @Test - public void testValidApiMethodName() { + void testValidApiMethodName() { commandLineCommand.setApiMethod("Java.Get"); assertEquals("Get", commandLineCommand.getApiMethodName()); } @Test - public void testGetHelp() { + void testGetHelp() { List<String> keywordList = commandLineCommand.getKeywordlist(); List<CommandLineArgument> argumentList = commandLineCommand.getArgumentList(); assertEquals("{}: ", commandLineCommand.getHelp()); @@ -94,8 +94,7 @@ public class CommandLineCommandTest { } @Test - public void testCompareTo() { - assertEquals(0, commandLineCommand.compareTo(commandLineCommand)); + void testCompareTo() { CommandLineCommand otherCommand = new CommandLineCommand(); otherCommand.setSystemCommand(true); assertThat(commandLineCommand).isNotEqualByComparingTo(otherCommand); @@ -104,7 +103,7 @@ public class CommandLineCommandTest { } @Test - public void testCompareKeywordList() { + void testCompareKeywordList() { CommandLineCommand otherCommand = new CommandLineCommand(); otherCommand.getKeywordlist().add("test"); assertThat(commandLineCommand).isNotEqualByComparingTo(otherCommand); @@ -117,7 +116,7 @@ public class CommandLineCommandTest { } @Test - public void testHashCode() { + void testHashCode() { CommandLineCommand otherCommand = new CommandLineCommand(); assertEquals(commandLineCommand.hashCode(), otherCommand.hashCode()); commandLineCommand.getKeywordlist().add("Test"); @@ -128,10 +127,9 @@ public class CommandLineCommandTest { } @Test - public void testEquals() { + void testEquals() { assertNotEquals(commandLineCommand, new Object()); - assertEquals(commandLineCommand, commandLineCommand); - assertNotEquals(commandLineCommand, null); + assertNotEquals(null, commandLineCommand); CommandLineCommand otherCommand = new CommandLineCommand(); assertEquals(commandLineCommand, otherCommand); diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorEventsContextTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorEventsContextTest.java index d5d288d04..437ae0fbb 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorEventsContextTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorEventsContextTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020, 2024 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -23,22 +23,20 @@ package org.onap.policy.apex.auth.clieditor; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.File; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.onap.policy.common.utils.resources.TextFileUtils; /** * The Class TestCLIEditorEventsContext. */ -public class CommandLineEditorEventsContextTest { +class CommandLineEditorEventsContextTest { // CHECKSTYLE:OFF: MagicNumber private static final Path SRC_MAIN_FOLDER = Paths.get("src/main/resources/"); @@ -56,20 +54,19 @@ public class CommandLineEditorEventsContextTest { private static final String JSON_FILE = FILE_NAME + ".json"; private static final String LOG_FILE = FILE_NAME + ".log"; - @Rule - public TemporaryFolder temporaryFolder = new TemporaryFolder(); + @TempDir + static Path temporaryFolder; /** * Test java context model. * * @throws IOException Signals that an I/O exception has occurred. - * @throws ApexModelException if an Apex error happens */ @Test - public void testJavaContextModel() throws IOException, ApexModelException { + void testJavaContextModel() throws IOException { - final File tempLogFile = temporaryFolder.newFile(LOG_FILE); - final File tempModelFile = temporaryFolder.newFile(JSON_FILE); + final File tempLogFile = temporaryFolder.resolve(LOG_FILE).toFile(); + final File tempModelFile = temporaryFolder.resolve(JSON_FILE).toFile(); final String[] cliArgs = new String[] {"-c", APEX_JAVA_POLICY_FILE.toString(), "-l", tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()}; @@ -81,7 +78,7 @@ public class CommandLineEditorEventsContextTest { final String logString = TextFileUtils.getTextFileAsString(tempLogFile.getCanonicalPath()); final String modelString = TextFileUtils.getTextFileAsString(tempModelFile.getCanonicalPath()); - // As a sanity check, count the number of non white space characters in log and model files + // As a sanity check, count the number of non-white space characters in log and model files final int logCharCount = logString.replaceAll(SPACES, EMPTY_STRING).length(); final int modelCharCount = modelString.replaceAll(SPACES, EMPTY_STRING).length(); @@ -93,13 +90,12 @@ public class CommandLineEditorEventsContextTest { * Test avro context model. * * @throws IOException Signals that an I/O exception has occurred. - * @throws ApexModelException if an Apex error happens */ @Test - public void testAvroContextModel() throws IOException, ApexModelException { + void testAvroContextModel() throws IOException { - final File tempLogFile = temporaryFolder.newFile(LOG_FILE); - final File tempModelFile = temporaryFolder.newFile(JSON_FILE); + final File tempLogFile = temporaryFolder.resolve(LOG_FILE).toFile(); + final File tempModelFile = temporaryFolder.resolve(JSON_FILE).toFile(); final String[] cliArgs = new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()}; @@ -111,7 +107,7 @@ public class CommandLineEditorEventsContextTest { final String logString = TextFileUtils.getTextFileAsString(tempLogFile.getCanonicalPath()); final String modelString = TextFileUtils.getTextFileAsString(tempModelFile.getCanonicalPath()); - // As a sanity check, count the number of non white space characters in log and model files + // As a sanity check, count the number of non-white space characters in log and model files final int logCharCount = logString.replaceAll(SPACES, EMPTY_STRING).length(); final int modelCharCount = modelString.replaceAll(SPACES, EMPTY_STRING).length(); @@ -121,18 +117,18 @@ public class CommandLineEditorEventsContextTest { } @Test - public void test_emptyMetadataCommandFileWithEmptyJsonTag_errorcountGreaterThanOne() throws IOException { + void test_emptyMetadataCommandFileWithEmptyJsonTag_errorCountGreaterThanOne() { - final File tempLogFile = temporaryFolder.newFile(LOG_FILE); - final File tempModelFile = temporaryFolder.newFile(JSON_FILE); + final File tempLogFile = temporaryFolder.resolve(LOG_FILE).toFile(); + final File tempModelFile = temporaryFolder.resolve(JSON_FILE).toFile(); final String modelFile = SRC_TEST_FOLDER.resolve("model").resolve("empty_commands.json").toString(); final String apexPropertiesLocation = - SRC_MAIN_FOLDER.resolve("etc/editor").resolve("ApexModelProperties.json").toString(); + SRC_MAIN_FOLDER.resolve("etc/editor").resolve("ApexModelProperties.json").toString(); final String[] cliArgs = - new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", tempLogFile.getAbsolutePath(), "-o", - tempModelFile.getAbsolutePath(), "-m", modelFile, "-a", apexPropertiesLocation}; + new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", tempLogFile.getAbsolutePath(), "-o", + tempModelFile.getAbsolutePath(), "-m", modelFile, "-a", apexPropertiesLocation}; final ApexCommandLineEditorMain objUnderTest = new ApexCommandLineEditorMain(cliArgs); assertEquals(1, objUnderTest.getErrorCount()); @@ -140,19 +136,19 @@ public class CommandLineEditorEventsContextTest { } @Test - public void test_emptyMetadataCommandFile_errorcountGreaterThanOne() throws IOException { + void test_emptyMetadataCommandFile_errorCountGreaterThanOne() { - final File tempLogFile = temporaryFolder.newFile(LOG_FILE); - final File tempModelFile = temporaryFolder.newFile(JSON_FILE); + final File tempLogFile = temporaryFolder.resolve(LOG_FILE).toFile(); + final File tempModelFile = temporaryFolder.resolve(JSON_FILE).toFile(); - final File modelFile = temporaryFolder.newFile("empty_commands.json"); + final File modelFile = temporaryFolder.resolve("empty_commands.json").toFile(); final String apexPropertiesLocation = - SRC_MAIN_FOLDER.resolve("etc/editor").resolve("ApexModelProperties.json").toString(); + SRC_MAIN_FOLDER.resolve("etc/editor").resolve("ApexModelProperties.json").toString(); final String[] cliArgs = - new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", tempLogFile.getAbsolutePath(), "-o", - tempModelFile.getAbsolutePath(), "-m", modelFile.getAbsolutePath(), "-a", apexPropertiesLocation}; + new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", tempLogFile.getAbsolutePath(), "-o", + tempModelFile.getAbsolutePath(), "-m", modelFile.getAbsolutePath(), "-a", apexPropertiesLocation}; final ApexCommandLineEditorMain objUnderTest = new ApexCommandLineEditorMain(cliArgs); assertEquals(1, objUnderTest.getErrorCount()); diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java index e49422996..dfdb4c2a3 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020,2022 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2022, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,16 +21,15 @@ package org.onap.policy.apex.auth.clieditor; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.PrintStream; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.resources.TextFileUtils; /** @@ -38,17 +37,16 @@ import org.onap.policy.common.utils.resources.TextFileUtils; * * @author Liam Fallon (liam.fallon@ericsson.com) */ -public class CommandLineEditorOptionsTest { +class CommandLineEditorOptionsTest { // CHECKSTYLE:OFF: MagicNumber /** * Test script options log model. * * @throws IOException Signals that an I/O exception has occurred. - * @throws ApexModelException if there is an Apex error */ @Test - public void testScriptOptionsLogModel() throws IOException, ApexModelException { + void testScriptOptionsLogModel() throws IOException { final File tempLogFile = File.createTempFile("ShellPolicyModel", ".log"); final File tempModelFile = File.createTempFile("ShellPolicyModel", ".json"); @@ -62,25 +60,24 @@ public class CommandLineEditorOptionsTest { final String logString = TextFileUtils.getTextFileAsString(tempLogFile.getCanonicalPath()); final String modelString = TextFileUtils.getTextFileAsString(tempModelFile.getCanonicalPath()); - // As a sanity check, count the number of non white space characters in log and model files + // As a sanity check, count the number of non-white space characters in log and model files final int logCharCount = logString.replaceAll("\\s+", "").length(); final int modelCharCount = modelString.replaceAll("\\s+", "").length(); assertEquals(1204, logCharCount); assertEquals(2904, modelCharCount); - tempLogFile.delete(); - tempModelFile.delete(); + assertTrue(tempLogFile.delete()); + assertTrue(tempModelFile.delete()); } /** * Test script options no log no model spec. * * @throws IOException Signals that an I/O exception has occurred. - * @throws ApexModelException if there is an Apex error */ @Test - public void testScriptOptionsNoLogNoModelSpec() throws IOException, ApexModelException { + void testScriptOptionsNoLogNoModelSpec() throws IOException { final File tempLogFile = File.createTempFile("ShellPolicyModel", ".log"); final File tempModelFile = File.createTempFile("ShellPolicyModel", ".json"); @@ -101,18 +98,17 @@ public class CommandLineEditorOptionsTest { assertEquals(0, logCharCount); assertEquals(0, modelCharCount); - tempLogFile.delete(); - tempModelFile.delete(); + assertTrue(tempLogFile.delete()); + assertTrue(tempModelFile.delete()); } /** * Test script options log no model spec. * * @throws IOException Signals that an I/O exception has occurred. - * @throws ApexModelException if there is an Apex error */ @Test - public void testScriptOptionsLogNoModelSpec() throws IOException, ApexModelException { + void testScriptOptionsLogNoModelSpec() throws IOException { final File tempLogFile = File.createTempFile("ShellPolicyModel", ".log"); final File tempModelFile = File.createTempFile("ShellPolicyModel", ".json"); @@ -133,18 +129,17 @@ public class CommandLineEditorOptionsTest { assertEquals(1204, logCharCount); assertEquals(0, modelCharCount); - tempLogFile.delete(); - tempModelFile.delete(); + assertTrue(tempLogFile.delete()); + assertTrue(tempModelFile.delete()); } /** * Test script options no log model spec. * * @throws IOException Signals that an I/O exception has occurred. - * @throws ApexModelException if there is an Apex error */ @Test - public void testScriptOptionsNoLogModelSpec() throws IOException, ApexModelException { + void testScriptOptionsNoLogModelSpec() throws IOException { final File tempLogFile = File.createTempFile("ShellPolicyModel", ".log"); final File tempModelFile = File.createTempFile("ShellPolicyModel", ".json"); @@ -165,20 +160,17 @@ public class CommandLineEditorOptionsTest { assertEquals(0, logCharCount); assertEquals(2904, modelCharCount); - tempLogFile.delete(); - tempModelFile.delete(); + assertTrue(tempLogFile.delete()); + assertTrue(tempModelFile.delete()); } /** * Test script options no log no model no spec. - * - * @throws IOException Signals that an I/O exception has occurred. - * @throws ApexModelException if there is an Apex error */ @Test - public void testScriptOptionsNoLogNoModelNoSpec() throws IOException, ApexModelException { + void testScriptOptionsNoLogNoModelNoSpec() { final String[] cliArgs = - new String[] {"-c", "src/main/resources/examples/scripts/ShellPolicyModel.apex", "-nl", "-nm"}; + new String[] {"-c", "src/main/resources/examples/scripts/ShellPolicyModel.apex", "-nl", "-nm"}; final ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -195,12 +187,9 @@ public class CommandLineEditorOptionsTest { /** * Test script options log model no spec. - * - * @throws IOException Signals that an I/O exception has occurred. - * @throws ApexModelException if there is an Apex error */ @Test - public void testScriptOptionsLogModelNoSpec() throws IOException, ApexModelException { + void testScriptOptionsLogModelNoSpec() { final String[] cliArgs = new String[] {"-c", "src/main/resources/examples/scripts/ShellPolicyModel.apex"}; final ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -223,10 +212,9 @@ public class CommandLineEditorOptionsTest { * Test script options input output model. * * @throws IOException Signals that an I/O exception has occurred. - * @throws ApexModelException if there is an Apex error */ @Test - public void testScriptOptionsInputOutputModel() throws IOException, ApexModelException { + void testScriptOptionsInputOutputModel() throws IOException { final File tempLogFileIn = File.createTempFile("ShellPolicyModelIn", ".log"); final File tempLogFileOut = File.createTempFile("ShellPolicyModelOut", ".log"); final File tempModelFileIn = File.createTempFile("ShellPolicyModelIn", ".json"); @@ -243,7 +231,7 @@ public class CommandLineEditorOptionsTest { final String tempLogFileInString = TextFileUtils.getTextFileAsString(tempLogFileIn.getCanonicalPath()); final String tempModelFileInString = TextFileUtils.getTextFileAsString(tempModelFileIn.getCanonicalPath()); - // As a sanity check, count the number of non white space characters in log and model files + // As a sanity check, count the number of non-white space characters in log and model files final int tempLogFileInCharCount = tempLogFileInString.replaceAll("\\s+", "").length(); final int tempModelFileInCharCount = tempModelFileInString.replaceAll("\\s+", "").length(); @@ -268,9 +256,9 @@ public class CommandLineEditorOptionsTest { assertEquals(1154, tempLogFileOutCharCount); assertEquals(3336, tempModelFileOutCharCount); - tempLogFileIn.delete(); - tempModelFileIn.delete(); - tempLogFileOut.delete(); - tempModelFileOut.delete(); + assertTrue(tempLogFileIn.delete()); + assertTrue(tempModelFileIn.delete()); + assertTrue(tempLogFileOut.delete()); + assertTrue(tempModelFileOut.delete()); } } diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java index d2b3a812f..395f4c6bf 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020,2022 Nordix Foundation. + * Modifications Copyright (C) 2019-2020, 2022, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,15 +21,15 @@ package org.onap.policy.apex.auth.clieditor; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; import java.net.URL; -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.model.basicmodel.concepts.AxValidationResult; import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; @@ -41,7 +41,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils; * * @author Liam Fallon (liam.fallon@ericsson.com) */ -public class CommandLineEditorScriptingTest { +class CommandLineEditorScriptingTest { private File tempModelFile; private File tempLogFile; @@ -55,7 +55,7 @@ public class CommandLineEditorScriptingTest { * * @throws IOException Signals that an I/O exception has occurred. */ - @Before + @BeforeEach public void initialiseArgs() throws IOException { tempModelFile = File.createTempFile("SampleLBPolicyMap", ".json"); tempLogFile = File.createTempFile("SampleLBPolicyMap", ".log"); @@ -70,10 +70,10 @@ public class CommandLineEditorScriptingTest { /** * Removes the generated files. */ - @After + @AfterEach public void removeGeneratedFiles() { - tempModelFile.delete(); - tempLogFile.delete(); + assertTrue(tempModelFile.delete()); + assertTrue(tempLogFile.delete()); } /** @@ -83,7 +83,7 @@ public class CommandLineEditorScriptingTest { * @throws ApexModelException if there is an Apex error */ @Test - public void testSamplePolicyScript() throws IOException, ApexModelException { + void testSamplePolicyScript() throws IOException, ApexModelException { final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(samplePolicyArgs); assertEquals(0, cliEditor.getErrorCount()); @@ -118,8 +118,8 @@ public class CommandLineEditorScriptingTest { * @throws ApexModelException if there is an Apex error */ @Test - public void testSampleMapPolicyScript() throws IOException, ApexModelException { - tempModelFile.delete(); + void testSampleMapPolicyScript() throws IOException, ApexModelException { + assertTrue(tempModelFile.delete()); final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(samplePolicyMapArgs); assertEquals(0, cliEditor.getErrorCount()); diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.java index ab9b900af..6984b6701 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 Nordix Foundation. + * Modifications Copyright (C) 2020, 2022, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,15 +21,16 @@ package org.onap.policy.apex.auth.clieditor; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; import java.net.URL; -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.model.basicmodel.handling.ApexModelException; import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; @@ -38,7 +39,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils; /** * The Class TestContextAlbums. */ -public class ContextAlbumsTest { +class ContextAlbumsTest { private String[] logicBlockArgs; private File tempModelFile; @@ -48,30 +49,30 @@ public class ContextAlbumsTest { * * @throws IOException Signals that an I/O exception has occurred. */ - @Before - public void createTempFiles() throws IOException { + @BeforeEach + void createTempFiles() throws IOException { tempModelFile = File.createTempFile("TestPolicyModel", ".json"); logicBlockArgs = new String[] {"-c", "src/test/resources/scripts/ContextAlbums.apex", "-o", - tempModelFile.getAbsolutePath(), "-nl"}; + tempModelFile.getAbsolutePath(), "-nl"}; } /** * Removes the generated models. */ - @After - public void removeGeneratedModels() { - tempModelFile.delete(); + @AfterEach + void removeGeneratedModels() { + assertTrue(tempModelFile.delete()); } /** * Test logic block. * - * @throws IOException Signals that an I/O exception has occurred. + * @throws IOException Signals that an I/O exception has occurred. * @throws ApexModelException if there is an Apex error */ @Test - public void testLogicBlock() throws IOException, ApexModelException { + void testLogicBlock() throws IOException, ApexModelException { final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(logicBlockArgs); assertEquals(1, cliEditor.getErrorCount()); @@ -84,7 +85,7 @@ public class ContextAlbumsTest { assertNotNull(writtenModel); final URL compareModelUrl = - ResourceUtils.getLocalFile("src/test/resources/compare/ContextAlbumsModel_Compare.json"); + ResourceUtils.getLocalFile("src/test/resources/compare/ContextAlbumsModel_Compare.json"); final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream()); // Ignore key info UUIDs diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.java index 9896ab9ee..d407e5a4e 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 Nordix Foundation. + * Modifications Copyright (C) 2020, 2022, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,15 +21,16 @@ package org.onap.policy.apex.auth.clieditor; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; import java.net.URL; import java.nio.file.Paths; -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.model.basicmodel.handling.ApexModelException; import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; @@ -39,7 +40,7 @@ import org.onap.policy.common.utils.resources.TextFileUtils; /** * Test FileMacro in the CLI. */ -public class FileMacroTest { +class FileMacroTest { private String[] fileMacroArgs; private File tempModelFile; @@ -50,8 +51,8 @@ public class FileMacroTest { * * @throws IOException Signals that an I/O exception has occurred. */ - @Before - public void createTempFiles() throws IOException { + @BeforeEach + void createTempFiles() throws IOException { tempModelFile = File.createTempFile("TestPolicyModel", ".json"); tempLogFile = File.createTempFile("TestPolicyModel", ".log"); @@ -62,19 +63,19 @@ public class FileMacroTest { /** * Removes the generated models. */ - @After - public void removeGeneratedModels() { - tempModelFile.delete(); + @AfterEach + void removeGeneratedModels() { + assertTrue(tempModelFile.delete()); } /** * Test logic block macro in CLI scripts. * - * @throws IOException Signals that an I/O exception has occurred. + * @throws IOException Signals that an I/O exception has occurred. * @throws ApexModelException if there is an Apex error */ @Test - public void testLogicBlock() throws IOException, ApexModelException { + void testLogicBlock() throws IOException, ApexModelException { final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(fileMacroArgs); // We expect eight errors assertEquals(8, cliEditor.getErrorCount()); @@ -87,7 +88,7 @@ public class FileMacroTest { final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream()); final URL compareModelUrl = - ResourceUtils.getLocalFile("src/test/resources/compare/FileMacroModel_Compare.json"); + ResourceUtils.getLocalFile("src/test/resources/compare/FileMacroModel_Compare.json"); final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream()); // Ignore key info UUIDs @@ -100,11 +101,11 @@ public class FileMacroTest { final File outputLogFile = new File(tempLogFile.getCanonicalPath()); final String outputLogString = TextFileUtils.getTextFileAsString(outputLogFile.getCanonicalPath()) - .replace(Paths.get("").toAbsolutePath().toString() + File.separator, "").replaceAll("\\s+", ""); + .replace(Paths.get("").toAbsolutePath() + File.separator, "").replaceAll("\\s+", ""); // We compare the log to what we expect to get final String outputLogCompareString = TextFileUtils - .getTextFileAsString("src/test/resources/compare/FileMacro_Compare.log").replaceAll("\\s+", ""); + .getTextFileAsString("src/test/resources/compare/FileMacro_Compare.log").replaceAll("\\s+", ""); // Check what we got is what we expected to get assertEquals(outputLogCompareString, outputLogString); diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.java index 077f354f6..e30780ca0 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020,2022 Nordix Foundation. + * Modifications Copyright (C) 2020, 2022, 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,24 +21,24 @@ package org.onap.policy.apex.auth.clieditor; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; import java.net.URL; -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.model.basicmodel.handling.ApexModelException; import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; import org.onap.policy.common.utils.resources.ResourceUtils; -// TODO: Auto-generated Javadoc /** * The Class TestLogicBlock. */ -public class LogicBlockTest { +class LogicBlockTest { private String[] logicBlockArgs; private String[] avroSchemaArgs; @@ -50,35 +50,35 @@ public class LogicBlockTest { * * @throws IOException Signals that an I/O exception has occurred. */ - @Before - public void createTempFiles() throws IOException { + @BeforeEach + void createTempFiles() throws IOException { tempLogicModelFile = File.createTempFile("TestLogicPolicyModel", ".json"); tempAvroModelFile = File.createTempFile("TestAvroPolicyModel", ".json"); logicBlockArgs = new String[] {"-c", "src/test/resources/scripts/LogicBlock.apex", "-o", - tempLogicModelFile.getCanonicalPath(), "-if", "true", "-nl"}; + tempLogicModelFile.getCanonicalPath(), "-if", "true", "-nl"}; avroSchemaArgs = new String[] {"-c", "src/test/resources/scripts/AvroSchema.apex", "-o", - tempAvroModelFile.getCanonicalPath(), "-nl"}; + tempAvroModelFile.getCanonicalPath(), "-nl"}; } /** * Removes the temp files. */ - @After - public void removeTempFiles() { - tempLogicModelFile.delete(); - tempAvroModelFile.delete(); + @AfterEach + void removeTempFiles() { + assertTrue(tempLogicModelFile.delete()); + assertTrue(tempAvroModelFile.delete()); } /** * Test logic block. * - * @throws IOException Signals that an I/O exception has occurred. + * @throws IOException Signals that an I/O exception has occurred. * @throws ApexModelException if there is an Apex error */ @Test - public void testLogicBlock() throws IOException, ApexModelException { + void testLogicBlock() throws IOException, ApexModelException { new ApexCommandLineEditorMain(logicBlockArgs); // Read the file from disk @@ -89,7 +89,7 @@ public class LogicBlockTest { final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream()); final URL compareModelUrl = - ResourceUtils.getLocalFile("src/test/resources/compare/LogicBlockModel_Compare.json"); + ResourceUtils.getLocalFile("src/test/resources/compare/LogicBlockModel_Compare.json"); final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream()); // Ignore key info UUIDs @@ -102,11 +102,11 @@ public class LogicBlockTest { /** * Test avro schema. * - * @throws IOException Signals that an I/O exception has occurred. + * @throws IOException Signals that an I/O exception has occurred. * @throws ApexModelException if there is an Apex error */ @Test - public void testAvroSchema() throws IOException, ApexModelException { + void testAvroSchema() throws IOException, ApexModelException { new ApexCommandLineEditorMain(avroSchemaArgs); // Read the file from disk @@ -117,7 +117,7 @@ public class LogicBlockTest { final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream()); final URL compareModelUrl = - ResourceUtils.getLocalFile("src/test/resources/compare/AvroSchemaModel_Compare.json"); + ResourceUtils.getLocalFile("src/test/resources/compare/AvroSchemaModel_Compare.json"); final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream()); // Ignore key info UUIDs diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java index 51659c2ea..9399b821b 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019,2022 Nordix Foundation. + * Copyright (C) 2019, 2022, 2024 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,17 +22,17 @@ package org.onap.policy.apex.auth.clieditor.tosca; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.resources.TextFileUtils; /** @@ -40,7 +40,7 @@ import org.onap.policy.common.utils.resources.TextFileUtils; * * @author Ajith Sreekumar (ajith.sreekumar@est.tech) */ -public class ApexCliToscaEditorTest { +class ApexCliToscaEditorTest { private File tempOutputToscaFile; private File tempLogFile; @@ -52,7 +52,7 @@ public class ApexCliToscaEditorTest { * * @throws IOException Signals that an I/O exception has occurred. */ - @Before + @BeforeEach public void initialiseArgs() throws IOException { tempOutputToscaFile = File.createTempFile("ToscaPolicyOutput", ".json"); @@ -64,21 +64,21 @@ public class ApexCliToscaEditorTest { "-t", CommonTestData.INPUT_TOSCA_TEMPLATE_FILE_NAME, "-ot", tempOutputToscaFile.getAbsolutePath(), "-l", tempLogFile.getAbsolutePath() - }; + }; } /** * Removes the generated files. */ - @After + @AfterEach public void removeGeneratedFiles() { - tempOutputToscaFile.delete(); - tempLogFile.delete(); - tempNodeTemplateFile.delete(); + assertTrue(tempOutputToscaFile.delete()); + assertTrue(tempLogFile.delete()); + assertTrue(tempNodeTemplateFile.delete()); } @Test - public void testApexCliToscaParameterParser() { + void testApexCliToscaParameterParser() { ApexCliToscaParameters params = new ApexCliToscaParameterParser().parse(sampleArgs); assertEquals(CommonTestData.APEX_CONFIG_FILE_NAME, params.getApexConfigFileName()); assertEquals(CommonTestData.COMMAND_FILE_NAME, params.getCommandFileName()); @@ -88,7 +88,7 @@ public class ApexCliToscaEditorTest { } @Test - public void testApexCliTosca_success() throws IOException { + void testApexCliTosca_success() throws IOException { final ApexCliToscaEditorMain cliEditor = new ApexCliToscaEditorMain(sampleArgs); @@ -101,24 +101,26 @@ public class ApexCliToscaEditorTest { } @Test - public void testApexCliTosca_no_args() { + void testApexCliTosca_no_args() { String[] noArgs = new String[] {}; assertThatThrownBy(() -> new ApexCliToscaEditorMain(noArgs)).hasMessage("Insufficient arguments provided."); } @Test - public void testApexCliTosca_missing_commandfile() { - String[] sampleArgs = new String[] { - "-ac", CommonTestData.APEX_CONFIG_FILE_NAME, - "-t", CommonTestData.INPUT_TOSCA_TEMPLATE_FILE_NAME, - "-ot", tempOutputToscaFile.getAbsolutePath(), - "-l", tempLogFile.getAbsolutePath() + void testApexCliTosca_missing_commandFile() { + assertThatThrownBy(() -> { + String[] sampleArgs = new String[] { + "-ac", CommonTestData.APEX_CONFIG_FILE_NAME, + "-t", CommonTestData.INPUT_TOSCA_TEMPLATE_FILE_NAME, + "-ot", tempOutputToscaFile.getAbsolutePath(), + "-l", tempLogFile.getAbsolutePath() }; - assertThatThrownBy(() -> new ApexCliToscaEditorMain(sampleArgs)).hasMessage("Insufficient arguments provided."); + new ApexCliToscaEditorMain(sampleArgs); + }).hasMessage("Insufficient arguments provided."); } @Test - public void testGenerateToscaPolicyMetadataSet() throws Exception { + void testGenerateToscaPolicyMetadataSet() throws Exception { // @formatter:off final String[] cliArgs = new String[] { "-c", CommonTestData.COMMAND_FILE_NAME, @@ -135,9 +137,9 @@ public class ApexCliToscaEditorTest { assertTrue(tempOutputToscaFile.length() > 0); assertTrue(Files.lines(Paths.get(tempOutputToscaFile.toString())) - .noneMatch(l -> l.contains("policy_type_impl"))); + .noneMatch(l -> l.contains("policy_type_impl"))); assertTrue(tempNodeTemplateFile.length() > 0); assertTrue(Files.lines(Paths.get(tempNodeTemplateFile.toString())) - .anyMatch(l -> l.contains("policyModel"))); + .anyMatch(l -> l.contains("policyModel"))); } } diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java index ba3ab7627..eb1fabec5 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019,2022 Nordix Foundation. + * Copyright (C) 2019, 2022, 2024 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,17 +22,17 @@ package org.onap.policy.apex.auth.clieditor.utils; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.Properties; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaParameterParser; import org.onap.policy.apex.auth.clieditor.tosca.ApexCliToscaParameters; import org.onap.policy.apex.auth.clieditor.tosca.CommonTestData; @@ -44,7 +44,7 @@ import org.onap.policy.common.utils.resources.TextFileUtils; * * @author Ajith Sreekumar (ajith.sreekumar@est.tech) */ -public class CliUtilsTest { +class CliUtilsTest { private File tempOutputToscaFile; private File tempLogFile; @@ -56,7 +56,7 @@ public class CliUtilsTest { * * @throws IOException Signals that an I/O exception has occurred. */ - @Before + @BeforeEach public void initialiseArgs() throws IOException { tempOutputToscaFile = File.createTempFile("ToscaPolicyOutput", ".json"); @@ -70,14 +70,14 @@ public class CliUtilsTest { /** * Removes the generated files. */ - @After + @AfterEach public void removeGeneratedFiles() { - tempOutputToscaFile.delete(); - tempLogFile.delete(); + assertTrue(tempOutputToscaFile.delete()); + assertTrue(tempLogFile.delete()); } @Test - public void testCreateToscaServiceTemplate() throws IOException, CoderException { + void testCreateToscaServiceTemplate() throws IOException, CoderException { ApexCliToscaParameters params = new ApexCliToscaParameterParser().parse(sampleArgs); CliUtils.createToscaPolicy(params, policyModelFilePath, null); String outputTosca = TextFileUtils.getTextFileAsString(tempOutputToscaFile.getAbsolutePath()); @@ -87,43 +87,43 @@ public class CliUtilsTest { } @Test - public void testValidateReadableFile_validfile() { + void testValidateReadableFile_validFile() { CliUtils.validateReadableFile("Apex Config File", CommonTestData.APEX_CONFIG_FILE_NAME); } @Test - public void testValidateReadableFile_invalidfile() { + void testValidateReadableFile_invalidFile() { String invalidFileName = "src/test/resources/tosca/ApexConfigxyz.json"; assertThatThrownBy(() -> CliUtils.validateReadableFile("Apex Config File", invalidFileName)) .hasMessage("File " + invalidFileName + " of type Apex Config File does not exist"); } @Test - public void testValidateWritableFile_validfile() { + void testValidateWritableFile_validFile() { CliUtils.validateWritableFile("Output Tosca Policy File", tempOutputToscaFile.getAbsolutePath()); } @Test - public void testValidateWritableFile_invalidfile() { + void testValidateWritableFile_invalidFile() { String invalidFileName = "src/test/resources/tosca"; assertThatThrownBy(() -> CliUtils.validateWritableFile("Output Tosca Policy File", invalidFileName)) .hasMessage("File " + invalidFileName + " of type Output Tosca Policy File is not a normal file"); } @Test - public void testValidateWritableDirectory_validdirectory() { + void testValidateWritableDirectory_validDirectory() { CliUtils.validateWritableDirectory("Working Directory", "src/test/resources/tosca"); } @Test - public void testValidateWritableDirectory_invaliddirectory() { + void testValidateWritableDirectory_invalidDirectory() { assertThatThrownBy(() -> CliUtils.validateWritableDirectory("Working Directory", CommonTestData.APEX_CONFIG_FILE_NAME)).hasMessage("directory " + CommonTestData.APEX_CONFIG_FILE_NAME - + " of type Working Directory is not a directory"); + + " of type Working Directory is not a directory"); } @Test - public void testGenerateArgumentsForCliEditor_success() { + void testGenerateArgumentsForCliEditor_success() { ApexCliToscaParameters params = new ApexCliToscaParameterParser().parse(sampleArgs); Properties optionVariableMap = new Properties(); optionVariableMap.setProperty("c", "commandFileName"); @@ -137,7 +137,7 @@ public class CliUtilsTest { } @Test - public void testGenerateArgumentsForCliEditor_invalidvariable() { + void testGenerateArgumentsForCliEditor_invalidVariable() { ApexCliToscaParameters params = new ApexCliToscaParameterParser().parse(sampleArgs); Properties optionVariableMap = new Properties(); optionVariableMap.setProperty("c", "invalidFileName"); @@ -147,7 +147,7 @@ public class CliUtilsTest { } @Test - public void testGenerateArgumentsForCliEditor_missingoption() { + void testGenerateArgumentsForCliEditor_missingOption() { ApexCliToscaParameters params = new ApexCliToscaParameterParser().parse(sampleArgs); Properties optionVariableMap = new Properties(); List<String> cliArgsList = |