diff options
author | liamfallon <liam.fallon@est.tech> | 2022-02-07 17:56:44 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2022-02-08 18:39:03 +0000 |
commit | 59b90519eda3b95b0cfc49b6349a591c7d0c78e2 (patch) | |
tree | 810e07f7d5cf270582264c40245372f597c713a2 /auth/cli-editor/src/test/java | |
parent | def44b294fa00bb5470e977eef9a05e5087035f0 (diff) |
Remove JAXB and XML, use GSON for JSON
This review converst apex-pdp to use GSON for JSON handling. In order to
preserve backward compatibility with the JAXB format of JSON, custom
handling of maps was required. Therefore, the policy-common
StandardCoder could not be used.
There are a lot of small changes, removing annotations from concepts and
tweaking of test data. However, this cleans up the code base so it is
worth doing.
Issue-ID: POLICY-1820
Change-Id: I213fa64f6d7f3f1df8d10f111d9fbedbe80f9fe0
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'auth/cli-editor/src/test/java')
7 files changed, 28 insertions, 23 deletions
diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java index 509a57cf8..e49422996 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorOptionsTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2020,2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -67,7 +67,7 @@ public class CommandLineEditorOptionsTest { final int modelCharCount = modelString.replaceAll("\\s+", "").length(); assertEquals(1204, logCharCount); - assertEquals(2561, modelCharCount); + assertEquals(2904, modelCharCount); tempLogFile.delete(); tempModelFile.delete(); @@ -126,7 +126,6 @@ public class CommandLineEditorOptionsTest { final String logString = TextFileUtils.getTextFileAsString(tempLogFile.getCanonicalPath()); final String modelString = TextFileUtils.getTextFileAsString(tempModelFile.getCanonicalPath()); - System.err.println(modelString); // As a sanity check, count the number of non white space characters in log and model files final int logCharCount = logString.replaceAll("\\s+", "").length(); final int modelCharCount = modelString.replaceAll("\\s+", "").length(); @@ -164,7 +163,7 @@ public class CommandLineEditorOptionsTest { final int modelCharCount = modelString.replaceAll("\\s+", "").length(); assertEquals(0, logCharCount); - assertEquals(2561, modelCharCount); + assertEquals(2904, modelCharCount); tempLogFile.delete(); tempModelFile.delete(); @@ -249,7 +248,7 @@ public class CommandLineEditorOptionsTest { final int tempModelFileInCharCount = tempModelFileInString.replaceAll("\\s+", "").length(); assertEquals(1204, tempLogFileInCharCount); - assertEquals(2561, tempModelFileInCharCount); + assertEquals(2904, tempModelFileInCharCount); final String[] cliArgsOut = new String[] {"-i", tempModelFileIn.getAbsolutePath(), "-c", "src/main/resources/examples/scripts/ShellPolicyModelAddSchema.apex", "-l", @@ -267,7 +266,7 @@ public class CommandLineEditorOptionsTest { final int tempModelFileOutCharCount = tempModelFileOutString.replaceAll("\\s+", "").length(); assertEquals(1154, tempLogFileOutCharCount); - assertEquals(2993, tempModelFileOutCharCount); + assertEquals(3336, tempModelFileOutCharCount); tempLogFileIn.delete(); tempModelFileIn.delete(); diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java index b41cd49b2..75a880a4f 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/CommandLineEditorScriptingTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. + * Modifications Copyright (C) 2019-2020,2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,9 +30,11 @@ import java.net.URL; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelStringWriter; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; import org.onap.policy.common.utils.resources.ResourceUtils; @@ -61,10 +63,10 @@ public class CommandLineEditorScriptingTest { tempLogFile = File.createTempFile("SampleLBPolicyMap", ".log"); samplePolicyArgs = new String[] {"-c", "src/test/resources/scripts/SampleLBPolicy.apex", "-o", - tempModelFile.getAbsolutePath(), "-l", tempLogFile.getAbsolutePath()}; + tempModelFile.getAbsolutePath(), "-l", tempLogFile.getAbsolutePath()}; samplePolicyMapArgs = new String[] {"-c", "src/test/resources/scripts/SampleLBPolicy_WithMap.apex", "-o", - tempModelFile.getAbsolutePath(), "-l", tempLogFile.getAbsolutePath()}; + tempModelFile.getAbsolutePath(), "-l", tempLogFile.getAbsolutePath()}; } /** @@ -79,7 +81,7 @@ public class CommandLineEditorScriptingTest { /** * Test sample FLB policy script. * - * @throws IOException Signals that an I/O exception has occurred. + * @throws IOException Signals that an I/O exception has occurred. * @throws ApexModelException if there is an Apex error */ @Test @@ -94,7 +96,7 @@ public class CommandLineEditorScriptingTest { final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream()); final URL compareModelUrl = - ResourceUtils.getLocalFile("src/test/resources/compare/FLBPolicyModel_Compare.json"); + ResourceUtils.getLocalFile("src/test/resources/compare/FLBPolicyModel_Compare.json"); final AxPolicyModel compareModel = modelReader.read(compareModelUrl.openStream()); final URL compareModelNoAlbumsUrl = @@ -114,7 +116,7 @@ public class CommandLineEditorScriptingTest { /** * Test sample FLB map policy script. * - * @throws IOException Signals that an I/O exception has occurred. + * @throws IOException Signals that an I/O exception has occurred. * @throws ApexModelException if there is an Apex error */ @Test diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.java index db44bbb9a..ab9b900af 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/ContextAlbumsTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020,2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -77,7 +77,7 @@ public class ContextAlbumsTest { // Read the file from disk final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class); - modelReader.setValidateFlag(false); + modelReader.setValidate(false); final URL writtenModelUrl = ResourceUtils.getLocalFile(tempModelFile.getCanonicalPath()); final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream()); diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.java index 7acf2ab89..9896ab9ee 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/FileMacroTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020,2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -81,7 +81,7 @@ public class FileMacroTest { // Read the file from disk final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class); - modelReader.setValidateFlag(false); + modelReader.setValidate(false); final URL writtenModelUrl = ResourceUtils.getLocalFile(tempModelFile.getCanonicalPath()); final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream()); diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.java index 702013945..31e75e579 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/LogicBlockTest.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. + * Modifications Copyright (C) 2020,2022 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,7 @@ import org.junit.Before; import org.junit.Test; import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelStringWriter; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; import org.onap.policy.common.utils.resources.ResourceUtils; @@ -83,7 +84,7 @@ public class LogicBlockTest { // Read the file from disk final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class); - modelReader.setValidateFlag(false); + modelReader.setValidate(false); final URL writtenModelUrl = ResourceUtils.getLocalFile(tempLogicModelFile.getCanonicalPath()); final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream()); @@ -111,7 +112,7 @@ public class LogicBlockTest { // Read the file from disk final ApexModelReader<AxPolicyModel> modelReader = new ApexModelReader<>(AxPolicyModel.class); - modelReader.setValidateFlag(false); + modelReader.setValidate(false); final URL writtenModelUrl = ResourceUtils.getLocalFile(tempAvroModelFile.getCanonicalPath()); final AxPolicyModel writtenModel = modelReader.read(writtenModelUrl.openStream()); diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java index 9ac046381..b75199ac3 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/tosca/ApexCliToscaEditorTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019,2022 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -84,9 +84,12 @@ public class ApexCliToscaEditorTest { @Test public void testApexCliTosca_success() throws IOException { final ApexCliToscaEditorMain cliEditor = new ApexCliToscaEditorMain(sampleArgs); + + String outputTosca = TextFileUtils.getTextFileAsString(tempOutputToscaFile.getAbsolutePath()); String outputToscaCompare = - TextFileUtils.getTextFileAsString("src/test/resources/tosca/ToscaPolicyOutput_compare.json").trim(); + TextFileUtils.getTextFileAsString("src/test/resources/tosca/ToscaPolicyOutput_compare_2.json").trim(); + assertEquals(outputToscaCompare, outputTosca); assertFalse(cliEditor.isFailure()); } diff --git a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java index 371efd7d2..2ce34e148 100644 --- a/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java +++ b/auth/cli-editor/src/test/java/org/onap/policy/apex/auth/clieditor/utils/CliUtilsTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019,2022 Nordix Foundation. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -82,7 +82,7 @@ public class CliUtilsTest { CliUtils.createToscaServiceTemplate(params, policyModelFilePath); String outputTosca = TextFileUtils.getTextFileAsString(tempOutputToscaFile.getAbsolutePath()); String outputToscaCompare = - TextFileUtils.getTextFileAsString("src/test/resources/tosca/ToscaPolicyOutput_compare.json").trim(); + TextFileUtils.getTextFileAsString("src/test/resources/tosca/ToscaPolicyOutput_compare_1.json").trim(); assertEquals(outputToscaCompare, outputTosca); } |