From 752af31947114d88a2994ee6435c94ed9643f76a Mon Sep 17 00:00:00 2001 From: Parshad Patel Date: Fri, 30 Nov 2018 20:15:11 +0900 Subject: Rename test classes in apex-pdp Make test classes name consitence by adding 'Support' or 'Dummy' at start of util or dummy type of test classes Issue-ID: POLICY-1263 Change-Id: I1dc1a7f174660a90664ebdcff2ea79ed30aa465c Signed-off-by: Parshad Patel --- .../apex/auth/clicodegen/CliCodegenTest.java | 434 --------------------- .../clicodegen/CodeGeneratorCliEditorTest.java | 434 +++++++++++++++++++++ .../apex/auth/clicodegen/DummyStErrorListener.java | 111 ++++++ .../apex/auth/clicodegen/GenerationTest.java | 138 ------- .../policy/apex/auth/clicodegen/KeyInfoGetter.java | 159 -------- .../apex/auth/clicodegen/StErrorListener.java | 111 ------ .../auth/clicodegen/SupportGenerationTester.java | 138 +++++++ .../apex/auth/clicodegen/SupportKeyInfoGetter.java | 159 ++++++++ .../client/editor/rest/handling/bean/BeanFake.java | 49 --- .../editor/rest/handling/bean/BeansTest.java | 2 +- .../editor/rest/handling/bean/DummyBeanBase.java | 49 +++ .../context/impl/schema/java/BadJsonAdapter.java | 63 --- .../java/JavaSchemaHelperParametersTest.java | 6 +- .../impl/schema/java/JavaSchemaHelperTest.java | 10 +- .../apex/context/impl/schema/java/MyBaseClass.java | 33 -- .../apex/context/impl/schema/java/MySubClass.java | 27 -- .../impl/schema/java/SupportBadJsonAdapter.java | 63 +++ .../context/impl/schema/java/SupportBaseClass.java | 33 ++ .../impl/schema/java/SupportJsonAdapter.java | 55 +++ .../impl/schema/java/SupportJsonDeserializer.java | 44 +++ .../impl/schema/java/SupportJsonSerializer.java | 50 +++ .../context/impl/schema/java/SupportSubClass.java | 27 ++ .../context/impl/schema/java/TestJsonAdapter.java | 55 --- .../impl/schema/java/TestJsonDeserializer.java | 44 --- .../impl/schema/java/TestJsonSerializer.java | 50 --- 25 files changed, 1172 insertions(+), 1172 deletions(-) delete mode 100644 auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CliCodegenTest.java create mode 100644 auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java create mode 100644 auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/DummyStErrorListener.java delete mode 100644 auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/GenerationTest.java delete mode 100644 auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/KeyInfoGetter.java delete mode 100644 auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/StErrorListener.java create mode 100644 auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTester.java create mode 100644 auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportKeyInfoGetter.java delete mode 100644 client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/BeanFake.java create mode 100644 client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/DummyBeanBase.java delete mode 100644 context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/BadJsonAdapter.java delete mode 100644 context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/MyBaseClass.java delete mode 100644 context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/MySubClass.java create mode 100644 context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportBadJsonAdapter.java create mode 100644 context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportBaseClass.java create mode 100644 context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportJsonAdapter.java create mode 100644 context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportJsonDeserializer.java create mode 100644 context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportJsonSerializer.java create mode 100644 context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportSubClass.java delete mode 100644 context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/TestJsonAdapter.java delete mode 100644 context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/TestJsonDeserializer.java delete mode 100644 context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/TestJsonSerializer.java diff --git a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CliCodegenTest.java b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CliCodegenTest.java deleted file mode 100644 index 5433f2d15..000000000 --- a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CliCodegenTest.java +++ /dev/null @@ -1,434 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 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 static org.junit.Assert.fail; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.FileWriter; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import org.junit.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; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; -import org.onap.policy.apex.model.eventmodel.concepts.AxField; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicy; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; -import org.onap.policy.apex.model.policymodel.concepts.AxState; -import org.onap.policy.apex.model.policymodel.concepts.AxStateFinalizerLogic; -import org.onap.policy.apex.model.policymodel.concepts.AxStateOutput; -import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference; -import org.onap.policy.apex.model.policymodel.concepts.AxTask; -import org.onap.policy.apex.model.policymodel.concepts.AxTaskLogic; -import org.onap.policy.apex.model.policymodel.concepts.AxTaskParameter; -import org.onap.policy.apex.model.policymodel.concepts.AxTaskSelectionLogic; -import org.stringtemplate.v4.ST; - -/** - * Test CLI code generation. - */ -public class CliCodegenTest { - - private KeyInfoGetter kig; - private File outFile = null; - - @Test - public void test() throws IOException { - final CodeGeneratorCliEditor codeGen = new CodeGeneratorCliEditor(); - - outFile = File.createTempFile("ApexTestGenerated", ".apex"); - - ApexModelReader modelReader = null; - try { - modelReader = new ApexModelReader<>(AxPolicyModel.class); - } catch (ApexModelException e1) { - fail("test should not throw an exception"); - } - modelReader.setValidateFlag(false); - AxPolicyModel apexPolicyModel = null; - try { - apexPolicyModel = modelReader - .read(new FileInputStream(new File("src/test/resources/models/TestPolicyModel.json"))); - } catch (ApexModelException | FileNotFoundException e) { - fail("test should not throw an exception"); - } - - assertEquals(0, generateCli(codeGen, apexPolicyModel)); - } - - /** - * Generate the CLI from the model. - * - * @param codeGen the code generator - * @param policyModel the policy model - * @throws IOException on generation exceptions - */ - private int generateCli(final CodeGeneratorCliEditor codeGen, final AxPolicyModel policyModel) throws IOException { - kig = new KeyInfoGetter(policyModel); - - // Order is important. 0: model, 1: context schemas, 2: tasks, 3: events, 4: ContextAlbums, 5: Policies - // 0: model - final AxArtifactKey pmkey = policyModel.getKey(); - codeGen.addModelParams(kig.getName(pmkey), kig.getVersion(pmkey), kig.getUuid(pmkey), kig.getDesc(pmkey)); - - // 1: Context Schemas - for (final AxContextSchema s : policyModel.getSchemas().getSchemasMap().values()) { - final AxArtifactKey key = s.getKey(); - - codeGen.addSchemaDeclaration(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key), - s.getSchemaFlavour(), s.getSchema()); - } - - // 2: tasks - for (final AxTask t : policyModel.getTasks().getTaskMap().values()) { - final AxArtifactKey key = t.getKey(); - final List infields = getInfieldsForTask(codeGen, t); - final List outfields = getOutfieldsForTask(codeGen, t); - final ST logic = getLogicForTask(codeGen, t); - final List parameters = getParametersForTask(codeGen, t); - final List contextRefs = getCtxtRefsForTask(codeGen, t); - - codeGen.addTaskDeclaration(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key), - infields, outfields, logic, parameters, contextRefs); - } - - // 3: events - for (final AxEvent e : policyModel.getEvents().getEventMap().values()) { - final AxArtifactKey key = e.getKey(); - final List fields = getParametersForEvent(codeGen, e); - - codeGen.addEventDeclaration( - new EventDeclarationBuilder() - .setName(kig.getName(key)) - .setVersion(kig.getVersion(key)) - .setUuid(kig.getUuid(key)) - .setDescription(kig.getDesc(key)) - .setNameSpace(e.getNameSpace()) - .setSource(e.getSource()) - .setTarget(e.getTarget()) - .setFields(fields)); - } - - // 4: context albums - for (final AxContextAlbum a : policyModel.getAlbums().getAlbumsMap().values()) { - final AxArtifactKey key = a.getKey(); - - codeGen.addContextAlbumDeclaration( - new CodeGenCliEditorBuilder() - .setName(kig.getName(key)) - .setVersion(kig.getVersion(key)) - .setUuid(kig.getUuid(key)) - .setDescription(kig.getDesc(key)) - .setScope(a.getScope()) - .setWritable(a.isWritable()) - .setSchemaName(kig.getName(a.getItemSchema())) - .setSchemaVersion(kig.getVersion(a.getItemSchema()))); - } - - // 5: policies - for (final AxPolicy p : policyModel.getPolicies().getPolicyMap().values()) { - final AxArtifactKey key = p.getKey(); - final List states = getStatesForPolicy(codeGen, p); - codeGen.addPolicyDefinition(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key), - p.getTemplate(), p.getFirstState(), states); - } - - final String out = codeGen.getModel().render(); - - FileWriter outFileWriter = new FileWriter(outFile); - outFileWriter.write(out); - outFileWriter.close(); - - return 0; - } - - /** - * Gets the parameters for event. - * - * @param cg the code generator - * @param event the event - * @return the parameters for event - */ - private List getParametersForEvent(final CodeGeneratorCliEditor cg, final AxEvent event) { - final Collection fields = event.getFields(); - final List ret = new ArrayList<>(fields.size()); - for (final AxField f : fields) { - 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()); - - ret.add(val); - } - return ret; - } - - /** - * Gets the context references for task. - * - * @param cg the code generator - * @param task the task - * @return the context references for task - */ - private List getCtxtRefsForTask(final CodeGeneratorCliEditor cg, final AxTask task) { - final Collection ctxs = task.getContextAlbumReferences(); - final List ret = new ArrayList<>(ctxs.size()); - final AxArtifactKey tkey = task.getKey(); - for (final AxArtifactKey ckey : ctxs) { - - final ST val = cg.createTaskDefinitionContextRef(kig.getName(tkey), kig.getVersion(tkey), kig.getName(ckey), - kig.getVersion(ckey)); - - ret.add(val); - } - return ret; - } - - /** - * Gets the parameters for task. - * - * @param cg the code generator - * @param task the task - * @return the parameters for task - */ - private List getParametersForTask(final CodeGeneratorCliEditor cg, final AxTask task) { - final Collection pars = task.getTaskParameters().values(); - final List ret = new ArrayList<>(pars.size()); - for (final AxTaskParameter p : pars) { - final AxReferenceKey pkey = p.getKey(); - - final ST val = cg.createTaskDefinitionParameters(kig.getPName(pkey), kig.getPVersion(pkey), - kig.getLName(pkey), p.getTaskParameterValue()); - - ret.add(val); - } - return ret; - } - - /** - * Gets the logic for task. - * - * @param cg the code generator - * @param task the task - * @return the logic for task - */ - private ST getLogicForTask(final CodeGeneratorCliEditor cg, final AxTask task) { - final AxArtifactKey tkey = task.getKey(); - final AxTaskLogic tl = task.getTaskLogic(); - - return cg.createTaskDefLogic(kig.getName(tkey), kig.getVersion(tkey), tl.getLogicFlavour(), tl.getLogic()); - } - - /** - * Gets the output fields for task. - * - * @param cg the code generator - * @param task the task - * @return the output fields for task - */ - private List getOutfieldsForTask(final CodeGeneratorCliEditor cg, final AxTask task) { - final Collection fields = task.getOutputFields().values(); - final List ret = new ArrayList<>(fields.size()); - for (final AxField f : fields) { - final AxReferenceKey fkey = f.getKey(); - - final ST val = cg.createTaskDefinitionOutfields(kig.getPName(fkey), kig.getPVersion(fkey), - kig.getLName(fkey), kig.getName(f.getSchema()), kig.getVersion(f.getSchema())); - - ret.add(val); - } - return ret; - } - - /** - * Gets the input fields for task. - * - * @param cg the code generator - * @param task the task - * @return the input fields for task - */ - private List getInfieldsForTask(final CodeGeneratorCliEditor cg, final AxTask task) { - final Collection fields = task.getInputFields().values(); - final List ret = new ArrayList<>(fields.size()); - for (final AxField f : fields) { - final AxReferenceKey fkey = f.getKey(); - - final ST val = cg.createTaskDefinitionInfields(kig.getPName(fkey), kig.getPVersion(fkey), - kig.getLName(fkey), kig.getName(f.getSchema()), kig.getVersion(f.getSchema())); - - ret.add(val); - } - return ret; - } - - /** - * Gets the states for policy. - * - * @param cg the code generator - * @param pol the policy - * @return the states for policy - */ - private List getStatesForPolicy(final CodeGeneratorCliEditor cg, final AxPolicy pol) { - final Collection states = pol.getStateMap().values(); - final List ret = new ArrayList<>(states.size()); - for (final AxState st : states) { - final AxReferenceKey skey = st.getKey(); - final List outputs = getStateOutputsForState(cg, st); - final List finalizerLogics = getFinalizersForState(cg, st); - final List tasks = getTaskRefsForState(cg, st); - final List tsLogic = getTslForState(cg, st); - final List ctxRefs = getCtxtRefsForState(cg, st); - - final ST val = cg.createPolicyStateDef(kig.getPName(skey), kig.getPVersion(skey), kig.getLName(skey), - kig.getName(st.getTrigger()), kig.getVersion(st.getTrigger()), - kig.getName(st.getDefaultTask()), kig.getVersion(st.getDefaultTask()), outputs, tasks, - tsLogic, finalizerLogics, ctxRefs); - - ret.add(val); - } - return ret; - } - - /** - * Gets the finalizers for state. - * - * @param cg the code generator - * @param st the state - * @return the finalizers for state - */ - private List getFinalizersForState(final CodeGeneratorCliEditor cg, final AxState st) { - final Collection fins = st.getStateFinalizerLogicMap().values(); - final List ret = new ArrayList<>(fins.size()); - final AxReferenceKey skey = st.getKey(); - for (final AxStateFinalizerLogic fin : fins) { - 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()); - - ret.add(val); - } - return ret; - } - - /** - * Gets the context references for state. - * - * @param cg the code generator - * @param st the state - * @return the context references for state - */ - private List getCtxtRefsForState(final CodeGeneratorCliEditor cg, final AxState st) { - final Collection ctxs = st.getContextAlbumReferences(); - final List ret = new ArrayList<>(ctxs.size()); - final AxReferenceKey skey = st.getKey(); - 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)); - - ret.add(val); - } - return ret; - } - - /** - * Gets the Task Selection Logic for state. - * - * @param cg the code generator - * @param st the state - * @return the TSL for state (if any) in a list - */ - private List getTslForState(final CodeGeneratorCliEditor cg, final AxState st) { - final AxReferenceKey skey = st.getKey(); - 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()); - return Collections.singletonList(val); - } else { - return Collections.emptyList(); - } - } - - /** - * Gets the task references for state. - * - * @param cg the code generator - * @param st the state - * @return the task references for state - */ - private List getTaskRefsForState(final CodeGeneratorCliEditor cg, final AxState st) { - final Map taskrefs = st.getTaskReferences(); - final List ret = new ArrayList<>(taskrefs.size()); - final AxReferenceKey skey = st.getKey(); - for (final Entry e : taskrefs.entrySet()) { - final AxArtifactKey tkey = e.getKey(); - final AxStateTaskReference tr = e.getValue(); - final AxReferenceKey trkey = tr.getKey(); - - final ST val = cg.createPolicyStateTask(kig.getPName(skey), kig.getPVersion(skey), kig.getLName(skey), - kig.getLName(trkey), kig.getName(tkey), kig.getVersion(tkey), - tr.getStateTaskOutputType().name(), kig.getLName(tr.getOutput())); - - ret.add(val); - } - return ret; - } - - /** - * Gets the state outputs for state. - * - * @param cg the code generator - * @param st the state - * @return the state outputs for state - */ - private List getStateOutputsForState(final CodeGeneratorCliEditor cg, final AxState st) { - final Collection outs = st.getStateOutputs().values(); - final List ret = new ArrayList<>(outs.size()); - final AxReferenceKey skey = st.getKey(); - for (final AxStateOutput out : outs) { - final AxReferenceKey outkey = out.getKey(); - - final ST val = cg.createPolicyStateOutput(kig.getPName(skey), kig.getPVersion(skey), kig.getLName(skey), - kig.getLName(outkey), kig.getName(out.getOutgingEvent()), - kig.getVersion(out.getOutgingEvent()), kig.getLName(out.getNextState())); - - ret.add(val); - } - return ret; - } - -} 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 new file mode 100644 index 000000000..e1bf3b298 --- /dev/null +++ b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/CodeGeneratorCliEditorTest.java @@ -0,0 +1,434 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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 static org.junit.Assert.fail; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.junit.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; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; +import org.onap.policy.apex.model.eventmodel.concepts.AxField; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicy; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; +import org.onap.policy.apex.model.policymodel.concepts.AxState; +import org.onap.policy.apex.model.policymodel.concepts.AxStateFinalizerLogic; +import org.onap.policy.apex.model.policymodel.concepts.AxStateOutput; +import org.onap.policy.apex.model.policymodel.concepts.AxStateTaskReference; +import org.onap.policy.apex.model.policymodel.concepts.AxTask; +import org.onap.policy.apex.model.policymodel.concepts.AxTaskLogic; +import org.onap.policy.apex.model.policymodel.concepts.AxTaskParameter; +import org.onap.policy.apex.model.policymodel.concepts.AxTaskSelectionLogic; +import org.stringtemplate.v4.ST; + +/** + * Test CLI code generation. + */ +public class CodeGeneratorCliEditorTest { + + private SupportKeyInfoGetter kig; + private File outFile = null; + + @Test + public void test() throws IOException { + final CodeGeneratorCliEditor codeGen = new CodeGeneratorCliEditor(); + + outFile = File.createTempFile("ApexTestGenerated", ".apex"); + + ApexModelReader modelReader = null; + try { + modelReader = new ApexModelReader<>(AxPolicyModel.class); + } catch (ApexModelException e1) { + fail("test should not throw an exception"); + } + modelReader.setValidateFlag(false); + AxPolicyModel apexPolicyModel = null; + try { + apexPolicyModel = modelReader + .read(new FileInputStream(new File("src/test/resources/models/TestPolicyModel.json"))); + } catch (ApexModelException | FileNotFoundException e) { + fail("test should not throw an exception"); + } + + assertEquals(0, generateCli(codeGen, apexPolicyModel)); + } + + /** + * Generate the CLI from the model. + * + * @param codeGen the code generator + * @param policyModel the policy model + * @throws IOException on generation exceptions + */ + private int generateCli(final CodeGeneratorCliEditor codeGen, final AxPolicyModel policyModel) throws IOException { + kig = new SupportKeyInfoGetter(policyModel); + + // Order is important. 0: model, 1: context schemas, 2: tasks, 3: events, 4: ContextAlbums, 5: Policies + // 0: model + final AxArtifactKey pmkey = policyModel.getKey(); + codeGen.addModelParams(kig.getName(pmkey), kig.getVersion(pmkey), kig.getUuid(pmkey), kig.getDesc(pmkey)); + + // 1: Context Schemas + for (final AxContextSchema s : policyModel.getSchemas().getSchemasMap().values()) { + final AxArtifactKey key = s.getKey(); + + codeGen.addSchemaDeclaration(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key), + s.getSchemaFlavour(), s.getSchema()); + } + + // 2: tasks + for (final AxTask t : policyModel.getTasks().getTaskMap().values()) { + final AxArtifactKey key = t.getKey(); + final List infields = getInfieldsForTask(codeGen, t); + final List outfields = getOutfieldsForTask(codeGen, t); + final ST logic = getLogicForTask(codeGen, t); + final List parameters = getParametersForTask(codeGen, t); + final List contextRefs = getCtxtRefsForTask(codeGen, t); + + codeGen.addTaskDeclaration(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key), + infields, outfields, logic, parameters, contextRefs); + } + + // 3: events + for (final AxEvent e : policyModel.getEvents().getEventMap().values()) { + final AxArtifactKey key = e.getKey(); + final List fields = getParametersForEvent(codeGen, e); + + codeGen.addEventDeclaration( + new EventDeclarationBuilder() + .setName(kig.getName(key)) + .setVersion(kig.getVersion(key)) + .setUuid(kig.getUuid(key)) + .setDescription(kig.getDesc(key)) + .setNameSpace(e.getNameSpace()) + .setSource(e.getSource()) + .setTarget(e.getTarget()) + .setFields(fields)); + } + + // 4: context albums + for (final AxContextAlbum a : policyModel.getAlbums().getAlbumsMap().values()) { + final AxArtifactKey key = a.getKey(); + + codeGen.addContextAlbumDeclaration( + new CodeGenCliEditorBuilder() + .setName(kig.getName(key)) + .setVersion(kig.getVersion(key)) + .setUuid(kig.getUuid(key)) + .setDescription(kig.getDesc(key)) + .setScope(a.getScope()) + .setWritable(a.isWritable()) + .setSchemaName(kig.getName(a.getItemSchema())) + .setSchemaVersion(kig.getVersion(a.getItemSchema()))); + } + + // 5: policies + for (final AxPolicy p : policyModel.getPolicies().getPolicyMap().values()) { + final AxArtifactKey key = p.getKey(); + final List states = getStatesForPolicy(codeGen, p); + codeGen.addPolicyDefinition(kig.getName(key), kig.getVersion(key), kig.getUuid(key), kig.getDesc(key), + p.getTemplate(), p.getFirstState(), states); + } + + final String out = codeGen.getModel().render(); + + FileWriter outFileWriter = new FileWriter(outFile); + outFileWriter.write(out); + outFileWriter.close(); + + return 0; + } + + /** + * Gets the parameters for event. + * + * @param cg the code generator + * @param event the event + * @return the parameters for event + */ + private List getParametersForEvent(final CodeGeneratorCliEditor cg, final AxEvent event) { + final Collection fields = event.getFields(); + final List ret = new ArrayList<>(fields.size()); + for (final AxField f : fields) { + 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()); + + ret.add(val); + } + return ret; + } + + /** + * Gets the context references for task. + * + * @param cg the code generator + * @param task the task + * @return the context references for task + */ + private List getCtxtRefsForTask(final CodeGeneratorCliEditor cg, final AxTask task) { + final Collection ctxs = task.getContextAlbumReferences(); + final List ret = new ArrayList<>(ctxs.size()); + final AxArtifactKey tkey = task.getKey(); + for (final AxArtifactKey ckey : ctxs) { + + final ST val = cg.createTaskDefinitionContextRef(kig.getName(tkey), kig.getVersion(tkey), kig.getName(ckey), + kig.getVersion(ckey)); + + ret.add(val); + } + return ret; + } + + /** + * Gets the parameters for task. + * + * @param cg the code generator + * @param task the task + * @return the parameters for task + */ + private List getParametersForTask(final CodeGeneratorCliEditor cg, final AxTask task) { + final Collection pars = task.getTaskParameters().values(); + final List ret = new ArrayList<>(pars.size()); + for (final AxTaskParameter p : pars) { + final AxReferenceKey pkey = p.getKey(); + + final ST val = cg.createTaskDefinitionParameters(kig.getPName(pkey), kig.getPVersion(pkey), + kig.getLName(pkey), p.getTaskParameterValue()); + + ret.add(val); + } + return ret; + } + + /** + * Gets the logic for task. + * + * @param cg the code generator + * @param task the task + * @return the logic for task + */ + private ST getLogicForTask(final CodeGeneratorCliEditor cg, final AxTask task) { + final AxArtifactKey tkey = task.getKey(); + final AxTaskLogic tl = task.getTaskLogic(); + + return cg.createTaskDefLogic(kig.getName(tkey), kig.getVersion(tkey), tl.getLogicFlavour(), tl.getLogic()); + } + + /** + * Gets the output fields for task. + * + * @param cg the code generator + * @param task the task + * @return the output fields for task + */ + private List getOutfieldsForTask(final CodeGeneratorCliEditor cg, final AxTask task) { + final Collection fields = task.getOutputFields().values(); + final List ret = new ArrayList<>(fields.size()); + for (final AxField f : fields) { + final AxReferenceKey fkey = f.getKey(); + + final ST val = cg.createTaskDefinitionOutfields(kig.getPName(fkey), kig.getPVersion(fkey), + kig.getLName(fkey), kig.getName(f.getSchema()), kig.getVersion(f.getSchema())); + + ret.add(val); + } + return ret; + } + + /** + * Gets the input fields for task. + * + * @param cg the code generator + * @param task the task + * @return the input fields for task + */ + private List getInfieldsForTask(final CodeGeneratorCliEditor cg, final AxTask task) { + final Collection fields = task.getInputFields().values(); + final List ret = new ArrayList<>(fields.size()); + for (final AxField f : fields) { + final AxReferenceKey fkey = f.getKey(); + + final ST val = cg.createTaskDefinitionInfields(kig.getPName(fkey), kig.getPVersion(fkey), + kig.getLName(fkey), kig.getName(f.getSchema()), kig.getVersion(f.getSchema())); + + ret.add(val); + } + return ret; + } + + /** + * Gets the states for policy. + * + * @param cg the code generator + * @param pol the policy + * @return the states for policy + */ + private List getStatesForPolicy(final CodeGeneratorCliEditor cg, final AxPolicy pol) { + final Collection states = pol.getStateMap().values(); + final List ret = new ArrayList<>(states.size()); + for (final AxState st : states) { + final AxReferenceKey skey = st.getKey(); + final List outputs = getStateOutputsForState(cg, st); + final List finalizerLogics = getFinalizersForState(cg, st); + final List tasks = getTaskRefsForState(cg, st); + final List tsLogic = getTslForState(cg, st); + final List ctxRefs = getCtxtRefsForState(cg, st); + + final ST val = cg.createPolicyStateDef(kig.getPName(skey), kig.getPVersion(skey), kig.getLName(skey), + kig.getName(st.getTrigger()), kig.getVersion(st.getTrigger()), + kig.getName(st.getDefaultTask()), kig.getVersion(st.getDefaultTask()), outputs, tasks, + tsLogic, finalizerLogics, ctxRefs); + + ret.add(val); + } + return ret; + } + + /** + * Gets the finalizers for state. + * + * @param cg the code generator + * @param st the state + * @return the finalizers for state + */ + private List getFinalizersForState(final CodeGeneratorCliEditor cg, final AxState st) { + final Collection fins = st.getStateFinalizerLogicMap().values(); + final List ret = new ArrayList<>(fins.size()); + final AxReferenceKey skey = st.getKey(); + for (final AxStateFinalizerLogic fin : fins) { + 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()); + + ret.add(val); + } + return ret; + } + + /** + * Gets the context references for state. + * + * @param cg the code generator + * @param st the state + * @return the context references for state + */ + private List getCtxtRefsForState(final CodeGeneratorCliEditor cg, final AxState st) { + final Collection ctxs = st.getContextAlbumReferences(); + final List ret = new ArrayList<>(ctxs.size()); + final AxReferenceKey skey = st.getKey(); + 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)); + + ret.add(val); + } + return ret; + } + + /** + * Gets the Task Selection Logic for state. + * + * @param cg the code generator + * @param st the state + * @return the TSL for state (if any) in a list + */ + private List getTslForState(final CodeGeneratorCliEditor cg, final AxState st) { + final AxReferenceKey skey = st.getKey(); + 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()); + return Collections.singletonList(val); + } else { + return Collections.emptyList(); + } + } + + /** + * Gets the task references for state. + * + * @param cg the code generator + * @param st the state + * @return the task references for state + */ + private List getTaskRefsForState(final CodeGeneratorCliEditor cg, final AxState st) { + final Map taskrefs = st.getTaskReferences(); + final List ret = new ArrayList<>(taskrefs.size()); + final AxReferenceKey skey = st.getKey(); + for (final Entry e : taskrefs.entrySet()) { + final AxArtifactKey tkey = e.getKey(); + final AxStateTaskReference tr = e.getValue(); + final AxReferenceKey trkey = tr.getKey(); + + final ST val = cg.createPolicyStateTask(kig.getPName(skey), kig.getPVersion(skey), kig.getLName(skey), + kig.getLName(trkey), kig.getName(tkey), kig.getVersion(tkey), + tr.getStateTaskOutputType().name(), kig.getLName(tr.getOutput())); + + ret.add(val); + } + return ret; + } + + /** + * Gets the state outputs for state. + * + * @param cg the code generator + * @param st the state + * @return the state outputs for state + */ + private List getStateOutputsForState(final CodeGeneratorCliEditor cg, final AxState st) { + final Collection outs = st.getStateOutputs().values(); + final List ret = new ArrayList<>(outs.size()); + final AxReferenceKey skey = st.getKey(); + for (final AxStateOutput out : outs) { + final AxReferenceKey outkey = out.getKey(); + + final ST val = cg.createPolicyStateOutput(kig.getPName(skey), kig.getPVersion(skey), kig.getLName(skey), + kig.getLName(outkey), kig.getName(out.getOutgingEvent()), + kig.getVersion(out.getOutgingEvent()), kig.getLName(out.getNextState())); + + ret.add(val); + } + return ret; + } + +} 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 new file mode 100644 index 000000000..33387accc --- /dev/null +++ b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/DummyStErrorListener.java @@ -0,0 +1,111 @@ +/*- + * ============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 org.stringtemplate.v4.STErrorListener; +import org.stringtemplate.v4.misc.STMessage; + +/** + * Customized ST error listener. + * + * @author Sven van der Meer (sven.van.der.meer@ericsson.com) + */ +public class DummyStErrorListener implements STErrorListener { + + /** Counts errors of the listener. */ + private int errorCount; + + /* (non-Javadoc) + * @see org.stringtemplate.v4.STErrorListener#IOError(org.stringtemplate.v4.misc.STMessage) + */ + @Override + public void IOError(final STMessage msg) { + switch (msg.error) { + default: + this.registerErrors(msg); + } + } + + /* (non-Javadoc) + * @see org.stringtemplate.v4.STErrorListener#compileTimeError(org.stringtemplate.v4.misc.STMessage) + */ + @Override + public void compileTimeError(final STMessage msg) { + switch (msg.error) { + default: + this.registerErrors(msg); + } + } + + /* (non-Javadoc) + * @see org.stringtemplate.v4.STErrorListener#internalError(org.stringtemplate.v4.misc.STMessage) + */ + @Override + public void internalError(final STMessage msg) { + switch (msg.error) { + default: + this.registerErrors(msg); + } + } + + /* (non-Javadoc) + * @see org.stringtemplate.v4.STErrorListener#runTimeError(org.stringtemplate.v4.misc.STMessage) + */ + @Override + public void runTimeError(final STMessage msg) { + switch (msg.error) { + case NO_SUCH_PROPERTY: + case ARGUMENT_COUNT_MISMATCH: + case ANON_ARGUMENT_MISMATCH: + break; + default: + this.registerErrors(msg); + } + } + + /** + * Registers an error with the local error listener and increases the error count. + * + * @param msg error message + */ + protected void registerErrors(final STMessage msg) { + setErrorCount(getErrorCount() + 1); + System.err.println("STG/ST (" + msg.error + ") " + msg.arg + " -> " + msg.cause); + } + + /** + * Gets the error count. + * + * @return the error count + */ + protected int getErrorCount() { + return errorCount; + } + + /** + * Sets the error count. + * + * @param errorCount the new error count + */ + protected void setErrorCount(final int errorCount) { + this.errorCount = errorCount; + } +} diff --git a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/GenerationTest.java b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/GenerationTest.java deleted file mode 100644 index 3b79e805c..000000000 --- a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/GenerationTest.java +++ /dev/null @@ -1,138 +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.onap.policy.apex.auth.clicodegen.CodeGeneratorCliEditor; -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 GenerationTest { - - /** - * 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 StErrorListener errListener = new StErrorListener(); - 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 StErrorListener errListener = new StErrorListener(); - 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/KeyInfoGetter.java b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/KeyInfoGetter.java deleted file mode 100644 index 97d05679c..000000000 --- a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/KeyInfoGetter.java +++ /dev/null @@ -1,159 +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 org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; -import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; - -/** - * Getter methods for policy keys. - * - * @author John Keeney (john.keeney@ericsson.com) - */ - -public class KeyInfoGetter { - - /** The policy model for the getters. */ - private final AxPolicyModel model; - - /** - * Creates a new key getter. - * - * @param model the policy model to use - */ - public KeyInfoGetter(final AxPolicyModel model) { - this.model = model; - } - - /** - * Returns the key name as string. - * - * @param key the key to transform - * @return key name as string, null if key was null - */ - public String getName(final AxArtifactKey key) { - if (key == null) { - return null; - } - return key.getName(); - } - - /** - * Returns the version of an artifact key. - * - * @param key the key to extract version from - * @return version of the key, null if key was null - */ - public String getVersion(final AxArtifactKey key) { - if (key == null) { - return null; - } - return key.getVersion(); - } - - /** - * Returns the parent name for the key. - * - * @param key the key to process - * @return parent name, null if key was null - */ - public String getPName(final AxReferenceKey key) { - if (key == null) { - return null; - } - return key.getParentKeyName(); - } - - /** - * Returns the parent version for the key. - * - * @param key the key to process - * @return parent version, null if key was null - */ - public String getPVersion(final AxReferenceKey key) { - if (key == null) { - return null; - } - return key.getParentKeyVersion(); - } - - /** - * Returns the local name for the key. - * - * @param key the key to process - * @return local name, null if key was null - */ - public String getLName(final AxReferenceKey key) { - if (key == null) { - return null; - } - return key.getLocalName(); - } - - /** - * Returns the local name of the parent for the key. - * - * @param key the key to process - * @return local name of the parent, null if key was null - */ - public String getPlName(final AxReferenceKey key) { - if (key == null) { - return null; - } - return key.getParentLocalName(); - } - - /** - * Returns the UUID of an artifact key. - * - * @param key the key to extract version from - * @return UUID of the key, null if key was null - */ - public String getUuid(final AxArtifactKey key) { - if (key == null) { - return null; - } - final AxKeyInfo ki = model.getKeyInformation().get(key); - if (ki == null || ki.getUuid() == null) { - return null; - } - return ki.getUuid().toString(); - } - - /** - * Returns the description of an artifact key. - * - * @param key the key to extract version from - * @return description of the key, null if key was null - */ - public String getDesc(final AxArtifactKey key) { - if (key == null) { - return null; - } - final AxKeyInfo ki = model.getKeyInformation().get(key); - if (ki == null || ki.getDescription() == null) { - return null; - } - return ki.getDescription(); - } -} diff --git a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/StErrorListener.java b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/StErrorListener.java deleted file mode 100644 index 28e32bca6..000000000 --- a/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/StErrorListener.java +++ /dev/null @@ -1,111 +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 org.stringtemplate.v4.STErrorListener; -import org.stringtemplate.v4.misc.STMessage; - -/** - * Customized ST error listener. - * - * @author Sven van der Meer (sven.van.der.meer@ericsson.com) - */ -public class StErrorListener implements STErrorListener { - - /** Counts errors of the listener. */ - private int errorCount; - - /* (non-Javadoc) - * @see org.stringtemplate.v4.STErrorListener#IOError(org.stringtemplate.v4.misc.STMessage) - */ - @Override - public void IOError(final STMessage msg) { - switch (msg.error) { - default: - this.registerErrors(msg); - } - } - - /* (non-Javadoc) - * @see org.stringtemplate.v4.STErrorListener#compileTimeError(org.stringtemplate.v4.misc.STMessage) - */ - @Override - public void compileTimeError(final STMessage msg) { - switch (msg.error) { - default: - this.registerErrors(msg); - } - } - - /* (non-Javadoc) - * @see org.stringtemplate.v4.STErrorListener#internalError(org.stringtemplate.v4.misc.STMessage) - */ - @Override - public void internalError(final STMessage msg) { - switch (msg.error) { - default: - this.registerErrors(msg); - } - } - - /* (non-Javadoc) - * @see org.stringtemplate.v4.STErrorListener#runTimeError(org.stringtemplate.v4.misc.STMessage) - */ - @Override - public void runTimeError(final STMessage msg) { - switch (msg.error) { - case NO_SUCH_PROPERTY: - case ARGUMENT_COUNT_MISMATCH: - case ANON_ARGUMENT_MISMATCH: - break; - default: - this.registerErrors(msg); - } - } - - /** - * Registers an error with the local error listener and increases the error count. - * - * @param msg error message - */ - protected void registerErrors(final STMessage msg) { - setErrorCount(getErrorCount() + 1); - System.err.println("STG/ST (" + msg.error + ") " + msg.arg + " -> " + msg.cause); - } - - /** - * Gets the error count. - * - * @return the error count - */ - protected int getErrorCount() { - return errorCount; - } - - /** - * Sets the error count. - * - * @param errorCount the new error count - */ - protected void setErrorCount(final int errorCount) { - this.errorCount = errorCount; - } -} 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 new file mode 100644 index 000000000..9d91f8f68 --- /dev/null +++ b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportGenerationTester.java @@ -0,0 +1,138 @@ +/*- + * ============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.onap.policy.apex.auth.clicodegen.CodeGeneratorCliEditor; +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-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 new file mode 100644 index 000000000..5547aa4f7 --- /dev/null +++ b/auth/cli-codegen/src/test/java/org/onap/policy/apex/auth/clicodegen/SupportKeyInfoGetter.java @@ -0,0 +1,159 @@ +/*- + * ============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 org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo; +import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; +import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; + +/** + * Getter methods for policy keys. + * + * @author John Keeney (john.keeney@ericsson.com) + */ + +public class SupportKeyInfoGetter { + + /** The policy model for the getters. */ + private final AxPolicyModel model; + + /** + * Creates a new key getter. + * + * @param model the policy model to use + */ + public SupportKeyInfoGetter(final AxPolicyModel model) { + this.model = model; + } + + /** + * Returns the key name as string. + * + * @param key the key to transform + * @return key name as string, null if key was null + */ + public String getName(final AxArtifactKey key) { + if (key == null) { + return null; + } + return key.getName(); + } + + /** + * Returns the version of an artifact key. + * + * @param key the key to extract version from + * @return version of the key, null if key was null + */ + public String getVersion(final AxArtifactKey key) { + if (key == null) { + return null; + } + return key.getVersion(); + } + + /** + * Returns the parent name for the key. + * + * @param key the key to process + * @return parent name, null if key was null + */ + public String getPName(final AxReferenceKey key) { + if (key == null) { + return null; + } + return key.getParentKeyName(); + } + + /** + * Returns the parent version for the key. + * + * @param key the key to process + * @return parent version, null if key was null + */ + public String getPVersion(final AxReferenceKey key) { + if (key == null) { + return null; + } + return key.getParentKeyVersion(); + } + + /** + * Returns the local name for the key. + * + * @param key the key to process + * @return local name, null if key was null + */ + public String getLName(final AxReferenceKey key) { + if (key == null) { + return null; + } + return key.getLocalName(); + } + + /** + * Returns the local name of the parent for the key. + * + * @param key the key to process + * @return local name of the parent, null if key was null + */ + public String getPlName(final AxReferenceKey key) { + if (key == null) { + return null; + } + return key.getParentLocalName(); + } + + /** + * Returns the UUID of an artifact key. + * + * @param key the key to extract version from + * @return UUID of the key, null if key was null + */ + public String getUuid(final AxArtifactKey key) { + if (key == null) { + return null; + } + final AxKeyInfo ki = model.getKeyInformation().get(key); + if (ki == null || ki.getUuid() == null) { + return null; + } + return ki.getUuid().toString(); + } + + /** + * Returns the description of an artifact key. + * + * @param key the key to extract version from + * @return description of the key, null if key was null + */ + public String getDesc(final AxArtifactKey key) { + if (key == null) { + return null; + } + final AxKeyInfo ki = model.getKeyInformation().get(key); + if (ki == null || ki.getDescription() == null) { + return null; + } + return ki.getDescription(); + } +} diff --git a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/BeanFake.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/BeanFake.java deleted file mode 100644 index 958f1a6cd..000000000 --- a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/BeanFake.java +++ /dev/null @@ -1,49 +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.client.editor.rest.handling.bean; - -import javax.xml.bind.annotation.XmlType; - -/** - * The Event Bean. - */ -@XmlType -public class BeanFake extends BeanBase { - private String name = null; - private String version = null; - private String field1 = null; - private int field2 = 0; - private int field3 = 0; - - public String getName() { - field1 = name; - return field1; - } - - public String getVersion() { - return version; - } - - public int getField2() { - field3 = field2; - return field3; - } -} diff --git a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/BeansTest.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/BeansTest.java index 2cae7703d..ba773b1ac 100644 --- a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/BeansTest.java +++ b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/BeansTest.java @@ -56,7 +56,7 @@ public class BeansTest { final BeanEvent beanEvent = new BeanEvent(); assertNull(beanEvent.get("name")); - final BeanFake beanFake = new BeanFake(); + final DummyBeanBase beanFake = new DummyBeanBase(); assertNull(beanFake.get("name")); assertNull(beanFake.get("field1")); diff --git a/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/DummyBeanBase.java b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/DummyBeanBase.java new file mode 100644 index 000000000..25a10e269 --- /dev/null +++ b/client/client-editor/src/test/java/org/onap/policy/apex/client/editor/rest/handling/bean/DummyBeanBase.java @@ -0,0 +1,49 @@ +/*- + * ============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.client.editor.rest.handling.bean; + +import javax.xml.bind.annotation.XmlType; + +/** + * The Event Bean. + */ +@XmlType +public class DummyBeanBase extends BeanBase { + private String name = null; + private String version = null; + private String field1 = null; + private int field2 = 0; + private int field3 = 0; + + public String getName() { + field1 = name; + return field1; + } + + public String getVersion() { + return version; + } + + public int getField2() { + field3 = field2; + return field3; + } +} diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/BadJsonAdapter.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/BadJsonAdapter.java deleted file mode 100644 index fef69ac33..000000000 --- a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/BadJsonAdapter.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 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.context.impl.schema.java; - -import com.google.gson.Gson; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import java.lang.reflect.Type; - -/** - * This class serialises and deserialises various type of event protocol parameters to and from - * JSON. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class BadJsonAdapter - implements JsonSerializer, JsonDeserializer { - - public BadJsonAdapter() throws IllegalAccessException { - throw new IllegalAccessException("Test for Bad Adapter"); - } - - /** - * {@inheritDoc} - */ - @Override - public JsonElement serialize(final String src, final Type typeOfSrc, - final JsonSerializationContext context) { - return new Gson().toJsonTree(src, String.class); - } - - /** - * {@inheritDoc} - */ - @Override - public String deserialize(final JsonElement json, final Type typeOfT, - final JsonDeserializationContext context) { - - return new Gson().fromJson(json, String.class); - } -} diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParametersTest.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParametersTest.java index c0287bfe2..8735c922a 100644 --- a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParametersTest.java +++ b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperParametersTest.java @@ -62,15 +62,15 @@ public class JavaSchemaHelperParametersTest { assertFalse(pars.validate().isValid()); jsonPars.setAdaptedClass("java.lang.String"); - jsonPars.setAdaptorClass("org.onap.policy.apex.context.impl.schema.java.TestJsonDeserializer"); + jsonPars.setAdaptorClass("org.onap.policy.apex.context.impl.schema.java.SupportJsonDeserializer"); assertFalse(pars.validate().isValid()); jsonPars.setAdaptedClass("java.lang.String"); - jsonPars.setAdaptorClass("org.onap.policy.apex.context.impl.schema.java.TestJsonSerializer"); + jsonPars.setAdaptorClass("org.onap.policy.apex.context.impl.schema.java.SupportJsonSerializer"); assertFalse(pars.validate().isValid()); jsonPars.setAdaptedClass("java.lang.String"); - jsonPars.setAdaptorClass("org.onap.policy.apex.context.impl.schema.java.TestJsonAdapter"); + jsonPars.setAdaptorClass("org.onap.policy.apex.context.impl.schema.java.SupportJsonAdapter"); assertTrue(pars.validate().isValid()); Map adapterMap = new LinkedHashMap<>(); diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperTest.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperTest.java index c746198e7..16976f268 100644 --- a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperTest.java +++ b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/JavaSchemaHelperTest.java @@ -52,7 +52,7 @@ public class JavaSchemaHelperTest { JavaSchemaHelperJsonAdapterParameters stringAdapterPars = new JavaSchemaHelperJsonAdapterParameters(); stringAdapterPars.setAdaptedClass("java.lang.String"); - stringAdapterPars.setAdaptorClass("org.onap.policy.apex.context.impl.schema.java.TestJsonAdapter"); + stringAdapterPars.setAdaptorClass("org.onap.policy.apex.context.impl.schema.java.SupportJsonAdapter"); javaSchemaHelperPars.getJsonAdapters().put("String", stringAdapterPars); @@ -212,7 +212,7 @@ public class JavaSchemaHelperTest { stringSchemaHelper.init(userKey, stringSchema); AxContextSchema myBaseClassSchema = new AxContextSchema(schemaKey, "Java", - "org.onap.policy.apex.context.impl.schema.java.MyBaseClass"); + "org.onap.policy.apex.context.impl.schema.java.SupportBaseClass"); SchemaHelper myBaseClassSchemaHelper = new JavaSchemaHelper(); myBaseClassSchemaHelper.init(userKey, myBaseClassSchema); @@ -315,7 +315,7 @@ public class JavaSchemaHelperTest { assertEquals("123", stringSchemaHelper.unmarshal(123)); - MySubClass subClassInstance = new MySubClass("123"); + SupportSubClass subClassInstance = new SupportSubClass("123"); assertEquals(subClassInstance, myBaseClassSchemaHelper.unmarshal(subClassInstance)); } @@ -375,7 +375,7 @@ public class JavaSchemaHelperTest { JavaSchemaHelperParameters javaShPars = (JavaSchemaHelperParameters) pars.getSchemaHelperParameterMap() .get("Java"); javaShPars.getJsonAdapters().get("String") - .setAdaptorClass("org.onap.policy.apex.context.impl.schema.java.BadJsonAdapter"); + .setAdaptorClass("org.onap.policy.apex.context.impl.schema.java.SupportBadJsonAdapter"); AxContextSchema stringSchema = new AxContextSchema(schemaKey, "Java", "java.lang.String"); SchemaHelper stringSchemaHelper = new JavaSchemaHelper(); @@ -386,7 +386,7 @@ public class JavaSchemaHelperTest { fail("test should throw an exception"); } catch (ContextRuntimeException pre) { assertEquals("UserKey:0.0.1: instantiation of adapter class " - + "\"org.onap.policy.apex.context.impl.schema.java.BadJsonAdapter\" " + + "\"org.onap.policy.apex.context.impl.schema.java.SupportBadJsonAdapter\" " + "to decode and encode class \"java.lang.String\" failed: Test for Bad Adapter", pre.getMessage()); } diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/MyBaseClass.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/MyBaseClass.java deleted file mode 100644 index 6dd6e2527..000000000 --- a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/MyBaseClass.java +++ /dev/null @@ -1,33 +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.context.impl.schema.java; - -public class MyBaseClass { - final String stringField; - - public MyBaseClass(final String stringField) { - this.stringField = stringField; - } - - public String getStringField() { - return stringField; - } -} diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/MySubClass.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/MySubClass.java deleted file mode 100644 index f68bcf4dc..000000000 --- a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/MySubClass.java +++ /dev/null @@ -1,27 +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.context.impl.schema.java; - -public class MySubClass extends MyBaseClass { - public MySubClass(String stringField) { - super(stringField); - } -} diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportBadJsonAdapter.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportBadJsonAdapter.java new file mode 100644 index 000000000..e45eb9aa3 --- /dev/null +++ b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportBadJsonAdapter.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.context.impl.schema.java; + +import com.google.gson.Gson; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +/** + * This class serialises and deserialises various type of event protocol parameters to and from + * JSON. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class SupportBadJsonAdapter + implements JsonSerializer, JsonDeserializer { + + public SupportBadJsonAdapter() throws IllegalAccessException { + throw new IllegalAccessException("Test for Bad Adapter"); + } + + /** + * {@inheritDoc} + */ + @Override + public JsonElement serialize(final String src, final Type typeOfSrc, + final JsonSerializationContext context) { + return new Gson().toJsonTree(src, String.class); + } + + /** + * {@inheritDoc} + */ + @Override + public String deserialize(final JsonElement json, final Type typeOfT, + final JsonDeserializationContext context) { + + return new Gson().fromJson(json, String.class); + } +} diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportBaseClass.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportBaseClass.java new file mode 100644 index 000000000..004737559 --- /dev/null +++ b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportBaseClass.java @@ -0,0 +1,33 @@ +/*- + * ============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.context.impl.schema.java; + +public class SupportBaseClass { + final String stringField; + + public SupportBaseClass(final String stringField) { + this.stringField = stringField; + } + + public String getStringField() { + return stringField; + } +} diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportJsonAdapter.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportJsonAdapter.java new file mode 100644 index 000000000..5c26beaee --- /dev/null +++ b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportJsonAdapter.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.context.impl.schema.java; + +import com.google.gson.Gson; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +/** + * This class serialises and deserialises various type of event protocol parameters to and from JSON. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class SupportJsonAdapter implements JsonSerializer, JsonDeserializer { + + /** + * {@inheritDoc} + */ + @Override + public JsonElement serialize(final String src, final Type typeOfSrc, final JsonSerializationContext context) { + return new Gson().toJsonTree(src, String.class); + } + + /** + * {@inheritDoc} + */ + @Override + public String deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) { + + return new Gson().fromJson(json, String.class); + } +} diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportJsonDeserializer.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportJsonDeserializer.java new file mode 100644 index 000000000..be279bf52 --- /dev/null +++ b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportJsonDeserializer.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.context.impl.schema.java; + +import com.google.gson.Gson; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; + +import java.lang.reflect.Type; + +/** + * This class serialises and deserialises various type of event protocol parameters to and from JSON. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class SupportJsonDeserializer implements JsonDeserializer { + /** + * {@inheritDoc} + */ + @Override + public String deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) { + + return new Gson().fromJson(json, String.class); + } +} diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportJsonSerializer.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportJsonSerializer.java new file mode 100644 index 000000000..1fcb858ab --- /dev/null +++ b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportJsonSerializer.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 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.context.impl.schema.java; + +import com.google.gson.JsonElement; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +import org.onap.policy.common.parameters.ParameterRuntimeException; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +/** + * This class serialises and deserialises various type of event protocol parameters to and from JSON. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class SupportJsonSerializer implements JsonSerializer { + private static final XLogger LOGGER = XLoggerFactory.getXLogger(SupportJsonSerializer.class); + + /** + * {@inheritDoc} + */ + @Override + public JsonElement serialize(final String src, final Type typeOfSrc, final JsonSerializationContext context) { + final String returnMessage = "serialization of Apex event protocol parameters to Json is not supported"; + LOGGER.error(returnMessage); + throw new ParameterRuntimeException(returnMessage); + } +} diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportSubClass.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportSubClass.java new file mode 100644 index 000000000..260f4eb8c --- /dev/null +++ b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/SupportSubClass.java @@ -0,0 +1,27 @@ +/*- + * ============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.context.impl.schema.java; + +public class SupportSubClass extends SupportBaseClass { + public SupportSubClass(String stringField) { + super(stringField); + } +} diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/TestJsonAdapter.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/TestJsonAdapter.java deleted file mode 100644 index 89dfb4c2d..000000000 --- a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/TestJsonAdapter.java +++ /dev/null @@ -1,55 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 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.context.impl.schema.java; - -import com.google.gson.Gson; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import java.lang.reflect.Type; - -/** - * This class serialises and deserialises various type of event protocol parameters to and from JSON. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestJsonAdapter implements JsonSerializer, JsonDeserializer { - - /** - * {@inheritDoc} - */ - @Override - public JsonElement serialize(final String src, final Type typeOfSrc, final JsonSerializationContext context) { - return new Gson().toJsonTree(src, String.class); - } - - /** - * {@inheritDoc} - */ - @Override - public String deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) { - - return new Gson().fromJson(json, String.class); - } -} diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/TestJsonDeserializer.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/TestJsonDeserializer.java deleted file mode 100644 index 463945872..000000000 --- a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/TestJsonDeserializer.java +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 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.context.impl.schema.java; - -import com.google.gson.Gson; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; - -import java.lang.reflect.Type; - -/** - * This class serialises and deserialises various type of event protocol parameters to and from JSON. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestJsonDeserializer implements JsonDeserializer { - /** - * {@inheritDoc} - */ - @Override - public String deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) { - - return new Gson().fromJson(json, String.class); - } -} diff --git a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/TestJsonSerializer.java b/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/TestJsonSerializer.java deleted file mode 100644 index d58be6069..000000000 --- a/context/context-management/src/test/java/org/onap/policy/apex/context/impl/schema/java/TestJsonSerializer.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 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.context.impl.schema.java; - -import com.google.gson.JsonElement; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import java.lang.reflect.Type; - -import org.onap.policy.common.parameters.ParameterRuntimeException; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -/** - * This class serialises and deserialises various type of event protocol parameters to and from JSON. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestJsonSerializer implements JsonSerializer { - private static final XLogger LOGGER = XLoggerFactory.getXLogger(TestJsonSerializer.class); - - /** - * {@inheritDoc} - */ - @Override - public JsonElement serialize(final String src, final Type typeOfSrc, final JsonSerializationContext context) { - final String returnMessage = "serialization of Apex event protocol parameters to Json is not supported"; - LOGGER.error(returnMessage); - throw new ParameterRuntimeException(returnMessage); - } -} -- cgit 1.2.3-korg