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 --- .../contextmodel/concepts/ContextAlbumsTest.java | 212 ++++++++++++++ .../contextmodel/concepts/ContextModelTest.java | 96 +++++++ .../contextmodel/concepts/ContextSchemasTest.java | 195 +++++++++++++ .../contextmodel/concepts/TestContextAlbums.java | 212 -------------- .../contextmodel/concepts/TestContextModel.java | 96 ------- .../contextmodel/concepts/TestContextSchemas.java | 195 ------------- .../handling/ApexContextModelTest.java | 153 ++++++++++ .../handling/ContextComparisonTest.java | 189 +++++++++++++ .../handling/TestApexContextModel.java | 153 ---------- .../handling/TestContextComparison.java | 189 ------------- .../enginemodel/concepts/EngineModelTest.java | 188 +++++++++++++ .../enginemodel/concepts/EngineStatsTest.java | 201 ++++++++++++++ .../enginemodel/concepts/TestEngineModel.java | 188 ------------- .../enginemodel/concepts/TestEngineStats.java | 201 -------------- .../enginemodel/handling/ApexEngineModelTest.java | 110 ++++++++ .../enginemodel/handling/TestApexEngineModel.java | 110 -------- .../model/eventmodel/concepts/EventModelTest.java | 90 ++++++ .../apex/model/eventmodel/concepts/EventsTest.java | 299 ++++++++++++++++++++ .../apex/model/eventmodel/concepts/FieldTest.java | 138 +++++++++ .../model/eventmodel/concepts/TestEventModel.java | 90 ------ .../apex/model/eventmodel/concepts/TestEvents.java | 299 -------------------- .../apex/model/eventmodel/concepts/TestField.java | 138 --------- .../eventmodel/handling/ApexEventModelTest.java | 308 +++++++++++++++++++++ .../eventmodel/handling/TestApexEventModel.java | 308 --------------------- 62 files changed, 4272 insertions(+), 4272 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 create mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java create mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextModelTest.java create mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java delete mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextAlbums.java delete mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextModel.java delete mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextSchemas.java create mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java create mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ContextComparisonTest.java delete mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestApexContextModel.java delete mode 100644 model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestContextComparison.java create mode 100644 model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineModelTest.java create mode 100644 model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java delete mode 100644 model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineModel.java delete mode 100644 model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineStats.java create mode 100644 model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java delete mode 100644 model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModel.java create mode 100644 model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventModelTest.java create mode 100644 model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventsTest.java create mode 100644 model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/FieldTest.java delete mode 100644 model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/TestEventModel.java delete mode 100644 model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/TestEvents.java delete mode 100644 model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/TestField.java create mode 100644 model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/ApexEventModelTest.java delete mode 100644 model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/TestApexEventModel.java (limited to 'model') 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()); - } -} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java new file mode 100644 index 000000000..eb0db0da7 --- /dev/null +++ b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextAlbumsTest.java @@ -0,0 +1,212 @@ +/*- + * ============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.contextmodel.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 static org.junit.Assert.fail; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +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.contextmodel.concepts.AxContextAlbum; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums; + +/** + * Context album tests. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ContextAlbumsTest { + + @Test + public void testContextAlbums() { + assertNotNull(new AxContextAlbum()); + assertNotNull(new AxContextAlbum(new AxArtifactKey())); + assertNotNull(new AxContextAlbum(new AxArtifactKey(), "AlbumScope", false, new AxArtifactKey())); + + final AxArtifactKey albumKey = new AxArtifactKey("AlbumName", "0.0.1"); + final AxArtifactKey albumSchemaKey = new AxArtifactKey("AlbumSchemaName", "0.0.1"); + + final AxContextAlbum album = new AxContextAlbum(albumKey, "AlbumScope", false, albumSchemaKey); + assertNotNull(album); + + final AxArtifactKey newKey = new AxArtifactKey("NewAlbumName", "0.0.1"); + album.setKey(newKey); + assertEquals("NewAlbumName:0.0.1", album.getKey().getId()); + assertEquals("NewAlbumName:0.0.1", album.getKeys().get(0).getId()); + album.setKey(albumKey); + + try { + album.setScope(""); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals("parameter \"scope\": value \"\", does not match regular expression \"[A-Za-z0-9\\-_]+\"", + e.getMessage()); + } + + album.setScope("NewAlbumScope"); + assertEquals("NewAlbumScope", album.getScope()); + + assertEquals(false, album.isWritable()); + album.setWritable(true); + assertEquals(true, album.isWritable()); + + final AxArtifactKey newSchemaKey = new AxArtifactKey("NewAlbumSchemaName", "0.0.1"); + album.setItemSchema(newSchemaKey); + assertEquals("NewAlbumSchemaName:0.0.1", album.getItemSchema().getId()); + album.setItemSchema(albumSchemaKey); + + AxValidationResult result = new AxValidationResult(); + result = album.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + album.setKey(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = album.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + album.setKey(newKey); + result = new AxValidationResult(); + result = album.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + album.setScope("UNDEFINED"); + result = new AxValidationResult(); + result = album.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + album.setScope("NewAlbumScope"); + result = new AxValidationResult(); + result = album.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + album.setItemSchema(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = album.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + album.setItemSchema(albumSchemaKey); + result = new AxValidationResult(); + result = album.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + album.clean(); + + final AxContextAlbum clonedAlbum = new AxContextAlbum(album); + assertEquals("AxContextAlbum:(key=AxArtifactKey:(name=NewAlbumName,version=0.0.1)," + + "scope=NewAlbumScope,isWritable=true,itemSchema=" + + "AxArtifactKey:(name=AlbumSchemaName,version=0.0.1))", clonedAlbum.toString()); + + assertFalse(album.hashCode() == 0); + + assertTrue(album.equals(album)); + assertTrue(album.equals(clonedAlbum)); + assertFalse(album.equals(null)); + assertFalse(album.equals("Hello")); + assertFalse(album.equals(new AxContextAlbum(new AxArtifactKey(), "Scope", false, AxArtifactKey.getNullKey()))); + assertFalse(album.equals(new AxContextAlbum(newKey, "Scope", false, AxArtifactKey.getNullKey()))); + assertFalse(album.equals(new AxContextAlbum(newKey, "NewAlbumScope", false, AxArtifactKey.getNullKey()))); + assertFalse(album.equals(new AxContextAlbum(newKey, "NewAlbumScope", true, AxArtifactKey.getNullKey()))); + assertTrue(album.equals(new AxContextAlbum(newKey, "NewAlbumScope", true, albumSchemaKey))); + + assertEquals(0, album.compareTo(album)); + assertEquals(0, album.compareTo(clonedAlbum)); + assertNotEquals(0, album.compareTo(null)); + assertNotEquals(0, album.compareTo(new AxArtifactKey())); + assertNotEquals(0, album.compareTo( + new AxContextAlbum(new AxArtifactKey(), "Scope", false, AxArtifactKey.getNullKey()))); + assertNotEquals(0, album.compareTo(new AxContextAlbum(newKey, "Scope", false, AxArtifactKey.getNullKey()))); + assertNotEquals(0, album + .compareTo(new AxContextAlbum(newKey, "NewAlbumScope", false, AxArtifactKey.getNullKey()))); + assertNotEquals(0, + album.compareTo(new AxContextAlbum(newKey, "NewAlbumScope", true, AxArtifactKey.getNullKey()))); + assertEquals(0, album.compareTo(new AxContextAlbum(newKey, "NewAlbumScope", true, albumSchemaKey))); + + final AxContextAlbums albums = new AxContextAlbums(); + result = new AxValidationResult(); + result = albums.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + // Observation, no albums in album map + albums.setKey(new AxArtifactKey("AlbumsKey", "0.0.1")); + result = new AxValidationResult(); + result = albums.validate(result); + assertEquals(ValidationResult.OBSERVATION, result.getValidationResult()); + + albums.getAlbumsMap().put(newKey, album); + result = new AxValidationResult(); + result = albums.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + albums.getAlbumsMap().put(AxArtifactKey.getNullKey(), null); + result = new AxValidationResult(); + result = albums.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + albums.getAlbumsMap().remove(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = albums.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + albums.getAlbumsMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null); + result = new AxValidationResult(); + result = albums.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + albums.getAlbumsMap().remove(new AxArtifactKey("NullValueKey", "0.0.1")); + result = new AxValidationResult(); + result = albums.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + albums.clean(); + + final AxContextAlbums clonedAlbums = new AxContextAlbums(albums); + assertTrue(clonedAlbums.toString().startsWith( + "AxContextAlbums:(AxContextAlbums:(key=AxArtifactKey:(name=AlbumsKey,version=0.0.1)")); + + assertFalse(albums.hashCode() == 0); + + assertTrue(albums.equals(albums)); + assertTrue(albums.equals(clonedAlbums)); + assertFalse(albums.equals(null)); + assertFalse(albums.equals("Hello")); + assertFalse(albums.equals(new AxContextAlbums(new AxArtifactKey()))); + + assertEquals(0, albums.compareTo(albums)); + assertEquals(0, albums.compareTo(clonedAlbums)); + assertNotEquals(0, albums.compareTo(null)); + assertNotEquals(0, albums.compareTo(new AxArtifactKey())); + assertNotEquals(0, albums.compareTo(new AxContextAlbums(new AxArtifactKey()))); + + clonedAlbums.get(newKey).setScope("YetAnotherScope"); + assertNotEquals(0, albums.compareTo(clonedAlbums)); + + assertEquals("NewAlbumName", albums.get("NewAlbumName").getKey().getName()); + assertEquals("NewAlbumName", albums.get("NewAlbumName", "0.0.1").getKey().getName()); + assertEquals(1, albums.getAll("NewAlbumName", "0.0.1").size()); + assertEquals(0, albums.getAll("NonExistantAlbumName").size()); + } +} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextModelTest.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextModelTest.java new file mode 100644 index 000000000..fbf97881f --- /dev/null +++ b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextModelTest.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.contextmodel.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.AxKeyInformation; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; + +/** + * Context model tests. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ContextModelTest { + + @Test + public void test() { + assertNotNull(new AxContextModel()); + assertNotNull(new AxContextModel(new AxArtifactKey())); + assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation())); + assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(), + new AxKeyInformation())); + + final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1"); + final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1"); + final AxArtifactKey albumsKey = new AxArtifactKey("SchemasKey", "0.0.1"); + final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1"); + final AxContextModel model = new AxContextModel(modelKey, new AxContextSchemas(schemasKey), + new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey)); + model.register(); + + model.clean(); + assertNotNull(model); + assertEquals("AxContextModel:(AxContextModel:(key=AxArtifactKey:", model.toString().substring(0, 50)); + + final AxContextModel clonedModel = new AxContextModel(model); + + assertFalse(model.hashCode() == 0); + + assertTrue(model.equals(model)); + assertTrue(model.equals(clonedModel)); + assertFalse(model.equals("Hello")); + assertFalse(model.equals(new AxContextModel(new AxArtifactKey()))); + assertFalse(model.equals(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(), + new AxKeyInformation()))); + assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), + new AxKeyInformation()))); + assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), + new AxKeyInformation(keyInfoKey)))); + assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), new AxContextAlbums(), + new AxKeyInformation(keyInfoKey)))); + assertTrue(model.equals(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), + new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey)))); + + assertEquals(0, model.compareTo(model)); + assertEquals(0, model.compareTo(clonedModel)); + assertNotEquals(0, model.compareTo(new AxArtifactKey())); + assertNotEquals(0, model.compareTo(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), + new AxContextAlbums(), new AxKeyInformation()))); + assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), + new AxKeyInformation()))); + assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), + new AxKeyInformation(keyInfoKey)))); + assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), + new AxContextAlbums(), new AxKeyInformation(keyInfoKey)))); + assertEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), + new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey)))); + } +} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java new file mode 100644 index 000000000..73f4c3086 --- /dev/null +++ b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/ContextSchemasTest.java @@ -0,0 +1,195 @@ +/*- + * ============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.contextmodel.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 static org.junit.Assert.fail; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +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.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; + +/** + * Context schema tests. + */ +public class ContextSchemasTest { + + @Test + public void testContextSchemas() { + assertNotNull(new AxContextSchema()); + assertNotNull(new AxContextSchema(new AxArtifactKey(), "SchemaFlavour", "SchemaDefinition")); + + final AxContextSchema schema = new AxContextSchema(new AxArtifactKey("SchemaName", "0.0.1"), "SchemaFlavour", + "SchemaDefinition"); + assertNotNull(schema); + + final AxArtifactKey newKey = new AxArtifactKey("NewSchemaName", "0.0.1"); + schema.setKey(newKey); + assertEquals("NewSchemaName:0.0.1", schema.getKey().getId()); + assertEquals("NewSchemaName:0.0.1", schema.getKeys().get(0).getId()); + + try { + schema.setSchemaFlavour(""); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals("parameter \"schemaFlavour\": value \"\", " + + "does not match regular expression \"[A-Za-z0-9\\-_]+\"", e.getMessage()); + } + + schema.setSchemaFlavour("NewSchemaFlavour"); + assertEquals("NewSchemaFlavour", schema.getSchemaFlavour()); + + schema.setSchema("NewSchemaDefinition"); + assertEquals("NewSchemaDefinition", schema.getSchema()); + + AxValidationResult result = new AxValidationResult(); + result = schema.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + schema.setKey(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = schema.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + schema.setKey(newKey); + result = new AxValidationResult(); + result = schema.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + schema.setSchemaFlavour("UNDEFINED"); + result = new AxValidationResult(); + result = schema.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + schema.setSchemaFlavour("NewSchemaFlavour"); + result = new AxValidationResult(); + result = schema.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + schema.setSchema(""); + result = new AxValidationResult(); + result = schema.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + schema.setSchema("NewSchemaDefinition"); + result = new AxValidationResult(); + result = schema.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + schema.clean(); + + final AxContextSchema clonedSchema = new AxContextSchema(schema); + assertEquals("AxContextSchema:(key=AxArtifactKey:(name=NewSchemaName,version=0.0.1)," + + "schemaFlavour=NewSchemaFlavour,schemaDefinition=NewSchemaDefinition)", + clonedSchema.toString()); + + assertFalse(schema.hashCode() == 0); + + assertTrue(schema.equals(schema)); + assertTrue(schema.equals(clonedSchema)); + assertFalse(schema.equals(null)); + assertFalse(schema.equals((Object) "Hello")); + assertFalse(schema.equals(new AxContextSchema(new AxArtifactKey(), "Flavour", "Def"))); + assertFalse(schema.equals(new AxContextSchema(newKey, "Flavour", "Def"))); + assertFalse(schema.equals(new AxContextSchema(newKey, "NewSchemaFlavour", "Def"))); + assertTrue(schema.equals(new AxContextSchema(newKey, "NewSchemaFlavour", "NewSchemaDefinition"))); + + assertEquals(0, schema.compareTo(schema)); + assertEquals(0, schema.compareTo(clonedSchema)); + assertNotEquals(0, schema.compareTo(null)); + assertNotEquals(0, schema.compareTo(new AxArtifactKey())); + assertNotEquals(0, schema.compareTo(new AxContextSchema(new AxArtifactKey(), "Flavour", "Def"))); + assertNotEquals(0, schema.compareTo(new AxContextSchema(newKey, "Flavour", "Def"))); + assertNotEquals(0, schema.compareTo(new AxContextSchema(newKey, "NewSchemaFlavour", "Def"))); + assertEquals(0, schema.compareTo(new AxContextSchema(newKey, "NewSchemaFlavour", "NewSchemaDefinition"))); + + final AxContextSchemas schemas = new AxContextSchemas(); + result = new AxValidationResult(); + result = schemas.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + // Still invalid, no schemas in schema map + schemas.setKey(new AxArtifactKey("SchemasKey", "0.0.1")); + result = new AxValidationResult(); + result = schemas.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + schemas.getSchemasMap().put(newKey, schema); + result = new AxValidationResult(); + result = schemas.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + schemas.getSchemasMap().put(AxArtifactKey.getNullKey(), null); + result = new AxValidationResult(); + result = schemas.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + schemas.getSchemasMap().remove(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = schemas.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + schemas.getSchemasMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null); + result = new AxValidationResult(); + result = schemas.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + schemas.getSchemasMap().remove(new AxArtifactKey("NullValueKey", "0.0.1")); + result = new AxValidationResult(); + result = schemas.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + schemas.clean(); + + final AxContextSchemas clonedSchemas = new AxContextSchemas(schemas); + assertTrue(clonedSchemas.toString() + .startsWith("AxContextSchemas:(key=AxArtifactKey:(name=SchemasKey,version=0.0.1),")); + + assertFalse(schemas.hashCode() == 0); + + assertTrue(schemas.equals(schemas)); + assertTrue(schemas.equals(clonedSchemas)); + assertFalse(schemas.equals(null)); + assertFalse(schemas.equals((Object) "Hello")); + assertFalse(schemas.equals(new AxContextSchemas(new AxArtifactKey()))); + + assertEquals(0, schemas.compareTo(schemas)); + assertEquals(0, schemas.compareTo(clonedSchemas)); + assertNotEquals(0, schemas.compareTo(null)); + assertNotEquals(0, schemas.compareTo(new AxArtifactKey())); + assertNotEquals(0, schemas.compareTo(new AxContextSchemas(new AxArtifactKey()))); + + clonedSchemas.get(newKey).setSchemaFlavour("YetAnotherFlavour"); + assertNotEquals(0, schemas.compareTo(clonedSchemas)); + + assertEquals("NewSchemaName", schemas.get("NewSchemaName").getKey().getName()); + assertEquals("NewSchemaName", schemas.get("NewSchemaName", "0.0.1").getKey().getName()); + assertEquals(1, schemas.getAll("NewSchemaName", "0.0.1").size()); + assertEquals(0, schemas.getAll("NonExistantSchemaName").size()); + } +} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextAlbums.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextAlbums.java deleted file mode 100644 index 6ba0b2fa6..000000000 --- a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextAlbums.java +++ /dev/null @@ -1,212 +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.contextmodel.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 static org.junit.Assert.fail; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -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.contextmodel.concepts.AxContextAlbum; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums; - -/** - * Context album tests. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestContextAlbums { - - @Test - public void testContextAlbums() { - assertNotNull(new AxContextAlbum()); - assertNotNull(new AxContextAlbum(new AxArtifactKey())); - assertNotNull(new AxContextAlbum(new AxArtifactKey(), "AlbumScope", false, new AxArtifactKey())); - - final AxArtifactKey albumKey = new AxArtifactKey("AlbumName", "0.0.1"); - final AxArtifactKey albumSchemaKey = new AxArtifactKey("AlbumSchemaName", "0.0.1"); - - final AxContextAlbum album = new AxContextAlbum(albumKey, "AlbumScope", false, albumSchemaKey); - assertNotNull(album); - - final AxArtifactKey newKey = new AxArtifactKey("NewAlbumName", "0.0.1"); - album.setKey(newKey); - assertEquals("NewAlbumName:0.0.1", album.getKey().getId()); - assertEquals("NewAlbumName:0.0.1", album.getKeys().get(0).getId()); - album.setKey(albumKey); - - try { - album.setScope(""); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals("parameter \"scope\": value \"\", does not match regular expression \"[A-Za-z0-9\\-_]+\"", - e.getMessage()); - } - - album.setScope("NewAlbumScope"); - assertEquals("NewAlbumScope", album.getScope()); - - assertEquals(false, album.isWritable()); - album.setWritable(true); - assertEquals(true, album.isWritable()); - - final AxArtifactKey newSchemaKey = new AxArtifactKey("NewAlbumSchemaName", "0.0.1"); - album.setItemSchema(newSchemaKey); - assertEquals("NewAlbumSchemaName:0.0.1", album.getItemSchema().getId()); - album.setItemSchema(albumSchemaKey); - - AxValidationResult result = new AxValidationResult(); - result = album.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - album.setKey(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = album.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - album.setKey(newKey); - result = new AxValidationResult(); - result = album.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - album.setScope("UNDEFINED"); - result = new AxValidationResult(); - result = album.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - album.setScope("NewAlbumScope"); - result = new AxValidationResult(); - result = album.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - album.setItemSchema(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = album.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - album.setItemSchema(albumSchemaKey); - result = new AxValidationResult(); - result = album.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - album.clean(); - - final AxContextAlbum clonedAlbum = new AxContextAlbum(album); - assertEquals("AxContextAlbum:(key=AxArtifactKey:(name=NewAlbumName,version=0.0.1)," - + "scope=NewAlbumScope,isWritable=true,itemSchema=" - + "AxArtifactKey:(name=AlbumSchemaName,version=0.0.1))", clonedAlbum.toString()); - - assertFalse(album.hashCode() == 0); - - assertTrue(album.equals(album)); - assertTrue(album.equals(clonedAlbum)); - assertFalse(album.equals(null)); - assertFalse(album.equals("Hello")); - assertFalse(album.equals(new AxContextAlbum(new AxArtifactKey(), "Scope", false, AxArtifactKey.getNullKey()))); - assertFalse(album.equals(new AxContextAlbum(newKey, "Scope", false, AxArtifactKey.getNullKey()))); - assertFalse(album.equals(new AxContextAlbum(newKey, "NewAlbumScope", false, AxArtifactKey.getNullKey()))); - assertFalse(album.equals(new AxContextAlbum(newKey, "NewAlbumScope", true, AxArtifactKey.getNullKey()))); - assertTrue(album.equals(new AxContextAlbum(newKey, "NewAlbumScope", true, albumSchemaKey))); - - assertEquals(0, album.compareTo(album)); - assertEquals(0, album.compareTo(clonedAlbum)); - assertNotEquals(0, album.compareTo(null)); - assertNotEquals(0, album.compareTo(new AxArtifactKey())); - assertNotEquals(0, album.compareTo( - new AxContextAlbum(new AxArtifactKey(), "Scope", false, AxArtifactKey.getNullKey()))); - assertNotEquals(0, album.compareTo(new AxContextAlbum(newKey, "Scope", false, AxArtifactKey.getNullKey()))); - assertNotEquals(0, album - .compareTo(new AxContextAlbum(newKey, "NewAlbumScope", false, AxArtifactKey.getNullKey()))); - assertNotEquals(0, - album.compareTo(new AxContextAlbum(newKey, "NewAlbumScope", true, AxArtifactKey.getNullKey()))); - assertEquals(0, album.compareTo(new AxContextAlbum(newKey, "NewAlbumScope", true, albumSchemaKey))); - - final AxContextAlbums albums = new AxContextAlbums(); - result = new AxValidationResult(); - result = albums.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - // Observation, no albums in album map - albums.setKey(new AxArtifactKey("AlbumsKey", "0.0.1")); - result = new AxValidationResult(); - result = albums.validate(result); - assertEquals(ValidationResult.OBSERVATION, result.getValidationResult()); - - albums.getAlbumsMap().put(newKey, album); - result = new AxValidationResult(); - result = albums.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - albums.getAlbumsMap().put(AxArtifactKey.getNullKey(), null); - result = new AxValidationResult(); - result = albums.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - albums.getAlbumsMap().remove(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = albums.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - albums.getAlbumsMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null); - result = new AxValidationResult(); - result = albums.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - albums.getAlbumsMap().remove(new AxArtifactKey("NullValueKey", "0.0.1")); - result = new AxValidationResult(); - result = albums.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - albums.clean(); - - final AxContextAlbums clonedAlbums = new AxContextAlbums(albums); - assertTrue(clonedAlbums.toString().startsWith( - "AxContextAlbums:(AxContextAlbums:(key=AxArtifactKey:(name=AlbumsKey,version=0.0.1)")); - - assertFalse(albums.hashCode() == 0); - - assertTrue(albums.equals(albums)); - assertTrue(albums.equals(clonedAlbums)); - assertFalse(albums.equals(null)); - assertFalse(albums.equals("Hello")); - assertFalse(albums.equals(new AxContextAlbums(new AxArtifactKey()))); - - assertEquals(0, albums.compareTo(albums)); - assertEquals(0, albums.compareTo(clonedAlbums)); - assertNotEquals(0, albums.compareTo(null)); - assertNotEquals(0, albums.compareTo(new AxArtifactKey())); - assertNotEquals(0, albums.compareTo(new AxContextAlbums(new AxArtifactKey()))); - - clonedAlbums.get(newKey).setScope("YetAnotherScope"); - assertNotEquals(0, albums.compareTo(clonedAlbums)); - - assertEquals("NewAlbumName", albums.get("NewAlbumName").getKey().getName()); - assertEquals("NewAlbumName", albums.get("NewAlbumName", "0.0.1").getKey().getName()); - assertEquals(1, albums.getAll("NewAlbumName", "0.0.1").size()); - assertEquals(0, albums.getAll("NonExistantAlbumName").size()); - } -} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextModel.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextModel.java deleted file mode 100644 index 290183e5f..000000000 --- a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextModel.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.contextmodel.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.AxKeyInformation; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; - -/** - * Context model tests. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestContextModel { - - @Test - public void test() { - assertNotNull(new AxContextModel()); - assertNotNull(new AxContextModel(new AxArtifactKey())); - assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation())); - assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(), - new AxKeyInformation())); - - final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1"); - final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1"); - final AxArtifactKey albumsKey = new AxArtifactKey("SchemasKey", "0.0.1"); - final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1"); - final AxContextModel model = new AxContextModel(modelKey, new AxContextSchemas(schemasKey), - new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey)); - model.register(); - - model.clean(); - assertNotNull(model); - assertEquals("AxContextModel:(AxContextModel:(key=AxArtifactKey:", model.toString().substring(0, 50)); - - final AxContextModel clonedModel = new AxContextModel(model); - - assertFalse(model.hashCode() == 0); - - assertTrue(model.equals(model)); - assertTrue(model.equals(clonedModel)); - assertFalse(model.equals("Hello")); - assertFalse(model.equals(new AxContextModel(new AxArtifactKey()))); - assertFalse(model.equals(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(), - new AxKeyInformation()))); - assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), - new AxKeyInformation()))); - assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), - new AxKeyInformation(keyInfoKey)))); - assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), new AxContextAlbums(), - new AxKeyInformation(keyInfoKey)))); - assertTrue(model.equals(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), - new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey)))); - - assertEquals(0, model.compareTo(model)); - assertEquals(0, model.compareTo(clonedModel)); - assertNotEquals(0, model.compareTo(new AxArtifactKey())); - assertNotEquals(0, model.compareTo(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), - new AxContextAlbums(), new AxKeyInformation()))); - assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), - new AxKeyInformation()))); - assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), - new AxKeyInformation(keyInfoKey)))); - assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), - new AxContextAlbums(), new AxKeyInformation(keyInfoKey)))); - assertEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), - new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey)))); - } -} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextSchemas.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextSchemas.java deleted file mode 100644 index a8dde7781..000000000 --- a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/concepts/TestContextSchemas.java +++ /dev/null @@ -1,195 +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.contextmodel.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 static org.junit.Assert.fail; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -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.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; - -/** - * Context schema tests. - */ -public class TestContextSchemas { - - @Test - public void testContextSchemas() { - assertNotNull(new AxContextSchema()); - assertNotNull(new AxContextSchema(new AxArtifactKey(), "SchemaFlavour", "SchemaDefinition")); - - final AxContextSchema schema = new AxContextSchema(new AxArtifactKey("SchemaName", "0.0.1"), "SchemaFlavour", - "SchemaDefinition"); - assertNotNull(schema); - - final AxArtifactKey newKey = new AxArtifactKey("NewSchemaName", "0.0.1"); - schema.setKey(newKey); - assertEquals("NewSchemaName:0.0.1", schema.getKey().getId()); - assertEquals("NewSchemaName:0.0.1", schema.getKeys().get(0).getId()); - - try { - schema.setSchemaFlavour(""); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals("parameter \"schemaFlavour\": value \"\", " - + "does not match regular expression \"[A-Za-z0-9\\-_]+\"", e.getMessage()); - } - - schema.setSchemaFlavour("NewSchemaFlavour"); - assertEquals("NewSchemaFlavour", schema.getSchemaFlavour()); - - schema.setSchema("NewSchemaDefinition"); - assertEquals("NewSchemaDefinition", schema.getSchema()); - - AxValidationResult result = new AxValidationResult(); - result = schema.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - schema.setKey(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = schema.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - schema.setKey(newKey); - result = new AxValidationResult(); - result = schema.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - schema.setSchemaFlavour("UNDEFINED"); - result = new AxValidationResult(); - result = schema.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - schema.setSchemaFlavour("NewSchemaFlavour"); - result = new AxValidationResult(); - result = schema.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - schema.setSchema(""); - result = new AxValidationResult(); - result = schema.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - schema.setSchema("NewSchemaDefinition"); - result = new AxValidationResult(); - result = schema.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - schema.clean(); - - final AxContextSchema clonedSchema = new AxContextSchema(schema); - assertEquals("AxContextSchema:(key=AxArtifactKey:(name=NewSchemaName,version=0.0.1)," - + "schemaFlavour=NewSchemaFlavour,schemaDefinition=NewSchemaDefinition)", - clonedSchema.toString()); - - assertFalse(schema.hashCode() == 0); - - assertTrue(schema.equals(schema)); - assertTrue(schema.equals(clonedSchema)); - assertFalse(schema.equals(null)); - assertFalse(schema.equals((Object) "Hello")); - assertFalse(schema.equals(new AxContextSchema(new AxArtifactKey(), "Flavour", "Def"))); - assertFalse(schema.equals(new AxContextSchema(newKey, "Flavour", "Def"))); - assertFalse(schema.equals(new AxContextSchema(newKey, "NewSchemaFlavour", "Def"))); - assertTrue(schema.equals(new AxContextSchema(newKey, "NewSchemaFlavour", "NewSchemaDefinition"))); - - assertEquals(0, schema.compareTo(schema)); - assertEquals(0, schema.compareTo(clonedSchema)); - assertNotEquals(0, schema.compareTo(null)); - assertNotEquals(0, schema.compareTo(new AxArtifactKey())); - assertNotEquals(0, schema.compareTo(new AxContextSchema(new AxArtifactKey(), "Flavour", "Def"))); - assertNotEquals(0, schema.compareTo(new AxContextSchema(newKey, "Flavour", "Def"))); - assertNotEquals(0, schema.compareTo(new AxContextSchema(newKey, "NewSchemaFlavour", "Def"))); - assertEquals(0, schema.compareTo(new AxContextSchema(newKey, "NewSchemaFlavour", "NewSchemaDefinition"))); - - final AxContextSchemas schemas = new AxContextSchemas(); - result = new AxValidationResult(); - result = schemas.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - // Still invalid, no schemas in schema map - schemas.setKey(new AxArtifactKey("SchemasKey", "0.0.1")); - result = new AxValidationResult(); - result = schemas.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - schemas.getSchemasMap().put(newKey, schema); - result = new AxValidationResult(); - result = schemas.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - schemas.getSchemasMap().put(AxArtifactKey.getNullKey(), null); - result = new AxValidationResult(); - result = schemas.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - schemas.getSchemasMap().remove(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = schemas.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - schemas.getSchemasMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null); - result = new AxValidationResult(); - result = schemas.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - schemas.getSchemasMap().remove(new AxArtifactKey("NullValueKey", "0.0.1")); - result = new AxValidationResult(); - result = schemas.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - schemas.clean(); - - final AxContextSchemas clonedSchemas = new AxContextSchemas(schemas); - assertTrue(clonedSchemas.toString() - .startsWith("AxContextSchemas:(key=AxArtifactKey:(name=SchemasKey,version=0.0.1),")); - - assertFalse(schemas.hashCode() == 0); - - assertTrue(schemas.equals(schemas)); - assertTrue(schemas.equals(clonedSchemas)); - assertFalse(schemas.equals(null)); - assertFalse(schemas.equals((Object) "Hello")); - assertFalse(schemas.equals(new AxContextSchemas(new AxArtifactKey()))); - - assertEquals(0, schemas.compareTo(schemas)); - assertEquals(0, schemas.compareTo(clonedSchemas)); - assertNotEquals(0, schemas.compareTo(null)); - assertNotEquals(0, schemas.compareTo(new AxArtifactKey())); - assertNotEquals(0, schemas.compareTo(new AxContextSchemas(new AxArtifactKey()))); - - clonedSchemas.get(newKey).setSchemaFlavour("YetAnotherFlavour"); - assertNotEquals(0, schemas.compareTo(clonedSchemas)); - - assertEquals("NewSchemaName", schemas.get("NewSchemaName").getKey().getName()); - assertEquals("NewSchemaName", schemas.get("NewSchemaName", "0.0.1").getKey().getName()); - assertEquals(1, schemas.getAll("NewSchemaName", "0.0.1").size()); - assertEquals(0, schemas.getAll("NonExistantSchemaName").size()); - } -} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java new file mode 100644 index 000000000..948c2024c --- /dev/null +++ b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java @@ -0,0 +1,153 @@ +/*- + * ============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.contextmodel.handling; + +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.AxValidationResult; +import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; +import org.onap.policy.apex.model.basicmodel.test.TestApexModel; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; + +/** + * Apex context model tests. + * + * @author liam + * + */ +public class ApexContextModelTest { + private Connection connection; + TestApexModel testApexModel; + + /** + * Set up tests. + * + * @throws Exception a testing exception + */ + @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(AxContextModel.class, new TestApexContextModelCreator()); + } + + @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 { + final AxValidationResult result = testApexModel.testApexModelVaidateObservation(); + assertTrue(result.toString().equals(OBSERVATION_MODEL_STRING)); + } + + @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); + } + + private static final String VALID_MODEL_STRING = "***validation of model successful***"; + + private static final String OBSERVATION_MODEL_STRING = "\n" + + "***observations noted during validation of model***\n" + + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):" + + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo:OBSERVATION:description is blank\n" + + "********************************"; + + private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n" + + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):" + + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo:WARNING:" + + "UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n" + + "********************************"; + + private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n" + + "AxArtifactKey:(name=StringType,version=0.0.1):" + + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema:INVALID:" + + "no schemaDefinition specified, schemaDefinition may not be blank\n" + + "AxArtifactKey:(name=contextAlbum0,version=0.0.1):" + + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:" + + "scope is not defined\n" + "********************************"; + + private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n" + + "AxArtifactKey:(name=ContextModel,version=0.0.1):" + + "org.onap.policy.apex.model.contextmodel.concepts.AxContextModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=contextAlbum1,version=0.0.2)\n" + + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):" + + "org.onap.policy.apex.model.contextmodel.concepts.AxContextModel:WARNING:" + + "key not found for key information entry\n" + "AxArtifactKey:(name=ContextSchemas,version=0.0.1):" + + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas:INVALID:" + + "key on schemas entry AxArtifactKey:(name=MapType,version=0.0.1) " + + "does not equal entry key AxArtifactKey:(name=MapType,version=0.0.2)\n" + + "AxArtifactKey:(name=contextAlbums,version=0.0.1):" + + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums:INVALID:" + + "key on context album entry key AxArtifactKey:(name=contextAlbum1,version=0.0.1) " + + "does not equal context album value key AxArtifactKey:(name=contextAlbum1,version=0.0.2)\n" + + "********************************"; + +} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ContextComparisonTest.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ContextComparisonTest.java new file mode 100644 index 000000000..81609cacf --- /dev/null +++ b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ContextComparisonTest.java @@ -0,0 +1,189 @@ +/*- + * ============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.contextmodel.handling; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; +import org.onap.policy.apex.model.contextmodel.handling.ContextComparer; +import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference; + +/** + * Test context comparisons. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class ContextComparisonTest { + private AxContextModel emptyModel; + private AxContextModel fullModel; + private AxContextModel noGlobalContextModel; + private AxContextModel shellModel; + private AxContextModel singleEntryModel; + + /** + * Set up tests. + */ + @Before + public void getContext() { + final TestContextComparisonFactory factory = new TestContextComparisonFactory(); + emptyModel = factory.getEmptyModel(); + fullModel = factory.getFullModel(); + noGlobalContextModel = factory.getNoGlobalContextModel(); + shellModel = factory.getShellModel(); + singleEntryModel = factory.getSingleEntryModel(); + } + + @Test + public void testEmptyEmpty() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(emptyModel.getSchemas(), emptyModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(emptyModel.getSchemas().getSchemasMap().equals(schemaResult.getIdenticalValues())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(emptyModel.getAlbums(), emptyModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(emptyModel.getAlbums().getAlbumsMap().equals(albumResult.getIdenticalValues())); + } + + @Test + public void testEmptyFull() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(emptyModel.getSchemas(), fullModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(emptyModel.getAlbums(), fullModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly())); + } + + @Test + public void testFullEmpty() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(fullModel.getSchemas(), emptyModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(fullModel.getAlbums(), emptyModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly())); + } + + @Test + public void testEmptyNoGlobalContext() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(emptyModel.getSchemas(), noGlobalContextModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(noGlobalContextModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(emptyModel.getAlbums(), noGlobalContextModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(noGlobalContextModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly())); + } + + @Test + public void testNoGlobalContextEmpty() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(noGlobalContextModel.getSchemas(), emptyModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(noGlobalContextModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(noGlobalContextModel.getAlbums(), emptyModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(noGlobalContextModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly())); + } + + @Test + public void testEmptyShell() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(emptyModel.getSchemas(), shellModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(shellModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(emptyModel.getAlbums(), shellModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(shellModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly())); + } + + @Test + public void testShellEmpty() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(shellModel.getSchemas(), emptyModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(shellModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(shellModel.getAlbums(), emptyModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(shellModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly())); + } + + @Test + public void testEmptySingleEntry() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(emptyModel.getSchemas(), singleEntryModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(singleEntryModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(emptyModel.getAlbums(), singleEntryModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(singleEntryModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly())); + } + + @Test + public void testSingleEntryEmpty() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(singleEntryModel.getSchemas(), emptyModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(singleEntryModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(singleEntryModel.getAlbums(), emptyModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(singleEntryModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly())); + } + + @Test + public void testFullFull() { + final KeyedMapDifference schemaResult = new ContextComparer() + .compare(fullModel.getSchemas(), fullModel.getSchemas()); + assertNotNull(schemaResult); + assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getIdenticalValues())); + + final KeyedMapDifference albumResult = new ContextComparer() + .compare(fullModel.getAlbums(), fullModel.getAlbums()); + assertNotNull(albumResult); + assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getIdenticalValues())); + } +} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestApexContextModel.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestApexContextModel.java deleted file mode 100644 index 94a36844f..000000000 --- a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestApexContextModel.java +++ /dev/null @@ -1,153 +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.contextmodel.handling; - -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.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; -import org.onap.policy.apex.model.basicmodel.test.TestApexModel; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; - -/** - * Apex context model tests. - * - * @author liam - * - */ -public class TestApexContextModel { - private Connection connection; - TestApexModel testApexModel; - - /** - * Set up tests. - * - * @throws Exception a testing exception - */ - @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(AxContextModel.class, new TestApexContextModelCreator()); - } - - @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 { - final AxValidationResult result = testApexModel.testApexModelVaidateObservation(); - assertTrue(result.toString().equals(OBSERVATION_MODEL_STRING)); - } - - @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); - } - - private static final String VALID_MODEL_STRING = "***validation of model successful***"; - - private static final String OBSERVATION_MODEL_STRING = "\n" - + "***observations noted during validation of model***\n" - + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):" - + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo:OBSERVATION:description is blank\n" - + "********************************"; - - private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n" - + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):" - + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo:WARNING:" - + "UUID is a zero UUID: 00000000-0000-0000-0000-000000000000\n" - + "********************************"; - - private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n" - + "AxArtifactKey:(name=StringType,version=0.0.1):" - + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema:INVALID:" - + "no schemaDefinition specified, schemaDefinition may not be blank\n" - + "AxArtifactKey:(name=contextAlbum0,version=0.0.1):" - + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum:INVALID:" - + "scope is not defined\n" + "********************************"; - - private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n" - + "AxArtifactKey:(name=ContextModel,version=0.0.1):" - + "org.onap.policy.apex.model.contextmodel.concepts.AxContextModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=contextAlbum1,version=0.0.2)\n" - + "AxArtifactKey:(name=contextAlbum1,version=0.0.1):" - + "org.onap.policy.apex.model.contextmodel.concepts.AxContextModel:WARNING:" - + "key not found for key information entry\n" + "AxArtifactKey:(name=ContextSchemas,version=0.0.1):" - + "org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas:INVALID:" - + "key on schemas entry AxArtifactKey:(name=MapType,version=0.0.1) " - + "does not equal entry key AxArtifactKey:(name=MapType,version=0.0.2)\n" - + "AxArtifactKey:(name=contextAlbums,version=0.0.1):" - + "org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums:INVALID:" - + "key on context album entry key AxArtifactKey:(name=contextAlbum1,version=0.0.1) " - + "does not equal context album value key AxArtifactKey:(name=contextAlbum1,version=0.0.2)\n" - + "********************************"; - -} diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestContextComparison.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestContextComparison.java deleted file mode 100644 index 65295c13b..000000000 --- a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/TestContextComparison.java +++ /dev/null @@ -1,189 +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.contextmodel.handling; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbum; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchema; -import org.onap.policy.apex.model.contextmodel.handling.ContextComparer; -import org.onap.policy.apex.model.utilities.comparison.KeyedMapDifference; - -/** - * Test context comparisons. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestContextComparison { - private AxContextModel emptyModel; - private AxContextModel fullModel; - private AxContextModel noGlobalContextModel; - private AxContextModel shellModel; - private AxContextModel singleEntryModel; - - /** - * Set up tests. - */ - @Before - public void getContext() { - final TestContextComparisonFactory factory = new TestContextComparisonFactory(); - emptyModel = factory.getEmptyModel(); - fullModel = factory.getFullModel(); - noGlobalContextModel = factory.getNoGlobalContextModel(); - shellModel = factory.getShellModel(); - singleEntryModel = factory.getSingleEntryModel(); - } - - @Test - public void testEmptyEmpty() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(emptyModel.getSchemas(), emptyModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(emptyModel.getSchemas().getSchemasMap().equals(schemaResult.getIdenticalValues())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(emptyModel.getAlbums(), emptyModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(emptyModel.getAlbums().getAlbumsMap().equals(albumResult.getIdenticalValues())); - } - - @Test - public void testEmptyFull() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(emptyModel.getSchemas(), fullModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(emptyModel.getAlbums(), fullModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly())); - } - - @Test - public void testFullEmpty() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(fullModel.getSchemas(), emptyModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(fullModel.getAlbums(), emptyModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly())); - } - - @Test - public void testEmptyNoGlobalContext() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(emptyModel.getSchemas(), noGlobalContextModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(noGlobalContextModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(emptyModel.getAlbums(), noGlobalContextModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(noGlobalContextModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly())); - } - - @Test - public void testNoGlobalContextEmpty() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(noGlobalContextModel.getSchemas(), emptyModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(noGlobalContextModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(noGlobalContextModel.getAlbums(), emptyModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(noGlobalContextModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly())); - } - - @Test - public void testEmptyShell() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(emptyModel.getSchemas(), shellModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(shellModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(emptyModel.getAlbums(), shellModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(shellModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly())); - } - - @Test - public void testShellEmpty() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(shellModel.getSchemas(), emptyModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(shellModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(shellModel.getAlbums(), emptyModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(shellModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly())); - } - - @Test - public void testEmptySingleEntry() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(emptyModel.getSchemas(), singleEntryModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(singleEntryModel.getSchemas().getSchemasMap().equals(schemaResult.getRightOnly())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(emptyModel.getAlbums(), singleEntryModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(singleEntryModel.getAlbums().getAlbumsMap().equals(albumResult.getRightOnly())); - } - - @Test - public void testSingleEntryEmpty() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(singleEntryModel.getSchemas(), emptyModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(singleEntryModel.getSchemas().getSchemasMap().equals(schemaResult.getLeftOnly())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(singleEntryModel.getAlbums(), emptyModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(singleEntryModel.getAlbums().getAlbumsMap().equals(albumResult.getLeftOnly())); - } - - @Test - public void testFullFull() { - final KeyedMapDifference schemaResult = new ContextComparer() - .compare(fullModel.getSchemas(), fullModel.getSchemas()); - assertNotNull(schemaResult); - assertTrue(fullModel.getSchemas().getSchemasMap().equals(schemaResult.getIdenticalValues())); - - final KeyedMapDifference albumResult = new ContextComparer() - .compare(fullModel.getAlbums(), fullModel.getAlbums()); - assertNotNull(albumResult); - assertTrue(fullModel.getAlbums().getAlbumsMap().equals(albumResult.getIdenticalValues())); - } -} diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineModelTest.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineModelTest.java new file mode 100644 index 000000000..392bdd53b --- /dev/null +++ b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineModelTest.java @@ -0,0 +1,188 @@ +/*- + * ============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.enginemodel.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 static org.junit.Assert.fail; + +import org.junit.Test; +import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation; +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.contextmodel.concepts.AxContextAlbums; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; + +/** + * Test engine models. + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class EngineModelTest { + + @Test + public void testEnginetModel() { + assertNotNull(new AxEngineModel()); + assertNotNull(new AxEngineModel(new AxArtifactKey())); + assertNotNull(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(), + new AxContextAlbums())); + assertNotNull(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(), + new AxContextAlbums(), AxEngineState.UNDEFINED, new AxEngineStats())); + + final AxArtifactKey modelKey = new AxArtifactKey("ModelName", "0.0.1"); + final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1"); + final AxArtifactKey albumKey = new AxArtifactKey("AlbumKey", "0.0.1"); + final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1"); + final AxEngineStats stats = new AxEngineStats(new AxReferenceKey(modelKey, "EngineStats")); + final AxEngineStats otherStats = new AxEngineStats(); + otherStats.setAverageExecutionTime(100); + + final AxEngineModel model = new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats); + model.register(); + + try { + model.setKey(null); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals("key may not be null", e.getMessage()); + } + + model.setKey(modelKey); + assertEquals("ModelName:0.0.1", model.getKey().getId()); + assertEquals("ModelName:0.0.1", model.getKeys().get(0).getId()); + + final long timestamp = System.currentTimeMillis(); + model.setTimestamp(timestamp); + assertEquals(timestamp, model.getTimestamp()); + model.setTimestamp(-1); + assertTrue(model.getTimeStampString().matches("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3}")); + + try { + model.setState(null); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals("state may not be null", e.getMessage()); + } + + for (final AxEngineState state : AxEngineState.values()) { + model.setState(state); + assertEquals(state, model.getState()); + } + + model.setState(AxEngineState.READY); + assertEquals(AxEngineState.READY, model.getState()); + + try { + model.setStats(null); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals("stats may not be null", e.getMessage()); + } + + model.setStats(stats); + assertEquals(stats, model.getStats()); + + model.clean(); + assertNotNull(model); + assertEquals("AxEngineModel:(AxEngineModel:(AxEngineModel:(key=A", model.toString().substring(0, 50)); + + final AxEngineModel clonedModel = new AxEngineModel(model); + + assertFalse(model.hashCode() == 0); + + assertTrue(model.equals(model)); + assertTrue(model.equals(clonedModel)); + assertFalse(model.equals("Hello")); + assertFalse(model.equals(new AxEngineModel(new AxArtifactKey()))); + assertFalse(model.equals(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); + assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(), new AxKeyInformation(keyInfoKey), + new AxContextAlbums(albumKey), AxEngineState.READY, stats))); + assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), new AxKeyInformation(), + new AxContextAlbums(albumKey), AxEngineState.READY, stats))); + assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(), AxEngineState.READY, stats))); + assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.STOPPED, stats))); + assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, otherStats))); + model.setTimestamp(timestamp); + assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); + model.setTimestamp(0); + assertTrue(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); + + model.setTimestamp(-1); + assertEquals(0, model.compareTo(model)); + assertEquals(0, model.compareTo(clonedModel)); + assertNotEquals(0, model.compareTo(new AxArtifactKey())); + assertFalse(model.equals(new AxEngineModel(new AxArtifactKey()))); + assertNotEquals(0, model.compareTo(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); + assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); + assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); + assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(), AxEngineState.READY, stats))); + assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.STOPPED, stats))); + assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, otherStats))); + model.setTimestamp(timestamp); + assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); + model.setTimestamp(0); + assertEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); + + model.setTimestamp(timestamp); + AxValidationResult result = new AxValidationResult(); + result = model.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + model.setTimestamp(-1); + result = new AxValidationResult(); + result = model.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + model.setTimestamp(timestamp); + result = new AxValidationResult(); + result = model.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + model.setState(AxEngineState.UNDEFINED); + result = new AxValidationResult(); + result = model.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + model.setState(AxEngineState.READY); + result = new AxValidationResult(); + result = model.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + } +} diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java new file mode 100644 index 000000000..86a8c4763 --- /dev/null +++ b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/EngineStatsTest.java @@ -0,0 +1,201 @@ +/*- + * ============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.enginemodel.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 static org.junit.Assert.fail; + +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.AxValidationResult; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; + +/** + * Test engine statistics. + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class EngineStatsTest { + private static final Object WAIT_LOCK = new Object(); + + @Test + public void testEngineStats() { + assertNotNull(new AxEngineStats()); + assertNotNull(new AxEngineStats(new AxReferenceKey())); + + final AxReferenceKey statsKey = new AxReferenceKey("EngineKey", "0.0.1", "EngineStats"); + final AxEngineStats stats = new AxEngineStats(statsKey); + + try { + stats.setKey(null); + fail("test should throw an exception here"); + } catch (final Exception e) { + assertEquals("key may not be null", e.getMessage()); + } + + stats.setKey(statsKey); + assertEquals("EngineKey:0.0.1:NULL:EngineStats", stats.getKey().getId()); + assertEquals("EngineKey:0.0.1:NULL:EngineStats", stats.getKeys().get(0).getId()); + + stats.setAverageExecutionTime(123.45); + assertEquals(new Double(123.45), new Double(stats.getAverageExecutionTime())); + + stats.setEventCount(987); + assertEquals(987, stats.getEventCount()); + + final long lastExecutionTime = System.currentTimeMillis(); + stats.setLastExecutionTime(lastExecutionTime); + assertEquals(lastExecutionTime, stats.getLastExecutionTime()); + + final long timestamp = System.currentTimeMillis(); + stats.setTimeStamp(timestamp); + assertEquals(timestamp, stats.getTimeStamp()); + assertNotNull(stats.getTimeStampString()); + + final long upTime = System.currentTimeMillis() - timestamp; + stats.setUpTime(upTime); + assertEquals(upTime, stats.getUpTime()); + + stats.engineStart(); + assertTrue(stats.getUpTime() > -1); + stats.engineStop(); + assertTrue(stats.getUpTime() >= 0); + + stats.engineStop(); + + stats.reset(); + + stats.setEventCount(-2); + stats.executionEnter(new AxArtifactKey()); + assertEquals(2, stats.getEventCount()); + + stats.setEventCount(10); + stats.executionEnter(new AxArtifactKey()); + assertEquals(11, stats.getEventCount()); + + stats.reset(); + stats.engineStart(); + stats.setEventCount(4); + stats.executionEnter(new AxArtifactKey()); + + synchronized (WAIT_LOCK) { + try { + WAIT_LOCK.wait(10); + } catch (InterruptedException e) { + fail("test should not throw an exception"); + } + } + + stats.executionExit(); + final double avExecutionTime = stats.getAverageExecutionTime(); + assertTrue(avExecutionTime >= 2.0 && avExecutionTime < 10.0); + stats.engineStop(); + + AxValidationResult result = new AxValidationResult(); + result = stats.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + stats.setKey(new AxReferenceKey()); + result = new AxValidationResult(); + result = stats.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + stats.setKey(statsKey); + result = new AxValidationResult(); + result = stats.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + stats.clean(); + stats.reset(); + + final AxEngineStats clonedStats = new AxEngineStats(stats); + assertEquals("AxEngineStats:(engineKey=AxReferenceKey:(parentKey", clonedStats.toString().substring(0, 50)); + + assertNotNull(stats.getKeys()); + + assertFalse(stats.hashCode() == 0); + + assertTrue(stats.equals(stats)); + assertTrue(stats.equals(clonedStats)); + assertFalse(stats.equals(null)); + assertFalse(stats.equals("Hello")); + assertFalse(stats.equals(new AxEngineStats(new AxReferenceKey()))); + + assertEquals(0, stats.compareTo(stats)); + assertEquals(0, stats.compareTo(clonedStats)); + assertNotEquals(0, stats.compareTo(new AxArtifactKey())); + assertNotEquals(0, stats.compareTo(null)); + assertNotEquals(0, stats.compareTo(new AxEngineStats(new AxReferenceKey()))); + + stats.setTimeStamp(1); + assertFalse(stats.equals(new AxEngineStats(statsKey))); + assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + stats.setTimeStamp(0); + assertTrue(stats.equals(new AxEngineStats(statsKey))); + assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + + stats.setEventCount(1); + assertFalse(stats.equals(new AxEngineStats(statsKey))); + assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + stats.setEventCount(0); + assertTrue(stats.equals(new AxEngineStats(statsKey))); + assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + + stats.setLastExecutionTime(1); + assertFalse(stats.equals(new AxEngineStats(statsKey))); + assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + stats.setLastExecutionTime(0); + assertTrue(stats.equals(new AxEngineStats(statsKey))); + assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + + stats.setAverageExecutionTime(1); + assertFalse(stats.equals(new AxEngineStats(statsKey))); + assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + stats.setAverageExecutionTime(0); + assertTrue(stats.equals(new AxEngineStats(statsKey))); + assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + + stats.setUpTime(1); + assertFalse(stats.equals(new AxEngineStats(statsKey))); + assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + stats.setUpTime(0); + assertTrue(stats.equals(new AxEngineStats(statsKey))); + assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + + assertEquals(-1, stats.compareTo(new AxEngineStats(statsKey, 0, 0, 0, 0.0, 0, 1))); + + stats.engineStart(); + assertFalse(stats.equals(new AxEngineStats(statsKey))); + final AxEngineStats newStats = new AxEngineStats(statsKey); + newStats.setTimeStamp(stats.getTimeStamp()); + assertFalse(stats.equals(newStats)); + assertNotEquals(0, stats.compareTo(newStats)); + stats.engineStop(); + stats.reset(); + assertTrue(stats.equals(new AxEngineStats(statsKey))); + assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); + } + +} diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineModel.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineModel.java deleted file mode 100644 index 2c1ab4bff..000000000 --- a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineModel.java +++ /dev/null @@ -1,188 +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.enginemodel.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 static org.junit.Assert.fail; - -import org.junit.Test; -import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; -import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation; -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.contextmodel.concepts.AxContextAlbums; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; - -/** - * Test engine models. - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestEngineModel { - - @Test - public void testEnginetModel() { - assertNotNull(new AxEngineModel()); - assertNotNull(new AxEngineModel(new AxArtifactKey())); - assertNotNull(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(), - new AxContextAlbums())); - assertNotNull(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(), - new AxContextAlbums(), AxEngineState.UNDEFINED, new AxEngineStats())); - - final AxArtifactKey modelKey = new AxArtifactKey("ModelName", "0.0.1"); - final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1"); - final AxArtifactKey albumKey = new AxArtifactKey("AlbumKey", "0.0.1"); - final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1"); - final AxEngineStats stats = new AxEngineStats(new AxReferenceKey(modelKey, "EngineStats")); - final AxEngineStats otherStats = new AxEngineStats(); - otherStats.setAverageExecutionTime(100); - - final AxEngineModel model = new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats); - model.register(); - - try { - model.setKey(null); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals("key may not be null", e.getMessage()); - } - - model.setKey(modelKey); - assertEquals("ModelName:0.0.1", model.getKey().getId()); - assertEquals("ModelName:0.0.1", model.getKeys().get(0).getId()); - - final long timestamp = System.currentTimeMillis(); - model.setTimestamp(timestamp); - assertEquals(timestamp, model.getTimestamp()); - model.setTimestamp(-1); - assertTrue(model.getTimeStampString().matches("\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}.\\d{3}")); - - try { - model.setState(null); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals("state may not be null", e.getMessage()); - } - - for (final AxEngineState state : AxEngineState.values()) { - model.setState(state); - assertEquals(state, model.getState()); - } - - model.setState(AxEngineState.READY); - assertEquals(AxEngineState.READY, model.getState()); - - try { - model.setStats(null); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals("stats may not be null", e.getMessage()); - } - - model.setStats(stats); - assertEquals(stats, model.getStats()); - - model.clean(); - assertNotNull(model); - assertEquals("AxEngineModel:(AxEngineModel:(AxEngineModel:(key=A", model.toString().substring(0, 50)); - - final AxEngineModel clonedModel = new AxEngineModel(model); - - assertFalse(model.hashCode() == 0); - - assertTrue(model.equals(model)); - assertTrue(model.equals(clonedModel)); - assertFalse(model.equals("Hello")); - assertFalse(model.equals(new AxEngineModel(new AxArtifactKey()))); - assertFalse(model.equals(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); - assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(), new AxKeyInformation(keyInfoKey), - new AxContextAlbums(albumKey), AxEngineState.READY, stats))); - assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), new AxKeyInformation(), - new AxContextAlbums(albumKey), AxEngineState.READY, stats))); - assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(), AxEngineState.READY, stats))); - assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.STOPPED, stats))); - assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, otherStats))); - model.setTimestamp(timestamp); - assertFalse(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); - model.setTimestamp(0); - assertTrue(model.equals(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); - - model.setTimestamp(-1); - assertEquals(0, model.compareTo(model)); - assertEquals(0, model.compareTo(clonedModel)); - assertNotEquals(0, model.compareTo(new AxArtifactKey())); - assertFalse(model.equals(new AxEngineModel(new AxArtifactKey()))); - assertNotEquals(0, model.compareTo(new AxEngineModel(new AxArtifactKey(), new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); - assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); - assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); - assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(), AxEngineState.READY, stats))); - assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.STOPPED, stats))); - assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, otherStats))); - model.setTimestamp(timestamp); - assertNotEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); - model.setTimestamp(0); - assertEquals(0, model.compareTo(new AxEngineModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxContextAlbums(albumKey), AxEngineState.READY, stats))); - - model.setTimestamp(timestamp); - AxValidationResult result = new AxValidationResult(); - result = model.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - model.setTimestamp(-1); - result = new AxValidationResult(); - result = model.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - model.setTimestamp(timestamp); - result = new AxValidationResult(); - result = model.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - model.setState(AxEngineState.UNDEFINED); - result = new AxValidationResult(); - result = model.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - model.setState(AxEngineState.READY); - result = new AxValidationResult(); - result = model.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - } -} diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineStats.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineStats.java deleted file mode 100644 index 8bd5756ab..000000000 --- a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/concepts/TestEngineStats.java +++ /dev/null @@ -1,201 +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.enginemodel.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 static org.junit.Assert.fail; - -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.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; - -/** - * Test engine statistics. - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestEngineStats { - private static final Object WAIT_LOCK = new Object(); - - @Test - public void testEngineStats() { - assertNotNull(new AxEngineStats()); - assertNotNull(new AxEngineStats(new AxReferenceKey())); - - final AxReferenceKey statsKey = new AxReferenceKey("EngineKey", "0.0.1", "EngineStats"); - final AxEngineStats stats = new AxEngineStats(statsKey); - - try { - stats.setKey(null); - fail("test should throw an exception here"); - } catch (final Exception e) { - assertEquals("key may not be null", e.getMessage()); - } - - stats.setKey(statsKey); - assertEquals("EngineKey:0.0.1:NULL:EngineStats", stats.getKey().getId()); - assertEquals("EngineKey:0.0.1:NULL:EngineStats", stats.getKeys().get(0).getId()); - - stats.setAverageExecutionTime(123.45); - assertEquals(new Double(123.45), new Double(stats.getAverageExecutionTime())); - - stats.setEventCount(987); - assertEquals(987, stats.getEventCount()); - - final long lastExecutionTime = System.currentTimeMillis(); - stats.setLastExecutionTime(lastExecutionTime); - assertEquals(lastExecutionTime, stats.getLastExecutionTime()); - - final long timestamp = System.currentTimeMillis(); - stats.setTimeStamp(timestamp); - assertEquals(timestamp, stats.getTimeStamp()); - assertNotNull(stats.getTimeStampString()); - - final long upTime = System.currentTimeMillis() - timestamp; - stats.setUpTime(upTime); - assertEquals(upTime, stats.getUpTime()); - - stats.engineStart(); - assertTrue(stats.getUpTime() > -1); - stats.engineStop(); - assertTrue(stats.getUpTime() >= 0); - - stats.engineStop(); - - stats.reset(); - - stats.setEventCount(-2); - stats.executionEnter(new AxArtifactKey()); - assertEquals(2, stats.getEventCount()); - - stats.setEventCount(10); - stats.executionEnter(new AxArtifactKey()); - assertEquals(11, stats.getEventCount()); - - stats.reset(); - stats.engineStart(); - stats.setEventCount(4); - stats.executionEnter(new AxArtifactKey()); - - synchronized (WAIT_LOCK) { - try { - WAIT_LOCK.wait(10); - } catch (InterruptedException e) { - fail("test should not throw an exception"); - } - } - - stats.executionExit(); - final double avExecutionTime = stats.getAverageExecutionTime(); - assertTrue(avExecutionTime >= 2.0 && avExecutionTime < 10.0); - stats.engineStop(); - - AxValidationResult result = new AxValidationResult(); - result = stats.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - stats.setKey(new AxReferenceKey()); - result = new AxValidationResult(); - result = stats.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - stats.setKey(statsKey); - result = new AxValidationResult(); - result = stats.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - stats.clean(); - stats.reset(); - - final AxEngineStats clonedStats = new AxEngineStats(stats); - assertEquals("AxEngineStats:(engineKey=AxReferenceKey:(parentKey", clonedStats.toString().substring(0, 50)); - - assertNotNull(stats.getKeys()); - - assertFalse(stats.hashCode() == 0); - - assertTrue(stats.equals(stats)); - assertTrue(stats.equals(clonedStats)); - assertFalse(stats.equals(null)); - assertFalse(stats.equals("Hello")); - assertFalse(stats.equals(new AxEngineStats(new AxReferenceKey()))); - - assertEquals(0, stats.compareTo(stats)); - assertEquals(0, stats.compareTo(clonedStats)); - assertNotEquals(0, stats.compareTo(new AxArtifactKey())); - assertNotEquals(0, stats.compareTo(null)); - assertNotEquals(0, stats.compareTo(new AxEngineStats(new AxReferenceKey()))); - - stats.setTimeStamp(1); - assertFalse(stats.equals(new AxEngineStats(statsKey))); - assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - stats.setTimeStamp(0); - assertTrue(stats.equals(new AxEngineStats(statsKey))); - assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - - stats.setEventCount(1); - assertFalse(stats.equals(new AxEngineStats(statsKey))); - assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - stats.setEventCount(0); - assertTrue(stats.equals(new AxEngineStats(statsKey))); - assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - - stats.setLastExecutionTime(1); - assertFalse(stats.equals(new AxEngineStats(statsKey))); - assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - stats.setLastExecutionTime(0); - assertTrue(stats.equals(new AxEngineStats(statsKey))); - assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - - stats.setAverageExecutionTime(1); - assertFalse(stats.equals(new AxEngineStats(statsKey))); - assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - stats.setAverageExecutionTime(0); - assertTrue(stats.equals(new AxEngineStats(statsKey))); - assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - - stats.setUpTime(1); - assertFalse(stats.equals(new AxEngineStats(statsKey))); - assertNotEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - stats.setUpTime(0); - assertTrue(stats.equals(new AxEngineStats(statsKey))); - assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - - assertEquals(-1, stats.compareTo(new AxEngineStats(statsKey, 0, 0, 0, 0.0, 0, 1))); - - stats.engineStart(); - assertFalse(stats.equals(new AxEngineStats(statsKey))); - final AxEngineStats newStats = new AxEngineStats(statsKey); - newStats.setTimeStamp(stats.getTimeStamp()); - assertFalse(stats.equals(newStats)); - assertNotEquals(0, stats.compareTo(newStats)); - stats.engineStop(); - stats.reset(); - assertTrue(stats.equals(new AxEngineStats(statsKey))); - assertEquals(0, stats.compareTo(new AxEngineStats(statsKey))); - } - -} diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java new file mode 100644 index 000000000..32c4ff38b --- /dev/null +++ b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.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.enginemodel.handling; + +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.AxValidationResult; +import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; +import org.onap.policy.apex.model.basicmodel.test.TestApexModel; +import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel; + +public class ApexEngineModelTest { + private Connection connection; + TestApexModel testApexModel; + + /** + * Set up the test. + * + * @throws Exception errors from test setup + */ + @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(AxEngineModel.class, new TestApexEngineModelCreator()); + } + + @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 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); + } + + private static final String VALID_MODEL_STRING = "***validation of model successful***"; + + private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n" + + "AxArtifactKey:(name=AnEngine,version=0.0.1):" + + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:" + + "AxEngineModel - state is UNDEFINED\n" + "********************************"; + + private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n" + + "AxArtifactKey:(name=AnEngine,version=0.0.1):" + + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:" + + "AxEngineModel - timestamp is not set\n" + "AxArtifactKey:(name=AnEngine,version=0.0.1):" + + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:" + + "AxEngineModel - state is UNDEFINED\n" + "********************************"; +} diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModel.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModel.java deleted file mode 100644 index 10abbf3fe..000000000 --- a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/TestApexEngineModel.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.enginemodel.handling; - -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.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; -import org.onap.policy.apex.model.basicmodel.test.TestApexModel; -import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel; - -public class TestApexEngineModel { - private Connection connection; - TestApexModel testApexModel; - - /** - * Set up the test. - * - * @throws Exception errors from test setup - */ - @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(AxEngineModel.class, new TestApexEngineModelCreator()); - } - - @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 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); - } - - private static final String VALID_MODEL_STRING = "***validation of model successful***"; - - private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n" - + "AxArtifactKey:(name=AnEngine,version=0.0.1):" - + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:" - + "AxEngineModel - state is UNDEFINED\n" + "********************************"; - - private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n" - + "AxArtifactKey:(name=AnEngine,version=0.0.1):" - + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:" - + "AxEngineModel - timestamp is not set\n" + "AxArtifactKey:(name=AnEngine,version=0.0.1):" - + "org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel:INVALID:" - + "AxEngineModel - state is UNDEFINED\n" + "********************************"; -} diff --git a/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventModelTest.java b/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventModelTest.java new file mode 100644 index 000000000..74f092a94 --- /dev/null +++ b/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventModelTest.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.eventmodel.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.AxKeyInformation; +import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; +import org.onap.policy.apex.model.eventmodel.concepts.AxEventModel; +import org.onap.policy.apex.model.eventmodel.concepts.AxEvents; + +/** + * Test event models. + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class EventModelTest { + + @Test + public void testEventModel() { + assertNotNull(new AxEventModel()); + assertNotNull(new AxEventModel(new AxArtifactKey())); + assertNotNull( + new AxEventModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(), new AxEvents())); + + final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1"); + final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1"); + final AxArtifactKey eventsKey = new AxArtifactKey("EventsKey", "0.0.1"); + final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1"); + final AxEventModel model = new AxEventModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey)); + model.register(); + + model.clean(); + assertNotNull(model); + assertEquals("AxEventModel:(AxEventModel:(key=AxArtifactKey:(nam", model.toString().substring(0, 50)); + + final AxEventModel clonedModel = new AxEventModel(model); + + assertFalse(model.hashCode() == 0); + + assertTrue(model.equals(model)); + assertTrue(model.equals(clonedModel)); + assertFalse(model.equals("Hello")); + assertFalse(model.equals(new AxEventModel(new AxArtifactKey()))); + assertFalse(model.equals(new AxEventModel(modelKey, new AxContextSchemas(), new AxKeyInformation(keyInfoKey), + new AxEvents(eventsKey)))); + assertFalse(model.equals(new AxEventModel(modelKey, new AxContextSchemas(schemasKey), new AxKeyInformation(), + new AxEvents(eventsKey)))); + assertFalse(model.equals(new AxEventModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxEvents()))); + assertTrue(model.equals(new AxEventModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey)))); + + assertEquals(0, model.compareTo(model)); + assertEquals(0, model.compareTo(clonedModel)); + assertNotEquals(0, model.compareTo(new AxArtifactKey())); + assertNotEquals(0, model.compareTo(new AxEventModel(modelKey, new AxContextSchemas(), + new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey)))); + assertNotEquals(0, model.compareTo(new AxEventModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(), new AxEvents(eventsKey)))); + assertNotEquals(0, model.compareTo(new AxEventModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxEvents()))); + assertEquals(0, model.compareTo(new AxEventModel(modelKey, new AxContextSchemas(schemasKey), + new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey)))); + } +} diff --git a/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventsTest.java b/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventsTest.java new file mode 100644 index 000000000..4a17c2a48 --- /dev/null +++ b/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/EventsTest.java @@ -0,0 +1,299 @@ +/*- + * ============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.eventmodel.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.TreeMap; +import java.util.TreeSet; + +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; +import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; +import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; +import org.onap.policy.apex.model.eventmodel.concepts.AxEvents; +import org.onap.policy.apex.model.eventmodel.concepts.AxField; + +/** + * Test events. + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class EventsTest { + + @Test + public void testEvents() { + final TreeMap parameterMap = new TreeMap<>(); + final TreeMap parameterMapEmpty = new TreeMap<>(); + + assertNotNull(new AxEvent()); + assertNotNull(new AxEvent(new AxArtifactKey())); + assertNotNull(new AxEvent(new AxArtifactKey(), "namespace")); + assertNotNull(new AxEvent(new AxArtifactKey(), "namespace", "source", "target")); + assertNotNull(new AxEvent(new AxArtifactKey(), "namespace", "source", "target")); + assertNotNull(new AxEvent(new AxArtifactKey(), "namespace", "source", "target", parameterMap)); + + final AxEvent event = new AxEvent(); + + final AxArtifactKey eventKey = new AxArtifactKey("EventName", "0.0.1"); + event.setKey(eventKey); + assertEquals("EventName:0.0.1", event.getKey().getId()); + assertEquals("EventName:0.0.1", event.getKeys().get(0).getId()); + + event.setNameSpace("namespace"); + assertEquals("namespace", event.getNameSpace()); + + event.setSource("source"); + assertEquals("source", event.getSource()); + + event.setTarget("target"); + assertEquals("target", event.getTarget()); + + event.setParameterMap(parameterMap); + assertEquals(0, event.getParameterMap().size()); + + final AxField eventField = + new AxField(new AxReferenceKey(eventKey, "Field0"), new AxArtifactKey("Field0Schema", "0.0.1")); + event.getParameterMap().put(eventField.getKey().getLocalName(), eventField); + assertEquals(1, event.getParameterMap().size()); + + final AxField eventFieldBadParent = + new AxField(new AxReferenceKey(new AxArtifactKey("OtherEvent", "0.0.01"), "Field0"), + new AxArtifactKey("Field0Schema", "0.0.1")); + + final AxArtifactKey newEventKey = new AxArtifactKey("NewEventName", "0.0.1"); + event.setKey(newEventKey); + assertEquals("NewEventName:0.0.1", event.getKey().getId()); + assertEquals("NewEventName:0.0.1", event.getKeys().get(0).getId()); + assertEquals("NewEventName:0.0.1", + event.getParameterMap().get("Field0").getKey().getParentArtifactKey().getId()); + event.setKey(eventKey); + assertEquals("EventName:0.0.1", event.getKey().getId()); + assertEquals("EventName:0.0.1", event.getKeys().get(0).getId()); + + assertTrue("Field0", event.getFields().contains(eventField)); + assertTrue(event.hasFields(new TreeSet(parameterMap.values()))); + + AxValidationResult result = new AxValidationResult(); + result = event.validate(result); + assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult()); + + event.setKey(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + event.setKey(eventKey); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + event.setNameSpace(""); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.WARNING, result.getValidationResult()); + + event.setNameSpace("namespace"); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + event.setSource(""); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.OBSERVATION, result.getValidationResult()); + + event.setSource("source"); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + event.setTarget(""); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.OBSERVATION, result.getValidationResult()); + + event.setTarget("target"); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + event.getParameterMap().put(AxKey.NULL_KEY_NAME, null); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + event.getParameterMap().remove(AxKey.NULL_KEY_NAME); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + event.getParameterMap().put("NullField", null); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + event.getParameterMap().remove("NullField"); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + event.getParameterMap().put("NullField", eventField); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + event.getParameterMap().remove("NullField"); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + event.getParameterMap().put("BadParent", eventFieldBadParent); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + event.getParameterMap().remove("BadParent"); + result = new AxValidationResult(); + result = event.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + event.clean(); + event.afterUnmarshal(null, null); + + final AxEvent clonedEvent = new AxEvent(event); + assertEquals("AxEvent:(key=AxArtifactKey:(name=EventName,version=0.0.1),nameSpace=namespace", + clonedEvent.toString().substring(0, 77)); + + assertFalse(event.hashCode() == 0); + + assertTrue(event.equals(event)); + assertTrue(event.equals(clonedEvent)); + assertFalse(event.equals(null)); + assertFalse(event.equals("Hello")); + assertFalse( + event.equals(new AxEvent(AxArtifactKey.getNullKey(), "namespace", "source", "target", parameterMap))); + assertFalse(event.equals(new AxEvent(eventKey, "namespace1", "source", "target", parameterMap))); + assertFalse(event.equals(new AxEvent(eventKey, "namespace", "source2", "target", parameterMap))); + assertFalse(event.equals(new AxEvent(eventKey, "namespace", "source", "target3", parameterMap))); + assertFalse(event.equals(new AxEvent(eventKey, "namespace", "source", "target", parameterMapEmpty))); + assertTrue(event.equals(new AxEvent(eventKey, "namespace", "source", "target", parameterMap))); + + assertEquals(0, event.compareTo(event)); + assertEquals(0, event.compareTo(clonedEvent)); + assertNotEquals(0, event.compareTo(new AxArtifactKey())); + assertNotEquals(0, event.compareTo(null)); + assertNotEquals(0, event + .compareTo(new AxEvent(AxArtifactKey.getNullKey(), "namespace", "source", "target", parameterMap))); + assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace1", "source", "target", parameterMap))); + assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source2", "target", parameterMap))); + assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source", "target3", parameterMap))); + assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source", "target", parameterMapEmpty))); + assertEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source", "target", parameterMap))); + + assertNotNull(event.getKeys()); + + final AxEvents events = new AxEvents(); + result = new AxValidationResult(); + result = events.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + // Invalid, no events in event map + events.setKey(new AxArtifactKey("EventsKey", "0.0.1")); + assertEquals("EventsKey:0.0.1", events.getKey().getId()); + + result = new AxValidationResult(); + result = events.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + events.getEventMap().put(eventKey, event); + result = new AxValidationResult(); + result = events.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + events.getEventMap().put(AxArtifactKey.getNullKey(), null); + result = new AxValidationResult(); + result = events.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + events.getEventMap().remove(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = events.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + events.getEventMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null); + result = new AxValidationResult(); + result = events.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + events.getEventMap().remove(new AxArtifactKey("NullValueKey", "0.0.1")); + result = new AxValidationResult(); + result = events.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + events.getEventMap().put(new AxArtifactKey("BadEventKey", "0.0.1"), event); + result = new AxValidationResult(); + result = events.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + events.getEventMap().remove(new AxArtifactKey("BadEventKey", "0.0.1")); + result = new AxValidationResult(); + result = events.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + events.clean(); + events.afterUnmarshal(null, null); + + final AxEvents clonedEvents = new AxEvents(events); + assertEquals("AxEvents:(key=AxArtifactKey:(name=EventsKey,version=0.0.1),e", + clonedEvents.toString().substring(0, 60)); + + assertFalse(events.hashCode() == 0); + + assertTrue(events.equals(events)); + assertTrue(events.equals(clonedEvents)); + assertFalse(events.equals(null)); + assertFalse(events.equals("Hello")); + assertFalse(events.equals(new AxEvents(new AxArtifactKey()))); + + assertEquals(0, events.compareTo(events)); + assertEquals(0, events.compareTo(clonedEvents)); + assertNotEquals(0, events.compareTo(null)); + assertNotEquals(0, events.compareTo(new AxArtifactKey())); + assertNotEquals(0, events.compareTo(new AxEvents(new AxArtifactKey()))); + + clonedEvents.get(eventKey).setSource("AnotherSource"); + assertNotEquals(0, events.compareTo(clonedEvents)); + + assertEquals(events.getKey(), events.getKeys().get(0)); + + assertEquals("EventName", events.get("EventName").getKey().getName()); + assertEquals("EventName", events.get("EventName", "0.0.1").getKey().getName()); + assertEquals(1, events.getAll("EventName", "0.0.1").size()); + assertEquals(0, events.getAll("NonExistantEventsName").size()); + } +} diff --git a/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/FieldTest.java b/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/FieldTest.java new file mode 100644 index 000000000..3d88b4c81 --- /dev/null +++ b/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/FieldTest.java @@ -0,0 +1,138 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2016-2018 Ericsson. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.model.eventmodel.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.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.eventmodel.concepts.AxField; +import org.onap.policy.apex.model.eventmodel.concepts.AxInputField; +import org.onap.policy.apex.model.eventmodel.concepts.AxOutputField; + +/** + * Test fields. + * + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class FieldTest { + + @Test + public void testField() { + assertNotNull(new AxField()); + assertNotNull(new AxField(new AxReferenceKey())); + assertNotNull(new AxField(new AxReferenceKey(), new AxArtifactKey())); + assertNotNull(new AxField(new AxReferenceKey(), new AxArtifactKey(), false)); + assertNotNull(new AxField("LocalName", new AxArtifactKey(), false)); + assertNotNull(new AxField("LocalName", new AxArtifactKey())); + assertNotNull(new AxField("LocalName", new AxArtifactKey(), false)); + + assertNotNull(new AxInputField()); + assertNotNull(new AxInputField(new AxReferenceKey())); + assertNotNull(new AxInputField(new AxReferenceKey(), new AxArtifactKey())); + assertNotNull(new AxInputField(new AxReferenceKey(), new AxArtifactKey(), true)); + assertNotNull(new AxInputField("LocalName", new AxArtifactKey())); + assertNotNull(new AxInputField(new AxInputField())); + + assertNotNull(new AxOutputField()); + assertNotNull(new AxOutputField(new AxReferenceKey())); + assertNotNull(new AxOutputField(new AxReferenceKey(), new AxArtifactKey())); + assertNotNull(new AxOutputField(new AxReferenceKey(), new AxArtifactKey(), false)); + assertNotNull(new AxOutputField("LocalName", new AxArtifactKey())); + assertNotNull(new AxOutputField(new AxOutputField())); + + final AxField field = new AxField(); + + final AxReferenceKey fieldKey = new AxReferenceKey("FieldName", "0.0.1", "PLN", "LN"); + field.setKey(fieldKey); + assertEquals("FieldName:0.0.1:PLN:LN", field.getKey().getId()); + assertEquals("FieldName:0.0.1:PLN:LN", field.getKeys().get(0).getId()); + + final AxArtifactKey schemaKey = new AxArtifactKey("SchemaName", "0.0.1"); + field.setSchema(schemaKey); + assertEquals("SchemaName:0.0.1", field.getSchema().getId()); + + assertEquals(false, field.getOptional()); + field.setOptional(true); + assertEquals(true, field.getOptional()); + + AxValidationResult result = new AxValidationResult(); + result = field.validate(result); + assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult()); + + field.setKey(AxReferenceKey.getNullKey()); + result = new AxValidationResult(); + result = field.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + field.setKey(fieldKey); + result = new AxValidationResult(); + result = field.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + field.setSchema(AxArtifactKey.getNullKey()); + result = new AxValidationResult(); + result = field.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + + field.setSchema(schemaKey); + result = new AxValidationResult(); + result = field.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + field.clean(); + + final AxField clonedField = new AxField(field); + assertEquals("AxField:(key=AxReferenceKey:(parentKeyName=FieldName,parentKeyVersion=0.0.1," + + "parentLocalName=PLN,localName=LN),fieldSchemaKey=" + + "AxArtifactKey:(name=SchemaName,version=0.0.1),optional=true)", clonedField.toString()); + + assertFalse(field.hashCode() == 0); + + assertTrue(field.equals(field)); + assertTrue(field.equals(clonedField)); + assertFalse(field.equals(null)); + assertFalse(field.equals("Hello")); + assertFalse(field.equals(new AxField(AxReferenceKey.getNullKey(), AxArtifactKey.getNullKey(), false))); + assertFalse(field.equals(new AxField(fieldKey, AxArtifactKey.getNullKey(), false))); + assertFalse(field.equals(new AxField(fieldKey, schemaKey, false))); + assertTrue(field.equals(new AxField(fieldKey, schemaKey, true))); + + assertEquals(0, field.compareTo(field)); + assertEquals(0, field.compareTo(clonedField)); + assertNotEquals(0, field.compareTo(new AxArtifactKey())); + assertNotEquals(0, field.compareTo(null)); + assertNotEquals(0, + field.compareTo(new AxField(AxReferenceKey.getNullKey(), AxArtifactKey.getNullKey(), false))); + assertNotEquals(0, field.compareTo(new AxField(fieldKey, AxArtifactKey.getNullKey(), false))); + assertNotEquals(0, field.compareTo(new AxField(fieldKey, schemaKey, false))); + assertEquals(0, field.compareTo(new AxField(fieldKey, schemaKey, true))); + + assertNotNull(field.getKeys()); + } +} diff --git a/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/TestEventModel.java b/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/TestEventModel.java deleted file mode 100644 index a5d3a349a..000000000 --- a/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/TestEventModel.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.eventmodel.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.AxKeyInformation; -import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas; -import org.onap.policy.apex.model.eventmodel.concepts.AxEventModel; -import org.onap.policy.apex.model.eventmodel.concepts.AxEvents; - -/** - * Test event models. - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestEventModel { - - @Test - public void testEventModel() { - assertNotNull(new AxEventModel()); - assertNotNull(new AxEventModel(new AxArtifactKey())); - assertNotNull( - new AxEventModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(), new AxEvents())); - - final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1"); - final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1"); - final AxArtifactKey eventsKey = new AxArtifactKey("EventsKey", "0.0.1"); - final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1"); - final AxEventModel model = new AxEventModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey)); - model.register(); - - model.clean(); - assertNotNull(model); - assertEquals("AxEventModel:(AxEventModel:(key=AxArtifactKey:(nam", model.toString().substring(0, 50)); - - final AxEventModel clonedModel = new AxEventModel(model); - - assertFalse(model.hashCode() == 0); - - assertTrue(model.equals(model)); - assertTrue(model.equals(clonedModel)); - assertFalse(model.equals("Hello")); - assertFalse(model.equals(new AxEventModel(new AxArtifactKey()))); - assertFalse(model.equals(new AxEventModel(modelKey, new AxContextSchemas(), new AxKeyInformation(keyInfoKey), - new AxEvents(eventsKey)))); - assertFalse(model.equals(new AxEventModel(modelKey, new AxContextSchemas(schemasKey), new AxKeyInformation(), - new AxEvents(eventsKey)))); - assertFalse(model.equals(new AxEventModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxEvents()))); - assertTrue(model.equals(new AxEventModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey)))); - - assertEquals(0, model.compareTo(model)); - assertEquals(0, model.compareTo(clonedModel)); - assertNotEquals(0, model.compareTo(new AxArtifactKey())); - assertNotEquals(0, model.compareTo(new AxEventModel(modelKey, new AxContextSchemas(), - new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey)))); - assertNotEquals(0, model.compareTo(new AxEventModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(), new AxEvents(eventsKey)))); - assertNotEquals(0, model.compareTo(new AxEventModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxEvents()))); - assertEquals(0, model.compareTo(new AxEventModel(modelKey, new AxContextSchemas(schemasKey), - new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey)))); - } -} diff --git a/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/TestEvents.java b/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/TestEvents.java deleted file mode 100644 index 36ef6ade5..000000000 --- a/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/TestEvents.java +++ /dev/null @@ -1,299 +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.eventmodel.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.TreeMap; -import java.util.TreeSet; - -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; -import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult.ValidationResult; -import org.onap.policy.apex.model.eventmodel.concepts.AxEvent; -import org.onap.policy.apex.model.eventmodel.concepts.AxEvents; -import org.onap.policy.apex.model.eventmodel.concepts.AxField; - -/** - * Test events. - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestEvents { - - @Test - public void testEvents() { - final TreeMap parameterMap = new TreeMap<>(); - final TreeMap parameterMapEmpty = new TreeMap<>(); - - assertNotNull(new AxEvent()); - assertNotNull(new AxEvent(new AxArtifactKey())); - assertNotNull(new AxEvent(new AxArtifactKey(), "namespace")); - assertNotNull(new AxEvent(new AxArtifactKey(), "namespace", "source", "target")); - assertNotNull(new AxEvent(new AxArtifactKey(), "namespace", "source", "target")); - assertNotNull(new AxEvent(new AxArtifactKey(), "namespace", "source", "target", parameterMap)); - - final AxEvent event = new AxEvent(); - - final AxArtifactKey eventKey = new AxArtifactKey("EventName", "0.0.1"); - event.setKey(eventKey); - assertEquals("EventName:0.0.1", event.getKey().getId()); - assertEquals("EventName:0.0.1", event.getKeys().get(0).getId()); - - event.setNameSpace("namespace"); - assertEquals("namespace", event.getNameSpace()); - - event.setSource("source"); - assertEquals("source", event.getSource()); - - event.setTarget("target"); - assertEquals("target", event.getTarget()); - - event.setParameterMap(parameterMap); - assertEquals(0, event.getParameterMap().size()); - - final AxField eventField = - new AxField(new AxReferenceKey(eventKey, "Field0"), new AxArtifactKey("Field0Schema", "0.0.1")); - event.getParameterMap().put(eventField.getKey().getLocalName(), eventField); - assertEquals(1, event.getParameterMap().size()); - - final AxField eventFieldBadParent = - new AxField(new AxReferenceKey(new AxArtifactKey("OtherEvent", "0.0.01"), "Field0"), - new AxArtifactKey("Field0Schema", "0.0.1")); - - final AxArtifactKey newEventKey = new AxArtifactKey("NewEventName", "0.0.1"); - event.setKey(newEventKey); - assertEquals("NewEventName:0.0.1", event.getKey().getId()); - assertEquals("NewEventName:0.0.1", event.getKeys().get(0).getId()); - assertEquals("NewEventName:0.0.1", - event.getParameterMap().get("Field0").getKey().getParentArtifactKey().getId()); - event.setKey(eventKey); - assertEquals("EventName:0.0.1", event.getKey().getId()); - assertEquals("EventName:0.0.1", event.getKeys().get(0).getId()); - - assertTrue("Field0", event.getFields().contains(eventField)); - assertTrue(event.hasFields(new TreeSet(parameterMap.values()))); - - AxValidationResult result = new AxValidationResult(); - result = event.validate(result); - assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult()); - - event.setKey(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = event.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - event.setKey(eventKey); - result = new AxValidationResult(); - result = event.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - event.setNameSpace(""); - result = new AxValidationResult(); - result = event.validate(result); - assertEquals(ValidationResult.WARNING, result.getValidationResult()); - - event.setNameSpace("namespace"); - result = new AxValidationResult(); - result = event.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - event.setSource(""); - result = new AxValidationResult(); - result = event.validate(result); - assertEquals(ValidationResult.OBSERVATION, result.getValidationResult()); - - event.setSource("source"); - result = new AxValidationResult(); - result = event.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - event.setTarget(""); - result = new AxValidationResult(); - result = event.validate(result); - assertEquals(ValidationResult.OBSERVATION, result.getValidationResult()); - - event.setTarget("target"); - result = new AxValidationResult(); - result = event.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - event.getParameterMap().put(AxKey.NULL_KEY_NAME, null); - result = new AxValidationResult(); - result = event.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - event.getParameterMap().remove(AxKey.NULL_KEY_NAME); - result = new AxValidationResult(); - result = event.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - event.getParameterMap().put("NullField", null); - result = new AxValidationResult(); - result = event.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - event.getParameterMap().remove("NullField"); - result = new AxValidationResult(); - result = event.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - event.getParameterMap().put("NullField", eventField); - result = new AxValidationResult(); - result = event.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - event.getParameterMap().remove("NullField"); - result = new AxValidationResult(); - result = event.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - event.getParameterMap().put("BadParent", eventFieldBadParent); - result = new AxValidationResult(); - result = event.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - event.getParameterMap().remove("BadParent"); - result = new AxValidationResult(); - result = event.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - event.clean(); - event.afterUnmarshal(null, null); - - final AxEvent clonedEvent = new AxEvent(event); - assertEquals("AxEvent:(key=AxArtifactKey:(name=EventName,version=0.0.1),nameSpace=namespace", - clonedEvent.toString().substring(0, 77)); - - assertFalse(event.hashCode() == 0); - - assertTrue(event.equals(event)); - assertTrue(event.equals(clonedEvent)); - assertFalse(event.equals(null)); - assertFalse(event.equals("Hello")); - assertFalse( - event.equals(new AxEvent(AxArtifactKey.getNullKey(), "namespace", "source", "target", parameterMap))); - assertFalse(event.equals(new AxEvent(eventKey, "namespace1", "source", "target", parameterMap))); - assertFalse(event.equals(new AxEvent(eventKey, "namespace", "source2", "target", parameterMap))); - assertFalse(event.equals(new AxEvent(eventKey, "namespace", "source", "target3", parameterMap))); - assertFalse(event.equals(new AxEvent(eventKey, "namespace", "source", "target", parameterMapEmpty))); - assertTrue(event.equals(new AxEvent(eventKey, "namespace", "source", "target", parameterMap))); - - assertEquals(0, event.compareTo(event)); - assertEquals(0, event.compareTo(clonedEvent)); - assertNotEquals(0, event.compareTo(new AxArtifactKey())); - assertNotEquals(0, event.compareTo(null)); - assertNotEquals(0, event - .compareTo(new AxEvent(AxArtifactKey.getNullKey(), "namespace", "source", "target", parameterMap))); - assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace1", "source", "target", parameterMap))); - assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source2", "target", parameterMap))); - assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source", "target3", parameterMap))); - assertNotEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source", "target", parameterMapEmpty))); - assertEquals(0, event.compareTo(new AxEvent(eventKey, "namespace", "source", "target", parameterMap))); - - assertNotNull(event.getKeys()); - - final AxEvents events = new AxEvents(); - result = new AxValidationResult(); - result = events.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - // Invalid, no events in event map - events.setKey(new AxArtifactKey("EventsKey", "0.0.1")); - assertEquals("EventsKey:0.0.1", events.getKey().getId()); - - result = new AxValidationResult(); - result = events.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - events.getEventMap().put(eventKey, event); - result = new AxValidationResult(); - result = events.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - events.getEventMap().put(AxArtifactKey.getNullKey(), null); - result = new AxValidationResult(); - result = events.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - events.getEventMap().remove(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = events.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - events.getEventMap().put(new AxArtifactKey("NullValueKey", "0.0.1"), null); - result = new AxValidationResult(); - result = events.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - events.getEventMap().remove(new AxArtifactKey("NullValueKey", "0.0.1")); - result = new AxValidationResult(); - result = events.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - events.getEventMap().put(new AxArtifactKey("BadEventKey", "0.0.1"), event); - result = new AxValidationResult(); - result = events.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - events.getEventMap().remove(new AxArtifactKey("BadEventKey", "0.0.1")); - result = new AxValidationResult(); - result = events.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - events.clean(); - events.afterUnmarshal(null, null); - - final AxEvents clonedEvents = new AxEvents(events); - assertEquals("AxEvents:(key=AxArtifactKey:(name=EventsKey,version=0.0.1),e", - clonedEvents.toString().substring(0, 60)); - - assertFalse(events.hashCode() == 0); - - assertTrue(events.equals(events)); - assertTrue(events.equals(clonedEvents)); - assertFalse(events.equals(null)); - assertFalse(events.equals("Hello")); - assertFalse(events.equals(new AxEvents(new AxArtifactKey()))); - - assertEquals(0, events.compareTo(events)); - assertEquals(0, events.compareTo(clonedEvents)); - assertNotEquals(0, events.compareTo(null)); - assertNotEquals(0, events.compareTo(new AxArtifactKey())); - assertNotEquals(0, events.compareTo(new AxEvents(new AxArtifactKey()))); - - clonedEvents.get(eventKey).setSource("AnotherSource"); - assertNotEquals(0, events.compareTo(clonedEvents)); - - assertEquals(events.getKey(), events.getKeys().get(0)); - - assertEquals("EventName", events.get("EventName").getKey().getName()); - assertEquals("EventName", events.get("EventName", "0.0.1").getKey().getName()); - assertEquals(1, events.getAll("EventName", "0.0.1").size()); - assertEquals(0, events.getAll("NonExistantEventsName").size()); - } -} diff --git a/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/TestField.java b/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/TestField.java deleted file mode 100644 index 75fced1b0..000000000 --- a/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/concepts/TestField.java +++ /dev/null @@ -1,138 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2016-2018 Ericsson. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.apex.model.eventmodel.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.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.eventmodel.concepts.AxField; -import org.onap.policy.apex.model.eventmodel.concepts.AxInputField; -import org.onap.policy.apex.model.eventmodel.concepts.AxOutputField; - -/** - * Test fields. - * - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestField { - - @Test - public void testField() { - assertNotNull(new AxField()); - assertNotNull(new AxField(new AxReferenceKey())); - assertNotNull(new AxField(new AxReferenceKey(), new AxArtifactKey())); - assertNotNull(new AxField(new AxReferenceKey(), new AxArtifactKey(), false)); - assertNotNull(new AxField("LocalName", new AxArtifactKey(), false)); - assertNotNull(new AxField("LocalName", new AxArtifactKey())); - assertNotNull(new AxField("LocalName", new AxArtifactKey(), false)); - - assertNotNull(new AxInputField()); - assertNotNull(new AxInputField(new AxReferenceKey())); - assertNotNull(new AxInputField(new AxReferenceKey(), new AxArtifactKey())); - assertNotNull(new AxInputField(new AxReferenceKey(), new AxArtifactKey(), true)); - assertNotNull(new AxInputField("LocalName", new AxArtifactKey())); - assertNotNull(new AxInputField(new AxInputField())); - - assertNotNull(new AxOutputField()); - assertNotNull(new AxOutputField(new AxReferenceKey())); - assertNotNull(new AxOutputField(new AxReferenceKey(), new AxArtifactKey())); - assertNotNull(new AxOutputField(new AxReferenceKey(), new AxArtifactKey(), false)); - assertNotNull(new AxOutputField("LocalName", new AxArtifactKey())); - assertNotNull(new AxOutputField(new AxOutputField())); - - final AxField field = new AxField(); - - final AxReferenceKey fieldKey = new AxReferenceKey("FieldName", "0.0.1", "PLN", "LN"); - field.setKey(fieldKey); - assertEquals("FieldName:0.0.1:PLN:LN", field.getKey().getId()); - assertEquals("FieldName:0.0.1:PLN:LN", field.getKeys().get(0).getId()); - - final AxArtifactKey schemaKey = new AxArtifactKey("SchemaName", "0.0.1"); - field.setSchema(schemaKey); - assertEquals("SchemaName:0.0.1", field.getSchema().getId()); - - assertEquals(false, field.getOptional()); - field.setOptional(true); - assertEquals(true, field.getOptional()); - - AxValidationResult result = new AxValidationResult(); - result = field.validate(result); - assertEquals(AxValidationResult.ValidationResult.VALID, result.getValidationResult()); - - field.setKey(AxReferenceKey.getNullKey()); - result = new AxValidationResult(); - result = field.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - field.setKey(fieldKey); - result = new AxValidationResult(); - result = field.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - field.setSchema(AxArtifactKey.getNullKey()); - result = new AxValidationResult(); - result = field.validate(result); - assertEquals(ValidationResult.INVALID, result.getValidationResult()); - - field.setSchema(schemaKey); - result = new AxValidationResult(); - result = field.validate(result); - assertEquals(ValidationResult.VALID, result.getValidationResult()); - - field.clean(); - - final AxField clonedField = new AxField(field); - assertEquals("AxField:(key=AxReferenceKey:(parentKeyName=FieldName,parentKeyVersion=0.0.1," - + "parentLocalName=PLN,localName=LN),fieldSchemaKey=" - + "AxArtifactKey:(name=SchemaName,version=0.0.1),optional=true)", clonedField.toString()); - - assertFalse(field.hashCode() == 0); - - assertTrue(field.equals(field)); - assertTrue(field.equals(clonedField)); - assertFalse(field.equals(null)); - assertFalse(field.equals("Hello")); - assertFalse(field.equals(new AxField(AxReferenceKey.getNullKey(), AxArtifactKey.getNullKey(), false))); - assertFalse(field.equals(new AxField(fieldKey, AxArtifactKey.getNullKey(), false))); - assertFalse(field.equals(new AxField(fieldKey, schemaKey, false))); - assertTrue(field.equals(new AxField(fieldKey, schemaKey, true))); - - assertEquals(0, field.compareTo(field)); - assertEquals(0, field.compareTo(clonedField)); - assertNotEquals(0, field.compareTo(new AxArtifactKey())); - assertNotEquals(0, field.compareTo(null)); - assertNotEquals(0, - field.compareTo(new AxField(AxReferenceKey.getNullKey(), AxArtifactKey.getNullKey(), false))); - assertNotEquals(0, field.compareTo(new AxField(fieldKey, AxArtifactKey.getNullKey(), false))); - assertNotEquals(0, field.compareTo(new AxField(fieldKey, schemaKey, false))); - assertEquals(0, field.compareTo(new AxField(fieldKey, schemaKey, true))); - - assertNotNull(field.getKeys()); - } -} diff --git a/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/ApexEventModelTest.java b/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/ApexEventModelTest.java new file mode 100644 index 000000000..aaed3cd7f --- /dev/null +++ b/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/ApexEventModelTest.java @@ -0,0 +1,308 @@ +/*- + * ============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.eventmodel.handling; + +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.AxValidationResult; +import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; +import org.onap.policy.apex.model.basicmodel.test.TestApexModel; +import org.onap.policy.apex.model.eventmodel.concepts.AxEventModel; + +public class ApexEventModelTest { + private Connection connection; + TestApexModel testApexModel; + + /** + * Set up the test. + * + * @throws Exception exceptions from 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(AxEventModel.class, new TestApexEventModelCreator()); + } + + @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 { + final AxValidationResult result = testApexModel.testApexModelVaidateObservation(); + assertTrue(result.toString().equals(OBSERVATION_MODEL_STRING)); + } + + @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); + } + + private static final String VALID_MODEL_STRING = "***validation of model successful***"; + + private static final String OBSERVATION_MODEL_STRING = "\n" + + "***observations noted during validation of model***\n" + + "AxArtifactKey:(name=event0,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" + + "AxArtifactKey:(name=event0,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" + + "AxArtifactKey:(name=event1,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" + + "AxArtifactKey:(name=event1,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" + + "AxArtifactKey:(name=event2,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" + + "AxArtifactKey:(name=event2,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" + + "********************************"; + + private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n" + + "AxArtifactKey:(name=event0,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:WARNING:nameSpace on event is blank\n" + + "AxArtifactKey:(name=event0,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" + + "AxArtifactKey:(name=event0,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" + + "AxArtifactKey:(name=event1,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:WARNING:nameSpace on event is blank\n" + + "AxArtifactKey:(name=event1,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" + + "AxArtifactKey:(name=event1,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" + + "AxArtifactKey:(name=event2,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:WARNING:nameSpace on event is blank\n" + + "AxArtifactKey:(name=event2,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" + + "AxArtifactKey:(name=event2,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" + + "********************************"; + + private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n" + + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):" + + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation:INVALID:" + + "keyInfoMap may not be empty\n" + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=smallEventModel,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=Schemas,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=BigIntType,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=BooleanType,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=IntType,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=MapType,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=SetType,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=StringType,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=smallEventMap,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=event0,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for parent key of key AxReferenceKey:" + + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par0)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for parent key of key AxReferenceKey:" + + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for parent key of key AxReferenceKey:" + + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par2)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for parent key of key AxReferenceKey:" + + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par3)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for parent key of key AxReferenceKey:" + + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par4)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for parent key of key AxReferenceKey:" + + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par5)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for parent key of key AxReferenceKey:" + + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par6)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=event1,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for parent key of key AxReferenceKey:" + + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=theOnlyPar)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "duplicate key AxArtifactKey:(name=event1,version=0.0.1) found\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=event1,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "duplicate key AxReferenceKey:(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL," + + "localName=theOnlyPar) found\n" + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for parent key of key AxReferenceKey:" + + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=theOnlyPar)\n" + + "AxArtifactKey:(name=event0,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" + + "AxArtifactKey:(name=event0,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" + + "AxArtifactKey:(name=event1,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" + + "AxArtifactKey:(name=event1,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" + + "AxArtifactKey:(name=event1,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:INVALID:" + + "parent key on parameter field AxReferenceKey:(parentKeyName=event0,parentKeyVersion=0.0.1," + + "parentLocalName=NULL,localName=theOnlyPar) does not equal event key\n" + + "AxArtifactKey:(name=smallEventMap,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvents:INVALID:" + + "key on event entry key AxArtifactKey:(name=event2,version=0.0.1) does not equal event value key " + + "AxArtifactKey:(name=event1,version=0.0.1)\n" + "AxArtifactKey:(name=event1,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" + + "AxArtifactKey:(name=event1,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" + + "AxArtifactKey:(name=event1,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:INVALID:" + + "parent key on parameter field AxReferenceKey:(parentKeyName=event0,parentKeyVersion=0.0.1," + + "parentLocalName=NULL,localName=theOnlyPar) does not equal event key\n" + + "********************************"; + + private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n" + + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):" + + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation:INVALID:" + + "keyInfoMap may not be empty\n" + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=smallEventModel,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=Schemas,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=SetType,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=smallEventMap,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=event1,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for parent key of key AxReferenceKey:" + + "(parentKeyName=event1,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=theOnlyPar)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "duplicate key AxArtifactKey:(name=event1,version=0.0.1) found\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for key AxArtifactKey:(name=event1,version=0.0.1)\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "duplicate key AxReferenceKey:(parentKeyName=event1,parentKeyVersion=0.0.1," + + "parentLocalName=NULL,localName=theOnlyPar) found\n" + + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" + + "key information not found for parent key of key AxReferenceKey:" + + "(parentKeyName=event1,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=theOnlyPar)\n" + + "AxArtifactKey:(name=event1,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" + + "AxArtifactKey:(name=event1,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" + + "AxArtifactKey:(name=smallEventMap,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvents:INVALID:" + + "key on event entry key AxArtifactKey:(name=event2,version=0.0.1) does not equal event value key " + + "AxArtifactKey:(name=event1,version=0.0.1)\n" + "AxArtifactKey:(name=event1,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" + + "AxArtifactKey:(name=event1,version=0.0.1):" + + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" + + "********************************"; +} diff --git a/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/TestApexEventModel.java b/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/TestApexEventModel.java deleted file mode 100644 index 643bdfaa2..000000000 --- a/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/TestApexEventModel.java +++ /dev/null @@ -1,308 +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.eventmodel.handling; - -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.AxValidationResult; -import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; -import org.onap.policy.apex.model.basicmodel.test.TestApexModel; -import org.onap.policy.apex.model.eventmodel.concepts.AxEventModel; - -public class TestApexEventModel { - private Connection connection; - TestApexModel testApexModel; - - /** - * Set up the test. - * - * @throws Exception exceptions from 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(AxEventModel.class, new TestApexEventModelCreator()); - } - - @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 { - final AxValidationResult result = testApexModel.testApexModelVaidateObservation(); - assertTrue(result.toString().equals(OBSERVATION_MODEL_STRING)); - } - - @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); - } - - private static final String VALID_MODEL_STRING = "***validation of model successful***"; - - private static final String OBSERVATION_MODEL_STRING = "\n" - + "***observations noted during validation of model***\n" - + "AxArtifactKey:(name=event0,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" - + "AxArtifactKey:(name=event0,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" - + "AxArtifactKey:(name=event1,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" - + "AxArtifactKey:(name=event1,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" - + "AxArtifactKey:(name=event2,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" - + "AxArtifactKey:(name=event2,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" - + "********************************"; - - private static final String WARNING_MODEL_STRING = "\n" + "***warnings issued during validation of model***\n" - + "AxArtifactKey:(name=event0,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:WARNING:nameSpace on event is blank\n" - + "AxArtifactKey:(name=event0,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" - + "AxArtifactKey:(name=event0,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" - + "AxArtifactKey:(name=event1,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:WARNING:nameSpace on event is blank\n" - + "AxArtifactKey:(name=event1,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" - + "AxArtifactKey:(name=event1,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" - + "AxArtifactKey:(name=event2,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:WARNING:nameSpace on event is blank\n" - + "AxArtifactKey:(name=event2,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" - + "AxArtifactKey:(name=event2,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" - + "********************************"; - - private static final String INVALID_MODEL_STRING = "\n" + "***validation of model failed***\n" - + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):" - + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation:INVALID:" - + "keyInfoMap may not be empty\n" + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=smallEventModel,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=Schemas,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=BigIntType,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=BooleanType,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=IntType,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=MapType,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=SetType,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=StringType,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=smallEventMap,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=event0,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for parent key of key AxReferenceKey:" - + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par0)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for parent key of key AxReferenceKey:" - + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for parent key of key AxReferenceKey:" - + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par2)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for parent key of key AxReferenceKey:" - + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par3)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for parent key of key AxReferenceKey:" - + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par4)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for parent key of key AxReferenceKey:" - + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par5)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for parent key of key AxReferenceKey:" - + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=par6)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=event1,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for parent key of key AxReferenceKey:" - + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=theOnlyPar)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "duplicate key AxArtifactKey:(name=event1,version=0.0.1) found\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=event1,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "duplicate key AxReferenceKey:(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL," - + "localName=theOnlyPar) found\n" + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for parent key of key AxReferenceKey:" - + "(parentKeyName=event0,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=theOnlyPar)\n" - + "AxArtifactKey:(name=event0,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" - + "AxArtifactKey:(name=event0,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" - + "AxArtifactKey:(name=event1,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" - + "AxArtifactKey:(name=event1,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" - + "AxArtifactKey:(name=event1,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:INVALID:" - + "parent key on parameter field AxReferenceKey:(parentKeyName=event0,parentKeyVersion=0.0.1," - + "parentLocalName=NULL,localName=theOnlyPar) does not equal event key\n" - + "AxArtifactKey:(name=smallEventMap,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvents:INVALID:" - + "key on event entry key AxArtifactKey:(name=event2,version=0.0.1) does not equal event value key " - + "AxArtifactKey:(name=event1,version=0.0.1)\n" + "AxArtifactKey:(name=event1,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" - + "AxArtifactKey:(name=event1,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" - + "AxArtifactKey:(name=event1,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:INVALID:" - + "parent key on parameter field AxReferenceKey:(parentKeyName=event0,parentKeyVersion=0.0.1," - + "parentLocalName=NULL,localName=theOnlyPar) does not equal event key\n" - + "********************************"; - - private static final String INVALID_MODEL_MALSTRUCTURED_STRING = "\n" + "***validation of model failed***\n" - + "AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1):" - + "org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation:INVALID:" - + "keyInfoMap may not be empty\n" + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=smallEventModel,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=KeyInfoMapKey,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=Schemas,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=SetType,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=smallEventMap,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=event1,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for parent key of key AxReferenceKey:" - + "(parentKeyName=event1,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=theOnlyPar)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "duplicate key AxArtifactKey:(name=event1,version=0.0.1) found\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for key AxArtifactKey:(name=event1,version=0.0.1)\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "duplicate key AxReferenceKey:(parentKeyName=event1,parentKeyVersion=0.0.1," - + "parentLocalName=NULL,localName=theOnlyPar) found\n" - + "AxArtifactKey:(name=smallEventModel,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEventModel:INVALID:" - + "key information not found for parent key of key AxReferenceKey:" - + "(parentKeyName=event1,parentKeyVersion=0.0.1,parentLocalName=NULL,localName=theOnlyPar)\n" - + "AxArtifactKey:(name=event1,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" - + "AxArtifactKey:(name=event1,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" - + "AxArtifactKey:(name=smallEventMap,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvents:INVALID:" - + "key on event entry key AxArtifactKey:(name=event2,version=0.0.1) does not equal event value key " - + "AxArtifactKey:(name=event1,version=0.0.1)\n" + "AxArtifactKey:(name=event1,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:source on event is blank\n" - + "AxArtifactKey:(name=event1,version=0.0.1):" - + "org.onap.policy.apex.model.eventmodel.concepts.AxEvent:OBSERVATION:target on event is blank\n" - + "********************************"; -} -- cgit 1.2.3-korg