From 59b90519eda3b95b0cfc49b6349a591c7d0c78e2 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Mon, 7 Feb 2022 17:56:44 +0000 Subject: 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 --- .../apex/model/policymodel/concepts/PoliciesTest.java | 13 ++++++------- .../policy/apex/model/policymodel/concepts/StateTest.java | 10 ++++++---- .../policy/apex/model/policymodel/concepts/TasksTest.java | 11 ++++++----- .../model/policymodel/handling/ApexPolicyModelTest.java | 5 ----- 4 files changed, 18 insertions(+), 21 deletions(-) (limited to 'model/policy-model/src/test') diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PoliciesTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PoliciesTest.java index e724a4663..526f5a628 100644 --- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PoliciesTest.java +++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/PoliciesTest.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. @@ -190,9 +190,9 @@ public class PoliciesTest { final AxState clonedState = new AxState(policyPN.getStateMap().get("state")); clonedState.getKey().setLocalName("ClonedState"); - clonedState.afterUnmarshal(null, null); savedStateMap.put(clonedState.getKey().getLocalName(), clonedState); + policyPN.buildReferences(); result = new AxValidationResult(); result = policyPN.validate(result); assertEquals(ValidationResult.WARNING, result.getValidationResult()); @@ -213,7 +213,9 @@ public class PoliciesTest { assertEquals(policyPN, policyPN); // NOSONAR assertEquals(policyPN, clonedPolicy); assertNotNull(policyPN); - assertNotEquals(policyPN, (Object) "Hello"); + + Object helloObj = "Hello"; + assertNotEquals(policyPN, helloObj); assertNotEquals(policyPN, new AxPolicy(AxArtifactKey.getNullKey(), savedTemplate, savedStateMap, savedFirstState)); assertNotEquals(policyPN, new AxPolicy(savedPolicyKey, "SomeTemplate", savedStateMap, savedFirstState)); @@ -287,7 +289,6 @@ public class PoliciesTest { assertEquals(ValidationResult.VALID, result.getValidationResult()); policies.clean(); - policies.afterUnmarshal(null, null); final AxPolicies clonedPolicies = new AxPolicies(policies); assertEquals("AxPolicies:(key=AxArtifactKey:(name=PoliciesKey,version=0.0.", @@ -298,7 +299,7 @@ public class PoliciesTest { assertEquals(policies, policies); // NOSONAR assertEquals(policies, clonedPolicies); assertNotNull(policies); - assertNotEquals(policies, (Object) "Hello"); + assertNotEquals(policyPN, helloObj); assertNotEquals(policies, new AxPolicies(new AxArtifactKey())); assertEquals(0, policies.compareTo(policies)); @@ -324,7 +325,6 @@ public class PoliciesTest { final AxState secondState = new AxState(policyPN.getStateMap().get("state")); secondState.getKey().setLocalName("SecondState"); - secondState.afterUnmarshal(null, null); policyPN.getStateMap().put("SecondState", secondState); policyPN.getStateMap().get("state").getStateOutputs().get("stateOutput0").setNextState(secondState.getKey()); @@ -344,7 +344,6 @@ public class PoliciesTest { final AxState thirdState = new AxState(policyPN.getStateMap().get("state")); thirdState.getKey().setLocalName("ThirdState"); - thirdState.afterUnmarshal(null, null); policyPN.getStateMap().put("ThirdState", thirdState); policyPN.getStateMap().get("SecondState").getStateOutputs().get("stateOutput0") .setNextState(thirdState.getKey()); diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTest.java index 95a91325a..7fbe78078 100644 --- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTest.java +++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/StateTest.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. @@ -147,10 +147,10 @@ public class StateTest { state.setTaskReferences(trMap); assertEquals(trMap, state.getTaskReferences()); - state.afterUnmarshal(null, null); + state.buildReferences(); assertEquals(state.getKey(), state.getKeys().get(0)); state.getTaskSelectionLogic().getKey().setLocalName(AxKey.NULL_KEY_NAME); - state.afterUnmarshal(null, null); + state.buildReferences(); assertEquals(state.getKey(), state.getKeys().get(0)); final Set stateSet = state.getNextStateSet(); @@ -387,7 +387,9 @@ public class StateTest { assertEquals(state, state); // NOSONAR assertEquals(state, clonedState); assertNotNull(state); - assertNotEquals(state, (Object) "Hello"); + + Object helloObj = "Hello"; + assertNotEquals(state, helloObj); assertNotEquals(state, new AxState(new AxStateParamsBuilder().key(new AxReferenceKey()).trigger(triggerKey) .stateOutputs(soMap).contextAlbumReferenceSet(ctxtSet).taskSelectionLogic(tsl) .stateFinalizerLogicMap(sflMap).defaultTask(defTaskKey).taskReferenceMap(trMap))); diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TasksTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TasksTest.java index 89dc9a048..9c7866c85 100644 --- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TasksTest.java +++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/concepts/TasksTest.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. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -85,7 +85,7 @@ public class TasksTest { assertEquals("TaskName:0.0.1", task.getKey().getId()); assertEquals("TaskName:0.0.1", task.getKeys().get(0).getId()); - task.afterUnmarshal(null, null); + task.buildReferences(); assertEquals(1, task.getTaskParameters().size()); AxValidationResult result = new AxValidationResult(); @@ -154,7 +154,9 @@ public class TasksTest { assertEquals(task, task); // NOSONAR assertEquals(task, clonedTask); assertNotNull(task); - assertNotEquals(task, (Object) "Hello"); + + Object helloObj = "Hello"; + assertNotEquals(task, helloObj); assertNotEquals(task, new AxTask(new AxArtifactKey(), tpMap, ctxtSet, tl)); assertEquals(task, new AxTask(taskKey, tpMap, ctxtSet, tl)); assertNotEquals(task, new AxTask(taskKey, tpEmptyMap, ctxtSet, tl)); @@ -224,7 +226,6 @@ public class TasksTest { assertEquals(ValidationResult.VALID, result.getValidationResult()); tasks.clean(); - tasks.afterUnmarshal(null, null); final AxTasks clonedTasks = new AxTasks(tasks); assertEquals("AxTasks:(key=AxArtifactKey:(name=TasksKey,version=0.0.1),tas", @@ -236,7 +237,7 @@ public class TasksTest { assertEquals(tasks, tasks); // NOSONAR assertEquals(tasks, clonedTasks); assertNotNull(tasks); - assertNotEquals(tasks, (Object) "Hello"); + assertNotEquals(tasks, helloObj); assertNotEquals(tasks, new AxTasks(new AxArtifactKey())); assertEquals(0, tasks.compareTo(tasks)); diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/ApexPolicyModelTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/ApexPolicyModelTest.java index a2a997e8d..48e4f87f9 100644 --- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/ApexPolicyModelTest.java +++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/ApexPolicyModelTest.java @@ -131,11 +131,6 @@ public class ApexPolicyModelTest { assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString()); } - @Test - public void testModelWriteReadXml() throws Exception { - testApexModel.testApexModelWriteReadXml(); - } - @Test public void testModelWriteReadJson() throws Exception { testApexModel.testApexModelWriteReadJson(); -- cgit 1.2.3-korg