From f8000a9d35928f136216be504828ef9074dfb42a Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 23 Jan 2020 16:50:47 +0000 Subject: Remove apex-pdp TextFileUtils class This class was moved to policy-common some time ago. Removing it in apex-pdp. Issue-ID: POLICY-1913 Change-Id: I982fbd799334b34f1526e19f339236b52205b91e Signed-off-by: liamfallon --- .../apex/auth/clieditor/CommandLineEditorLoop.java | 46 ++++++++++---------- .../CommandLineEditorEventsContextTest.java | 50 +++++++++------------- .../clieditor/CommandLineEditorOptionsTest.java | 13 +++--- .../policy/apex/auth/clieditor/FileMacroTest.java | 11 ++--- 4 files changed, 56 insertions(+), 64 deletions(-) (limited to 'auth/cli-editor/src') diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java index b4f31b9e8..93a8f0d14 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,12 +39,13 @@ import java.util.List; import java.util.Map.Entry; import java.util.Properties; import java.util.TreeMap; + import org.apache.commons.lang3.tuple.MutablePair; import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.apex.model.modelapi.ApexApiResult; import org.onap.policy.apex.model.modelapi.ApexApiResult.Result; -import org.onap.policy.apex.model.utilities.TextFileUtils; import org.onap.policy.apex.model.utilities.TreeMapUtils; +import org.onap.policy.common.utils.resources.TextFileUtils; import org.slf4j.ext.XLogger; import org.slf4j.ext.XLoggerFactory; @@ -83,7 +84,7 @@ public class CommandLineEditorLoop { * @param rootKeywordNode The root keyword node tree */ public CommandLineEditorLoop(final Properties properties, final ApexModelHandler modelHandler, - final KeywordNode rootKeywordNode) { + final KeywordNode rootKeywordNode) { this.modelHandler = modelHandler; keywordNodeDeque.push(rootKeywordNode); @@ -102,7 +103,7 @@ public class CommandLineEditorLoop { * @throws IOException Thrown on exceptions on IO */ public int runLoop(final InputStream inputStream, final OutputStream outputStream, - final CommandLineParameters parameters) throws IOException { + final CommandLineParameters parameters) throws IOException { // Readers and writers for input and output final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); final PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream)); @@ -160,8 +161,7 @@ public class CommandLineEditorLoop { * @param executionStatus the status of the logic block read */ private void processIncomingCommands(final CommandLineParameters parameters, final BufferedReader reader, - final PrintWriter writer, final CommandLineParser parser, - MutablePair executionStatus) { + final PrintWriter writer, final CommandLineParser parser, MutablePair executionStatus) { try { // Output prompt and get a line of input @@ -197,8 +197,8 @@ public class CommandLineEditorLoop { final CommandLineCommand command = findCommand(commandWords); if (command != null) { // Check the arguments of the command - final TreeMap argumentValues = getArgumentValues(command, - commandWords); + final TreeMap argumentValues = + getArgumentValues(command, commandWords); // Execute the command, a FINISHED result means a command causes the loop to // leave execution @@ -229,7 +229,7 @@ public class CommandLineEditorLoop { * @return the result of the logic block read */ private String readLogicBlock(final CommandLineParameters parameters, final BufferedReader reader, - final PrintWriter writer, MutablePair executionStatus) { + final PrintWriter writer, MutablePair executionStatus) { String logicBlock; logicBlock = ""; @@ -311,15 +311,15 @@ public class CommandLineEditorLoop { // If the node entries found is not equal to one, then we have either no command or more // than one command matching - final List> foundNodeEntries = findMatchingEntries( - searchKeywordNode.getChildren(), commandWords.get(i)); + final List> foundNodeEntries = + findMatchingEntries(searchKeywordNode.getChildren(), commandWords.get(i)); if (foundNodeEntries.isEmpty()) { unwindStack(startKeywordNode); throw new CommandLineException("command not found: " + stringAL2String(commandWords)); } else if (foundNodeEntries.size() > 1) { unwindStack(startKeywordNode); throw new CommandLineException("multiple commands matched: " + stringAL2String(commandWords) + " [" - + nodeAL2String(foundNodeEntries) + ']'); + + nodeAL2String(foundNodeEntries) + ']'); } // Record the fully expanded command word @@ -365,7 +365,7 @@ public class CommandLineEditorLoop { * @return the argument values */ private TreeMap getArgumentValues(final CommandLineCommand command, - final List commandWords) { + final List commandWords) { final TreeMap argumentValues = new TreeMap<>(); for (final CommandLineArgument argument : command.getArgumentList()) { if (argument != null) { @@ -375,14 +375,14 @@ public class CommandLineEditorLoop { // Set the value of the arguments for (final Entry argument : getCommandArguments(commandWords)) { - final List> foundArguments = TreeMapUtils - .findMatchingEntries(argumentValues, argument.getKey()); + final List> foundArguments = + TreeMapUtils.findMatchingEntries(argumentValues, argument.getKey()); if (foundArguments.isEmpty()) { throw new CommandLineException(COMMAND + stringAL2String(commandWords) + ": " + " argument \"" - + argument.getKey() + "\" not allowed on command"); + + argument.getKey() + "\" not allowed on command"); } else if (foundArguments.size() > 1) { throw new CommandLineException(COMMAND + stringAL2String(commandWords) + ": " + " argument " + argument - + " matches multiple arguments [" + argumentAL2String(foundArguments) + ']'); + + " matches multiple arguments [" + argumentAL2String(foundArguments) + ']'); } // Set the value of the argument, stripping off any quotes @@ -396,7 +396,7 @@ public class CommandLineEditorLoop { // mandatory if (!argumentValue.isSpecified() && !argumentValue.getCliArgument().isNullable()) { throw new CommandLineException(COMMAND + stringAL2String(commandWords) + ": " + " mandatory argument \"" - + argumentValue.getCliArgument().getArgumentName() + "\" not specified"); + + argumentValue.getCliArgument().getArgumentName() + "\" not specified"); } } @@ -417,8 +417,8 @@ public class CommandLineEditorLoop { for (final String word : commandWords) { final int equalsPos = word.indexOf('='); if (equalsPos > 0) { - arguments.add(new SimpleEntry<>(word.substring(0, equalsPos), - word.substring(equalsPos + 1, word.length()))); + arguments.add( + new SimpleEntry<>(word.substring(0, equalsPos), word.substring(equalsPos + 1, word.length()))); } } @@ -434,7 +434,7 @@ public class CommandLineEditorLoop { * @return the result of execution of the command */ private Result executeCommand(final CommandLineCommand command, - final TreeMap argumentValues, final PrintWriter writer) { + final TreeMap argumentValues, final PrintWriter writer) { if (command.isSystemCommand()) { return exceuteSystemCommand(command, writer); } else { @@ -575,8 +575,8 @@ public class CommandLineEditorLoop { if (macroFileName.length() > 2 && macroFileName.startsWith("\"") && macroFileName.endsWith("\"")) { macroFileName = macroFileName.substring(1, macroFileName.length() - 1); } else { - throw new CommandLineException("macro file name \"" + macroFileName - + "\" must exist and be quoted with double quotes \"\""); + throw new CommandLineException( + "macro file name \"" + macroFileName + "\" must exist and be quoted with double quotes \"\""); } // Append the working directory to the macro file name 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 efd12f4e4..88d99a27d 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,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 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========================================================= */ @@ -31,7 +32,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; -import org.onap.policy.apex.model.utilities.TextFileUtils; +import org.onap.policy.common.utils.resources.TextFileUtils; /** * The Class TestCLIEditorEventsContext. @@ -69,9 +70,8 @@ public class CommandLineEditorEventsContextTest { final File tempLogFile = temporaryFolder.newFile(LOG_FILE); final File tempModelFile = temporaryFolder.newFile(JSON_FILE); - final String[] cliArgs = new String[] - { "-c", APEX_JAVA_POLICY_FILE.toString(), "-l", tempLogFile.getAbsolutePath(), "-o", - tempModelFile.getAbsolutePath() }; + final String[] cliArgs = new String[] {"-c", APEX_JAVA_POLICY_FILE.toString(), "-l", + tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()}; final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(cliArgs); assertEquals(0, cliEditor.getErrorCount()); @@ -100,9 +100,8 @@ public class CommandLineEditorEventsContextTest { final File tempLogFile = temporaryFolder.newFile(LOG_FILE); final File tempModelFile = temporaryFolder.newFile(JSON_FILE); - final String[] cliArgs = new String[] - { "-c", APEX_AVRO_POLICY_FILE.toString(), "-l", tempLogFile.getAbsolutePath(), "-o", - tempModelFile.getAbsolutePath() }; + final String[] cliArgs = new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", + tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()}; final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(cliArgs); assertEquals(0, cliEditor.getErrorCount()); @@ -127,12 +126,12 @@ public class CommandLineEditorEventsContextTest { final File tempModelFile = temporaryFolder.newFile(JSON_FILE); 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(); + final String apexPropertiesLocation = + 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 }; + final String[] cliArgs = + 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()); @@ -147,21 +146,12 @@ public class CommandLineEditorEventsContextTest { final File modelFile = temporaryFolder.newFile("empty_commands.json"); - final String apexPropertiesLocation = 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 - }; + final String apexPropertiesLocation = + 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}; 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 5e0501288..a5362a8f1 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 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,9 +29,10 @@ 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.onap.policy.apex.model.utilities.TextFileUtils; +import org.onap.policy.common.utils.resources.TextFileUtils; /** * The Class TestCLIEditorOptions. @@ -53,7 +54,7 @@ public class CommandLineEditorOptionsTest { final File tempModelFile = File.createTempFile("ShellPolicyModel", ".json"); final String[] cliArgs = new String[] {"-c", "src/main/resources/examples/scripts/ShellPolicyModel.apex", "-l", - tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()}; + tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath()}; final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(cliArgs); assertEquals(0, cliEditor.getErrorCount()); @@ -85,7 +86,7 @@ public class CommandLineEditorOptionsTest { final File tempModelFile = File.createTempFile("ShellPolicyModel", ".json"); final String[] cliArgs = new String[] {"-c", "src/main/resources/examples/scripts/ShellPolicyModel.apex", "-l", - tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath(), "-nl", "-nm"}; + tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath(), "-nl", "-nm"}; final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(cliArgs); assertEquals(0, cliEditor.getErrorCount()); @@ -117,7 +118,7 @@ public class CommandLineEditorOptionsTest { final File tempModelFile = File.createTempFile("ShellPolicyModel", ".json"); final String[] cliArgs = new String[] {"-c", "src/main/resources/examples/scripts/ShellPolicyModel.apex", "-l", - tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath(), "-nm"}; + tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath(), "-nm"}; final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(cliArgs); assertEquals(0, cliEditor.getErrorCount()); @@ -150,7 +151,7 @@ public class CommandLineEditorOptionsTest { final File tempModelFile = File.createTempFile("ShellPolicyModel", ".json"); final String[] cliArgs = new String[] {"-c", "src/main/resources/examples/scripts/ShellPolicyModel.apex", "-l", - tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath(), "-nl"}; + tempLogFile.getAbsolutePath(), "-o", tempModelFile.getAbsolutePath(), "-nl"}; final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(cliArgs); assertEquals(0, cliEditor.getErrorCount()); 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 5bded368e..f458a9fb9 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,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020 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========================================================= */ @@ -34,8 +35,8 @@ import org.junit.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.apex.model.utilities.TextFileUtils; import org.onap.policy.common.utils.resources.ResourceUtils; +import org.onap.policy.common.utils.resources.TextFileUtils; /** * Test FileMacro in the CLI. @@ -57,7 +58,7 @@ public class FileMacroTest { tempLogFile = File.createTempFile("TestPolicyModel", ".log"); fileMacroArgs = new String[] {"-c", "src/test/resources/scripts/FileMacro.apex", "-l", - tempLogFile.getCanonicalPath(), "-o", tempModelFile.getCanonicalPath(), "-if", "true"}; + tempLogFile.getCanonicalPath(), "-o", tempModelFile.getCanonicalPath(), "-if", "true"}; } /** -- cgit 1.2.3-korg