Fix Sonar Issues on Apex-pdp 70/121570/3
authorlapentafd <francesco.lapenta@est.tech>
Thu, 27 May 2021 09:18:49 +0000 (10:18 +0100)
committerlapentafd <francesco.lapenta@est.tech>
Mon, 31 May 2021 15:39:15 +0000 (16:39 +0100)
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 <francesco.lapenta@est.tech>
20 files changed:
auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CgStringRenderer.java
auth/cli-codegen/src/main/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditor.java
auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTest.java [moved from auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTester.java with 98% similarity]
auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexCommandLineEditorMain.java
auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelHandler.java
auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/ApexModelProperties.java
auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineArgument.java
auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineCommand.java
auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorLoop.java
auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameterParser.java
auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParameters.java
auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/CommandLineParser.java
auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/KeywordNode.java
auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorMain.java
auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaParameterParser.java
auth/cli-editor/src/main/java/org/onap/policy/apex/auth/clieditor/utils/CliUtils.java
auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineCommandTest.java
core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/ApexEngineImplTest.java
core/core-engine/src/test/java/org/onap/policy/apex/core/engine/engine/impl/DummySlowEnEventListener.java
core/core-engine/src/test/java/org/onap/policy/apex/core/engine/event/EnEventTest.java

index b2cd9b9..c7235af 100644 (file)
@@ -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<Object> {
             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<Object> {
         }
 
         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 {
index 53acc9c..6ad5fbc 100644 (file)
@@ -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<ST> 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);
@@ -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=========================================================
  */
@@ -37,7 +38,7 @@ import org.stringtemplate.v4.STGroupFile;
  *
  * @author Sven van der Meer (sven.van.der.meer@ericsson.com)
  */
-public class SupportGenerationTester {
+public class SupportGenerationTest {
 
     /**
      * Get the chunks for the codegen.
index 9258b45..424f585 100644 (file)
@@ -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) {
index 6814eab..896448b 100644 (file)
@@ -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<String, CommandLineArgumentValue> 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<String, CommandLineArgumentValue> 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())
index 0e3cd06..d618b15 100644 (file)
@@ -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);
index 48899ba..772cd50 100644 (file)
@@ -98,7 +98,7 @@ public class CommandLineArgument implements Comparable<CommandLineArgument> {
      * @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<CommandLineArgument> {
      */
     @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);
index beae65a..37806af 100644 (file)
@@ -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<CommandLineCommand> {
      * @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<CommandLineCommand> {
      */
     @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());
index 991257e..e198b66 100644 (file)
@@ -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<Result, Integer> 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<Result, Integer> 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<KeywordNode> keynodeDequeIter = keywordNodeDeque.descendingIterator();
 
         while (keynodeDequeIter.hasNext()) {
@@ -300,11 +299,11 @@ public class CommandLineEditorLoop {
     private CommandLineCommand findCommand(final List<String> 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<String> 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
index d630d89..912a208 100644 (file)
@@ -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);
 
index 9f0672b..111d56a 100644 (file)
@@ -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();
             }
index c9316cb..fcbf571 100644 (file)
@@ -79,9 +79,9 @@ public class CommandLineParser {
     private ArrayList<String> mergeQuotes(final ArrayList<String> wordsSplitOnQuotes) {
         final ArrayList<String> 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<String> mergeEquals(final ArrayList<String> wordsSplitOnEquals) {
         final ArrayList<String> 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<String> mergeArguments(final ArrayList<String> words) {
         final ArrayList<String> 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<String> splitOnChar(final String line, final char splitChar) {
         final ArrayList<String> 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;
index a2b15f5..0a99eb0 100644 (file)
@@ -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<KeywordNode> {
             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<KeywordNode> {
 
     @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());
index f5d6d31..1f2703d 100644 (file)
@@ -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);
index d5c6685..5a35499 100644 (file)
@@ -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);
 
index a70439e..22c541c 100644 (file)
@@ -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);
index f05757f..15b2b98 100644 (file)
@@ -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
index d559d75..c9d9b9c 100644 (file)
@@ -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);
index 47b8562..e794a7d 100644 (file)
@@ -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 {
index fa04f19..128e585 100644 (file)
@@ -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);