From b6c674891e00f3bac43bd7b4fca06e7a87b8dd34 Mon Sep 17 00:00:00 2001 From: lapentafd Date: Thu, 27 May 2021 10:18:49 +0100 Subject: Fix Sonar Issues on Apex-pdp Changes made into cli-codegen, cli-editor, and core-engine Renamed one test class to match other test classes Issue-ID: POLICY-3093 Change-Id: Ib2d947782021590ffc08d426e7a1607a8c33f98a Signed-off-by: lapentafd --- .../apex/auth/clicodegen/CgStringRenderer.java | 5 +- .../auth/clicodegen/CodeGeneratorCliEditor.java | 36 +++--- .../auth/clicodegen/SupportGenerationTest.java | 137 +++++++++++++++++++++ .../auth/clicodegen/SupportGenerationTester.java | 136 -------------------- .../auth/clieditor/ApexCommandLineEditorMain.java | 12 +- .../apex/auth/clieditor/ApexModelHandler.java | 15 +-- .../apex/auth/clieditor/ApexModelProperties.java | 9 +- .../apex/auth/clieditor/CommandLineArgument.java | 6 +- .../apex/auth/clieditor/CommandLineCommand.java | 8 +- .../apex/auth/clieditor/CommandLineEditorLoop.java | 29 +++-- .../auth/clieditor/CommandLineParameterParser.java | 6 +- .../apex/auth/clieditor/CommandLineParameters.java | 4 +- .../apex/auth/clieditor/CommandLineParser.java | 39 +++--- .../policy/apex/auth/clieditor/KeywordNode.java | 8 +- .../clieditor/tosca/ApexCliToscaEditorMain.java | 8 +- .../tosca/ApexCliToscaParameterParser.java | 7 +- .../policy/apex/auth/clieditor/utils/CliUtils.java | 28 ++--- .../auth/clieditor/CommandLineCommandTest.java | 7 +- .../engine/engine/impl/ApexEngineImplTest.java | 18 ++- .../engine/impl/DummySlowEnEventListener.java | 9 +- .../policy/apex/core/engine/event/EnEventTest.java | 11 +- 21 files changed, 282 insertions(+), 256 deletions(-) create mode 100644 auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTest.java delete mode 100644 auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTester.java diff --git a/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CgStringRenderer.java b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CgStringRenderer.java index b2cd9b9ca..c7235afb6 100644 --- a/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CgStringRenderer.java +++ b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CgStringRenderer.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,7 +43,7 @@ public class CgStringRenderer implements AttributeRenderer { if (obj == null) { return null; } - String ret = obj.toString(); + var ret = obj.toString(); if (ret.length() == 0) { return "\"\""; } @@ -53,7 +54,7 @@ public class CgStringRenderer implements AttributeRenderer { } if ("doDescription".equals(format)) { - String ret = obj.toString(); + var ret = obj.toString(); if (ret.contains("\n") || ret.contains("\"")) { ret = "LS" + "\n" + ret + "\n" + "LE"; } else { diff --git a/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditor.java b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditor.java index 53acc9cf2..6ad5fbc3c 100644 --- a/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditor.java +++ b/auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditor.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -172,7 +172,7 @@ public class CodeGeneratorCliEditor { */ public void addSchemaDeclaration(final String name, final String version, final String uuid, final String description, final String flavour, final String schema) { - final ST st = stg.getInstanceOf("schemaDecl"); + final var st = stg.getInstanceOf("schemaDecl"); st.add(NAME, name); st.add(VERSION, version); st.add(UUID, uuid); @@ -188,7 +188,7 @@ public class CodeGeneratorCliEditor { * @param codeGenCliEditorBuilder The parameters for the context album */ public void addContextAlbumDeclaration(CodeGenCliEditorBuilder codeGenCliEditorBuilder) { - final ST st = stg.getInstanceOf("ctxAlbumDecl"); + final var st = stg.getInstanceOf("ctxAlbumDecl"); st.add(NAME, codeGenCliEditorBuilder.getName()); st.add(VERSION, codeGenCliEditorBuilder.getVersion()); st.add(UUID, codeGenCliEditorBuilder.getUuid()); @@ -213,7 +213,7 @@ public class CodeGeneratorCliEditor { */ public ST createEventFieldDefinition(final String eventName, final String version, final String fieldName, final String fieldSchema, final String fieldSchemaVersion, final boolean optional) { - final ST st = stg.getInstanceOf("eventDefField"); + final var st = stg.getInstanceOf("eventDefField"); st.add(EVENT_NAME, eventName); st.add(VERSION, version); st.add(FIELD_NAME, fieldName); @@ -234,7 +234,7 @@ public class CodeGeneratorCliEditor { */ public ST createTaskDefLogic(final String taskName, final String version, final String flavour, final String logic) { - final ST st = stg.getInstanceOf("taskDefLogic"); + final var st = stg.getInstanceOf("taskDefLogic"); st.add(TASK_NAME, taskName); st.add(VERSION, version); st.add(FLAVOUR, flavour); @@ -248,7 +248,7 @@ public class CodeGeneratorCliEditor { * @param eventDeclarationBuilder param object for event declaration */ public void addEventDeclaration(EventDeclarationBuilder eventDeclarationBuilder) { - final ST st = stg.getInstanceOf("eventDecl"); + final var st = stg.getInstanceOf("eventDecl"); st.add(NAME, eventDeclarationBuilder.getName()); st.add(VERSION, eventDeclarationBuilder.getVersion()); st.add(UUID, eventDeclarationBuilder.getUuid()); @@ -272,7 +272,7 @@ public class CodeGeneratorCliEditor { * @param taskDeclarationBuilder builder for the task declaration parameters */ public void addTaskDeclaration(TaskDeclarationBuilder taskDeclarationBuilder) { - final ST st = stg.getInstanceOf("taskDecl"); + final var st = stg.getInstanceOf("taskDecl"); st.add(NAME, taskDeclarationBuilder.getName()); st.add(VERSION, taskDeclarationBuilder.getVersion()); st.add(UUID, taskDeclarationBuilder.getUuid()); @@ -298,7 +298,7 @@ public class CodeGeneratorCliEditor { */ public void addPolicyDefinition(final String name, final String version, final String uuid, final String description, final String template, final String firstState, final List states) { - final ST st = stg.getInstanceOf("policyDef"); + final var st = stg.getInstanceOf("policyDef"); st.add(NAME, name); st.add(VERSION, version); st.add(UUID, uuid); @@ -321,7 +321,7 @@ public class CodeGeneratorCliEditor { */ public ST createTaskDefinitionInfields(final String taskName, final String version, final String fieldName, final String fieldSchema, final String fieldSchemaVersion) { - final ST st = stg.getInstanceOf("taskDefInputFields"); + final var st = stg.getInstanceOf("taskDefInputFields"); st.add(TASK_NAME, taskName); st.add(VERSION, version); st.add(FIELD_NAME, fieldName); @@ -342,7 +342,7 @@ public class CodeGeneratorCliEditor { */ public ST createTaskDefinitionOutfields(final String taskName, final String version, final String fieldName, final String fieldSchema, final String fieldSchemaVersion) { - final ST st = stg.getInstanceOf("taskDefOutputFields"); + final var st = stg.getInstanceOf("taskDefOutputFields"); st.add(TASK_NAME, taskName); st.add(VERSION, version); st.add(FIELD_NAME, fieldName); @@ -362,7 +362,7 @@ public class CodeGeneratorCliEditor { */ public ST createTaskDefinitionParameters(final String name, final String version, final String parName, final String defaultValue) { - final ST st = stg.getInstanceOf("taskDefParameter"); + final var st = stg.getInstanceOf("taskDefParameter"); st.add(NAME, name); st.add(VERSION, version); st.add(PAR_NAME, parName); @@ -381,7 +381,7 @@ public class CodeGeneratorCliEditor { */ public ST createTaskDefinitionContextRef(final String name, final String version, final String albumName, final String albumVersion) { - final ST st = stg.getInstanceOf("taskDefCtxRef"); + final var st = stg.getInstanceOf("taskDefCtxRef"); st.add(NAME, name); st.add(VERSION, version); st.add(ALBUM_NAME, albumName); @@ -396,7 +396,7 @@ public class CodeGeneratorCliEditor { * @return a CLI command for a policy state task definition */ public ST createPolicyStateTask(PolicyStateTaskBuilder policyStateTaskBuilder) { - final ST st = stg.getInstanceOf("policyStateTask"); + final var st = stg.getInstanceOf("policyStateTask"); st.add(POLICY_NAME, policyStateTaskBuilder.getPolicyName()); st.add(VERSION, policyStateTaskBuilder.getVersion()); st.add(STATE_NAME, policyStateTaskBuilder.getStateName()); @@ -423,7 +423,7 @@ public class CodeGeneratorCliEditor { public ST createPolicyStateOutput(final String policyName, final String version, final String stateName, final String outputName, final String eventName, final String eventVersion, final String nextState) { - final ST st = stg.getInstanceOf("policyStateOutput"); + final var st = stg.getInstanceOf("policyStateOutput"); st.add(POLICY_NAME, policyName); st.add(VERSION, version); st.add(STATE_NAME, stateName); @@ -441,7 +441,7 @@ public class CodeGeneratorCliEditor { * @return a CLI command for a policy state definition */ public ST createPolicyStateDef(PolicyStateDefBuilder policyStateDefBuilder) { - final ST st = stg.getInstanceOf("policyStateDef"); + final var st = stg.getInstanceOf("policyStateDef"); st.add(POLICY_NAME, policyStateDefBuilder.getPolicyName()); st.add(VERSION, policyStateDefBuilder.getVersion()); st.add(STATE_NAME, policyStateDefBuilder.getStateName()); @@ -469,7 +469,7 @@ public class CodeGeneratorCliEditor { */ public ST createPolicyStateDefTaskSelLogic(final String name, final String version, final String stateName, final String logicFlavour, final String logic) { - final ST st = stg.getInstanceOf("policyStateTaskSelectionLogic"); + final var st = stg.getInstanceOf("policyStateTaskSelectionLogic"); st.add(NAME, name); st.add(VERSION, version); st.add(STATE_NAME, stateName); @@ -491,7 +491,7 @@ public class CodeGeneratorCliEditor { */ public ST createPolicyStateDefFinalizerLogic(final String name, final String version, final String stateName, final String finalizerLogicName, final String logicFlavour, final String logic) { - final ST st = stg.getInstanceOf("policyStateFinalizerLogic"); + final var st = stg.getInstanceOf("policyStateFinalizerLogic"); st.add(NAME, name); st.add(VERSION, version); st.add(STATE_NAME, stateName); @@ -513,7 +513,7 @@ public class CodeGeneratorCliEditor { */ public ST createPolicyStateDefContextRef(final String name, final String version, final String stateName, final String albumName, final String albumVersion) { - final ST st = stg.getInstanceOf("policyStateContextRef"); + final var st = stg.getInstanceOf("policyStateContextRef"); st.add(NAME, name); st.add(VERSION, version); st.add(STATE_NAME, stateName); diff --git a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTest.java b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTest.java new file mode 100644 index 000000000..aed334590 --- /dev/null +++ b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTest.java @@ -0,0 +1,137 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.auth.clicodegen; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import org.junit.Test; +import org.stringtemplate.v4.STGroup; +import org.stringtemplate.v4.STGroupFile; + +/** + * Test for the CG CLI Editor STG file. + * + * @author Sven van der Meer (sven.van.der.meer@ericsson.com) + */ +public class SupportGenerationTest { + + /** + * Get the chunks for the codegen. + * + * @return the chunks + */ + private static Map> getCodeGenChunks() { + // CHECKSTYLE:OFF: LineLength + + final Map> chunks = new LinkedHashMap<>(); + + chunks.put("/policyModel", + Arrays.asList("name", "version", "uuid", "description", "declarations", "definitions")); + chunks.put("/schemaDecl", Arrays.asList("name", "version", "uuid", "description", "flavour", "schema")); + chunks.put("/ctxAlbumDecl", Arrays.asList("name", "version", "uuid", "description", "scope", "writable", + "schemaName", "schemaVersion")); + chunks.put("/eventDecl", + Arrays.asList("name", "version", "uuid", "description", "nameSpace", "source", "target", "fields")); + chunks.put("/eventDefField", + Arrays.asList("eventName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion", "optional")); + chunks.put("/taskDecl", + Arrays.asList("name", "version", "uuid", "description", "infields", "outfields", "logic")); + chunks.put("/taskDefInputFields", + Arrays.asList("taskName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion")); + chunks.put("/taskDefOutputFields", + Arrays.asList("taskName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion")); + chunks.put("/taskDefLogic", Arrays.asList("taskName", "version", "flavour", "logic")); + chunks.put("/taskDefParameter", Arrays.asList("name", "version", "parName", "defaultValue")); + chunks.put("/taskDefCtxRef", Arrays.asList("name", "version", "albumName", "albumVersion")); + chunks.put("/policyDef", Arrays.asList("name", "version", "uuid", "description", "template", "firstState")); + chunks.put("/policyStateDef", Arrays.asList("policyName", "version", "stateName", "triggerName", + "triggerVersion", "defaultTask", "defaultTaskVersion", "outputs", "tasks")); + chunks.put("/policyStateOutput", Arrays.asList("policyName", "version", "stateName", "outputName", "eventName", + "eventVersion", "nextState")); + chunks.put("/policyStateTaskSelectionLogic", + Arrays.asList("name", "version", "stateName", "logicFlavour", "logic")); + chunks.put("/policyStateTask", Arrays.asList("policyName", "version", "stateName", "taskLocalName", "taskName", + "taskVersion", "outputType", "outputName")); + chunks.put("/policyStateFinalizerLogic", + Arrays.asList("name", "version", "stateName", "finalizerLogicName", "logicFlavour", "logic")); + chunks.put("/policyStateContextRef", + Arrays.asList("name", "version", "stateName", "albumName", "albumVersion")); + + return chunks; + // CHECKSTYLE:ON: LineLength + } + + /** Test STG load. */ + @Test + public void testGenerationLoad() { + final DummyStErrorListener errListener = new DummyStErrorListener(); + final STGroupFile stg = new STGroupFile(CodeGeneratorCliEditor.STG_FILE); + stg.setListener(errListener); + + stg.getTemplateNames(); // dummy to compile group and get errors + assertEquals(0, errListener.getErrorCount()); + } + + /** Test STG chunks. */ + @Test + public void testGenerationChunks() { + final DummyStErrorListener errListener = new DummyStErrorListener(); + final STGroupFile stg = new STGroupFile(CodeGeneratorCliEditor.STG_FILE); + stg.setListener(errListener); + + stg.getTemplateNames(); // dummy to compile group and get errors + final Map> chunks = getCodeGenChunks(); + String error = ""; + final Set definedNames = stg.getTemplateNames(); + for (final STGroup group : stg.getImportedGroups()) { + definedNames.addAll(group.getTemplateNames()); + } + final Set requiredNames = chunks.keySet(); + + for (final String required : requiredNames) { + if (!definedNames.contains(required)) { + error += " - target STG does not define template for <" + required + ">\n"; + } else { + final Set definedParams = ((stg.getInstanceOf(required).getAttributes() == null) + ? new TreeSet() : stg.getInstanceOf(required).getAttributes().keySet()); + final List requiredParams = chunks.get(required); + for (final String reqArg : requiredParams) { + if (!definedParams.contains(reqArg)) { + error += " - target STG with template <" + required + "> does not define argument <" + reqArg + + ">\n"; + } + } + } + } + + if (!("".equals(error))) { + System.err.println(error); + } + assertEquals(0, error.length()); + } +} diff --git a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTester.java b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTester.java deleted file mode 100644 index 3e010d056..000000000 --- a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTester.java +++ /dev/null @@ -1,136 +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.clicodegen; - -import static org.junit.Assert.assertEquals; - -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import org.junit.Test; -import org.stringtemplate.v4.STGroup; -import org.stringtemplate.v4.STGroupFile; - -/** - * Test for the CG CLI Editor STG file. - * - * @author Sven van der Meer (sven.van.der.meer@ericsson.com) - */ -public class SupportGenerationTester { - - /** - * Get the chunks for the codegen. - * - * @return the chunks - */ - private static Map> getCodeGenChunks() { - // CHECKSTYLE:OFF: LineLength - - final Map> chunks = new LinkedHashMap<>(); - - chunks.put("/policyModel", - Arrays.asList("name", "version", "uuid", "description", "declarations", "definitions")); - chunks.put("/schemaDecl", Arrays.asList("name", "version", "uuid", "description", "flavour", "schema")); - chunks.put("/ctxAlbumDecl", Arrays.asList("name", "version", "uuid", "description", "scope", "writable", - "schemaName", "schemaVersion")); - chunks.put("/eventDecl", - Arrays.asList("name", "version", "uuid", "description", "nameSpace", "source", "target", "fields")); - chunks.put("/eventDefField", - Arrays.asList("eventName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion", "optional")); - chunks.put("/taskDecl", - Arrays.asList("name", "version", "uuid", "description", "infields", "outfields", "logic")); - chunks.put("/taskDefInputFields", - Arrays.asList("taskName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion")); - chunks.put("/taskDefOutputFields", - Arrays.asList("taskName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion")); - chunks.put("/taskDefLogic", Arrays.asList("taskName", "version", "flavour", "logic")); - chunks.put("/taskDefParameter", Arrays.asList("name", "version", "parName", "defaultValue")); - chunks.put("/taskDefCtxRef", Arrays.asList("name", "version", "albumName", "albumVersion")); - chunks.put("/policyDef", Arrays.asList("name", "version", "uuid", "description", "template", "firstState")); - chunks.put("/policyStateDef", Arrays.asList("policyName", "version", "stateName", "triggerName", - "triggerVersion", "defaultTask", "defaultTaskVersion", "outputs", "tasks")); - chunks.put("/policyStateOutput", Arrays.asList("policyName", "version", "stateName", "outputName", "eventName", - "eventVersion", "nextState")); - chunks.put("/policyStateTaskSelectionLogic", - Arrays.asList("name", "version", "stateName", "logicFlavour", "logic")); - chunks.put("/policyStateTask", Arrays.asList("policyName", "version", "stateName", "taskLocalName", "taskName", - "taskVersion", "outputType", "outputName")); - chunks.put("/policyStateFinalizerLogic", - Arrays.asList("name", "version", "stateName", "finalizerLogicName", "logicFlavour", "logic")); - chunks.put("/policyStateContextRef", - Arrays.asList("name", "version", "stateName", "albumName", "albumVersion")); - - return chunks; - // CHECKSTYLE:ON: LineLength - } - - /** Test STG load. */ - @Test - public void testGenerationLoad() { - final DummyStErrorListener errListener = new DummyStErrorListener(); - final STGroupFile stg = new STGroupFile(CodeGeneratorCliEditor.STG_FILE); - stg.setListener(errListener); - - stg.getTemplateNames(); // dummy to compile group and get errors - assertEquals(0, errListener.getErrorCount()); - } - - /** Test STG chunks. */ - @Test - public void testGenerationChunks() { - final DummyStErrorListener errListener = new DummyStErrorListener(); - final STGroupFile stg = new STGroupFile(CodeGeneratorCliEditor.STG_FILE); - stg.setListener(errListener); - - stg.getTemplateNames(); // dummy to compile group and get errors - final Map> chunks = getCodeGenChunks(); - String error = ""; - final Set definedNames = stg.getTemplateNames(); - for (final STGroup group : stg.getImportedGroups()) { - definedNames.addAll(group.getTemplateNames()); - } - final Set requiredNames = chunks.keySet(); - - for (final String required : requiredNames) { - if (!definedNames.contains(required)) { - error += " - target STG does not define template for <" + required + ">\n"; - } else { - final Set definedParams = ((stg.getInstanceOf(required).getAttributes() == null) - ? new TreeSet() : stg.getInstanceOf(required).getAttributes().keySet()); - final List requiredParams = chunks.get(required); - for (final String reqArg : requiredParams) { - if (!definedParams.contains(reqArg)) { - error += " - target STG with template <" + required + "> does not define argument <" + reqArg - + ">\n"; - } - } - } - } - - if (!("".equals(error))) { - System.err.println(error); - } - assertEquals(0, error.length()); - } -} diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java index 9258b45b8..424f5853f 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,7 +61,7 @@ public class ApexCommandLineEditorMain { LOGGER.info(startMessage); try { - final CommandLineParameterParser parser = new CommandLineParameterParser(); + final var parser = new CommandLineParameterParser(); parameters = parser.parse(args); if (parameters.isHelpSet()) { @@ -118,7 +118,7 @@ public class ApexCommandLineEditorMain { return; } - String modelPropertiesString = "model properties are: " + apexModelProperties.toString(); + var modelPropertiesString = "model properties are: " + apexModelProperties.toString(); LOGGER.debug(modelPropertiesString); // Find the system commands @@ -130,7 +130,7 @@ public class ApexCommandLineEditorMain { } // Read in the command hierarchy, this builds a tree of commands - final KeywordNode rootKeywordNode = new KeywordNode("root"); + final var rootKeywordNode = new KeywordNode("root"); for (final CommandLineCommand command : commands.getCommandSet()) { rootKeywordNode.processKeywords(command.getKeywordlist(), command); } @@ -147,7 +147,7 @@ public class ApexCommandLineEditorMain { return; } - final CommandLineEditorLoop cliEditorLoop = new CommandLineEditorLoop(apexModelProperties.getProperties(), + final var cliEditorLoop = new CommandLineEditorLoop(apexModelProperties.getProperties(), modelHandler, rootKeywordNode); try { errorCount = cliEditorLoop.runLoop(parameters.getCommandInputStream(), parameters.getOutputStream(), @@ -188,7 +188,7 @@ public class ApexCommandLineEditorMain { * @param args the arguments */ public static void main(final String[] args) { - final ApexCommandLineEditorMain cliEditor = new ApexCommandLineEditorMain(args); + final var cliEditor = new ApexCommandLineEditorMain(args); // Only call system.exit on errors as it brings the JVM down if (cliEditor.getErrorCount() > 0) { diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelHandler.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelHandler.java index 6814eab8c..896448b4f 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelHandler.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelHandler.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -79,13 +80,13 @@ public class ApexModelHandler { public Result executeCommand(final CommandLineCommand command, final SortedMap argumentValues, final PrintWriter writer) { // Get the method - final Method apiMethod = getCommandMethod(command); + final var apiMethod = getCommandMethod(command); // Get the method arguments final Object[] parameterArray = getParameterArray(command, argumentValues, apiMethod); try { - final Object returnObject = apiMethod.invoke(apexModel, parameterArray); + final var returnObject = apiMethod.invoke(apexModel, parameterArray); if (returnObject instanceof ApexApiResult) { final ApexApiResult result = (ApexApiResult) returnObject; @@ -146,9 +147,9 @@ public class ApexModelHandler { */ private Object[] getParameterArray(final CommandLineCommand command, final SortedMap argumentValues, final Method apiMethod) { - final Object[] parameterArray = new Object[argumentValues.size()]; + final var parameterArray = new Object[argumentValues.size()]; - int item = 0; + var item = 0; try { for (final Class parametertype : apiMethod.getParameterTypes()) { final String parameterValue = argumentValues.get(command.getArgumentList().get(item).getArgumentName()) diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelProperties.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelProperties.java index 0e3cd0634..d618b159b 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelProperties.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelProperties.java @@ -1,19 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -69,7 +70,7 @@ public class ApexModelProperties { * @return the default properties */ public Properties getProperties() { - final Properties properties = new Properties(); + final var properties = new Properties(); // @formatter:off properties.setProperty("DEFAULT_CONCEPT_VERSION", defaultConceptVersion); properties.setProperty("DEFAULT_EVENT_NAMESPACE", defaultEventNamespace); diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineArgument.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineArgument.java index 48899baa6..772cd506e 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineArgument.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineArgument.java @@ -98,7 +98,7 @@ public class CommandLineArgument implements Comparable { * @return the argument help */ public String getHelp() { - final StringBuilder builder = new StringBuilder(); + final var builder = new StringBuilder(); builder.append(argumentName); builder.append(nullable ? ": (O) " : ": (M) "); builder.append(description); @@ -144,8 +144,8 @@ public class CommandLineArgument implements Comparable { */ @Override public int hashCode() { - final int prime = 31; - int result = 1; + final var prime = 31; + var result = 1; result = prime * result + ((argumentName == null) ? 0 : argumentName.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + (nullable ? 1231 : 1237); diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineCommand.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineCommand.java index beae65a06..37806af66 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineCommand.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineCommand.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -166,7 +166,7 @@ public class CommandLineCommand implements Comparable { * @return the help for this command */ public String getHelp() { - final StringBuilder builder = new StringBuilder(); + final var builder = new StringBuilder(); for (final String keyword : keywordlist) { builder.append(keyword); builder.append(' '); @@ -255,8 +255,8 @@ public class CommandLineCommand implements Comparable { */ @Override public int hashCode() { - final int prime = 31; - int result = 1; + final var prime = 31; + var result = 1; result = prime * result + ((apiMethod == null) ? 0 : apiMethod.hashCode()); result = prime * result + argumentList.hashCode(); result = prime * result + ((description == null) ? 0 : description.hashCode()); diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java index 991257e6b..e198b663d 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -105,11 +105,11 @@ public class CommandLineEditorLoop { public int runLoop(final InputStream inputStream, final OutputStream outputStream, final CommandLineParameters parameters) throws IOException { // Readers and writers for input and output - final BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); - final PrintWriter writer = new PrintWriter(new OutputStreamWriter(outputStream)); + final var reader = new BufferedReader(new InputStreamReader(inputStream)); + final var writer = new PrintWriter(new OutputStreamWriter(outputStream)); // The parser parses the input lines into commands and arguments - final CommandLineParser parser = new CommandLineParser(); + final var parser = new CommandLineParser(); // The execution status has the result of the latest command and a cumulative error count MutablePair executionStatus = new MutablePair<>(Result.SUCCESS, 0); @@ -122,7 +122,7 @@ public class CommandLineEditorLoop { // Get the output model if (!parameters.isSuppressModelOutput()) { - final String modelString = modelHandler.writeModelToString(writer); + final var modelString = modelHandler.writeModelToString(writer); if (parameters.checkSetOutputModelFileName()) { TextFileUtils.putStringAsTextFile(modelString, parameters.getOutputModelFileName()); @@ -136,7 +136,6 @@ public class CommandLineEditorLoop { if (!System.in.equals(inputStream)) { reader.close(); } - if (!System.out.equals(outputStream) && !System.err.equals(outputStream)) { writer.close(); } @@ -236,7 +235,7 @@ public class CommandLineEditorLoop { */ private String readLogicBlock(final CommandLineParameters parameters, final BufferedReader reader, final PrintWriter writer, MutablePair executionStatus) { - StringBuilder logicBlock = new StringBuilder(); + var logicBlock = new StringBuilder(); while (true) { try { @@ -277,7 +276,7 @@ public class CommandLineEditorLoop { * @return A string with the prompt */ private String getPrompt() { - final StringBuilder builder = new StringBuilder(); + final var builder = new StringBuilder(); final Iterator keynodeDequeIter = keywordNodeDeque.descendingIterator(); while (keynodeDequeIter.hasNext()) { @@ -300,11 +299,11 @@ public class CommandLineEditorLoop { private CommandLineCommand findCommand(final List commandWords) { CommandLineCommand command = null; - final KeywordNode startKeywordNode = keywordNodeDeque.peek(); + final var startKeywordNode = keywordNodeDeque.peek(); // Go down through the keywords searching for the command - for (int i = 0; i < commandWords.size(); i++) { - final KeywordNode searchKeywordNode = keywordNodeDeque.peek(); + for (var i = 0; i < commandWords.size(); i++) { + final var searchKeywordNode = keywordNodeDeque.peek(); // We have got to the arguments, time to stop looking if (commandWords.get(i).indexOf('=') >= 0) { @@ -330,7 +329,7 @@ public class CommandLineEditorLoop { commandWords.set(i, foundNodeEntries.get(0).getKey()); // Check if there is a command - final KeywordNode childKeywordNode = foundNodeEntries.get(0).getValue(); + final var childKeywordNode = foundNodeEntries.get(0).getValue(); command = childKeywordNode.getCommand(); // If the command is null, we go into a sub mode, otherwise we unwind the stack of @@ -538,8 +537,8 @@ public class CommandLineEditorLoop { * @return the string */ private String stringAL2String(final List stringArrayList) { - final StringBuilder builder = new StringBuilder(); - boolean first = true; + final var builder = new StringBuilder(); + var first = true; for (final String word : stringArrayList) { if (first) { first = false; @@ -564,7 +563,7 @@ public class CommandLineEditorLoop { final int macroTagPos = line.indexOf(macroFileTag); // Get the line before and after the macro tag - final String lineBeforeMacroTag = line.substring(0, macroTagPos); + final var lineBeforeMacroTag = line.substring(0, macroTagPos); final String lineAfterMacroTag = line.substring(macroTagPos + macroFileTag.length()).replaceAll("^\\s*", ""); // Get the file name that is the argument of the Macro tag diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java index d630d89a5..912a2085e 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -96,8 +96,8 @@ public class CommandLineParameterParser { * @return the CLI parameters */ public CommandLineParameters parse(final String[] args) { - CommandLine commandLine = parseDefault(args); - final CommandLineParameters parameters = new CommandLineParameters(); + var commandLine = parseDefault(args); + final var parameters = new CommandLineParameters(); parseSingleLetterOptions(commandLine, parameters); parseDoubleLetterOptions(commandLine, parameters); diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameters.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameters.java index 9f0672bf1..111d56adb 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameters.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameters.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -173,7 +173,7 @@ public class CommandLineParameters { if (logFileName == null) { return System.out; } else { - File logFile = new File(logFileName); + var logFile = new File(logFileName); if (!logFile.getParentFile().exists()) { logFile.getParentFile().mkdirs(); } diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParser.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParser.java index c9316cbd2..fcbf571ca 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParser.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParser.java @@ -79,9 +79,9 @@ public class CommandLineParser { private ArrayList mergeQuotes(final ArrayList wordsSplitOnQuotes) { final ArrayList wordsWithQuotesMerged = new ArrayList<>(); - int loopWordIndex; - for (int wordIndex = 0; wordIndex < wordsSplitOnQuotes.size(); wordIndex = loopWordIndex) { - loopWordIndex = mergeQuote(wordsSplitOnQuotes, wordsWithQuotesMerged, wordIndex); + var wordIndex = 0; + while (wordIndex < wordsSplitOnQuotes.size()) { + wordIndex = mergeQuote(wordsSplitOnQuotes, wordsWithQuotesMerged, wordIndex); } return wordsWithQuotesMerged; @@ -99,7 +99,7 @@ public class CommandLineParser { int wordIndex) { if ("\"".equals(wordsSplitOnQuotes.get(wordIndex))) { - StringBuilder quotedWord = new StringBuilder(wordsSplitOnQuotes.get(wordIndex++)); + var quotedWord = new StringBuilder(wordsSplitOnQuotes.get(wordIndex++)); for (; wordIndex < wordsSplitOnQuotes.size(); wordIndex++) { quotedWord.append(wordsSplitOnQuotes.get(wordIndex)); @@ -108,7 +108,7 @@ public class CommandLineParser { break; } } - String quotedWordToString = quotedWord.toString(); + var quotedWordToString = quotedWord.toString(); if (quotedWordToString.matches("^\".*\"$")) { wordsWithQuotesMerged.add(quotedWordToString); } else { @@ -156,27 +156,26 @@ public class CommandLineParser { private ArrayList mergeEquals(final ArrayList wordsSplitOnEquals) { final ArrayList wordsWithEqualsMerged = new ArrayList<>(); - int loopWordIndex; - for (int wordIndex = 0; wordIndex < wordsSplitOnEquals.size(); wordIndex = loopWordIndex) { - loopWordIndex = wordIndex; + var wordIndex = 0; + while (wordIndex < wordsSplitOnEquals.size()) { // Is this a quoted word ? - if (wordsSplitOnEquals.get(loopWordIndex).startsWith("\"")) { - wordsWithEqualsMerged.add(wordsSplitOnEquals.get(loopWordIndex)); + if (wordsSplitOnEquals.get(wordIndex).startsWith("\"")) { + wordsWithEqualsMerged.add(wordsSplitOnEquals.get(wordIndex)); continue; } - if ("=".equals(wordsSplitOnEquals.get(loopWordIndex))) { - if (loopWordIndex < wordsSplitOnEquals.size() - 1 - && !wordsSplitOnEquals.get(loopWordIndex + 1).startsWith("=")) { + if ("=".equals(wordsSplitOnEquals.get(wordIndex))) { + if (wordIndex < wordsSplitOnEquals.size() - 1 + && !wordsSplitOnEquals.get(wordIndex + 1).startsWith("=")) { wordsWithEqualsMerged.add( - wordsSplitOnEquals.get(loopWordIndex) + wordsSplitOnEquals.get(loopWordIndex + 1)); - loopWordIndex += 2; + wordsSplitOnEquals.get(wordIndex) + wordsSplitOnEquals.get(wordIndex + 1)); + wordIndex += 2; } else { - wordsWithEqualsMerged.add(wordsSplitOnEquals.get(loopWordIndex++)); + wordsWithEqualsMerged.add(wordsSplitOnEquals.get(wordIndex++)); } } else { - wordsWithEqualsMerged.add(wordsSplitOnEquals.get(loopWordIndex++)); + wordsWithEqualsMerged.add(wordsSplitOnEquals.get(wordIndex++)); } } @@ -193,7 +192,7 @@ public class CommandLineParser { private ArrayList mergeArguments(final ArrayList words) { final ArrayList mergedArguments = new ArrayList<>(); - for (int i = 0; i < words.size(); i++) { + for (var i = 0; i < words.size(); i++) { // Is this a quoted word ? if (words.get(i).startsWith("\"")) { mergedArguments.add(words.get(i)); @@ -275,7 +274,7 @@ public class CommandLineParser { private ArrayList splitOnChar(final String line, final char splitChar) { final ArrayList wordsSplitOnQuotes = new ArrayList<>(); - int currentPos = 0; + var currentPos = 0; while (currentPos != -1) { final int quotePos = line.indexOf(splitChar, currentPos); if (quotePos != -1) { @@ -317,7 +316,7 @@ public class CommandLineParser { } // Now check that we have a sequence of commands at the beginning - int currentWordPos = 0; + var currentWordPos = 0; for (; currentWordPos < commandWords.size(); currentWordPos++) { if (!commandWords.get(currentWordPos).matches("^[a-zA-Z0-9]*$")) { break; diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java index a2b15f50e..0a99eb067 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -172,7 +172,7 @@ public class KeywordNode implements Comparable { return this.hashCode() - otherKeywordNode.hashCode(); } - final KeywordNode other = otherKeywordNode; + final var other = otherKeywordNode; if (!keyword.equals(other.keyword)) { return keyword.compareTo(other.keyword); @@ -185,8 +185,8 @@ public class KeywordNode implements Comparable { @Override public int hashCode() { - final int prime = 31; - int result = 1; + final var prime = 31; + var result = 1; result = prime * result + ((children == null) ? 0 : children.hashCode()); result = prime * result + ((command == null) ? 0 : command.hashCode()); result = prime * result + ((keyword == null) ? 0 : keyword.hashCode()); diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java index f5d6d31fd..1f2703daa 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,10 +52,10 @@ public class ApexCliToscaEditorMain { * @param args the command line arguments */ public ApexCliToscaEditorMain(final String[] args) { - final String argumentString = Arrays.toString(args); + final var argumentString = Arrays.toString(args); LOGGER.info("Starting Apex CLI Tosca editor with arguments - {}", argumentString); - final ApexCliToscaParameterParser parser = new ApexCliToscaParameterParser(); + final var parser = new ApexCliToscaParameterParser(); parameters = parser.parse(args); if (parameters.isHelpSet()) { CliUtils.help(ApexCliToscaEditorMain.class.getName(), parser.getOptions()); @@ -65,7 +65,7 @@ public class ApexCliToscaEditorMain { String policyModelFilePath = null; try { - final File tempModelFile = File.createTempFile("policyModel", ".json"); + final var tempModelFile = File.createTempFile("policyModel", ".json"); policyModelFilePath = tempModelFile.getAbsolutePath(); } catch (IOException e) { LOGGER.error("Cannot create the policy model temp file.", e); diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameterParser.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameterParser.java index d5c66858f..5a35499c7 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameterParser.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameterParser.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,6 @@ package org.onap.policy.apex.auth.clieditor.tosca; -import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.onap.policy.apex.auth.clieditor.CommandLineParameterParser; @@ -54,8 +53,8 @@ public class ApexCliToscaParameterParser extends CommandLineParameterParser { */ @Override public ApexCliToscaParameters parse(final String[] args) { - CommandLine commandLine = parseDefault(args); - final ApexCliToscaParameters parameters = new ApexCliToscaParameters(); + var commandLine = parseDefault(args); + final var parameters = new ApexCliToscaParameters(); parseSingleLetterOptions(commandLine, parameters); parseDoubleLetterOptions(commandLine, parameters); diff --git a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/utils/CliUtils.java b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/utils/CliUtils.java index a70439e10..22c541c3a 100644 --- a/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/utils/CliUtils.java +++ b/auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/utils/CliUtils.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,17 +68,17 @@ public class CliUtils { */ public static void createToscaServiceTemplate(ApexCliToscaParameters parameters, String policyModelFilePath) throws IOException, CoderException { - final StandardCoder standardCoder = new StandardCoder(); - String apexConfig = TextFileUtils.getTextFileAsString(parameters.getApexConfigFileName()); + final var standardCoder = new StandardCoder(); + var apexConfig = TextFileUtils.getTextFileAsString(parameters.getApexConfigFileName()); JsonObject apexConfigJson = standardCoder.decode(apexConfig, JsonObject.class); - String policyModel = TextFileUtils.getTextFileAsString(policyModelFilePath); + var policyModel = TextFileUtils.getTextFileAsString(policyModelFilePath); JsonObject policyModelJson = standardCoder.decode(policyModel, JsonObject.class); - String toscaTemplate = TextFileUtils.getTextFileAsString(parameters.getInputToscaTemplateFileName()); + var toscaTemplate = TextFileUtils.getTextFileAsString(parameters.getInputToscaTemplateFileName()); JsonObject toscaTemplateJson = standardCoder.decode(toscaTemplate, JsonObject.class); - JsonObject toscaPolicyProperties = toscaTemplateJson.get("topology_template").getAsJsonObject(); - JsonObject toscaPolicy = toscaPolicyProperties.get("policies").getAsJsonArray().get(0).getAsJsonObject(); - JsonObject toscaProperties = toscaPolicy.get(toscaPolicy.keySet().toArray()[0].toString()).getAsJsonObject() + var toscaPolicyProperties = toscaTemplateJson.get("topology_template").getAsJsonObject(); + var toscaPolicy = toscaPolicyProperties.get("policies").getAsJsonArray().get(0).getAsJsonObject(); + var toscaProperties = toscaPolicy.get(toscaPolicy.keySet().toArray()[0].toString()).getAsJsonObject() .get("properties").getAsJsonObject(); apexConfigJson.entrySet().forEach(entry -> { @@ -87,7 +87,7 @@ public class CliUtils { } toscaProperties.add(entry.getKey(), entry.getValue()); }); - final String toscaPolicyString = standardCoder.encode(toscaTemplateJson); + final var toscaPolicyString = standardCoder.encode(toscaTemplateJson); final String toscaPolicyFileName = parameters.getOutputToscaPolicyFileName(); if (StringUtils.isNotBlank(toscaPolicyFileName)) { TextFileUtils.putStringAsTextFile(toscaPolicyString, toscaPolicyFileName); @@ -106,7 +106,7 @@ public class CliUtils { if (fileName == null) { return; } - final File theFile = new File(fileName); + final var theFile = new File(fileName); final String prefixExceptionMessage = "File " + fileName + OF_TYPE_TAG + fileTag; if (!theFile.exists()) { @@ -130,7 +130,7 @@ public class CliUtils { if (fileName == null) { return; } - final File theFile = new File(fileName); + final var theFile = new File(fileName); final String prefixExceptionMessage = "File " + fileName + OF_TYPE_TAG + fileTag; if (theFile.exists()) { if (!theFile.isFile()) { @@ -163,7 +163,7 @@ public class CliUtils { if (directoryName == null) { return; } - final File theDirectory = new File(directoryName); + final var theDirectory = new File(directoryName); final String prefixExceptionMessage = "directory " + directoryName + OF_TYPE_TAG + directoryTag; if (theDirectory.exists()) { @@ -187,7 +187,7 @@ public class CliUtils { * @param options the options for cli editor */ public static void help(final String mainClassName, Options options) { - final HelpFormatter helpFormatter = new HelpFormatter(); + final var helpFormatter = new HelpFormatter(); helpFormatter.printHelp(MAX_HELP_LINE_LENGTH, mainClassName + " [options...]", "options", options, ""); } @@ -212,7 +212,7 @@ public class CliUtils { pd = new PropertyDescriptor(entry.getValue().toString(), class1); getter = pd.getReadMethod(); argValue = getter.invoke(parameters); - String key = entry.getKey().toString(); + var key = entry.getKey().toString(); if (argValue instanceof String && !key.equals("o")) { cliArgsList.add("-" + key); 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 f05757fc8..15b2b98f3 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (c) 2020 Nordix Foundation. + * Copyright (c) 2020-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ package org.onap.policy.apex.auth.clieditor; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import java.util.List; @@ -66,11 +67,11 @@ public class CommandLineCommandTest { commandLineCommand.getApiMethodName(); } - @Test(expected = CommandLineException.class) + @Test() public void testInvalidApiMethod() { commandLineCommand.setApiMethod("fail."); assertEquals("fail.", commandLineCommand.getApiMethod()); - commandLineCommand.getApiMethodName(); + assertThrows(CommandLineException.class, () -> commandLineCommand.getApiMethodName()); } @Test diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java index d559d7591..c9d9b9c8d 100644 --- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java +++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -169,7 +169,7 @@ public class ApexEngineImplTest { } @Test - public void testSanity() throws ApexException { + public void testSanity() throws ApexException { AxArtifactKey engineKey = new AxArtifactKey("Engine:0.0.1"); ApexEngineImpl engine = (ApexEngineImpl) new ApexEngineFactory().createApexEngine(engineKey); assertNotNull(engine); @@ -196,6 +196,12 @@ public class ApexEngineImplTest { assertThatThrownBy(() -> engine.removeEventListener(null)) .hasMessage("removeEventListener()<-Engine:0.0.1,STOPPED, listenerName is null"); + } + + @Test + public void testListener() throws ApexException { + AxArtifactKey engineKey = new AxArtifactKey("Engine:0.0.1"); + ApexEngineImpl engine = (ApexEngineImpl) new ApexEngineFactory().createApexEngine(engineKey); engine.addEventListener("myListener", new DummyListener()); engine.removeEventListener("myListener"); @@ -244,6 +250,14 @@ public class ApexEngineImplTest { assertEquals(AxEngineState.READY, engine.getState()); assertNull(engine.createEvent(null)); + } + + @Test + public void testEventKey() throws ApexException { + AxArtifactKey engineKey = new AxArtifactKey("Engine:0.0.1"); + ApexEngineImpl engine = (ApexEngineImpl) new ApexEngineFactory().createApexEngine(engineKey); + engine.updateModel(policyModel, false); + engine.start(); AxArtifactKey eventKey = new AxArtifactKey("Event:0.0.1"); EnEvent event = engine.createEvent(eventKey); diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java index 47b85629f..e794a7d04 100644 --- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java +++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java @@ -1,20 +1,20 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -27,6 +27,7 @@ import org.onap.policy.apex.model.basicmodel.concepts.ApexException; /** * Dummy engine event listener for unit test. + * Thread.sleep is used to simulate a slow event listener. * */ public class DummySlowEnEventListener implements EnEventListener { diff --git a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java index fa04f19b5..128e585fe 100644 --- a/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java +++ b/core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation + * Modifications Copyright (C) 2020-2021 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -101,6 +101,15 @@ public class EnEventTest { .hasMessage("null keys are illegal on method parameter \"key\""); assertThatThrownBy(() -> event.put("NonField", null)) .hasMessage("parameter with key \"NonField\" not defined on event \"Event\""); + } + + @Test + public void testAxEvent() { + AxArtifactKey eventKey = new AxArtifactKey("Event:0.0.1"); + AxEvent axEvent = new AxEvent(eventKey, "a.name.space", "some source", "some target"); + ModelService.getModel(AxEvents.class).getEventMap().put(eventKey, axEvent); + EnEvent event = new EnEvent(eventKey); + AxReferenceKey fieldKey = new AxReferenceKey("Parent", "0.0.1", "MyParent", "MyField"); AxArtifactKey fieldSchemaKey = new AxArtifactKey("FieldSchema:0.0.1"); AxField axField = new AxField(fieldKey, fieldSchemaKey); -- cgit 1.2.3-korg