From c7014b65d81dbb61309885f81e07ac915459aaf4 Mon Sep 17 00:00:00 2001 From: Parshad Patel Date: Wed, 28 Nov 2018 16:53:33 +0900 Subject: Rename test classes in apex-pdp/model/basic-model Make test classes name consitence by adding 'Support' or 'Dummy' at start of util or dummy type of test classes Issue-ID: POLICY-1263 Change-Id: Ia90e0ea73af16f6cde37692e98f1c4afc408dd2b Signed-off-by: Parshad Patel --- .../model/basicmodel/concepts/AxKeyUseTest.java | 82 ++++++ .../model/basicmodel/concepts/DummyEntity.java | 180 +++++++++++++ .../apex/model/basicmodel/concepts/KeyUseTest.java | 82 ------ .../apex/model/basicmodel/concepts/TestEntity.java | 180 ------------- .../apex/model/basicmodel/dao/EntityTest.java | 64 ++--- .../handling/ApexBasicModelConceptsTest.java | 279 --------------------- .../basicmodel/handling/ApexBasicModelTest.java | 149 ----------- .../handling/ApexModelExceptionTest.java | 41 +++ .../handling/ApexModelFileWriterTest.java | 127 ++++++++++ .../basicmodel/handling/ApexModelReaderTest.java | 152 +++++++++++ .../basicmodel/handling/ApexModelSaverTest.java | 51 ++++ .../handling/ApexModelStringWriterTest.java | 96 +++++++ .../basicmodel/handling/ApexModelWriterTest.java | 92 +++++++ .../handling/ApexSchemaGeneratorTest.java | 90 +++++++ .../basicmodel/handling/AxModelWithReferences.java | 72 ------ .../model/basicmodel/handling/BasicModelTest.java | 147 ----------- .../basicmodel/handling/ConceptGetterTest.java | 202 --------------- .../handling/DummyApexBasicModelCreator.java | 124 +++++++++ .../handling/DummyAxModelWithReferences.java | 72 ++++++ .../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 ------- .../SupportApexBasicModelConceptsTester.java | 279 +++++++++++++++++++++ .../handling/SupportApexBasicModelTester.java | 149 +++++++++++ .../handling/SupportBasicModelTester.java | 147 +++++++++++ .../handling/SupportConceptGetterTester.java | 202 +++++++++++++++ .../handling/TestApexBasicModelCreator.java | 124 --------- .../handling/TestApexModelCreator0Test.java | 64 +++++ .../handling/TestApexModelCreator1Test.java | 69 +++++ .../handling/TestApexModelCreator2Test.java | 64 +++++ .../handling/TestApexTestModelCreator0.java | 64 ----- .../handling/TestApexTestModelCreator1.java | 69 ----- .../handling/TestApexTestModelCreator2.java | 64 ----- .../model/basicmodel/service/ModelServiceTest.java | 6 +- .../src/test/resources/META-INF/persistence.xml | 2 +- 39 files changed, 2117 insertions(+), 2117 deletions(-) create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyUseTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java delete 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/TestEntity.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexBasicModelConceptsTest.java delete 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/ApexModelExceptionTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGeneratorTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/AxModelWithReferences.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/BasicModelTest.java delete 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/DummyApexBasicModelCreator.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyAxModelWithReferences.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ExceptionsTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelFileWriterTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelReaderTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelSaverTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelStringWriterTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelWriterTest.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SchemaGeneratorTest.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTester.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTester.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTester.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTester.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexBasicModelCreator.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexModelCreator0Test.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexModelCreator1Test.java create mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexModelCreator2Test.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexTestModelCreator0.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexTestModelCreator1.java delete mode 100644 model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexTestModelCreator2.java (limited to 'model') diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyUseTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyUseTest.java new file mode 100644 index 000000000..a1d272775 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/AxKeyUseTest.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 AxKeyUseTest { + + @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/DummyEntity.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java new file mode 100644 index 000000000..02174488e --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/DummyEntity.java @@ -0,0 +1,180 @@ +/* + * ============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 java.util.Arrays; +import java.util.List; + +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.Table; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + +import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; +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.xml.AxReferenceKeyAdapter; + +@Entity +@Table(name = "TestEntity") + +public class DummyEntity extends AxConcept { + private static final long serialVersionUID = -2962570563281067894L; + + @EmbeddedId() + @XmlElement(name = "key", required = true) + @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class) + protected AxReferenceKey key; + + private double doubleValue; + + public DummyEntity() { + this.key = new AxReferenceKey(); + this.doubleValue = 0; + } + + public DummyEntity(Double doubleValue) { + this.key = new AxReferenceKey(); + this.doubleValue = doubleValue; + } + + public DummyEntity(AxReferenceKey key, Double doubleValue) { + this.key = key; + this.doubleValue = doubleValue; + } + + public AxReferenceKey getKey() { + return key; + } + + public List getKeys() { + return Arrays.asList((AxKey) getKey()); + } + + public void setKey(AxReferenceKey key) { + this.key = key; + } + + public boolean checkSetKey() { + return (this.key != null); + } + + public double getDoubleValue() { + return doubleValue; + } + + public void setDoubleValue(double doubleValue) { + this.doubleValue = doubleValue; + } + + @Override + public AxValidationResult validate(AxValidationResult result) { + return key.validate(result); + } + + @Override + public void clean() { + key.clean(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("doubleValue="); + builder.append(doubleValue); + return builder.toString(); + } + + @Override + public AxConcept copyTo(AxConcept target) { + final Object copyObject = ((target == null) ? new DummyEntity() : target); + if (copyObject instanceof DummyEntity) { + final DummyEntity copy = ((DummyEntity) copyObject); + if (this.checkSetKey()) { + copy.setKey(new AxReferenceKey(key)); + } else { + copy.key = null; + } + copy.doubleValue = doubleValue; + return copy; + } else { + return null; + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((key == null) ? 0 : key.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (this == obj) { + return true; + } + if (getClass() != obj.getClass()) { + return false; + } + DummyEntity other = (DummyEntity) obj; + if (key == null) { + if (other.key != null) { + return false; + } + } else if (!key.equals(other.key)) { + return false; + } + if (doubleValue != other.doubleValue) { + return false; + } + return true; + } + + @Override + public int compareTo(AxConcept otherObj) { + if (otherObj == null) { + return -1; + } + if (this == otherObj) { + return 0; + } + DummyEntity other = (DummyEntity) otherObj; + if (key == null) { + if (other.key != null) { + return 1; + } + } else if (!key.equals(other.key)) { + return key.compareTo(other.key); + } + if (doubleValue != other.doubleValue) { + return new Double(doubleValue).compareTo(other.doubleValue); + } + + return 0; + } +} 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 deleted file mode 100644 index 65df26d65..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/KeyUseTest.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 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/TestEntity.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestEntity.java deleted file mode 100644 index 2667f3d4d..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/concepts/TestEntity.java +++ /dev/null @@ -1,180 +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 java.util.Arrays; -import java.util.List; - -import javax.persistence.EmbeddedId; -import javax.persistence.Entity; -import javax.persistence.Table; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; - -import org.onap.policy.apex.model.basicmodel.concepts.AxConcept; -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.xml.AxReferenceKeyAdapter; - -@Entity -@Table(name = "TestEntity") - -public class TestEntity extends AxConcept { - private static final long serialVersionUID = -2962570563281067894L; - - @EmbeddedId() - @XmlElement(name = "key", required = true) - @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class) - protected AxReferenceKey key; - - private double doubleValue; - - public TestEntity() { - this.key = new AxReferenceKey(); - this.doubleValue = 0; - } - - public TestEntity(Double doubleValue) { - this.key = new AxReferenceKey(); - this.doubleValue = doubleValue; - } - - public TestEntity(AxReferenceKey key, Double doubleValue) { - this.key = key; - this.doubleValue = doubleValue; - } - - public AxReferenceKey getKey() { - return key; - } - - public List getKeys() { - return Arrays.asList((AxKey) getKey()); - } - - public void setKey(AxReferenceKey key) { - this.key = key; - } - - public boolean checkSetKey() { - return (this.key != null); - } - - public double getDoubleValue() { - return doubleValue; - } - - public void setDoubleValue(double doubleValue) { - this.doubleValue = doubleValue; - } - - @Override - public AxValidationResult validate(AxValidationResult result) { - return key.validate(result); - } - - @Override - public void clean() { - key.clean(); - } - - @Override - public String toString() { - final StringBuilder builder = new StringBuilder(); - builder.append("doubleValue="); - builder.append(doubleValue); - return builder.toString(); - } - - @Override - public AxConcept copyTo(AxConcept target) { - final Object copyObject = ((target == null) ? new TestEntity() : target); - if (copyObject instanceof TestEntity) { - final TestEntity copy = ((TestEntity) copyObject); - if (this.checkSetKey()) { - copy.setKey(new AxReferenceKey(key)); - } else { - copy.key = null; - } - copy.doubleValue = doubleValue; - return copy; - } else { - return null; - } - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((key == null) ? 0 : key.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (this == obj) { - return true; - } - if (getClass() != obj.getClass()) { - return false; - } - TestEntity other = (TestEntity) obj; - if (key == null) { - if (other.key != null) { - return false; - } - } else if (!key.equals(other.key)) { - return false; - } - if (doubleValue != other.doubleValue) { - return false; - } - return true; - } - - @Override - public int compareTo(AxConcept otherObj) { - if (otherObj == null) { - return -1; - } - if (this == otherObj) { - return 0; - } - TestEntity other = (TestEntity) otherObj; - if (key == null) { - if (other.key != null) { - return 1; - } - } else if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - if (doubleValue != other.doubleValue) { - return new Double(doubleValue).compareTo(other.doubleValue); - } - - return 0; - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/EntityTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/EntityTest.java index 4c99ce314..0258b9305 100644 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/EntityTest.java +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/EntityTest.java @@ -42,7 +42,7 @@ 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.AxReferenceKey; -import org.onap.policy.apex.model.basicmodel.concepts.TestEntity; +import org.onap.policy.apex.model.basicmodel.concepts.DummyEntity; /** * JUnit test class. @@ -240,57 +240,57 @@ public class EntityTest { final AxArtifactKey owner4Key = new AxArtifactKey("Owner4", "0.0.1"); final AxArtifactKey owner5Key = new AxArtifactKey("Owner5", "0.0.1"); - apexDao.create(new TestEntity(new AxReferenceKey(owner0Key, "Entity0"), 100.0)); - apexDao.create(new TestEntity(new AxReferenceKey(owner0Key, "Entity1"), 101.0)); - apexDao.create(new TestEntity(new AxReferenceKey(owner0Key, "Entity2"), 102.0)); - apexDao.create(new TestEntity(new AxReferenceKey(owner0Key, "Entity3"), 103.0)); - apexDao.create(new TestEntity(new AxReferenceKey(owner0Key, "Entity4"), 104.0)); - apexDao.create(new TestEntity(new AxReferenceKey(owner1Key, "Entity5"), 105.0)); - apexDao.create(new TestEntity(new AxReferenceKey(owner1Key, "Entity6"), 106.0)); - apexDao.create(new TestEntity(new AxReferenceKey(owner1Key, "Entity7"), 107.0)); - apexDao.create(new TestEntity(new AxReferenceKey(owner2Key, "Entity8"), 108.0)); - apexDao.create(new TestEntity(new AxReferenceKey(owner2Key, "Entity9"), 109.0)); - apexDao.create(new TestEntity(new AxReferenceKey(owner3Key, "EntityA"), 110.0)); - apexDao.create(new TestEntity(new AxReferenceKey(owner4Key, "EntityB"), 111.0)); - apexDao.create(new TestEntity(new AxReferenceKey(owner5Key, "EntityC"), 112.0)); - apexDao.create(new TestEntity(new AxReferenceKey(owner5Key, "EntityD"), 113.0)); - apexDao.create(new TestEntity(new AxReferenceKey(owner5Key, "EntityE"), 114.0)); - apexDao.create(new TestEntity(new AxReferenceKey(owner5Key, "EntityF"), 115.0)); - - TreeSet testEntitySetOut = new TreeSet(apexDao.getAll(TestEntity.class)); + apexDao.create(new DummyEntity(new AxReferenceKey(owner0Key, "Entity0"), 100.0)); + apexDao.create(new DummyEntity(new AxReferenceKey(owner0Key, "Entity1"), 101.0)); + apexDao.create(new DummyEntity(new AxReferenceKey(owner0Key, "Entity2"), 102.0)); + apexDao.create(new DummyEntity(new AxReferenceKey(owner0Key, "Entity3"), 103.0)); + apexDao.create(new DummyEntity(new AxReferenceKey(owner0Key, "Entity4"), 104.0)); + apexDao.create(new DummyEntity(new AxReferenceKey(owner1Key, "Entity5"), 105.0)); + apexDao.create(new DummyEntity(new AxReferenceKey(owner1Key, "Entity6"), 106.0)); + apexDao.create(new DummyEntity(new AxReferenceKey(owner1Key, "Entity7"), 107.0)); + apexDao.create(new DummyEntity(new AxReferenceKey(owner2Key, "Entity8"), 108.0)); + apexDao.create(new DummyEntity(new AxReferenceKey(owner2Key, "Entity9"), 109.0)); + apexDao.create(new DummyEntity(new AxReferenceKey(owner3Key, "EntityA"), 110.0)); + apexDao.create(new DummyEntity(new AxReferenceKey(owner4Key, "EntityB"), 111.0)); + apexDao.create(new DummyEntity(new AxReferenceKey(owner5Key, "EntityC"), 112.0)); + apexDao.create(new DummyEntity(new AxReferenceKey(owner5Key, "EntityD"), 113.0)); + apexDao.create(new DummyEntity(new AxReferenceKey(owner5Key, "EntityE"), 114.0)); + apexDao.create(new DummyEntity(new AxReferenceKey(owner5Key, "EntityF"), 115.0)); + + TreeSet testEntitySetOut = new TreeSet(apexDao.getAll(DummyEntity.class)); assertEquals(16, testEntitySetOut.size()); - testEntitySetOut = new TreeSet(apexDao.getAll(TestEntity.class, owner0Key)); + testEntitySetOut = new TreeSet(apexDao.getAll(DummyEntity.class, owner0Key)); assertEquals(5, testEntitySetOut.size()); - testEntitySetOut = new TreeSet(apexDao.getAll(TestEntity.class, owner1Key)); + testEntitySetOut = new TreeSet(apexDao.getAll(DummyEntity.class, owner1Key)); assertEquals(3, testEntitySetOut.size()); - testEntitySetOut = new TreeSet(apexDao.getAll(TestEntity.class, owner2Key)); + testEntitySetOut = new TreeSet(apexDao.getAll(DummyEntity.class, owner2Key)); assertEquals(2, testEntitySetOut.size()); - testEntitySetOut = new TreeSet(apexDao.getAll(TestEntity.class, owner3Key)); + testEntitySetOut = new TreeSet(apexDao.getAll(DummyEntity.class, owner3Key)); assertEquals(1, testEntitySetOut.size()); - testEntitySetOut = new TreeSet(apexDao.getAll(TestEntity.class, owner4Key)); + testEntitySetOut = new TreeSet(apexDao.getAll(DummyEntity.class, owner4Key)); assertEquals(1, testEntitySetOut.size()); - testEntitySetOut = new TreeSet(apexDao.getAll(TestEntity.class, owner5Key)); + testEntitySetOut = new TreeSet(apexDao.getAll(DummyEntity.class, owner5Key)); assertEquals(4, testEntitySetOut.size()); - assertNotNull(apexDao.get(TestEntity.class, new AxReferenceKey(owner0Key, "Entity0"))); - assertNotNull(apexDao.getArtifact(TestEntity.class, new AxReferenceKey(owner0Key, "Entity0"))); - assertNull(apexDao.get(TestEntity.class, new AxReferenceKey(owner0Key, "Entity1000"))); - assertNull(apexDao.getArtifact(TestEntity.class, new AxReferenceKey(owner0Key, "Entity1000"))); - apexDao.delete(TestEntity.class, new AxReferenceKey(owner0Key, "Entity0")); + assertNotNull(apexDao.get(DummyEntity.class, new AxReferenceKey(owner0Key, "Entity0"))); + assertNotNull(apexDao.getArtifact(DummyEntity.class, new AxReferenceKey(owner0Key, "Entity0"))); + assertNull(apexDao.get(DummyEntity.class, new AxReferenceKey(owner0Key, "Entity1000"))); + assertNull(apexDao.getArtifact(DummyEntity.class, new AxReferenceKey(owner0Key, "Entity1000"))); + apexDao.delete(DummyEntity.class, new AxReferenceKey(owner0Key, "Entity0")); final Set rKeySetIn = new TreeSet(); rKeySetIn.add(new AxReferenceKey(owner4Key, "EntityB")); rKeySetIn.add(new AxReferenceKey(owner5Key, "EntityD")); - final int deletedRCount = apexDao.deleteByReferenceKey(TestEntity.class, rKeySetIn); + final int deletedRCount = apexDao.deleteByReferenceKey(DummyEntity.class, rKeySetIn); assertEquals(2, deletedRCount); - apexDao.update(new TestEntity(new AxReferenceKey(owner5Key, "EntityF"), 120.0)); + apexDao.update(new DummyEntity(new AxReferenceKey(owner5Key, "EntityF"), 120.0)); } } 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 deleted file mode 100644 index f2076c6e4..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexBasicModelConceptsTest.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 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 deleted file mode 100644 index e8c8ef154..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexBasicModelTest.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 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/ApexModelExceptionTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelExceptionTest.java new file mode 100644 index 000000000..c74f33ccb --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelExceptionTest.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 ApexModelExceptionTest { + + @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/ApexModelFileWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.java new file mode 100644 index 000000000..7c0ccc7d1 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelFileWriterTest.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 ApexModelFileWriterTest { + + @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 DummyApexBasicModelCreator().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/ApexModelReaderTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.java new file mode 100644 index 000000000..20815ae72 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelReaderTest.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 ApexModelReaderTest { + + @Test + public void testModelReader() throws IOException, ApexException { + AxModel model = new DummyApexBasicModelCreator().getModel(); + AxModel invalidModel = new DummyApexBasicModelCreator().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/ApexModelSaverTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.java new file mode 100644 index 000000000..65640916a --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelSaverTest.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 ApexModelSaverTest { + + @Test + public void testModelSaver() throws IOException, ApexException { + AxModel model = new DummyApexBasicModelCreator().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/ApexModelStringWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.java new file mode 100644 index 000000000..22271dda3 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelStringWriterTest.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 ApexModelStringWriterTest { + + @Test + public void testModelStringWriter() throws IOException, ApexException { + AxModel basicModel = new DummyApexBasicModelCreator().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/ApexModelWriterTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.java new file mode 100644 index 000000000..d7ff4c08b --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexModelWriterTest.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 ApexModelWriterTest { + + @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 DummyApexBasicModelCreator().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/ApexSchemaGeneratorTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGeneratorTest.java new file mode 100644 index 000000000..e7388b7e9 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ApexSchemaGeneratorTest.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 ApexSchemaGeneratorTest { + + @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/AxModelWithReferences.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/AxModelWithReferences.java deleted file mode 100644 index 8e52b393f..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/AxModelWithReferences.java +++ /dev/null @@ -1,72 +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.util.ArrayList; -import java.util.List; - -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.AxModel; -import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; - -public class AxModelWithReferences extends AxModel { - private static final long serialVersionUID = -8194956638511120008L; - - private List extrakeyList = new ArrayList<>(); - - public AxModelWithReferences(final AxArtifactKey key) { - super(key); - } - - @Override - public List getKeys() { - List keys = super.getKeys(); - keys.addAll(extrakeyList); - - return keys; - } - - public List getExtrakeyList() { - return extrakeyList; - } - - /** - * Set the reference key list. - */ - public void setReferenceKeyList() { - List keys = super.getKeys(); - - for (AxKey key: keys) { - AxArtifactKey akey = (AxArtifactKey)key; - AxReferenceKey keyRef = new AxReferenceKey(akey, akey.getName()); - extrakeyList.add(keyRef); - } - } - - public void addKey(final AxKey akey) { - extrakeyList.add(akey); - } - - public void removeKey(final AxKey akey) { - extrakeyList.remove(akey); - } -} 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 deleted file mode 100644 index 9881c7355..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/BasicModelTest.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 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 deleted file mode 100644 index 5dfd6711b..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ConceptGetterTest.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 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/DummyApexBasicModelCreator.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyApexBasicModelCreator.java new file mode 100644 index 000000000..d04d3a441 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyApexBasicModelCreator.java @@ -0,0 +1,124 @@ +/* + * ============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.util.UUID; + +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.AxKeyInformation; +import org.onap.policy.apex.model.basicmodel.concepts.AxModel; +import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator; + +public class DummyApexBasicModelCreator implements TestApexModelCreator { + + @Override + public AxModel getModel() { + AxModel basicModel = new AxModel(); + + basicModel.setKey(new AxArtifactKey("BasicModel", "0.0.1")); + basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); + + basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey())); + basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(), + new AxKeyInfo(basicModel.getKeyInformation().getKey())); + + AxKeyInfo intKeyInfo = new AxKeyInfo(new AxArtifactKey("IntegerKIKey", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey description"); + basicModel.getKeyInformation().getKeyInfoMap().put(intKeyInfo.getKey(), new AxKeyInfo(intKeyInfo.getKey())); + + AxKeyInfo floatKeyInfo = new AxKeyInfo(new AxArtifactKey("FloatKIKey", "0.0.1"), UUID.randomUUID(), + "FloatKIKey description"); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKeyInfo.getKey(), new AxKeyInfo(floatKeyInfo.getKey())); + + return basicModel; + } + + @Override + public final AxModel getMalstructuredModel() { + AxModel basicModel = new AxModel(); + + // Note: No Data types + basicModel.setKey(new AxArtifactKey("BasicModelKey", "0.0.1")); + basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); + + basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey(), + UUID.fromString("00000000-0000-0000-0000-000000000000"), + "\nbasic model description\nThis is a multi line description\nwith another line of text.")); + + return basicModel; + } + + @Override + public final AxModel getObservationModel() { + AxModel basicModel = getModel(); + + // Set key information as blank + basicModel.getKeyInformation().getKeyInfoMap().get(basicModel.getKey()).setDescription(""); + + return basicModel; + } + + @Override + public final AxModel getWarningModel() { + AxModel basicModel = getModel(); + + // Add unreferenced key information + AxKeyInfo unreferencedKeyInfo0 = new AxKeyInfo(new AxArtifactKey("Unref0", "0.0.1")); + AxKeyInfo unreferencedKeyInfo1 = new AxKeyInfo(new AxArtifactKey("Unref1", "0.0.1")); + + basicModel.getKeyInformation().getKeyInfoMap().put(unreferencedKeyInfo0.getKey(), unreferencedKeyInfo0); + basicModel.getKeyInformation().getKeyInfoMap().put(unreferencedKeyInfo1.getKey(), unreferencedKeyInfo1); + + return basicModel; + } + + @Override + public final AxModel getInvalidModel() { + AxModel basicModel = new AxModel(); + + basicModel.setKey(new AxArtifactKey("BasicModelKey", "0.0.1")); + basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); + + basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey(), + UUID.fromString("00000000-0000-0000-0000-000000000000"), + "nbasic model description\nThis is a multi line description\nwith another line of text.")); + basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(), + new AxKeyInfo(basicModel.getKeyInformation().getKey(), + UUID.fromString("00000000-0000-0000-0000-000000000000"), "")); + + return basicModel; + } + + /** + * Get the model with its references. + * @return the model with its references + */ + public final DummyAxModelWithReferences getModelWithReferences() { + AxModel model = getModel(); + + DummyAxModelWithReferences modelWithReferences = new DummyAxModelWithReferences(model.getKey()); + modelWithReferences.setKeyInformation(model.getKeyInformation()); + modelWithReferences.setReferenceKeyList(); + + return modelWithReferences; + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyAxModelWithReferences.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyAxModelWithReferences.java new file mode 100644 index 000000000..e0fe60337 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/DummyAxModelWithReferences.java @@ -0,0 +1,72 @@ +/* + * ============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.util.ArrayList; +import java.util.List; + +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.AxModel; +import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey; + +public class DummyAxModelWithReferences extends AxModel { + private static final long serialVersionUID = -8194956638511120008L; + + private List extrakeyList = new ArrayList<>(); + + public DummyAxModelWithReferences(final AxArtifactKey key) { + super(key); + } + + @Override + public List getKeys() { + List keys = super.getKeys(); + keys.addAll(extrakeyList); + + return keys; + } + + public List getExtrakeyList() { + return extrakeyList; + } + + /** + * Set the reference key list. + */ + public void setReferenceKeyList() { + List keys = super.getKeys(); + + for (AxKey key: keys) { + AxArtifactKey akey = (AxArtifactKey)key; + AxReferenceKey keyRef = new AxReferenceKey(akey, akey.getName()); + extrakeyList.add(keyRef); + } + } + + public void addKey(final AxKey akey) { + extrakeyList.add(akey); + } + + public void removeKey(final AxKey akey) { + extrakeyList.remove(akey); + } +} 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 deleted file mode 100644 index 8715cabe5..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ExceptionsTest.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 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 deleted file mode 100644 index 9a894e86b..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelFileWriterTest.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 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 deleted file mode 100644 index e4e33460e..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelReaderTest.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 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 deleted file mode 100644 index b318fc7af..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelSaverTest.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 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 deleted file mode 100644 index a44387559..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelStringWriterTest.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 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 deleted file mode 100644 index f79b4e4c6..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/ModelWriterTest.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 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 deleted file mode 100644 index 5950f1acc..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SchemaGeneratorTest.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 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/SupportApexBasicModelConceptsTester.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTester.java new file mode 100644 index 000000000..6ca94ddc8 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelConceptsTester.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 SupportApexBasicModelConceptsTester { + TestApexModel testApexModel; + + @Before + public void setup() throws Exception { + testApexModel = new TestApexModel(AxModel.class, new DummyApexBasicModelCreator()); + } + + @Test + public void testModelConcepts() { + final AxModel model = testApexModel.getModel(); + assertNotNull(model); + model.clean(); + assertNotNull(model); + + AxValidationResult result = new AxValidationResult(); + result = model.validate(result); + assertEquals(ValidationResult.WARNING, result.getValidationResult()); + + model.register(); + assertEquals(model.getKeyInformation(), ModelService.getModel(AxKeyInformation.class)); + + final AxModel clonedModel = new AxModel(model); + assertTrue(clonedModel.toString().startsWith("AxModel:(key=AxArtifactKey:(name=BasicModel")); + + 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 DummyAxModelWithReferences mwr = new DummyApexBasicModelCreator().getModelWithReferences(); + assertNotNull(mwr); + mwr.getKeyInformation().getKeyInfoMap().clear(); + mwr.getKeyInformation().generateKeyInfo(mwr); + + AxValidationResult result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + // Duplicate key error + mwr.addKey(mwr.getKey()); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + mwr.removeKey(mwr.getKey()); + + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + // Null Reference Key + mwr.addKey(AxReferenceKey.getNullKey()); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + mwr.removeKey(AxReferenceKey.getNullKey()); + + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + // Duplicate Reference Key + final AxReferenceKey rKey = new AxReferenceKey(mwr.getKey(), "LocalName"); + mwr.addKey(rKey); + mwr.addKey(rKey); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + mwr.removeKey(rKey); + mwr.removeKey(rKey); + + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + + // Key Use is legal + final AxKeyUse keyU = new AxKeyUse(mwr.getKey()); + mwr.addKey(keyU); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + mwr.removeKey(keyU); + + // Key Use on bad artifact key + final AxKeyUse keyBadUsage = new AxKeyUse(new AxArtifactKey("SomeKey", "0.0.1")); + mwr.addKey(keyBadUsage); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + mwr.removeKey(keyBadUsage); + + // Key Use on bad reference key + final AxKeyUse keyBadReferenceUsage = new AxKeyUse(new AxReferenceKey("SomeKey", "0.0.1", "Local")); + mwr.addKey(keyBadReferenceUsage); + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.INVALID, result.getValidationResult()); + mwr.removeKey(keyBadReferenceUsage); + + result = new AxValidationResult(); + result = mwr.validate(result); + assertEquals(ValidationResult.VALID, result.getValidationResult()); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTester.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTester.java new file mode 100644 index 000000000..a89be5477 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTester.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 SupportApexBasicModelTester { + 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 DummyApexBasicModelCreator()); + } + + @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/SupportBasicModelTester.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTester.java new file mode 100644 index 000000000..e632a521e --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportBasicModelTester.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 SupportBasicModelTester { + + @Test + public void testNormalModelCreator() throws ApexException { + final TestApexModel testApexModel = new TestApexModel(AxModel.class, + new DummyApexBasicModelCreator()); + + 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 TestApexModelCreator0Test()); + + 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 TestApexModelCreator1Test()); + + 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 TestApexModelCreator2Test()); + + 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 TestApexModelCreator1Test()); + + 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/SupportConceptGetterTester.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTester.java new file mode 100644 index 000000000..bed65c6e7 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportConceptGetterTester.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 SupportConceptGetterTester { + + @Test + public void testConceptGetter() throws IOException, ApexException { + AxModel basicModel = new DummyApexBasicModelCreator().getModel(); + assertNotNull(basicModel); + + AxKeyInfo intKI01 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey01", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey01 description"); + AxKeyInfo intKI11 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey11", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey11 description"); + AxKeyInfo intKI21 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey21", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey21 description"); + AxKeyInfo intKI22 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey22", "0.0.2"), UUID.randomUUID(), + "IntegerKIKey22 description"); + AxKeyInfo intKI23 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey23", "0.0.3"), UUID.randomUUID(), + "IntegerKIKey23 description"); + AxKeyInfo intKI24 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey24", "0.0.4"), UUID.randomUUID(), + "IntegerKIKey24 description"); + AxKeyInfo intKI25 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey25", "0.0.5"), UUID.randomUUID(), + "IntegerKIKey25 description"); + AxKeyInfo intKI26 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey26", "0.0.6"), UUID.randomUUID(), + "IntegerKIKey26 description"); + AxKeyInfo intKI31 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey31", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey31 description"); + AxKeyInfo intKI41 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey41", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey41 description"); + AxKeyInfo intKI51 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey51", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey51 description"); + AxKeyInfo intKI52 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey52", "0.0.2"), UUID.randomUUID(), + "IntegerKIKey52 description"); + AxKeyInfo intKI53 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey53", "0.0.3"), UUID.randomUUID(), + "IntegerKIKey53 description"); + AxKeyInfo intKI54 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey54", "0.0.4"), UUID.randomUUID(), + "IntegerKIKey54 description"); + AxKeyInfo intKI61 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey61", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey61 description"); + AxKeyInfo intKI62 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey62", "0.0.2"), UUID.randomUUID(), + "IntegerKIKey62 description"); + AxKeyInfo intKI63 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey63", "0.0.3"), UUID.randomUUID(), + "IntegerKIKey63 description"); + AxKeyInfo intKI64 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey64", "0.0.4"), UUID.randomUUID(), + "IntegerKIKey64 description"); + AxKeyInfo intKI71 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey71", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey71 description"); + AxKeyInfo intKI81 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey81", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey81 description"); + AxKeyInfo intKI91 = new AxKeyInfo(new AxArtifactKey("IntegerKIKey91", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey91 description"); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI31.getKey(), intKI31); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI24.getKey(), intKI24); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI11.getKey(), intKI11); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI64.getKey(), intKI64); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI41.getKey(), intKI41); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI51.getKey(), intKI51); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI23.getKey(), intKI23); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI81.getKey(), intKI81); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI71.getKey(), intKI71); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI01.getKey(), intKI01); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI91.getKey(), intKI91); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI52.getKey(), intKI52); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI53.getKey(), intKI53); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI62.getKey(), intKI62); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI54.getKey(), intKI54); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI26.getKey(), intKI26); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI22.getKey(), intKI22); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI25.getKey(), intKI25); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI21.getKey(), intKI21); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI61.getKey(), intKI61); + basicModel.getKeyInformation().getKeyInfoMap().put(intKI63.getKey(), intKI63); + + AxKeyInfo floatKI01 = new AxKeyInfo(new AxArtifactKey("FloatKIKey01", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey01 description"); + AxKeyInfo floatKI11 = new AxKeyInfo(new AxArtifactKey("FloatKIKey11", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey11 description"); + AxKeyInfo floatKI21 = new AxKeyInfo(new AxArtifactKey("FloatKIKey21", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey21 description"); + AxKeyInfo floatKI31 = new AxKeyInfo(new AxArtifactKey("FloatKIKey31", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey31 description"); + AxKeyInfo floatKI41 = new AxKeyInfo(new AxArtifactKey("FloatKIKey41", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey41 description"); + AxKeyInfo floatKI51 = new AxKeyInfo(new AxArtifactKey("FloatKIKey51", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey51 description"); + AxKeyInfo floatKI61 = new AxKeyInfo(new AxArtifactKey("FloatKIKey61", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey61 description"); + AxKeyInfo floatKI71 = new AxKeyInfo(new AxArtifactKey("FloatKIKey71", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey71 description"); + AxKeyInfo floatKI81 = new AxKeyInfo(new AxArtifactKey("FloatKIKey81", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey81 description"); + AxKeyInfo floatKI82 = new AxKeyInfo(new AxArtifactKey("FloatKIKey82", "0.0.2"), UUID.randomUUID(), + "IntegerKIKey82 description"); + AxKeyInfo floatKI83 = new AxKeyInfo(new AxArtifactKey("FloatKIKey83", "0.0.3"), UUID.randomUUID(), + "IntegerKIKey83 description"); + AxKeyInfo floatKI91 = new AxKeyInfo(new AxArtifactKey("FloatKIKey91", "0.0.1"), UUID.randomUUID(), + "IntegerKIKey91 description"); + AxKeyInfo floatKI92 = new AxKeyInfo(new AxArtifactKey("FloatKIKey92", "0.0.2"), UUID.randomUUID(), + "IntegerKIKey92 description"); + AxKeyInfo floatKI93 = new AxKeyInfo(new AxArtifactKey("FloatKIKey93", "0.0.3"), UUID.randomUUID(), + "IntegerKIKey93 description"); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI11.getKey(), floatKI11); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI83.getKey(), floatKI83); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI51.getKey(), floatKI51); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI71.getKey(), floatKI71); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI21.getKey(), floatKI21); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI81.getKey(), floatKI81); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI92.getKey(), floatKI92); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI91.getKey(), floatKI91); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI01.getKey(), floatKI01); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI82.getKey(), floatKI82); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI61.getKey(), floatKI61); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI41.getKey(), floatKI41); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI31.getKey(), floatKI31); + basicModel.getKeyInformation().getKeyInfoMap().put(floatKI93.getKey(), floatKI93); + + assertNull(basicModel.getKeyInformation().get("NonExistantKey", "0.0.6")); + 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/TestApexBasicModelCreator.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexBasicModelCreator.java deleted file mode 100644 index b11669fdf..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexBasicModelCreator.java +++ /dev/null @@ -1,124 +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.util.UUID; - -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.AxKeyInformation; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator; - -public class TestApexBasicModelCreator implements TestApexModelCreator { - - @Override - public AxModel getModel() { - AxModel basicModel = new AxModel(); - - basicModel.setKey(new AxArtifactKey("BasicModel", "0.0.1")); - basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); - - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey())); - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(), - new AxKeyInfo(basicModel.getKeyInformation().getKey())); - - AxKeyInfo intKeyInfo = new AxKeyInfo(new AxArtifactKey("IntegerKIKey", "0.0.1"), UUID.randomUUID(), - "IntegerKIKey description"); - basicModel.getKeyInformation().getKeyInfoMap().put(intKeyInfo.getKey(), new AxKeyInfo(intKeyInfo.getKey())); - - AxKeyInfo floatKeyInfo = new AxKeyInfo(new AxArtifactKey("FloatKIKey", "0.0.1"), UUID.randomUUID(), - "FloatKIKey description"); - basicModel.getKeyInformation().getKeyInfoMap().put(floatKeyInfo.getKey(), new AxKeyInfo(floatKeyInfo.getKey())); - - return basicModel; - } - - @Override - public final AxModel getMalstructuredModel() { - AxModel basicModel = new AxModel(); - - // Note: No Data types - basicModel.setKey(new AxArtifactKey("BasicModelKey", "0.0.1")); - basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); - - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey(), - UUID.fromString("00000000-0000-0000-0000-000000000000"), - "\nbasic model description\nThis is a multi line description\nwith another line of text.")); - - return basicModel; - } - - @Override - public final AxModel getObservationModel() { - AxModel basicModel = getModel(); - - // Set key information as blank - basicModel.getKeyInformation().getKeyInfoMap().get(basicModel.getKey()).setDescription(""); - - return basicModel; - } - - @Override - public final AxModel getWarningModel() { - AxModel basicModel = getModel(); - - // Add unreferenced key information - AxKeyInfo unreferencedKeyInfo0 = new AxKeyInfo(new AxArtifactKey("Unref0", "0.0.1")); - AxKeyInfo unreferencedKeyInfo1 = new AxKeyInfo(new AxArtifactKey("Unref1", "0.0.1")); - - basicModel.getKeyInformation().getKeyInfoMap().put(unreferencedKeyInfo0.getKey(), unreferencedKeyInfo0); - basicModel.getKeyInformation().getKeyInfoMap().put(unreferencedKeyInfo1.getKey(), unreferencedKeyInfo1); - - return basicModel; - } - - @Override - public final AxModel getInvalidModel() { - AxModel basicModel = new AxModel(); - - basicModel.setKey(new AxArtifactKey("BasicModelKey", "0.0.1")); - basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); - - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey(), - UUID.fromString("00000000-0000-0000-0000-000000000000"), - "nbasic model description\nThis is a multi line description\nwith another line of text.")); - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(), - new AxKeyInfo(basicModel.getKeyInformation().getKey(), - UUID.fromString("00000000-0000-0000-0000-000000000000"), "")); - - return basicModel; - } - - /** - * Get the model with its references. - * @return the model with its references - */ - public final AxModelWithReferences getModelWithReferences() { - AxModel model = getModel(); - - AxModelWithReferences modelWithReferences = new AxModelWithReferences(model.getKey()); - modelWithReferences.setKeyInformation(model.getKeyInformation()); - modelWithReferences.setReferenceKeyList(); - - return modelWithReferences; - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexModelCreator0Test.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexModelCreator0Test.java new file mode 100644 index 000000000..d0e8807e1 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexModelCreator0Test.java @@ -0,0 +1,64 @@ +/* + * ============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 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.AxKeyInformation; +import org.onap.policy.apex.model.basicmodel.concepts.AxModel; +import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator; + +public class TestApexModelCreator0Test implements TestApexModelCreator { + + @Override + public AxModel getModel() { + AxModel basicModel = new AxModel(); + + basicModel.setKey(new AxArtifactKey("BasicModel", "0.0.1")); + basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); + + basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey())); + basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(), + new AxKeyInfo(basicModel.getKeyInformation().getKey())); + + return basicModel; + } + + @Override + public final AxModel getMalstructuredModel() { + return getModel(); + } + + @Override + public final AxModel getObservationModel() { + return getModel(); + } + + @Override + public final AxModel getWarningModel() { + return getModel(); + } + + @Override + public final AxModel getInvalidModel() { + return getModel(); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexModelCreator1Test.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexModelCreator1Test.java new file mode 100644 index 000000000..f785a47ba --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexModelCreator1Test.java @@ -0,0 +1,69 @@ +/* + * ============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.util.UUID; + +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.AxKeyInformation; +import org.onap.policy.apex.model.basicmodel.concepts.AxModel; +import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator; + +public class TestApexModelCreator1Test implements TestApexModelCreator { + + @Override + public AxModel getModel() { + return getInvalidModel(); + } + + @Override + public final AxModel getMalstructuredModel() { + return getInvalidModel(); + } + + @Override + public final AxModel getObservationModel() { + return getInvalidModel(); + } + + @Override + public final AxModel getWarningModel() { + return getInvalidModel(); + } + + @Override + public final AxModel getInvalidModel() { + AxModel basicModel = new AxModel(); + + basicModel.setKey(new AxArtifactKey("BasicModelKey", "0.0.1")); + basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); + + basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey(), + UUID.fromString("00000000-0000-0000-0000-000000000000"), + "nbasic model description\nThis is a multi line description\nwith another line of text.")); + basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(), + new AxKeyInfo(basicModel.getKeyInformation().getKey(), + UUID.fromString("00000000-0000-0000-0000-000000000000"), "")); + + return basicModel; + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexModelCreator2Test.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexModelCreator2Test.java new file mode 100644 index 000000000..9be21f522 --- /dev/null +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexModelCreator2Test.java @@ -0,0 +1,64 @@ +/* + * ============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 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.AxKeyInformation; +import org.onap.policy.apex.model.basicmodel.concepts.AxModel; +import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator; + +public class TestApexModelCreator2Test implements TestApexModelCreator { + + @Override + public AxModel getModel() { + AxModel basicModel = new AxModel(); + + basicModel.setKey(new AxArtifactKey("BasicModel", "0.0.1")); + basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); + + basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey())); + basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(), + new AxKeyInfo(basicModel.getKeyInformation().getKey())); + basicModel.getKeyInformation().get("BasicModel").setDescription(""); + return basicModel; + } + + @Override + public final AxModel getMalstructuredModel() { + return getModel(); + } + + @Override + public final AxModel getObservationModel() { + return getModel(); + } + + @Override + public final AxModel getWarningModel() { + return getModel(); + } + + @Override + public final AxModel getInvalidModel() { + return getModel(); + } +} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexTestModelCreator0.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexTestModelCreator0.java deleted file mode 100644 index a3d841a51..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexTestModelCreator0.java +++ /dev/null @@ -1,64 +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 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.AxKeyInformation; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator; - -public class TestApexTestModelCreator0 implements TestApexModelCreator { - - @Override - public AxModel getModel() { - AxModel basicModel = new AxModel(); - - basicModel.setKey(new AxArtifactKey("BasicModel", "0.0.1")); - basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); - - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey())); - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(), - new AxKeyInfo(basicModel.getKeyInformation().getKey())); - - return basicModel; - } - - @Override - public final AxModel getMalstructuredModel() { - return getModel(); - } - - @Override - public final AxModel getObservationModel() { - return getModel(); - } - - @Override - public final AxModel getWarningModel() { - return getModel(); - } - - @Override - public final AxModel getInvalidModel() { - return getModel(); - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexTestModelCreator1.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexTestModelCreator1.java deleted file mode 100644 index cbbe05a36..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexTestModelCreator1.java +++ /dev/null @@ -1,69 +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.util.UUID; - -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.AxKeyInformation; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator; - -public class TestApexTestModelCreator1 implements TestApexModelCreator { - - @Override - public AxModel getModel() { - return getInvalidModel(); - } - - @Override - public final AxModel getMalstructuredModel() { - return getInvalidModel(); - } - - @Override - public final AxModel getObservationModel() { - return getInvalidModel(); - } - - @Override - public final AxModel getWarningModel() { - return getInvalidModel(); - } - - @Override - public final AxModel getInvalidModel() { - AxModel basicModel = new AxModel(); - - basicModel.setKey(new AxArtifactKey("BasicModelKey", "0.0.1")); - basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); - - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey(), - UUID.fromString("00000000-0000-0000-0000-000000000000"), - "nbasic model description\nThis is a multi line description\nwith another line of text.")); - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(), - new AxKeyInfo(basicModel.getKeyInformation().getKey(), - UUID.fromString("00000000-0000-0000-0000-000000000000"), "")); - - return basicModel; - } -} diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexTestModelCreator2.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexTestModelCreator2.java deleted file mode 100644 index a7b77865d..000000000 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/TestApexTestModelCreator2.java +++ /dev/null @@ -1,64 +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 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.AxKeyInformation; -import org.onap.policy.apex.model.basicmodel.concepts.AxModel; -import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator; - -public class TestApexTestModelCreator2 implements TestApexModelCreator { - - @Override - public AxModel getModel() { - AxModel basicModel = new AxModel(); - - basicModel.setKey(new AxArtifactKey("BasicModel", "0.0.1")); - basicModel.setKeyInformation(new AxKeyInformation(new AxArtifactKey("KeyInfoMapKey", "0.0.1"))); - - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKey(), new AxKeyInfo(basicModel.getKey())); - basicModel.getKeyInformation().getKeyInfoMap().put(basicModel.getKeyInformation().getKey(), - new AxKeyInfo(basicModel.getKeyInformation().getKey())); - basicModel.getKeyInformation().get("BasicModel").setDescription(""); - return basicModel; - } - - @Override - public final AxModel getMalstructuredModel() { - return getModel(); - } - - @Override - public final AxModel getObservationModel() { - return getModel(); - } - - @Override - public final AxModel getWarningModel() { - return getModel(); - } - - @Override - public final AxModel getInvalidModel() { - return getModel(); - } -} 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 index f1bb220b3..1ebfb6d71 100644 --- 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 @@ -27,7 +27,7 @@ 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; +import org.onap.policy.apex.model.basicmodel.handling.DummyApexBasicModelCreator; public class ModelServiceTest { @@ -44,7 +44,7 @@ public class ModelServiceTest { } ModelService.registerModel(AxKeyInformation.class, - new TestApexBasicModelCreator().getModel().getKeyInformation()); + new DummyApexBasicModelCreator().getModel().getKeyInformation()); assertTrue(ModelService.existsModel(AxKeyInformation.class)); assertNotNull(ModelService.getModel(AxKeyInformation.class)); @@ -59,7 +59,7 @@ public class ModelServiceTest { } ModelService.registerModel(AxKeyInformation.class, - new TestApexBasicModelCreator().getModel().getKeyInformation()); + new DummyApexBasicModelCreator().getModel().getKeyInformation()); assertTrue(ModelService.existsModel(AxKeyInformation.class)); assertNotNull(ModelService.getModel(AxKeyInformation.class)); diff --git a/model/basic-model/src/test/resources/META-INF/persistence.xml b/model/basic-model/src/test/resources/META-INF/persistence.xml index ffc6526c3..68f03e8e5 100644 --- a/model/basic-model/src/test/resources/META-INF/persistence.xml +++ b/model/basic-model/src/test/resources/META-INF/persistence.xml @@ -30,7 +30,7 @@ org.onap.policy.apex.model.basicmodel.concepts.AxKeyInfo org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation org.onap.policy.apex.model.basicmodel.concepts.AxModel - org.onap.policy.apex.model.basicmodel.concepts.TestEntity + org.onap.policy.apex.model.basicmodel.concepts.DummyEntity -- cgit 1.2.3-korg