From 4cfa2e2d98f6877d54da304ef17f096284430908 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 13 Sep 2018 15:25:32 +0100 Subject: Sonar/Checkstyle in service/plugins Sonar and Checkstyle changes in plugins and services, and knock on changes Issue-ID: POLICY-1034 Change-Id: Iff7df74e54fce2c661dcc2fae75ae93d4cacfe5b Signed-off-by: liamfallon --- .../auth/clieditor/TestCLIEditorEventsContext.java | 161 ------------ .../apex/auth/clieditor/TestCLIEditorOptions.java | 277 --------------------- .../auth/clieditor/TestCLIEditorScripting.java | 132 ---------- .../TestCommandLineEditorEventsContext.java | 171 +++++++++++++ .../clieditor/TestCommandLineEditorOptions.java | 277 +++++++++++++++++++++ .../clieditor/TestCommandLineEditorScripting.java | 132 ++++++++++ .../apex/auth/clieditor/TestContextAlbums.java | 18 +- .../policy/apex/auth/clieditor/TestFileMacro.java | 18 +- .../policy/apex/auth/clieditor/TestLogicBlock.java | 32 ++- 9 files changed, 628 insertions(+), 590 deletions(-) delete mode 100644 auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorEventsContext.java delete mode 100644 auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorOptions.java delete mode 100644 auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorScripting.java create mode 100644 auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCommandLineEditorEventsContext.java create mode 100644 auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCommandLineEditorOptions.java create mode 100644 auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCommandLineEditorScripting.java (limited to 'auth/cli-editor/src/test/java/org/onap') diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorEventsContext.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorEventsContext.java deleted file mode 100644 index bd75ddf76..000000000 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorEventsContext.java +++ /dev/null @@ -1,161 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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.auth.clieditor; - -import static org.junit.Assert.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.onap.policy.apex.model.utilities.TextFileUtils; - -/** - * The Class TestCLIEditorEventsContext. - */ -public class TestCLIEditorEventsContext { - // CHECKSTYLE:OFF: MagicNumber - - private static final Path SRC_MAIN_FOLDER = Paths.get("src/main/resources/"); - private static final Path SRC_TEST_FOLDER = Paths.get("src/test/resources/"); - - private static final Path SUB_FOLDER = SRC_MAIN_FOLDER.resolve("examples/scripts/"); - - private static final String SPACES = "\\s+"; - private static final String EMPTY_STRING = ""; - - private static final Path APEX_AVRO_POLICY_FILE = SUB_FOLDER.resolve("TestPolicyAvroEventContext.apex"); - private static final Path APEX_JAVA_POLICY_FILE = SUB_FOLDER.resolve("TestPolicyJavaEventContext.apex"); - - private static final String FILE_NAME = "TestPolicyJavaEventsAndContext"; - private static final String JSON_FILE = FILE_NAME + ".json"; - private static final String LOG_FILE = FILE_NAME + ".log"; - - - @Rule - public TemporaryFolder temporaryFolder = new 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 { - - 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 ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(cliArgs); - assertEquals(0, cliEditor.getErrorCount()); - - // Get the model and log into strings - 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 - final int logCharCount = logString.replaceAll(SPACES, EMPTY_STRING).length(); - final int modelCharCount = modelString.replaceAll(SPACES, EMPTY_STRING).length(); - - assertEquals(25962, logCharCount); - assertEquals(46189, modelCharCount); - } - - /** - * 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 { - - 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 ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(cliArgs); - assertEquals(0, cliEditor.getErrorCount()); - - // Get the model and log into strings - 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 - final int logCharCount = logString.replaceAll(SPACES, EMPTY_STRING).length(); - final int modelCharCount = modelString.replaceAll(SPACES, EMPTY_STRING).length(); - - assertEquals(30407, logCharCount); - assertEquals(53022, modelCharCount); - - } - - @Test - public void test_emptyMetadataCommandFileWithEmptyJsonTag_errorcountGreaterThanOne() throws IOException { - - final File tempLogFile = temporaryFolder.newFile(LOG_FILE); - 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[] cliArgs = - new String[] {"-c", APEX_AVRO_POLICY_FILE.toString(), "-l", tempLogFile.getAbsolutePath(), "-o", - tempModelFile.getAbsolutePath(), "-m", modelFile, "-a", apexPropertiesLocation}; - - final ApexCLIEditorMain objUnderTest = new ApexCLIEditorMain(cliArgs); - assertEquals(1, objUnderTest.getErrorCount()); - - } - - @Test - public void test_emptyMetadataCommandFile_errorcountGreaterThanOne() throws IOException { - - final File tempLogFile = temporaryFolder.newFile(LOG_FILE); - final File tempModelFile = temporaryFolder.newFile(JSON_FILE); - - 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 ApexCLIEditorMain objUnderTest = new ApexCLIEditorMain(cliArgs); - assertEquals(1, objUnderTest.getErrorCount()); - - } - -} diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorOptions.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorOptions.java deleted file mode 100644 index 2056c9239..000000000 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorOptions.java +++ /dev/null @@ -1,277 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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.auth.clieditor; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.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.onap.policy.apex.model.utilities.TextFileUtils; - -/** - * The Class TestCLIEditorOptions. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestCLIEditorOptions { - // 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 { - final File tempLogFile = File.createTempFile("ShellPolicyModel", ".log"); - 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()}; - - final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(cliArgs); - assertEquals(0, cliEditor.getErrorCount()); - - // Get the model and log into strings - 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 - final int logCharCount = logString.replaceAll("\\s+", "").length(); - final int modelCharCount = modelString.replaceAll("\\s+", "").length(); - - assertEquals(1204, logCharCount); - assertEquals(2924, modelCharCount); - - tempLogFile.delete(); - 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 { - final File tempLogFile = File.createTempFile("ShellPolicyModel", ".log"); - 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"}; - - final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(cliArgs); - assertEquals(0, cliEditor.getErrorCount()); - - // Get the model and log into strings - 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 - final int logCharCount = logString.replaceAll("\\s+", "").length(); - final int modelCharCount = modelString.replaceAll("\\s+", "").length(); - - assertEquals(0, logCharCount); - assertEquals(0, modelCharCount); - - tempLogFile.delete(); - 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 { - final File tempLogFile = File.createTempFile("ShellPolicyModel", ".log"); - 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"}; - - final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(cliArgs); - assertEquals(0, cliEditor.getErrorCount()); - - // Get the model and log into strings - final String logString = TextFileUtils.getTextFileAsString(tempLogFile.getCanonicalPath()); - final String modelString = TextFileUtils.getTextFileAsString(tempModelFile.getCanonicalPath()); - - System.err.println(modelString); - // 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(0, modelCharCount); - - tempLogFile.delete(); - 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 { - final File tempLogFile = File.createTempFile("ShellPolicyModel", ".log"); - 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"}; - - final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(cliArgs); - assertEquals(0, cliEditor.getErrorCount()); - - // Get the model and log into strings - 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 - final int logCharCount = logString.replaceAll("\\s+", "").length(); - final int modelCharCount = modelString.replaceAll("\\s+", "").length(); - - assertEquals(0, logCharCount); - assertEquals(2924, modelCharCount); - - tempLogFile.delete(); - 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 { - final String[] cliArgs = - new String[] {"-c", "src/main/resources/examples/scripts/ShellPolicyModel.apex", "-nl", "-nm"}; - - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - System.setOut(new PrintStream(baos)); - final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(cliArgs); - assertEquals(0, cliEditor.getErrorCount()); - - // Cursor for log - assertFalse(baos.toString().contains(">")); - - // Curly bracket from JSON model - assertFalse(baos.toString().contains("{")); - } - - /** - * 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 { - final String[] cliArgs = new String[] {"-c", "src/main/resources/examples/scripts/ShellPolicyModel.apex"}; - - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - final PrintStream stdout = System.out; - System.setOut(new PrintStream(baos)); - final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(cliArgs); - assertEquals(0, cliEditor.getErrorCount()); - - // Cursor for log - assertTrue(baos.toString().contains(">")); - - // Curly bracket from JSON model - assertTrue(baos.toString().contains("{")); - - System.setOut(stdout); - } - - /** - * 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 { - final File tempLogFileIn = File.createTempFile("ShellPolicyModelIn", ".log"); - final File tempLogFileOut = File.createTempFile("ShellPolicyModelOut", ".log"); - final File tempModelFileIn = File.createTempFile("ShellPolicyModelIn", ".json"); - final File tempModelFileOut = File.createTempFile("ShellPolicyModelOut", ".json"); - - // Generate input model - final String[] cliArgsIn = new String[] {"-c", "src/main/resources/examples/scripts/ShellPolicyModel.apex", - "-l", tempLogFileIn.getAbsolutePath(), "-o", tempModelFileIn.getAbsolutePath()}; - - final ApexCLIEditorMain cliEditorIn = new ApexCLIEditorMain(cliArgsIn); - assertEquals(0, cliEditorIn.getErrorCount()); - - // Get the model and log into strings - 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 - final int tempLogFileInCharCount = tempLogFileInString.replaceAll("\\s+", "").length(); - final int tempModelFileInCharCount = tempModelFileInString.replaceAll("\\s+", "").length(); - - assertEquals(1204, tempLogFileInCharCount); - assertEquals(2924, tempModelFileInCharCount); - - final String[] cliArgsOut = new String[] {"-i", tempModelFileIn.getAbsolutePath(), "-c", - "src/main/resources/examples/scripts/ShellPolicyModelAddSchema.apex", "-l", - tempLogFileOut.getAbsolutePath(), "-o", tempModelFileOut.getAbsolutePath()}; - - final ApexCLIEditorMain cliEditorOut = new ApexCLIEditorMain(cliArgsOut); - assertEquals(0, cliEditorOut.getErrorCount()); - - // Get the model and log into strings - final String tempLogFileOutString = TextFileUtils.getTextFileAsString(tempLogFileOut.getCanonicalPath()); - final String tempModelFileOutString = TextFileUtils.getTextFileAsString(tempModelFileOut.getCanonicalPath()); - - // As a sanity check, count the number of non white space characters in log and model files - final int tempLogFileOutCharCount = tempLogFileOutString.replaceAll("\\s+", "").length(); - final int tempModelFileOutCharCount = tempModelFileOutString.replaceAll("\\s+", "").length(); - - assertEquals(1154, tempLogFileOutCharCount); - assertEquals(3356, tempModelFileOutCharCount); - - tempLogFileIn.delete(); - tempModelFileIn.delete(); - tempLogFileOut.delete(); - tempModelFileOut.delete(); - } -} diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorScripting.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorScripting.java deleted file mode 100644 index 44cc5c702..000000000 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorScripting.java +++ /dev/null @@ -1,132 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * 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.auth.clieditor; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.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.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; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.common.utils.resources.ResourceUtils; - -/** - * The Class TestCLIEditorScripting. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestCLIEditorScripting { - - private File tempModelFile; - private File tempLogFile; - - private String[] sampleLBPolicyArgs; - - private String[] sampleLBPolicyMapArgs; - - /** - * Initialise args. - * - * @throws IOException Signals that an I/O exception has occurred. - */ - @Before - public void initialiseArgs() throws IOException { - tempModelFile = File.createTempFile("SampleLBPolicyMap", ".json"); - tempLogFile = File.createTempFile("SampleLBPolicyMap", ".log"); - - sampleLBPolicyArgs = new String[] {"-c", "src/test/resources/scripts/SampleLBPolicy.apex", "-o", - tempModelFile.getAbsolutePath(), "-l", tempLogFile.getAbsolutePath()}; - - sampleLBPolicyMapArgs = new String[] {"-c", "src/test/resources/scripts/SampleLBPolicy_WithMap.apex", "-o", - tempModelFile.getAbsolutePath(), "-l", tempLogFile.getAbsolutePath()}; - } - - /** - * Removes the generated files. - */ - @After - public void removeGeneratedFiles() { - tempModelFile.delete(); - tempLogFile.delete(); - } - - /** - * Test sample Fuzzy LB policy script. - * - * @throws IOException Signals that an I/O exception has occurred. - * @throws ApexModelException if there is an Apex error - */ - @Test - public void testSampleLBPolicyScript() throws IOException, ApexModelException { - final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(sampleLBPolicyArgs); - assertEquals(0, cliEditor.getErrorCount()); - - // Read the file from disk - final ApexModelReader modelReader = new ApexModelReader<>(AxPolicyModel.class); - - final URL writtenModelURL = ResourceUtils.getLocalFile(tempModelFile.getCanonicalPath()); - final AxPolicyModel writtenModel = modelReader.read(writtenModelURL.openStream()); - - final URL compareModelURL = - ResourceUtils.getLocalFile("src/test/resources/compare/FuzzyPolicyModel_Compare.json"); - final AxPolicyModel compareModel = modelReader.read(compareModelURL.openStream()); - - // Ignore key info UUIDs - writtenModel.getKeyInformation().getKeyInfoMap().clear(); - compareModel.getKeyInformation().getKeyInfoMap().clear(); - - assertTrue(writtenModel.equals(compareModel)); - } - - /** - * Test sample Fuzzy LB map policy script. - * - * @throws IOException Signals that an I/O exception has occurred. - * @throws ApexModelException if there is an Apex error - */ - @Test - public void testSampleLBMapPolicyScript() throws IOException, ApexModelException { - tempModelFile.delete(); - - final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(sampleLBPolicyMapArgs); - assertEquals(0, cliEditor.getErrorCount()); - - assertTrue(tempModelFile.isFile()); - - // Read the file from disk - final ApexModelReader modelReader = new ApexModelReader<>(AxPolicyModel.class); - - final URL writtenModelURL = ResourceUtils.getLocalFile(tempModelFile.getCanonicalPath()); - final AxPolicyModel writtenModel = modelReader.read(writtenModelURL.openStream()); - - final AxValidationResult validationResult = new AxValidationResult(); - writtenModel.validate(validationResult); - assertEquals(AxValidationResult.ValidationResult.OBSERVATION, validationResult.getValidationResult()); - } -} diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCommandLineEditorEventsContext.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCommandLineEditorEventsContext.java new file mode 100644 index 000000000..b0d82b6fa --- /dev/null +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCommandLineEditorEventsContext.java @@ -0,0 +1,171 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * 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.auth.clieditor; + +import static org.junit.Assert.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.onap.policy.apex.model.utilities.TextFileUtils; + +/** + * The Class TestCLIEditorEventsContext. + */ +public class TestCommandLineEditorEventsContext { + // CHECKSTYLE:OFF: MagicNumber + + private static final Path SRC_MAIN_FOLDER = Paths.get("src/main/resources/"); + private static final Path SRC_TEST_FOLDER = Paths.get("src/test/resources/"); + + private static final Path SUB_FOLDER = SRC_MAIN_FOLDER.resolve("examples/scripts/"); + + private static final String SPACES = "\\s+"; + private static final String EMPTY_STRING = ""; + + private static final Path APEX_AVRO_POLICY_FILE = SUB_FOLDER.resolve("TestPolicyAvroEventContext.apex"); + private static final Path APEX_JAVA_POLICY_FILE = SUB_FOLDER.resolve("TestPolicyJavaEventContext.apex"); + + private static final String FILE_NAME = "TestPolicyJavaEventsAndContext"; + private static final String JSON_FILE = FILE_NAME + ".json"; + private static final String LOG_FILE = FILE_NAME + ".log"; + + @Rule + public TemporaryFolder temporaryFolder = new 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 { + + 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 ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(cliArgs); + assertEquals(0, cliEditor.getErrorCount()); + + // Get the model and log into strings + 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 + final int logCharCount = logString.replaceAll(SPACES, EMPTY_STRING).length(); + final int modelCharCount = modelString.replaceAll(SPACES, EMPTY_STRING).length(); + + assertEquals(25962, logCharCount); + assertEquals(46189, modelCharCount); + } + + /** + * 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 { + + 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 ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(cliArgs); + assertEquals(0, cliEditor.getErrorCount()); + + // Get the model and log into strings + 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 + final int logCharCount = logString.replaceAll(SPACES, EMPTY_STRING).length(); + final int modelCharCount = modelString.replaceAll(SPACES, EMPTY_STRING).length(); + + assertEquals(30407, logCharCount); + assertEquals(53022, modelCharCount); + + } + + @Test + public void test_emptyMetadataCommandFileWithEmptyJsonTag_errorcountGreaterThanOne() throws IOException { + + final File tempLogFile = temporaryFolder.newFile(LOG_FILE); + 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[] 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()); + + } + + @Test + public void test_emptyMetadataCommandFile_errorcountGreaterThanOne() throws IOException { + + final File tempLogFile = temporaryFolder.newFile(LOG_FILE); + final File tempModelFile = temporaryFolder.newFile(JSON_FILE); + + 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 ApexCommandLineEditorMain objUnderTest = new ApexCommandLineEditorMain(cliArgs); + assertEquals(1, objUnderTest.getErrorCount()); + + } + +} diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCommandLineEditorOptions.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCommandLineEditorOptions.java new file mode 100644 index 000000000..5ff87c01b --- /dev/null +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCommandLineEditorOptions.java @@ -0,0 +1,277 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * 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.auth.clieditor; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.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.onap.policy.apex.model.utilities.TextFileUtils; + +/** + * The Class TestCLIEditorOptions. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class TestCommandLineEditorOptions { + // 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 { + final File tempLogFile = File.createTempFile("ShellPolicyModel", ".log"); + 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()}; + + final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(cliArgs); + assertEquals(0, cliEditor.getErrorCount()); + + // Get the model and log into strings + 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 + final int logCharCount = logString.replaceAll("\\s+", "").length(); + final int modelCharCount = modelString.replaceAll("\\s+", "").length(); + + assertEquals(1204, logCharCount); + assertEquals(2924, modelCharCount); + + tempLogFile.delete(); + 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 { + final File tempLogFile = File.createTempFile("ShellPolicyModel", ".log"); + 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"}; + + final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(cliArgs); + assertEquals(0, cliEditor.getErrorCount()); + + // Get the model and log into strings + 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 + final int logCharCount = logString.replaceAll("\\s+", "").length(); + final int modelCharCount = modelString.replaceAll("\\s+", "").length(); + + assertEquals(0, logCharCount); + assertEquals(0, modelCharCount); + + tempLogFile.delete(); + 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 { + final File tempLogFile = File.createTempFile("ShellPolicyModel", ".log"); + 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"}; + + final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(cliArgs); + assertEquals(0, cliEditor.getErrorCount()); + + // Get the model and log into strings + final String logString = TextFileUtils.getTextFileAsString(tempLogFile.getCanonicalPath()); + final String modelString = TextFileUtils.getTextFileAsString(tempModelFile.getCanonicalPath()); + + System.err.println(modelString); + // 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(0, modelCharCount); + + tempLogFile.delete(); + 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 { + final File tempLogFile = File.createTempFile("ShellPolicyModel", ".log"); + 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"}; + + final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(cliArgs); + assertEquals(0, cliEditor.getErrorCount()); + + // Get the model and log into strings + 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 + final int logCharCount = logString.replaceAll("\\s+", "").length(); + final int modelCharCount = modelString.replaceAll("\\s+", "").length(); + + assertEquals(0, logCharCount); + assertEquals(2924, modelCharCount); + + tempLogFile.delete(); + 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 { + final String[] cliArgs = + new String[] {"-c", "src/main/resources/examples/scripts/ShellPolicyModel.apex", "-nl", "-nm"}; + + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + System.setOut(new PrintStream(baos)); + final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(cliArgs); + assertEquals(0, cliEditor.getErrorCount()); + + // Cursor for log + assertFalse(baos.toString().contains(">")); + + // Curly bracket from JSON model + assertFalse(baos.toString().contains("{")); + } + + /** + * 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 { + final String[] cliArgs = new String[] {"-c", "src/main/resources/examples/scripts/ShellPolicyModel.apex"}; + + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + final PrintStream stdout = System.out; + System.setOut(new PrintStream(baos)); + final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(cliArgs); + assertEquals(0, cliEditor.getErrorCount()); + + // Cursor for log + assertTrue(baos.toString().contains(">")); + + // Curly bracket from JSON model + assertTrue(baos.toString().contains("{")); + + System.setOut(stdout); + } + + /** + * 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 { + final File tempLogFileIn = File.createTempFile("ShellPolicyModelIn", ".log"); + final File tempLogFileOut = File.createTempFile("ShellPolicyModelOut", ".log"); + final File tempModelFileIn = File.createTempFile("ShellPolicyModelIn", ".json"); + final File tempModelFileOut = File.createTempFile("ShellPolicyModelOut", ".json"); + + // Generate input model + final String[] cliArgsIn = new String[] {"-c", "src/main/resources/examples/scripts/ShellPolicyModel.apex", + "-l", tempLogFileIn.getAbsolutePath(), "-o", tempModelFileIn.getAbsolutePath()}; + + final ApexCommandLineEditorMain cliEditorIn = new ApexCommandLineEditorMain(cliArgsIn); + assertEquals(0, cliEditorIn.getErrorCount()); + + // Get the model and log into strings + 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 + final int tempLogFileInCharCount = tempLogFileInString.replaceAll("\\s+", "").length(); + final int tempModelFileInCharCount = tempModelFileInString.replaceAll("\\s+", "").length(); + + assertEquals(1204, tempLogFileInCharCount); + assertEquals(2924, tempModelFileInCharCount); + + final String[] cliArgsOut = new String[] {"-i", tempModelFileIn.getAbsolutePath(), "-c", + "src/main/resources/examples/scripts/ShellPolicyModelAddSchema.apex", "-l", + tempLogFileOut.getAbsolutePath(), "-o", tempModelFileOut.getAbsolutePath()}; + + final ApexCommandLineEditorMain cliEditorOut = new ApexCommandLineEditorMain(cliArgsOut); + assertEquals(0, cliEditorOut.getErrorCount()); + + // Get the model and log into strings + final String tempLogFileOutString = TextFileUtils.getTextFileAsString(tempLogFileOut.getCanonicalPath()); + final String tempModelFileOutString = TextFileUtils.getTextFileAsString(tempModelFileOut.getCanonicalPath()); + + // As a sanity check, count the number of non white space characters in log and model files + final int tempLogFileOutCharCount = tempLogFileOutString.replaceAll("\\s+", "").length(); + final int tempModelFileOutCharCount = tempModelFileOutString.replaceAll("\\s+", "").length(); + + assertEquals(1154, tempLogFileOutCharCount); + assertEquals(3356, tempModelFileOutCharCount); + + tempLogFileIn.delete(); + tempModelFileIn.delete(); + tempLogFileOut.delete(); + tempModelFileOut.delete(); + } +} diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCommandLineEditorScripting.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCommandLineEditorScripting.java new file mode 100644 index 000000000..1b49fb362 --- /dev/null +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCommandLineEditorScripting.java @@ -0,0 +1,132 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * 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.auth.clieditor; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.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.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; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; +import org.onap.policy.common.utils.resources.ResourceUtils; + +/** + * The Class TestCLIEditorScripting. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class TestCommandLineEditorScripting { + + private File tempModelFile; + private File tempLogFile; + + private String[] samplePolicyArgs; + + private String[] samplePolicyMapArgs; + + /** + * Initialise args. + * + * @throws IOException Signals that an I/O exception has occurred. + */ + @Before + public void initialiseArgs() throws IOException { + tempModelFile = File.createTempFile("SampleLBPolicyMap", ".json"); + tempLogFile = File.createTempFile("SampleLBPolicyMap", ".log"); + + samplePolicyArgs = new String[] {"-c", "src/test/resources/scripts/SampleLBPolicy.apex", "-o", + tempModelFile.getAbsolutePath(), "-l", tempLogFile.getAbsolutePath()}; + + samplePolicyMapArgs = new String[] {"-c", "src/test/resources/scripts/SampleLBPolicy_WithMap.apex", "-o", + tempModelFile.getAbsolutePath(), "-l", tempLogFile.getAbsolutePath()}; + } + + /** + * Removes the generated files. + */ + @After + public void removeGeneratedFiles() { + tempModelFile.delete(); + tempLogFile.delete(); + } + + /** + * Test sample Fuzzy LB policy script. + * + * @throws IOException Signals that an I/O exception has occurred. + * @throws ApexModelException if there is an Apex error + */ + @Test + public void testSamplePolicyScript() throws IOException, ApexModelException { + final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(samplePolicyArgs); + assertEquals(0, cliEditor.getErrorCount()); + + // Read the file from disk + final ApexModelReader modelReader = new ApexModelReader<>(AxPolicyModel.class); + + final URL writtenModelUrl = ResourceUtils.getLocalFile(tempModelFile.getCanonicalPath()); + final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream()); + + final URL compareModelUrl = + ResourceUtils.getLocalFile("src/test/resources/compare/FuzzyPolicyModel_Compare.json"); + final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream()); + + // Ignore key info UUIDs + writtenModel.getKeyInformation().getKeyInfoMap().clear(); + compareModel.getKeyInformation().getKeyInfoMap().clear(); + + assertTrue(writtenModel.equals(compareModel)); + } + + /** + * Test sample Fuzzy LB map policy script. + * + * @throws IOException Signals that an I/O exception has occurred. + * @throws ApexModelException if there is an Apex error + */ + @Test + public void testSampleMapPolicyScript() throws IOException, ApexModelException { + tempModelFile.delete(); + + final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(samplePolicyMapArgs); + assertEquals(0, cliEditor.getErrorCount()); + + assertTrue(tempModelFile.isFile()); + + // Read the file from disk + final ApexModelReader modelReader = new ApexModelReader<>(AxPolicyModel.class); + + final URL writtenModelUrl = ResourceUtils.getLocalFile(tempModelFile.getCanonicalPath()); + final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream()); + + final AxValidationResult validationResult = new AxValidationResult(); + writtenModel.validate(validationResult); + assertEquals(AxValidationResult.ValidationResult.OBSERVATION, validationResult.getValidationResult()); + } +} diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestContextAlbums.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestContextAlbums.java index 1b99fce16..a45212007 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestContextAlbums.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestContextAlbums.java @@ -36,11 +36,19 @@ 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; +/** + * The Class TestContextAlbums. + */ public class TestContextAlbums { private String[] logicBlockArgs; private File tempModelFile; + /** + * Creates the temp files. + * + * @throws IOException Signals that an I/O exception has occurred. + */ @Before public void createTempFiles() throws IOException { tempModelFile = File.createTempFile("TestPolicyModel", ".json"); @@ -65,20 +73,20 @@ public class TestContextAlbums { */ @Test public void testLogicBlock() throws IOException, ApexModelException { - final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(logicBlockArgs); + final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(logicBlockArgs); assertEquals(1, cliEditor.getErrorCount()); // Read the file from disk final ApexModelReader modelReader = new ApexModelReader<>(AxPolicyModel.class); modelReader.setValidateFlag(false); - final URL writtenModelURL = ResourceUtils.getLocalFile(tempModelFile.getCanonicalPath()); - final AxPolicyModel writtenModel = modelReader.read(writtenModelURL.openStream()); + final URL writtenModelUrl = ResourceUtils.getLocalFile(tempModelFile.getCanonicalPath()); + final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream()); assertNotNull(writtenModel); - final URL compareModelURL = + final URL compareModelUrl = ResourceUtils.getLocalFile("src/test/resources/compare/ContextAlbumsModel_Compare.json"); - final AxPolicyModel compareModel = modelReader.read(compareModelURL.openStream()); + final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream()); // Ignore key info UUIDs writtenModel.getKeyInformation().getKeyInfoMap().clear(); diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestFileMacro.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestFileMacro.java index eb2f2a46b..3195bf025 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestFileMacro.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestFileMacro.java @@ -46,6 +46,11 @@ public class TestFileMacro { private File tempModelFile; private File tempLogFile; + /** + * Creates the temp files. + * + * @throws IOException Signals that an I/O exception has occurred. + */ @Before public void createTempFiles() throws IOException { tempModelFile = File.createTempFile("TestPolicyModel", ".json"); @@ -55,6 +60,9 @@ public class TestFileMacro { tempLogFile.getCanonicalPath(), "-o", tempModelFile.getCanonicalPath(), "-if", "true"}; } + /** + * Removes the generated models. + */ @After public void removeGeneratedModels() { tempModelFile.delete(); @@ -68,7 +76,7 @@ public class TestFileMacro { */ @Test public void testLogicBlock() throws IOException, ApexModelException { - final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(fileMacroArgs); + final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(fileMacroArgs); // We expect eight errors assertEquals(8, cliEditor.getErrorCount()); @@ -76,12 +84,12 @@ public class TestFileMacro { final ApexModelReader modelReader = new ApexModelReader<>(AxPolicyModel.class); modelReader.setValidateFlag(false); - final URL writtenModelURL = ResourceUtils.getLocalFile(tempModelFile.getCanonicalPath()); - final AxPolicyModel writtenModel = modelReader.read(writtenModelURL.openStream()); + final URL writtenModelUrl = ResourceUtils.getLocalFile(tempModelFile.getCanonicalPath()); + final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream()); - final URL compareModelURL = + final URL compareModelUrl = ResourceUtils.getLocalFile("src/test/resources/compare/FileMacroModel_Compare.json"); - final AxPolicyModel compareModel = modelReader.read(compareModelURL.openStream()); + final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream()); // Ignore key info UUIDs writtenModel.getKeyInformation().getKeyInfoMap().clear(); diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestLogicBlock.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestLogicBlock.java index 591acb29a..1a4f75576 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestLogicBlock.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestLogicBlock.java @@ -34,6 +34,10 @@ 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 TestLogicBlock { private String[] logicBlockArgs; private String[] avroSchemaArgs; @@ -41,6 +45,11 @@ public class TestLogicBlock { private File tempLogicModelFile; private File tempAvroModelFile; + /** + * Creates the temp files. + * + * @throws IOException Signals that an I/O exception has occurred. + */ @Before public void createTempFiles() throws IOException { tempLogicModelFile = File.createTempFile("TestLogicPolicyModel", ".json"); @@ -53,6 +62,9 @@ public class TestLogicBlock { tempAvroModelFile.getCanonicalPath(), "-nl"}; } + /** + * Removes the temp files. + */ @After public void removeTempFiles() { tempLogicModelFile.delete(); @@ -67,18 +79,18 @@ public class TestLogicBlock { */ @Test public void testLogicBlock() throws IOException, ApexModelException { - new ApexCLIEditorMain(logicBlockArgs); + new ApexCommandLineEditorMain(logicBlockArgs); // Read the file from disk final ApexModelReader modelReader = new ApexModelReader<>(AxPolicyModel.class); modelReader.setValidateFlag(false); - final URL writtenModelURL = ResourceUtils.getLocalFile(tempLogicModelFile.getCanonicalPath()); - final AxPolicyModel writtenModel = modelReader.read(writtenModelURL.openStream()); + final URL writtenModelUrl = ResourceUtils.getLocalFile(tempLogicModelFile.getCanonicalPath()); + final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream()); - final URL compareModelURL = + final URL compareModelUrl = ResourceUtils.getLocalFile("src/test/resources/compare/LogicBlockModel_Compare.json"); - final AxPolicyModel compareModel = modelReader.read(compareModelURL.openStream()); + final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream()); // Ignore key info UUIDs writtenModel.getKeyInformation().getKeyInfoMap().clear(); @@ -95,18 +107,18 @@ public class TestLogicBlock { */ @Test public void testAvroSchema() throws IOException, ApexModelException { - new ApexCLIEditorMain(avroSchemaArgs); + new ApexCommandLineEditorMain(avroSchemaArgs); // Read the file from disk final ApexModelReader modelReader = new ApexModelReader<>(AxPolicyModel.class); modelReader.setValidateFlag(false); - final URL writtenModelURL = ResourceUtils.getLocalFile(tempAvroModelFile.getCanonicalPath()); - final AxPolicyModel writtenModel = modelReader.read(writtenModelURL.openStream()); + final URL writtenModelUrl = ResourceUtils.getLocalFile(tempAvroModelFile.getCanonicalPath()); + final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream()); - final URL compareModelURL = + final URL compareModelUrl = ResourceUtils.getLocalFile("src/test/resources/compare/AvroSchemaModel_Compare.json"); - final AxPolicyModel compareModel = modelReader.read(compareModelURL.openStream()); + final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream()); // Ignore key info UUIDs writtenModel.getKeyInformation().getKeyInfoMap().clear(); -- cgit 1.2.3-korg