summaryrefslogtreecommitdiffstats
path: root/auth/cli-editor/src/test/java
diff options
context:
space:
mode:
authorwaqas.ikram <waqas.ikram@ericsson.com>2018-06-01 14:23:01 +0100
committerwaqas.ikram <waqas.ikram@ericsson.com>2018-06-01 14:23:04 +0100
commit5722440b2eb8ff1923dda9d4d856f0adc1ac8e6f (patch)
tree5fb695630a8d4a2a3b111a5e3bfcacfba3dfc71d /auth/cli-editor/src/test/java
parentfa529999c7d6e024cc3c4a478ef089a77e284974 (diff)
Adding apex auth modules
Change-Id: Iec210465636458f0c104c99893440706279062f0 Issue-ID: POLICY-860 Signed-off-by: waqas.ikram <waqas.ikram@ericsson.com>
Diffstat (limited to 'auth/cli-editor/src/test/java')
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorEventsContext.java103
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorOptions.java277
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorScripting.java132
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestContextAlbums.java93
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestFileMacro.java115
-rw-r--r--auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestLogicBlock.java117
6 files changed, 837 insertions, 0 deletions
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
new file mode 100644
index 000000000..43238d63d
--- /dev/null
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorEventsContext.java
@@ -0,0 +1,103 @@
+/*-
+ * ============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 org.junit.Test;
+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
+
+ /**
+ * 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 = File.createTempFile("TestPolicyJavaEventsAndContext", ".log");
+ final File tempModelFile = File.createTempFile("TestPolicyJavaEventsAndContext", ".json");
+
+ final String[] cliArgs =
+ new String[] {"-c", "src/main/resources/examples/scripts/TestPolicyJavaEventContext.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(25911, logCharCount);
+ assertEquals(46138, modelCharCount);
+
+ tempLogFile.delete();
+ tempModelFile.delete();
+ }
+
+ /**
+ * 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 = File.createTempFile("TestPolicyAvroEventsAndContext", ".log");
+ final File tempModelFile = File.createTempFile("TestPolicyAvroEventsAndContext", ".json");
+
+ final String[] cliArgs =
+ new String[] {"-c", "src/main/resources/examples/scripts/TestPolicyAvroEventContext.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(30315, logCharCount);
+ assertEquals(52930, modelCharCount);
+
+ tempLogFile.delete();
+ tempModelFile.delete();
+ }
+}
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
new file mode 100644
index 000000000..87618e18d
--- /dev/null
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorOptions.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 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
new file mode 100644
index 000000000..b57a72dab
--- /dev/null
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestCLIEditorScripting.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.apex.model.utilities.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<AxPolicyModel> 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<AxPolicyModel> 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
new file mode 100644
index 000000000..59b2f2471
--- /dev/null
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestContextAlbums.java
@@ -0,0 +1,93 @@
+/*-
+ * ============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.assertNotNull;
+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.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.ResourceUtils;
+
+public class TestContextAlbums {
+ private String[] logicBlockArgs;
+
+ private File tempModelFile;
+
+ @Before
+ public void createTempFiles() throws IOException {
+ tempModelFile = File.createTempFile("TestPolicyModel", ".json");
+
+ logicBlockArgs = new String[] {
+ "-c",
+ "src/test/resources/scripts/ContextAlbums.apex",
+ "-o",
+ tempModelFile.getAbsolutePath(),
+ "-nl"
+ };
+ }
+
+ /**
+ * Removes the generated models.
+ */
+ @After
+ public void removeGeneratedModels() {
+ tempModelFile.delete();
+ }
+
+ /**
+ * Test logic block.
+ *
+ * @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 {
+ final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(logicBlockArgs);
+ assertEquals(1, cliEditor.getErrorCount());
+
+ // Read the file from disk
+ final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
+ modelReader.setValidateFlag(false);
+
+ final URL writtenModelURL = ResourceUtils.getLocalFile(tempModelFile.getCanonicalPath());
+ final AxPolicyModel writtenModel = modelReader.read(writtenModelURL.openStream());
+ assertNotNull(writtenModel);
+
+ final URL compareModelURL = ResourceUtils.getLocalFile("src/test/resources/compare/ContextAlbumsModel_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));
+ }
+}
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
new file mode 100644
index 000000000..e102bd2fd
--- /dev/null
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestFileMacro.java
@@ -0,0 +1,115 @@
+/*-
+ * ============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 java.nio.file.Paths;
+
+import org.junit.After;
+import org.junit.Before;
+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.ResourceUtils;
+import org.onap.policy.apex.model.utilities.TextFileUtils;
+
+/**
+ * Test FileMacro in the CLI.
+ */
+public class TestFileMacro {
+ private String[] fileMacroArgs;
+
+ private File tempModelFile;
+ private File tempLogFile;
+
+ @Before
+ public void createTempFiles() throws IOException {
+ tempModelFile = File.createTempFile("TestPolicyModel", ".json");
+ tempLogFile = File.createTempFile("TestPolicyModel", ".log");
+
+ fileMacroArgs = new String[] {
+ "-c",
+ "src/test/resources/scripts/FileMacro.apex",
+ "-l",
+ tempLogFile.getCanonicalPath(),
+ "-o",
+ tempModelFile.getCanonicalPath(),
+ "-if",
+ "true"
+ };
+ }
+
+ @After
+ public void removeGeneratedModels() {
+ tempModelFile.delete();
+ }
+
+ /**
+ * Test logic block macro in CLI scripts.
+ *
+ * @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 {
+ final ApexCLIEditorMain cliEditor = new ApexCLIEditorMain(fileMacroArgs);
+ // We expect eight errors
+ assertEquals(8, cliEditor.getErrorCount());
+
+ // Read the file from disk
+ final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
+ modelReader.setValidateFlag(false);
+
+ final URL writtenModelURL = ResourceUtils.getLocalFile(tempModelFile.getCanonicalPath());
+ final AxPolicyModel writtenModel = modelReader.read(writtenModelURL.openStream());
+
+ final URL compareModelURL = ResourceUtils.getLocalFile("src/test/resources/compare/FileMacroModel_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));
+
+ // The output event is in this file
+ final File outputLogFile = new File(tempLogFile.getCanonicalPath());
+
+ final String outputLogString = TextFileUtils
+ .getTextFileAsString(outputLogFile.getCanonicalPath())
+ .replace(Paths.get("").toAbsolutePath().toString() + 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+", "");
+
+ // 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/TestLogicBlock.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestLogicBlock.java
new file mode 100644
index 000000000..2fe63fcf8
--- /dev/null
+++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/TestLogicBlock.java
@@ -0,0 +1,117 @@
+/*-
+ * ============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.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.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.ResourceUtils;
+
+public class TestLogicBlock {
+ private String[] logicBlockArgs;
+ private String[] avroSchemaArgs;
+
+ private File tempLogicModelFile;
+ private File tempAvroModelFile;
+
+ @Before
+ public 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"};
+
+ avroSchemaArgs = new String[] {"-c", "src/test/resources/scripts/AvroSchema.apex", "-o",
+ tempAvroModelFile.getCanonicalPath(), "-nl"};
+ }
+
+ @After
+ public void removeTempFiles() {
+ tempLogicModelFile.delete();
+ tempAvroModelFile.delete();
+ }
+
+ /**
+ * Test logic block.
+ *
+ * @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 {
+ new ApexCLIEditorMain(logicBlockArgs);
+
+ // Read the file from disk
+ final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
+ modelReader.setValidateFlag(false);
+
+ final URL writtenModelURL = ResourceUtils.getLocalFile(tempLogicModelFile.getCanonicalPath());
+ final AxPolicyModel writtenModel = modelReader.read(writtenModelURL.openStream());
+
+ final URL compareModelURL =
+ ResourceUtils.getLocalFile("src/test/resources/compare/LogicBlockModel_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 avro schema.
+ *
+ * @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 {
+ new ApexCLIEditorMain(avroSchemaArgs);
+
+ // Read the file from disk
+ final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class);
+ modelReader.setValidateFlag(false);
+
+ final URL writtenModelURL = ResourceUtils.getLocalFile(tempAvroModelFile.getCanonicalPath());
+ final AxPolicyModel writtenModel = modelReader.read(writtenModelURL.openStream());
+
+ final URL compareModelURL =
+ ResourceUtils.getLocalFile("src/test/resources/compare/AvroSchemaModel_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));
+ }
+}