diff options
Diffstat (limited to 'plugins/plugins-persistence/plugins-persistence-jpa')
6 files changed, 551 insertions, 15 deletions
diff --git a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/EclipselinkApexDaoTest.java b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/EclipselinkApexDaoTest.java index 21b58f878..311af8257 100644 --- a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/EclipselinkApexDaoTest.java +++ b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/EclipselinkApexDaoTest.java @@ -5,15 +5,15 @@ * 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========================================================= */ @@ -32,16 +32,16 @@ import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.onap.policy.apex.context.test.entities.ArtifactKeyTestEntity; -import org.onap.policy.apex.context.test.entities.ReferenceKeyTestEntity; 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.AxReferenceKey; import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; +import org.onap.policy.apex.plugins.persistence.jpa.eclipselink.entities.ArtifactKeyTestEntity; +import org.onap.policy.apex.plugins.persistence.jpa.eclipselink.entities.ReferenceKeyTestEntity; /** * Junit tests for class EclipselinkApexDao. - * + * * @author Dinh Danh Le (dinh.danh.le@ericsson.com) * */ @@ -57,7 +57,7 @@ public class EclipselinkApexDaoTest { /** * Setup the tests. - * + * * @throws ApexException Exceptions from test setup */ @Before @@ -192,7 +192,7 @@ public class EclipselinkApexDaoTest { new AxReferenceKey(owner0Key, "Entity02"), new AxReferenceKey(owner0Key, "Entity03") }); - + // prepare 2 more AxReferenceKeys corresponding to owner1Key final AxReferenceKey refKey11 = new AxReferenceKey(owner1Key, "Entity11"); final AxReferenceKey refKey12 = new AxReferenceKey(owner1Key, "Entity12"); diff --git a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/ArtifactKeyTestEntity.java b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/ArtifactKeyTestEntity.java new file mode 100644 index 000000000..cd0d7d16d --- /dev/null +++ b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/ArtifactKeyTestEntity.java @@ -0,0 +1,257 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.persistence.jpa.eclipselink.entities; + +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 org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; +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.AxValidationResult; + +/** + * The Class ArtifactKeyTestEntity is an entity for testing artifact keys. + */ +@Entity +@Table(name = "ArtifactKeyTestEntity") +public class ArtifactKeyTestEntity extends AxConcept { + private static final long serialVersionUID = -2962570563281067896L; + + @EmbeddedId() + @XmlElement(name = "key", required = true) + protected AxArtifactKey key; + + private double doubleValue; + + /** + * Instantiates a new artifact key test entity. + */ + public ArtifactKeyTestEntity() { + this.key = new AxArtifactKey(); + this.doubleValue = 0; + } + + /** + * Instantiates a new artifact key test entity. + * + * @param doubleValue the double value + */ + public ArtifactKeyTestEntity(final Double doubleValue) { + this.key = new AxArtifactKey(); + this.doubleValue = doubleValue; + } + + /** + * Instantiates a new artifact key test entity. + * + * @param key the key + * @param doubleValue the double value + */ + public ArtifactKeyTestEntity(final AxArtifactKey key, final Double doubleValue) { + this.key = key; + this.doubleValue = doubleValue; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey() + */ + @Override + public AxArtifactKey getKey() { + return key; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys() + */ + @Override + public List<AxKey> getKeys() { + return Arrays.asList((AxKey) getKey()); + } + + /** + * Sets the key. + * + * @param key the new key + */ + public void setKey(final AxArtifactKey key) { + this.key = key; + } + + /** + * Check set key. + * + * @return true, if successful + */ + public boolean checkSetKey() { + return (this.key != null); + } + + /** + * Gets the double value. + * + * @return the double value + */ + public double getDoubleValue() { + return doubleValue; + } + + /** + * Sets the double value. + * + * @param doubleValue the new double value + */ + public void setDoubleValue(final double doubleValue) { + this.doubleValue = doubleValue; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.basicmodel.concepts. + * AxValidationResult) + */ + @Override + public AxValidationResult validate(final AxValidationResult result) { + return key.validate(result); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean() + */ + @Override + public void clean() { + key.clean(); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString() + */ + @Override + public String toString() { + return "ArtifactKeyTestEntity [key=" + key + ", doubleValue=" + doubleValue + "]"; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.basicmodel.concepts. + * AxConcept) + */ + @Override + public AxConcept copyTo(final AxConcept target) { + final Object copyObject = ((target == null) ? new ArtifactKeyTestEntity() : target); + if (copyObject instanceof ArtifactKeyTestEntity) { + final ArtifactKeyTestEntity copy = ((ArtifactKeyTestEntity) copyObject); + if (this.checkSetKey()) { + copy.setKey(new AxArtifactKey(key)); + } else { + copy.key = null; + } + copy.doubleValue = doubleValue; + return copy; + } else { + return null; + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((key == null) ? 0 : key.hashCode()); + return result; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object) + */ + @Override + public boolean equals(final Object obj) { + if (obj == null) { + return false; + } + if (this == obj) { + return true; + } + if (getClass() != obj.getClass()) { + return false; + } + final ArtifactKeyTestEntity other = (ArtifactKeyTestEntity) obj; + if (key == null) { + if (other.key != null) { + return false; + } + } else if (!key.equals(other.key)) { + return false; + } + return (Double.compare(doubleValue, other.doubleValue) == 0); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + @Override + public int compareTo(final AxConcept otherObj) { + if (otherObj == null) { + return -1; + } + if (this == otherObj) { + return 0; + } + if (getClass() != otherObj.getClass()) { + return -1; + } + final ArtifactKeyTestEntity other = (ArtifactKeyTestEntity) otherObj; + if (key == null) { + if (other.key != null) { + return 1; + } + } else if (!key.equals(other.key)) { + return key.compareTo(other.key); + } + return Double.compare(doubleValue, other.doubleValue); + } +} diff --git a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/ReferenceKeyTestEntity.java b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/ReferenceKeyTestEntity.java new file mode 100644 index 000000000..eb5db7145 --- /dev/null +++ b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/ReferenceKeyTestEntity.java @@ -0,0 +1,260 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.apex.plugins.persistence.jpa.eclipselink.entities; + +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; + +/** + * The Class ReferenceKeyTestEntity provides a reference key test concept. + */ +@Entity +@Table(name = "ReferenceKeyTestEntity") +public class ReferenceKeyTestEntity extends AxConcept { + private static final long serialVersionUID = -2962570563281067895L; + + @EmbeddedId() + @XmlElement(name = "key", required = true) + @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class) + protected AxReferenceKey key; + + private double doubleValue; + + /** + * Instantiates a new reference key test entity. + */ + public ReferenceKeyTestEntity() { + this.key = new AxReferenceKey(); + this.doubleValue = 0; + } + + /** + * Instantiates a new reference key test entity. + * + * @param doubleValue the double value + */ + public ReferenceKeyTestEntity(final Double doubleValue) { + this.key = new AxReferenceKey(); + this.doubleValue = doubleValue; + } + + /** + * Instantiates a new reference key test entity. + * + * @param key the key + * @param doubleValue the double value + */ + public ReferenceKeyTestEntity(final AxReferenceKey key, final Double doubleValue) { + this.key = key; + this.doubleValue = doubleValue; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey() + */ + @Override + public AxReferenceKey getKey() { + return key; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys() + */ + @Override + public List<AxKey> getKeys() { + return Arrays.asList((AxKey) getKey()); + } + + /** + * Sets the key. + * + * @param key the new key + */ + public void setKey(final AxReferenceKey key) { + this.key = key; + } + + /** + * Check set key. + * + * @return true, if successful + */ + public boolean checkSetKey() { + return (this.key != null); + } + + /** + * Gets the double value. + * + * @return the double value + */ + public double getDoubleValue() { + return doubleValue; + } + + /** + * Sets the double value. + * + * @param doubleValue the new double value + */ + public void setDoubleValue(final double doubleValue) { + this.doubleValue = doubleValue; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.basicmodel.concepts. + * AxValidationResult) + */ + @Override + public AxValidationResult validate(final AxValidationResult result) { + return key.validate(result); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean() + */ + @Override + public void clean() { + key.clean(); + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString() + */ + @Override + public String toString() { + return "ReferenceKeyTestEntity [key=" + key + ", doubleValue=" + doubleValue + "]"; + } + + /* + * (non-Javadoc) + * + * @see + * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.basicmodel.concepts. + * AxConcept) + */ + @Override + public AxConcept copyTo(final AxConcept target) { + final Object copyObject = ((target == null) ? new ReferenceKeyTestEntity() : target); + if (copyObject instanceof ReferenceKeyTestEntity) { + final ReferenceKeyTestEntity copy = ((ReferenceKeyTestEntity) copyObject); + if (this.checkSetKey()) { + copy.setKey(new AxReferenceKey(key)); + } else { + copy.key = null; + } + copy.doubleValue = doubleValue; + return copy; + } else { + return null; + } + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((key == null) ? 0 : key.hashCode()); + return result; + } + + /* + * (non-Javadoc) + * + * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object) + */ + @Override + public boolean equals(final Object obj) { + if (obj == null) { + return false; + } + if (this == obj) { + return true; + } + if (getClass() != obj.getClass()) { + return false; + } + final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) obj; + if (key == null) { + if (other.key != null) { + return false; + } + } else if (!key.equals(other.key)) { + return false; + } + return (Double.compare(doubleValue, other.doubleValue) == 0); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + @Override + public int compareTo(final AxConcept otherObj) { + if (otherObj == null) { + return -1; + } + if (this == otherObj) { + return 0; + } + if (getClass() != otherObj.getClass()) { + return -1; + } + final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) otherObj; + if (key == null) { + if (other.key != null) { + return 1; + } + } else if (!key.equals(other.key)) { + return key.compareTo(other.key); + } + return Double.compare(doubleValue, other.doubleValue); + } +} diff --git a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/package-info.java b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/package-info.java new file mode 100644 index 000000000..b30d40559 --- /dev/null +++ b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/java/org/onap/policy/apex/plugins/persistence/jpa/eclipselink/entities/package-info.java @@ -0,0 +1,24 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +/** + * Contains common test entities. + */ +package org.onap.policy.apex.plugins.persistence.jpa.eclipselink.entities; diff --git a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/resources/META-INF/persistence.xml b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/resources/META-INF/persistence.xml index 130079dd9..3f8be58e4 100644 --- a/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/resources/META-INF/persistence.xml +++ b/plugins/plugins-persistence/plugins-persistence-jpa/plugins-persistence-jpa-eclipselink/src/test/resources/META-INF/persistence.xml @@ -24,8 +24,8 @@ <persistence-unit name="DAOTest" transaction-type="RESOURCE_LOCAL"> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> - <class>org.onap.policy.apex.context.test.entities.ReferenceKeyTestEntity</class> - <class>org.onap.policy.apex.context.test.entities.ArtifactKeyTestEntity</class> + <class>org.onap.policy.apex.plugins.persistence.jpa.eclipselink.entities.ReferenceKeyTestEntity</class> + <class>org.onap.policy.apex.plugins.persistence.jpa.eclipselink.entities.ArtifactKeyTestEntity</class> <properties> <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" /> diff --git a/plugins/plugins-persistence/plugins-persistence-jpa/pom.xml b/plugins/plugins-persistence/plugins-persistence-jpa/pom.xml index 8425af3ee..b43cc4d71 100644 --- a/plugins/plugins-persistence/plugins-persistence-jpa/pom.xml +++ b/plugins/plugins-persistence/plugins-persistence-jpa/pom.xml @@ -39,11 +39,6 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>org.onap.policy.apex-pdp.context</groupId> - <artifactId>context-test-utils</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>test</scope> |