diff options
author | rameshiyer27 <ramesh.murugan.iyer@est.tech> | 2024-07-17 09:12:52 +0100 |
---|---|---|
committer | rameshiyer27 <ramesh.murugan.iyer@est.tech> | 2024-09-18 09:27:05 +0100 |
commit | 683a4a788de041d390d57c5a8f71c4d83fff8820 (patch) | |
tree | 4ee82966876ac62e37cf5f83e8475370733a7060 /auth/cli-editor | |
parent | 827a10e2abc1a0967cd215988de63c94a83d6e64 (diff) |
Apex pdp code improvements
Fix compilation issues in windows
Replace Acm policy with kafka
coverage improvements
Issue-ID: POLICY-5059
Signed-off-by: zrrmmua <ramesh.murugan.iyer@est.tech>
Change-Id: Idfac722cce2d1a2fa471e8c77286006bd883e9a7
Diffstat (limited to 'auth/cli-editor')
7 files changed, 110 insertions, 10 deletions
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java index 5028abd31..ad606153a 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java @@ -24,10 +24,14 @@ package org.onap.policy.apex.auth.clieditor; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.List; +import java.util.Properties; +import java.util.SortedMap; +import java.util.TreeMap; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -136,4 +140,38 @@ class CommandLineCommandTest { otherCommand.getKeywordlist().add("TestKeyword"); assertNotEquals(commandLineCommand, otherCommand); } + + @Test + void testExecuteInvalidCommand() { + var handler = new ApexModelHandler(new Properties()); + var command = new CommandLineCommand(); + command.setApiMethod("java.invalid"); // invalid class + assertThrows(CommandLineException.class, () -> handler.executeCommand(command, null, null)); + + command.setApiMethod("org.onap.policy.apex.model.modelapi.ApexModel.invalid"); //invalid method + assertThrows(CommandLineException.class, () -> handler.executeCommand(command, null, null)); + + command.setApiMethod("org.onap.policy.apex.model.modelapi.ApexModel.saveToFile"); + SortedMap<String, CommandLineArgumentValue> map = new TreeMap<>(); + map.put("key", new CommandLineArgumentValue(null)); + assertThrows(CommandLineException.class, () -> handler.executeCommand(command, map, null)); + } + + @Test + void testCommandLineArgument() { + var argument = new CommandLineArgument(); + assertThat(argument).isEqualByComparingTo(argument); + var otherArgument = new CommandLineArgument("otherArgument"); + assertThat(argument).isLessThan(otherArgument); + + } + + @Test + void testKeyWordNodeCommands() { + var kn = new KeywordNode("test"); + var cmd = new CommandLineCommand(); + List<String> keywordList = List.of("key1", "key2"); + kn.processKeywords(keywordList, cmd); + assertNotNull(kn.getCommands()); + } } diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java index dfdb4c2a3..eb31d15fb 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java @@ -257,8 +257,8 @@ class CommandLineEditorOptionsTest { assertEquals(3336, tempModelFileOutCharCount); assertTrue(tempLogFileIn.delete()); - assertTrue(tempModelFileIn.delete()); assertTrue(tempLogFileOut.delete()); assertTrue(tempModelFileOut.delete()); + tempModelFileIn.delete(); } } diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java index 395f4c6bf..2e98fcf45 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java @@ -72,8 +72,8 @@ class CommandLineEditorScriptingTest { */ @AfterEach public void removeGeneratedFiles() { - assertTrue(tempModelFile.delete()); assertTrue(tempLogFile.delete()); + tempModelFile.delete(); } /** diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineParametersTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineParametersTest.java new file mode 100644 index 000000000..b979d73df --- /dev/null +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineParametersTest.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2024 Nordix Foundation. 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.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.io.IOException; +import org.junit.jupiter.api.Test; + + +class CommandLineParametersTest { + + @Test + void testMetadataFile() { + var clParameters = new CommandLineParameters(); + assertNotNull(clParameters.getMetadataLocation()); + assertFalse(clParameters.checkSetMetadataFileName()); + clParameters.setMetadataFileName("testFile"); + assertEquals("file: \"testFile\"", clParameters.getMetadataLocation()); + assertTrue(clParameters.checkSetMetadataFileName()); + } + + @Test + void testApexPropertiesFile() throws IOException { + var clParameters = new CommandLineParameters(); + assertNotNull(clParameters.getApexPropertiesLocation()); + assertNotNull(clParameters.getApexPropertiesStream()); + assertFalse(clParameters.checkSetApexPropertiesFileName()); + clParameters.setApexPropertiesFileName("testApexPropertiesFile"); + assertTrue(clParameters.checkSetApexPropertiesFileName()); + } + + @Test + void testInputModelFile() { + var clParameters = new CommandLineParameters(); + assertFalse(clParameters.checkSetInputModelFileName()); + assertFalse(clParameters.checkSetLogFileName()); + clParameters.validate(); + } +} diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.java index 6984b6701..e9ac89ae0 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.java @@ -23,7 +23,6 @@ package org.onap.policy.apex.auth.clieditor; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; @@ -62,7 +61,7 @@ class ContextAlbumsTest { */ @AfterEach void removeGeneratedModels() { - assertTrue(tempModelFile.delete()); + tempModelFile.delete(); } /** diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.java index 443727236..aecc3a066 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.java @@ -22,7 +22,6 @@ package org.onap.policy.apex.auth.clieditor; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; @@ -67,7 +66,7 @@ class FileMacroTest { */ @AfterEach void removeGeneratedModels() { - assertTrue(tempModelFile.delete()); + tempModelFile.delete(); } /** @@ -97,7 +96,7 @@ class FileMacroTest { writtenModel.getKeyInformation().getKeyInfoMap().clear(); compareModel.getKeyInformation().getKeyInfoMap().clear(); - assertEquals(writtenModel, compareModel); + assertEquals(normalizeNewlines(writtenModel.toString()), normalizeNewlines(compareModel.toString())); // The output event is in this file final File outputLogFile = new File(tempLogFile.getCanonicalPath()); @@ -114,4 +113,8 @@ class FileMacroTest { // Check what we got is what we expected to get assertEquals(outputLogCompareString, outputLogString); } + + private String normalizeNewlines(String input) { + return input.replace("\r\n", "\n"); + } } diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.java index 982d5195e..111215b26 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.java @@ -22,7 +22,6 @@ package org.onap.policy.apex.auth.clieditor; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; @@ -67,8 +66,8 @@ class LogicBlockTest { */ @AfterEach void removeTempFiles() { - assertTrue(tempLogicModelFile.delete()); - assertTrue(tempAvroModelFile.delete()); + tempLogicModelFile.delete(); + tempAvroModelFile.delete(); } /** |