From 1418e7fcc3bba8980e1877c6576983583877ec1e Mon Sep 17 00:00:00 2001 From: lapentafd Date: Wed, 2 Jun 2021 12:02:46 +0100 Subject: Fix Sonar Issues in apex-pdp-model Changes made into model/basic-model Renamed test classes to match the others Issue-ID: POLICY-3093 Change-Id: I7a0d6046ead42a9165aaf96b89511dd8d064d109 Signed-off-by: lapentafd --- .../model/basicmodel/concepts/AxKeyInfoTest.java | 17 +- .../SupportApexBasicModelConceptsTest.java | 294 +++++++++++++++++++++ .../SupportApexBasicModelConceptsTester.java | 279 ------------------- .../handling/SupportApexBasicModelTest.java | 131 +++++++++ .../handling/SupportApexBasicModelTester.java | 131 --------- .../basicmodel/handling/SupportBasicModelTest.java | 115 ++++++++ .../handling/SupportBasicModelTester.java | 115 -------- .../handling/SupportConceptGetterTest.java | 217 +++++++++++++++ .../handling/SupportConceptGetterTester.java | 200 -------------- 9 files changed, 773 insertions(+), 726 deletions(-) create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTester.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTester.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTester.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTester.java (limited to 'model/basic-model/src/test/java') diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java index 5a57ba3a6..ff7adcd26 100644 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019 Nordix-2020 Foundation. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -70,6 +70,21 @@ public class AxKeyInfoTest { assertEquals(0, testKeyInfo.compareTo(testKeyInfo)); assertEquals(0, testKeyInfo.compareTo(clonedReferenceKey)); + + + } + + @Test + public void testAxKeyValidation() { + AxKeyInfo testKeyInfo = new AxKeyInfo(); + + AxArtifactKey key = new AxArtifactKey("key", "0.0.1"); + testKeyInfo.setKey(key); + + UUID uuid = UUID.randomUUID(); + testKeyInfo.setUuid(uuid); + testKeyInfo.setDescription("Key Description"); + assertNotEquals(0, testKeyInfo.compareTo(null)); assertNotEquals(0, testKeyInfo.compareTo(new AxArtifactKey())); assertNotEquals(0, testKeyInfo.compareTo(new AxKeyInfo(new AxArtifactKey()))); diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTest.java new file mode 100644 index 000000000..905a27f38 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTest.java @@ -0,0 +1,294 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2019-2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.handling; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.List; +import java.util.Set; +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo; +import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation; +import org.onap.policy.apex.model.basicmodel.concepts.AxKeyUse; +import org.onap.policy.apex.model.basicmodel.concepts.AxModel; +import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; +import org.onap.policy.apex.model.basicmodel.service.ModelService; +import org.onap.policy.apex.model.basicmodel.test.TestApexModel; + +public class SupportApexBasicModelConceptsTest { + TestApexModel testApexModel; + + @Before + public void setup() throws Exception { + testApexModel = new TestApexModel(AxModel.class, new DummyApexBasicModelCreator()); + } + + @Test + public void testModelConcepts() { + final AxModel model = testApexModel.getModel(); + assertNotNull(model); + model.clean(); + assertNotNull(model); + + AxValidationResult result = new AxValidationResult(); + result = model.validate(result); + assertEquals(ValidationResult.WARNING, result.getValidationResult()); + + model.register(); + assertEquals(model.getKeyInformation(), ModelService.getModel(AxKeyInformation.class)); + + final AxModel clonedModel = new AxModel(model); + assertTrue(clonedModel.toString().startsWith("AxModel:(key=AxArtifactKey:(name=BasicModel")); + + assertNotEquals(0, model.hashCode()); + + // disabling sonar because this code tests the equals() method + assertEquals(model, model); // NOSONAR + assertEquals(model, clonedModel); + assertNotNull(model); + assertNotEquals(model, (Object) "Hello"); + clonedModel.getKey().setVersion("0.0.2"); + assertNotEquals(model, clonedModel); + clonedModel.getKey().setVersion("0.0.1"); + + assertEquals(0, model.compareTo(model)); + assertNotEquals(0, model.compareTo(null)); + assertNotEquals(0, model.compareTo(new AxReferenceKey())); + assertEquals(0, model.compareTo(clonedModel)); + clonedModel.getKey().setVersion("0.0.2"); + assertNotEquals(0, model.compareTo(clonedModel)); + clonedModel.getKey().setVersion("0.0.1"); + + assertNotNull(model.getKeys()); + + model.getKeyInformation().generateKeyInfo(model); + assertNotNull(model.getKeyInformation()); + + } + + @Test + public void testKeyInformation() { + + final AxModel model = testApexModel.getModel(); + final AxKeyInformation keyI = model.getKeyInformation(); + final AxKeyInformation clonedKeyI = new AxKeyInformation(keyI); + + assertNotNull(keyI); + assertNotEquals(keyI, (Object) new AxArtifactKey()); + assertEquals(keyI, clonedKeyI); + + clonedKeyI.setKey(new AxArtifactKey()); + assertNotEquals(keyI, clonedKeyI); + clonedKeyI.setKey(keyI.getKey()); + + assertEquals(0, keyI.compareTo(keyI)); + assertEquals(0, keyI.compareTo(clonedKeyI)); + assertNotEquals(0, keyI.compareTo(null)); + assertNotEquals(0, keyI.compareTo(new AxArtifactKey())); + + clonedKeyI.setKey(new AxArtifactKey()); + assertNotEquals(0, keyI.compareTo(clonedKeyI)); + clonedKeyI.setKey(keyI.getKey()); + assertEquals(0, keyI.compareTo(clonedKeyI)); + + clonedKeyI.getKeyInfoMap().clear(); + assertNotEquals(0, keyI.compareTo(clonedKeyI)); + + AxKeyInfo keyInfo = keyI.get("BasicModel"); + assertNotNull(keyInfo); + + keyInfo = keyI.get(new AxArtifactKey("BasicModel", "0.0.1")); + assertNotNull(keyInfo); + + Set keyInfoSet = keyI.getAll("BasicModel"); + assertNotNull(keyInfoSet); + + keyInfoSet = keyI.getAll("BasicModel", "0..0.1"); + assertNotNull(keyInfoSet); + + List keys = model.getKeys(); + assertNotEquals(0, keys.size()); + + keys = keyI.getKeys(); + assertNotEquals(0, keys.size()); + + model.getKeyInformation().generateKeyInfo(model); + assertNotNull(model.getKeyInformation()); + model.getKeyInformation().getKeyInfoMap().clear(); + model.getKeyInformation().generateKeyInfo(model); + assertNotNull(model.getKeyInformation()); + } + + @Test + public void testClonedKey() { + final AxModel model = testApexModel.getModel(); + final AxKeyInformation keyI = model.getKeyInformation(); + final AxKeyInformation clonedKeyI = new AxKeyInformation(keyI); + AxValidationResult result = new AxValidationResult(); + + clonedKeyI.setKey(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + clonedKeyI.setKey(keyI.getKey()); + + clonedKeyI.getKeyInfoMap().clear(); + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + clonedKeyI.generateKeyInfo(model); + + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + clonedKeyI.getKeyInfoMap().put(AxArtifactKey.getNullKey(), null); + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + clonedKeyI.getKeyInfoMap().clear(); + clonedKeyI.generateKeyInfo(model); + + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + clonedKeyI.getKeyInfoMap().put(new AxArtifactKey("SomeKey", "0.0.1"), null); + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + clonedKeyI.getKeyInfoMap().clear(); + clonedKeyI.generateKeyInfo(model); + + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + final AxKeyInfo mk = clonedKeyI.get(new AxArtifactKey("BasicModel", "0.0.1")); + assertNotNull(mk); + mk.setKey(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + clonedKeyI.getKeyInfoMap().clear(); + clonedKeyI.generateKeyInfo(model); + + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + final AxModel clonedModel = new AxModel(model); + clonedModel.setKey(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = clonedModel.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + clonedModel.setKey(model.getKey()); + result = new AxValidationResult(); + result = clonedKeyI.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + } + + @Test + public void testModelConceptsWithReferences() { + final DummyAxModelWithReferences mwr = new DummyApexBasicModelCreator().getModelWithReferences(); + assertNotNull(mwr); + mwr.getKeyInformation().getKeyInfoMap().clear(); + mwr.getKeyInformation().generateKeyInfo(mwr); + + AxValidationResult result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + // Duplicate key error + mwr.addKey(mwr.getKey()); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + mwr.removeKey(mwr.getKey()); + + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + // Null Reference Key + mwr.addKey(AxReferenceKey.getNullKey()); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + mwr.removeKey(AxReferenceKey.getNullKey()); + + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + // Duplicate Reference Key + final AxReferenceKey rKey = new AxReferenceKey(mwr.getKey(), "LocalName"); + mwr.addKey(rKey); + mwr.addKey(rKey); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + mwr.removeKey(rKey); + mwr.removeKey(rKey); + + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + // Key Use is legal + final AxKeyUse keyU = new AxKeyUse(mwr.getKey()); + mwr.addKey(keyU); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + mwr.removeKey(keyU); + + // Key Use on bad artifact key + final AxKeyUse keyBadUsage = new AxKeyUse(new AxArtifactKey("SomeKey", "0.0.1")); + mwr.addKey(keyBadUsage); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + mwr.removeKey(keyBadUsage); + + // Key Use on bad reference key + final AxKeyUse keyBadReferenceUsage = new AxKeyUse(new AxReferenceKey("SomeKey", "0.0.1", "Local")); + mwr.addKey(keyBadReferenceUsage); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + mwr.removeKey(keyBadReferenceUsage); + + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTester.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTester.java deleted file mode 100644 index 8ce072c68..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTester.java +++ /dev/null @@ -1,279 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2019-2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.List; -import java.util.Set; -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyUse; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; -import org.onap.policy.apex.model.basicmodel.service.ModelService; -import org.onap.policy.apex.model.basicmodel.test.TestApexModel; - -public class SupportApexBasicModelConceptsTester { - TestApexModel testApexModel; - - @Before - public void setup() throws Exception { - testApexModel = new TestApexModel(AxModel.class, new DummyApexBasicModelCreator()); - } - - @Test - public void testModelConcepts() { - final AxModel model = testApexModel.getModel(); - assertNotNull(model); - model.clean(); - assertNotNull(model); - - AxValidationResult result = new AxValidationResult(); - result = model.validate(result); - assertEquals(ValidationResult.WARNING, result.getValidationResult()); - - model.register(); - assertEquals(model.getKeyInformation(), ModelService.getModel(AxKeyInformation.class)); - - final AxModel clonedModel = new AxModel(model); - assertTrue(clonedModel.toString().startsWith("AxModel:(key=AxArtifactKey:(name=BasicModel")); - - assertNotEquals(0, model.hashCode()); - - // disabling sonar because this code tests the equals() method - assertEquals(model, model); // NOSONAR - assertEquals(model, clonedModel); - assertNotNull(model); - assertNotEquals(model, (Object) "Hello"); - clonedModel.getKey().setVersion("0.0.2"); - assertNotEquals(model, clonedModel); - clonedModel.getKey().setVersion("0.0.1"); - - assertEquals(0, model.compareTo(model)); - assertNotEquals(0, model.compareTo(null)); - assertNotEquals(0, model.compareTo(new AxReferenceKey())); - assertEquals(0, model.compareTo(clonedModel)); - clonedModel.getKey().setVersion("0.0.2"); - assertNotEquals(0, model.compareTo(clonedModel)); - clonedModel.getKey().setVersion("0.0.1"); - - assertNotNull(model.getKeys()); - - model.getKeyInformation().generateKeyInfo(model); - assertNotNull(model.getKeyInformation()); - - final AxKeyInformation keyI = model.getKeyInformation(); - final AxKeyInformation clonedKeyI = new AxKeyInformation(keyI); - - assertNotNull(keyI); - assertNotEquals(keyI, (Object) new AxArtifactKey()); - assertEquals(keyI, clonedKeyI); - - clonedKeyI.setKey(new AxArtifactKey()); - assertNotEquals(keyI, clonedKeyI); - clonedKeyI.setKey(keyI.getKey()); - - assertEquals(0, keyI.compareTo(keyI)); - assertEquals(0, keyI.compareTo(clonedKeyI)); - assertNotEquals(0, keyI.compareTo(null)); - assertNotEquals(0, keyI.compareTo(new AxArtifactKey())); - - clonedKeyI.setKey(new AxArtifactKey()); - assertNotEquals(0, keyI.compareTo(clonedKeyI)); - clonedKeyI.setKey(keyI.getKey()); - assertEquals(0, keyI.compareTo(clonedKeyI)); - - clonedKeyI.getKeyInfoMap().clear(); - assertNotEquals(0, keyI.compareTo(clonedKeyI)); - - AxKeyInfo keyInfo = keyI.get("BasicModel"); - assertNotNull(keyInfo); - - keyInfo = keyI.get(new AxArtifactKey("BasicModel", "0.0.1")); - assertNotNull(keyInfo); - - Set keyInfoSet = keyI.getAll("BasicModel"); - assertNotNull(keyInfoSet); - - keyInfoSet = keyI.getAll("BasicModel", "0..0.1"); - assertNotNull(keyInfoSet); - - List keys = model.getKeys(); - assertNotEquals(0, keys.size()); - - keys = keyI.getKeys(); - assertNotEquals(0, keys.size()); - - model.getKeyInformation().generateKeyInfo(model); - assertNotNull(model.getKeyInformation()); - model.getKeyInformation().getKeyInfoMap().clear(); - model.getKeyInformation().generateKeyInfo(model); - assertNotNull(model.getKeyInformation()); - - clonedKeyI.setKey(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - clonedKeyI.setKey(keyI.getKey()); - - clonedKeyI.getKeyInfoMap().clear(); - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - clonedKeyI.generateKeyInfo(model); - - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - clonedKeyI.getKeyInfoMap().put(AxArtifactKey.getNullKey(), null); - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - clonedKeyI.getKeyInfoMap().clear(); - clonedKeyI.generateKeyInfo(model); - - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - clonedKeyI.getKeyInfoMap().put(new AxArtifactKey("SomeKey", "0.0.1"), null); - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - clonedKeyI.getKeyInfoMap().clear(); - clonedKeyI.generateKeyInfo(model); - - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - final AxKeyInfo mk = clonedKeyI.get(new AxArtifactKey("BasicModel", "0.0.1")); - assertNotNull(mk); - mk.setKey(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - clonedKeyI.getKeyInfoMap().clear(); - clonedKeyI.generateKeyInfo(model); - - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - clonedModel.setKey(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = clonedModel.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - clonedModel.setKey(model.getKey()); - result = new AxValidationResult(); - result = clonedKeyI.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - } - - @Test - public void testModelConceptsWithReferences() { - final DummyAxModelWithReferences mwr = new DummyApexBasicModelCreator().getModelWithReferences(); - assertNotNull(mwr); - mwr.getKeyInformation().getKeyInfoMap().clear(); - mwr.getKeyInformation().generateKeyInfo(mwr); - - AxValidationResult result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - // Duplicate key error - mwr.addKey(mwr.getKey()); - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - mwr.removeKey(mwr.getKey()); - - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - // Null Reference Key - mwr.addKey(AxReferenceKey.getNullKey()); - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - mwr.removeKey(AxReferenceKey.getNullKey()); - - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - // Duplicate Reference Key - final AxReferenceKey rKey = new AxReferenceKey(mwr.getKey(), "LocalName"); - mwr.addKey(rKey); - mwr.addKey(rKey); - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - mwr.removeKey(rKey); - mwr.removeKey(rKey); - - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - // Key Use is legal - final AxKeyUse keyU = new AxKeyUse(mwr.getKey()); - mwr.addKey(keyU); - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - mwr.removeKey(keyU); - - // Key Use on bad artifact key - final AxKeyUse keyBadUsage = new AxKeyUse(new AxArtifactKey("SomeKey", "0.0.1")); - mwr.addKey(keyBadUsage); - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - mwr.removeKey(keyBadUsage); - - // Key Use on bad reference key - final AxKeyUse keyBadReferenceUsage = new AxKeyUse(new AxReferenceKey("SomeKey", "0.0.1", "Local")); - mwr.addKey(keyBadReferenceUsage); - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - mwr.removeKey(keyBadReferenceUsage); - - result = new AxValidationResult(); - result = mwr.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java new file mode 100644 index 000000000..1c21b6c33 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTest.java @@ -0,0 +1,131 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020-2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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.model.basicmodel.handling; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxModel; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; +import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; +import org.onap.policy.apex.model.basicmodel.test.TestApexModel; + +public class SupportApexBasicModelTest { + TestApexModel testApexModel; + + /** + * Set up the test. + * + * @throws Exception any exception thrown by the test + */ + @Before + public void setup() throws Exception { + testApexModel = new TestApexModel(AxModel.class, new DummyApexBasicModelCreator()); + } + + @Test + public void testModelValid() throws Exception { + final AxValidationResult result = testApexModel.testApexModelValid(); + assertEquals(VALID_MODEL_STRING, result.toString()); + } + + @Test + public void testApexModelVaidateObservation() throws Exception { + assertThatThrownBy(testApexModel::testApexModelVaidateObservation) + .hasMessage("model should have observations"); + } + + @Test + public void testApexModelVaidateWarning() throws Exception { + final AxValidationResult result = testApexModel.testApexModelVaidateWarning(); + assertEquals(WARNING_MODEL_STRING, result.toString()); + } + + @Test + public void testModelVaidateInvalidModel() throws Exception { + final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel(); + assertEquals(INVALID_MODEL_STRING, result.toString()); + } + + @Test + public void testModelVaidateMalstructured() throws Exception { + final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured(); + assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString()); + } + + @Test + public void testModelWriteReadXml() throws Exception { + testApexModel.testApexModelWriteReadXml(); + } + + @Test + public void testModelWriteReadJson() throws Exception { + testApexModel.testApexModelWriteReadJson(); + } + + @Test + public void testModelWriteReadJpa() throws Exception { + final DaoParameters daoParameters = new DaoParameters(); + daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao"); + daoParameters.setPersistenceUnit("DaoTest"); + + testApexModel.testApexModelWriteReadJpa(daoParameters); + } + + // As there are no real concepts in a basic model, this is as near to a valid model as we can get + private static final String VALID_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n" + + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" + + ".AxModel:WARNING:key not found for key information entry\n" + + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" + + ".AxModel:WARNING:key not found for key information entry\n" + "********************************"; + + private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n" + + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" + + ".AxModel:WARNING:key not found for key information entry\n" + + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" + + ".AxModel:WARNING:key not found for key information entry\n" + + "AxArtifactKey:(name=Unref0,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" + + ".AxModel:WARNING:key not found for key information entry\n" + + "AxArtifactKey:(name=Unref1,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" + + ".AxModel:WARNING:key not found for key information entry\n" + "********************************"; + + private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n" + + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." + + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n" + + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." + + "AxKeyInfo:OBSERVATION:description is blank\n" + + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." + + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n" + + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." + + "AxKeyInformation:INVALID:duplicate UUID found on keyInfoMap entry AxArtifactKey:" + + "(name=KeyInfoMapKey,version=0.0.1):00000000-0000-0000-0000-000000000000\n" + + "********************************"; + + private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n" + + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." + + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n" + + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." + + "AxModel:INVALID:key information not found for key " + + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n" + "********************************"; +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTester.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTester.java deleted file mode 100644 index 064a107e7..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTester.java +++ /dev/null @@ -1,131 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; - -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; -import org.onap.policy.apex.model.basicmodel.test.TestApexModel; - -public class SupportApexBasicModelTester { - TestApexModel testApexModel; - - /** - * Set up the test. - * - * @throws Exception any exception thrown by the test - */ - @Before - public void setup() throws Exception { - testApexModel = new TestApexModel(AxModel.class, new DummyApexBasicModelCreator()); - } - - @Test - public void testModelValid() throws Exception { - final AxValidationResult result = testApexModel.testApexModelValid(); - assertEquals(VALID_MODEL_STRING, result.toString()); - } - - @Test - public void testApexModelVaidateObservation() throws Exception { - assertThatThrownBy(testApexModel::testApexModelVaidateObservation) - .hasMessage("model should have observations"); - } - - @Test - public void testApexModelVaidateWarning() throws Exception { - final AxValidationResult result = testApexModel.testApexModelVaidateWarning(); - assertEquals(WARNING_MODEL_STRING, result.toString()); - } - - @Test - public void testModelVaidateInvalidModel() throws Exception { - final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel(); - assertEquals(INVALID_MODEL_STRING, result.toString()); - } - - @Test - public void testModelVaidateMalstructured() throws Exception { - final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured(); - assertEquals(INVALID_MODEL_MALSTRUCTURED_STRING, result.toString()); - } - - @Test - public void testModelWriteReadXml() throws Exception { - testApexModel.testApexModelWriteReadXml(); - } - - @Test - public void testModelWriteReadJson() throws Exception { - testApexModel.testApexModelWriteReadJson(); - } - - @Test - public void testModelWriteReadJpa() throws Exception { - final DaoParameters daoParameters = new DaoParameters(); - daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao"); - daoParameters.setPersistenceUnit("DaoTest"); - - testApexModel.testApexModelWriteReadJpa(daoParameters); - } - - // As there are no real concepts in a basic model, this is as near to a valid model as we can get - private static final String VALID_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n" - + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" - + ".AxModel:WARNING:key not found for key information entry\n" - + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" - + ".AxModel:WARNING:key not found for key information entry\n" + "********************************"; - - private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n" - + "AxArtifactKey:(name=FloatKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" - + ".AxModel:WARNING:key not found for key information entry\n" - + "AxArtifactKey:(name=IntegerKIKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" - + ".AxModel:WARNING:key not found for key information entry\n" - + "AxArtifactKey:(name=Unref0,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" - + ".AxModel:WARNING:key not found for key information entry\n" - + "AxArtifactKey:(name=Unref1,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts" - + ".AxModel:WARNING:key not found for key information entry\n" + "********************************"; - - private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n" - + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." - + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n" - + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." - + "AxKeyInfo:OBSERVATION:description is blank\n" - + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." - + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n" - + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." - + "AxKeyInformation:INVALID:duplicate UUID found on keyInfoMap entry AxArtifactKey:" - + "(name=KeyInfoMapKey,version=0.0.1):00000000-0000-0000-0000-000000000000\n" - + "********************************"; - - private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n" - + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." - + "AxKeyInfo:WARNING:UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n" - + "AxArtifactKey:(name=BasicModelKey,version=0.0.1):org.onap.policy.apex.model.basicmodel.concepts." - + "AxModel:INVALID:key information not found for key " - + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n" + "********************************"; -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java new file mode 100644 index 000000000..5fc678ac0 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTest.java @@ -0,0 +1,115 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020-2021 Nordix Foundation + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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.model.basicmodel.handling; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.concepts.AxModel; +import org.onap.policy.apex.model.basicmodel.test.TestApexModel; + +public class SupportBasicModelTest { + + @Test + public void testNormalModelCreator() throws ApexException { + final TestApexModel testApexModel = new TestApexModel(AxModel.class, + new DummyApexBasicModelCreator()); + + testApexModel.testApexModelValid(); + assertThatThrownBy(testApexModel::testApexModelVaidateObservation) + .hasMessage("model should have observations"); + testApexModel.testApexModelVaidateWarning(); + testApexModel.testApexModelVaidateInvalidModel(); + testApexModel.testApexModelVaidateMalstructured(); + + testApexModel.testApexModelWriteReadJson(); + testApexModel.testApexModelWriteReadXml(); + } + + @Test + public void testModelsUnequal() throws ApexException { + final TestApexModel testApexModel0 = new TestApexModel(AxModel.class, + new DummyApexBasicModelCreator()); + final TestApexModel testApexModel1 = new TestApexModel(AxModel.class, + new DummyApexBasicModelCreator()); + + testApexModel1.getModel().getKey().setVersion("0.0.2"); + + assertThatThrownBy(() -> testApexModel0.checkModelEquality(testApexModel0.getModel(), testApexModel1.getModel(), + "Models are not equal")).hasMessage("Models are not equal"); + } + + @Test + public void testModelCreator0() throws ApexException { + final TestApexModel testApexModel = new TestApexModel(AxModel.class, + new SupportApexModelCreator0()); + + testApexModel.testApexModelValid(); + assertThatThrownBy(() -> testApexModel.testApexModelVaidateObservation()) + .hasMessage("model should have observations"); + assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning()) + .hasMessage("model should have warnings"); + assertThatThrownBy(() -> testApexModel.testApexModelVaidateInvalidModel()) + .hasMessage("model should not be valid ***validation of model successful***"); + assertThatThrownBy(() -> testApexModel.testApexModelVaidateMalstructured()) + .hasMessage("model should not be valid ***validation of model successful***"); + } + + @Test + public void testModelCreator1() throws ApexException { + final TestApexModel testApexModel = new TestApexModel(AxModel.class, + new SupportApexModelCreator1()); + + assertThatThrownBy(() -> testApexModel.testApexModelValid()) + .hasMessageStartingWith("model is invalid"); + assertThatThrownBy(() -> testApexModel.testApexModelVaidateObservation()) + .hasMessageStartingWith("model is invalid"); + assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning()) + .hasMessageStartingWith("model is invalid"); + testApexModel.testApexModelVaidateInvalidModel(); + testApexModel.testApexModelVaidateMalstructured(); + } + + @Test + public void testModelCreator2() throws ApexException { + final TestApexModel testApexModel = new TestApexModel(AxModel.class, + new SupportApexModelCreator2()); + + testApexModel.testApexModelValid(); + testApexModel.testApexModelVaidateObservation(); + assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning()) + .hasMessage("model should have warnings"); + } + + @Test + public void testModelCreator1XmlJson() throws ApexException { + final TestApexModel testApexModel = new TestApexModel(AxModel.class, + new SupportApexModelCreator1()); + + assertThatThrownBy(() -> testApexModel.testApexModelWriteReadJson()) + .hasMessageStartingWith("error processing file"); + + assertThatThrownBy(() -> testApexModel.testApexModelWriteReadXml()) + .hasMessageStartingWith("error processing file"); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTester.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTester.java deleted file mode 100644 index 2761d86da..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTester.java +++ /dev/null @@ -1,115 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.apex.model.basicmodel.test.TestApexModel; - -public class SupportBasicModelTester { - - @Test - public void testNormalModelCreator() throws ApexException { - final TestApexModel testApexModel = new TestApexModel(AxModel.class, - new DummyApexBasicModelCreator()); - - testApexModel.testApexModelValid(); - assertThatThrownBy(testApexModel::testApexModelVaidateObservation) - .hasMessage("model should have observations"); - testApexModel.testApexModelVaidateWarning(); - testApexModel.testApexModelVaidateInvalidModel(); - testApexModel.testApexModelVaidateMalstructured(); - - testApexModel.testApexModelWriteReadJson(); - testApexModel.testApexModelWriteReadXml(); - } - - @Test - public void testModelsUnequal() throws ApexException { - final TestApexModel testApexModel0 = new TestApexModel(AxModel.class, - new DummyApexBasicModelCreator()); - final TestApexModel testApexModel1 = new TestApexModel(AxModel.class, - new DummyApexBasicModelCreator()); - - testApexModel1.getModel().getKey().setVersion("0.0.2"); - - assertThatThrownBy(() -> testApexModel0.checkModelEquality(testApexModel0.getModel(), testApexModel1.getModel(), - "Models are not equal")).hasMessage("Models are not equal"); - } - - @Test - public void testModelCreator0() throws ApexException { - final TestApexModel testApexModel = new TestApexModel(AxModel.class, - new SupportApexModelCreator0()); - - testApexModel.testApexModelValid(); - assertThatThrownBy(() -> testApexModel.testApexModelVaidateObservation()) - .hasMessage("model should have observations"); - assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning()) - .hasMessage("model should have warnings"); - assertThatThrownBy(() -> testApexModel.testApexModelVaidateInvalidModel()) - .hasMessage("model should not be valid ***validation of model successful***"); - assertThatThrownBy(() -> testApexModel.testApexModelVaidateMalstructured()) - .hasMessage("model should not be valid ***validation of model successful***"); - } - - @Test - public void testModelCreator1() throws ApexException { - final TestApexModel testApexModel = new TestApexModel(AxModel.class, - new SupportApexModelCreator1()); - - assertThatThrownBy(() -> testApexModel.testApexModelValid()) - .hasMessageStartingWith("model is invalid"); - assertThatThrownBy(() -> testApexModel.testApexModelVaidateObservation()) - .hasMessageStartingWith("model is invalid"); - assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning()) - .hasMessageStartingWith("model is invalid"); - testApexModel.testApexModelVaidateInvalidModel(); - testApexModel.testApexModelVaidateMalstructured(); - } - - @Test - public void testModelCreator2() throws ApexException { - final TestApexModel testApexModel = new TestApexModel(AxModel.class, - new SupportApexModelCreator2()); - - testApexModel.testApexModelValid(); - testApexModel.testApexModelVaidateObservation(); - assertThatThrownBy(() -> testApexModel.testApexModelVaidateWarning()) - .hasMessage("model should have warnings"); - } - - @Test - public void testModelCreator1XmlJson() throws ApexException { - final TestApexModel testApexModel = new TestApexModel(AxModel.class, - new SupportApexModelCreator1()); - - assertThatThrownBy(() -> testApexModel.testApexModelWriteReadJson()) - .hasMessageStartingWith("error processing file"); - - assertThatThrownBy(() -> testApexModel.testApexModelWriteReadXml()) - .hasMessageStartingWith("error processing file"); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java new file mode 100644 index 000000000..006c583ec --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTest.java @@ -0,0 +1,217 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * Modifications Copyright (C) 2020-2021 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * 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.model.basicmodel.handling; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.UUID; +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +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.AxModel; + +public class SupportConceptGetterTest { + + private static final AxKeyInfo intKI01 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey01", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey01 description"); + private static final AxKeyInfo intKI11 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey11", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey11 description"); + private static final AxKeyInfo intKI21 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey21", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey21 description"); + private static final AxKeyInfo intKI22 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey22", "0.0.2"), + UUID.randomUUID(), "IntegerKIKey22 description"); + private static final AxKeyInfo intKI23 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey23", "0.0.3"), + UUID.randomUUID(), "IntegerKIKey23 description"); + private static final AxKeyInfo intKI24 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey24", "0.0.4"), + UUID.randomUUID(), "IntegerKIKey24 description"); + private static final AxKeyInfo intKI25 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey25", "0.0.5"), + UUID.randomUUID(), "IntegerKIKey25 description"); + private static final AxKeyInfo intKI26 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey26", "0.0.6"), + UUID.randomUUID(), "IntegerKIKey26 description"); + private static final AxKeyInfo intKI31 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey31", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey31 description"); + private static final AxKeyInfo intKI41 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey41", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey41 description"); + private static final AxKeyInfo intKI51 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey51", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey51 description"); + private static final AxKeyInfo intKI52 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey52", "0.0.2"), + UUID.randomUUID(), "IntegerKIKey52 description"); + private static final AxKeyInfo intKI53 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey53", "0.0.3"), + UUID.randomUUID(), "IntegerKIKey53 description"); + private static final AxKeyInfo intKI54 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey54", "0.0.4"), + UUID.randomUUID(), "IntegerKIKey54 description"); + private static final AxKeyInfo intKI61 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey61", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey61 description"); + private static final AxKeyInfo intKI62 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey62", "0.0.2"), + UUID.randomUUID(), "IntegerKIKey62 description"); + private static final AxKeyInfo intKI63 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey63", "0.0.3"), + UUID.randomUUID(), "IntegerKIKey63 description"); + private static final AxKeyInfo intKI64 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey64", "0.0.4"), + UUID.randomUUID(), "IntegerKIKey64 description"); + private static final AxKeyInfo intKI71 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey71", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey71 description"); + private static final AxKeyInfo intKI81 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey81", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey81 description"); + private static final AxKeyInfo intKI91 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey91", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey91 description"); + private static final AxKeyInfo floatKI01 = new AxKeyInfo(new AxArtifactKey("FloatKIKey01", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey01 description"); + private static final AxKeyInfo floatKI11 = new AxKeyInfo(new AxArtifactKey("FloatKIKey11", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey11 description"); + private static final AxKeyInfo floatKI21 = new AxKeyInfo(new AxArtifactKey("FloatKIKey21", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey21 description"); + private static final AxKeyInfo floatKI31 = new AxKeyInfo(new AxArtifactKey("FloatKIKey31", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey31 description"); + private static final AxKeyInfo floatKI41 = new AxKeyInfo(new AxArtifactKey("FloatKIKey41", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey41 description"); + private static final AxKeyInfo floatKI51 = new AxKeyInfo(new AxArtifactKey("FloatKIKey51", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey51 description"); + private static final AxKeyInfo floatKI61 = new AxKeyInfo(new AxArtifactKey("FloatKIKey61", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey61 description"); + private static final AxKeyInfo floatKI71 = new AxKeyInfo(new AxArtifactKey("FloatKIKey71", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey71 description"); + private static final AxKeyInfo floatKI81 = new AxKeyInfo(new AxArtifactKey("FloatKIKey81", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey81 description"); + private static final AxKeyInfo floatKI82 = new AxKeyInfo(new AxArtifactKey("FloatKIKey82", "0.0.2"), + UUID.randomUUID(), "IntegerKIKey82 description"); + private static final AxKeyInfo floatKI83 = new AxKeyInfo(new AxArtifactKey("FloatKIKey83", "0.0.3"), + UUID.randomUUID(), "IntegerKIKey83 description"); + private static final AxKeyInfo floatKI91 = new AxKeyInfo(new AxArtifactKey("FloatKIKey91", "0.0.1"), + UUID.randomUUID(), "IntegerKIKey91 description"); + private static final AxKeyInfo floatKI92 = new AxKeyInfo(new AxArtifactKey("FloatKIKey92", "0.0.2"), + UUID.randomUUID(), "IntegerKIKey92 description"); + private static final AxKeyInfo floatKI93 = new AxKeyInfo(new AxArtifactKey("FloatKIKey93", "0.0.3"), + UUID.randomUUID(), "IntegerKIKey93 description"); + + @Test + public void testConceptGetterInteger() { + AxModel basicModel = setTestBasicModel(); + + assertNull(basicModel.getKeyInformation().get("NonExistantKey", "0.0.6")); + assertEquals(intKI26, basicModel.getKeyInformation().get("IntegerKIKey26", "0.0.6")); + assertEquals(intKI62, basicModel.getKeyInformation().get("IntegerKIKey62", "0.0.2")); + assertEquals(intKI21, basicModel.getKeyInformation().get("IntegerKIKey21", "0.0.1")); + assertEquals(intKI61, basicModel.getKeyInformation().get("IntegerKIKey61", "0.0.1")); + + assertNull(basicModel.getKeyInformation().get("NonExistantKey")); + + assertEquals(intKI01, basicModel.getKeyInformation().get("IntegerKIKey01")); + assertEquals(intKI11, basicModel.getKeyInformation().get("IntegerKIKey11")); + assertEquals(intKI26, basicModel.getKeyInformation().get("IntegerKIKey26")); + assertEquals(intKI31, basicModel.getKeyInformation().get("IntegerKIKey31")); + assertEquals(intKI41, basicModel.getKeyInformation().get("IntegerKIKey41")); + assertEquals(intKI54, basicModel.getKeyInformation().get("IntegerKIKey54")); + assertEquals(intKI64, basicModel.getKeyInformation().get("IntegerKIKey64")); + assertEquals(intKI71, basicModel.getKeyInformation().get("IntegerKIKey71")); + assertEquals(intKI81, basicModel.getKeyInformation().get("IntegerKIKey81")); + assertEquals(intKI91, basicModel.getKeyInformation().get("IntegerKIKey91")); + } + + @Test + public void testConceptGetterFloat() { + AxModel basicModel = setTestBasicModel(); + + assertEquals(floatKI01, basicModel.getKeyInformation().get("FloatKIKey01")); + assertEquals(floatKI11, basicModel.getKeyInformation().get("FloatKIKey11")); + assertEquals(floatKI21, basicModel.getKeyInformation().get("FloatKIKey21")); + assertEquals(floatKI31, basicModel.getKeyInformation().get("FloatKIKey31")); + assertEquals(floatKI41, basicModel.getKeyInformation().get("FloatKIKey41")); + assertEquals(floatKI51, basicModel.getKeyInformation().get("FloatKIKey51")); + assertEquals(floatKI61, basicModel.getKeyInformation().get("FloatKIKey61")); + assertEquals(floatKI71, basicModel.getKeyInformation().get("FloatKIKey71")); + assertEquals(floatKI83, basicModel.getKeyInformation().get("FloatKIKey83")); + assertEquals(floatKI93, basicModel.getKeyInformation().get("FloatKIKey93")); + } + + @Test + public void testMarshalling() throws IOException, ApexException { + AxModel basicModel = setTestBasicModel(); + + // Ensure marshalling and unmarshalling is OK + ApexModelReader modelReader = new ApexModelReader(AxModel.class); + ApexModelFileWriter modelWriter = new ApexModelFileWriter(true); + + modelReader.setValidateFlag(false); + modelWriter.setValidateFlag(false); + + File tempXmlFile = File.createTempFile("ApexModel", "xml"); + modelWriter.apexModelWriteJsonFile(basicModel, AxModel.class, tempXmlFile.getCanonicalPath()); + + FileInputStream xmlFileInputStream = new FileInputStream(tempXmlFile); + AxModel readXmlModel = modelReader.read(xmlFileInputStream); + xmlFileInputStream.close(); + assertEquals(basicModel, readXmlModel); + assertEquals(intKI91, readXmlModel.getKeyInformation().get("IntegerKIKey91")); + assertNotNull(readXmlModel.getKeyInformation().get("FloatKIKey")); + tempXmlFile.delete(); + } + + private AxModel setTestBasicModel() { + AxModel basicModel = new DummyApexBasicModelCreator().getModel(); + assertNotNull(basicModel); + + basicModel.getKeyInformation().getKeyInfoMap().put(intKI31.getKey(), intKI31); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI24.getKey(), intKI24); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI11.getKey(), intKI11); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI64.getKey(), intKI64); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI41.getKey(), intKI41); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI51.getKey(), intKI51); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI23.getKey(), intKI23); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI81.getKey(), intKI81); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI71.getKey(), intKI71); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI01.getKey(), intKI01); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI91.getKey(), intKI91); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI52.getKey(), intKI52); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI53.getKey(), intKI53); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI62.getKey(), intKI62); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI54.getKey(), intKI54); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI26.getKey(), intKI26); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI22.getKey(), intKI22); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI25.getKey(), intKI25); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI21.getKey(), intKI21); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI61.getKey(), intKI61); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI63.getKey(), intKI63); + + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI11.getKey(), floatKI11); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI83.getKey(), floatKI83); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI51.getKey(), floatKI51); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI71.getKey(), floatKI71); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI21.getKey(), floatKI21); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI81.getKey(), floatKI81); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI92.getKey(), floatKI92); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI91.getKey(), floatKI91); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI01.getKey(), floatKI01); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI82.getKey(), floatKI82); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI61.getKey(), floatKI61); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI41.getKey(), floatKI41); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI31.getKey(), floatKI31); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI93.getKey(), floatKI93); + + return basicModel; + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTester.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTester.java deleted file mode 100644 index 786df5258..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTester.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2020 Nordix Foundation. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.UUID; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -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.AxModel; - -public class SupportConceptGetterTester { - - @Test - public void testConceptGetter() throws IOException, ApexException { - AxModel basicModel = new DummyApexBasicModelCreator().getModel(); - assertNotNull(basicModel); - - AxKeyInfo intKI01 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey01", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey01 description"); - AxKeyInfo intKI11 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey11", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey11 description"); - AxKeyInfo intKI21 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey21", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey21 description"); - AxKeyInfo intKI22 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey22", "0.0.2"), UUID.randomUUID(), - "IntegerKIKey22 description"); - AxKeyInfo intKI23 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey23", "0.0.3"), UUID.randomUUID(), - "IntegerKIKey23 description"); - AxKeyInfo intKI24 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey24", "0.0.4"), UUID.randomUUID(), - "IntegerKIKey24 description"); - AxKeyInfo intKI25 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey25", "0.0.5"), UUID.randomUUID(), - "IntegerKIKey25 description"); - AxKeyInfo intKI26 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey26", "0.0.6"), UUID.randomUUID(), - "IntegerKIKey26 description"); - AxKeyInfo intKI31 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey31", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey31 description"); - AxKeyInfo intKI41 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey41", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey41 description"); - AxKeyInfo intKI51 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey51", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey51 description"); - AxKeyInfo intKI52 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey52", "0.0.2"), UUID.randomUUID(), - "IntegerKIKey52 description"); - AxKeyInfo intKI53 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey53", "0.0.3"), UUID.randomUUID(), - "IntegerKIKey53 description"); - AxKeyInfo intKI54 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey54", "0.0.4"), UUID.randomUUID(), - "IntegerKIKey54 description"); - AxKeyInfo intKI61 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey61", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey61 description"); - AxKeyInfo intKI62 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey62", "0.0.2"), UUID.randomUUID(), - "IntegerKIKey62 description"); - AxKeyInfo intKI63 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey63", "0.0.3"), UUID.randomUUID(), - "IntegerKIKey63 description"); - AxKeyInfo intKI64 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey64", "0.0.4"), UUID.randomUUID(), - "IntegerKIKey64 description"); - AxKeyInfo intKI71 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey71", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey71 description"); - AxKeyInfo intKI81 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey81", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey81 description"); - AxKeyInfo intKI91 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey91", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey91 description"); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI31.getKey(), intKI31); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI24.getKey(), intKI24); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI11.getKey(), intKI11); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI64.getKey(), intKI64); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI41.getKey(), intKI41); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI51.getKey(), intKI51); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI23.getKey(), intKI23); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI81.getKey(), intKI81); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI71.getKey(), intKI71); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI01.getKey(), intKI01); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI91.getKey(), intKI91); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI52.getKey(), intKI52); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI53.getKey(), intKI53); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI62.getKey(), intKI62); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI54.getKey(), intKI54); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI26.getKey(), intKI26); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI22.getKey(), intKI22); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI25.getKey(), intKI25); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI21.getKey(), intKI21); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI61.getKey(), intKI61); - basicModel.getKeyInformation().getKeyInfoMap().put(intKI63.getKey(), intKI63); - - AxKeyInfo floatKI01 = new AxKeyInfo(new AxArtifactKey("FloatKIKey01", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey01 description"); - AxKeyInfo floatKI11 = new AxKeyInfo(new AxArtifactKey("FloatKIKey11", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey11 description"); - AxKeyInfo floatKI21 = new AxKeyInfo(new AxArtifactKey("FloatKIKey21", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey21 description"); - AxKeyInfo floatKI31 = new AxKeyInfo(new AxArtifactKey("FloatKIKey31", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey31 description"); - AxKeyInfo floatKI41 = new AxKeyInfo(new AxArtifactKey("FloatKIKey41", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey41 description"); - AxKeyInfo floatKI51 = new AxKeyInfo(new AxArtifactKey("FloatKIKey51", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey51 description"); - AxKeyInfo floatKI61 = new AxKeyInfo(new AxArtifactKey("FloatKIKey61", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey61 description"); - AxKeyInfo floatKI71 = new AxKeyInfo(new AxArtifactKey("FloatKIKey71", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey71 description"); - AxKeyInfo floatKI81 = new AxKeyInfo(new AxArtifactKey("FloatKIKey81", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey81 description"); - AxKeyInfo floatKI82 = new AxKeyInfo(new AxArtifactKey("FloatKIKey82", "0.0.2"), UUID.randomUUID(), - "IntegerKIKey82 description"); - AxKeyInfo floatKI83 = new AxKeyInfo(new AxArtifactKey("FloatKIKey83", "0.0.3"), UUID.randomUUID(), - "IntegerKIKey83 description"); - AxKeyInfo floatKI91 = new AxKeyInfo(new AxArtifactKey("FloatKIKey91", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey91 description"); - AxKeyInfo floatKI92 = new AxKeyInfo(new AxArtifactKey("FloatKIKey92", "0.0.2"), UUID.randomUUID(), - "IntegerKIKey92 description"); - AxKeyInfo floatKI93 = new AxKeyInfo(new AxArtifactKey("FloatKIKey93", "0.0.3"), UUID.randomUUID(), - "IntegerKIKey93 description"); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI11.getKey(), floatKI11); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI83.getKey(), floatKI83); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI51.getKey(), floatKI51); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI71.getKey(), floatKI71); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI21.getKey(), floatKI21); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI81.getKey(), floatKI81); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI92.getKey(), floatKI92); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI91.getKey(), floatKI91); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI01.getKey(), floatKI01); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI82.getKey(), floatKI82); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI61.getKey(), floatKI61); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI41.getKey(), floatKI41); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI31.getKey(), floatKI31); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKI93.getKey(), floatKI93); - - assertNull(basicModel.getKeyInformation().get("NonExistantKey", "0.0.6")); - assertEquals(intKI26, basicModel.getKeyInformation().get("IntegerKIKey26", "0.0.6")); - assertEquals(intKI62, basicModel.getKeyInformation().get("IntegerKIKey62", "0.0.2")); - assertEquals(intKI21, basicModel.getKeyInformation().get("IntegerKIKey21", "0.0.1")); - assertEquals(intKI61, basicModel.getKeyInformation().get("IntegerKIKey61", "0.0.1")); - - assertNull(basicModel.getKeyInformation().get("NonExistantKey")); - - assertEquals(intKI01, basicModel.getKeyInformation().get("IntegerKIKey01")); - assertEquals(intKI11, basicModel.getKeyInformation().get("IntegerKIKey11")); - assertEquals(intKI26, basicModel.getKeyInformation().get("IntegerKIKey26")); - assertEquals(intKI31, basicModel.getKeyInformation().get("IntegerKIKey31")); - assertEquals(intKI41, basicModel.getKeyInformation().get("IntegerKIKey41")); - assertEquals(intKI54, basicModel.getKeyInformation().get("IntegerKIKey54")); - assertEquals(intKI64, basicModel.getKeyInformation().get("IntegerKIKey64")); - assertEquals(intKI71, basicModel.getKeyInformation().get("IntegerKIKey71")); - assertEquals(intKI81, basicModel.getKeyInformation().get("IntegerKIKey81")); - assertEquals(intKI91, basicModel.getKeyInformation().get("IntegerKIKey91")); - - assertEquals(floatKI01, basicModel.getKeyInformation().get("FloatKIKey01")); - assertEquals(floatKI11, basicModel.getKeyInformation().get("FloatKIKey11")); - assertEquals(floatKI21, basicModel.getKeyInformation().get("FloatKIKey21")); - assertEquals(floatKI31, basicModel.getKeyInformation().get("FloatKIKey31")); - assertEquals(floatKI41, basicModel.getKeyInformation().get("FloatKIKey41")); - assertEquals(floatKI51, basicModel.getKeyInformation().get("FloatKIKey51")); - assertEquals(floatKI61, basicModel.getKeyInformation().get("FloatKIKey61")); - assertEquals(floatKI71, basicModel.getKeyInformation().get("FloatKIKey71")); - assertEquals(floatKI83, basicModel.getKeyInformation().get("FloatKIKey83")); - assertEquals(floatKI93, basicModel.getKeyInformation().get("FloatKIKey93")); - - // Ensure marshalling and unmarshalling is OK - ApexModelReader modelReader = new ApexModelReader(AxModel.class); - ApexModelFileWriter modelWriter = new ApexModelFileWriter(true); - - modelReader.setValidateFlag(false); - modelWriter.setValidateFlag(false); - - File tempXmlFile = File.createTempFile("ApexModel", "xml"); - modelWriter.apexModelWriteJsonFile(basicModel, AxModel.class, tempXmlFile.getCanonicalPath()); - - FileInputStream xmlFileInputStream = new FileInputStream(tempXmlFile); - AxModel readXmlModel = modelReader.read(xmlFileInputStream); - xmlFileInputStream.close(); - assertEquals(basicModel, readXmlModel); - assertEquals(intKI91, readXmlModel.getKeyInformation().get("IntegerKIKey91")); - assertNotNull(readXmlModel.getKeyInformation().get("FloatKIKey")); - tempXmlFile.delete(); - } -} -- cgit 1.2.3-korg