diff options
author | adheli.tavares <adheli.tavares@est.tech> | 2024-06-13 10:54:26 +0100 |
---|---|---|
committer | Adheli Tavares <adheli.tavares@est.tech> | 2024-06-14 10:02:50 +0000 |
commit | e9b746340711ddfccee7ac0f669ace626b1b3d46 (patch) | |
tree | 43077652efad7d4e10c6d858e9006eac15dc1041 /auth/cli-codegen | |
parent | 70e614910a05b3588902a779e996a9c695c4b3d9 (diff) |
Convert junit4 to junit5
Issue-ID: POLICY-5041
Change-Id: I14f9451a7569f6740bcbd84ae3188d2371067cd0
Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
Diffstat (limited to 'auth/cli-codegen')
4 files changed, 96 insertions, 98 deletions
diff --git a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java index f0cb1d879..1b44f66e7 100644 --- a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java +++ b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd. - * Modifications Copyright (C) 2020,2022 Nordix Foundation + * Modifications Copyright (C) 2020, 2022, 2024 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. * ================================================================================ @@ -24,7 +24,7 @@ package org.onap.policy.apex.auth.clicodegen; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.File; import java.io.FileInputStream; @@ -36,7 +36,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; @@ -60,13 +60,13 @@ import org.stringtemplate.v4.ST; /** * Test CLI code generation. */ -public class CodeGeneratorCliEditorTest { +class CodeGeneratorCliEditorTest { private SupportKeyInfoGetter kig; private File outFile = null; @Test - public void test() throws IOException, ApexModelException { + void test() throws IOException, ApexModelException { final CodeGeneratorCliEditor codeGen = new CodeGeneratorCliEditor(); outFile = File.createTempFile("ApexTestGenerated", ".apex"); @@ -76,8 +76,7 @@ public class CodeGeneratorCliEditorTest { modelReader.setValidate(false); AxPolicyModel apexPolicyModel = null; - apexPolicyModel = modelReader - .read(new FileInputStream(new File("src/test/resources/models/TestPolicyModel.json"))); + apexPolicyModel = modelReader.read(new FileInputStream("src/test/resources/models/TestPolicyModel.json")); assertEquals(0, generateCli(codeGen, apexPolicyModel)); } @@ -85,9 +84,9 @@ public class CodeGeneratorCliEditorTest { /** * Generate the CLI from the model. * - * @param codeGen the code generator + * @param codeGen the code generator * @param policyModel the policy model - * @throws IOException on generation exceptions + * @throws IOException on generation exceptions */ private int generateCli(final CodeGeneratorCliEditor codeGen, final AxPolicyModel policyModel) throws IOException { kig = new SupportKeyInfoGetter(policyModel); @@ -102,7 +101,7 @@ public class CodeGeneratorCliEditorTest { final AxArtifactKey key = s.getKey(); codeGen.addSchemaDeclaration(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key), - s.getSchemaFlavour(), s.getSchema()); + s.getSchemaFlavour(), s.getSchema()); } // 2: tasks @@ -123,16 +122,16 @@ public class CodeGeneratorCliEditorTest { final List<ST> fields = getParametersForEvent(codeGen, e); codeGen.addEventDeclaration( - EventDeclaration.builder() - .name(kig.getName(key)) - .version(kig.getVersion(key)) - .uuid(kig.getUuid(key)) - .description(kig.getDesc(key)) - .nameSpace(e.getNameSpace()) - .source(e.getSource()) - .target(e.getTarget()) - .fields(fields) - .build()); + EventDeclaration.builder() + .name(kig.getName(key)) + .version(kig.getVersion(key)) + .uuid(kig.getUuid(key)) + .description(kig.getDesc(key)) + .nameSpace(e.getNameSpace()) + .source(e.getSource()) + .target(e.getTarget()) + .fields(fields) + .build()); } // 4: context albums @@ -140,16 +139,16 @@ public class CodeGeneratorCliEditorTest { final AxArtifactKey key = a.getKey(); codeGen.addContextAlbumDeclaration( - CodeGenCliEditor.builder() - .name(kig.getName(key)) - .version(kig.getVersion(key)) - .uuid(kig.getUuid(key)) - .description(kig.getDesc(key)) - .scope(a.getScope()) - .writable(a.isWritable()) - .schemaName(kig.getName(a.getItemSchema())) - .schemaVersion(kig.getVersion(a.getItemSchema())) - .build()); + CodeGenCliEditor.builder() + .name(kig.getName(key)) + .version(kig.getVersion(key)) + .uuid(kig.getUuid(key)) + .description(kig.getDesc(key)) + .scope(a.getScope()) + .writable(a.isWritable()) + .schemaName(kig.getName(a.getItemSchema())) + .schemaVersion(kig.getVersion(a.getItemSchema())) + .build()); } // 5: policies @@ -157,7 +156,7 @@ public class CodeGeneratorCliEditorTest { final AxArtifactKey key = p.getKey(); final List<ST> states = getStatesForPolicy(codeGen, p); codeGen.addPolicyDefinition(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key), - p.getTemplate(), p.getFirstState(), states); + p.getTemplate(), p.getFirstState(), states); } final String out = codeGen.getModel().render(); @@ -172,7 +171,7 @@ public class CodeGeneratorCliEditorTest { /** * Gets the parameters for event. * - * @param cg the code generator + * @param cg the code generator * @param event the event * @return the parameters for event */ @@ -183,7 +182,7 @@ public class CodeGeneratorCliEditorTest { final AxReferenceKey fkey = f.getKey(); final ST val = cg.createEventFieldDefinition(kig.getPName(fkey), kig.getPVersion(fkey), kig.getLName(fkey), - kig.getName(f.getSchema()), kig.getVersion(f.getSchema()), f.getOptional()); + kig.getName(f.getSchema()), kig.getVersion(f.getSchema()), f.getOptional()); ret.add(val); } @@ -193,7 +192,7 @@ public class CodeGeneratorCliEditorTest { /** * Gets the context references for task. * - * @param cg the code generator + * @param cg the code generator * @param task the task * @return the context references for task */ @@ -204,7 +203,7 @@ public class CodeGeneratorCliEditorTest { for (final AxArtifactKey ckey : ctxs) { final ST val = cg.createTaskDefinitionContextRef(kig.getName(tkey), kig.getVersion(tkey), kig.getName(ckey), - kig.getVersion(ckey)); + kig.getVersion(ckey)); ret.add(val); } @@ -214,7 +213,7 @@ public class CodeGeneratorCliEditorTest { /** * Gets the parameters for task. * - * @param cg the code generator + * @param cg the code generator * @param task the task * @return the parameters for task */ @@ -225,7 +224,7 @@ public class CodeGeneratorCliEditorTest { final AxReferenceKey pkey = p.getKey(); final ST val = cg.createTaskDefinitionParameters(kig.getPName(pkey), kig.getPVersion(pkey), - kig.getLName(pkey), p.getTaskParameterValue()); + kig.getLName(pkey), p.getTaskParameterValue()); ret.add(val); } @@ -235,7 +234,7 @@ public class CodeGeneratorCliEditorTest { /** * Gets the logic for task. * - * @param cg the code generator + * @param cg the code generator * @param task the task * @return the logic for task */ @@ -249,7 +248,7 @@ public class CodeGeneratorCliEditorTest { /** * Gets the states for policy. * - * @param cg the code generator + * @param cg the code generator * @param pol the policy * @return the states for policy */ @@ -265,13 +264,13 @@ public class CodeGeneratorCliEditorTest { final List<ST> ctxRefs = getCtxtRefsForState(cg, st); final ST val = cg.createPolicyStateDef(PolicyStateDef.builder() - .policyName(kig.getPName(skey)).version(kig.getPVersion(skey)) - .stateName(kig.getLName(skey)).triggerName(kig.getName(st.getTrigger())) - .triggerVersion(kig.getVersion(st.getTrigger())) - .defaultTask(kig.getName(st.getDefaultTask())) - .defaultTaskVersion(kig.getVersion(st.getDefaultTask())).outputs(outputs) - .tasks(tasks).tsLogic(tsLogic).finalizerLogics(finalizerLogics) - .ctxRefs(ctxRefs).build()); + .policyName(kig.getPName(skey)).version(kig.getPVersion(skey)) + .stateName(kig.getLName(skey)).triggerName(kig.getName(st.getTrigger())) + .triggerVersion(kig.getVersion(st.getTrigger())) + .defaultTask(kig.getName(st.getDefaultTask())) + .defaultTaskVersion(kig.getVersion(st.getDefaultTask())).outputs(outputs) + .tasks(tasks).tsLogic(tsLogic).finalizerLogics(finalizerLogics) + .ctxRefs(ctxRefs).build()); ret.add(val); } @@ -293,7 +292,7 @@ public class CodeGeneratorCliEditorTest { final AxReferenceKey finkey = fin.getKey(); final ST val = cg.createPolicyStateDefFinalizerLogic(kig.getPName(skey), kig.getPVersion(skey), - kig.getLName(skey), kig.getLName(finkey), fin.getLogicFlavour(), fin.getLogic()); + kig.getLName(skey), kig.getLName(finkey), fin.getLogicFlavour(), fin.getLogic()); ret.add(val); } @@ -314,7 +313,7 @@ public class CodeGeneratorCliEditorTest { for (final AxArtifactKey ctx : ctxs) { final ST val = cg.createPolicyStateDefContextRef(kig.getPName(skey), kig.getPVersion(skey), - kig.getLName(skey), kig.getName(ctx), kig.getVersion(ctx)); + kig.getLName(skey), kig.getName(ctx), kig.getVersion(ctx)); ret.add(val); } @@ -333,7 +332,7 @@ public class CodeGeneratorCliEditorTest { if (st.checkSetTaskSelectionLogic()) { final AxTaskSelectionLogic tsl = st.getTaskSelectionLogic(); final ST val = cg.createPolicyStateDefTaskSelLogic(kig.getPName(skey), kig.getPVersion(skey), - kig.getLName(skey), tsl.getLogicFlavour(), tsl.getLogic()); + kig.getLName(skey), tsl.getLogicFlavour(), tsl.getLogic()); return Collections.singletonList(val); } else { return Collections.emptyList(); @@ -357,12 +356,12 @@ public class CodeGeneratorCliEditorTest { final AxReferenceKey trkey = tr.getKey(); final ST val = cg.createPolicyStateTask(PolicyStateTask.builder() - .policyName(kig.getPName(skey)).version(kig.getPVersion(skey)) - .stateName(kig.getLName(skey)).taskLocalName(kig.getLName(trkey)) - .taskName(kig.getName(tkey)).taskVersion(kig.getVersion(tkey)) - .outputType(tr.getStateTaskOutputType().name()) - .outputName(kig.getLName(tr.getOutput())) - .build()); + .policyName(kig.getPName(skey)).version(kig.getPVersion(skey)) + .stateName(kig.getLName(skey)).taskLocalName(kig.getLName(trkey)) + .taskName(kig.getName(tkey)).taskVersion(kig.getVersion(tkey)) + .outputType(tr.getStateTaskOutputType().name()) + .outputName(kig.getLName(tr.getOutput())) + .build()); ret.add(val); } diff --git a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/DummyStErrorListener.java b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/DummyStErrorListener.java index 572b40e74..be3ec8642 100644 --- a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/DummyStErrorListener.java +++ b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/DummyStErrorListener.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) 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +35,9 @@ import org.stringtemplate.v4.misc.STMessage; */ public class DummyStErrorListener implements STErrorListener { - /** Counts errors of the listener. */ + /** + * Counts errors of the listener. + */ @Getter(AccessLevel.PROTECTED) @Setter(AccessLevel.PROTECTED) private int errorCount; @@ -44,10 +47,7 @@ public class DummyStErrorListener implements STErrorListener { */ @Override public void IOError(final STMessage msg) { - switch (msg.error) { - default: - this.registerErrors(msg); - } + this.registerErrors(msg); } /** @@ -55,10 +55,7 @@ public class DummyStErrorListener implements STErrorListener { */ @Override public void compileTimeError(final STMessage msg) { - switch (msg.error) { - default: - this.registerErrors(msg); - } + this.registerErrors(msg); } /** @@ -66,10 +63,7 @@ public class DummyStErrorListener implements STErrorListener { */ @Override public void internalError(final STMessage msg) { - switch (msg.error) { - default: - this.registerErrors(msg); - } + this.registerErrors(msg); } /** @@ -78,9 +72,7 @@ public class DummyStErrorListener implements STErrorListener { @Override public void runTimeError(final STMessage msg) { switch (msg.error) { - case NO_SUCH_PROPERTY: - case ARGUMENT_COUNT_MISMATCH: - case ANON_ARGUMENT_MISMATCH: + case NO_SUCH_PROPERTY, ARGUMENT_COUNT_MISMATCH, ANON_ARGUMENT_MISMATCH: break; default: this.registerErrors(msg); 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 index e6c43692f..e45a44296 100644 --- 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 @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2021-2022 Nordix Foundation + * Modifications Copyright (C) 2021-2022, 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ package org.onap.policy.apex.auth.clicodegen; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Arrays; import java.util.LinkedHashMap; @@ -29,7 +29,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeSet; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.stringtemplate.v4.STGroup; import org.stringtemplate.v4.STGroupFile; @@ -38,7 +38,7 @@ import org.stringtemplate.v4.STGroupFile; * * @author Sven van der Meer (sven.van.der.meer@ericsson.com) */ -public class SupportGenerationTest { +class SupportGenerationTest { /** * Get the chunks for the codegen. @@ -51,44 +51,46 @@ public class SupportGenerationTest { final Map<String, List<String>> chunks = new LinkedHashMap<>(); chunks.put("/policyModel", - Arrays.asList("name", "version", "uuid", "description", "declarations", "definitions")); + 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")); + "schemaName", "schemaVersion")); chunks.put("/eventDecl", - Arrays.asList("name", "version", "uuid", "description", "nameSpace", "source", "target", "fields")); + Arrays.asList("name", "version", "uuid", "description", "nameSpace", "source", "target", "fields")); chunks.put("/eventDefField", - Arrays.asList("eventName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion", "optional")); + Arrays.asList("eventName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion", "optional")); chunks.put("/taskDecl", - Arrays.asList("name", "version", "uuid", "description", "infields", "outfields", "logic")); + Arrays.asList("name", "version", "uuid", "description", "infields", "outfields", "logic")); chunks.put("/taskDefInputFields", - Arrays.asList("taskName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion")); + Arrays.asList("taskName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion")); chunks.put("/taskDefOutputFields", - Arrays.asList("taskName", "version", "fieldName", "fieldSchema", "fieldSchemaVersion")); + 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")); + "triggerVersion", "defaultTask", "defaultTaskVersion", "outputs", "tasks")); chunks.put("/policyStateOutput", Arrays.asList("policyName", "version", "stateName", "outputName", "eventName", - "eventVersion", "nextState")); + "eventVersion", "nextState")); chunks.put("/policyStateTaskSelectionLogic", - Arrays.asList("name", "version", "stateName", "logicFlavour", "logic")); + Arrays.asList("name", "version", "stateName", "logicFlavour", "logic")); chunks.put("/policyStateTask", Arrays.asList("policyName", "version", "stateName", "taskLocalName", "taskName", - "taskVersion", "outputType", "outputName")); + "taskVersion", "outputType", "outputName")); chunks.put("/policyStateFinalizerLogic", - Arrays.asList("name", "version", "stateName", "finalizerLogicName", "logicFlavour", "logic")); + Arrays.asList("name", "version", "stateName", "finalizerLogicName", "logicFlavour", "logic")); chunks.put("/policyStateContextRef", - Arrays.asList("name", "version", "stateName", "albumName", "albumVersion")); + Arrays.asList("name", "version", "stateName", "albumName", "albumVersion")); return chunks; // CHECKSTYLE:ON: LineLength } - /** Test STG load. */ + /** + * Test STG load. + */ @Test - public void testGenerationLoad() { + void testGenerationLoad() { final DummyStErrorListener errListener = new DummyStErrorListener(); final STGroupFile stg = new STGroupFile(CodeGeneratorCliEditor.STG_FILE); stg.setListener(errListener); @@ -97,16 +99,18 @@ public class SupportGenerationTest { assertEquals(0, errListener.getErrorCount()); } - /** Test STG chunks. */ + /** + * Test STG chunks. + */ @Test - public void testGenerationChunks() { + 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<String, List<String>> chunks = getCodeGenChunks(); - String error = ""; + StringBuilder error = new StringBuilder(); final Set<String> definedNames = stg.getTemplateNames(); for (final STGroup group : stg.getImportedGroups()) { definedNames.addAll(group.getTemplateNames()); @@ -115,15 +119,15 @@ public class SupportGenerationTest { for (final String required : requiredNames) { if (!definedNames.contains(required)) { - error += " - target STG does not define template for <" + required + ">\n"; + error.append(" - target STG does not define template for <").append(required).append(">\n"); } else { final Set<String> definedParams = ((stg.getInstanceOf(required).getAttributes() == null) - ? new TreeSet<String>() : stg.getInstanceOf(required).getAttributes().keySet()); + ? new TreeSet<>() : stg.getInstanceOf(required).getAttributes().keySet()); final List<String> 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"; + error.append(" - target STG with template <").append(required) + .append("> does not define argument <").append(reqArg).append(">\n"); } } } diff --git a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportKeyInfoGetter.java b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportKeyInfoGetter.java index 567991666..1d24c1f51 100644 --- a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportKeyInfoGetter.java +++ b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportKeyInfoGetter.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) 2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,7 +36,9 @@ import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; @AllArgsConstructor public class SupportKeyInfoGetter { - /** The policy model for the getters. */ + /** + * The policy model for the getters. + */ private final AxPolicyModel model; /** |