From 62475a30ef2d425fe04df35ef2dac53c7ab5306a Mon Sep 17 00:00:00 2001 From: Parshad Patel Date: Fri, 16 Nov 2018 20:59:14 +0900 Subject: Rename test classes in apex-pdp Make test classes name consistence by putting 'Test' at end Issue-ID: POLICY-1263 Change-Id: I0179388d84826e698276a1995dd8173a40b5fd2b Signed-off-by: Parshad Patel --- .../model/basicmodel/concepts/AxKeyInfoTest.java | 106 ++++++++ .../basicmodel/concepts/AxReferenceKeyTest.java | 110 ++++++++ .../model/basicmodel/concepts/ExceptionsTest.java | 70 ++++++ .../apex/model/basicmodel/concepts/KeyUseTest.java | 82 ++++++ .../model/basicmodel/concepts/TestAxKeyInfo.java | 106 -------- .../basicmodel/concepts/TestAxReferenceKey.java | 110 -------- .../model/basicmodel/concepts/TestExceptions.java | 70 ------ .../apex/model/basicmodel/concepts/TestKeyUse.java | 82 ------ .../model/basicmodel/concepts/TestValidation.java | 94 ------- .../model/basicmodel/concepts/ValidationTest.java | 94 +++++++ .../apex/model/basicmodel/dao/DaoMiscTest.java | 86 +++++++ .../apex/model/basicmodel/dao/TestDaoMisc.java | 86 ------- .../handling/ApexBasicModelConceptsTest.java | 279 +++++++++++++++++++++ .../basicmodel/handling/ApexBasicModelTest.java | 149 +++++++++++ .../model/basicmodel/handling/BasicModelTest.java | 147 +++++++++++ .../basicmodel/handling/ConceptGetterTest.java | 202 +++++++++++++++ .../model/basicmodel/handling/ExceptionsTest.java | 41 +++ .../basicmodel/handling/ModelFileWriterTest.java | 127 ++++++++++ .../model/basicmodel/handling/ModelReaderTest.java | 152 +++++++++++ .../model/basicmodel/handling/ModelSaverTest.java | 51 ++++ .../basicmodel/handling/ModelStringWriterTest.java | 96 +++++++ .../model/basicmodel/handling/ModelWriterTest.java | 92 +++++++ .../basicmodel/handling/SchemaGeneratorTest.java | 90 +++++++ .../basicmodel/handling/TestApexBasicModel.java | 149 ----------- .../handling/TestApexBasicModelConcepts.java | 279 --------------------- .../basicmodel/handling/TestBasicModelTest.java | 147 ----------- .../basicmodel/handling/TestConceptGetter.java | 202 --------------- .../model/basicmodel/handling/TestExceptions.java | 41 --- .../basicmodel/handling/TestModelFileWriter.java | 127 ---------- .../model/basicmodel/handling/TestModelReader.java | 152 ----------- .../model/basicmodel/handling/TestModelSaver.java | 51 ---- .../basicmodel/handling/TestModelStringWriter.java | 96 ------- .../model/basicmodel/handling/TestModelWriter.java | 92 ------- .../basicmodel/handling/TestSchemaGenerator.java | 90 ------- .../model/basicmodel/service/ModelServiceTest.java | 76 ++++++ .../model/basicmodel/service/TestModelService.java | 76 ------ .../basicmodel/xml/AxReferenceKeyAdapterTest.java | 43 ++++ .../basicmodel/xml/TestAxReferenceKeyAdapter.java | 43 ---- 38 files changed, 2093 insertions(+), 2093 deletions(-) create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKeyTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ExceptionsTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/KeyUseTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestAxKeyInfo.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestAxReferenceKey.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestExceptions.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestKeyUse.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestValidation.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ValidationTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/DaoMiscTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/TestDaoMisc.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexBasicModelConceptsTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexBasicModelTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/BasicModelTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ConceptGetterTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ExceptionsTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelFileWriterTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelReaderTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelSaverTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelStringWriterTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelWriterTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SchemaGeneratorTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexBasicModel.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexBasicModelConcepts.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestBasicModelTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestConceptGetter.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestExceptions.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelFileWriter.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelReader.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelSaver.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelStringWriter.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelWriter.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestSchemaGenerator.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/service/ModelServiceTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/service/TestModelService.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapterTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/TestAxReferenceKeyAdapter.java (limited to 'model/basic-model/src/test') 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 new file mode 100644 index 000000000..3f1635cce --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyInfoTest.java @@ -0,0 +1,106 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.concepts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.UUID; + +import org.junit.Test; +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.AxValidationResult; + +public class AxKeyInfoTest { + + @Test + public void testAxKeyInfo() { + assertNotNull(new AxKeyInfo()); + assertNotNull(new AxKeyInfo(new AxArtifactKey())); + assertNotNull(new AxKeyInfo(new AxArtifactKey(), UUID.randomUUID(), "Key description")); + + AxKeyInfo testKeyInfo = new AxKeyInfo(); + testKeyInfo.setKey((new AxArtifactKey("PN", "0.0.1"))); + assertEquals("PN:0.0.1", testKeyInfo.getKey().getId()); + + AxArtifactKey key = new AxArtifactKey("key", "0.0.1"); + testKeyInfo.setKey(key); + assertEquals(key, testKeyInfo.getKey()); + + UUID uuid = UUID.randomUUID(); + testKeyInfo.setUuid(uuid); + assertEquals(uuid, testKeyInfo.getUuid()); + testKeyInfo.setDescription("Key Description"); + assertEquals("Key Description", testKeyInfo.getDescription()); + + AxKeyInfo clonedReferenceKey = new AxKeyInfo(testKeyInfo); + assertTrue(clonedReferenceKey.toString() + .startsWith("AxKeyInfo:(artifactId=AxArtifactKey:(name=key,version=0.0.1),uuid=")); + + assertFalse(testKeyInfo.hashCode() == 0); + + assertTrue(testKeyInfo.equals(testKeyInfo)); + assertTrue(testKeyInfo.equals(clonedReferenceKey)); + assertFalse(testKeyInfo.equals(null)); + assertFalse(testKeyInfo.equals(new AxArtifactKey())); + assertFalse(testKeyInfo.equals(new AxKeyInfo(new AxArtifactKey()))); + assertFalse(testKeyInfo.equals(new AxKeyInfo(key, UUID.randomUUID(), "Some Description"))); + assertFalse(testKeyInfo.equals(new AxKeyInfo(key, uuid, "Some Description"))); + assertTrue(testKeyInfo.equals(new AxKeyInfo(key, uuid, "Key Description"))); + + assertEquals(0, testKeyInfo.compareTo(testKeyInfo)); + assertEquals(0, testKeyInfo.compareTo(clonedReferenceKey)); + assertNotEquals(0, testKeyInfo.compareTo(null)); + assertNotEquals(0, testKeyInfo.compareTo(new AxArtifactKey())); + assertNotEquals(0, testKeyInfo.compareTo(new AxKeyInfo(new AxArtifactKey()))); + assertNotEquals(0, testKeyInfo.compareTo(new AxKeyInfo(key, UUID.randomUUID(), "Some Description"))); + assertNotEquals(0, testKeyInfo.compareTo(new AxKeyInfo(key, uuid, "Some Description"))); + assertEquals(0, testKeyInfo.compareTo(new AxKeyInfo(key, uuid, "Key Description"))); + + assertNotNull(testKeyInfo.getKeys()); + + AxValidationResult result = new AxValidationResult(); + result = testKeyInfo.validate(result); + assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult()); + + testKeyInfo.setDescription(""); + result = testKeyInfo.validate(result); + assertEquals(AxValidationResult.ValidationResult.OBSERVATION, result.getValidationResult()); + + testKeyInfo.setUuid(new UUID(0, 0)); + result = testKeyInfo.validate(result); + assertEquals(AxValidationResult.ValidationResult.WARNING, result.getValidationResult()); + + testKeyInfo.setKey(AxArtifactKey.getNullKey()); + result = testKeyInfo.validate(result); + assertEquals(AxValidationResult.ValidationResult.INVALID, result.getValidationResult()); + + assertNotNull(AxKeyInfo.generateReproducibleUuid(null)); + assertNotNull(AxKeyInfo.generateReproducibleUuid("SeedString")); + + testKeyInfo.clean(); + assertNotNull(testKeyInfo); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKeyTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKeyTest.java new file mode 100644 index 000000000..68be4cdbb --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxReferenceKeyTest.java @@ -0,0 +1,110 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.concepts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +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.AxReferenceKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; + +public class AxReferenceKeyTest { + + @Test + public void testAxReferenceKey() { + assertNotNull(new AxReferenceKey()); + assertNotNull(new AxReferenceKey(new AxArtifactKey())); + assertNotNull(new AxReferenceKey(new AxArtifactKey(), "LocalName")); + assertNotNull(new AxReferenceKey(new AxReferenceKey())); + assertNotNull(new AxReferenceKey(new AxReferenceKey(), "LocalName")); + assertNotNull(new AxReferenceKey(new AxArtifactKey(), "ParentLocalName", "LocalName")); + assertNotNull(new AxReferenceKey("ParentKeyName", "0.0.1", "LocalName")); + assertNotNull(new AxReferenceKey("ParentKeyName", "0.0.1", "ParentLocalName", "LocalName")); + assertNotNull(new AxReferenceKey("ParentKeyName:0.0.1:ParentLocalName:LocalName")); + assertEquals(AxReferenceKey.getNullKey().getKey(), AxReferenceKey.getNullKey()); + assertEquals("NULL:0.0.0:NULL:NULL", AxReferenceKey.getNullKey().getId()); + + AxReferenceKey testReferenceKey = new AxReferenceKey(); + testReferenceKey.setParentArtifactKey(new AxArtifactKey("PN", "0.0.1")); + assertEquals("PN:0.0.1", testReferenceKey.getParentArtifactKey().getId()); + + testReferenceKey.setParentReferenceKey(new AxReferenceKey("PN", "0.0.1", "LN")); + assertEquals("PN:0.0.1:NULL:LN", testReferenceKey.getParentReferenceKey().getId()); + + testReferenceKey.setParentKeyName("NPKN"); + assertEquals("NPKN", testReferenceKey.getParentKeyName()); + + testReferenceKey.setParentKeyVersion("0.0.1"); + assertEquals("0.0.1", testReferenceKey.getParentKeyVersion()); + + testReferenceKey.setParentLocalName("NPKLN"); + assertEquals("NPKLN", testReferenceKey.getParentLocalName()); + + testReferenceKey.setLocalName("NLN"); + assertEquals("NLN", testReferenceKey.getLocalName()); + + assertFalse(testReferenceKey.isCompatible(AxArtifactKey.getNullKey())); + assertFalse(testReferenceKey.isCompatible(AxReferenceKey.getNullKey())); + assertTrue(testReferenceKey.isCompatible(testReferenceKey)); + + assertEquals(AxKey.Compatibility.DIFFERENT, testReferenceKey.getCompatibility(AxArtifactKey.getNullKey())); + assertEquals(AxKey.Compatibility.DIFFERENT, testReferenceKey.getCompatibility(AxReferenceKey.getNullKey())); + assertEquals(AxKey.Compatibility.IDENTICAL, testReferenceKey.getCompatibility(testReferenceKey)); + + AxValidationResult result = new AxValidationResult(); + result = testReferenceKey.validate(result); + assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult()); + + testReferenceKey.clean(); + + AxReferenceKey clonedReferenceKey = new AxReferenceKey(testReferenceKey); + assertEquals("AxReferenceKey:(parentKeyName=NPKN,parentKeyVersion=0.0.1,parentLocalName=NPKLN,localName=NLN)", + clonedReferenceKey.toString()); + + assertFalse(testReferenceKey.hashCode() == 0); + + assertTrue(testReferenceKey.equals(testReferenceKey)); + assertTrue(testReferenceKey.equals(clonedReferenceKey)); + assertFalse(testReferenceKey.equals("Hello")); + assertFalse(testReferenceKey.equals(new AxReferenceKey("PKN", "0.0.2", "PLN", "LN"))); + assertFalse(testReferenceKey.equals(new AxReferenceKey("NPKN", "0.0.2", "PLN", "LN"))); + assertFalse(testReferenceKey.equals(new AxReferenceKey("NPKN", "0.0.1", "PLN", "LN"))); + assertFalse(testReferenceKey.equals(new AxReferenceKey("NPKN", "0.0.1", "NPLN", "LN"))); + assertTrue(testReferenceKey.equals(new AxReferenceKey("NPKN", "0.0.1", "NPKLN", "NLN"))); + + assertEquals(0, testReferenceKey.compareTo(testReferenceKey)); + assertEquals(0, testReferenceKey.compareTo(clonedReferenceKey)); + assertNotEquals(0, testReferenceKey.compareTo(new AxArtifactKey())); + assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("PKN", "0.0.2", "PLN", "LN"))); + assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.2", "PLN", "LN"))); + assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "PLN", "LN"))); + assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "NPLN", "LN"))); + assertEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "NPKLN", "NLN"))); + + assertNotNull(testReferenceKey.getKeys()); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ExceptionsTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ExceptionsTest.java new file mode 100644 index 000000000..0c62a0376 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ExceptionsTest.java @@ -0,0 +1,70 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.concepts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.ApexConceptException; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; + +public class ExceptionsTest { + + @Test + public void test() { + assertNotNull(new ApexException("Message")); + assertNotNull(new ApexException("Message", new AxArtifactKey())); + assertNotNull(new ApexException("Message", new IOException())); + assertNotNull(new ApexException("Message", new IOException(), new AxArtifactKey())); + + AxArtifactKey key = new AxArtifactKey(); + ApexException ae = new ApexException("Message", new IOException("IO exception message"), key); + assertEquals("Message\ncaused by: Message\ncaused by: IO exception message", ae.getCascadedMessage()); + assertEquals(key, ae.getObject()); + + assertNotNull(new ApexRuntimeException("Message")); + assertNotNull(new ApexRuntimeException("Message", new AxArtifactKey())); + assertNotNull(new ApexRuntimeException("Message", new IOException())); + assertNotNull(new ApexRuntimeException("Message", new IOException(), new AxArtifactKey())); + + AxArtifactKey rkey = new AxArtifactKey(); + ApexRuntimeException re = new ApexRuntimeException("Runtime Message", + new IOException("IO runtime exception message"), rkey); + assertEquals("Runtime Message\ncaused by: Runtime Message\ncaused by: IO runtime exception message", + re.getCascadedMessage()); + assertEquals(key, re.getObject()); + + assertNotNull(new ApexConceptException("Message")); + assertNotNull(new ApexConceptException("Message", new IOException())); + + AxArtifactKey ckey = new AxArtifactKey(); + ApexException ace = new ApexException("Concept Message", new IOException("IO concept exception message"), ckey); + assertEquals("Concept Message\ncaused by: Concept Message\ncaused by: IO concept exception message", + ace.getCascadedMessage()); + assertEquals(ckey, ace.getObject()); + } + +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/KeyUseTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/KeyUseTest.java new file mode 100644 index 000000000..65df26d65 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/KeyUseTest.java @@ -0,0 +1,82 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.concepts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKey.Compatibility; +import org.onap.policy.apex.model.basicmodel.concepts.AxKeyUse; +import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; + +public class KeyUseTest { + + @Test + public void test() { + assertNotNull(new AxKeyUse()); + assertNotNull(new AxKeyUse(new AxArtifactKey())); + assertNotNull(new AxKeyUse(new AxReferenceKey())); + + AxArtifactKey key = new AxArtifactKey("Key", "0.0.1"); + AxKeyUse keyUse = new AxKeyUse(); + keyUse.setKey(key); + assertEquals(key, keyUse.getKey()); + assertEquals("Key:0.0.1", keyUse.getId()); + assertEquals(key, keyUse.getKeys().get(0)); + + assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key)); + assertTrue(keyUse.isCompatible(key)); + + keyUse.clean(); + assertNotNull(keyUse); + + AxValidationResult result = new AxValidationResult(); + result = keyUse.validate(result); + assertNotNull(result); + + assertNotEquals(0, keyUse.hashCode()); + + AxKeyUse clonedKeyUse = new AxKeyUse(keyUse); + assertEquals("AxKeyUse:(usedKey=AxArtifactKey:(name=Key,version=0.0.1))", clonedKeyUse.toString()); + + assertFalse(keyUse.hashCode() == 0); + + assertTrue(keyUse.equals(keyUse)); + assertTrue(keyUse.equals(clonedKeyUse)); + assertFalse(keyUse.equals("Hello")); + assertTrue(keyUse.equals(new AxKeyUse(key))); + + assertEquals(0, keyUse.compareTo(keyUse)); + assertEquals(0, keyUse.compareTo(clonedKeyUse)); + assertNotEquals(0, keyUse.compareTo(new AxArtifactKey())); + assertEquals(0, keyUse.compareTo(new AxKeyUse(key))); + + AxKeyUse keyUseNull = new AxKeyUse(AxArtifactKey.getNullKey()); + AxValidationResult resultNull = new AxValidationResult(); + assertEquals(false, keyUseNull.validate(resultNull).isValid()); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestAxKeyInfo.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestAxKeyInfo.java deleted file mode 100644 index f615d9db9..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestAxKeyInfo.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.concepts; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.UUID; - -import org.junit.Test; -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.AxValidationResult; - -public class TestAxKeyInfo { - - @Test - public void testAxKeyInfo() { - assertNotNull(new AxKeyInfo()); - assertNotNull(new AxKeyInfo(new AxArtifactKey())); - assertNotNull(new AxKeyInfo(new AxArtifactKey(), UUID.randomUUID(), "Key description")); - - AxKeyInfo testKeyInfo = new AxKeyInfo(); - testKeyInfo.setKey((new AxArtifactKey("PN", "0.0.1"))); - assertEquals("PN:0.0.1", testKeyInfo.getKey().getId()); - - AxArtifactKey key = new AxArtifactKey("key", "0.0.1"); - testKeyInfo.setKey(key); - assertEquals(key, testKeyInfo.getKey()); - - UUID uuid = UUID.randomUUID(); - testKeyInfo.setUuid(uuid); - assertEquals(uuid, testKeyInfo.getUuid()); - testKeyInfo.setDescription("Key Description"); - assertEquals("Key Description", testKeyInfo.getDescription()); - - AxKeyInfo clonedReferenceKey = new AxKeyInfo(testKeyInfo); - assertTrue(clonedReferenceKey.toString() - .startsWith("AxKeyInfo:(artifactId=AxArtifactKey:(name=key,version=0.0.1),uuid=")); - - assertFalse(testKeyInfo.hashCode() == 0); - - assertTrue(testKeyInfo.equals(testKeyInfo)); - assertTrue(testKeyInfo.equals(clonedReferenceKey)); - assertFalse(testKeyInfo.equals(null)); - assertFalse(testKeyInfo.equals(new AxArtifactKey())); - assertFalse(testKeyInfo.equals(new AxKeyInfo(new AxArtifactKey()))); - assertFalse(testKeyInfo.equals(new AxKeyInfo(key, UUID.randomUUID(), "Some Description"))); - assertFalse(testKeyInfo.equals(new AxKeyInfo(key, uuid, "Some Description"))); - assertTrue(testKeyInfo.equals(new AxKeyInfo(key, uuid, "Key Description"))); - - assertEquals(0, testKeyInfo.compareTo(testKeyInfo)); - assertEquals(0, testKeyInfo.compareTo(clonedReferenceKey)); - assertNotEquals(0, testKeyInfo.compareTo(null)); - assertNotEquals(0, testKeyInfo.compareTo(new AxArtifactKey())); - assertNotEquals(0, testKeyInfo.compareTo(new AxKeyInfo(new AxArtifactKey()))); - assertNotEquals(0, testKeyInfo.compareTo(new AxKeyInfo(key, UUID.randomUUID(), "Some Description"))); - assertNotEquals(0, testKeyInfo.compareTo(new AxKeyInfo(key, uuid, "Some Description"))); - assertEquals(0, testKeyInfo.compareTo(new AxKeyInfo(key, uuid, "Key Description"))); - - assertNotNull(testKeyInfo.getKeys()); - - AxValidationResult result = new AxValidationResult(); - result = testKeyInfo.validate(result); - assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult()); - - testKeyInfo.setDescription(""); - result = testKeyInfo.validate(result); - assertEquals(AxValidationResult.ValidationResult.OBSERVATION, result.getValidationResult()); - - testKeyInfo.setUuid(new UUID(0, 0)); - result = testKeyInfo.validate(result); - assertEquals(AxValidationResult.ValidationResult.WARNING, result.getValidationResult()); - - testKeyInfo.setKey(AxArtifactKey.getNullKey()); - result = testKeyInfo.validate(result); - assertEquals(AxValidationResult.ValidationResult.INVALID, result.getValidationResult()); - - assertNotNull(AxKeyInfo.generateReproducibleUuid(null)); - assertNotNull(AxKeyInfo.generateReproducibleUuid("SeedString")); - - testKeyInfo.clean(); - assertNotNull(testKeyInfo); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestAxReferenceKey.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestAxReferenceKey.java deleted file mode 100644 index 79f3984c3..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestAxReferenceKey.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.concepts; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -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.AxReferenceKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; - -public class TestAxReferenceKey { - - @Test - public void testAxReferenceKey() { - assertNotNull(new AxReferenceKey()); - assertNotNull(new AxReferenceKey(new AxArtifactKey())); - assertNotNull(new AxReferenceKey(new AxArtifactKey(), "LocalName")); - assertNotNull(new AxReferenceKey(new AxReferenceKey())); - assertNotNull(new AxReferenceKey(new AxReferenceKey(), "LocalName")); - assertNotNull(new AxReferenceKey(new AxArtifactKey(), "ParentLocalName", "LocalName")); - assertNotNull(new AxReferenceKey("ParentKeyName", "0.0.1", "LocalName")); - assertNotNull(new AxReferenceKey("ParentKeyName", "0.0.1", "ParentLocalName", "LocalName")); - assertNotNull(new AxReferenceKey("ParentKeyName:0.0.1:ParentLocalName:LocalName")); - assertEquals(AxReferenceKey.getNullKey().getKey(), AxReferenceKey.getNullKey()); - assertEquals("NULL:0.0.0:NULL:NULL", AxReferenceKey.getNullKey().getId()); - - AxReferenceKey testReferenceKey = new AxReferenceKey(); - testReferenceKey.setParentArtifactKey(new AxArtifactKey("PN", "0.0.1")); - assertEquals("PN:0.0.1", testReferenceKey.getParentArtifactKey().getId()); - - testReferenceKey.setParentReferenceKey(new AxReferenceKey("PN", "0.0.1", "LN")); - assertEquals("PN:0.0.1:NULL:LN", testReferenceKey.getParentReferenceKey().getId()); - - testReferenceKey.setParentKeyName("NPKN"); - assertEquals("NPKN", testReferenceKey.getParentKeyName()); - - testReferenceKey.setParentKeyVersion("0.0.1"); - assertEquals("0.0.1", testReferenceKey.getParentKeyVersion()); - - testReferenceKey.setParentLocalName("NPKLN"); - assertEquals("NPKLN", testReferenceKey.getParentLocalName()); - - testReferenceKey.setLocalName("NLN"); - assertEquals("NLN", testReferenceKey.getLocalName()); - - assertFalse(testReferenceKey.isCompatible(AxArtifactKey.getNullKey())); - assertFalse(testReferenceKey.isCompatible(AxReferenceKey.getNullKey())); - assertTrue(testReferenceKey.isCompatible(testReferenceKey)); - - assertEquals(AxKey.Compatibility.DIFFERENT, testReferenceKey.getCompatibility(AxArtifactKey.getNullKey())); - assertEquals(AxKey.Compatibility.DIFFERENT, testReferenceKey.getCompatibility(AxReferenceKey.getNullKey())); - assertEquals(AxKey.Compatibility.IDENTICAL, testReferenceKey.getCompatibility(testReferenceKey)); - - AxValidationResult result = new AxValidationResult(); - result = testReferenceKey.validate(result); - assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult()); - - testReferenceKey.clean(); - - AxReferenceKey clonedReferenceKey = new AxReferenceKey(testReferenceKey); - assertEquals("AxReferenceKey:(parentKeyName=NPKN,parentKeyVersion=0.0.1,parentLocalName=NPKLN,localName=NLN)", - clonedReferenceKey.toString()); - - assertFalse(testReferenceKey.hashCode() == 0); - - assertTrue(testReferenceKey.equals(testReferenceKey)); - assertTrue(testReferenceKey.equals(clonedReferenceKey)); - assertFalse(testReferenceKey.equals("Hello")); - assertFalse(testReferenceKey.equals(new AxReferenceKey("PKN", "0.0.2", "PLN", "LN"))); - assertFalse(testReferenceKey.equals(new AxReferenceKey("NPKN", "0.0.2", "PLN", "LN"))); - assertFalse(testReferenceKey.equals(new AxReferenceKey("NPKN", "0.0.1", "PLN", "LN"))); - assertFalse(testReferenceKey.equals(new AxReferenceKey("NPKN", "0.0.1", "NPLN", "LN"))); - assertTrue(testReferenceKey.equals(new AxReferenceKey("NPKN", "0.0.1", "NPKLN", "NLN"))); - - assertEquals(0, testReferenceKey.compareTo(testReferenceKey)); - assertEquals(0, testReferenceKey.compareTo(clonedReferenceKey)); - assertNotEquals(0, testReferenceKey.compareTo(new AxArtifactKey())); - assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("PKN", "0.0.2", "PLN", "LN"))); - assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.2", "PLN", "LN"))); - assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "PLN", "LN"))); - assertNotEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "NPLN", "LN"))); - assertEquals(0, testReferenceKey.compareTo(new AxReferenceKey("NPKN", "0.0.1", "NPKLN", "NLN"))); - - assertNotNull(testReferenceKey.getKeys()); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestExceptions.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestExceptions.java deleted file mode 100644 index 7a980d5f6..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestExceptions.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.concepts; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.ApexConceptException; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.concepts.ApexRuntimeException; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; - -public class TestExceptions { - - @Test - public void test() { - assertNotNull(new ApexException("Message")); - assertNotNull(new ApexException("Message", new AxArtifactKey())); - assertNotNull(new ApexException("Message", new IOException())); - assertNotNull(new ApexException("Message", new IOException(), new AxArtifactKey())); - - AxArtifactKey key = new AxArtifactKey(); - ApexException ae = new ApexException("Message", new IOException("IO exception message"), key); - assertEquals("Message\ncaused by: Message\ncaused by: IO exception message", ae.getCascadedMessage()); - assertEquals(key, ae.getObject()); - - assertNotNull(new ApexRuntimeException("Message")); - assertNotNull(new ApexRuntimeException("Message", new AxArtifactKey())); - assertNotNull(new ApexRuntimeException("Message", new IOException())); - assertNotNull(new ApexRuntimeException("Message", new IOException(), new AxArtifactKey())); - - AxArtifactKey rkey = new AxArtifactKey(); - ApexRuntimeException re = new ApexRuntimeException("Runtime Message", - new IOException("IO runtime exception message"), rkey); - assertEquals("Runtime Message\ncaused by: Runtime Message\ncaused by: IO runtime exception message", - re.getCascadedMessage()); - assertEquals(key, re.getObject()); - - assertNotNull(new ApexConceptException("Message")); - assertNotNull(new ApexConceptException("Message", new IOException())); - - AxArtifactKey ckey = new AxArtifactKey(); - ApexException ace = new ApexException("Concept Message", new IOException("IO concept exception message"), ckey); - assertEquals("Concept Message\ncaused by: Concept Message\ncaused by: IO concept exception message", - ace.getCascadedMessage()); - assertEquals(ckey, ace.getObject()); - } - -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestKeyUse.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestKeyUse.java deleted file mode 100644 index 6b5346971..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestKeyUse.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.concepts; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKey.Compatibility; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyUse; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; - -public class TestKeyUse { - - @Test - public void test() { - assertNotNull(new AxKeyUse()); - assertNotNull(new AxKeyUse(new AxArtifactKey())); - assertNotNull(new AxKeyUse(new AxReferenceKey())); - - AxArtifactKey key = new AxArtifactKey("Key", "0.0.1"); - AxKeyUse keyUse = new AxKeyUse(); - keyUse.setKey(key); - assertEquals(key, keyUse.getKey()); - assertEquals("Key:0.0.1", keyUse.getId()); - assertEquals(key, keyUse.getKeys().get(0)); - - assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key)); - assertTrue(keyUse.isCompatible(key)); - - keyUse.clean(); - assertNotNull(keyUse); - - AxValidationResult result = new AxValidationResult(); - result = keyUse.validate(result); - assertNotNull(result); - - assertNotEquals(0, keyUse.hashCode()); - - AxKeyUse clonedKeyUse = new AxKeyUse(keyUse); - assertEquals("AxKeyUse:(usedKey=AxArtifactKey:(name=Key,version=0.0.1))", clonedKeyUse.toString()); - - assertFalse(keyUse.hashCode() == 0); - - assertTrue(keyUse.equals(keyUse)); - assertTrue(keyUse.equals(clonedKeyUse)); - assertFalse(keyUse.equals("Hello")); - assertTrue(keyUse.equals(new AxKeyUse(key))); - - assertEquals(0, keyUse.compareTo(keyUse)); - assertEquals(0, keyUse.compareTo(clonedKeyUse)); - assertNotEquals(0, keyUse.compareTo(new AxArtifactKey())); - assertEquals(0, keyUse.compareTo(new AxKeyUse(key))); - - AxKeyUse keyUseNull = new AxKeyUse(AxArtifactKey.getNullKey()); - AxValidationResult resultNull = new AxValidationResult(); - assertEquals(false, keyUseNull.validate(resultNull).isValid()); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestValidation.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestValidation.java deleted file mode 100644 index cfa4d0ded..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestValidation.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.concepts; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; - -public class TestValidation { - - @Test - public void test() { - AxValidationResult result = new AxValidationResult(); - AxReferenceKey refKey = new AxReferenceKey("PK", "0.0.1", "PLN", "LN"); - result = refKey.validate(result); - - assertNotNull(result); - assertTrue(result.isOk()); - assertTrue(result.isValid()); - assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult()); - assertNotNull(result.getMessageList()); - - AxValidationMessage vmess0 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class, - ValidationResult.VALID, "Some message"); - result.addValidationMessage(vmess0); - - assertTrue(result.isOk()); - assertTrue(result.isValid()); - assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult()); - assertNotNull(result.getMessageList()); - assertNotNull("hello", result.toString()); - - AxValidationMessage vmess1 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class, - ValidationResult.OBSERVATION, "Some message"); - result.addValidationMessage(vmess1); - - assertTrue(result.isOk()); - assertTrue(result.isValid()); - assertEquals(AxValidationResult.ValidationResult.OBSERVATION, result.getValidationResult()); - assertNotNull(result.getMessageList()); - assertNotNull("hello", result.toString()); - - AxValidationMessage vmess2 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class, - ValidationResult.WARNING, "Some message"); - result.addValidationMessage(vmess2); - - assertFalse(result.isOk()); - assertTrue(result.isValid()); - assertEquals(AxValidationResult.ValidationResult.WARNING, result.getValidationResult()); - assertNotNull(result.getMessageList()); - assertNotNull("hello", result.toString()); - - AxValidationMessage vmess3 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class, - ValidationResult.INVALID, "Some message"); - result.addValidationMessage(vmess3); - - assertFalse(result.isOk()); - assertFalse(result.isValid()); - assertEquals(AxValidationResult.ValidationResult.INVALID, result.getValidationResult()); - assertNotNull(result.getMessageList()); - assertNotNull("hello", result.toString()); - - assertEquals(AxValidationResult.ValidationResult.INVALID, result.getMessageList().get(3).getValidationResult()); - assertEquals("Some message", result.getMessageList().get(3).getMessage()); - assertEquals(AxArtifactKey.class.getCanonicalName(), result.getMessageList().get(3).getObservedClass()); - assertEquals(AxArtifactKey.getNullKey(), result.getMessageList().get(3).getObservedKey()); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ValidationTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ValidationTest.java new file mode 100644 index 000000000..f30babe91 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/ValidationTest.java @@ -0,0 +1,94 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.concepts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationMessage; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; + +public class ValidationTest { + + @Test + public void test() { + AxValidationResult result = new AxValidationResult(); + AxReferenceKey refKey = new AxReferenceKey("PK", "0.0.1", "PLN", "LN"); + result = refKey.validate(result); + + assertNotNull(result); + assertTrue(result.isOk()); + assertTrue(result.isValid()); + assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult()); + assertNotNull(result.getMessageList()); + + AxValidationMessage vmess0 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class, + ValidationResult.VALID, "Some message"); + result.addValidationMessage(vmess0); + + assertTrue(result.isOk()); + assertTrue(result.isValid()); + assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult()); + assertNotNull(result.getMessageList()); + assertNotNull("hello", result.toString()); + + AxValidationMessage vmess1 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class, + ValidationResult.OBSERVATION, "Some message"); + result.addValidationMessage(vmess1); + + assertTrue(result.isOk()); + assertTrue(result.isValid()); + assertEquals(AxValidationResult.ValidationResult.OBSERVATION, result.getValidationResult()); + assertNotNull(result.getMessageList()); + assertNotNull("hello", result.toString()); + + AxValidationMessage vmess2 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class, + ValidationResult.WARNING, "Some message"); + result.addValidationMessage(vmess2); + + assertFalse(result.isOk()); + assertTrue(result.isValid()); + assertEquals(AxValidationResult.ValidationResult.WARNING, result.getValidationResult()); + assertNotNull(result.getMessageList()); + assertNotNull("hello", result.toString()); + + AxValidationMessage vmess3 = new AxValidationMessage(AxArtifactKey.getNullKey(), AxArtifactKey.class, + ValidationResult.INVALID, "Some message"); + result.addValidationMessage(vmess3); + + assertFalse(result.isOk()); + assertFalse(result.isValid()); + assertEquals(AxValidationResult.ValidationResult.INVALID, result.getValidationResult()); + assertNotNull(result.getMessageList()); + assertNotNull("hello", result.toString()); + + assertEquals(AxValidationResult.ValidationResult.INVALID, result.getMessageList().get(3).getValidationResult()); + assertEquals("Some message", result.getMessageList().get(3).getMessage()); + assertEquals(AxArtifactKey.class.getCanonicalName(), result.getMessageList().get(3).getObservedClass()); + assertEquals(AxArtifactKey.getNullKey(), result.getMessageList().get(3).getObservedKey()); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/DaoMiscTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/DaoMiscTest.java new file mode 100644 index 000000000..197c4b206 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/DaoMiscTest.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.dao; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import java.util.Properties; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.dao.converters.CDataConditioner; +import org.onap.policy.apex.model.basicmodel.dao.converters.Uuid2String; + +public class DaoMiscTest { + + @Test + public void testUuid2StringMopUp() { + final Uuid2String uuid2String = new Uuid2String(); + assertEquals("", uuid2String.convertToDatabaseColumn(null)); + } + + @Test + public void testCDataConditionerMopUp() { + assertNull(CDataConditioner.clean(null)); + } + + @Test + public void testDaoFactory() { + final DaoParameters daoParameters = new DaoParameters(); + + daoParameters.setPluginClass("somewhere.over.the.rainbow"); + try { + new ApexDaoFactory().createApexDao(daoParameters); + fail("test shold throw an exception here"); + } catch (final Exception e) { + assertEquals("Apex DAO class not found for DAO plugin \"somewhere.over.the.rainbow\"", e.getMessage()); + } + + daoParameters.setPluginClass("java.lang.String"); + try { + new ApexDaoFactory().createApexDao(daoParameters); + fail("test shold throw an exception here"); + } catch (final Exception e) { + assertEquals("Specified Apex DAO plugin class \"java.lang.String\" " + + "does not implement the ApexDao interface", e.getMessage()); + } + } + + @Test + public void testDaoParameters() { + final DaoParameters pars = new DaoParameters(); + pars.setJdbcProperties(new Properties()); + assertEquals(0, pars.getJdbcProperties().size()); + + pars.setJdbcProperty("name", "Dorothy"); + assertEquals("Dorothy", pars.getJdbcProperty("name")); + + pars.setPersistenceUnit("Kansas"); + assertEquals("Kansas", pars.getPersistenceUnit()); + + pars.setPluginClass("somewhere.over.the.rainbow"); + assertEquals("somewhere.over.the.rainbow", pars.getPluginClass()); + + assertEquals("DAOParameters [pluginClass=somewhere.over.the.rainbow, " + + "persistenceUnit=Kansas, jdbcProperties={name=Dorothy}]", pars.toString()); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/TestDaoMisc.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/TestDaoMisc.java deleted file mode 100644 index 7966e8d4f..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/TestDaoMisc.java +++ /dev/null @@ -1,86 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.dao; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; - -import java.util.Properties; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.dao.converters.CDataConditioner; -import org.onap.policy.apex.model.basicmodel.dao.converters.Uuid2String; - -public class TestDaoMisc { - - @Test - public void testUuid2StringMopUp() { - final Uuid2String uuid2String = new Uuid2String(); - assertEquals("", uuid2String.convertToDatabaseColumn(null)); - } - - @Test - public void testCDataConditionerMopUp() { - assertNull(CDataConditioner.clean(null)); - } - - @Test - public void testDaoFactory() { - final DaoParameters daoParameters = new DaoParameters(); - - daoParameters.setPluginClass("somewhere.over.the.rainbow"); - try { - new ApexDaoFactory().createApexDao(daoParameters); - fail("test shold throw an exception here"); - } catch (final Exception e) { - assertEquals("Apex DAO class not found for DAO plugin \"somewhere.over.the.rainbow\"", e.getMessage()); - } - - daoParameters.setPluginClass("java.lang.String"); - try { - new ApexDaoFactory().createApexDao(daoParameters); - fail("test shold throw an exception here"); - } catch (final Exception e) { - assertEquals("Specified Apex DAO plugin class \"java.lang.String\" " - + "does not implement the ApexDao interface", e.getMessage()); - } - } - - @Test - public void testDaoParameters() { - final DaoParameters pars = new DaoParameters(); - pars.setJdbcProperties(new Properties()); - assertEquals(0, pars.getJdbcProperties().size()); - - pars.setJdbcProperty("name", "Dorothy"); - assertEquals("Dorothy", pars.getJdbcProperty("name")); - - pars.setPersistenceUnit("Kansas"); - assertEquals("Kansas", pars.getPersistenceUnit()); - - pars.setPluginClass("somewhere.over.the.rainbow"); - assertEquals("somewhere.over.the.rainbow", pars.getPluginClass()); - - assertEquals("DAOParameters [pluginClass=somewhere.over.the.rainbow, " - + "persistenceUnit=Kansas, jdbcProperties={name=Dorothy}]", pars.toString()); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexBasicModelConceptsTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexBasicModelConceptsTest.java new file mode 100644 index 000000000..f2076c6e4 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexBasicModelConceptsTest.java @@ -0,0 +1,279 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.handling; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +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 ApexBasicModelConceptsTest { + TestApexModel testApexModel; + + @Before + public void setup() throws Exception { + testApexModel = new TestApexModel(AxModel.class, new TestApexBasicModelCreator()); + } + + @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")); + + assertFalse(model.hashCode() == 0); + + assertTrue(model.equals(model)); + assertTrue(model.equals(clonedModel)); + assertFalse(model.equals(null)); + assertFalse(model.equals("Hello")); + clonedModel.getKey().setVersion("0.0.2"); + assertFalse(model.equals(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); + + assertFalse(keyI.equals(null)); + assertFalse(keyI.equals(new AxArtifactKey())); + assertTrue(keyI.equals(clonedKeyI)); + + clonedKeyI.setKey(new AxArtifactKey()); + assertFalse(keyI.equals(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 AxModelWithReferences mwr = new TestApexBasicModelCreator().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/ApexBasicModelTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexBasicModelTest.java new file mode 100644 index 000000000..e8c8ef154 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexBasicModelTest.java @@ -0,0 +1,149 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.handling; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.sql.Connection; +import java.sql.DriverManager; + +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.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 ApexBasicModelTest { + private Connection connection; + TestApexModel testApexModel; + + /** + * Set up the test. + * + * @throws Exception any exception thrown by the test + */ + @Before + public void setup() throws Exception { + Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); + connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true"); + + testApexModel = new TestApexModel(AxModel.class, new TestApexBasicModelCreator()); + } + + @After + public void teardown() throws Exception { + connection.close(); + new File("derby.log").delete(); + } + + @Test + public void testModelValid() throws Exception { + final AxValidationResult result = testApexModel.testApexModelValid(); + assertTrue(result.toString().equals(VALID_MODEL_STRING)); + } + + @Test + public void testApexModelVaidateObservation() throws Exception { + try { + testApexModel.testApexModelVaidateObservation(); + } catch (final ApexException e) { + assertEquals("model should have observations", e.getMessage()); + } + } + + @Test + public void testApexModelVaidateWarning() throws Exception { + final AxValidationResult result = testApexModel.testApexModelVaidateWarning(); + assertTrue(result.toString().equals(WARNING_MODEL_STRING)); + } + + @Test + public void testModelVaidateInvalidModel() throws Exception { + final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel(); + assertTrue(result.toString().equals(INVALID_MODEL_STRING)); + } + + @Test + public void testModelVaidateMalstructured() throws Exception { + final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured(); + assertTrue(result.toString().equals(INVALID_MODEL_MALSTRUCTURED_STRING)); + } + + @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/BasicModelTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/BasicModelTest.java new file mode 100644 index 000000000..9881c7355 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/BasicModelTest.java @@ -0,0 +1,147 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.handling; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +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 BasicModelTest { + + @Test + public void testNormalModelCreator() throws ApexException { + final TestApexModel testApexModel = new TestApexModel(AxModel.class, + new TestApexBasicModelCreator()); + + testApexModel.testApexModelValid(); + try { + testApexModel.testApexModelVaidateObservation(); + fail("Test should throw an exception"); + } catch (final Exception e) { + assertEquals("model should have observations", e.getMessage()); + } + testApexModel.testApexModelVaidateWarning(); + testApexModel.testApexModelVaidateInvalidModel(); + testApexModel.testApexModelVaidateMalstructured(); + + testApexModel.testApexModelWriteReadJson(); + testApexModel.testApexModelWriteReadXml(); + } + + @Test + public void testModelCreator0() throws ApexException { + final TestApexModel testApexModel = new TestApexModel(AxModel.class, + new TestApexTestModelCreator0()); + + testApexModel.testApexModelValid(); + try { + testApexModel.testApexModelVaidateObservation(); + fail("Test should throw an exception"); + } catch (final Exception e) { + assertEquals("model should have observations", e.getMessage()); + } + try { + testApexModel.testApexModelVaidateWarning(); + fail("Test should throw an exception"); + } catch (final Exception e) { + assertEquals("model should have warnings", e.getMessage()); + } + try { + testApexModel.testApexModelVaidateInvalidModel(); + fail("Test should throw an exception"); + } catch (final Exception e) { + assertEquals("model should not be valid ***validation of model successful***", e.getMessage()); + } + try { + testApexModel.testApexModelVaidateMalstructured(); + fail("Test should throw an exception"); + } catch (final Exception e) { + assertEquals("model should not be valid ***validation of model successful***", e.getMessage()); + } + } + + @Test + public void testModelCreator1() throws ApexException { + final TestApexModel testApexModel = new TestApexModel(AxModel.class, + new TestApexTestModelCreator1()); + + try { + testApexModel.testApexModelValid(); + fail("Test should throw an exception"); + } catch (final Exception e) { + assertTrue(e.getMessage().startsWith("model is invalid")); + } + try { + testApexModel.testApexModelVaidateObservation(); + fail("Test should throw an exception"); + } catch (final Exception e) { + assertTrue(e.getMessage().startsWith("model is invalid")); + } + try { + testApexModel.testApexModelVaidateWarning(); + fail("Test should throw an exception"); + } catch (final Exception e) { + assertTrue(e.getMessage().startsWith("model is invalid")); + } + testApexModel.testApexModelVaidateInvalidModel(); + testApexModel.testApexModelVaidateMalstructured(); + } + + @Test + public void testModelCreator2() throws ApexException { + final TestApexModel testApexModel = new TestApexModel(AxModel.class, + new TestApexTestModelCreator2()); + + testApexModel.testApexModelValid(); + testApexModel.testApexModelVaidateObservation(); + try { + testApexModel.testApexModelVaidateWarning(); + fail("Test should throw an exception"); + } catch (final Exception e) { + assertEquals("model should have warnings", e.getMessage()); + } + } + + @Test + public void testModelCreator1XmlJson() throws ApexException { + final TestApexModel testApexModel = new TestApexModel(AxModel.class, + new TestApexTestModelCreator1()); + + try { + testApexModel.testApexModelWriteReadJson(); + fail("Test should throw an exception"); + } catch (final Exception e) { + assertTrue(e.getMessage().startsWith("error processing file")); + } + + try { + testApexModel.testApexModelWriteReadXml(); + fail("Test should throw an exception"); + } catch (final Exception e) { + assertTrue(e.getMessage().startsWith("error processing file")); + } + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ConceptGetterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ConceptGetterTest.java new file mode 100644 index 000000000..5dfd6711b --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ConceptGetterTest.java @@ -0,0 +1,202 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.handling; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +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; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelFileWriter; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; + +public class ConceptGetterTest { + + @Test + public void testConceptGetter() throws IOException, ApexException { + AxModel basicModel = new TestApexBasicModelCreator().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")); + assertTrue(basicModel.getKeyInformation().get("IntegerKIKey26", "0.0.6").equals(intKI26)); + assertTrue(basicModel.getKeyInformation().get("IntegerKIKey62", "0.0.2").equals(intKI62)); + assertTrue(basicModel.getKeyInformation().get("IntegerKIKey21", "0.0.1").equals(intKI21)); + assertTrue(basicModel.getKeyInformation().get("IntegerKIKey61", "0.0.1").equals(intKI61)); + + assertNull(basicModel.getKeyInformation().get("NonExistantKey")); + + assertTrue(basicModel.getKeyInformation().get("IntegerKIKey01").equals(intKI01)); + assertTrue(basicModel.getKeyInformation().get("IntegerKIKey11").equals(intKI11)); + assertTrue(basicModel.getKeyInformation().get("IntegerKIKey26").equals(intKI26)); + assertTrue(basicModel.getKeyInformation().get("IntegerKIKey31").equals(intKI31)); + assertTrue(basicModel.getKeyInformation().get("IntegerKIKey41").equals(intKI41)); + assertTrue(basicModel.getKeyInformation().get("IntegerKIKey54").equals(intKI54)); + assertTrue(basicModel.getKeyInformation().get("IntegerKIKey64").equals(intKI64)); + assertTrue(basicModel.getKeyInformation().get("IntegerKIKey71").equals(intKI71)); + assertTrue(basicModel.getKeyInformation().get("IntegerKIKey81").equals(intKI81)); + assertTrue(basicModel.getKeyInformation().get("IntegerKIKey91").equals(intKI91)); + + assertTrue(basicModel.getKeyInformation().get("FloatKIKey01").equals(floatKI01)); + assertTrue(basicModel.getKeyInformation().get("FloatKIKey11").equals(floatKI11)); + assertTrue(basicModel.getKeyInformation().get("FloatKIKey21").equals(floatKI21)); + assertTrue(basicModel.getKeyInformation().get("FloatKIKey31").equals(floatKI31)); + assertTrue(basicModel.getKeyInformation().get("FloatKIKey41").equals(floatKI41)); + assertTrue(basicModel.getKeyInformation().get("FloatKIKey51").equals(floatKI51)); + assertTrue(basicModel.getKeyInformation().get("FloatKIKey61").equals(floatKI61)); + assertTrue(basicModel.getKeyInformation().get("FloatKIKey71").equals(floatKI71)); + assertTrue(basicModel.getKeyInformation().get("FloatKIKey83").equals(floatKI83)); + assertTrue(basicModel.getKeyInformation().get("FloatKIKey93").equals(floatKI93)); + + // 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(); + assertTrue(basicModel.equals(readXmlModel)); + assertTrue(readXmlModel.getKeyInformation().get("IntegerKIKey91").equals(intKI91)); + assertNotNull(readXmlModel.getKeyInformation().get("FloatKIKey")); + tempXmlFile.delete(); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ExceptionsTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ExceptionsTest.java new file mode 100644 index 000000000..8715cabe5 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ExceptionsTest.java @@ -0,0 +1,41 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.handling; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; + +public class ExceptionsTest { + + @Test + public void test() { + assertNotNull(new ApexModelException("Message")); + assertNotNull(new ApexModelException("Message", new IOException())); + + ApexModelException ame = new ApexModelException("Message", new IOException("IO exception message")); + assertEquals("Message\ncaused by: Message\ncaused by: IO exception message", ame.getCascadedMessage()); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelFileWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelFileWriterTest.java new file mode 100644 index 000000000..9a894e86b --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelFileWriterTest.java @@ -0,0 +1,127 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.handling; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.IOException; + +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.handling.ApexModelFileWriter; + +public class ModelFileWriterTest { + + @Test + public void testModelFileWriter() throws IOException, ApexException { + ApexModelFileWriter modelFileWriter = new ApexModelFileWriter<>(true); + + modelFileWriter.setValidateFlag(true); + assertTrue(modelFileWriter.isValidateFlag()); + + File tempFile = File.createTempFile("ApexFileWriterTest", "test"); + File tempDir = tempFile.getParentFile(); + tempFile.delete(); + + File jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/ApexFileWriterTest.json"); + File xmlTempFile = new File(tempDir.getAbsolutePath() + "/ccc/ApexFileWriterTest.xml"); + + AxModel model = new TestApexBasicModelCreator().getModel(); + + modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath()); + modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, xmlTempFile.getAbsolutePath()); + + jsonTempFile.delete(); + xmlTempFile.delete(); + new File(tempDir.getAbsolutePath() + "/aaa").delete(); + new File(tempDir.getAbsolutePath() + "/ccc").delete(); + + jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json"); + xmlTempFile = new File(tempDir.getAbsolutePath() + "/ccc/ddd/ApexFileWriterTest.xml"); + + modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath()); + modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, xmlTempFile.getAbsolutePath()); + + jsonTempFile.delete(); + xmlTempFile.delete(); + + new File(tempDir.getAbsolutePath() + "/aaa/bbb").delete(); + new File(tempDir.getAbsolutePath() + "/aaa").delete(); + new File(tempDir.getAbsolutePath() + "/ccc/ddd").delete(); + new File(tempDir.getAbsolutePath() + "/ccc").delete(); + + File dirA = new File(tempDir.getAbsolutePath() + "/aaa"); + //File dirB = new File(tempDir.getAbsolutePath() + "/aaa/bbb"); + dirA.createNewFile(); + //dirB.createNewFile(); + + jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json"); + jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.xml"); + + try { + modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath()); + fail("this test should throw an exception here"); + } + catch (Exception e) { + assertTrue(e.getMessage().contains("could not create directory ")); + } + + try { + modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, jsonTempFile.getAbsolutePath()); + fail("this test should throw an exception here"); + } + catch (Exception e) { + assertTrue(e.getMessage().contains("could not create directory ")); + } + + dirA.delete(); + + dirA = new File(tempDir.getAbsolutePath() + "/aaa"); + File fileB = new File(tempDir.getAbsolutePath() + "/aaa/bbb"); + dirA.mkdir(); + fileB.createNewFile(); + + jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json"); + jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.xml"); + + try { + modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath()); + fail("this test should throw an exception here"); + } + catch (Exception e) { + assertTrue(e.getMessage().contains("error processing file ")); + } + + try { + modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, jsonTempFile.getAbsolutePath()); + fail("this test should throw an exception here"); + } + catch (Exception e) { + assertTrue(e.getMessage().contains("error processing file ")); + } + + fileB.delete(); + dirA.delete(); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelReaderTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelReaderTest.java new file mode 100644 index 000000000..e4e33460e --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelReaderTest.java @@ -0,0 +1,152 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.handling; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.BufferedReader; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; + +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.handling.ApexModelReader; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelWriter; + +public class ModelReaderTest { + + @Test + public void testModelReader() throws IOException, ApexException { + AxModel model = new TestApexBasicModelCreator().getModel(); + AxModel invalidModel = new TestApexBasicModelCreator().getInvalidModel(); + + ApexModelWriter modelWriter = new ApexModelWriter(AxModel.class); + modelWriter.setValidateFlag(true); + modelWriter.setJsonOutput(true); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + modelWriter.write(model, baos); + + ByteArrayOutputStream baosInvalid = new ByteArrayOutputStream(); + modelWriter.setValidateFlag(false); + modelWriter.write(invalidModel, baosInvalid); + + ApexModelReader modelReader = new ApexModelReader(AxModel.class, true); + + modelReader.setValidateFlag(true); + assertTrue(modelReader.getValidateFlag()); + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + AxModel readModel = modelReader.read(bais); + assertEquals(model, readModel); + + ByteArrayInputStream baisInvalid = new ByteArrayInputStream(baosInvalid.toByteArray()); + try { + modelReader.read(baisInvalid); + fail("test should throw an exceptino here"); + } + catch (Exception e) { + assertTrue(e.getMessage().startsWith("Apex concept validation failed")); + } + + modelReader.setValidateFlag(false); + assertFalse(modelReader.getValidateFlag()); + + ByteArrayInputStream bais2 = new ByteArrayInputStream(baos.toByteArray()); + AxModel readModel2 = modelReader.read(bais2); + assertEquals(model, readModel2); + + modelWriter.setJsonOutput(false); + + ByteArrayOutputStream baosXml = new ByteArrayOutputStream(); + modelWriter.write(model, baosXml); + + ByteArrayInputStream baisXml = new ByteArrayInputStream(baosXml.toByteArray()); + AxModel readModelXml = modelReader.read(baisXml); + assertEquals(model, readModelXml); + + String dummyString = "SomeDummyText"; + ByteArrayInputStream baisDummy = new ByteArrayInputStream(dummyString.getBytes()); + try { + modelReader.read(baisDummy); + fail("test should throw an exception here"); + } + catch (Exception e) { + assertEquals("format of input for Apex concept is neither JSON nor XML", e.getMessage()); + } + + try { + ByteArrayInputStream nullBais = null; + modelReader.read(nullBais); + fail("test should throw an exception here"); + } + catch (Exception e) { + assertEquals("concept stream may not be null", e.getMessage()); + } + + try { + FileInputStream fis = new FileInputStream(new File("somewhere/over/the/rainbow")); + modelReader.read(fis); + fail("test should throw an exception here"); + } + catch (Exception e) { + assertTrue(e.getMessage().contains("rainbow")); + } + + File tempFile = File.createTempFile("Apex", "Dummy"); + try { + BufferedReader br = new BufferedReader(new FileReader(tempFile)); + br.close(); + modelReader.read(br); + fail("test should throw an exception here"); + } + catch (Exception e) { + assertEquals("Unable to read Apex concept ", e.getMessage()); + } + finally { + tempFile.delete(); + } + + modelReader.setSchema(null); + + tempFile = File.createTempFile("Apex", "Dummy"); + try { + modelReader.setSchema(tempFile.getCanonicalPath()); + fail("test should throw an exception here"); + } + catch (Exception e) { + assertEquals("Unable to load schema", e.getMessage()); + } + finally { + tempFile.delete(); + } + + modelReader.setSchema("xml/example.xsd"); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelSaverTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelSaverTest.java new file mode 100644 index 000000000..b318fc7af --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelSaverTest.java @@ -0,0 +1,51 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.handling; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +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.handling.ApexModelSaver; + +public class ModelSaverTest { + + @Test + public void testModelSaver() throws IOException, ApexException { + AxModel model = new TestApexBasicModelCreator().getModel(); + + Path tempPath = Files.createTempDirectory("ApexTest"); + + ApexModelSaver modelSaver = new ApexModelSaver(AxModel.class, model, + tempPath.toAbsolutePath().toString()); + + modelSaver.apexModelWriteXml(); + modelSaver.apexModelWriteJson(); + + Files.deleteIfExists(new File(tempPath.toAbsolutePath() + "/BasicModel.json").toPath()); + Files.deleteIfExists(new File(tempPath.toAbsolutePath() + "/BasicModel.xml").toPath()); + Files.deleteIfExists(tempPath); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelStringWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelStringWriterTest.java new file mode 100644 index 000000000..a44387559 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelStringWriterTest.java @@ -0,0 +1,96 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.handling; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.ApexException; +import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo; +import org.onap.policy.apex.model.basicmodel.concepts.AxModel; +import org.onap.policy.apex.model.basicmodel.handling.ApexModelStringWriter; + +public class ModelStringWriterTest { + + @Test + public void testModelStringWriter() throws IOException, ApexException { + AxModel basicModel = new TestApexBasicModelCreator().getModel(); + assertNotNull(basicModel); + + AxKeyInfo intKeyInfo = basicModel.getKeyInformation().get("IntegerKIKey"); + AxKeyInfo floatKeyInfo = basicModel.getKeyInformation().get("FloatKIKey"); + + // Ensure marshalling is OK + ApexModelStringWriter stringWriter = new ApexModelStringWriter(true); + + assertNotNull(stringWriter.writeJsonString(intKeyInfo, AxKeyInfo.class)); + assertNotNull(stringWriter.writeJsonString(floatKeyInfo, AxKeyInfo.class)); + + assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class, true)); + assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class, true)); + + assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class, false)); + assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class, false)); + + assertNotNull(stringWriter.writeXmlString(intKeyInfo, AxKeyInfo.class)); + assertNotNull(stringWriter.writeXmlString(floatKeyInfo, AxKeyInfo.class)); + + try { + stringWriter.writeString(null, AxKeyInfo.class, true); + fail("test should thrown an exception here"); + } + catch (Exception e) { + assertEquals("concept may not be null", e.getMessage()); + } + + try { + stringWriter.writeString(null, AxKeyInfo.class, false); + fail("test should thrown an exception here"); + } + catch (Exception e) { + assertEquals("concept may not be null", e.getMessage()); + } + + try { + stringWriter.writeJsonString(null, AxKeyInfo.class); + fail("test should thrown an exception here"); + } + catch (Exception e) { + assertEquals("error writing JSON string", e.getMessage()); + } + + try { + stringWriter.writeXmlString(null, AxKeyInfo.class); + fail("test should thrown an exception here"); + } + catch (Exception e) { + assertEquals("error writing XML string", e.getMessage()); + } + + stringWriter.setValidateFlag(true); + assertTrue(stringWriter.isValidateFlag()); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelWriterTest.java new file mode 100644 index 000000000..f79b4e4c6 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelWriterTest.java @@ -0,0 +1,92 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.handling; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +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.handling.ApexModelWriter; + +public class ModelWriterTest { + + @Test + public void testModelWriter() throws IOException, ApexException { + ApexModelWriter modelWriter = new ApexModelWriter(AxModel.class); + + modelWriter.setValidateFlag(true); + assertTrue(modelWriter.getValidateFlag()); + assertEquals(0, modelWriter.getCDataFieldSet().size()); + + assertFalse(modelWriter.isJsonOutput()); + modelWriter.setJsonOutput(true); + assertTrue(modelWriter.isJsonOutput()); + modelWriter.setJsonOutput(false); + assertFalse(modelWriter.isJsonOutput()); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + + AxModel model = new TestApexBasicModelCreator().getModel(); + + modelWriter.write(model, baos); + modelWriter.setJsonOutput(true); + modelWriter.write(model, baos); + modelWriter.setJsonOutput(false); + + modelWriter.setValidateFlag(false); + modelWriter.write(model, baos); + modelWriter.setJsonOutput(true); + modelWriter.write(model, baos); + modelWriter.setJsonOutput(false); + + modelWriter.setValidateFlag(true); + model.getKeyInformation().getKeyInfoMap().clear(); + try { + modelWriter.write(model, baos); + fail("Test should throw an exception here"); + } catch (Exception e) { + assertEquals("Apex concept xml (BasicModel:0.0.1) validation failed", e.getMessage().substring(0, 53)); + } + model.getKeyInformation().generateKeyInfo(model); + + try { + modelWriter.write(null, baos); + fail("Test should throw an exception here"); + } catch (Exception e) { + assertEquals("concept may not be null", e.getMessage()); + } + + try { + ByteArrayOutputStream nullBaos = null; + modelWriter.write(model, nullBaos); + fail("Test should throw an exception here"); + } catch (Exception e) { + assertEquals("concept stream may not be null", e.getMessage()); + } + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SchemaGeneratorTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SchemaGeneratorTest.java new file mode 100644 index 000000000..5950f1acc --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SchemaGeneratorTest.java @@ -0,0 +1,90 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.handling; + +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileDescriptor; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +import org.junit.Test; + +public class SchemaGeneratorTest { + + @Test + public void test() throws IOException { + final ByteArrayOutputStream baos0 = new ByteArrayOutputStream(); + System.setOut(new PrintStream(baos0)); + + final String[] args0 = {}; + ApexSchemaGenerator.main(args0); + assertTrue(baos0.toString().contains("usage: ApexSchemaGenerator apex-root-class [schema-file-name]")); + System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); + + final ByteArrayOutputStream baos1 = new ByteArrayOutputStream(); + System.setOut(new PrintStream(baos1)); + + final String[] args1 = { "hello", "goodbye", "here" }; + ApexSchemaGenerator.main(args1); + assertTrue(baos1.toString().contains("usage: ApexSchemaGenerator apex-root-class [schema-file-name]")); + System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); + + final ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); + System.setOut(new PrintStream(baos2)); + + final String[] args2 = { "hello", "goodbye" }; + ApexSchemaGenerator.main(args2); + assertTrue(baos2.toString().contains("error on Apex schema output")); + System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); + + final ByteArrayOutputStream baos3 = new ByteArrayOutputStream(); + System.setOut(new PrintStream(baos3)); + + final String[] args3 = { "hello" }; + ApexSchemaGenerator.main(args3); + assertTrue(baos3.toString().contains("could not create JAXB context, root class hello not found")); + System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); + + final ByteArrayOutputStream baos4 = new ByteArrayOutputStream(); + System.setOut(new PrintStream(baos4)); + + final String[] args4 = { "org.onap.policy.apex.model.basicmodel.concepts.AxModel" }; + ApexSchemaGenerator.main(args4); + assertTrue(baos4.toString().contains("targetNamespace=\"http://www.onap.org/policy/apex-pdp\"")); + System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); + + final ByteArrayOutputStream baos5 = new ByteArrayOutputStream(); + System.setOut(new PrintStream(baos5)); + + final File tempFile = File.createTempFile("ApexSchemaGeneratorTest", "xsd"); + final String[] args5 = + { "org.onap.policy.apex.model.basicmodel.concepts.AxModel", tempFile.getCanonicalPath() }; + + ApexSchemaGenerator.main(args5); + assertTrue(tempFile.length() > 100); + System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); + tempFile.delete(); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexBasicModel.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexBasicModel.java deleted file mode 100644 index 69942b3df..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexBasicModel.java +++ /dev/null @@ -1,149 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; - -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.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 TestApexBasicModel { - private Connection connection; - TestApexModel testApexModel; - - /** - * Set up the test. - * - * @throws Exception any exception thrown by the test - */ - @Before - public void setup() throws Exception { - Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); - connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true"); - - testApexModel = new TestApexModel(AxModel.class, new TestApexBasicModelCreator()); - } - - @After - public void teardown() throws Exception { - connection.close(); - new File("derby.log").delete(); - } - - @Test - public void testModelValid() throws Exception { - final AxValidationResult result = testApexModel.testApexModelValid(); - assertTrue(result.toString().equals(VALID_MODEL_STRING)); - } - - @Test - public void testApexModelVaidateObservation() throws Exception { - try { - testApexModel.testApexModelVaidateObservation(); - } catch (final ApexException e) { - assertEquals("model should have observations", e.getMessage()); - } - } - - @Test - public void testApexModelVaidateWarning() throws Exception { - final AxValidationResult result = testApexModel.testApexModelVaidateWarning(); - assertTrue(result.toString().equals(WARNING_MODEL_STRING)); - } - - @Test - public void testModelVaidateInvalidModel() throws Exception { - final AxValidationResult result = testApexModel.testApexModelVaidateInvalidModel(); - assertTrue(result.toString().equals(INVALID_MODEL_STRING)); - } - - @Test - public void testModelVaidateMalstructured() throws Exception { - final AxValidationResult result = testApexModel.testApexModelVaidateMalstructured(); - assertTrue(result.toString().equals(INVALID_MODEL_MALSTRUCTURED_STRING)); - } - - @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/TestApexBasicModelConcepts.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexBasicModelConcepts.java deleted file mode 100644 index 11cab6d88..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexBasicModelConcepts.java +++ /dev/null @@ -1,279 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -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 TestApexBasicModelConcepts { - TestApexModel testApexModel; - - @Before - public void setup() throws Exception { - testApexModel = new TestApexModel(AxModel.class, new TestApexBasicModelCreator()); - } - - @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")); - - assertFalse(model.hashCode() == 0); - - assertTrue(model.equals(model)); - assertTrue(model.equals(clonedModel)); - assertFalse(model.equals(null)); - assertFalse(model.equals("Hello")); - clonedModel.getKey().setVersion("0.0.2"); - assertFalse(model.equals(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); - - assertFalse(keyI.equals(null)); - assertFalse(keyI.equals(new AxArtifactKey())); - assertTrue(keyI.equals(clonedKeyI)); - - clonedKeyI.setKey(new AxArtifactKey()); - assertFalse(keyI.equals(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 AxModelWithReferences mwr = new TestApexBasicModelCreator().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/TestBasicModelTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestBasicModelTest.java deleted file mode 100644 index 905f9e16b..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestBasicModelTest.java +++ /dev/null @@ -1,147 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -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 TestBasicModelTest { - - @Test - public void testNormalModelCreator() throws ApexException { - final TestApexModel testApexModel = new TestApexModel(AxModel.class, - new TestApexBasicModelCreator()); - - testApexModel.testApexModelValid(); - try { - testApexModel.testApexModelVaidateObservation(); - fail("Test should throw an exception"); - } catch (final Exception e) { - assertEquals("model should have observations", e.getMessage()); - } - testApexModel.testApexModelVaidateWarning(); - testApexModel.testApexModelVaidateInvalidModel(); - testApexModel.testApexModelVaidateMalstructured(); - - testApexModel.testApexModelWriteReadJson(); - testApexModel.testApexModelWriteReadXml(); - } - - @Test - public void testModelCreator0() throws ApexException { - final TestApexModel testApexModel = new TestApexModel(AxModel.class, - new TestApexTestModelCreator0()); - - testApexModel.testApexModelValid(); - try { - testApexModel.testApexModelVaidateObservation(); - fail("Test should throw an exception"); - } catch (final Exception e) { - assertEquals("model should have observations", e.getMessage()); - } - try { - testApexModel.testApexModelVaidateWarning(); - fail("Test should throw an exception"); - } catch (final Exception e) { - assertEquals("model should have warnings", e.getMessage()); - } - try { - testApexModel.testApexModelVaidateInvalidModel(); - fail("Test should throw an exception"); - } catch (final Exception e) { - assertEquals("model should not be valid ***validation of model successful***", e.getMessage()); - } - try { - testApexModel.testApexModelVaidateMalstructured(); - fail("Test should throw an exception"); - } catch (final Exception e) { - assertEquals("model should not be valid ***validation of model successful***", e.getMessage()); - } - } - - @Test - public void testModelCreator1() throws ApexException { - final TestApexModel testApexModel = new TestApexModel(AxModel.class, - new TestApexTestModelCreator1()); - - try { - testApexModel.testApexModelValid(); - fail("Test should throw an exception"); - } catch (final Exception e) { - assertTrue(e.getMessage().startsWith("model is invalid")); - } - try { - testApexModel.testApexModelVaidateObservation(); - fail("Test should throw an exception"); - } catch (final Exception e) { - assertTrue(e.getMessage().startsWith("model is invalid")); - } - try { - testApexModel.testApexModelVaidateWarning(); - fail("Test should throw an exception"); - } catch (final Exception e) { - assertTrue(e.getMessage().startsWith("model is invalid")); - } - testApexModel.testApexModelVaidateInvalidModel(); - testApexModel.testApexModelVaidateMalstructured(); - } - - @Test - public void testModelCreator2() throws ApexException { - final TestApexModel testApexModel = new TestApexModel(AxModel.class, - new TestApexTestModelCreator2()); - - testApexModel.testApexModelValid(); - testApexModel.testApexModelVaidateObservation(); - try { - testApexModel.testApexModelVaidateWarning(); - fail("Test should throw an exception"); - } catch (final Exception e) { - assertEquals("model should have warnings", e.getMessage()); - } - } - - @Test - public void testModelCreator1XmlJson() throws ApexException { - final TestApexModel testApexModel = new TestApexModel(AxModel.class, - new TestApexTestModelCreator1()); - - try { - testApexModel.testApexModelWriteReadJson(); - fail("Test should throw an exception"); - } catch (final Exception e) { - assertTrue(e.getMessage().startsWith("error processing file")); - } - - try { - testApexModel.testApexModelWriteReadXml(); - fail("Test should throw an exception"); - } catch (final Exception e) { - assertTrue(e.getMessage().startsWith("error processing file")); - } - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestConceptGetter.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestConceptGetter.java deleted file mode 100644 index f95c0b41d..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestConceptGetter.java +++ /dev/null @@ -1,202 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -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; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelFileWriter; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelReader; - -public class TestConceptGetter { - - @Test - public void testConceptGetter() throws IOException, ApexException { - AxModel basicModel = new TestApexBasicModelCreator().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")); - assertTrue(basicModel.getKeyInformation().get("IntegerKIKey26", "0.0.6").equals(intKI26)); - assertTrue(basicModel.getKeyInformation().get("IntegerKIKey62", "0.0.2").equals(intKI62)); - assertTrue(basicModel.getKeyInformation().get("IntegerKIKey21", "0.0.1").equals(intKI21)); - assertTrue(basicModel.getKeyInformation().get("IntegerKIKey61", "0.0.1").equals(intKI61)); - - assertNull(basicModel.getKeyInformation().get("NonExistantKey")); - - assertTrue(basicModel.getKeyInformation().get("IntegerKIKey01").equals(intKI01)); - assertTrue(basicModel.getKeyInformation().get("IntegerKIKey11").equals(intKI11)); - assertTrue(basicModel.getKeyInformation().get("IntegerKIKey26").equals(intKI26)); - assertTrue(basicModel.getKeyInformation().get("IntegerKIKey31").equals(intKI31)); - assertTrue(basicModel.getKeyInformation().get("IntegerKIKey41").equals(intKI41)); - assertTrue(basicModel.getKeyInformation().get("IntegerKIKey54").equals(intKI54)); - assertTrue(basicModel.getKeyInformation().get("IntegerKIKey64").equals(intKI64)); - assertTrue(basicModel.getKeyInformation().get("IntegerKIKey71").equals(intKI71)); - assertTrue(basicModel.getKeyInformation().get("IntegerKIKey81").equals(intKI81)); - assertTrue(basicModel.getKeyInformation().get("IntegerKIKey91").equals(intKI91)); - - assertTrue(basicModel.getKeyInformation().get("FloatKIKey01").equals(floatKI01)); - assertTrue(basicModel.getKeyInformation().get("FloatKIKey11").equals(floatKI11)); - assertTrue(basicModel.getKeyInformation().get("FloatKIKey21").equals(floatKI21)); - assertTrue(basicModel.getKeyInformation().get("FloatKIKey31").equals(floatKI31)); - assertTrue(basicModel.getKeyInformation().get("FloatKIKey41").equals(floatKI41)); - assertTrue(basicModel.getKeyInformation().get("FloatKIKey51").equals(floatKI51)); - assertTrue(basicModel.getKeyInformation().get("FloatKIKey61").equals(floatKI61)); - assertTrue(basicModel.getKeyInformation().get("FloatKIKey71").equals(floatKI71)); - assertTrue(basicModel.getKeyInformation().get("FloatKIKey83").equals(floatKI83)); - assertTrue(basicModel.getKeyInformation().get("FloatKIKey93").equals(floatKI93)); - - // 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(); - assertTrue(basicModel.equals(readXmlModel)); - assertTrue(readXmlModel.getKeyInformation().get("IntegerKIKey91").equals(intKI91)); - assertNotNull(readXmlModel.getKeyInformation().get("FloatKIKey")); - tempXmlFile.delete(); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestExceptions.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestExceptions.java deleted file mode 100644 index 8b0196b31..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestExceptions.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelException; - -public class TestExceptions { - - @Test - public void test() { - assertNotNull(new ApexModelException("Message")); - assertNotNull(new ApexModelException("Message", new IOException())); - - ApexModelException ame = new ApexModelException("Message", new IOException("IO exception message")); - assertEquals("Message\ncaused by: Message\ncaused by: IO exception message", ame.getCascadedMessage()); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelFileWriter.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelFileWriter.java deleted file mode 100644 index 3e860e3b1..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelFileWriter.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.File; -import java.io.IOException; - -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.handling.ApexModelFileWriter; - -public class TestModelFileWriter { - - @Test - public void testModelFileWriter() throws IOException, ApexException { - ApexModelFileWriter modelFileWriter = new ApexModelFileWriter<>(true); - - modelFileWriter.setValidateFlag(true); - assertTrue(modelFileWriter.isValidateFlag()); - - File tempFile = File.createTempFile("ApexFileWriterTest", "test"); - File tempDir = tempFile.getParentFile(); - tempFile.delete(); - - File jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/ApexFileWriterTest.json"); - File xmlTempFile = new File(tempDir.getAbsolutePath() + "/ccc/ApexFileWriterTest.xml"); - - AxModel model = new TestApexBasicModelCreator().getModel(); - - modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath()); - modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, xmlTempFile.getAbsolutePath()); - - jsonTempFile.delete(); - xmlTempFile.delete(); - new File(tempDir.getAbsolutePath() + "/aaa").delete(); - new File(tempDir.getAbsolutePath() + "/ccc").delete(); - - jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json"); - xmlTempFile = new File(tempDir.getAbsolutePath() + "/ccc/ddd/ApexFileWriterTest.xml"); - - modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath()); - modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, xmlTempFile.getAbsolutePath()); - - jsonTempFile.delete(); - xmlTempFile.delete(); - - new File(tempDir.getAbsolutePath() + "/aaa/bbb").delete(); - new File(tempDir.getAbsolutePath() + "/aaa").delete(); - new File(tempDir.getAbsolutePath() + "/ccc/ddd").delete(); - new File(tempDir.getAbsolutePath() + "/ccc").delete(); - - File dirA = new File(tempDir.getAbsolutePath() + "/aaa"); - //File dirB = new File(tempDir.getAbsolutePath() + "/aaa/bbb"); - dirA.createNewFile(); - //dirB.createNewFile(); - - jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json"); - jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.xml"); - - try { - modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath()); - fail("this test should throw an exception here"); - } - catch (Exception e) { - assertTrue(e.getMessage().contains("could not create directory ")); - } - - try { - modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, jsonTempFile.getAbsolutePath()); - fail("this test should throw an exception here"); - } - catch (Exception e) { - assertTrue(e.getMessage().contains("could not create directory ")); - } - - dirA.delete(); - - dirA = new File(tempDir.getAbsolutePath() + "/aaa"); - File fileB = new File(tempDir.getAbsolutePath() + "/aaa/bbb"); - dirA.mkdir(); - fileB.createNewFile(); - - jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.json"); - jsonTempFile = new File(tempDir.getAbsolutePath() + "/aaa/bbb/ApexFileWriterTest.xml"); - - try { - modelFileWriter.apexModelWriteJsonFile(model, AxModel.class, jsonTempFile.getAbsolutePath()); - fail("this test should throw an exception here"); - } - catch (Exception e) { - assertTrue(e.getMessage().contains("error processing file ")); - } - - try { - modelFileWriter.apexModelWriteXmlFile(model, AxModel.class, jsonTempFile.getAbsolutePath()); - fail("this test should throw an exception here"); - } - catch (Exception e) { - assertTrue(e.getMessage().contains("error processing file ")); - } - - fileB.delete(); - dirA.delete(); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelReader.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelReader.java deleted file mode 100644 index 1695a0b2c..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelReader.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.BufferedReader; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.IOException; - -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.handling.ApexModelReader; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelWriter; - -public class TestModelReader { - - @Test - public void testModelReader() throws IOException, ApexException { - AxModel model = new TestApexBasicModelCreator().getModel(); - AxModel invalidModel = new TestApexBasicModelCreator().getInvalidModel(); - - ApexModelWriter modelWriter = new ApexModelWriter(AxModel.class); - modelWriter.setValidateFlag(true); - modelWriter.setJsonOutput(true); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - modelWriter.write(model, baos); - - ByteArrayOutputStream baosInvalid = new ByteArrayOutputStream(); - modelWriter.setValidateFlag(false); - modelWriter.write(invalidModel, baosInvalid); - - ApexModelReader modelReader = new ApexModelReader(AxModel.class, true); - - modelReader.setValidateFlag(true); - assertTrue(modelReader.getValidateFlag()); - - ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - AxModel readModel = modelReader.read(bais); - assertEquals(model, readModel); - - ByteArrayInputStream baisInvalid = new ByteArrayInputStream(baosInvalid.toByteArray()); - try { - modelReader.read(baisInvalid); - fail("test should throw an exceptino here"); - } - catch (Exception e) { - assertTrue(e.getMessage().startsWith("Apex concept validation failed")); - } - - modelReader.setValidateFlag(false); - assertFalse(modelReader.getValidateFlag()); - - ByteArrayInputStream bais2 = new ByteArrayInputStream(baos.toByteArray()); - AxModel readModel2 = modelReader.read(bais2); - assertEquals(model, readModel2); - - modelWriter.setJsonOutput(false); - - ByteArrayOutputStream baosXml = new ByteArrayOutputStream(); - modelWriter.write(model, baosXml); - - ByteArrayInputStream baisXml = new ByteArrayInputStream(baosXml.toByteArray()); - AxModel readModelXml = modelReader.read(baisXml); - assertEquals(model, readModelXml); - - String dummyString = "SomeDummyText"; - ByteArrayInputStream baisDummy = new ByteArrayInputStream(dummyString.getBytes()); - try { - modelReader.read(baisDummy); - fail("test should throw an exception here"); - } - catch (Exception e) { - assertEquals("format of input for Apex concept is neither JSON nor XML", e.getMessage()); - } - - try { - ByteArrayInputStream nullBais = null; - modelReader.read(nullBais); - fail("test should throw an exception here"); - } - catch (Exception e) { - assertEquals("concept stream may not be null", e.getMessage()); - } - - try { - FileInputStream fis = new FileInputStream(new File("somewhere/over/the/rainbow")); - modelReader.read(fis); - fail("test should throw an exception here"); - } - catch (Exception e) { - assertTrue(e.getMessage().contains("rainbow")); - } - - File tempFile = File.createTempFile("Apex", "Dummy"); - try { - BufferedReader br = new BufferedReader(new FileReader(tempFile)); - br.close(); - modelReader.read(br); - fail("test should throw an exception here"); - } - catch (Exception e) { - assertEquals("Unable to read Apex concept ", e.getMessage()); - } - finally { - tempFile.delete(); - } - - modelReader.setSchema(null); - - tempFile = File.createTempFile("Apex", "Dummy"); - try { - modelReader.setSchema(tempFile.getCanonicalPath()); - fail("test should throw an exception here"); - } - catch (Exception e) { - assertEquals("Unable to load schema", e.getMessage()); - } - finally { - tempFile.delete(); - } - - modelReader.setSchema("xml/example.xsd"); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelSaver.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelSaver.java deleted file mode 100644 index 634a929d9..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelSaver.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -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.handling.ApexModelSaver; - -public class TestModelSaver { - - @Test - public void testModelSaver() throws IOException, ApexException { - AxModel model = new TestApexBasicModelCreator().getModel(); - - Path tempPath = Files.createTempDirectory("ApexTest"); - - ApexModelSaver modelSaver = new ApexModelSaver(AxModel.class, model, - tempPath.toAbsolutePath().toString()); - - modelSaver.apexModelWriteXml(); - modelSaver.apexModelWriteJson(); - - Files.deleteIfExists(new File(tempPath.toAbsolutePath() + "/BasicModel.json").toPath()); - Files.deleteIfExists(new File(tempPath.toAbsolutePath() + "/BasicModel.xml").toPath()); - Files.deleteIfExists(tempPath); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelStringWriter.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelStringWriter.java deleted file mode 100644 index d187e55ee..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelStringWriter.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.IOException; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.ApexException; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.apex.model.basicmodel.handling.ApexModelStringWriter; - -public class TestModelStringWriter { - - @Test - public void testModelStringWriter() throws IOException, ApexException { - AxModel basicModel = new TestApexBasicModelCreator().getModel(); - assertNotNull(basicModel); - - AxKeyInfo intKeyInfo = basicModel.getKeyInformation().get("IntegerKIKey"); - AxKeyInfo floatKeyInfo = basicModel.getKeyInformation().get("FloatKIKey"); - - // Ensure marshalling is OK - ApexModelStringWriter stringWriter = new ApexModelStringWriter(true); - - assertNotNull(stringWriter.writeJsonString(intKeyInfo, AxKeyInfo.class)); - assertNotNull(stringWriter.writeJsonString(floatKeyInfo, AxKeyInfo.class)); - - assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class, true)); - assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class, true)); - - assertNotNull(stringWriter.writeString(intKeyInfo, AxKeyInfo.class, false)); - assertNotNull(stringWriter.writeString(floatKeyInfo, AxKeyInfo.class, false)); - - assertNotNull(stringWriter.writeXmlString(intKeyInfo, AxKeyInfo.class)); - assertNotNull(stringWriter.writeXmlString(floatKeyInfo, AxKeyInfo.class)); - - try { - stringWriter.writeString(null, AxKeyInfo.class, true); - fail("test should thrown an exception here"); - } - catch (Exception e) { - assertEquals("concept may not be null", e.getMessage()); - } - - try { - stringWriter.writeString(null, AxKeyInfo.class, false); - fail("test should thrown an exception here"); - } - catch (Exception e) { - assertEquals("concept may not be null", e.getMessage()); - } - - try { - stringWriter.writeJsonString(null, AxKeyInfo.class); - fail("test should thrown an exception here"); - } - catch (Exception e) { - assertEquals("error writing JSON string", e.getMessage()); - } - - try { - stringWriter.writeXmlString(null, AxKeyInfo.class); - fail("test should thrown an exception here"); - } - catch (Exception e) { - assertEquals("error writing XML string", e.getMessage()); - } - - stringWriter.setValidateFlag(true); - assertTrue(stringWriter.isValidateFlag()); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelWriter.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelWriter.java deleted file mode 100644 index 57c30db11..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestModelWriter.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; - -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.handling.ApexModelWriter; - -public class TestModelWriter { - - @Test - public void testModelWriter() throws IOException, ApexException { - ApexModelWriter modelWriter = new ApexModelWriter(AxModel.class); - - modelWriter.setValidateFlag(true); - assertTrue(modelWriter.getValidateFlag()); - assertEquals(0, modelWriter.getCDataFieldSet().size()); - - assertFalse(modelWriter.isJsonOutput()); - modelWriter.setJsonOutput(true); - assertTrue(modelWriter.isJsonOutput()); - modelWriter.setJsonOutput(false); - assertFalse(modelWriter.isJsonOutput()); - - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - - AxModel model = new TestApexBasicModelCreator().getModel(); - - modelWriter.write(model, baos); - modelWriter.setJsonOutput(true); - modelWriter.write(model, baos); - modelWriter.setJsonOutput(false); - - modelWriter.setValidateFlag(false); - modelWriter.write(model, baos); - modelWriter.setJsonOutput(true); - modelWriter.write(model, baos); - modelWriter.setJsonOutput(false); - - modelWriter.setValidateFlag(true); - model.getKeyInformation().getKeyInfoMap().clear(); - try { - modelWriter.write(model, baos); - fail("Test should throw an exception here"); - } catch (Exception e) { - assertEquals("Apex concept xml (BasicModel:0.0.1) validation failed", e.getMessage().substring(0, 53)); - } - model.getKeyInformation().generateKeyInfo(model); - - try { - modelWriter.write(null, baos); - fail("Test should throw an exception here"); - } catch (Exception e) { - assertEquals("concept may not be null", e.getMessage()); - } - - try { - ByteArrayOutputStream nullBaos = null; - modelWriter.write(model, nullBaos); - fail("Test should throw an exception here"); - } catch (Exception e) { - assertEquals("concept stream may not be null", e.getMessage()); - } - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestSchemaGenerator.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestSchemaGenerator.java deleted file mode 100644 index 36e4125ec..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestSchemaGenerator.java +++ /dev/null @@ -1,90 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.handling; - -import static org.junit.Assert.assertTrue; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileDescriptor; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.PrintStream; - -import org.junit.Test; - -public class TestSchemaGenerator { - - @Test - public void test() throws IOException { - final ByteArrayOutputStream baos0 = new ByteArrayOutputStream(); - System.setOut(new PrintStream(baos0)); - - final String[] args0 = {}; - ApexSchemaGenerator.main(args0); - assertTrue(baos0.toString().contains("usage: ApexSchemaGenerator apex-root-class [schema-file-name]")); - System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); - - final ByteArrayOutputStream baos1 = new ByteArrayOutputStream(); - System.setOut(new PrintStream(baos1)); - - final String[] args1 = { "hello", "goodbye", "here" }; - ApexSchemaGenerator.main(args1); - assertTrue(baos1.toString().contains("usage: ApexSchemaGenerator apex-root-class [schema-file-name]")); - System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); - - final ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); - System.setOut(new PrintStream(baos2)); - - final String[] args2 = { "hello", "goodbye" }; - ApexSchemaGenerator.main(args2); - assertTrue(baos2.toString().contains("error on Apex schema output")); - System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); - - final ByteArrayOutputStream baos3 = new ByteArrayOutputStream(); - System.setOut(new PrintStream(baos3)); - - final String[] args3 = { "hello" }; - ApexSchemaGenerator.main(args3); - assertTrue(baos3.toString().contains("could not create JAXB context, root class hello not found")); - System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); - - final ByteArrayOutputStream baos4 = new ByteArrayOutputStream(); - System.setOut(new PrintStream(baos4)); - - final String[] args4 = { "org.onap.policy.apex.model.basicmodel.concepts.AxModel" }; - ApexSchemaGenerator.main(args4); - assertTrue(baos4.toString().contains("targetNamespace=\"http://www.onap.org/policy/apex-pdp\"")); - System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); - - final ByteArrayOutputStream baos5 = new ByteArrayOutputStream(); - System.setOut(new PrintStream(baos5)); - - final File tempFile = File.createTempFile("ApexSchemaGeneratorTest", "xsd"); - final String[] args5 = - { "org.onap.policy.apex.model.basicmodel.concepts.AxModel", tempFile.getCanonicalPath() }; - - ApexSchemaGenerator.main(args5); - assertTrue(tempFile.length() > 100); - System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out))); - tempFile.delete(); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/service/ModelServiceTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/service/ModelServiceTest.java new file mode 100644 index 000000000..f1bb220b3 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/service/ModelServiceTest.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.service; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation; +import org.onap.policy.apex.model.basicmodel.handling.TestApexBasicModelCreator; + +public class ModelServiceTest { + + @Test + public void testModelService() { + ModelService.clear(); + + assertFalse(ModelService.existsModel(AxKeyInformation.class)); + try { + ModelService.getModel(AxKeyInformation.class); + } catch (final Exception e) { + assertEquals("Model for org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation " + + "not found in model service", e.getMessage()); + } + + ModelService.registerModel(AxKeyInformation.class, + new TestApexBasicModelCreator().getModel().getKeyInformation()); + assertTrue(ModelService.existsModel(AxKeyInformation.class)); + assertNotNull(ModelService.getModel(AxKeyInformation.class)); + + ModelService.deregisterModel(AxKeyInformation.class); + + assertFalse(ModelService.existsModel(AxKeyInformation.class)); + try { + ModelService.getModel(AxKeyInformation.class); + } catch (final Exception e) { + assertEquals("Model for org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation " + + "not found in model service", e.getMessage()); + } + + ModelService.registerModel(AxKeyInformation.class, + new TestApexBasicModelCreator().getModel().getKeyInformation()); + assertTrue(ModelService.existsModel(AxKeyInformation.class)); + assertNotNull(ModelService.getModel(AxKeyInformation.class)); + + ModelService.clear(); + assertFalse(ModelService.existsModel(AxKeyInformation.class)); + try { + ModelService.getModel(AxKeyInformation.class); + } catch (final Exception e) { + assertEquals("Model for org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation " + + "not found in model service", e.getMessage()); + } + + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/service/TestModelService.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/service/TestModelService.java deleted file mode 100644 index 4f05de177..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/service/TestModelService.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.service; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation; -import org.onap.policy.apex.model.basicmodel.handling.TestApexBasicModelCreator; - -public class TestModelService { - - @Test - public void testModelService() { - ModelService.clear(); - - assertFalse(ModelService.existsModel(AxKeyInformation.class)); - try { - ModelService.getModel(AxKeyInformation.class); - } catch (final Exception e) { - assertEquals("Model for org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation " - + "not found in model service", e.getMessage()); - } - - ModelService.registerModel(AxKeyInformation.class, - new TestApexBasicModelCreator().getModel().getKeyInformation()); - assertTrue(ModelService.existsModel(AxKeyInformation.class)); - assertNotNull(ModelService.getModel(AxKeyInformation.class)); - - ModelService.deregisterModel(AxKeyInformation.class); - - assertFalse(ModelService.existsModel(AxKeyInformation.class)); - try { - ModelService.getModel(AxKeyInformation.class); - } catch (final Exception e) { - assertEquals("Model for org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation " - + "not found in model service", e.getMessage()); - } - - ModelService.registerModel(AxKeyInformation.class, - new TestApexBasicModelCreator().getModel().getKeyInformation()); - assertTrue(ModelService.existsModel(AxKeyInformation.class)); - assertNotNull(ModelService.getModel(AxKeyInformation.class)); - - ModelService.clear(); - assertFalse(ModelService.existsModel(AxKeyInformation.class)); - try { - ModelService.getModel(AxKeyInformation.class); - } catch (final Exception e) { - assertEquals("Model for org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation " - + "not found in model service", e.getMessage()); - } - - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapterTest.java new file mode 100644 index 000000000..2befe3336 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/AxReferenceKeyAdapterTest.java @@ -0,0 +1,43 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.basicmodel.xml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; +import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter; + +public class AxReferenceKeyAdapterTest { + + @Test + public void test() throws Exception { + AxReferenceKeyAdapter arka = new AxReferenceKeyAdapter(); + assertNotNull(arka); + + AxReferenceKey rkey = new AxReferenceKey("Name", "0.0.1", "PLN", "LN"); + + String rkeyString = arka.marshal(rkey); + assertEquals("LN", rkeyString); + assertEquals(rkey.getLocalName(),arka.unmarshal(rkeyString).getLocalName()); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/TestAxReferenceKeyAdapter.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/TestAxReferenceKeyAdapter.java deleted file mode 100644 index a7773c37c..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/xml/TestAxReferenceKeyAdapter.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.basicmodel.xml; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; -import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter; - -public class TestAxReferenceKeyAdapter { - - @Test - public void test() throws Exception { - AxReferenceKeyAdapter arka = new AxReferenceKeyAdapter(); - assertNotNull(arka); - - AxReferenceKey rkey = new AxReferenceKey("Name", "0.0.1", "PLN", "LN"); - - String rkeyString = arka.marshal(rkey); - assertEquals("LN", rkeyString); - assertEquals(rkey.getLocalName(),arka.unmarshal(rkeyString).getLocalName()); - } -} -- cgit 1.2.3-korg