summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lombok.config2
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConcept.java28
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java268
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java20
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfKey.java13
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfKeyUse.java84
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfModel.java73
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfModelException.java38
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfModelRuntimeException.java38
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfModelService.java36
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java5
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfUtils.java59
-rw-r--r--models-base/src/main/java/org/onap/policy/models/base/PfValidationResult.java23
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/ExceptionsTest.java27
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/ModelServiceTest.java105
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java199
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfConceptGetterImplTest.java4
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java69
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java59
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java145
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java10
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaEventFilter.java)46
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java137
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptContainer.java77
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptKeySub.java (renamed from models-base/src/test/java/org/onap/policy/models/base/testpojos/DummyPfConcept.java)70
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptSub.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaEntrySchema.java)53
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java (renamed from models-base/src/test/java/org/onap/policy/models/base/testpojos/DummyPfKey.java)7
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfModel.java174
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/DaoParameters.java2
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/PfDaoFactory.java8
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/converters/CDataConditioner.java2
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/converters/Uuid2String.java4
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/converters/package-info.java2
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java12
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/impl/package-info.java2
-rw-r--r--models-dao/src/main/java/org/onap/policy/models/dao/package-info.java6
-rw-r--r--models-dao/src/test/java/org/onap/policy/models/dao/converters/CDataConditionerTest.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaPolicyList.java)41
-rw-r--r--models-dao/src/test/java/org/onap/policy/models/dao/converters/Uuid2StringConditionerTest.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaPolicyTypeList.java)44
-rw-r--r--models-provider/pom.xml54
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java156
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaTimeInterval.java)36
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/PolicyModelsProviderImpl.java98
-rw-r--r--models-tosca/pom.xml8
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaConstraint.java93
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaDataType.java70
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaPolicy.java70
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaPolicyType.java75
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaProperty.java80
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaTrigger.java88
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraint.java125
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogical.java119
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalKey.java155
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalString.java137
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataType.java246
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataTypes.java86
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntityType.java (renamed from models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaEntityType.java)97
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntrySchema.java228
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEventFilter.java197
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaModel.java160
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicies.java86
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicy.java273
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyType.java294
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypes.java86
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaProperty.java308
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplate.java222
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplates.java86
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTimeInterval.java188
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplate.java178
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTrigger.java335
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/TestPojos.java (renamed from models-tosca/src/test/java/org/onap/policy/models/tosca/TestPojos.java)4
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalKeyTest.java134
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalStringTest.java133
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalTest.java166
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaDataTypeTest.java140
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaDataTypesTest.java76
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaEntrySchemaTest.java147
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaEventFilterTest.java165
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaModelTest.java142
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPoliciesTest.java76
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTest.java162
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypeTest.java208
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypesTest.java76
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPropertyTest.java223
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplateTest.java170
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplatesTest.java76
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTimeIntervalTest.java181
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplateTest.java134
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTriggerTest.java228
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/testconcepts/DummyToscaConstraint.java62
-rw-r--r--pom.xml9
90 files changed, 8246 insertions, 892 deletions
diff --git a/lombok.config b/lombok.config
new file mode 100644
index 000000000..df71bb6a0
--- /dev/null
+++ b/lombok.config
@@ -0,0 +1,2 @@
+config.stopBubbling = true
+lombok.addLombokGeneratedAnnotation = true
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConcept.java b/models-base/src/main/java/org/onap/policy/models/base/PfConcept.java
index b74b0374d..c41b0de56 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfConcept.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfConcept.java
@@ -23,7 +23,7 @@ package org.onap.policy.models.base;
import java.io.Serializable;
import java.util.List;
-import org.onap.policy.common.utils.validation.Assertions;
+import lombok.NonNull;
/**
* This class is the base class for all Policy Framework concept classes. It enforces implementation
@@ -43,8 +43,7 @@ public abstract class PfConcept implements Serializable, Comparable<PfConcept> {
*
* @param copyConcept the concept to copy from
*/
- public PfConcept(final PfConcept copyConcept) {
- Assertions.argumentNotNull(copyConcept, "copy concept may not be null");
+ public PfConcept(@NonNull final PfConcept copyConcept) {
copyConcept.copyTo(this);
}
@@ -70,7 +69,7 @@ public abstract class PfConcept implements Serializable, Comparable<PfConcept> {
* @return the validation result that was passed in in the @{link result} field with the result
* of this validation added
*/
- public abstract PfValidationResult validate(PfValidationResult result);
+ public abstract PfValidationResult validate(@NonNull final PfValidationResult result);
/**
* Clean this concept, tidy up any superfluous information such as leading and trailing white
@@ -78,27 +77,12 @@ public abstract class PfConcept implements Serializable, Comparable<PfConcept> {
*/
public abstract void clean();
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#equals(java.lang.Object)
- */
@Override
public abstract boolean equals(Object otherObject);
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#toString()
- */
@Override
public abstract String toString();
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Object#hashCode()
- */
@Override
public abstract int hashCode();
@@ -109,7 +93,7 @@ public abstract class PfConcept implements Serializable, Comparable<PfConcept> {
* @param target the target object to which this object is copied
* @return the copied object
*/
- public abstract PfConcept copyTo(PfConcept target);
+ public abstract PfConcept copyTo(@NonNull PfConcept target);
/**
* Gets the ID string of this concept.
@@ -126,9 +110,7 @@ public abstract class PfConcept implements Serializable, Comparable<PfConcept> {
* @param id the key ID to match against
* @return true, if this key matches the ID
*/
- public final boolean matchesId(final String id) {
- Assertions.argumentNotNull(id, "id may not be null");
-
+ public final boolean matchesId(@NonNull final String id) {
// Check the ID
return getId().equals(id);
}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
new file mode 100644
index 000000000..46094610a
--- /dev/null
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptContainer.java
@@ -0,0 +1,268 @@
+/*-
+ * ============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.models.base;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.NavigableMap;
+import java.util.Set;
+import java.util.TreeMap;
+
+import javax.persistence.CascadeType;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.ManyToMany;
+import javax.persistence.Table;
+import javax.ws.rs.core.Response;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+
+import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+
+/**
+ * This class is a concept container and holds a map of concepts. The {@link PfConceptContainer}
+ * class implements the helper methods of the {@link PfConceptGetter} interface to allow
+ * {@link PfConceptContainer} instances to be retrieved by calling methods directly on this class
+ * without referencing the contained map.
+ *
+ * <p>Validation checks that the container key is not null. An error is issued if no concepts are
+ * defined in the container. Each concept entry is checked to ensure that its key and value are not
+ * null and that the key matches the key in the map value. Each concept entry is then validated
+ * individually.
+ *
+ * @param C the concept being contained
+ */
+@Entity
+@Table(name = "PfConceptContainer")
+@Data
+@EqualsAndHashCode(callSuper = false)
+
+public class PfConceptContainer<C extends PfConcept> extends PfConcept implements PfConceptGetter<C> {
+ private static final long serialVersionUID = -324211738823208318L;
+
+ @EmbeddedId
+ private PfConceptKey key;
+
+ @ManyToMany(cascade = CascadeType.ALL)
+ private Map<PfConceptKey, C> conceptMap;
+
+ /**
+ * The Default Constructor creates a {@link PfConceptContainer} object with a null artifact key
+ * and creates an empty concept map.
+ */
+ public PfConceptContainer() {
+ this(new PfConceptKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link PfConceptContainer} object with the given artifact key
+ * and creates an empty concept map.
+ *
+ * @param key the concept key
+ */
+ public PfConceptContainer(@NonNull final PfConceptKey key) {
+ this(key, new TreeMap<PfConceptKey, C>());
+ }
+
+ /**
+ * This Constructor creates an concept container with all of its fields defined.
+ *
+ * @param key the concept container key
+ * @param conceptMap the concepts to be stored in the concept container
+ */
+ public PfConceptContainer(@NonNull final PfConceptKey key, @NonNull final Map<PfConceptKey, C> conceptMap) {
+ super();
+
+ this.key = key;
+ this.conceptMap = new TreeMap<>(conceptMap);
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public PfConceptContainer(@NonNull final PfConceptContainer<C> copyConcept) {
+ super(copyConcept);
+ }
+
+ @Override
+ public List<PfKey> getKeys() {
+ final List<PfKey> keyList = key.getKeys();
+
+ for (final C concept : conceptMap.values()) {
+ keyList.addAll(concept.getKeys());
+ }
+
+ return keyList;
+ }
+
+ @Override
+ public void clean() {
+ key.clean();
+ for (final Entry<PfConceptKey, C> conceptEntry : conceptMap.entrySet()) {
+ conceptEntry.getKey().clean();
+ conceptEntry.getValue().clean();
+ }
+ }
+
+ @Override
+ public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ if (key.equals(PfConceptKey.getNullKey())) {
+ result.addValidationMessage(
+ new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
+ }
+
+ result = key.validate(result);
+
+ if (conceptMap.isEmpty()) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "conceptMap may not be empty"));
+ } else {
+ result = validateConceptMap(result);
+ }
+
+ return result;
+ }
+
+ /**
+ * Validate the concept map of the container.
+ *
+ * @param resultIn the incoming validation results so far
+ * @return the validation results with the results of this validation added
+ */
+ private PfValidationResult validateConceptMap(final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ for (final Entry<PfConceptKey, C> conceptEntry : conceptMap.entrySet()) {
+ if (conceptEntry.getKey().equals(PfConceptKey.getNullKey())) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "key on concept entry " + conceptEntry.getKey() + " may not be the null key"));
+ } else if (conceptEntry.getValue() == null) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "value on concept entry " + conceptEntry.getKey() + " may not be null"));
+ } else if (!conceptEntry.getKey().equals(conceptEntry.getValue().getKey())) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(),
+ ValidationResult.INVALID, "key on concept entry key " + conceptEntry.getKey()
+ + " does not equal concept value key " + conceptEntry.getValue().getKey()));
+ result = conceptEntry.getValue().validate(result);
+ } else {
+ result = conceptEntry.getValue().validate(result);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+ if (this == otherConcept) {
+ return 0;
+ }
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ @SuppressWarnings("unchecked")
+ final PfConceptContainer<C> other = (PfConceptContainer<C>) otherConcept;
+ int retVal = key.compareTo(other.key);
+ if (retVal != 0) {
+ return retVal;
+ }
+
+ if (!conceptMap.equals(other.conceptMap)) {
+ return (conceptMap.hashCode() - other.conceptMap.hashCode());
+ }
+
+ return 0;
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull final PfConcept target) {
+ Assertions.instanceOf(target, PfConceptContainer.class);
+
+ @SuppressWarnings("unchecked")
+ final PfConceptContainer<C> copy = (PfConceptContainer<C>) target;
+ copy.setKey(new PfConceptKey(key));
+ final Map<PfConceptKey, C> newConceptMap = new TreeMap<>();
+ for (final Entry<PfConceptKey, C> conceptMapEntry : conceptMap.entrySet()) {
+ newConceptMap.put(new PfConceptKey(conceptMapEntry.getKey()),
+ new ConceptCloner().cloneConcept(conceptMapEntry.getValue()));
+ }
+ copy.setConceptMap(newConceptMap);
+
+ return copy;
+ }
+
+ @Override
+ public C get(final PfConceptKey conceptKey) {
+ return new PfConceptGetterImpl<>((NavigableMap<PfConceptKey, C>) conceptMap).get(conceptKey);
+ }
+
+ @Override
+ public C get(final String conceptKeyName) {
+ return new PfConceptGetterImpl<>((NavigableMap<PfConceptKey, C>) conceptMap).get(conceptKeyName);
+ }
+
+ @Override
+ public C get(final String conceptKeyName, final String conceptKeyVersion) {
+ return new PfConceptGetterImpl<>((NavigableMap<PfConceptKey, C>) conceptMap).get(conceptKeyName,
+ conceptKeyVersion);
+ }
+
+ @Override
+ public Set<C> getAll(final String conceptKeyName) {
+ return new PfConceptGetterImpl<>((NavigableMap<PfConceptKey, C>) conceptMap).getAll(conceptKeyName);
+ }
+
+ @Override
+ public Set<C> getAll(final String conceptKeyName, final String conceptKeyVersion) {
+ return new PfConceptGetterImpl<>((NavigableMap<PfConceptKey, C>) conceptMap).getAll(conceptKeyName,
+ conceptKeyVersion);
+ }
+
+ /**
+ * Private inner class that returns a clone of a concept by calling the copy constructor on the
+ * original class.
+ */
+ private class ConceptCloner {
+ @SuppressWarnings("unchecked")
+ public C cloneConcept(final C originalConcept) {
+ try {
+ C clonedConcept = (C) originalConcept.getClass().newInstance();
+ originalConcept.copyTo(clonedConcept);
+ return clonedConcept;
+ } catch (Exception ex) {
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
+ "Failed to create a clone of class \"" + originalConcept.getClass().getCanonicalName() + "\"",
+ ex);
+ }
+ }
+ }
+}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java
index efcbe392c..695ca4712 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfConceptKey.java
@@ -28,6 +28,7 @@ import javax.persistence.Embeddable;
import lombok.Data;
import lombok.EqualsAndHashCode;
+import lombok.NonNull;
import org.onap.policy.common.utils.validation.Assertions;
import org.onap.policy.models.base.PfValidationResult.ValidationResult;
@@ -67,7 +68,7 @@ public class PfConceptKey extends PfKey {
*
* @param copyConcept the concept to copy from
*/
- public PfConceptKey(final PfConceptKey copyConcept) {
+ public PfConceptKey(@NonNull final PfConceptKey copyConcept) {
super(copyConcept);
}
@@ -77,7 +78,7 @@ public class PfConceptKey extends PfKey {
* @param name the key name
* @param version the key version
*/
- public PfConceptKey(final String name, final String version) {
+ public PfConceptKey(@NonNull final String name, @NonNull final String version) {
super();
this.name = Assertions.validateStringParameter(NAME_TOKEN, name, NAME_REGEXP);
this.version = Assertions.validateStringParameter(VERSION_TOKEN, version, VERSION_REGEXP);
@@ -88,9 +89,7 @@ public class PfConceptKey extends PfKey {
*
* @param id the key ID in a format that respects the KEY_ID_REGEXP
*/
- public PfConceptKey(final String id) {
- Assertions.argumentNotNull(id, "id may not be null");
-
+ public PfConceptKey(@NonNull final String id) {
// Check the incoming ID is valid
Assertions.validateStringParameter("id", id, KEY_ID_REGEXP);
@@ -131,7 +130,12 @@ public class PfConceptKey extends PfKey {
}
@Override
- public PfKey.Compatibility getCompatibility(final PfKey otherKey) {
+ public boolean isNullKey() {
+ return this.equals(PfConceptKey.getNullKey());
+ }
+
+ @Override
+ public PfKey.Compatibility getCompatibility(@NonNull final PfKey otherKey) {
if (!(otherKey instanceof PfConceptKey)) {
return Compatibility.DIFFERENT;
}
@@ -161,7 +165,7 @@ public class PfConceptKey extends PfKey {
}
@Override
- public boolean isCompatible(final PfKey otherKey) {
+ public boolean isCompatible(@NonNull final PfKey otherKey) {
if (!(otherKey instanceof PfConceptKey)) {
return false;
}
@@ -212,7 +216,7 @@ public class PfConceptKey extends PfKey {
}
@Override
- public int compareTo(final PfConcept otherObj) {
+ public int compareTo(@NonNull final PfConcept otherObj) {
Assertions.argumentNotNull(otherObj, "comparison object may not be null");
if (this == otherObj) {
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfKey.java
index dda4cdc03..6e9035e95 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfKey.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfKey.java
@@ -20,6 +20,8 @@
package org.onap.policy.models.base;
+import lombok.NonNull;
+
/**
* The key uniquely identifies every entity in the system. This class is an abstract class to give a common parent for
* all key types in the system.
@@ -89,7 +91,7 @@ public abstract class PfKey extends PfConcept {
* @param otherKey the key to check compatibility against
* @return the compatibility result of the check
*/
- public abstract Compatibility getCompatibility(PfKey otherKey);
+ public abstract Compatibility getCompatibility(@NonNull PfKey otherKey);
/**
* Check if two keys are compatible, that is the keys are IDENTICAL or have only MINOR, PATCH differences.
@@ -97,5 +99,12 @@ public abstract class PfKey extends PfConcept {
* @param otherKey the key to check compatibility against
* @return true, if the keys are compatible
*/
- public abstract boolean isCompatible(PfKey otherKey);
+ public abstract boolean isCompatible(@NonNull PfKey otherKey);
+
+ /**
+ * Check if a key equals its null key.
+ *
+ * @return true, if the key is a null key
+ */
+ public abstract boolean isNullKey();
}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfKeyUse.java b/models-base/src/main/java/org/onap/policy/models/base/PfKeyUse.java
index 0eb55a711..57141c2fa 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfKeyUse.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfKeyUse.java
@@ -22,16 +22,20 @@ package org.onap.policy.models.base;
import java.util.List;
+import javax.ws.rs.core.Response;
+
import lombok.EqualsAndHashCode;
+import lombok.NonNull;
import lombok.ToString;
import org.onap.policy.common.utils.validation.Assertions;
import org.onap.policy.models.base.PfValidationResult.ValidationResult;
/**
- * This class records a usage of a key in the system. When the list of keys being used by a concept is built using the
- * getKeys() method of the {@link PfConcept} class, an instance of this class is created for every key occurrence. The
- * list of keys returned by the getKeys() method is a list of {@link PfKeyUse} objects.
+ * This class records a usage of a key in the system. When the list of keys being used by a concept
+ * is built using the getKeys() method of the {@link PfConcept} class, an instance of this class is
+ * created for every key occurrence. The list of keys returned by the getKeys() method is a list of
+ * {@link PfKeyUse} objects.
*
* <p>Validation checks that each key is valid.
*/
@@ -50,22 +54,21 @@ public class PfKeyUse extends PfKey {
}
/**
- * Copy constructor.
+ * This constructor creates an instance of this class, and holds a reference to a used key.
*
- * @param copyConcept the concept to copy from
+ * @param usedKey a used key
*/
- public PfKeyUse(final PfKeyUse copyConcept) {
- super(copyConcept);
+ public PfKeyUse(@NonNull final PfKey usedKey) {
+ this.usedKey = usedKey;
}
/**
- * This constructor creates an instance of this class, and holds a reference to a used key.
+ * Copy constructor.
*
- * @param usedKey a used key
+ * @param copyConcept the concept to copy from
*/
- public PfKeyUse(final PfKey usedKey) {
- Assertions.argumentNotNull(usedKey, "usedKey may not be null");
- this.usedKey = usedKey;
+ public PfKeyUse(@NonNull final PfKeyUse copyConcept) {
+ super(copyConcept);
}
@Override
@@ -83,56 +86,42 @@ public class PfKeyUse extends PfKey {
return usedKey.getId();
}
+ @Override
+ public boolean isNullKey() {
+ return usedKey.isNullKey();
+ }
+
/**
* Sets the key.
*
* @param key the key
*/
- public void setKey(final PfKey key) {
- Assertions.argumentNotNull(key, "usedKey may not be null");
+ public void setKey(@NonNull final PfKey key) {
this.usedKey = key;
}
@Override
- public PfKey.Compatibility getCompatibility(final PfKey otherKey) {
+ public PfKey.Compatibility getCompatibility(@NonNull final PfKey otherKey) {
return usedKey.getCompatibility(otherKey);
}
@Override
- public boolean isCompatible(final PfKey otherKey) {
+ public boolean isCompatible(@NonNull final PfKey otherKey) {
return usedKey.isCompatible(otherKey);
}
@Override
- public PfValidationResult validate(final PfValidationResult result) {
- if (usedKey.equals(PfConceptKey.getNullKey())) {
- result.addValidationMessage(new PfValidationMessage(usedKey, this.getClass(), ValidationResult.INVALID,
- "usedKey is a null key"));
- }
- return usedKey.validate(result);
- }
-
- @Override
public void clean() {
usedKey.clean();
}
@Override
- public PfConcept copyTo(final PfConcept target) {
- Assertions.argumentNotNull(target, "target may not be null");
-
- final Object copyObject = target;
- Assertions.instanceOf(copyObject, PfKeyUse.class);
-
- final PfKeyUse copy = ((PfKeyUse) copyObject);
- try {
- copy.usedKey = usedKey.getClass().newInstance();
- } catch (final Exception e) {
- throw new PfModelRuntimeException("error copying concept key: " + e.getMessage(), e);
+ public PfValidationResult validate(@NonNull final PfValidationResult result) {
+ if (usedKey.isNullKey()) {
+ result.addValidationMessage(new PfValidationMessage(usedKey, this.getClass(), ValidationResult.INVALID,
+ "usedKey is a null key"));
}
- usedKey.copyTo(copy.usedKey);
-
- return copy;
+ return usedKey.validate(result);
}
@Override
@@ -150,4 +139,21 @@ public class PfKeyUse extends PfKey {
return usedKey.compareTo(other.usedKey);
}
+
+ @Override
+ public PfConcept copyTo(@NonNull final PfConcept target) {
+ final Object copyObject = target;
+ Assertions.instanceOf(copyObject, PfKeyUse.class);
+
+ final PfKeyUse copy = ((PfKeyUse) copyObject);
+ try {
+ copy.usedKey = usedKey.getClass().newInstance();
+ } catch (final Exception e) {
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
+ "error copying concept key: " + e.getMessage(), e);
+ }
+ usedKey.copyTo(copy.usedKey);
+
+ return copy;
+ }
}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfModel.java b/models-base/src/main/java/org/onap/policy/models/base/PfModel.java
index c9174bde8..3dc233b02 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfModel.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfModel.java
@@ -63,8 +63,7 @@ public abstract class PfModel extends PfConcept {
private static final long serialVersionUID = -771659065637205430L;
@EmbeddedId
- @NonNull
- private PfConceptKey key = PfConceptKey.getNullKey();
+ private PfConceptKey key;
/**
* The Default Constructor creates this concept with a NULL artifact key.
@@ -74,20 +73,11 @@ public abstract class PfModel extends PfConcept {
}
/**
- * Copy constructor.
- *
- * @param copyConcept the concept to copy from
- */
- public PfModel(final PfModel copyConcept) {
- super(copyConcept);
- }
-
- /**
* Constructor to create this concept with the specified key.
*
* @param key the key of this concept
*/
- public PfModel(final PfConceptKey key) {
+ public PfModel(@NonNull final PfConceptKey key) {
super();
Assertions.argumentNotNull(key, "key may not be null");
@@ -95,6 +85,15 @@ public abstract class PfModel extends PfConcept {
}
/**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public PfModel(@NonNull final PfModel copyConcept) {
+ super(copyConcept);
+ }
+
+ /**
* Registers this model with the {@link PfModelService}. All models are registered with the
* model service so that models can be references from anywhere in the Policy Framework system
* without being passed as references through deep call chains.
@@ -107,10 +106,15 @@ public abstract class PfModel extends PfConcept {
}
@Override
- public PfValidationResult validate(final PfValidationResult resultIn) {
+ public void clean() {
+ key.clean();
+ }
+
+ @Override
+ public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
PfValidationResult result = resultIn;
- if (key.equals(PfConceptKey.getNullKey())) {
+ if (key.isNullKey()) {
result.addValidationMessage(
new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
}
@@ -129,7 +133,7 @@ public abstract class PfModel extends PfConcept {
} else if (pfKey instanceof PfReferenceKey) {
result = validateReferenceKeyInModel((PfReferenceKey) pfKey, referenceKeySet, result);
}
- // It must be an PfKeyUse, nothing else is legal
+ // It must be a PfKeyUse, nothing else is legal
else {
usedKeySet.add((PfKeyUse) pfKey);
}
@@ -160,7 +164,7 @@ public abstract class PfModel extends PfConcept {
private PfValidationResult validateArtifactKeyInModel(final PfConceptKey artifactKey,
final Set<PfConceptKey> artifactKeySet, final PfValidationResult result) {
// Null key check
- if (artifactKey.equals(PfConceptKey.getNullKey())) {
+ if (artifactKey.isNullKey()) {
result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
"key " + artifactKey + IS_A_NULL_KEY));
}
@@ -194,13 +198,13 @@ public abstract class PfModel extends PfConcept {
private PfValidationResult validateReferenceKeyInModel(final PfReferenceKey referenceKey,
final Set<PfReferenceKey> referenceKeySet, final PfValidationResult result) {
// Null key check
- if (referenceKey.equals(PfReferenceKey.getNullKey())) {
+ if (referenceKey.isNullKey()) {
result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
"key " + referenceKey + IS_A_NULL_KEY));
}
// Null parent key check
- if (referenceKey.getParentConceptKey().equals(PfConceptKey.getNullKey())) {
+ if (referenceKey.getParentConceptKey().isNullKey()) {
result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
"parent artifact key of key " + referenceKey + IS_A_NULL_KEY));
}
@@ -262,29 +266,6 @@ public abstract class PfModel extends PfConcept {
}
@Override
- public void clean() {
- key.clean();
- }
-
- @Override
- public PfConcept copyTo(final PfConcept target) {
- Assertions.argumentNotNull(target, "target may not be null");
-
- final Object copyObject = target;
- Assertions.instanceOf(copyObject, PfModel.class);
-
- final PfModel copy = ((PfModel) copyObject);
- copy.setKey(new PfConceptKey(key));
-
- return copy;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see java.lang.Comparable#compareTo(java.lang.Object)
- */
- @Override
public int compareTo(final PfConcept otherObj) {
if (otherObj == null) {
return -1;
@@ -300,4 +281,14 @@ public abstract class PfModel extends PfConcept {
return key.compareTo(other.key);
}
+
+ @Override
+ public PfConcept copyTo(@NonNull final PfConcept target) {
+ Assertions.instanceOf(target, PfModel.class);
+
+ final PfModel copy = ((PfModel) target);
+ copy.setKey(new PfConceptKey(key));
+
+ return copy;
+ }
}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfModelException.java b/models-base/src/main/java/org/onap/policy/models/base/PfModelException.java
index 3d1bb1794..97ea7de00 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfModelException.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfModelException.java
@@ -20,54 +20,71 @@
package org.onap.policy.models.base;
+import javax.ws.rs.core.Response;
+
+import lombok.Getter;
+import lombok.ToString;
+
/**
* This class is a base exception from which all model exceptions are sub classes.
*/
+@Getter
+@ToString
public class PfModelException extends Exception {
private static final long serialVersionUID = -8507246953751956974L;
+ // The status code on the exception
+ private final Response.Status statusCode;
+
// The object on which the exception was thrown
private final transient Object object;
/**
* Instantiates a new model exception.
*
+ * @param statusCode the return code for the exception
* @param message the message on the exception
*/
- public PfModelException(final String message) {
- this(message, null);
+ public PfModelException(final Response.Status statusCode, final String message) {
+ this(statusCode, message, null);
}
/**
* Instantiates a new model exception.
*
+ * @param statusCode the return code for the exception
* @param message the message on the exception
* @param object the object that the exception was thrown on
*/
- public PfModelException(final String message, final Object object) {
+ public PfModelException(final Response.Status statusCode, final String message, final Object object) {
super(message);
+ this.statusCode = statusCode;
this.object = object;
}
/**
* Instantiates a new model exception.
*
+ * @param statusCode the return code for the exception
* @param message the message on the exception
* @param exception the exception that caused this exception
*/
- public PfModelException(final String message, final Exception exception) {
- this(message, exception, null);
+ public PfModelException(final Response.Status statusCode, final String message, final Exception exception) {
+ this(statusCode, message, exception, null);
}
/**
* Instantiates a new exception.
*
+ * @param statusCode the return code for the exception
* @param message the message on the exception
* @param exception the exception that caused this exception
* @param object the object that the exception was thrown on
*/
- public PfModelException(final String message, final Exception exception, final Object object) {
+ public PfModelException(final Response.Status statusCode, final String message, final Exception exception,
+ final Object object) {
super(message, exception);
+ this.statusCode = statusCode;
this.object = object;
}
@@ -97,13 +114,4 @@ public class PfModelException extends Exception {
return builder.toString();
}
-
- /**
- * Get the object on which the exception was thrown.
- *
- * @return The object on which the exception was thrown
- */
- public Object getObject() {
- return object;
- }
}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfModelRuntimeException.java b/models-base/src/main/java/org/onap/policy/models/base/PfModelRuntimeException.java
index 0780a9e20..c4684bc09 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfModelRuntimeException.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfModelRuntimeException.java
@@ -20,56 +20,73 @@
package org.onap.policy.models.base;
+import javax.ws.rs.core.Response;
+
+import lombok.Getter;
+import lombok.ToString;
+
/**
* This class is a base model run time exception from which all model run time exceptions are sub
* classes.
*/
+@Getter
+@ToString
public class PfModelRuntimeException extends RuntimeException {
private static final long serialVersionUID = -8507246953751956974L;
+ // The return code on the exception
+ private final Response.Status statusCode;
+
// The object on which the exception was thrown
private final transient Object object;
/**
* Instantiates a new model runtime exception.
*
+ * @param statusCode the return code for the exception
* @param message the message on the exception
*/
- public PfModelRuntimeException(final String message) {
- this(message, null);
+ public PfModelRuntimeException(final Response.Status statusCode, final String message) {
+ this(statusCode, message, null);
}
/**
* Instantiates a new model runtime exception.
*
+ * @param statusCode the return code for the exception
* @param message the message on the exception
* @param object the object that the exception was thrown on
*/
- public PfModelRuntimeException(final String message, final Object object) {
+ public PfModelRuntimeException(final Response.Status statusCode, final String message, final Object object) {
super(message);
this.object = object;
+ this.statusCode = statusCode;
}
/**
* Instantiates a new model runtime exception.
*
+ * @param statusCode the return code for the exception
* @param message the message on the exception
* @param exception the exception that caused this model exception
*/
- public PfModelRuntimeException(final String message, final Exception exception) {
- this(message, exception, null);
+ public PfModelRuntimeException(final Response.Status statusCode, final String message, final Exception exception) {
+ this(statusCode, message, exception, null);
}
/**
* Instantiates a new model runtime exception.
*
+ * @param statusCode the return code for the exception
* @param message the message on the exception
* @param exception the exception that caused this model exception
* @param object the object that the exception was thrown on
*/
- public PfModelRuntimeException(final String message, final Exception exception, final Object object) {
+ public PfModelRuntimeException(final Response.Status statusCode, final String message, final Exception exception,
+ final Object object) {
super(message, exception);
this.object = object;
+ this.statusCode = statusCode;
}
/**
@@ -80,13 +97,4 @@ public class PfModelRuntimeException extends RuntimeException {
public String getCascadedMessage() {
return PfModelException.buildCascadedMessage(this);
}
-
- /**
- * Get the object on which the exception was thrown.
- *
- * @return The object
- */
- public Object getObject() {
- return object;
- }
}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfModelService.java b/models-base/src/main/java/org/onap/policy/models/base/PfModelService.java
index c02de6aa7..67ba59c8b 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfModelService.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfModelService.java
@@ -23,6 +23,10 @@ package org.onap.policy.models.base;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import javax.ws.rs.core.Response;
+
+import lombok.NonNull;
+
/**
* The model service makes Policy Framework models available to all classes in a JVM.
*
@@ -37,7 +41,7 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public abstract class PfModelService {
// The map holding the models
- private static Map<Class<?>, PfConcept> modelMap = new ConcurrentHashMap<>();
+ private static Map<String, PfConcept> modelMap = new ConcurrentHashMap<>();
/**
* This class is an abstract static class that cannot be extended.
@@ -48,37 +52,36 @@ public abstract class PfModelService {
* Register a model with the model service.
*
* @param <M> the generic type
- * @param modelClass the class of the model, used to index the model
+ * @param modelKey the key of the model, used to index the model
* @param model The model
*/
- public static <M extends PfConcept> void registerModel(final Class<M> modelClass, final M model) {
- modelMap.put(modelClass, model);
+ public static <M extends PfConcept> void registerModel(@NonNull final String modelKey, @NonNull final M model) {
+ modelMap.put(modelKey, model);
}
/**
* Remove a model from the model service.
*
- * @param <M> the generic type
- * @param modelClass the class of the model, used to index the model
+ * @param modelKey the key of the model, used to index the model
*/
- public static <M extends PfConcept> void deregisterModel(final Class<M> modelClass) {
- modelMap.remove(modelClass);
+ public static void deregisterModel(@NonNull final String modelKey) {
+ modelMap.remove(modelKey);
}
/**
* Get a model from the model service.
*
* @param <M> the generic type
- * @param modelClass the class of the model, used to index the model
+ * @param modelKey the key of the model, used to index the model
* @return The model
*/
@SuppressWarnings("unchecked")
- public static <M extends PfConcept> M getModel(final Class<M> modelClass) {
- final M model = (M) modelMap.get(modelClass);
+ public static <M extends PfConcept> M getModel(@NonNull final String modelKey) {
+ final M model = (M) modelMap.get(modelKey);
if (model == null) {
- throw new PfModelRuntimeException(
- "Model for " + modelClass.getCanonicalName() + " not found in model service");
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
+ "Model for name " + modelKey + " not found in model service");
}
return model;
@@ -87,12 +90,11 @@ public abstract class PfModelService {
/**
* Check if a model is defined on the model service.
*
- * @param <M> the generic type
- * @param modelClass the class of the model, used to index the model
+ * @param modelKey the key of the model, used to index the model
* @return true if the model is defined
*/
- public static <M extends PfConcept> boolean existsModel(final Class<M> modelClass) {
- return modelMap.get(modelClass) != null;
+ public static boolean existsModel(final String modelKey) {
+ return modelMap.get(modelKey) != null;
}
/**
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java
index e3b92c0e9..2e9f48ba5 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfReferenceKey.java
@@ -243,6 +243,11 @@ public class PfReferenceKey extends PfKey {
return parentKeyName + ':' + parentKeyVersion + ':' + parentLocalName + ':' + localName;
}
+ @Override
+ public boolean isNullKey() {
+ return this.equals(PfReferenceKey.getNullKey());
+ }
+
/**
* Gets the parent concept key of this reference key.
*
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java b/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java
new file mode 100644
index 000000000..a18315ceb
--- /dev/null
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfUtils.java
@@ -0,0 +1,59 @@
+/*-
+ * ============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.models.base;
+
+/**
+ * Utility class for Policy Framework concept utilities.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public final class PfUtils {
+ private PfUtils() {
+ // Cannot be subclassed
+ }
+
+ /**
+ * Compare two objects using their equals methods, nulls are allowed.
+ *
+ * @param leftObject the first object
+ * @param rightObject the second object
+ * @return a measure of the comparison
+ */
+ public static int compareObjects(final Object leftObject, final Object rightObject) {
+ if (leftObject == null && rightObject == null) {
+ return 0;
+ }
+
+ if (leftObject == null) {
+ return 1;
+ }
+
+ if (rightObject == null) {
+ return -1;
+ }
+
+ if (!leftObject.equals(rightObject)) {
+ return leftObject.hashCode() - rightObject.hashCode();
+ }
+
+ return 0;
+ }
+}
diff --git a/models-base/src/main/java/org/onap/policy/models/base/PfValidationResult.java b/models-base/src/main/java/org/onap/policy/models/base/PfValidationResult.java
index 284c11ac2..4f8d06bdc 100644
--- a/models-base/src/main/java/org/onap/policy/models/base/PfValidationResult.java
+++ b/models-base/src/main/java/org/onap/policy/models/base/PfValidationResult.java
@@ -23,9 +23,12 @@ package org.onap.policy.models.base;
import java.util.LinkedList;
import java.util.List;
+import lombok.Getter;
+
/**
- * This class records the result of a validation and holds all validatino observation messages.
+ * This class records the result of a validation and holds all validation observation messages.
*/
+@Getter
public class PfValidationResult {
/**
* The ValidationResult enumeration describes the severity of a validation result.
@@ -77,24 +80,6 @@ public class PfValidationResult {
}
/**
- * Gets the validation result.
- *
- * @return the validation result on a concept
- */
- public ValidationResult getValidationResult() {
- return validationResult;
- }
-
- /**
- * Gets the list of validation results on the concept.
- *
- * @return the list of validaiton results
- */
- public List<PfValidationMessage> getMessageList() {
- return messageList;
- }
-
- /**
* Adds a validation message to the validation result, used by validate() implementations on
* {@link PfConcept} subclasses to report validaiton observations.
*
diff --git a/models-base/src/test/java/org/onap/policy/models/base/ExceptionsTest.java b/models-base/src/test/java/org/onap/policy/models/base/ExceptionsTest.java
index c0898c187..0a5b6a0a6 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/ExceptionsTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/ExceptionsTest.java
@@ -25,32 +25,35 @@ import static org.junit.Assert.assertNotNull;
import java.io.IOException;
+import javax.ws.rs.core.Response;
+
import org.junit.Test;
public class ExceptionsTest {
@Test
public void test() {
- assertNotNull(new PfModelException("Message"));
- assertNotNull(new PfModelException("Message", "String"));
- assertNotNull(new PfModelException("Message", new IOException()));
- assertNotNull(new PfModelException("Message", new IOException(), "String"));
+ assertNotNull(new PfModelException(Response.Status.OK, "Message"));
+ assertNotNull(new PfModelException(Response.Status.OK, "Message", "String"));
+ assertNotNull(new PfModelException(Response.Status.OK, "Message", new IOException()));
+ assertNotNull(new PfModelException(Response.Status.OK, "Message", new IOException(), "String"));
String key = "A String";
- PfModelException ae = new PfModelException("Message", new IOException("IO exception message"), key);
+ PfModelException ae =
+ new PfModelException(Response.Status.OK, "Message", new IOException("IO exception message"), key);
assertEquals("Message\ncaused by: Message\ncaused by: IO exception message", ae.getCascadedMessage());
assertEquals(key, ae.getObject());
- assertNotNull(new PfModelRuntimeException("Message"));
- assertNotNull(new PfModelRuntimeException("Message", "String"));
- assertNotNull(new PfModelRuntimeException("Message", new IOException()));
- assertNotNull(new PfModelRuntimeException("Message", new IOException(), "String"));
+ assertNotNull(new PfModelRuntimeException(Response.Status.OK, "Message"));
+ assertNotNull(new PfModelRuntimeException(Response.Status.OK, "Message", "String"));
+ assertNotNull(new PfModelRuntimeException(Response.Status.OK, "Message", new IOException()));
+ assertNotNull(new PfModelRuntimeException(Response.Status.OK, "Message", new IOException(), "String"));
String rkey = "A String";
- PfModelRuntimeException re = new PfModelRuntimeException("Runtime Message",
- new IOException("IO runtime exception message"), rkey);
+ PfModelRuntimeException re = new PfModelRuntimeException(Response.Status.OK, "Runtime Message",
+ new IOException("IO runtime exception message"), rkey);
assertEquals("Runtime Message\ncaused by: Runtime Message\ncaused by: IO runtime exception message",
- re.getCascadedMessage());
+ re.getCascadedMessage());
assertEquals(key, re.getObject());
}
}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/ModelServiceTest.java b/models-base/src/test/java/org/onap/policy/models/base/ModelServiceTest.java
new file mode 100644
index 000000000..0e790d3dc
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/ModelServiceTest.java
@@ -0,0 +1,105 @@
+/*-
+ * ============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.models.base;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.models.base.testconcepts.DummyPfModel;
+
+public class ModelServiceTest {
+
+ @Test
+ public void testModelService() {
+ PfModelService.clear();
+
+ assertFalse(PfModelService.existsModel("NonExistantName"));
+ try {
+ PfModelService.getModel("NonExistantName");
+ } catch (final Exception e) {
+ assertEquals("Model for name NonExistantName not found in model service", e.getMessage());
+ }
+
+ PfModelService.registerModel("ModelName", new DummyPfModel());
+ assertTrue(PfModelService.existsModel("ModelName"));
+ assertNotNull(PfModelService.getModel("ModelName"));
+
+ PfModelService.deregisterModel("ModelName");
+
+ assertFalse(PfModelService.existsModel("ModelName"));
+ try {
+ PfModelService.getModel("ModelName");
+ } catch (final Exception e) {
+ assertEquals("Model for name ModelName not found in model service", e.getMessage());
+ }
+
+ PfModelService.registerModel("ModelName", new DummyPfModel());
+ assertTrue(PfModelService.existsModel("ModelName"));
+ assertNotNull(PfModelService.getModel("ModelName"));
+
+ PfModelService.clear();
+ assertFalse(PfModelService.existsModel("ModelName"));
+ try {
+ PfModelService.getModel("ModelName");
+ } catch (final Exception e) {
+ assertEquals("Model for name ModelName not found in model service", e.getMessage());
+ }
+
+ try {
+ PfModelService.registerModel(null, null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("modelKey is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ PfModelService.registerModel("nullModelName", null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("model is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ PfModelService.registerModel(null, new DummyPfModel());
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("modelKey is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ PfModelService.deregisterModel(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("modelKey is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ PfModelService.getModel(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("modelKey is marked @NonNull but is null", exc.getMessage());
+ }
+ }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
new file mode 100644
index 000000000..0ed04c4e6
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java
@@ -0,0 +1,199 @@
+/*-
+ * ============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.models.base;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import org.junit.Test;
+import org.onap.policy.models.base.testconcepts.DummyPfConcept;
+import org.onap.policy.models.base.testconcepts.DummyPfConceptContainer;
+import org.onap.policy.models.base.testconcepts.DummyPfConceptSub;
+
+/**
+ * Test the PfCOnceptCOntainer class.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class PfConceptContainerTest {
+
+ @Test
+ public void test() {
+ DummyPfConceptContainer container = new DummyPfConceptContainer();
+ assertNotNull(container);
+
+ container = new DummyPfConceptContainer();
+ assertNotNull(container);
+
+ container = new DummyPfConceptContainer(new PfConceptKey());
+ assertNotNull(container);
+
+ container = new DummyPfConceptContainer(new PfConceptKey(), new TreeMap<PfConceptKey, DummyPfConcept>());
+ assertNotNull(container);
+
+ try {
+ container = new DummyPfConceptContainer((PfConceptKey) null, null);
+ fail("test should throw an exception here");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ container = new DummyPfConceptContainer(new PfConceptKey(), null);
+ fail("test should throw an exception here");
+ } catch (Exception exc) {
+ assertEquals("conceptMap is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ container = new DummyPfConceptContainer(null, new TreeMap<PfConceptKey, DummyPfConcept>());
+ fail("test should throw an exception here");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ container.getKey().setName("Dummy");
+ DummyPfConceptContainer clonedContainer = new DummyPfConceptContainer(container);
+ assertNotNull(clonedContainer);
+ assertEquals("Dummy", clonedContainer.getKey().getName());
+
+ try {
+ DummyPfConceptContainer conceptContainter = null;
+ container = new DummyPfConceptContainer(conceptContainter);
+ fail("test should throw an exception here");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ List<PfKey> keyList = container.getKeys();
+ assertEquals(1, keyList.size());
+
+ PfConceptKey conceptKey = new PfConceptKey("Key", "0.0.1");
+ Map<PfConceptKey, DummyPfConcept> conceptMap = new TreeMap<>();
+ conceptMap.put(conceptKey, new DummyPfConcept(conceptKey));
+
+ container.setConceptMap(conceptMap);
+ keyList = container.getKeys();
+ assertEquals(2, keyList.size());
+
+ clonedContainer = new DummyPfConceptContainer(container);
+ assertNotNull(clonedContainer);
+ assertEquals("Dummy", clonedContainer.getKey().getName());
+ assertEquals(2, clonedContainer.getKeys().size());
+
+ assertEquals(clonedContainer, container);
+ container.clean();
+ assertEquals(clonedContainer, container);
+
+ PfValidationResult result = new PfValidationResult();
+ result = container.validate(result);
+ assertTrue(result.isOk());
+
+ assertEquals(0, container.compareTo(clonedContainer));
+
+ try {
+ container.copyTo(null);
+ fail("test should throw an exception here");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertFalse(container.compareTo(null) == 0);
+ assertEquals(0, container.compareTo(container));
+ assertFalse(container.compareTo(conceptKey) == 0);
+
+ DummyPfConceptContainer testContainer = new DummyPfConceptContainer(container);
+ testContainer.getKey().setVersion("0.0.2");
+ assertFalse(container.compareTo(testContainer) == 0);
+ testContainer.getKey().setVersion(container.getKey().getVersion());
+ assertEquals(0, container.compareTo(testContainer));
+
+ PfConceptKey testConceptKey = new PfConceptKey("TestKey", "0.0.1");
+ testContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey));
+ assertFalse(container.compareTo(testContainer) == 0);
+
+ try {
+ container.validate(null);
+ fail("test should throw an exception here");
+ } catch (Exception exc) {
+ assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
+ }
+
+ DummyPfConceptContainer validateContainer = new DummyPfConceptContainer();
+ assertFalse(validateContainer.validate(new PfValidationResult()).isOk());
+ validateContainer.setKey(new PfConceptKey("VCKey", "0.0.1"));
+ assertFalse(validateContainer.validate(new PfValidationResult()).isOk());
+
+ validateContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey));
+ assertTrue(validateContainer.validate(new PfValidationResult()).isOk());
+
+ validateContainer.getConceptMap().put(PfConceptKey.getNullKey(), new DummyPfConcept(PfConceptKey.getNullKey()));
+ assertFalse(validateContainer.validate(new PfValidationResult()).isOk());
+ validateContainer.getConceptMap().remove(PfConceptKey.getNullKey());
+ assertTrue(validateContainer.validate(new PfValidationResult()).isOk());
+
+ validateContainer.getConceptMap().put(testConceptKey, null);
+ assertFalse(validateContainer.validate(new PfValidationResult()).isOk());
+ validateContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey));
+ assertTrue(validateContainer.validate(new PfValidationResult()).isOk());
+
+ validateContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(conceptKey));
+ assertFalse(validateContainer.validate(new PfValidationResult()).isOk());
+ validateContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey));
+ assertTrue(validateContainer.validate(new PfValidationResult()).isOk());
+
+ assertEquals(conceptKey, container.get(conceptKey).getKey());
+ assertEquals(conceptKey, container.get(conceptKey.getName()).getKey());
+ assertEquals(conceptKey, container.get(conceptKey.getName(), conceptKey.getVersion()).getKey());
+
+ Set<DummyPfConcept> returnSet = container.getAll(conceptKey.getName());
+ assertEquals(conceptKey, returnSet.iterator().next().getKey());
+
+ returnSet = container.getAll(conceptKey.getName(), conceptKey.getVersion());
+ assertEquals(conceptKey, returnSet.iterator().next().getKey());
+
+ container.getConceptMap().put(conceptKey, new DummyPfConceptSub(conceptKey));
+
+ DummyPfConceptContainer exceptionOnCopyContainer = new DummyPfConceptContainer();
+ try {
+ container.copyTo(exceptionOnCopyContainer);
+ fail("test should throw an exception here");
+ } catch (Exception exc) {
+ assertEquals(
+ "Failed to create a clone of class \"org.onap.policy.models.base.testconcepts.DummyPfConceptSub\"",
+ exc.getMessage());
+ }
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testnullKey() {
+ PfConceptKey nullKey = null;
+ new DummyPfConceptContainer(nullKey);
+ }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptGetterImplTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptGetterImplTest.java
index 0a5ccdc5a..ae5b2ff2b 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfConceptGetterImplTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptGetterImplTest.java
@@ -32,12 +32,12 @@ import java.util.TreeSet;
import org.junit.Test;
/**
- * Test the AxConceptGetterImpl class.
+ * Test the given concept class.
*/
public class PfConceptGetterImplTest {
@Test
- public void testAxConceptGetterImpl() {
+ public void testPfConceptGetterImpl() {
NavigableMap<PfConceptKey, PfConceptKey> keyMap = new TreeMap<>();
PfConceptGetterImpl<PfConceptKey> getter = new PfConceptGetterImpl<>(keyMap);
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java
index 1ffc5d262..848889cc3 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java
@@ -31,8 +31,8 @@ import java.lang.reflect.Field;
import org.junit.Test;
import org.onap.policy.models.base.PfKey.Compatibility;
-import org.onap.policy.models.base.testpojos.DummyPfConcept;
-import org.onap.policy.models.base.testpojos.DummyPfKey;
+import org.onap.policy.models.base.testconcepts.DummyPfConcept;
+import org.onap.policy.models.base.testconcepts.DummyPfKey;
public class PfKeyTest {
@@ -67,6 +67,9 @@ public class PfKeyTest {
PfConceptKey someKey4 = new PfConceptKey(someKey1);
someKey4.setVersion("0.1.2");
+ PfConceptKey someKey4a = new PfConceptKey(someKey1);
+ someKey4a.setVersion("0");
+
PfConceptKey someKey5 = new PfConceptKey(someKey1);
someKey5.setVersion("1.2.2");
@@ -77,13 +80,25 @@ public class PfKeyTest {
PfConcept pfc = new DummyPfConcept();
assertEquals(PfConceptKey.getNullKey().getId(), pfc.getId());
+
assertTrue(PfConceptKey.getNullKey().matchesId(pfc.getId()));
+ assertTrue(PfConceptKey.getNullKey().isNullKey());
+
+ try {
+ PfConceptKey.getNullKey().matchesId(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("id is marked @NonNull but is null", exc.getMessage());
+ }
+
assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(new DummyPfKey()));
assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(someKey1));
assertEquals(Compatibility.IDENTICAL, someKey2.getCompatibility(someKey1));
assertEquals(Compatibility.PATCH, someKey3.getCompatibility(someKey1));
assertEquals(Compatibility.MINOR, someKey4.getCompatibility(someKey1));
+ assertEquals(Compatibility.PATCH, someKey4a.getCompatibility(someKey1));
+ assertEquals(Compatibility.PATCH, someKey1.getCompatibility(someKey4a));
assertEquals(Compatibility.MAJOR, someKey5.getCompatibility(someKey1));
assertEquals(Compatibility.MAJOR, someKey6.getCompatibility(someKey1));
@@ -119,8 +134,9 @@ public class PfKeyTest {
try {
someKey0.compareTo(null);
- } catch (IllegalArgumentException e) {
- assertEquals("comparison object may not be null", e.getMessage());
+ fail("test should throw an exception here");
+ } catch (NullPointerException e) {
+ assertEquals("otherObj is marked @NonNull but is null", e.getMessage());
}
assertEquals(0, someKey0.compareTo(someKey0));
@@ -131,6 +147,51 @@ public class PfKeyTest {
assertFalse(((PfKey) someKey0).equals(new DummyPfKey()));
}
+ @Test
+ public void testNullArguments() {
+ try {
+ new PfConceptKey((String)null);
+ fail("test should throw an exception here");
+ } catch (Exception exc) {
+ assertEquals("id is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new PfConceptKey((PfConceptKey)null);
+ fail("id is marked @NonNull but is null");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new PfConceptKey(null, null);
+ fail("id is marked @NonNull but is null");
+ } catch (Exception exc) {
+ assertEquals("name is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new PfConceptKey("name", null);
+ fail("id is marked @NonNull but is null");
+ } catch (Exception exc) {
+ assertEquals("version is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new PfConceptKey(null, "0.0.1");
+ fail("id is marked @NonNull but is null");
+ } catch (Exception exc) {
+ assertEquals("name is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ PfConceptKey key = new PfConceptKey("AKey", "0.0.1");
+ key.isCompatible(null);
+ fail("id is marked @NonNull but is null");
+ } catch (Exception exc) {
+ assertEquals("otherKey is marked @NonNull but is null", exc.getMessage());
+ }
+ }
@Test
public void testValidation() {
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java
index 7dbde7414..ccdc72dcd 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java
@@ -25,24 +25,35 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import org.junit.Test;
import org.onap.policy.models.base.PfKey.Compatibility;
+import org.onap.policy.models.base.testconcepts.DummyPfConceptKeySub;
public class PfKeyUseTest {
+ @SuppressWarnings("unlikely-arg-type")
@Test
- public void test() {
+ public void testKeyUse() {
assertNotNull(new PfKeyUse());
assertNotNull(new PfKeyUse(new PfConceptKey()));
assertNotNull(new PfKeyUse(new PfReferenceKey()));
+ try {
+ new PfKeyUse((PfKeyUse)null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
PfConceptKey key = new PfConceptKey("Key", "0.0.1");
PfKeyUse keyUse = new PfKeyUse();
keyUse.setKey(key);
assertEquals(key, keyUse.getKey());
assertEquals("Key:0.0.1", keyUse.getId());
assertEquals(key, keyUse.getKeys().get(0));
+ assertFalse(keyUse.isNullKey());
assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key));
assertTrue(keyUse.isCompatible(key));
@@ -74,5 +85,51 @@ public class PfKeyUseTest {
PfKeyUse keyUseNull = new PfKeyUse(PfConceptKey.getNullKey());
PfValidationResult resultNull = new PfValidationResult();
assertEquals(false, keyUseNull.validate(resultNull).isValid());
+
+ try {
+ keyUse.setKey(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ keyUse.getCompatibility(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("otherKey is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ keyUse.isCompatible(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("otherKey is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ keyUse.validate(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("result is marked @NonNull but is null", exc.getMessage());
+ }
+
+ PfKeyUse testKeyUse = new PfKeyUse(new DummyPfConceptKeySub(new PfConceptKey()));
+ PfKeyUse targetKeyUse = new PfKeyUse(key);
+
+ try {
+ keyUse.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ testKeyUse.copyTo(targetKeyUse);
+ keyUse.isCompatible(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("error copying concept key: Some error message", exc.getMessage());
+ }
}
}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java
new file mode 100644
index 000000000..cf7c41f6b
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java
@@ -0,0 +1,145 @@
+package org.onap.policy.models.base;
+/*-
+ * ============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=========================================================
+ */
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.models.base.testconcepts.DummyPfModel;
+
+/**
+ * Test of the PfModel clas.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class PfModelTest {
+
+ @Test
+ public void testPfModel() {
+ assertNotNull(new DummyPfModel());
+ assertNotNull(new DummyPfModel(new PfConceptKey()));
+ assertNotNull(new DummyPfModel(new DummyPfModel()));
+
+ try {
+ new DummyPfModel((PfConceptKey)null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ DummyPfModel nullModel = null;
+ new DummyPfModel(nullModel);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ DummyPfModel dpm = new DummyPfModel(new PfConceptKey("modelKey", "0.0.1"));
+ DummyPfModel dpmClone = new DummyPfModel(dpm);
+ assertEquals(dpm, dpmClone);
+
+ assertEquals(1, dpm.getKeys().size());
+
+ dpmClone.clean();
+ assertEquals(dpm, dpmClone);
+
+ try {
+ dpm.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(0, dpm.compareTo(dpmClone));
+ assertEquals(-1, dpm.compareTo(null));
+ assertEquals(0, dpm.compareTo(dpm));
+ assertFalse(dpm.compareTo(dpm.getKey()) == 0);
+ }
+
+ @Test
+ public void testPfModelValidation() {
+ PfConceptKey dpmKey = new PfConceptKey("modelKey", "0.0.1");
+ DummyPfModel dpm = new DummyPfModel(dpmKey);
+ assertTrue(dpm.validate(new PfValidationResult()).isValid());
+
+ try {
+ dpm.validate(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
+ }
+
+ dpm.setKey(PfConceptKey.getNullKey());
+ assertFalse(dpm.validate(new PfValidationResult()).isValid());
+ dpm.setKey(dpmKey);
+ assertTrue(dpm.validate(new PfValidationResult()).isValid());
+
+ dpm.getKeyList().add(PfReferenceKey.getNullKey());
+ dpm.getKeyList().add(new PfKeyUse(PfReferenceKey.getNullKey()));
+ assertFalse(dpm.validate(new PfValidationResult()).isValid());
+ dpm.getKeyList().clear();
+ assertTrue(dpm.validate(new PfValidationResult()).isValid());
+
+ PfConceptKey goodCKey = new PfConceptKey("goodCKey", "0.0.1");
+ PfReferenceKey goodRKey = new PfReferenceKey(goodCKey, "goodLocalName");
+
+ dpm.getKeyList().add(goodCKey);
+ dpm.getKeyList().add(goodRKey);
+ assertTrue(dpm.validate(new PfValidationResult()).isValid());
+
+ PfConceptKey goodCKeyDup = new PfConceptKey(goodCKey);
+ dpm.getKeyList().add(goodCKeyDup);
+ assertFalse(dpm.validate(new PfValidationResult()).isValid());
+ dpm.getKeyList().remove(goodCKeyDup);
+ assertTrue(dpm.validate(new PfValidationResult()).isValid());
+
+ PfReferenceKey goodRKeyDup = new PfReferenceKey(goodRKey);
+ dpm.getKeyList().add(goodRKeyDup);
+ assertFalse(dpm.validate(new PfValidationResult()).isValid());
+ dpm.getKeyList().remove(goodRKeyDup);
+ assertTrue(dpm.validate(new PfValidationResult()).isValid());
+
+ PfKeyUse goodCKeyUse = new PfKeyUse(goodCKey);
+ dpm.getKeyList().add(goodCKeyUse);
+ assertTrue(dpm.validate(new PfValidationResult()).isValid());
+
+ PfKeyUse goodRKeyUse = new PfKeyUse(goodRKey);
+ dpm.getKeyList().add(goodRKeyUse);
+ assertTrue(dpm.validate(new PfValidationResult()).isValid());
+
+ PfConceptKey badCKey = new PfConceptKey("badCKey", "0.0.1");
+ PfKeyUse badCKeyUse = new PfKeyUse(badCKey);
+ dpm.getKeyList().add(badCKeyUse);
+ assertFalse(dpm.validate(new PfValidationResult()).isValid());
+ dpm.getKeyList().remove(badCKeyUse);
+ assertTrue(dpm.validate(new PfValidationResult()).isValid());
+
+ PfKeyUse badRKeyUse = new PfKeyUse(new PfReferenceKey(badCKey, "badLocalName"));
+ dpm.getKeyList().add(badRKeyUse);
+ assertFalse(dpm.validate(new PfValidationResult()).isValid());
+ dpm.getKeyList().remove(badRKeyUse);
+ assertTrue(dpm.validate(new PfValidationResult()).isValid());
+ }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java
index feedc2cc3..64d4bc6b8 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java
@@ -47,10 +47,20 @@ public class PfReferenceKeyTest {
assertEquals(PfReferenceKey.getNullKey().getKey(), PfReferenceKey.getNullKey());
assertEquals("NULL:0.0.0:NULL:NULL", PfReferenceKey.getNullKey().getId());
+ try {
+ new PfReferenceKey(new PfConceptKey(), null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("parameter \"localName\" is null", exc.getMessage());
+ }
+
PfReferenceKey testReferenceKey = new PfReferenceKey();
testReferenceKey.setParentConceptKey(new PfConceptKey("PN", "0.0.1"));
assertEquals("PN:0.0.1", testReferenceKey.getParentConceptKey().getId());
+ assertEquals(1, testReferenceKey.getKeys().size());
+ assertFalse(testReferenceKey.isNullKey());
+
testReferenceKey.setParentReferenceKey(new PfReferenceKey("PN", "0.0.1", "LN"));
assertEquals("PN:0.0.1:NULL:LN", testReferenceKey.getParentReferenceKey().getId());
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaEventFilter.java b/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java
index 34d791202..2b495a1e7 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaEventFilter.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java
@@ -1,8 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * ONAP Policy Model
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -20,34 +18,26 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca;
+package org.onap.policy.models.base;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
-import com.google.gson.annotations.SerializedName;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
+import org.junit.Test;
/**
- * Class to represent the EventFilter in TOSCA definition.
- *
- * @author Chenfei Gao (cgao@research.att.com)
+ * Test the PfUtils class.
*
+ * @author Liam Fallon (liam.fallon@est.tech)
*/
-@ToString
-public class ToscaEventFilter {
-
- @Getter
- @Setter
- @SerializedName("node")
- private String node;
-
- @Getter
- @Setter
- @SerializedName("requirement")
- private String requirement;
+public class PfUtilsTest {
- @Getter
- @Setter
- @SerializedName("capability")
- private String capability;
-} \ No newline at end of file
+ @Test
+ public void testPfUtils() {
+ assertEquals(0, PfUtils.compareObjects(null, null));
+ assertEquals(-1, PfUtils.compareObjects("hello", null));
+ assertEquals(1, PfUtils.compareObjects(null, "hello"));
+ assertFalse(PfUtils.compareObjects("hello", "goodbye") == 0);
+ assertEquals(0, PfUtils.compareObjects("hello", "hello"));
+ }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java
new file mode 100644
index 000000000..9fb6b5793
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java
@@ -0,0 +1,137 @@
+/*-
+ * ============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.models.base.testconcepts;
+
+import java.util.List;
+
+import javax.persistence.EmbeddedId;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+
+import org.apache.commons.lang3.ObjectUtils;
+import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfValidationMessage;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class DummyPfConcept extends PfConcept {
+ private static final long serialVersionUID = 1L;
+ @EmbeddedId
+ private PfConceptKey key;
+
+ private String description;
+
+ /**
+ * The Default Constructor creates a {@link DummyPfConcept} object with a null key.
+ */
+ public DummyPfConcept() {
+ this(new PfConceptKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link DummyPfConcept} object with the given concept key.
+ *
+ * @param key the key
+ */
+ public DummyPfConcept(@NonNull final PfConceptKey key) {
+ this.key = key;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public DummyPfConcept(final DummyPfConcept copyConcept) {
+ super(copyConcept);
+ }
+
+ @Override
+ public List<PfKey> getKeys() {
+ final List<PfKey> keyList = getKey().getKeys();
+ return keyList;
+ }
+
+ @Override
+ public void clean() {
+ key.clean();
+
+ description = (description != null ? description.trim() : null);
+ }
+
+ @Override
+ public PfValidationResult validate(PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ if (key.isNullKey()) {
+ result.addValidationMessage(
+ new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
+ }
+
+ result = key.validate(result);
+
+ if (description != null && description.trim().length() == 0) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "property description may not be blank"));
+ }
+
+ return result;
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+ if (this == otherConcept) {
+ return 0;
+ }
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final DummyPfConcept other = (DummyPfConcept) otherConcept;
+ if (!key.equals(other.key)) {
+ return key.compareTo(other.key);
+ }
+
+ return ObjectUtils.compare(description, other.description);
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull PfConcept target) {
+ final Object copyObject = target;
+ Assertions.instanceOf(copyObject, PfConcept.class);
+
+ final DummyPfConcept copy = ((DummyPfConcept) copyObject);
+ copy.setKey(new PfConceptKey(key));
+ copy.setDescription(description);
+
+ return copy;
+ }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptContainer.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptContainer.java
new file mode 100644
index 000000000..ac72ef8f6
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptContainer.java
@@ -0,0 +1,77 @@
+/*-
+ * ============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.models.base.testconcepts;
+
+import java.util.Map;
+
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfConceptContainer;
+import org.onap.policy.models.base.PfConceptKey;
+
+/**
+ * Dummy container for PF concepts.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class DummyPfConceptContainer extends PfConceptContainer<DummyPfConcept> {
+ private static final long serialVersionUID = -3018432331484294280L;
+
+
+ /**
+ * The Default Constructor creates a {@link DummyPfConceptContainer} object with a null artifact key
+ * and creates an empty concept map.
+ */
+ public DummyPfConceptContainer() {
+ super();
+ }
+
+ /**
+ * The Key Constructor creates a {@link DummyPfConceptContainer} object with the given artifact key and
+ * creates an empty concept map.
+ *
+ * @param key the concept key
+ */
+ public DummyPfConceptContainer(@NonNull final PfConceptKey key) {
+ super(key);
+ }
+
+ /**
+ * This Constructor creates an concept container with all of its fields defined.
+ *
+ * @param key the concept container key
+ * @param conceptMap the concepts to be stored in the concept container
+ */
+ public DummyPfConceptContainer(@NonNull final PfConceptKey key,
+ @NonNull final Map<PfConceptKey, DummyPfConcept> conceptMap) {
+ super(key, conceptMap);
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public DummyPfConceptContainer(@NonNull final DummyPfConceptContainer copyConcept) {
+ super(copyConcept);
+ }
+
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testpojos/DummyPfConcept.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptKeySub.java
index f28477f70..da18cba20 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/testpojos/DummyPfConcept.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptKeySub.java
@@ -18,60 +18,36 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.base.testpojos;
+package org.onap.policy.models.base.testconcepts;
-import java.util.Arrays;
-import java.util.List;
+import javax.ws.rs.core.Response;
+
+import lombok.NonNull;
-import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfKey;
-import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfModelRuntimeException;
-public class DummyPfConcept extends PfConcept {
+/**
+ * KeyUse subclass that throws exception on default constructor for testing.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class DummyPfConceptKeySub extends PfConceptKey {
private static final long serialVersionUID = 1L;
- @Override
- public int compareTo(PfConcept concept) {
- return 0;
- }
-
- @Override
- public PfKey getKey() {
- return new PfConceptKey();
- }
-
- @Override
- public List<PfKey> getKeys() {
- return Arrays.asList(getKey());
- }
-
- @Override
- public PfValidationResult validate(PfValidationResult result) {
- return null;
- }
-
- @Override
- public void clean() {
- }
-
- @Override
- public boolean equals(Object otherObject) {
- return false;
- }
-
- @Override
- public String toString() {
- return null;
- }
-
- @Override
- public int hashCode() {
- return 0;
+ /**
+ * The Default Constructor creates this concept with a null key.
+ */
+ public DummyPfConceptKeySub() {
+ throw new PfModelRuntimeException(Response.Status.BAD_GATEWAY, "Some error message");
}
- @Override
- public PfConcept copyTo(PfConcept target) {
- return null;
+ /**
+ * This constructor creates an instance of this class, and holds a reference to a used key.
+ *
+ * @param usedKey a used key
+ */
+ public DummyPfConceptKeySub(@NonNull final PfConceptKey usedKey) {
+ super(usedKey);
}
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaEntrySchema.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptSub.java
index b3079afc0..12875eaca 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaEntrySchema.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConceptSub.java
@@ -1,8 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * ONAP Policy Model
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -20,36 +18,31 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca;
+package org.onap.policy.models.base.testconcepts;
-import com.google.gson.annotations.SerializedName;
-import java.util.List;
+import javax.ws.rs.core.Response;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
+import lombok.NonNull;
-/**
- * Class to represent the EntrySchema of list/map property in TOSCA definition.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- *
- */
-@ToString
-public class ToscaEntrySchema {
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfModelRuntimeException;
- @Getter
- @Setter
- @SerializedName("description")
- private String description;
+public class DummyPfConceptSub extends DummyPfConcept {
+ private static final long serialVersionUID = 1L;
- @Getter
- @Setter
- @SerializedName("type")
- private String type;
+ /**
+ * The Default Constructor creates a {@link DummyPfConceptSub} object with a null key.
+ */
+ public DummyPfConceptSub() {
+ throw new PfModelRuntimeException(Response.Status.BAD_GATEWAY, "Some error message");
+ }
- @Getter
- @Setter
- @SerializedName("constraints")
- private List<ToscaConstraint> constraints;
-} \ No newline at end of file
+ /**
+ * The Key Constructor creates a {@link DummyPfConceptSub} object with the given concept key.
+ *
+ * @param key the key
+ */
+ public DummyPfConceptSub(@NonNull final PfConceptKey key) {
+ super(key);
+ }
+}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testpojos/DummyPfKey.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java
index 247ea88d1..6cf41e60c 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/testpojos/DummyPfKey.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.base.testpojos;
+package org.onap.policy.models.base.testconcepts;
import java.util.Arrays;
import java.util.List;
@@ -41,6 +41,11 @@ public class DummyPfKey extends PfKey {
}
@Override
+ public boolean isNullKey() {
+ return false;
+ }
+
+ @Override
public Compatibility getCompatibility(PfKey otherKey) {
return null;
}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfModel.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfModel.java
new file mode 100644
index 000000000..199a37f59
--- /dev/null
+++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfModel.java
@@ -0,0 +1,174 @@
+/*-
+ * ============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.models.base.testconcepts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.core.Response;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfModel;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.base.PfValidationResult;
+
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class DummyPfModel extends PfModel {
+ private static final long serialVersionUID = 8800599637708309945L;
+
+ private List<PfKey> keyList;
+
+ /**
+ * The Default Constructor creates a {@link DummyPfModel} object with a null concept key and
+ * creates an empty TOSCA model.
+ */
+ public DummyPfModel() {
+ super();
+ super.setKey(new PfConceptKey());
+ this.keyList = new ArrayList<PfKey>();
+ }
+
+ /**
+ * The Key Constructor creates a {@link DummyPfModel} object with the given concept key and
+ * creates an empty TOSCA model.
+ *
+ * @param key the TOSCA model key
+ */
+ public DummyPfModel(final PfConceptKey key) {
+ super(key);
+ this.keyList = new ArrayList<PfKey>();
+ }
+
+ /**
+ * Constructor that initiates a {@link ToscaModel} with all its fields.
+ *
+ * @param key the TOSCA model key
+ * @param keyList the service templates in the event model
+ */
+ public DummyPfModel(final PfConceptKey key, final List<PfKey> keyList) {
+ super(key);
+ this.keyList = keyList;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public DummyPfModel(final DummyPfModel copyConcept) {
+ super(copyConcept);
+ }
+
+ @Override
+ public void register() {
+ }
+
+ @Override
+ public List<PfKey> getKeys() {
+ final List<PfKey> listOfKeys = super.getKeys();
+
+ listOfKeys.addAll(keyList);
+
+ return listOfKeys;
+ }
+
+ @Override
+ public void clean() {
+ super.clean();
+ for (PfKey pfKey : keyList) {
+ pfKey.clean();
+ }
+ }
+
+ @Override
+ public PfValidationResult validate(final PfValidationResult resultIn) {
+ PfValidationResult result = super.validate(resultIn);
+
+ for (PfKey pfKey : keyList) {
+ result = pfKey.validate(result);
+ }
+
+ return result;
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (super.compareTo(otherConcept) != 0) {
+ return super.compareTo(otherConcept);
+ }
+
+ if (otherConcept == null) {
+ return -1;
+ }
+
+ if (this == otherConcept) {
+ return 0;
+ }
+
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final DummyPfModel other = (DummyPfModel) otherConcept;
+ if (!super.equals(other)) {
+ return super.compareTo(other);
+ }
+
+ if (!keyList.equals(other.keyList)) {
+ return (keyList.hashCode() - other.keyList.hashCode());
+ }
+
+ return 0;
+ }
+
+ @Override
+ public PfConcept copyTo(final PfConcept targetObject) {
+ super.copyTo(targetObject);
+
+ Assertions.instanceOf(targetObject, DummyPfModel.class);
+
+ final DummyPfModel copy = ((DummyPfModel) targetObject);
+
+ final List<PfKey> newKeyList = new ArrayList<>();
+ for (final PfKey pfKey : keyList) {
+ PfKey newPfKey;
+ try {
+ newPfKey = pfKey.getClass().newInstance();
+ } catch (final Exception e) {
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
+ "error copying concept key: " + e.getMessage(), e);
+ }
+ newPfKey.copyTo(pfKey);
+ newKeyList.add(newPfKey);
+ }
+ copy.setKeyList(newKeyList);
+
+
+ return copy;
+ }
+}
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/DaoParameters.java b/models-dao/src/main/java/org/onap/policy/models/dao/DaoParameters.java
index 18ae74ae1..a6b6f2f2e 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/DaoParameters.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/DaoParameters.java
@@ -24,6 +24,8 @@ import java.util.Properties;
/**
* This class is a POJO that holds properties for PF DAOs.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
*/
public class DaoParameters {
/** The default PF DAO plugin class. */
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/PfDaoFactory.java b/models-dao/src/main/java/org/onap/policy/models/dao/PfDaoFactory.java
index 3b7e31eb8..6b7c7b3ad 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/PfDaoFactory.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/PfDaoFactory.java
@@ -20,6 +20,8 @@
package org.onap.policy.models.dao;
+import javax.ws.rs.core.Response;
+
import org.onap.policy.common.utils.validation.Assertions;
import org.onap.policy.models.base.PfModelException;
import org.slf4j.Logger;
@@ -28,6 +30,8 @@ import org.slf4j.LoggerFactory;
/**
* This factory class returns a Policy Framework DAO for the configured persistence mechanism. The
* factory uses the plugin class specified in {@link DaoParameters} to instantiate a DAO instance.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
*/
public class PfDaoFactory {
// Get a reference to the logger
@@ -52,7 +56,7 @@ public class PfDaoFactory {
String errorMessage =
"Policy Framework DAO class not found for DAO plugin \"" + daoParameters.getPluginClass() + "\"";
LOGGER.error(errorMessage, e);
- throw new PfModelException(errorMessage, e);
+ throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, e);
}
// Check the class is a Policy Framework DAO
@@ -60,7 +64,7 @@ public class PfDaoFactory {
String errorMessage = "Specified DAO plugin class \"" + daoParameters.getPluginClass()
+ "\" does not implement the PfDao interface";
LOGGER.error(errorMessage);
- throw new PfModelException(errorMessage);
+ throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage);
}
return (PfDao) pfDaoObject;
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/converters/CDataConditioner.java b/models-dao/src/main/java/org/onap/policy/models/dao/converters/CDataConditioner.java
index 327f65ece..e4cfd74d3 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/converters/CDataConditioner.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/converters/CDataConditioner.java
@@ -25,7 +25,7 @@ import javax.persistence.Converter;
import javax.xml.bind.annotation.adapters.XmlAdapter;
/**
- * The Class CDATAConditioner converts a CDATA String to and from database format by removing spaces
+ * The Class CDataConditioner converts a CDATA String to and from database format by removing spaces
* at the ends of lines and platform-specific new line endings.
*/
@Converter
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/converters/Uuid2String.java b/models-dao/src/main/java/org/onap/policy/models/dao/converters/Uuid2String.java
index a2b1c085a..369b5a19d 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/converters/Uuid2String.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/converters/Uuid2String.java
@@ -27,7 +27,9 @@ import javax.persistence.Converter;
import javax.xml.bind.annotation.adapters.XmlAdapter;
/**
- * The Class UUIDConverter converts a UUID to and from database format.
+ * The Class UuidConverter converts a UUID to and from database format.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
*/
@Converter
public class Uuid2String extends XmlAdapter<String, UUID> implements AttributeConverter<UUID, String> {
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/converters/package-info.java b/models-dao/src/main/java/org/onap/policy/models/dao/converters/package-info.java
index 416eff20c..184f59b0e 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/converters/package-info.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/converters/package-info.java
@@ -21,6 +21,8 @@
/**
* Contains converters used by PF EclipseLink marshaling and unmarshaling of
* {@link org.onap.policy.models.base.PfConcept} instances to and from files and databases.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
*/
package org.onap.policy.models.dao.converters;
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
index 429632db0..947b866a1 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/impl/DefaultPfDao.java
@@ -27,6 +27,7 @@ import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
+import javax.ws.rs.core.Response;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
@@ -61,7 +62,8 @@ public class DefaultPfDao implements PfDao {
public void init(final DaoParameters daoParameters) throws PfModelException {
if (daoParameters == null || daoParameters.getPersistenceUnit() == null) {
LOGGER.error("Policy Framework persistence unit parameter not set");
- throw new PfModelException("Policy Framework persistence unit parameter not set");
+ throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR,
+ "Policy Framework persistence unit parameter not set");
}
LOGGER.debug("Creating Policy Framework persistence unit \"{}\" . . .", daoParameters.getPersistenceUnit());
@@ -72,7 +74,7 @@ public class DefaultPfDao implements PfDao {
String errorMessage = "Creation of Policy Framework persistence unit \""
+ daoParameters.getPersistenceUnit() + "\" failed";
LOGGER.warn(errorMessage, ex);
- throw new PfModelException(errorMessage, ex);
+ throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, ex);
}
LOGGER.debug("Created Policy Framework persistence unit \"{}\"", daoParameters.getPersistenceUnit());
}
@@ -85,7 +87,8 @@ public class DefaultPfDao implements PfDao {
protected final synchronized EntityManager getEntityManager() {
if (emf == null) {
LOGGER.warn("Policy Framework DAO has not been initialized");
- throw new PfModelRuntimeException("Policy Framework DAO has not been initialized");
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR,
+ "Policy Framework DAO has not been initialized");
}
return emf.createEntityManager();
@@ -196,8 +199,7 @@ public class DefaultPfDao implements PfDao {
}
@Override
- public <T extends PfConcept> int deleteByConceptKey(final Class<T> someClass,
- final Collection<PfConceptKey> keys) {
+ public <T extends PfConcept> int deleteByConceptKey(final Class<T> someClass, final Collection<PfConceptKey> keys) {
if (keys == null || keys.isEmpty()) {
return 0;
}
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/impl/package-info.java b/models-dao/src/main/java/org/onap/policy/models/dao/impl/package-info.java
index 0d27628a0..f62116639 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/impl/package-info.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/impl/package-info.java
@@ -21,5 +21,7 @@
/**
* Contains a default DAO implementation for the PF {@link org.onap.policy.models.base.PfConcept}
* classes that uses javax persistence.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
*/
package org.onap.policy.models.dao.impl;
diff --git a/models-dao/src/main/java/org/onap/policy/models/dao/package-info.java b/models-dao/src/main/java/org/onap/policy/models/dao/package-info.java
index e8cfbe4e7..c4cb6a265 100644
--- a/models-dao/src/main/java/org/onap/policy/models/dao/package-info.java
+++ b/models-dao/src/main/java/org/onap/policy/models/dao/package-info.java
@@ -19,9 +19,11 @@
*/
/**
- * Defines and implements the Data Access Object (DAO) that allows Apex
- * {@link org.onap.policy.apex.model.basicmodel.concepts.AxConcept} concepts to be read from and written to databases
+ * Defines and implements the Data Access Object (DAO) that allows Policy Framework
+ * {@link org.onap.policy.models.base.pfConcept} concepts to be read from and written to databases
* over JDBC.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
*/
package org.onap.policy.models.dao;
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaPolicyList.java b/models-dao/src/test/java/org/onap/policy/models/dao/converters/CDataConditionerTest.java
index ad8f1a498..60a42c299 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaPolicyList.java
+++ b/models-dao/src/test/java/org/onap/policy/models/dao/converters/CDataConditionerTest.java
@@ -1,8 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * ONAP Policy Model
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -20,31 +18,24 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca;
+package org.onap.policy.models.dao.converters;
+
+import static org.junit.Assert.assertEquals;
-import com.google.gson.annotations.SerializedName;
-import java.util.List;
-import java.util.Map;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
+import org.junit.Test;
/**
- * Class to represent the policy list in TOSCA definition.
- *
- * @author Chenfei Gao (cgao@research.att.com)
+ * Test the CDataConditioner Class.
*
+ * @author Liam Fallon (liam.fallon@est.tech)
*/
-@ToString
-public class ToscaPolicyList {
-
- @Getter
- @Setter
- @SerializedName("policies")
- private List<Map<String, ToscaPolicy>> policies;
+public class CDataConditionerTest {
- @Getter
- @Setter
- @SerializedName("data_types")
- private List<Map<String, ToscaDataType>> dataTypes;
-} \ No newline at end of file
+ @Test
+ public void testCDataConditioner() throws Exception {
+ assertEquals("Raw", new CDataConditioner().convertToDatabaseColumn("Raw"));
+ assertEquals("entityAttribute", new CDataConditioner().convertToEntityAttribute("entityAttribute"));
+ assertEquals("marshal", new CDataConditioner().marshal("marshal"));
+ assertEquals("unmarshal", new CDataConditioner().unmarshal("unmarshal"));
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaPolicyTypeList.java b/models-dao/src/test/java/org/onap/policy/models/dao/converters/Uuid2StringConditionerTest.java
index 4a6a42dbd..771f0fb65 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaPolicyTypeList.java
+++ b/models-dao/src/test/java/org/onap/policy/models/dao/converters/Uuid2StringConditionerTest.java
@@ -1,8 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * ONAP Policy Model
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -20,31 +18,27 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca;
+package org.onap.policy.models.dao.converters;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.UUID;
-import com.google.gson.annotations.SerializedName;
-import java.util.List;
-import java.util.Map;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
+import org.junit.Test;
/**
- * Class to represent the policy type list in TOSCA definition.
- *
- * @author Chenfei Gao (cgao@research.att.com)
+ * Test the UUID conditioner class.
*
+ * @author Liam Fallon (liam.fallon@est.tech)
*/
-@ToString
-public class ToscaPolicyTypeList {
-
- @Getter
- @Setter
- @SerializedName("policy_types")
- private List<Map<String, ToscaPolicyType>> policyTypes;
+public class Uuid2StringConditionerTest {
- @Getter
- @Setter
- @SerializedName("data_types")
- private List<Map<String, ToscaDataType>> dataTypes;
-} \ No newline at end of file
+ @Test
+ public void testUuidConditioner() throws Exception {
+ UUID randomUuid = UUID.randomUUID();
+ assertEquals(randomUuid.toString(), new Uuid2String().convertToDatabaseColumn(randomUuid));
+ assertEquals(randomUuid, new Uuid2String().convertToEntityAttribute(randomUuid.toString()));
+ assertEquals(randomUuid.toString(), new Uuid2String().marshal(randomUuid));
+ assertEquals(randomUuid, new Uuid2String().unmarshal(randomUuid.toString()));
+ }
+}
diff --git a/models-provider/pom.xml b/models-provider/pom.xml
new file mode 100644
index 000000000..755aea7cb
--- /dev/null
+++ b/models-provider/pom.xml
@@ -0,0 +1,54 @@
+<!--
+ ============LICENSE_START=======================================================
+ Copyright (C) 2019 AT&T Intellectual Property. 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=========================================================
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.onap.policy.models</groupId>
+ <artifactId>policy-models</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>policy-models-provider</artifactId>
+
+ <name>${project.artifactId}</name>
+ <description>The provider interface that allows components to manipualte models in the database</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onap.policy.models</groupId>
+ <artifactId>policy-models-base</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onap.policy.models</groupId>
+ <artifactId>policy-models-dao</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.onap.policy.models</groupId>
+ <artifactId>policy-models-tosca</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
new file mode 100644
index 000000000..0144f8c68
--- /dev/null
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProvider.java
@@ -0,0 +1,156 @@
+/*-
+ * ============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.models.provider;
+
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate;
+
+/**
+ * This interface describes the operations that are provided to users and components for reading
+ * objects from and writing objects to the database.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public interface PolicyModelsProvider {
+
+ /**
+ * Get policy types.
+ *
+ * @param policyTypeKey the policy type key for the policy types to be retrieved. A null key
+ * name returns all policy types. A null key version returns all versions of the policy
+ * type name specified in the key.
+ * @return the policy types found
+ * @throws PfModelException on errors getting policy types
+ */
+ public ToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException;
+
+ /**
+ * Create policy types.
+ *
+ * @param serviceTemplate the service template containing the definition of the policy types to
+ * be created
+ * @return the TOSCA service template containing the created policy types
+ * @throws PfModelException on errors creating policy types
+ */
+ public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
+ throws PfModelException;
+
+ /**
+ * Create policy types.
+ *
+ * @param serviceTemplate the service template containing the definition of the policy types to
+ * be modified
+ * @return the TOSCA service template containing the modified policy types
+ * @throws PfModelException on errors updating policy types
+ */
+ public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
+ throws PfModelException;
+
+ /**
+ * Delete policy types.
+ *
+ * @param policyTypeKey the policy type key for the policy types to be deleted, if the version
+ * of the key is null, all versions of the policy type are deleted.
+ * @return the TOSCA service template containing the policy types that were deleted
+ * @throws PfModelException on errors deleting policy types
+ */
+ public ToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException;
+
+ /**
+ * Get policies.
+ *
+ * @param policyKey the policy key for the policies to be retrieved. The parent name and version
+ * must be specified. A null local name returns all policies for a parent policy type.
+ * @return the policies found
+ * @throws PfModelException on errors getting policies
+ */
+ public ToscaServiceTemplate getPolicies(@NonNull final PfReferenceKey policyKey) throws PfModelException;
+
+ /**
+ * Create policies.
+ *
+ * @param serviceTemplate the service template containing the definitions of the new policies to
+ * be created.
+ * @return the TOSCA service template containing the policy types that were created
+ * @throws PfModelException on errors creating policies
+ */
+ public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
+ throws PfModelException;
+
+
+ /**
+ * Update policies.
+ *
+ * @param serviceTemplate the service template containing the definitions of the policies to be
+ * updated.
+ * @return the TOSCA service template containing the policies that were updated
+ * @throws PfModelException on errors updating policies
+ */
+ public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
+ throws PfModelException;
+
+ /**
+ * Delete policies.
+ *
+ * @param policyKey the policy key
+ * @return the TOSCA service template containing the policy types that were deleted
+ * @throws PfModelException on errors deleting policies
+ */
+ public ToscaServiceTemplate deletePolicies(@NonNull final PfReferenceKey policyKey) throws PfModelException;
+
+ /**
+ * Get PDP groups.
+ *
+ * @param somePdpGroupFilter a filter for the get
+ * @return the PDP groups found
+ * @throws PfModelException on errors getting PDP groups
+ */
+ public Object getPdpGroups(@NonNull final Object somePdpGroupFilter) throws PfModelException;
+
+ /**
+ * Creates PDP groups.
+ *
+ * @param somePdpGroupSpecification a specification for the PDP group
+ * @throws PfModelException on errors creating PDP groups
+ */
+ public Object createPdpGroups(@NonNull final Object somePdpGroupSpecification) throws PfModelException;
+
+
+ /**
+ * Updates PDP groups.
+ *
+ * @param somePdpGroupSpecification a specification for the PDP group
+ * @throws PfModelException on errors updating PDP groups
+ */
+ public Object updatePdpGroups(@NonNull final Object somePdpGroupSpecification) throws PfModelException;
+
+ /**
+ * Delete PDP groups.
+ *
+ * @param somePdpGroupFilter a filter for the get
+ * @throws PfModelException on errors deleting PDP groups
+ */
+ public void deletePdpGroups(@NonNull final Object somePdpGroupFilter) throws PfModelException;
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaTimeInterval.java b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java
index 86334ab7f..5c4342800 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaTimeInterval.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderFactory.java
@@ -1,8 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * ONAP Policy Model
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * 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.
@@ -20,29 +18,21 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca;
+package org.onap.policy.models.provider;
-import com.google.gson.annotations.SerializedName;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
+import org.onap.policy.models.provider.impl.PolicyModelsProviderImpl;
/**
- * Class to represent the TimeInterval in TOSCA definition.
- *
- * @author Chenfei Gao (cgao@research.att.com)
+ * A factory for creating PolicyModelsProvider objects using the default Policy Framework implementation.
*
+ * @author Liam Fallon (liam.fallon@est.tech)
*/
-@ToString
-public class ToscaTimeInterval {
- @Getter
- @Setter
- @SerializedName("start_time")
- private String startTime;
-
- @Getter
- @Setter
- @SerializedName("end_time")
- private String endTime;
+public class PolicyModelsProviderFactory {
-} \ No newline at end of file
+ /**
+ * Creates a new PolicyModelsProvider object from its implementation.
+ */
+ public PolicyModelsProvider createPolicyModelsProvider() {
+ return new PolicyModelsProviderImpl();
+ }
+}
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/PolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/PolicyModelsProviderImpl.java
new file mode 100644
index 000000000..12d7686b3
--- /dev/null
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/PolicyModelsProviderImpl.java
@@ -0,0 +1,98 @@
+/*-
+ * ============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.models.provider.impl;
+
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfModelException;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.provider.PolicyModelsProvider;
+import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate;
+
+/**
+ * This class provides the implementaiton of the defalut Policy Models Provider for the ONAP Policy Framework.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class PolicyModelsProviderImpl implements PolicyModelsProvider {
+
+ @Override
+ public ToscaServiceTemplate getPolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException {
+ return null;
+ }
+
+ @Override
+ public ToscaServiceTemplate createPolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate)
+ throws PfModelException {
+ return null;
+ }
+
+ @Override
+ public ToscaServiceTemplate deletePolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException {
+ return null;
+ }
+
+ @Override
+ public ToscaServiceTemplate getPolicies(@NonNull PfReferenceKey policyKey) throws PfModelException {
+ return null;
+ }
+
+ @Override
+ public ToscaServiceTemplate createPolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException {
+ return null;
+ }
+
+ @Override
+ public ToscaServiceTemplate updatePolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException {
+ return null;
+ }
+
+ @Override
+ public ToscaServiceTemplate deletePolicies(@NonNull PfReferenceKey policyKey) throws PfModelException {
+ return null;
+ }
+
+ @Override
+ public ToscaServiceTemplate updatePolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate)
+ throws PfModelException {
+ return null;
+ }
+
+ @Override
+ public Object getPdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException {
+ return null;
+ }
+
+ @Override
+ public Object createPdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException {
+ return null;
+ }
+
+ @Override
+ public Object updatePdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException {
+ return null;
+ }
+
+ @Override
+ public void deletePdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException {
+ }
+}
diff --git a/models-tosca/pom.xml b/models-tosca/pom.xml
index 839cc72c8..56c8d7c15 100644
--- a/models-tosca/pom.xml
+++ b/models-tosca/pom.xml
@@ -30,7 +30,7 @@
<artifactId>policy-models-tosca</artifactId>
<name>${project.artifactId}</name>
- <description>The platform models that are shared across different policy components</description>
+ <description>The TOSCA models that are shared across different policy components</description>
<dependencies>
<dependency>
@@ -38,5 +38,11 @@
<artifactId>policy-models-base</artifactId>
<version>${project.version}</version>
</dependency>
+
+ <dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>gson</artifactId>
+ <version>${policy.common.version}</version>
+ </dependency>
</dependencies>
</project>
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaConstraint.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaConstraint.java
deleted file mode 100644
index 47a4d35a6..000000000
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaConstraint.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy Model
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. 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.models.tosca;
-
-import com.google.gson.annotations.SerializedName;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
-
-/**
- * Class to represent the Constraint of property in TOSCA definition.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- *
- */
-@ToString
-public class ToscaConstraint {
-
- @Getter
- @Setter
- @SerializedName("equal")
- private String equal;
-
- @Getter
- @Setter
- @SerializedName("greater_than")
- private String greaterThan;
-
- @Getter
- @Setter
- @SerializedName("greater_or_equal")
- private String greaterOrEqual;
-
- @Getter
- @Setter
- @SerializedName("less_than")
- private String lessThan;
-
- @Getter
- @Setter
- @SerializedName("less_or_equal")
- private String lessOrEqual;
-
- @Getter
- @Setter
- @SerializedName("in_range")
- private String inRange;
-
- @Getter
- @Setter
- @SerializedName("valid_values")
- private String validValues;
-
- @Getter
- @Setter
- @SerializedName("length")
- private String length;
-
- @Getter
- @Setter
- @SerializedName("min_length")
- private String minLength;
-
- @Getter
- @Setter
- @SerializedName("max_length")
- private String maxLength;
-
- @Getter
- @Setter
- @SerializedName("pattern")
- private String pattern;
-} \ No newline at end of file
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaDataType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaDataType.java
deleted file mode 100644
index 0366ee467..000000000
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaDataType.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy Model
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. 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.models.tosca;
-
-import com.google.gson.annotations.SerializedName;
-import java.util.List;
-import java.util.Map;
-
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
-
-/**
- * Class to represent custom data type in TOSCA definition.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- *
- */
-@ToString
-public class ToscaDataType {
- @Getter
- @Setter
- @SerializedName("derived_from")
- private String derivedFrom;
-
- @Getter
- @Setter
- @SerializedName("version")
- private String version;
-
- @Getter
- @Setter
- @SerializedName("metadata")
- private Map<String, String> metadata;
-
- @Getter
- @Setter
- @SerializedName("description")
- private String description;
-
- @Getter
- @Setter
- @SerializedName("constraints")
- private List<ToscaConstraint> constraints;
-
- @Getter
- @Setter
- @SerializedName("properties")
- private List<Map<String, ToscaProperty>> properties;
-} \ No newline at end of file
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaPolicy.java
deleted file mode 100644
index 4f9210c43..000000000
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaPolicy.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy Model
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. 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.models.tosca;
-
-import com.google.gson.annotations.SerializedName;
-import java.util.List;
-import java.util.Map;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
-
-/**
- * Class to represent the policy in TOSCA definition.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- *
- */
-@ToString
-public class ToscaPolicy {
-
- @Getter
- @Setter
- @SerializedName("type")
- private String type;
-
- @Getter
- @Setter
- @SerializedName("description")
- private String description;
-
- @Getter
- @Setter
- @SerializedName("metadata")
- private Map<String, String> metadata;
-
- @Getter
- @Setter
- @SerializedName("properties")
- private List<Map<String, String>> properties;
-
- @Getter
- @Setter
- @SerializedName("targets")
- private List<String> targets;
-
- @Getter
- @Setter
- @SerializedName("triggers")
- private List<Map<String, ToscaTrigger>> triggers;
-} \ No newline at end of file
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaPolicyType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaPolicyType.java
deleted file mode 100644
index 241e178f5..000000000
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaPolicyType.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy Model
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. 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.models.tosca;
-
-import com.google.gson.annotations.SerializedName;
-import java.util.List;
-import java.util.Map;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
-
-/**
- * Class to represent the policy type in TOSCA definition.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- *
- */
-@ToString
-public class ToscaPolicyType {
-
- @Getter
- @Setter
- @SerializedName("derived_from")
- private String derivedFrom;
-
- @Getter
- @Setter
- @SerializedName("version")
- private String version;
-
- @Getter
- @Setter
- @SerializedName("metadata")
- private Map<String, String> metadata;
-
- @Getter
- @Setter
- @SerializedName("description")
- private String description;
-
- @Getter
- @Setter
- @SerializedName("properties")
- private List<Map<String, ToscaProperty>> properties;
-
- @Getter
- @Setter
- @SerializedName("targets")
- private List<String> targets;
-
- @Getter
- @Setter
- @SerializedName("triggers")
- private List<Map<String, ToscaTrigger>> triggers;
-} \ No newline at end of file
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaProperty.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaProperty.java
deleted file mode 100644
index 4ee5c45ec..000000000
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaProperty.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy Model
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. 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.models.tosca;
-
-import com.google.gson.annotations.SerializedName;
-import java.util.List;
-
-import javax.persistence.Column;
-
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
-
-import org.onap.policy.models.base.PfConceptKey;
-
-/**
- * Class to represent the property in TOSCA definition.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- *
- */
-@ToString
-public class ToscaProperty {
-
- @Getter
- @Setter
- @SerializedName("type")
- @Column(name = "derivedFrom")
- private PfConceptKey type;
-
- @Getter
- @Setter
- @SerializedName("description")
- private String description;
-
- @Getter
- @Setter
- @SerializedName("required")
- private boolean required;
-
- @Getter
- @Setter
- @SerializedName("default_value")
- private Object defaultValue;
-
- @Getter
- @Setter
- @SerializedName("status")
- private String status;
-
- @Getter
- @Setter
- @SerializedName("constraints")
- private List<ToscaConstraint> constraints;
-
- @Getter
- @Setter
- @SerializedName("entry_schema")
- private ToscaEntrySchema entrySchema;
-} \ No newline at end of file
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaTrigger.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaTrigger.java
deleted file mode 100644
index 2464c2e06..000000000
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaTrigger.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP Policy Model
- * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. 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.models.tosca;
-
-import com.google.gson.annotations.SerializedName;
-import lombok.Getter;
-import lombok.Setter;
-import lombok.ToString;
-
-/**
- * Class to represent the trigger of policy type in TOSCA definition.
- *
- * @author Chenfei Gao (cgao@research.att.com)
- *
- */
-@ToString
-public class ToscaTrigger {
-
- @Getter
- @Setter
- @SerializedName("description")
- private String description;
-
- @Getter
- @Setter
- @SerializedName("event_type")
- private String eventType;
-
- @Getter
- @Setter
- @SerializedName("schedule")
- private ToscaTimeInterval schedule;
-
- @Getter
- @Setter
- @SerializedName("target_filter")
- private ToscaEventFilter targetFilter;
-
- @Getter
- @Setter
- @SerializedName("condition")
- private ToscaConstraint condition;
-
- @Getter
- @Setter
- @SerializedName("constraint")
- private ToscaConstraint constraint;
-
- @Getter
- @Setter
- @SerializedName("period")
- private String period;
-
- @Getter
- @Setter
- @SerializedName("evaluations")
- private int evaluations;
-
- @Getter
- @Setter
- @SerializedName("method")
- private String method;
-
- @Getter
- @Setter
- @SerializedName("action")
- private String action;
-} \ No newline at end of file
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraint.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraint.java
new file mode 100644
index 000000000..dadad6fd6
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraint.java
@@ -0,0 +1,125 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Model
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.models.tosca.concepts;
+
+import java.util.List;
+
+import javax.persistence.EmbeddedId;
+import javax.ws.rs.core.Response;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfValidationMessage;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+
+/**
+ * Immutable class to represent the Constraint of property in TOSCA definition.
+ *
+ * @author Chenfei Gao (cgao@research.att.com)
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+public abstract class ToscaConstraint extends PfConcept {
+ private static final long serialVersionUID = 6426438089914347734L;
+
+ @EmbeddedId
+ private final PfReferenceKey key;
+
+ /**
+ * The Default Constructor creates a {@link ToscaConstraint} object with a null key.
+ */
+ public ToscaConstraint() {
+ this(new PfReferenceKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaConstraint} object with the given concept key.
+ *
+ * @param key the key
+ */
+ public ToscaConstraint(@NonNull final PfReferenceKey key) {
+ this.key = key;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaConstraint(@NonNull final ToscaConstraint copyConcept) {
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+ }
+
+ @Override
+ public List<PfKey> getKeys() {
+ return getKey().getKeys();
+ }
+
+ @Override
+ public void clean() {
+ key.clean();
+ }
+
+ @Override
+ public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ if (key.isNullKey()) {
+ result.addValidationMessage(
+ new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
+ }
+
+ return key.validate(result);
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+ if (this == otherConcept) {
+ return 0;
+ }
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final ToscaConstraint other = (ToscaConstraint) otherConcept;
+
+ return key.compareTo(other.key);
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull final PfConcept target) {
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogical.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogical.java
new file mode 100644
index 000000000..f186d8525
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogical.java
@@ -0,0 +1,119 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import javax.persistence.Column;
+import javax.ws.rs.core.Response;
+
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NonNull;
+import lombok.ToString;
+
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.base.PfReferenceKey;
+
+/**
+ * This class represents a logical TOSCA constraint: =,>,>=,<,<=.
+ */
+@EqualsAndHashCode(callSuper = false)
+@ToString
+public class ToscaConstraintLogical extends ToscaConstraint {
+ private static final long serialVersionUID = 2562306457768745444L;
+
+ public enum Operation {
+ EQ,
+ GT,
+ GE,
+ LT,
+ LE
+ }
+
+ @Column
+ @NonNull
+ @Getter
+ private final Operation operation;
+
+ /**
+ * The Default Constructor creates a {@link ToscaConstraintLogical} object with a null key.
+ */
+ public ToscaConstraintLogical() {
+ this(new PfReferenceKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaConstraintLogical} object with the given concept key.
+ *
+ * @param key the key of the constraint
+ */
+ public ToscaConstraintLogical(final PfReferenceKey key) {
+ this(key, Operation.EQ);
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaConstraintLogical} object with the given concept key and operation.
+ *
+ * @param key the key of the constraint
+ * @param operation the logical operation of the constraint
+ *
+ */
+ public ToscaConstraintLogical(final PfReferenceKey key, @NonNull final Operation operation) {
+ super(key);
+ this.operation = operation;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaConstraintLogical(@NonNull final ToscaConstraintLogical copyConcept) {
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+ if (this == otherConcept) {
+ return 0;
+ }
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final ToscaConstraintLogical other = (ToscaConstraintLogical) otherConcept;
+
+ int result = super.compareTo(other);
+ if (result != 0) {
+ return result;
+ }
+
+ return operation.compareTo(other.operation);
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull final PfConcept target) {
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalKey.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalKey.java
new file mode 100644
index 000000000..1a63f30c8
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalKey.java
@@ -0,0 +1,155 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+import javax.ws.rs.core.Response;
+
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NonNull;
+import lombok.ToString;
+
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfValidationMessage;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+
+/**
+ * This immutable class represents a logical TOSCA constraint: =,>,>=,<,<= that compares the owner
+ * of an instance of the class to the referenced key.
+ */
+@Entity
+@Table(name = "ToscaConstraintLogicalKey")
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
+@EqualsAndHashCode(callSuper = false)
+@ToString
+public final class ToscaConstraintLogicalKey extends ToscaConstraintLogical {
+ private static final long serialVersionUID = -2420828090326264341L;
+
+ @Column
+ @NonNull
+ @Getter
+ private final PfKey compareToKey;
+
+ /**
+ * The Default Constructor creates a {@link ToscaConstraintLogicalKey} object with a null key.
+ */
+ public ToscaConstraintLogicalKey() {
+ this(new PfReferenceKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaConstraintLogicalKey} object with the given concept
+ * key.
+ *
+ * @param key the key of the constraint
+ */
+ public ToscaConstraintLogicalKey(final PfReferenceKey key) {
+ this(key, Operation.EQ, PfConceptKey.getNullKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaConstraintLogicalKey} object with the given concept
+ * key, operation, and compare key.
+ *
+ * @param key the key of the constraint
+ * @param operation the logical operation of the constraint
+ * @param compareToKey the key of the object to which the object that owns this constraint will
+ * be compared
+ */
+ public ToscaConstraintLogicalKey(final PfReferenceKey key, @NonNull final Operation operation,
+ @NonNull final PfKey compareToKey) {
+ super(key, operation);
+ this.compareToKey = compareToKey;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaConstraintLogicalKey(@NonNull final ToscaConstraintLogical copyConcept) {
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+ }
+
+ @Override
+ public List<PfKey> getKeys() {
+ final List<PfKey> keyList = super.getKeys();
+ keyList.addAll(compareToKey.getKeys());
+ return keyList;
+ }
+
+ @Override
+ public void clean() {
+ super.clean();
+ compareToKey.clean();
+ }
+
+ @Override
+ public PfValidationResult validate(final PfValidationResult resultIn) {
+ PfValidationResult result = super.validate(resultIn);
+
+ if (compareToKey.isNullKey()) {
+ result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
+ "comparison key is a null key"));
+ }
+
+ return result;
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+ if (this == otherConcept) {
+ return 0;
+ }
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final ToscaConstraintLogicalKey other = (ToscaConstraintLogicalKey) otherConcept;
+
+ int result = super.compareTo(other);
+ if (result != 0) {
+ return result;
+ }
+
+ return compareToKey.compareTo(other.compareToKey);
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull final PfConcept target) {
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalString.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalString.java
new file mode 100644
index 000000000..c786d626b
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalString.java
@@ -0,0 +1,137 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+import javax.ws.rs.core.Response;
+
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NonNull;
+
+import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfValidationMessage;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+
+/**
+ * This class represents a logical TOSCA constraint: =,>,>=,<,<= that compares the owner of an
+ * instance of the class to the given string.
+ */
+@Entity
+@Table(name = "ToscaConstraintLogicalString")
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
+@EqualsAndHashCode(callSuper = false)
+public class ToscaConstraintLogicalString extends ToscaConstraintLogical {
+ private static final long serialVersionUID = 8167550632122339195L;
+
+ @Column
+ @NonNull
+ @Getter
+ private final String compareToString;
+
+ /**
+ * The Default Constructor creates a {@link ToscaConstraintLogicalString} object with a null key.
+ */
+ public ToscaConstraintLogicalString() {
+ this(new PfReferenceKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaConstraintLogicalString} object with the given concept
+ * key.
+ *
+ * @param key the key of the constraint
+ */
+ public ToscaConstraintLogicalString(final PfReferenceKey key) {
+ this(key, Operation.EQ, "");
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaConstraintLogicalString} object with the given concept
+ * key, operation, and compare string.
+ *
+ * @param key the key of the constraint
+ * @param operation the logical operation of the constraint
+ * @param compareToString the key of the object to which the object that owns this constraint will
+ * be compared
+ */
+ public ToscaConstraintLogicalString(final PfReferenceKey key, @NonNull final Operation operation,
+ @NonNull final String compareToString) {
+ super(key, operation);
+ this.compareToString = compareToString.trim();
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaConstraintLogicalString(@NonNull final ToscaConstraintLogical copyConcept) {
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+ }
+
+ @Override
+ public PfValidationResult validate(final PfValidationResult resultIn) {
+ PfValidationResult result = super.validate(resultIn);
+
+ if (!ParameterValidationUtils.validateStringParameter(compareToString)) {
+ result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
+ "comparison string is null or blank"));
+ }
+
+ return result;
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+ if (this == otherConcept) {
+ return 0;
+ }
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final ToscaConstraintLogicalString other = (ToscaConstraintLogicalString) otherConcept;
+
+ int result = super.compareTo(other);
+ if (result != 0) {
+ return result;
+ }
+
+ return compareToString.compareTo(other.compareToString);
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull final PfConcept target) {
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataType.java
new file mode 100644
index 000000000..5af24d6ed
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataType.java
@@ -0,0 +1,246 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Model
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.models.tosca.concepts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.ElementCollection;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+
+import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfUtils;
+import org.onap.policy.models.base.PfValidationMessage;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+
+/**
+ * Class to represent custom data type in TOSCA definition.
+ *
+ * @author Chenfei Gao (cgao@research.att.com)
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Entity
+@Table(name = "ToscaDataType")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ToscaDataType extends ToscaEntityType {
+ private static final long serialVersionUID = -3922690413436539164L;
+
+ @ElementCollection
+ private List<ToscaConstraint> constraints;
+
+ @ElementCollection
+ private List<ToscaProperty> properties;
+
+ /**
+ * The Default Constructor creates a {@link ToscaDataType} object with a null key.
+ */
+ public ToscaDataType() {
+ this(new PfConceptKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaDataType} object with the given concept key.
+ *
+ * @param key the key
+ */
+ public ToscaDataType(@NonNull final PfConceptKey key) {
+ super(key);
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaDataType(final ToscaDataType copyConcept) {
+ super(copyConcept);
+ }
+
+ @Override
+ public List<PfKey> getKeys() {
+ final List<PfKey> keyList = super.getKeys();
+
+ if (constraints != null) {
+ for (ToscaConstraint constraint : constraints) {
+ keyList.addAll(constraint.getKeys());
+ }
+ }
+
+ if (properties != null) {
+ for (ToscaProperty property : properties) {
+ keyList.addAll(property.getKeys());
+ }
+ }
+
+ return keyList;
+ }
+
+ @Override
+ public void clean() {
+ super.clean();
+
+ if (constraints != null) {
+ for (ToscaConstraint constraint : constraints) {
+ constraint.clean();
+ }
+ }
+
+ if (properties != null) {
+ for (ToscaProperty property : properties) {
+ property.clean();
+ }
+ }
+ }
+
+ @Override
+ public PfValidationResult validate(final PfValidationResult resultIn) {
+ PfValidationResult result = super.validate(resultIn);
+
+ if (constraints != null) {
+ result = validateConstraints(result);
+ }
+
+ if (properties != null) {
+ result = validateProperties(result);
+ }
+
+ return result;
+ }
+
+ /**
+ * Validate the constraints.
+ *
+ * @param result The result of validations up to now
+ * @return the validation result
+ */
+ private PfValidationResult validateConstraints(@NonNull final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ for (ToscaConstraint constraint : constraints) {
+ if (constraint == null) {
+ result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
+ "data type constraint may not be null "));
+ } else {
+ result = constraint.validate(result);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Validate the properties.
+ *
+ * @param result The result of validations up to now
+ * @return the validation result
+ */
+ private PfValidationResult validateProperties(final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ for (ToscaProperty property : properties) {
+ if (property == null) {
+ result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
+ "data type property may not be null "));
+ } else {
+ result = property.validate(result);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+ if (this == otherConcept) {
+ return 0;
+ }
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final ToscaDataType other = (ToscaDataType) otherConcept;
+ if (!super.equals(other)) {
+ return super.compareTo(other);
+ }
+
+ int result = PfUtils.compareObjects(constraints, other.constraints);
+ if (result != 0) {
+ return result;
+ }
+
+ result = PfUtils.compareObjects(properties, other.properties);
+ if (result != 0) {
+ return result;
+ }
+
+ return 0;
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull PfConcept target) {
+ final Object copyObject = target;
+ Assertions.instanceOf(copyObject, PfConcept.class);
+
+ final ToscaDataType copy = ((ToscaDataType) copyObject);
+ super.copyTo(target);
+
+ if (constraints == null) {
+ copy.setConstraints(null);
+ }
+ else {
+ final List<ToscaConstraint> newConstraints = new ArrayList<>();
+ for (final ToscaConstraint constraint : constraints) {
+ newConstraints.add(constraint); // Constraints are immutable
+ }
+ copy.setConstraints(newConstraints);
+ }
+
+ if (properties == null) {
+ copy.setProperties(null);
+ }
+ else {
+ final List<ToscaProperty> newProperties = new ArrayList<>();
+ for (final ToscaProperty property : properties) {
+ newProperties.add(new ToscaProperty(property));
+ }
+ copy.setProperties(newProperties);
+ }
+
+ return copy;
+ }
+} \ No newline at end of file
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataTypes.java
new file mode 100644
index 000000000..61c3500cb
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataTypes.java
@@ -0,0 +1,86 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import org.onap.policy.models.base.PfConceptContainer;
+import org.onap.policy.models.base.PfConceptKey;
+
+/**
+ * This class is a container for TOSCA data types.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Entity
+@Table(name = "ToscaDataTypes")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ToscaDataTypes extends PfConceptContainer<ToscaDataType> {
+ private static final long serialVersionUID = 2941102271022190348L;
+
+ /**
+ * The Default Constructor creates a {@link ToscaDataTypes} object with a null artifact key
+ * and creates an empty concept map.
+ */
+ public ToscaDataTypes() {
+ super(new PfConceptKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaDataTypes} object with the given artifact key
+ * and creates an empty concept map.
+ *
+ * @param key the concept key
+ */
+ public ToscaDataTypes(final PfConceptKey key) {
+ super(key, new TreeMap<PfConceptKey, ToscaDataType>());
+ }
+
+ /**
+ * This Constructor creates an concept container with all of its fields defined.
+ *
+ * @param key the concept container key
+ * @param conceptMap the concepts to be stored in the concept container
+ */
+ public ToscaDataTypes(final PfConceptKey key, final Map<PfConceptKey, ToscaDataType> conceptMap) {
+ super(key, conceptMap);
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaDataTypes(final ToscaDataTypes copyConcept) {
+ super(copyConcept);
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaEntityType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntityType.java
index 52a82cc53..b0dc58d93 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/ToscaEntityType.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntityType.java
@@ -18,11 +18,10 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca;
+package org.onap.policy.models.tosca.concepts;
import com.google.gson.annotations.SerializedName;
-import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -41,11 +40,16 @@ import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
+import org.apache.commons.lang3.ObjectUtils;
import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.common.utils.validation.ParameterValidationUtils;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfUtils;
+import org.onap.policy.models.base.PfValidationMessage;
import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
/**
* Class to represent the EntrySchema of list/map property in TOSCA definition.
@@ -59,8 +63,7 @@ public class ToscaEntityType extends PfConcept {
private static final long serialVersionUID = -1330661834220739393L;
@EmbeddedId
- @NonNull
- private PfConceptKey key = PfConceptKey.getNullKey();
+ private PfConceptKey key;
@SerializedName("derived_from")
@Column(name = "derivedFrom")
@@ -99,23 +102,65 @@ public class ToscaEntityType extends PfConcept {
@Override
public List<PfKey> getKeys() {
- final List<PfKey> keyList = new ArrayList<>();
- keyList.add(getKey());
+ final List<PfKey> keyList = getKey().getKeys();
+ if (derivedFrom != null) {
+ keyList.addAll(derivedFrom.getKeys());
+ }
return keyList;
}
@Override
public void clean() {
- description = description.trim();
+ key.clean();
+
+ if (derivedFrom != null) {
+ derivedFrom.clean();
+ }
- for (Entry<String, String> metadataEntry : metadata.entrySet()) {
- metadataEntry.setValue(metadataEntry.getValue().trim());
+ if (metadata != null) {
+ for (Entry<String, String> metadataEntry : metadata.entrySet()) {
+ metadataEntry.setValue(metadataEntry.getValue().trim());
+ }
}
+
+ description = (description != null ? description.trim() : null);
}
@Override
- public PfValidationResult validate(PfValidationResult result) {
- return null;
+ public PfValidationResult validate(PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ if (key.isNullKey()) {
+ result.addValidationMessage(
+ new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
+ }
+
+ result = key.validate(result);
+
+ if (derivedFrom != null && derivedFrom.isNullKey()) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "derived from key is a null key"));
+ }
+
+ if (metadata != null) {
+ for (Entry<String, String> metadataEntry : metadata.entrySet()) {
+ if (!ParameterValidationUtils.validateStringParameter(metadataEntry.getKey())) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "property metadata key may not be null"));
+ }
+ if (!ParameterValidationUtils.validateStringParameter(metadataEntry.getValue())) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "property metadata value may not be null"));
+ }
+ }
+ }
+
+ if (description != null && description.trim().length() == 0) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "property description may not be blank"));
+ }
+
+ return result;
}
@Override
@@ -135,15 +180,17 @@ public class ToscaEntityType extends PfConcept {
return key.compareTo(other.key);
}
- if (!derivedFrom.equals(other.derivedFrom)) {
- return derivedFrom.compareTo(other.derivedFrom);
+ int result = ObjectUtils.compare(derivedFrom, other.derivedFrom);
+ if (result != 0) {
+ return result;
}
- if (!metadata.equals(other.metadata)) {
- return (metadata.hashCode() - other.metadata.hashCode());
+ result = PfUtils.compareObjects(metadata, other.metadata);
+ if (result != 0) {
+ return result;
}
- return description.compareTo(other.description);
+ return ObjectUtils.compare(description, other.description);
}
@Override
@@ -152,16 +199,18 @@ public class ToscaEntityType extends PfConcept {
Assertions.instanceOf(copyObject, PfConcept.class);
final ToscaEntityType copy = ((ToscaEntityType) copyObject);
- copy.key = new PfConceptKey(key);
- copy.derivedFrom = new PfConceptKey(derivedFrom);
-
- final Map<String, String> newMatadata = new TreeMap<>();
- for (final Entry<String, String> metadataEntry : metadata.entrySet()) {
- newMatadata.put(metadataEntry.getKey(), metadataEntry.getValue());
+ copy.setKey(new PfConceptKey(key));
+ copy.setDerivedFrom(derivedFrom != null ? new PfConceptKey(derivedFrom) : null);
+
+ if (metadata != null) {
+ final Map<String, String> newMatadata = new TreeMap<>();
+ for (final Entry<String, String> metadataEntry : metadata.entrySet()) {
+ newMatadata.put(metadataEntry.getKey(), metadataEntry.getValue());
+ }
+ copy.setMetadata(newMatadata);
}
- copy.metadata = newMatadata;
- copy.description = description;
+ copy.setDescription(description);
return copy;
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntrySchema.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntrySchema.java
new file mode 100644
index 000000000..72bedbd9e
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntrySchema.java
@@ -0,0 +1,228 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Model
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.models.tosca.concepts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.ElementCollection;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+
+import org.apache.commons.lang3.ObjectUtils;
+import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfUtils;
+import org.onap.policy.models.base.PfValidationMessage;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+
+
+/**
+ * Class to represent the EntrySchema of list/map property in TOSCA definition.
+ *
+ * @author Chenfei Gao (cgao@research.att.com)
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Entity
+@Table(name = "ToscaEntrySchema")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class ToscaEntrySchema extends PfConcept {
+ private static final long serialVersionUID = 3645882081163287058L;
+
+ @EmbeddedId
+ private PfReferenceKey key;
+
+ @Column
+ private PfConceptKey type;
+
+ @Column
+ private String description;
+
+ @ElementCollection
+ private List<ToscaConstraint> constraints;
+
+ /**
+ * The Default Constructor creates a {@link ToscaEntrySchema} object with a null key.
+ */
+ public ToscaEntrySchema() {
+ this(new PfReferenceKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaEntrySchema} object with the given concept key.
+ *
+ * @param key the key
+ */
+ public ToscaEntrySchema(@NonNull final PfReferenceKey key) {
+ this(key, new PfConceptKey());
+ }
+
+ /**
+ * The full constructor creates a {@link ToscaEntrySchema} object with mandatory fields.
+ *
+ * @param key the key
+ * @param type the type of the entry schema
+ */
+ public ToscaEntrySchema(@NonNull final PfReferenceKey key, @NonNull final PfConceptKey type) {
+ this.key = key;
+ this.type = type;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaEntrySchema(final ToscaEntrySchema copyConcept) {
+ super(copyConcept);
+ }
+
+ @Override
+ public List<PfKey> getKeys() {
+ final List<PfKey> keyList = getKey().getKeys();
+
+ keyList.addAll(type.getKeys());
+
+ if (constraints != null) {
+ for (ToscaConstraint constraint : constraints) {
+ keyList.addAll(constraint.getKeys());
+ }
+ }
+
+ return keyList;
+ }
+
+ @Override
+ public void clean() {
+ key.clean();
+
+ type.clean();
+ description = (description != null ? description.trim() : null);
+
+ if (constraints != null) {
+ for (ToscaConstraint constraint : constraints) {
+ constraint.clean();
+ }
+ }
+ }
+
+ @Override
+ public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ if (key.isNullKey()) {
+ result.addValidationMessage(
+ new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
+ }
+
+ result = key.validate(result);
+
+ if (type == null || type.isNullKey()) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "entry schema type may not be null"));
+ }
+
+ if (description != null && description.trim().length() == 0) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "entry schema description may not be blank"));
+ }
+
+
+ if (constraints != null) {
+ for (ToscaConstraint constraint : constraints) {
+ if (constraint == null) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "property constraint may not be null "));
+ } else {
+ result = constraint.validate(result);
+ }
+ }
+ }
+
+ return result;
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+ if (this == otherConcept) {
+ return 0;
+ }
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final ToscaEntrySchema other = (ToscaEntrySchema) otherConcept;
+ if (!key.equals(other.key)) {
+ return key.compareTo(other.key);
+ }
+
+ if (!type.equals(other.type)) {
+ return type.compareTo(other.type);
+ }
+
+ int result = ObjectUtils.compare(description, other.description);
+ if (result != 0) {
+ return result;
+ }
+
+ return PfUtils.compareObjects(constraints, other.constraints);
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull final PfConcept target) {
+ Assertions.instanceOf(target, ToscaEntrySchema.class);
+
+ final ToscaEntrySchema copy = ((ToscaEntrySchema) target);
+ copy.setKey(new PfReferenceKey(key));
+ copy.setType(new PfConceptKey(type));
+ copy.setDescription(description);
+
+ if (constraints != null) {
+ final List<ToscaConstraint> newConstraints = new ArrayList<>();
+ for (final ToscaConstraint constraint : constraints) {
+ newConstraints.add(constraint); // Constraints are immutable
+ }
+ copy.setConstraints(newConstraints);
+ }
+
+ return copy;
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEventFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEventFilter.java
new file mode 100644
index 000000000..4e2d73763
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEventFilter.java
@@ -0,0 +1,197 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Model
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.models.tosca.concepts;
+
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+
+import org.apache.commons.lang3.ObjectUtils;
+import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfValidationMessage;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+
+/**
+ * Class to represent the EventFilter in TOSCA definition.
+ *
+ * @author Chenfei Gao (cgao@research.att.com)
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Entity
+@Table(name = "ToscaEventFilter")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class ToscaEventFilter extends PfConcept {
+ private static final long serialVersionUID = 8769020537228210247L;
+
+ @EmbeddedId
+ private PfReferenceKey key;
+
+ @Column
+ private PfConceptKey node;
+
+ @Column
+ private String requirement;
+
+ @Column
+ private String capability;
+
+ /**
+ * The Default Constructor creates a {@link ToscaEventFilter} object with a null key.
+ */
+ public ToscaEventFilter() {
+ this(new PfReferenceKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaEventFilter} object with the given concept key.
+ *
+ * @param key the key
+ */
+ public ToscaEventFilter(@NonNull final PfReferenceKey key) {
+ this(key, new PfConceptKey());
+ }
+
+ /**
+ * The full Constructor creates a {@link ToscaEventFilter} object with the given concept key and node.
+ *
+ * @param key the key
+ */
+ public ToscaEventFilter(@NonNull final PfReferenceKey key, @NonNull final PfConceptKey node) {
+ this.key = key;
+ this.node = node;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaEventFilter(final ToscaEventFilter copyConcept) {
+ super(copyConcept);
+ }
+
+ @Override
+ public List<PfKey> getKeys() {
+ final List<PfKey> keyList = getKey().getKeys();
+ keyList.addAll(node.getKeys());
+ return keyList;
+ }
+
+ @Override
+ public void clean() {
+ key.clean();
+ node.clean();
+
+ requirement = (requirement != null ? requirement.trim() : requirement);
+ capability = (capability != null ? capability.trim() : capability);
+ }
+
+ @Override
+ public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ if (key.isNullKey()) {
+ result.addValidationMessage(
+ new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
+ }
+
+ result = key.validate(result);
+
+ if (node == null || node.isNullKey()) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "node on an event filter may not be null"));
+ }
+
+ if (requirement != null && requirement.trim().length() == 0) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "event filter requirement may not be blank"));
+ }
+
+ if (capability != null && capability.trim().length() == 0) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "event filter capability may not be blank"));
+ }
+
+ return result;
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+ if (this == otherConcept) {
+ return 0;
+ }
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final ToscaEventFilter other = (ToscaEventFilter) otherConcept;
+ if (!key.equals(other.key)) {
+ return key.compareTo(other.key);
+ }
+
+ if (!node.equals(other.node)) {
+ return node.compareTo(other.node);
+ }
+
+ int result = ObjectUtils.compare(requirement, other.requirement);
+ if (result != 0) {
+ return result;
+ }
+
+ return ObjectUtils.compare(capability, other.capability);
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull final PfConcept target) {
+ final Object copyObject = target;
+ Assertions.instanceOf(copyObject, ToscaEventFilter.class);
+
+ final ToscaEventFilter copy = ((ToscaEventFilter) copyObject);
+ copy.setKey(new PfReferenceKey(key));
+ copy.setNode(new PfConceptKey(node));
+ copy.setRequirement(requirement);
+ copy.setCapability(capability);
+
+ return copy;
+ }
+} \ No newline at end of file
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaModel.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaModel.java
new file mode 100644
index 000000000..9169e6778
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaModel.java
@@ -0,0 +1,160 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import java.util.List;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+
+import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfModel;
+import org.onap.policy.models.base.PfModelService;
+import org.onap.policy.models.base.PfValidationResult;
+
+/**
+ * A container class for a TOSCA model with multiple service templates. This class is a container
+ * class that allows a model with many service templates to be constructed that contains a well
+ * formed overall TOSCA model.
+ *
+ * <p>Validation runs {@link ToscaModel} validation on the model and all its sub concepts.
+ */
+
+@Entity
+@Table(name = "ToscaModel")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ToscaModel extends PfModel {
+ private static final long serialVersionUID = 8800599637708309945L;
+
+ @OneToOne(cascade = CascadeType.ALL)
+ private ToscaServiceTemplates serviceTemplates;
+
+ /**
+ * The Default Constructor creates a {@link ToscaModel} object with a null concept key and
+ * creates an empty TOSCA model.
+ */
+ public ToscaModel() {
+ this(new PfConceptKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaModel} object with the given concept key and
+ * creates an empty TOSCA model.
+ *
+ * @param key the TOSCA model key
+ */
+ public ToscaModel(final PfConceptKey key) {
+ this(key, new ToscaServiceTemplates(new PfConceptKey()));
+ }
+
+ /**
+ * Constructor that initiates a {@link ToscaModel} with all its fields.
+ *
+ * @param key the TOSCA model key
+ * @param serviceTemplates the service templates in the event model
+ */
+ public ToscaModel(@NonNull final PfConceptKey key, @NonNull final ToscaServiceTemplates serviceTemplates) {
+ super(key);
+ this.serviceTemplates = serviceTemplates;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaModel(@NonNull final ToscaModel copyConcept) {
+ super(copyConcept);
+ }
+
+ @Override
+ public void register() {
+ PfModelService.registerModel(serviceTemplates.getId(), getServiceTemplates());
+ }
+
+ @Override
+ public List<PfKey> getKeys() {
+ final List<PfKey> keyList = super.getKeys();
+
+ keyList.addAll(serviceTemplates.getKeys());
+
+ return keyList;
+ }
+
+ @Override
+ public void clean() {
+ super.clean();
+ serviceTemplates.clean();
+ }
+
+ @Override
+ public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
+ PfValidationResult result = super.validate(resultIn);
+
+ return serviceTemplates.validate(result);
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+
+ if (this == otherConcept) {
+ return 0;
+ }
+
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final ToscaModel other = (ToscaModel) otherConcept;
+ if (!super.equals(other)) {
+ return super.compareTo(other);
+ }
+
+ return serviceTemplates.compareTo(other.serviceTemplates);
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull final PfConcept targetObject) {
+ Assertions.instanceOf(targetObject, ToscaModel.class);
+
+ final ToscaModel copy = ((ToscaModel) targetObject);
+ super.copyTo(targetObject);
+ copy.setServiceTemplates(new ToscaServiceTemplates(serviceTemplates));
+
+ return copy;
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicies.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicies.java
new file mode 100644
index 000000000..7209fd081
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicies.java
@@ -0,0 +1,86 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import org.onap.policy.models.base.PfConceptContainer;
+import org.onap.policy.models.base.PfConceptKey;
+
+/**
+ * This class is a container for TOSCA data types.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Entity
+@Table(name = "ToscaPolicies")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ToscaPolicies extends PfConceptContainer<ToscaPolicy> {
+ private static final long serialVersionUID = -7526648702327776101L;
+
+ /**
+ * The Default Constructor creates a {@link ToscaPolicies} object with a null artifact key and
+ * creates an empty concept map.
+ */
+ public ToscaPolicies() {
+ super(new PfConceptKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaPolicies} object with the given artifact key and
+ * creates an empty concept map.
+ *
+ * @param key the concept key
+ */
+ public ToscaPolicies(final PfConceptKey key) {
+ super(key, new TreeMap<PfConceptKey, ToscaPolicy>());
+ }
+
+ /**
+ * This Constructor creates an concept container with all of its fields defined.
+ *
+ * @param key the concept container key
+ * @param conceptMap the concepts to be stored in the concept container
+ */
+ public ToscaPolicies(final PfConceptKey key, final Map<PfConceptKey, ToscaPolicy> conceptMap) {
+ super(key, conceptMap);
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaPolicies(final ToscaPolicies copyConcept) {
+ super(copyConcept);
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicy.java
new file mode 100644
index 000000000..3e1fddd31
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicy.java
@@ -0,0 +1,273 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Model
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.models.tosca.concepts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.ElementCollection;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+
+import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfUtils;
+import org.onap.policy.models.base.PfValidationMessage;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+
+/**
+ * Class to represent the policy in TOSCA definition.
+ *
+ * @author Chenfei Gao (cgao@research.att.com)
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Entity
+@Table(name = "ToscaPolicy")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ToscaPolicy extends ToscaEntityType {
+ private static final long serialVersionUID = 3265174757061982805L;
+
+ @Column
+ private PfConceptKey type;
+
+ @ElementCollection
+ private List<ToscaProperty> properties;
+
+ @ElementCollection
+ private List<PfConceptKey> targets;
+
+ /**
+ * The Default Constructor creates a {@link ToscaPolicy} object with a null key.
+ */
+ public ToscaPolicy() {
+ this(new PfConceptKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaPolicy} object with the given concept key.
+ *
+ * @param key the key
+ */
+ public ToscaPolicy(@NonNull final PfConceptKey key) {
+ this(key, new PfConceptKey());
+ }
+
+ /**
+ * The full Constructor creates a {@link ToscaPolicy} object with all mandatory fields.
+ *
+ * @param key the key
+ * @param type the type of the policy
+ */
+ public ToscaPolicy(@NonNull final PfConceptKey key, @NonNull final PfConceptKey type) {
+ super(key);
+ this.type = type;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaPolicy(@NonNull final ToscaPolicy copyConcept) {
+ super(copyConcept);
+ }
+
+
+ @Override
+ public List<PfKey> getKeys() {
+ final List<PfKey> keyList = super.getKeys();
+
+ keyList.addAll(type.getKeys());
+
+ if (properties != null) {
+ for (ToscaProperty property : properties) {
+ keyList.addAll(property.getKeys());
+ }
+ }
+
+ if (targets != null) {
+ keyList.addAll(targets);
+ }
+
+ return keyList;
+ }
+
+ @Override
+ public void clean() {
+ super.clean();
+
+ type.clean();
+
+ if (properties != null) {
+ for (ToscaProperty property : properties) {
+ property.clean();
+ }
+ }
+
+ if (targets != null) {
+ for (PfConceptKey target : targets) {
+ target.clean();
+ }
+ }
+ }
+
+ @Override
+ public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
+ PfValidationResult result = super.validate(resultIn);
+
+ if (type == null || type.isNullKey()) {
+ result.addValidationMessage(new PfValidationMessage(type, this.getClass(), ValidationResult.INVALID,
+ "type is null or a null key"));
+ }
+ else {
+ result = type.validate(result);
+ }
+
+ if (properties != null) {
+ result = validateProperties(result);
+ }
+
+ if (targets != null) {
+ result = validateTargets(result);
+ }
+
+ return result;
+ }
+
+ /**
+ * Validate the policy properties.
+ *
+ * @param result The result of validations up to now
+ * @return the validation result
+ */
+ private PfValidationResult validateProperties(@NonNull final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ for (ToscaProperty property : properties) {
+ if (property == null) {
+ result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
+ "policy property may not be null "));
+ } else {
+ result = property.validate(result);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Validate the policy targets.
+ *
+ * @param result The result of validations up to now
+ * @return the validation result
+ */
+ private PfValidationResult validateTargets(final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ for (PfConceptKey target : targets) {
+ if (target == null) {
+ result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
+ "policy target may not be null "));
+ } else {
+ result = target.validate(result);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+
+ if (this == otherConcept) {
+ return 0;
+ }
+
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final ToscaPolicy other = (ToscaPolicy) otherConcept;
+ if (!super.equals(other)) {
+ return super.compareTo(other);
+ }
+
+ if (!type.equals(other.type)) {
+ return type.compareTo(other.type);
+ }
+
+ int retVal = PfUtils.compareObjects(properties, other.properties);
+ if (retVal != 0) {
+ return retVal;
+ }
+
+ return PfUtils.compareObjects(targets, other.targets);
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull PfConcept target) {
+ final Object copyObject = target;
+ Assertions.instanceOf(copyObject, PfConcept.class);
+
+ final ToscaPolicy copy = ((ToscaPolicy) copyObject);
+ super.copyTo(target);
+
+ copy.setType(new PfConceptKey(type));
+
+ if (properties == null) {
+ copy.setProperties(null);
+ } else {
+ final List<ToscaProperty> newProperties = new ArrayList<>();
+ for (final ToscaProperty property : properties) {
+ newProperties.add(new ToscaProperty(property));
+ }
+ copy.setProperties(newProperties);
+ }
+
+ if (targets == null) {
+ copy.setTargets(null);
+ } else {
+ final List<PfConceptKey> newTargets = new ArrayList<>();
+ for (final PfConceptKey oldTarget : targets) {
+ newTargets.add(new PfConceptKey(oldTarget));
+ }
+ copy.setTargets(newTargets);
+ }
+
+ return copy;
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyType.java
new file mode 100644
index 000000000..dbd011468
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyType.java
@@ -0,0 +1,294 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Model
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.models.tosca.concepts;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.persistence.ElementCollection;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+
+import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfUtils;
+import org.onap.policy.models.base.PfValidationMessage;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+
+/**
+ * Class to represent the policy type in TOSCA definition.
+ *
+ * @author Chenfei Gao (cgao@research.att.com)
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+
+@Entity
+@Table(name = "ToscaPolicyType")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ToscaPolicyType extends ToscaEntityType {
+ private static final long serialVersionUID = -563659852901842616L;
+
+ @ElementCollection
+ private List<ToscaProperty> properties;
+
+ @ElementCollection
+ private List<PfConceptKey> targets;
+
+ @ElementCollection
+ private List<ToscaTrigger> triggers;
+
+ /**
+ * The Default Constructor creates a {@link ToscaPolicyType} object with a null key.
+ */
+ public ToscaPolicyType() {
+ this(new PfConceptKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaPolicyType} object with the given concept key.
+ *
+ * @param key the key
+ */
+ public ToscaPolicyType(@NonNull final PfConceptKey key) {
+ super(key);
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaPolicyType(final ToscaPolicyType copyConcept) {
+ super(copyConcept);
+ }
+
+
+ @Override
+ public List<PfKey> getKeys() {
+ final List<PfKey> keyList = super.getKeys();
+
+ if (properties != null) {
+ for (ToscaProperty property : properties) {
+ keyList.addAll(property.getKeys());
+ }
+ }
+
+ if (targets != null) {
+ keyList.addAll(targets);
+ }
+
+ if (triggers != null) {
+ for (ToscaTrigger trigger : triggers) {
+ keyList.addAll(trigger.getKeys());
+ }
+ }
+
+ return keyList;
+ }
+
+ @Override
+ public void clean() {
+ super.clean();
+
+ if (properties != null) {
+ for (ToscaProperty property : properties) {
+ property.clean();
+ }
+ }
+
+ if (targets != null) {
+ for (PfConceptKey target : targets) {
+ target.clean();
+ }
+ }
+
+ if (triggers != null) {
+ for (ToscaTrigger trigger : triggers) {
+ trigger.clean();
+ }
+ }
+ }
+
+ @Override
+ public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
+ PfValidationResult result = super.validate(resultIn);
+
+ if (properties != null) {
+ result = validateProperties(result);
+ }
+
+ if (targets != null) {
+ result = validateTargets(result);
+ }
+
+ if (triggers != null) {
+ result = validateTriggers(result);
+ }
+
+ return result;
+ }
+
+ /**
+ * Validate the policy properties.
+ *
+ * @param result The result of validations up to now
+ * @return the validation result
+ */
+ private PfValidationResult validateProperties(final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ for (ToscaProperty property : properties) {
+ if (property == null) {
+ result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
+ "policy property may not be null "));
+ } else {
+ result = property.validate(result);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Validate the policy targets.
+ *
+ * @param result The result of validations up to now
+ * @return the validation result
+ */
+ private PfValidationResult validateTargets(final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ for (PfConceptKey target : targets) {
+ if (target == null) {
+ result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
+ "policy target may not be null "));
+ } else {
+ result = target.validate(result);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Validate the policy triggers.
+ *
+ * @param result The result of validations up to now
+ * @return the validation result
+ */
+ private PfValidationResult validateTriggers(final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ for (ToscaTrigger trigger : triggers) {
+ if (trigger == null) {
+ result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
+ "policy trigger may not be null "));
+ } else {
+ result = trigger.validate(result);
+ }
+ }
+ return result;
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+ if (this == otherConcept) {
+ return 0;
+ }
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final ToscaPolicyType other = (ToscaPolicyType) otherConcept;
+ if (!super.equals(other)) {
+ return super.compareTo(other);
+ }
+
+ int retVal = PfUtils.compareObjects(properties, other.properties);
+ if (retVal != 0) {
+ return retVal;
+ }
+
+ retVal = PfUtils.compareObjects(targets, other.targets);
+ if (retVal != 0) {
+ return retVal;
+ }
+
+ return PfUtils.compareObjects(triggers, other.triggers);
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull PfConcept target) {
+ final Object copyObject = target;
+ Assertions.instanceOf(copyObject, PfConcept.class);
+
+ final ToscaPolicyType copy = ((ToscaPolicyType) copyObject);
+ super.copyTo(target);
+
+ final List<ToscaProperty> newProperties = new ArrayList<>();
+
+ if (properties == null) {
+ copy.setProperties(null);
+ } else {
+ for (final ToscaProperty property : properties) {
+ newProperties.add(new ToscaProperty(property));
+ }
+ copy.setProperties(newProperties);
+ }
+
+ if (targets == null) {
+ copy.setTargets(null);
+ } else {
+ final List<PfConceptKey> newTargets = new ArrayList<>();
+ for (final PfConceptKey oldTarget : targets) {
+ newTargets.add(new PfConceptKey(oldTarget));
+ }
+ copy.setTargets(newTargets);
+ }
+
+ if (triggers == null) {
+ copy.setTargets(null);
+ } else {
+ final List<ToscaTrigger> newTriggers = new ArrayList<>();
+ for (final ToscaTrigger trigger : triggers) {
+ newTriggers.add(new ToscaTrigger(trigger));
+ }
+ copy.setTriggers(newTriggers);
+ }
+
+ return copy;
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypes.java
new file mode 100644
index 000000000..e33e6c0c9
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypes.java
@@ -0,0 +1,86 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import org.onap.policy.models.base.PfConceptContainer;
+import org.onap.policy.models.base.PfConceptKey;
+
+/**
+ * This class is a container for TOSCA policy types.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Entity
+@Table(name = "ToscaPolicyTypes")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ToscaPolicyTypes extends PfConceptContainer<ToscaPolicyType> {
+ private static final long serialVersionUID = -4157979965271220098L;
+
+ /**
+ * The Default Constructor creates a {@link ToscaPolicyTypes} object with a null artifact key
+ * and creates an empty concept map.
+ */
+ public ToscaPolicyTypes() {
+ super(new PfConceptKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaPolicyTypes} object with the given artifact key and
+ * creates an empty concept map.
+ *
+ * @param key the concept key
+ */
+ public ToscaPolicyTypes(final PfConceptKey key) {
+ super(key, new TreeMap<PfConceptKey, ToscaPolicyType>());
+ }
+
+ /**
+ * This Constructor creates an concept container with all of its fields defined.
+ *
+ * @param key the concept container key
+ * @param conceptMap the concepts to be stored in the concept container
+ */
+ public ToscaPolicyTypes(final PfConceptKey key, final Map<PfConceptKey, ToscaPolicyType> conceptMap) {
+ super(key, conceptMap);
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaPolicyTypes(final ToscaPolicyTypes copyConcept) {
+ super(copyConcept);
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaProperty.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaProperty.java
new file mode 100644
index 000000000..ab72ff60e
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaProperty.java
@@ -0,0 +1,308 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Model
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.models.tosca.concepts;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.ElementCollection;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+
+import org.apache.commons.lang3.ObjectUtils;
+import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfUtils;
+import org.onap.policy.models.base.PfValidationMessage;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+
+/**
+ * Class to represent the property in TOSCA definition.
+ *
+ * @author Chenfei Gao (cgao@research.att.com)
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Entity
+@Table(name = "ToscaProperty")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class ToscaProperty extends PfConcept {
+ private static final long serialVersionUID = 1675770231921107988L;
+
+ public enum Status {
+ SUPPORTED, UNSUPPORTED, EXPERIMENTAL, DEPRECATED
+ }
+
+ @EmbeddedId
+ private PfReferenceKey key;
+
+ @Column
+ private PfConceptKey type;
+
+ @Column
+ private String description;
+
+ @Column
+ private boolean required = false;
+
+ @Column(name = "default")
+ @SerializedName("default")
+ private PfKey defaultValue;
+
+ @Column
+ @NonNull
+ private Status status = Status.SUPPORTED;
+
+ @ElementCollection
+ private List<ToscaConstraint> constraints;
+
+ @Column
+ @SerializedName("entry_schema")
+ private ToscaEntrySchema entrySchema;
+
+ /**
+ * The Default Constructor creates a {@link ToscaProperty} object with a null key.
+ */
+ public ToscaProperty() {
+ this(new PfReferenceKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaProperty} object with the given concept key.
+ *
+ * @param key the key
+ */
+ public ToscaProperty(@NonNull final PfReferenceKey key) {
+ this(key, new PfConceptKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaProperty} object with the given concept key.
+ *
+ * @param key the key
+ * @param type the key of the property type
+ */
+ public ToscaProperty(@NonNull final PfReferenceKey key, @NonNull final PfConceptKey type) {
+ this.key = key;
+ this.type = type;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaProperty(final ToscaProperty copyConcept) {
+ super(copyConcept);
+ }
+
+ @Override
+ public List<PfKey> getKeys() {
+ final List<PfKey> keyList = getKey().getKeys();
+
+ keyList.addAll(type.getKeys());
+
+ if (defaultValue != null) {
+ keyList.addAll(defaultValue.getKeys());
+ }
+
+ if (constraints != null) {
+ for (ToscaConstraint constraint : constraints) {
+ keyList.addAll(constraint.getKeys());
+ }
+ }
+
+ if (entrySchema != null) {
+ keyList.addAll(entrySchema.getKeys());
+ }
+
+ return keyList;
+ }
+
+ @Override
+ public void clean() {
+ key.clean();
+
+ type.clean();
+
+ if (description != null) {
+ description = description.trim();
+ }
+
+ if (defaultValue != null) {
+ defaultValue.clean();
+ }
+
+ if (constraints != null) {
+ for (ToscaConstraint constraint : constraints) {
+ constraint.clean();
+ }
+ }
+
+ if (entrySchema != null) {
+ entrySchema.clean();
+ }
+ }
+
+ @Override
+ public PfValidationResult validate(final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ if (key.isNullKey()) {
+ result.addValidationMessage(
+ new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
+ }
+
+ result = key.validate(result);
+
+ if (type == null || type.isNullKey()) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "property type may not be null"));
+ }
+
+ return validateFields(result);
+ }
+
+ /**
+ * Validate the property fields.
+ *
+ * @param resultIn the incoming validation results so far
+ * @return the validation results including this validation
+ */
+ private PfValidationResult validateFields(final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ if (description != null && description.trim().length() == 0) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "property description may not be blank"));
+ }
+
+ if (defaultValue != null && defaultValue.isNullKey()) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "property default value may not be null"));
+ }
+
+ if (constraints != null) {
+ for (ToscaConstraint constraint : constraints) {
+ if (constraint == null) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "property constraint may not be null "));
+ } else {
+ result = constraint.validate(result);
+ }
+ }
+ }
+ return (entrySchema != null ? entrySchema.validate(result) : result);
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+ if (this == otherConcept) {
+ return 0;
+ }
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final ToscaProperty other = (ToscaProperty) otherConcept;
+ if (!key.equals(other.key)) {
+ return key.compareTo(other.key);
+ }
+
+ return compareFields(other);
+ }
+
+ /**
+ * Compare the fields of this ToscaProperty object with the fields of the other ToscaProperty
+ * object.
+ *
+ * @param other the other ToscaProperty object
+ */
+ private int compareFields(final ToscaProperty other) {
+ if (!type.equals(other.type)) {
+ return type.compareTo(other.type);
+ }
+
+ int result = ObjectUtils.compare(description, other.description);
+ if (result != 0) {
+ return result;
+ }
+
+ result = ObjectUtils.compare(required, other.required);
+ if (result != 0) {
+ return result;
+ }
+
+ result = ObjectUtils.compare(defaultValue, other.defaultValue);
+ if (result != 0) {
+ return result;
+ }
+
+ result = ObjectUtils.compare(status, other.status);
+ if (result != 0) {
+ return result;
+ }
+
+ result = PfUtils.compareObjects(constraints, other.constraints);
+ if (result != 0) {
+ return result;
+ }
+
+ return entrySchema.compareTo(other.entrySchema);
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull final PfConcept target) {
+ Assertions.instanceOf(target, ToscaProperty.class);
+
+ final ToscaProperty copy = ((ToscaProperty) target);
+ copy.setKey(new PfReferenceKey(key));
+ copy.setType(new PfConceptKey(type));
+ copy.setDescription(description);
+ copy.setRequired(required);
+ copy.setDefaultValue(defaultValue);
+ copy.setStatus(status);
+ copy.constraints = constraints; // Constraints are immutable
+ copy.setEntrySchema(entrySchema != null ? new ToscaEntrySchema(entrySchema) : null);
+
+ return copy;
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplate.java
new file mode 100644
index 000000000..acf231a3e
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplate.java
@@ -0,0 +1,222 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.util.List;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+
+import org.apache.commons.lang3.ObjectUtils;
+import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfValidationMessage;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+
+/**
+ * This class holds a full TOSCA service template. Note: Only the policy specific parts of the TOSCA
+ * service template are implemented.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Entity
+@Table(name = "ToscaServiceTemplate")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ToscaServiceTemplate extends ToscaEntityType {
+ private static final long serialVersionUID = 8084846046148349401L;
+
+ @Column
+ @SerializedName("tosca_definitions_version")
+ private String toscaDefinitionsVersion;
+
+ @OneToOne(cascade = CascadeType.ALL)
+ @SerializedName("data_types")
+ private ToscaDataTypes dataTypes;
+
+ @OneToOne(cascade = CascadeType.ALL)
+ @SerializedName("policy_types")
+ private ToscaPolicyTypes policyTypes;
+
+ @SerializedName("topology_template")
+ private ToscaTopologyTemplate topologyTemplate;
+
+
+ /**
+ * The Default Constructor creates a {@link ToscaServiceTemplate} object with a null key.
+ */
+ public ToscaServiceTemplate() {
+ this(new PfConceptKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaServiceTemplate} object with the given concept key.
+ *
+ * @param key the key
+ */
+ public ToscaServiceTemplate(@NonNull final PfConceptKey key) {
+ this(key, "");
+ }
+
+ /**
+ * The full constructor creates a {@link ToscaServiceTemplate} object with all mandatory
+ * parameters.
+ *
+ * @param key the key
+ * @param toscaDefinitionsVersion the TOSCA version string
+ */
+ public ToscaServiceTemplate(@NonNull final PfConceptKey key, @NonNull final String toscaDefinitionsVersion) {
+ super(key);
+ this.toscaDefinitionsVersion = toscaDefinitionsVersion;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaServiceTemplate(final ToscaServiceTemplate copyConcept) {
+ super(copyConcept);
+ }
+
+ @Override
+ public List<PfKey> getKeys() {
+ final List<PfKey> keyList = super.getKeys();
+
+ if (dataTypes != null) {
+ keyList.addAll(dataTypes.getKeys());
+ }
+
+ if (policyTypes != null) {
+ keyList.addAll(policyTypes.getKeys());
+ }
+
+ if (topologyTemplate != null) {
+ keyList.addAll(topologyTemplate.getKeys());
+ }
+
+ return keyList;
+ }
+
+ @Override
+ public void clean() {
+ toscaDefinitionsVersion = toscaDefinitionsVersion.trim();
+
+ if (dataTypes != null) {
+ dataTypes.clean();
+ }
+
+ if (policyTypes != null) {
+ policyTypes.clean();
+ }
+
+ if (topologyTemplate != null) {
+ topologyTemplate.clean();
+ }
+ }
+
+ @Override
+ public PfValidationResult validate(final PfValidationResult resultIn) {
+ PfValidationResult result = super.validate(resultIn);
+
+ if (!ParameterValidationUtils.validateStringParameter(toscaDefinitionsVersion)) {
+ result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
+ "service template tosca definitions version may not be null"));
+ }
+
+ if (dataTypes != null) {
+ result = dataTypes.validate(result);
+ }
+
+ if (policyTypes != null) {
+ result = policyTypes.validate(result);
+ }
+
+ return (topologyTemplate != null ? topologyTemplate.validate(result) : result);
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+ if (this == otherConcept) {
+ return 0;
+ }
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final ToscaServiceTemplate other = (ToscaServiceTemplate) otherConcept;
+ if (!super.equals(other)) {
+ return super.compareTo(other);
+ }
+
+ int result = ObjectUtils.compare(toscaDefinitionsVersion, other.toscaDefinitionsVersion);
+ if (result != 0) {
+ return result;
+ }
+
+ result = ObjectUtils.compare(dataTypes, other.dataTypes);
+ if (result != 0) {
+ return result;
+ }
+
+ result = ObjectUtils.compare(policyTypes, other.policyTypes);
+ if (result != 0) {
+ return result;
+ }
+
+ return ObjectUtils.compare(topologyTemplate, other.topologyTemplate);
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull PfConcept target) {
+ final Object copyObject = target;
+ Assertions.instanceOf(copyObject, PfConcept.class);
+
+ final ToscaServiceTemplate copy = ((ToscaServiceTemplate) copyObject);
+ super.copyTo(target);
+ copy.setToscaDefinitionsVersion(toscaDefinitionsVersion);
+
+ copy.setDataTypes(dataTypes != null ? new ToscaDataTypes(dataTypes) : null);
+ copy.setPolicyTypes(policyTypes != null ? new ToscaPolicyTypes(policyTypes) : null);
+ copy.setTopologyTemplate(topologyTemplate != null ? new ToscaTopologyTemplate(topologyTemplate) : null);
+
+ return copy;
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplates.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplates.java
new file mode 100644
index 000000000..bd1620747
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplates.java
@@ -0,0 +1,86 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+import org.onap.policy.models.base.PfConceptContainer;
+import org.onap.policy.models.base.PfConceptKey;
+
+/**
+ * This class is a container for TOSCA service templates.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Entity
+@Table(name = "ToscaServiceTemplates")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = true)
+public class ToscaServiceTemplates extends PfConceptContainer<ToscaServiceTemplate> {
+ private static final long serialVersionUID = -3053257884307604114L;
+
+ /**
+ * The Default Constructor creates a {@link ToscaServiceTemplates} object with a null artifact
+ * key and creates an empty concept map.
+ */
+ public ToscaServiceTemplates() {
+ super(new PfConceptKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaServiceTemplates} object with the given artifact
+ * key and creates an empty concept map.
+ *
+ * @param key the concept key
+ */
+ public ToscaServiceTemplates(final PfConceptKey key) {
+ super(key, new TreeMap<PfConceptKey, ToscaServiceTemplate>());
+ }
+
+ /**
+ * This Constructor creates an concept container with all of its fields defined.
+ *
+ * @param key the concept container key
+ * @param conceptMap the concepts to be stored in the concept container
+ */
+ public ToscaServiceTemplates(final PfConceptKey key, final Map<PfConceptKey, ToscaServiceTemplate> conceptMap) {
+ super(key, conceptMap);
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaServiceTemplates(final ToscaServiceTemplates copyConcept) {
+ super(copyConcept);
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTimeInterval.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTimeInterval.java
new file mode 100644
index 000000000..10ee6cc7d
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTimeInterval.java
@@ -0,0 +1,188 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Model
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.models.tosca.concepts;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.util.Date;
+import java.util.List;
+
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+
+import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfUtils;
+import org.onap.policy.models.base.PfValidationMessage;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+
+/**
+ * Class to represent the TimeInterval in TOSCA definition.
+ *
+ * @author Chenfei Gao (cgao@research.att.com)
+ * @author Liam Fallon (liam.fallon@est.tech)
+ *
+ */
+@Entity
+@Table(name = "ToscaTimeInterval")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class ToscaTimeInterval extends PfConcept {
+ private static final long serialVersionUID = 9151467029611969980L;
+
+ @EmbeddedId
+ private PfReferenceKey key;
+
+ @SerializedName("start_time")
+ private Date startTime;
+
+ @SerializedName("end_time")
+ private Date endTime;
+
+ /**
+ * The Default Constructor creates a {@link ToscaTimeInterval} object with a null key.
+ */
+ public ToscaTimeInterval() {
+ this(new PfReferenceKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaTimeInterval} object with the given concept key.
+ *
+ * @param key the key
+ */
+ public ToscaTimeInterval(@NonNull final PfReferenceKey key) {
+ this(key, new Date(0), new Date(0));
+ }
+
+ /**
+ * The full constructor creates a {@link ToscaTimeInterval} object with all fields.
+ *
+ * @param key the key
+ */
+ public ToscaTimeInterval(@NonNull final PfReferenceKey key, @NonNull final Date startTime,
+ @NonNull final Date endTime) {
+ this.key = key;
+ this.startTime = startTime;
+ this.endTime = endTime;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaTimeInterval(final ToscaTimeInterval copyConcept) {
+ super(copyConcept);
+ }
+
+ @Override
+ public List<PfKey> getKeys() {
+ return getKey().getKeys();
+ }
+
+ @Override
+ public void clean() {
+ key.clean();
+ }
+
+ @Override
+ public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ if (key.isNullKey()) {
+ result.addValidationMessage(
+ new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
+ }
+
+ result = key.validate(result);
+
+ if (startTime == null || startTime.getTime() == 0) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "start time on time interval may not be null or zero"));
+ }
+
+ if (endTime == null || endTime.getTime() == 0) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "end time on time interval may not be null or zero"));
+ }
+
+ if (startTime != null && endTime != null && endTime.before(startTime)) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "end time \"" + endTime.toString() + "\" on time interval may not be before start time \""
+ + startTime.toString() + "\""));
+ }
+
+ return result;
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+ if (this == otherConcept) {
+ return 0;
+ }
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final ToscaTimeInterval other = (ToscaTimeInterval) otherConcept;
+ if (!key.equals(other.key)) {
+ return key.compareTo(other.key);
+ }
+
+ int returnVal = PfUtils.compareObjects(startTime, other.startTime);
+ if (returnVal != 0) {
+ return returnVal;
+ }
+
+ return PfUtils.compareObjects(endTime, other.endTime);
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull final PfConcept target) {
+ final Object copyObject = target;
+ Assertions.instanceOf(copyObject, ToscaTimeInterval.class);
+
+ final ToscaTimeInterval copy = ((ToscaTimeInterval) copyObject);
+ copy.setKey(new PfReferenceKey(key));
+ copy.setStartTime(startTime);
+ copy.setEndTime(endTime);
+
+ return copy;
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplate.java
new file mode 100644
index 000000000..e8541f514
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplate.java
@@ -0,0 +1,178 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import java.util.List;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Column;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.OneToOne;
+import javax.persistence.Table;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+
+import org.apache.commons.lang3.ObjectUtils;
+import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfValidationMessage;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+
+/**
+ * This class holds a TOSCA topology template. Note: Only the policy specific parts of the TOSCA
+ * topology template are implemented.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Entity
+@Table(name = "ToscaTopologyTemplate")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class ToscaTopologyTemplate extends PfConcept {
+ private static final long serialVersionUID = 8969698734673232603L;
+
+ @EmbeddedId
+ private PfConceptKey key;
+
+ @Column(name = "description")
+ private String description;
+
+ @OneToOne(cascade = CascadeType.ALL)
+ private ToscaPolicies policies;
+
+ /**
+ * The Default Constructor creates a {@link ToscaTopologyTemplate} object with a null key.
+ */
+ public ToscaTopologyTemplate() {
+ this(new PfConceptKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaTopologyTemplate} object with the given concept
+ * key.
+ *
+ * @param key the key
+ */
+ public ToscaTopologyTemplate(@NonNull final PfConceptKey key) {
+ this.key = key;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaTopologyTemplate(final ToscaTopologyTemplate copyConcept) {
+ super(copyConcept);
+ }
+
+ @Override
+ public List<PfKey> getKeys() {
+ final List<PfKey> keyList = getKey().getKeys();
+
+ if (policies != null) {
+ keyList.addAll(policies.getKeys());
+ }
+
+ return keyList;
+ }
+
+ @Override
+ public void clean() {
+ key.clean();
+
+ description = (description != null ? description.trim() : null);
+
+ if (policies != null) {
+ policies.clean();
+ }
+ }
+
+ @Override
+ public PfValidationResult validate(PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ if (key.isNullKey()) {
+ result.addValidationMessage(
+ new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
+ }
+
+ result = key.validate(result);
+
+ if (description != null && description.trim().length() == 0) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "property description may not be blank"));
+ }
+
+ if (policies != null) {
+ result = policies.validate(result);
+ }
+
+ return result;
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+ if (this == otherConcept) {
+ return 0;
+ }
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final ToscaTopologyTemplate other = (ToscaTopologyTemplate) otherConcept;
+ if (!key.equals(other.key)) {
+ return key.compareTo(other.key);
+ }
+
+ int result = ObjectUtils.compare(description, other.description);
+ if (result != 0) {
+ return result;
+ }
+
+ return ObjectUtils.compare(policies, other.policies);
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull PfConcept target) {
+ final Object copyObject = target;
+ Assertions.instanceOf(copyObject, PfConcept.class);
+
+ final ToscaTopologyTemplate copy = ((ToscaTopologyTemplate) copyObject);
+ copy.setKey(new PfConceptKey(key));
+ copy.setDescription(description);
+ copy.setPolicies(policies != null ? new ToscaPolicies(policies) : null);
+
+ return copy;
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTrigger.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTrigger.java
new file mode 100644
index 000000000..5f3b6392f
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTrigger.java
@@ -0,0 +1,335 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Model
+ * ================================================================================
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications 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.models.tosca.concepts;
+
+import com.google.gson.annotations.SerializedName;
+
+import java.time.Duration;
+import java.util.List;
+
+import javax.persistence.Column;
+import javax.persistence.EmbeddedId;
+import javax.persistence.Entity;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.Table;
+
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+
+import org.apache.commons.lang3.ObjectUtils;
+import org.onap.policy.common.utils.validation.Assertions;
+import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfValidationMessage;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+
+/**
+ * Class to represent the trigger of policy type in TOSCA definition.
+ *
+ * @author Chenfei Gao (cgao@research.att.com)
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Entity
+@Table(name = "ToscaTrigger")
+@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class ToscaTrigger extends PfConcept {
+ private static final long serialVersionUID = -6515211640208986971L;
+
+ @EmbeddedId
+ private PfReferenceKey key;
+
+ @Column
+ private String description;
+
+ @Column
+ @SerializedName("event_type")
+ private String eventType;
+
+ @Column
+ @SerializedName("schedule")
+ private ToscaTimeInterval schedule;
+
+ @Column
+ @SerializedName("target_filter")
+ private ToscaEventFilter targetFilter;
+
+ @Column
+ private ToscaConstraint condition;
+
+ @Column
+ private ToscaConstraint constraint;
+
+ @Column
+ @SerializedName("period")
+ private Duration period;
+
+ @Column
+ private int evaluations = 0;
+
+ @Column
+ private String method;
+
+ @Column
+ private String action;
+
+ /**
+ * The Default Constructor creates a {@link ToscaTrigger} object with a null key.
+ */
+ public ToscaTrigger() {
+ this(new PfReferenceKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link ToscaTrigger} object with the given concept key.
+ *
+ * @param key the key
+ */
+ public ToscaTrigger(@NonNull final PfReferenceKey key) {
+ this(key, "", "");
+ }
+
+ /**
+ * The full Constructor creates a {@link ToscaTrigger} object with all mandatory objects.
+ *
+ * @param key the key
+ * @param eventType the event type
+ * @param action the trigger action
+ */
+ public ToscaTrigger(@NonNull final PfReferenceKey key, @NonNull final String eventType,
+ @NonNull final String action) {
+ this.key = key;
+ this.eventType = eventType;
+ this.action = action;
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public ToscaTrigger(final ToscaTrigger copyConcept) {
+ super(copyConcept);
+ }
+
+ @Override
+ public List<PfKey> getKeys() {
+ final List<PfKey> keyList = getKey().getKeys();
+ if (schedule != null) {
+ keyList.addAll(schedule.getKeys());
+ }
+ if (targetFilter != null) {
+ keyList.addAll(targetFilter.getKeys());
+ }
+ if (condition != null) {
+ keyList.addAll(condition.getKeys());
+ }
+ if (constraint != null) {
+ keyList.addAll(constraint.getKeys());
+ }
+ return keyList;
+ }
+
+ @Override
+ public void clean() {
+ key.clean();
+
+ description = (description != null ? description.trim() : description);
+ eventType = eventType.trim();
+
+ if (schedule != null) {
+ schedule.clean();
+ }
+ if (targetFilter != null) {
+ targetFilter.clean();
+ }
+ if (condition != null) {
+ condition.clean();
+ }
+ if (constraint != null) {
+ constraint.clean();
+ }
+
+ method = (method != null ? method.trim() : method);
+ action = action.trim();
+ }
+
+ @Override
+ public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ if (key.isNullKey()) {
+ result.addValidationMessage(
+ new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
+ }
+
+ result = key.validate(result);
+
+ if (description != null && description.trim().length() == 0) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "trigger description may not be blank"));
+ }
+
+ if (!ParameterValidationUtils.validateStringParameter(eventType)) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "event type on trigger must be defined"));
+ }
+
+ result = validateOptionalFields(result);
+
+ if (evaluations < 0) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "evaluations on trigger must be zero or a positive integer"));
+ }
+
+ if (method != null && method.trim().length() == 0) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "method on trigger may not be blank"));
+ }
+
+ if (!ParameterValidationUtils.validateStringParameter(action)) {
+ result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
+ "action on trigger must be defined"));
+ }
+
+ return result;
+ }
+
+ /**
+ * Validate optional fields.
+ *
+ * @param resultIn the validation result so far
+ * @return the validation resutls including these fields
+ */
+ private PfValidationResult validateOptionalFields(final PfValidationResult resultIn) {
+ PfValidationResult result = resultIn;
+
+ result = (schedule != null ? schedule.validate(result) : result);
+ result = (targetFilter != null ? targetFilter.validate(result) : result);
+ result = (condition != null ? condition.validate(result) : result);
+ result = (constraint != null ? constraint.validate(result) : result);
+
+ return result;
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (otherConcept == null) {
+ return -1;
+ }
+ if (this == otherConcept) {
+ return 0;
+ }
+ if (getClass() != otherConcept.getClass()) {
+ return this.hashCode() - otherConcept.hashCode();
+ }
+
+ final ToscaTrigger other = (ToscaTrigger) otherConcept;
+ if (!key.equals(other.key)) {
+ return key.compareTo(other.key);
+ }
+
+ return compareFields(other);
+ }
+
+ /**
+ * Compare the fields of this ToscaTrigger object with the fields of the other ToscaProperty
+ * object.
+ *
+ * @param other the other ToscaTrigger object
+ */
+ private int compareFields(final ToscaTrigger other) {
+ int result = ObjectUtils.compare(description, other.description);
+ if (result != 0) {
+ return result;
+ }
+
+ result = ObjectUtils.compare(eventType, other.eventType);
+ if (result != 0) {
+ return result;
+ }
+
+ result = ObjectUtils.compare(schedule, other.schedule);
+ if (result != 0) {
+ return result;
+ }
+
+ result = ObjectUtils.compare(targetFilter, other.targetFilter);
+ if (result != 0) {
+ return result;
+ }
+
+ result = ObjectUtils.compare(condition, other.condition);
+ if (result != 0) {
+ return result;
+ }
+
+ result = ObjectUtils.compare(constraint, other.constraint);
+ if (result != 0) {
+ return result;
+ }
+
+ result = ObjectUtils.compare(period, other.period);
+ if (result != 0) {
+ return result;
+ }
+
+ if (evaluations != other.evaluations) {
+ return evaluations - other.evaluations;
+ }
+
+ result = ObjectUtils.compare(method, other.method);
+ if (result != 0) {
+ return result;
+ }
+
+ return ObjectUtils.compare(action, other.action);
+ }
+
+ @Override
+ public PfConcept copyTo(@NonNull final PfConcept target) {
+ Assertions.instanceOf(target, ToscaTrigger.class);
+
+ final ToscaTrigger copy = ((ToscaTrigger) target);
+ copy.setKey(new PfReferenceKey(key));
+ copy.setDescription(description);
+ copy.setEventType(eventType);
+ copy.setSchedule(schedule != null ? new ToscaTimeInterval(schedule) : null);
+ copy.setTargetFilter(targetFilter != null ? new ToscaEventFilter(targetFilter) : null);
+ copy.setCondition(condition);
+ copy.setConstraint(constraint);
+ copy.setPeriod(period);
+ copy.setEvaluations(evaluations);
+ copy.setMethod(method);
+ copy.setAction(action);
+
+ return copy;
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/TestPojos.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/TestPojos.java
index 28cd4cc92..d5b5f55b3 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/TestPojos.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/TestPojos.java
@@ -20,7 +20,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.policy.models.tosca;
+package org.onap.policy.models.tosca.concepts;
import com.openpojo.reflection.filters.FilterPackageInfo;
import com.openpojo.validation.Validator;
@@ -41,7 +41,7 @@ import org.onap.policy.common.utils.validation.ToStringTester;
*/
public class TestPojos {
- private static final String POJO_PACKAGE = "org.onap.policy.models.tosca";
+ private static final String POJO_PACKAGE = "org.onap.policy.models.tosca.concepts";
@Test
public void testPojos() {
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalKeyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalKeyTest.java
new file mode 100644
index 000000000..60c6eb976
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalKeyTest.java
@@ -0,0 +1,134 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfValidationResult;
+
+/**
+ * DAO test for ToscaConstraintLogicalKey.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaConstraintLogicalKeyTest {
+
+ @Test
+ public void testConstraintLogicalKeyPojo() {
+ assertNotNull(new ToscaConstraintLogicalKey());
+ assertNotNull(new ToscaConstraintLogicalKey(new PfReferenceKey()));
+ assertNotNull(new ToscaConstraintLogicalKey(new PfReferenceKey(), ToscaConstraintLogicalKey.Operation.EQ,
+ new PfConceptKey()));
+
+ try {
+ new ToscaConstraintLogicalKey((PfReferenceKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaConstraintLogicalKey((ToscaConstraintLogicalKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ PfConceptKey tclParentKey = new PfConceptKey("tParentKey", "0.0.1");
+ PfReferenceKey tclKey = new PfReferenceKey(tclParentKey, "trigger0");
+ PfConceptKey constraintKey = new PfConceptKey("tParentKey", "0.0.1");
+ ToscaConstraintLogicalKey tcl =
+ new ToscaConstraintLogicalKey(tclKey, ToscaConstraintLogicalKey.Operation.EQ, constraintKey);
+
+ try {
+ new ToscaConstraintLogicalKey(tcl);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("cannot copy an immutable constraint", exc.getMessage());
+ }
+
+ ToscaConstraintLogicalKey tclClone1 = new ToscaConstraintLogicalKey();
+ try {
+ tcl.copyTo(tclClone1);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("cannot copy an immutable constraint", exc.getMessage());
+ }
+ tclClone1 = new ToscaConstraintLogicalKey(tclKey, ToscaConstraintLogicalKey.Operation.EQ, constraintKey);
+
+ assertEquals(tcl, tclClone1);
+ assertEquals(0, tcl.compareTo(tclClone1));
+
+ assertEquals(-1, tcl.compareTo(null));
+ assertEquals(0, tcl.compareTo(tcl));
+ assertFalse(tcl.compareTo(tcl.getKey()) == 0);
+
+ ToscaConstraintLogicalKey differentTcl = new ToscaConstraintLogicalKey(new PfReferenceKey(),
+ ToscaConstraintLogicalKey.Operation.EQ, constraintKey);
+ assertFalse(tcl.compareTo(differentTcl) == 0);
+
+ ToscaConstraintLogicalKey otherTc =
+ new ToscaConstraintLogicalKey(tclKey, ToscaConstraintLogicalKey.Operation.EQ, constraintKey);
+ assertEquals(0, tcl.compareTo(otherTc));
+
+ try {
+ tcl.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(2, tcl.getKeys().size());
+ assertEquals(2, new ToscaConstraintLogicalKey().getKeys().size());
+
+ new ToscaConstraintLogicalKey().clean();
+ tcl.clean();
+ assertEquals(tclClone1, tcl);
+
+ assertFalse(new ToscaConstraintLogicalKey().validate(new PfValidationResult()).isValid());
+ assertTrue(tcl.validate(new PfValidationResult()).isValid());
+
+ try {
+ tcl.validate(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaConstraintLogicalKey(tclKey, ToscaConstraintLogicalKey.Operation.EQ, null)
+ .validate(new PfValidationResult());
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("compareToKey is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertFalse(new ToscaConstraintLogicalKey(tclKey, ToscaConstraintLogicalKey.Operation.EQ, new PfConceptKey())
+ .validate(new PfValidationResult()).isValid());
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalStringTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalStringTest.java
new file mode 100644
index 000000000..5d0fe9332
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalStringTest.java
@@ -0,0 +1,133 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfValidationResult;
+
+/**
+ * DAO test for ToscaConstraintLogicalString.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaConstraintLogicalStringTest {
+
+ @Test
+ public void testConstraintLogicalStringPojo() {
+ assertNotNull(new ToscaConstraintLogicalString());
+ assertNotNull(new ToscaConstraintLogicalString(new PfReferenceKey()));
+ assertNotNull(new ToscaConstraintLogicalString(new PfReferenceKey(), ToscaConstraintLogicalString.Operation.EQ,
+ "Constraint"));
+
+ try {
+ new ToscaConstraintLogicalString((PfReferenceKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaConstraintLogicalString((ToscaConstraintLogicalString) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ PfConceptKey tclParentKey = new PfConceptKey("tParentKey", "0.0.1");
+ PfReferenceKey tclKey = new PfReferenceKey(tclParentKey, "trigger0");
+ ToscaConstraintLogicalString tcl =
+ new ToscaConstraintLogicalString(tclKey, ToscaConstraintLogicalString.Operation.EQ, "Constraint");
+
+ try {
+ new ToscaConstraintLogicalString(tcl);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("cannot copy an immutable constraint", exc.getMessage());
+ }
+
+ ToscaConstraintLogicalString tclClone1 = new ToscaConstraintLogicalString();
+ try {
+ tcl.copyTo(tclClone1);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("cannot copy an immutable constraint", exc.getMessage());
+ }
+ tclClone1 = new ToscaConstraintLogicalString(tclKey, ToscaConstraintLogicalString.Operation.EQ, "Constraint");
+
+ assertEquals(tcl, tclClone1);
+ assertEquals(0, tcl.compareTo(tclClone1));
+
+ assertEquals(-1, tcl.compareTo(null));
+ assertEquals(0, tcl.compareTo(tcl));
+ assertFalse(tcl.compareTo(tcl.getKey()) == 0);
+
+ ToscaConstraintLogicalString differentTcl = new ToscaConstraintLogicalString(new PfReferenceKey(),
+ ToscaConstraintLogicalString.Operation.EQ, "Constraint");
+ assertFalse(tcl.compareTo(differentTcl) == 0);
+
+ ToscaConstraintLogicalString otherTc =
+ new ToscaConstraintLogicalString(tclKey, ToscaConstraintLogicalString.Operation.EQ, "Constraint");
+ assertEquals(0, tcl.compareTo(otherTc));
+
+ try {
+ tcl.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(1, tcl.getKeys().size());
+ assertEquals(1, new ToscaConstraintLogicalString().getKeys().size());
+
+ new ToscaConstraintLogicalString().clean();
+ tcl.clean();
+ assertEquals(tclClone1, tcl);
+
+ assertFalse(new ToscaConstraintLogicalString().validate(new PfValidationResult()).isValid());
+ assertTrue(tcl.validate(new PfValidationResult()).isValid());
+
+ try {
+ tcl.validate(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaConstraintLogicalString(tclKey, ToscaConstraintLogicalString.Operation.EQ, null)
+ .validate(new PfValidationResult());
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("compareToString is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertFalse(new ToscaConstraintLogicalString(tclKey, ToscaConstraintLogicalString.Operation.EQ, "")
+ .validate(new PfValidationResult()).isValid());
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalTest.java
new file mode 100644
index 000000000..fc623f1dd
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalTest.java
@@ -0,0 +1,166 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.concepts.testconcepts.DummyToscaConstraint;
+
+/**
+ * DAO test for ToscaConstraintLogical.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaConstraintLogicalTest {
+
+ @Test
+ public void testConstraintLogicalPojo() {
+ assertNotNull(new ToscaConstraintLogical());
+ assertNotNull(new ToscaConstraintLogical(new PfReferenceKey()));
+
+ try {
+ new ToscaConstraintLogical((PfReferenceKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaConstraintLogical((ToscaConstraintLogical) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ PfConceptKey tclParentKey = new PfConceptKey("tParentKey", "0.0.1");
+ PfReferenceKey tclKey = new PfReferenceKey(tclParentKey, "trigger0");
+ ToscaConstraintLogical tcl = new ToscaConstraintLogical(tclKey, ToscaConstraintLogical.Operation.EQ);
+
+ try {
+ new ToscaConstraintLogical(tcl);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("cannot copy an immutable constraint", exc.getMessage());
+ }
+
+ ToscaConstraintLogical tclClone1 = new ToscaConstraintLogical();
+ try {
+ tcl.copyTo(tclClone1);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("cannot copy an immutable constraint", exc.getMessage());
+ }
+ tclClone1 = new ToscaConstraintLogical(tclKey, ToscaConstraintLogical.Operation.EQ);
+
+ assertEquals(tcl, tclClone1);
+ assertEquals(0, tcl.compareTo(tclClone1));
+
+ assertEquals(-1, tcl.compareTo(null));
+ assertEquals(0, tcl.compareTo(tcl));
+ assertFalse(tcl.compareTo(tcl.getKey()) == 0);
+
+ ToscaConstraintLogical differentTcl =
+ new ToscaConstraintLogical(new PfReferenceKey(), ToscaConstraintLogical.Operation.EQ);
+ assertFalse(tcl.compareTo(differentTcl) == 0);
+
+ ToscaConstraintLogical otherTc = new ToscaConstraintLogical(tclKey, ToscaConstraintLogical.Operation.EQ);
+ assertEquals(0, tcl.compareTo(otherTc));
+
+ try {
+ tcl.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(1, tcl.getKeys().size());
+ assertEquals(1, new ToscaConstraintLogical().getKeys().size());
+
+ ToscaConstraintLogical tclClone0 = new ToscaConstraintLogical();
+ new ToscaConstraintLogical().clean();
+ tcl.clean();
+ assertEquals(tclClone0, tcl);
+
+ assertFalse(new ToscaConstraintLogical().validate(new PfValidationResult()).isValid());
+ assertTrue(tcl.validate(new PfValidationResult()).isValid());
+
+ try {
+ tcl.validate(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
+ }
+
+ DummyToscaConstraint dtc = new DummyToscaConstraint();
+ try {
+ new DummyToscaConstraint(dtc);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("cannot copy an immutable constraint", exc.getMessage());
+ }
+
+ try {
+ new DummyToscaConstraint((PfReferenceKey)null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new DummyToscaConstraint((DummyToscaConstraint)null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ DummyToscaConstraint dtcClone = new DummyToscaConstraint();
+
+ assertEquals(dtc, dtcClone);
+ assertEquals(dtc, dtc);
+ assertEquals(0, dtc.compareTo(dtcClone));
+ assertEquals(0, dtc.compareTo(dtc));
+ assertEquals(-1, dtc.compareTo(null));
+ assertEquals(0, dtc.compareTo(dtcClone));
+ assertFalse(dtc.compareTo(dtcClone.getKey()) == 0);
+
+ try {
+ dtc.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ dtc.copyTo(dtcClone);
+ fail("target should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("cannot copy an immutable constraint", exc.getMessage());
+ }
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaDataTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaDataTypeTest.java
new file mode 100644
index 000000000..d0b9c7d9b
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaDataTypeTest.java
@@ -0,0 +1,140 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.concepts.ToscaConstraintLogical.Operation;
+
+/**
+ * DAO test for ToscaDatatype.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaDataTypeTest {
+
+ @Test
+ public void testDataTypePojo() {
+ assertNotNull(new ToscaDataType());
+ assertNotNull(new ToscaDataType(new PfConceptKey()));
+ assertNotNull(new ToscaDataType(new ToscaDataType()));
+
+ try {
+ new ToscaDataType((PfConceptKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaDataType((ToscaDataType) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ PfConceptKey dtKey = new PfConceptKey("tdt", "0.0.1");
+ ToscaDataType tdt = new ToscaDataType(dtKey);
+
+ List<ToscaConstraint> constraints = new ArrayList<>();
+ ToscaConstraintLogicalString lsc =
+ new ToscaConstraintLogicalString(new PfReferenceKey(dtKey, "sc"), Operation.EQ, "hello");
+ constraints.add(lsc);
+ tdt.setConstraints(constraints);
+ assertEquals(constraints, tdt.getConstraints());
+
+ List<ToscaProperty> properties = new ArrayList<>();
+ ToscaProperty tp = new ToscaProperty(new PfReferenceKey(dtKey, "pr"), new PfConceptKey("type", "0.0.1"));
+ properties.add(tp);
+ tdt.setProperties(properties);
+ assertEquals(properties, tdt.getProperties());
+
+ ToscaDataType tdtClone0 = new ToscaDataType(tdt);
+ assertEquals(tdt, tdtClone0);
+ assertEquals(0, tdt.compareTo(tdtClone0));
+
+ ToscaDataType tdtClone1 = new ToscaDataType();
+ tdt.copyTo(tdtClone1);
+ assertEquals(tdt, tdtClone1);
+ assertEquals(0, tdt.compareTo(tdtClone1));
+
+ assertEquals(-1, tdt.compareTo(null));
+ assertEquals(0, tdt.compareTo(tdt));
+ assertFalse(tdt.compareTo(tdt.getKey()) == 0);
+
+ PfConceptKey otherDtKey = new PfConceptKey("otherDt", "0.0.1");
+ ToscaDataType otherDt = new ToscaDataType(otherDtKey);
+
+ assertFalse(tdt.compareTo(otherDt) == 0);
+ otherDt.setKey(dtKey);
+ assertFalse(tdt.compareTo(otherDt) == 0);
+ otherDt.setConstraints(constraints);
+ assertFalse(tdt.compareTo(otherDt) == 0);
+ otherDt.setProperties(properties);
+ assertEquals(0, tdt.compareTo(otherDt));
+
+ try {
+ tdt.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(4, tdt.getKeys().size());
+ assertEquals(1, new ToscaDataType().getKeys().size());
+
+ new ToscaDataType().clean();
+ tdt.clean();
+ assertEquals(tdtClone0, tdt);
+
+ assertFalse(new ToscaDataType().validate(new PfValidationResult()).isValid());
+ assertTrue(tdt.validate(new PfValidationResult()).isValid());
+
+ tdt.getConstraints().add(null);
+ assertFalse(tdt.validate(new PfValidationResult()).isValid());
+ tdt.getConstraints().remove(null);
+ assertTrue(tdt.validate(new PfValidationResult()).isValid());
+
+ tdt.getProperties().add(null);
+ assertFalse(tdt.validate(new PfValidationResult()).isValid());
+ tdt.getProperties().remove(null);
+ assertTrue(tdt.validate(new PfValidationResult()).isValid());
+
+ try {
+ tdt.validate(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
+ }
+
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaDataTypesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaDataTypesTest.java
new file mode 100644
index 000000000..cd9c53e7c
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaDataTypesTest.java
@@ -0,0 +1,76 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.util.TreeMap;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+
+public class ToscaDataTypesTest {
+
+ @Test
+ public void testDataTypes() {
+ assertNotNull(new ToscaDataTypes());
+ assertNotNull(new ToscaDataTypes(new PfConceptKey()));
+ assertNotNull(new ToscaDataTypes(new PfConceptKey(), new TreeMap<PfConceptKey, ToscaDataType>()));
+ assertNotNull(new ToscaDataTypes(new ToscaDataTypes()));
+
+ try {
+ new ToscaDataTypes((PfConceptKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaDataTypes((ToscaDataTypes) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaDataTypes(null, null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaDataTypes(new PfConceptKey(), null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("conceptMap is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaDataTypes(null, new TreeMap<PfConceptKey, ToscaDataType>());
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaEntrySchemaTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaEntrySchemaTest.java
new file mode 100644
index 000000000..97d71a203
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaEntrySchemaTest.java
@@ -0,0 +1,147 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.concepts.ToscaConstraintLogical.Operation;
+
+/**
+ * DAO test for ToscaEntrySchema.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaEntrySchemaTest {
+
+ @Test
+ public void testEntrySchemaPojo() {
+ assertNotNull(new ToscaEntrySchema());
+ assertNotNull(new ToscaEntrySchema(new PfReferenceKey()));
+ assertNotNull(new ToscaEntrySchema(new PfReferenceKey(), new PfConceptKey()));
+ assertNotNull(new ToscaEntrySchema(new ToscaEntrySchema()));
+
+ try {
+ new ToscaEntrySchema((PfReferenceKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaEntrySchema((ToscaEntrySchema) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ PfReferenceKey esKey = new PfReferenceKey("entrySchemaParent", "0.0.1", "entrySchema");
+ PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
+ ToscaEntrySchema tes = new ToscaEntrySchema(esKey, typeKey);
+
+ tes.setDescription("A Description");
+ assertEquals("A Description", tes.getDescription());
+
+ List<ToscaConstraint> constraints = new ArrayList<>();
+ ToscaConstraintLogicalString lsc =
+ new ToscaConstraintLogicalString(new PfReferenceKey(esKey, "sc"), Operation.EQ, "hello");
+ constraints.add(lsc);
+ tes.setConstraints(constraints);
+ assertEquals(constraints, tes.getConstraints());
+
+ ToscaEntrySchema tdtClone0 = new ToscaEntrySchema(tes);
+ assertEquals(tes, tdtClone0);
+ assertEquals(0, tes.compareTo(tdtClone0));
+
+ ToscaEntrySchema tdtClone1 = new ToscaEntrySchema();
+ tes.copyTo(tdtClone1);
+ assertEquals(tes, tdtClone1);
+ assertEquals(0, tes.compareTo(tdtClone1));
+
+ assertEquals(-1, tes.compareTo(null));
+ assertEquals(0, tes.compareTo(tes));
+ assertFalse(tes.compareTo(tes.getKey()) == 0);
+
+ PfReferenceKey otherEsKey = new PfReferenceKey("entrySchemaParent", "0.0.1", "otherEntrySchema");
+ ToscaEntrySchema otherEs = new ToscaEntrySchema(otherEsKey);
+
+ assertFalse(tes.compareTo(otherEs) == 0);
+ otherEs.setKey(esKey);
+ assertFalse(tes.compareTo(otherEs) == 0);
+ otherEs.setType(typeKey);
+ assertFalse(tes.compareTo(otherEs) == 0);
+ otherEs.setDescription("A Description");
+ assertFalse(tes.compareTo(otherEs) == 0);
+ otherEs.setConstraints(constraints);
+ assertEquals(0, tes.compareTo(otherEs));
+
+ try {
+ tes.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(3, tes.getKeys().size());
+ assertEquals(2, new ToscaEntrySchema().getKeys().size());
+
+ new ToscaEntrySchema().clean();
+ tes.clean();
+ assertEquals(tdtClone0, tes);
+
+ assertFalse(new ToscaEntrySchema().validate(new PfValidationResult()).isValid());
+ assertTrue(tes.validate(new PfValidationResult()).isValid());
+
+ tes.setType(PfConceptKey.getNullKey());
+ assertFalse(tes.validate(new PfValidationResult()).isValid());
+ tes.setType(null);
+ assertFalse(tes.validate(new PfValidationResult()).isValid());
+ tes.setType(typeKey);
+ assertTrue(tes.validate(new PfValidationResult()).isValid());
+
+ tes.setDescription("");;
+ assertFalse(tes.validate(new PfValidationResult()).isValid());
+ tes.setDescription("A Description");
+ assertTrue(tes.validate(new PfValidationResult()).isValid());
+
+ tes.getConstraints().add(null);
+ assertFalse(tes.validate(new PfValidationResult()).isValid());
+ tes.getConstraints().remove(null);
+ assertTrue(tes.validate(new PfValidationResult()).isValid());
+
+ try {
+ tes.validate(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
+ }
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaEventFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaEventFilterTest.java
new file mode 100644
index 000000000..a45d65d69
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaEventFilterTest.java
@@ -0,0 +1,165 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfValidationResult;
+
+/**
+ * DAO test for ToscaEventFilter.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaEventFilterTest {
+
+ @Test
+ public void testEventFilterPojo() {
+ assertNotNull(new ToscaEventFilter());
+ assertNotNull(new ToscaEventFilter(new PfReferenceKey()));
+ assertNotNull(new ToscaEventFilter(new PfReferenceKey(), new PfConceptKey()));
+ assertNotNull(new ToscaEventFilter(new ToscaEventFilter()));
+
+ try {
+ new ToscaEventFilter((PfReferenceKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaEventFilter(null, null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaEventFilter(null, new PfConceptKey());
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaEventFilter(new PfReferenceKey(), null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("node is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaEventFilter((ToscaEventFilter) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ PfConceptKey efParentKey = new PfConceptKey("tParentKey", "0.0.1");
+ PfReferenceKey efKey = new PfReferenceKey(efParentKey, "trigger0");
+ PfConceptKey nodeKey = new PfConceptKey("tParentKey", "0.0.1");
+ ToscaEventFilter tef = new ToscaEventFilter(efKey, nodeKey);
+
+ tef.setRequirement("A Requrement");
+ assertEquals("A Requrement", tef.getRequirement());
+
+ tef.setCapability("A Capability");
+ assertEquals("A Capability", tef.getCapability());
+
+ ToscaEventFilter tdtClone0 = new ToscaEventFilter(tef);
+ assertEquals(tef, tdtClone0);
+ assertEquals(0, tef.compareTo(tdtClone0));
+
+ ToscaEventFilter tdtClone1 = new ToscaEventFilter();
+ tef.copyTo(tdtClone1);
+ assertEquals(tef, tdtClone1);
+ assertEquals(0, tef.compareTo(tdtClone1));
+
+ assertEquals(-1, tef.compareTo(null));
+ assertEquals(0, tef.compareTo(tef));
+ assertFalse(tef.compareTo(tef.getKey()) == 0);
+
+ PfReferenceKey otherDtKey = new PfReferenceKey("otherDt", "0.0.1", "OtherEventFilter");
+ ToscaEventFilter otherDt = new ToscaEventFilter(otherDtKey);
+
+ assertFalse(tef.compareTo(otherDt) == 0);
+ otherDt.setKey(efKey);
+ assertFalse(tef.compareTo(otherDt) == 0);
+ otherDt.setNode(nodeKey);
+ assertFalse(tef.compareTo(otherDt) == 0);
+ otherDt.setRequirement("A Requrement");
+ assertFalse(tef.compareTo(otherDt) == 0);
+ otherDt.setCapability("A Capability");
+ assertEquals(0, tef.compareTo(otherDt));
+
+ try {
+ tef.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(2, tef.getKeys().size());
+ assertEquals(2, new ToscaEventFilter().getKeys().size());
+
+ new ToscaEventFilter().clean();
+ tef.clean();
+ assertEquals(tdtClone0, tef);
+
+ assertFalse(new ToscaEventFilter().validate(new PfValidationResult()).isValid());
+ assertTrue(tef.validate(new PfValidationResult()).isValid());
+
+ tef.setRequirement(null);
+ assertTrue(tef.validate(new PfValidationResult()).isValid());
+ tef.setRequirement("");
+ assertFalse(tef.validate(new PfValidationResult()).isValid());
+ tef.setRequirement("A Requrement");
+ assertTrue(tef.validate(new PfValidationResult()).isValid());
+
+ tef.setCapability(null);
+ assertTrue(tef.validate(new PfValidationResult()).isValid());
+ tef.setCapability("");
+ assertFalse(tef.validate(new PfValidationResult()).isValid());
+ tef.setCapability("A Capability");
+ assertTrue(tef.validate(new PfValidationResult()).isValid());
+
+ tef.setNode(null);
+ assertFalse(tef.validate(new PfValidationResult()).isValid());
+ tef.setNode(PfConceptKey.getNullKey());
+ assertFalse(tef.validate(new PfValidationResult()).isValid());
+ tef.setNode(nodeKey);
+ assertTrue(tef.validate(new PfValidationResult()).isValid());
+
+ try {
+ tef.validate(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
+ }
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaModelTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaModelTest.java
new file mode 100644
index 000000000..ca6445f13
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaModelTest.java
@@ -0,0 +1,142 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfModelService;
+import org.onap.policy.models.base.PfValidationResult;
+
+/**
+ * DAO test for ToscaDatatype.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaModelTest {
+
+ @Test
+ public void testModelPojo() {
+ assertNotNull(new ToscaModel());
+ assertNotNull(new ToscaModel(new PfConceptKey()));
+ assertNotNull(new ToscaModel(new PfConceptKey(), new ToscaServiceTemplates()));
+ assertNotNull(new ToscaModel(new ToscaModel()));
+
+ try {
+ new ToscaModel((PfConceptKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaModel(null, null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaModel(null, new ToscaServiceTemplates());
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaModel(new PfConceptKey(), null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("serviceTemplates is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaModel((ToscaModel) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ PfConceptKey tstsKey = new PfConceptKey("tsts", "0.0.1");
+ Map<PfConceptKey, ToscaServiceTemplate> tstMap = new TreeMap<>();
+ ToscaServiceTemplates tsts = new ToscaServiceTemplates(tstsKey, tstMap);
+ PfConceptKey tmKey = new PfConceptKey("tst", "0.0.1");
+ ToscaModel tm = new ToscaModel(tmKey, tsts);
+
+ ToscaModel tttClone0 = new ToscaModel(tm);
+ assertEquals(tm, tttClone0);
+ assertEquals(0, tm.compareTo(tttClone0));
+
+ ToscaModel tttClone1 = new ToscaModel();
+ tm.copyTo(tttClone1);
+ assertEquals(tm, tttClone1);
+ assertEquals(0, tm.compareTo(tttClone1));
+
+ assertEquals(-1, tm.compareTo(null));
+ assertEquals(0, tm.compareTo(tm));
+ assertFalse(tm.compareTo(tm.getKey()) == 0);
+
+ PfConceptKey otherDtKey = new PfConceptKey("otherDt", "0.0.1");
+ ToscaModel otherDt = new ToscaModel(otherDtKey);
+
+ assertFalse(tm.compareTo(otherDt) == 0);
+ otherDt.setKey(tmKey);
+ assertFalse(tm.compareTo(otherDt) == 0);
+ otherDt.setServiceTemplates(tsts);
+ assertEquals(0, tm.compareTo(otherDt));
+
+ try {
+ tm.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("targetObject is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(2, tm.getKeys().size());
+ assertEquals(2, new ToscaModel().getKeys().size());
+
+ new ToscaModel().clean();
+ tm.clean();
+ assertEquals(tttClone0, tm);
+
+ assertFalse(new ToscaModel().validate(new PfValidationResult()).isValid());
+ assertFalse(tm.validate(new PfValidationResult()).isValid());
+
+ tm.register();
+ assertTrue(PfModelService.existsModel(tm.getServiceTemplates().getId()));
+ PfModelService.deregisterModel(tm.getServiceTemplates().getId());
+
+ try {
+ tm.validate(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
+ }
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPoliciesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPoliciesTest.java
new file mode 100644
index 000000000..76fdd538b
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPoliciesTest.java
@@ -0,0 +1,76 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.util.TreeMap;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+
+public class ToscaPoliciesTest {
+
+ @Test
+ public void testPolicies() {
+ assertNotNull(new ToscaPolicies());
+ assertNotNull(new ToscaPolicies(new PfConceptKey()));
+ assertNotNull(new ToscaPolicies(new PfConceptKey(), new TreeMap<PfConceptKey, ToscaPolicy>()));
+ assertNotNull(new ToscaPolicies(new ToscaPolicies()));
+
+ try {
+ new ToscaPolicies((PfConceptKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaPolicies((ToscaPolicies) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaPolicies(null, null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaPolicies(new PfConceptKey(), null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("conceptMap is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaPolicies(null, new TreeMap<PfConceptKey, ToscaPolicy>());
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTest.java
new file mode 100644
index 000000000..295c0f2fd
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTest.java
@@ -0,0 +1,162 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfValidationResult;
+
+/**
+ * DAO test for ToscaDatatype.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaPolicyTest {
+
+ @Test
+ public void testPolicyPojo() {
+ assertNotNull(new ToscaPolicy());
+ assertNotNull(new ToscaPolicy(new PfConceptKey()));
+ assertNotNull(new ToscaPolicy(new PfConceptKey(), new PfConceptKey()));
+ assertNotNull(new ToscaPolicy(new ToscaPolicy()));
+
+ try {
+ new ToscaPolicy((PfConceptKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaPolicy(null, null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaPolicy(new PfConceptKey(), null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("type is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaPolicy(null, new PfConceptKey());
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaPolicy((ToscaPolicy) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ PfConceptKey tpKey = new PfConceptKey("tdt", "0.0.1");
+ PfConceptKey ptKey = new PfConceptKey("policyType", "0.0.1");
+ ToscaPolicy tp = new ToscaPolicy(tpKey, ptKey);
+
+ List<ToscaProperty> properties = new ArrayList<>();
+ ToscaProperty property = new ToscaProperty(new PfReferenceKey(tpKey, "pr"), new PfConceptKey("type", "0.0.1"));
+ properties.add(property);
+ tp.setProperties(properties);
+ assertEquals(properties, tp.getProperties());
+
+ List<PfConceptKey> targets = new ArrayList<>();
+ PfConceptKey target = new PfConceptKey("target", "0.0.1");
+ targets.add(target);
+ tp.setTargets(targets);
+ assertEquals(targets, tp.getTargets());
+
+ ToscaPolicy tdtClone0 = new ToscaPolicy(tp);
+ assertEquals(tp, tdtClone0);
+ assertEquals(0, tp.compareTo(tdtClone0));
+
+ ToscaPolicy tdtClone1 = new ToscaPolicy();
+ tp.copyTo(tdtClone1);
+ assertEquals(tp, tdtClone1);
+ assertEquals(0, tp.compareTo(tdtClone1));
+
+ assertEquals(-1, tp.compareTo(null));
+ assertEquals(0, tp.compareTo(tp));
+ assertFalse(tp.compareTo(tp.getKey()) == 0);
+
+ PfConceptKey otherDtKey = new PfConceptKey("otherDt", "0.0.1");
+ ToscaPolicy otherDt = new ToscaPolicy(otherDtKey);
+
+ assertFalse(tp.compareTo(otherDt) == 0);
+ otherDt.setKey(tpKey);
+ assertFalse(tp.compareTo(otherDt) == 0);
+ otherDt.setType(ptKey);
+ assertFalse(tp.compareTo(otherDt) == 0);
+ otherDt.setProperties(properties);
+ assertFalse(tp.compareTo(otherDt) == 0);
+ otherDt.setTargets(targets);
+ assertEquals(0, tp.compareTo(otherDt));
+
+ try {
+ tp.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(5, tp.getKeys().size());
+ assertEquals(2, new ToscaPolicy().getKeys().size());
+
+ new ToscaPolicy().clean();
+ tp.clean();
+ assertEquals(tdtClone0, tp);
+
+ assertFalse(new ToscaPolicy().validate(new PfValidationResult()).isValid());
+ assertTrue(tp.validate(new PfValidationResult()).isValid());
+
+ tp.getProperties().add(null);
+ assertFalse(tp.validate(new PfValidationResult()).isValid());
+ tp.getProperties().remove(null);
+ assertTrue(tp.validate(new PfValidationResult()).isValid());
+
+ tp.getTargets().add(null);
+ assertFalse(tp.validate(new PfValidationResult()).isValid());
+ tp.getTargets().remove(null);
+ assertTrue(tp.validate(new PfValidationResult()).isValid());
+
+ try {
+ tp.validate(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
+ }
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypeTest.java
new file mode 100644
index 000000000..7926bfe78
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypeTest.java
@@ -0,0 +1,208 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfValidationResult;
+
+/**
+ * DAO test for ToscaPolicyType.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaPolicyTypeTest {
+
+ @Test
+ public void testPolicyTypePojo() {
+ assertNotNull(new ToscaPolicyType());
+ assertNotNull(new ToscaPolicyType(new PfConceptKey()));
+ assertNotNull(new ToscaPolicyType(new ToscaPolicyType()));
+
+ try {
+ new ToscaPolicyType((PfConceptKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaPolicyType((ToscaPolicyType) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ PfConceptKey ptKey = new PfConceptKey("tdt", "0.0.1");
+ ToscaPolicyType tpt = new ToscaPolicyType(ptKey);
+
+ PfConceptKey derivedFromKey = new PfConceptKey("deriveFrom", "0.0.1");
+ tpt.setDerivedFrom(derivedFromKey);
+
+ Map<String, String> metadata = new HashMap<>();
+ metadata.put("key", "value");
+ tpt.setMetadata(metadata);
+ assertEquals(metadata, tpt.getMetadata());
+
+ tpt.setDescription("A Description");
+
+ PfConceptKey propTypeKey = new PfConceptKey("propType", "0.0.1");
+ List<ToscaProperty> properties = new ArrayList<>();
+ ToscaProperty tp = new ToscaProperty(new PfReferenceKey(ptKey, "aProp"), propTypeKey);
+ properties.add(tp);
+ tpt.setProperties(properties);
+ assertEquals(properties, tpt.getProperties());
+
+ List<PfConceptKey> targets = new ArrayList<>();
+ PfConceptKey target = new PfConceptKey("target", "0.0.1");
+ targets.add(target);
+ tpt.setTargets(targets);
+ assertEquals(targets, tpt.getTargets());
+
+ List<ToscaTrigger> triggers = new ArrayList<>();
+ ToscaTrigger trigger = new ToscaTrigger(new PfReferenceKey(ptKey, "aTrigger"), "EventType", "Action");
+ triggers.add(trigger);
+ tpt.setTriggers(triggers);
+ assertEquals(triggers, tpt.getTriggers());
+
+ ToscaPolicyType tdtClone0 = new ToscaPolicyType(tpt);
+ assertEquals(tpt, tdtClone0);
+ assertEquals(0, tpt.compareTo(tdtClone0));
+
+ ToscaPolicyType tdtClone1 = new ToscaPolicyType();
+ tpt.copyTo(tdtClone1);
+ assertEquals(tpt, tdtClone1);
+ assertEquals(0, tpt.compareTo(tdtClone1));
+
+ assertEquals(-1, tpt.compareTo(null));
+ assertEquals(0, tpt.compareTo(tpt));
+ assertFalse(tpt.compareTo(tpt.getKey()) == 0);
+
+ PfConceptKey otherDtKey = new PfConceptKey("otherDt", "0.0.1");
+ ToscaPolicyType otherDt = new ToscaPolicyType(otherDtKey);
+
+ assertFalse(tpt.compareTo(otherDt) == 0);
+ otherDt.setKey(ptKey);
+ assertFalse(tpt.compareTo(otherDt) == 0);
+ otherDt.setDerivedFrom(derivedFromKey);
+ assertFalse(tpt.compareTo(otherDt) == 0);
+ otherDt.setMetadata(metadata);
+ assertFalse(tpt.compareTo(otherDt) == 0);
+ otherDt.setDescription("A Description");
+ assertFalse(tpt.compareTo(otherDt) == 0);
+ otherDt.setProperties(properties);
+ assertFalse(tpt.compareTo(otherDt) == 0);
+ otherDt.setTargets(targets);
+ assertFalse(tpt.compareTo(otherDt) == 0);
+ otherDt.setTriggers(triggers);
+ assertEquals(0, tpt.compareTo(otherDt));
+
+ try {
+ tpt.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(6, tpt.getKeys().size());
+ assertEquals(1, new ToscaPolicyType().getKeys().size());
+
+ new ToscaPolicyType().clean();
+ tpt.clean();
+ assertEquals(tdtClone0, tpt);
+
+ assertFalse(new ToscaPolicyType().validate(new PfValidationResult()).isValid());
+ assertTrue(tpt.validate(new PfValidationResult()).isValid());
+
+ tpt.getProperties().add(null);
+ assertFalse(tpt.validate(new PfValidationResult()).isValid());
+ tpt.getProperties().remove(null);
+ assertTrue(tpt.validate(new PfValidationResult()).isValid());
+
+ tpt.getTargets().add(null);
+ assertFalse(tpt.validate(new PfValidationResult()).isValid());
+ tpt.getTargets().remove(null);
+ assertTrue(tpt.validate(new PfValidationResult()).isValid());
+
+ tpt.getTriggers().add(null);
+ assertFalse(tpt.validate(new PfValidationResult()).isValid());
+ tpt.getTriggers().remove(null);
+ assertTrue(tpt.validate(new PfValidationResult()).isValid());
+
+ tpt.getMetadata().put(null, null);
+ assertFalse(tpt.validate(new PfValidationResult()).isValid());
+ tpt.getMetadata().remove(null);
+ assertTrue(tpt.validate(new PfValidationResult()).isValid());
+
+ tpt.getMetadata().put("nullKey", null);
+ assertFalse(tpt.validate(new PfValidationResult()).isValid());
+ tpt.getMetadata().remove("nullKey");
+ assertTrue(tpt.validate(new PfValidationResult()).isValid());
+
+ tpt.setDescription("");;
+ assertFalse(tpt.validate(new PfValidationResult()).isValid());
+ tpt.setDescription("A Description");
+ assertTrue(tpt.validate(new PfValidationResult()).isValid());
+
+ tpt.setDerivedFrom(PfConceptKey.getNullKey());
+ assertFalse(tpt.validate(new PfValidationResult()).isValid());
+ tpt.setDerivedFrom(derivedFromKey);
+ assertTrue(tpt.validate(new PfValidationResult()).isValid());
+
+ try {
+ tpt.validate(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaEntityType((PfConceptKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaEntityType((ToscaEntityType) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ ToscaEntityType tet = new ToscaEntityType(tpt.getKey());
+ assertEquals(-1, tet.compareTo(null));
+ assertEquals(0, tet.compareTo(tet));
+ assertFalse(tet.compareTo(tet.getKey()) == 0);
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypesTest.java
new file mode 100644
index 000000000..069346331
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypesTest.java
@@ -0,0 +1,76 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.util.TreeMap;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+
+public class ToscaPolicyTypesTest {
+
+ @Test
+ public void testPolicyTypes() {
+ assertNotNull(new ToscaPolicyTypes());
+ assertNotNull(new ToscaPolicyTypes(new PfConceptKey()));
+ assertNotNull(new ToscaPolicyTypes(new PfConceptKey(), new TreeMap<PfConceptKey, ToscaPolicyType>()));
+ assertNotNull(new ToscaPolicyTypes(new ToscaPolicyTypes()));
+
+ try {
+ new ToscaPolicyTypes((PfConceptKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaPolicyTypes((ToscaPolicyTypes) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaPolicyTypes(null, null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaPolicyTypes(new PfConceptKey(), null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("conceptMap is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaPolicyTypes(null, new TreeMap<PfConceptKey, ToscaPolicyType>());
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPropertyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPropertyTest.java
new file mode 100644
index 000000000..d0563fd26
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPropertyTest.java
@@ -0,0 +1,223 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.concepts.ToscaConstraintLogical.Operation;
+
+/**
+ * DAO test for ToscaProperty.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaPropertyTest {
+
+ @Test
+ public void testPropertyPojo() {
+ assertNotNull(new ToscaProperty());
+ assertNotNull(new ToscaProperty(new PfReferenceKey()));
+ assertNotNull(new ToscaProperty(new PfReferenceKey(), new PfConceptKey()));
+ assertNotNull(new ToscaProperty(new ToscaProperty()));
+
+ try {
+ new ToscaProperty((PfReferenceKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaProperty(null, null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaProperty(null, new PfConceptKey());
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaProperty(new PfReferenceKey(), null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("type is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaProperty((ToscaProperty) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ PfConceptKey pparentKey = new PfConceptKey("tParentKey", "0.0.1");
+ PfReferenceKey pkey = new PfReferenceKey(pparentKey, "trigger0");
+ PfConceptKey ptypeKey = new PfConceptKey("TTypeKey", "0.0.1");
+ ToscaProperty tp = new ToscaProperty(pkey, ptypeKey);
+
+ tp.setDescription("A Description");
+ assertEquals("A Description", tp.getDescription());
+
+ tp.setRequired(false);
+ assertFalse(tp.isRequired());
+
+ PfConceptKey tdefaultKey = new PfConceptKey("defaultKey", "0.0.1");
+ tp.setDefaultValue(tdefaultKey);
+
+ tp.setStatus(ToscaProperty.Status.SUPPORTED);
+
+ List<ToscaConstraint> constraints = new ArrayList<>();
+ ToscaConstraintLogicalString lsc =
+ new ToscaConstraintLogicalString(new PfReferenceKey(pkey, "sc"), Operation.EQ, "hello");
+ constraints.add(lsc);
+ tp.setConstraints(constraints);
+ assertEquals(constraints, tp.getConstraints());
+
+ PfReferenceKey esKey = new PfReferenceKey(pkey, "entrySchema");
+ PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
+ ToscaEntrySchema tes = new ToscaEntrySchema(esKey, typeKey);
+ tp.setEntrySchema(tes);
+
+ ToscaProperty tdtClone0 = new ToscaProperty(tp);
+ assertEquals(tp, tdtClone0);
+ assertEquals(0, tp.compareTo(tdtClone0));
+
+ ToscaProperty tdtClone1 = new ToscaProperty();
+ tp.copyTo(tdtClone1);
+ assertEquals(tp, tdtClone1);
+ assertEquals(0, tp.compareTo(tdtClone1));
+
+ assertEquals(-1, tp.compareTo(null));
+ assertEquals(0, tp.compareTo(tp));
+ assertFalse(tp.compareTo(tp.getKey()) == 0);
+
+ PfReferenceKey otherDtKey = new PfReferenceKey("otherDt", "0.0.1", "OtherProperty");
+ ToscaProperty otherDt = new ToscaProperty(otherDtKey);
+
+ assertFalse(tp.compareTo(otherDt) == 0);
+ otherDt.setKey(pkey);
+ assertFalse(tp.compareTo(otherDt) == 0);
+ otherDt.setType(ptypeKey);
+ assertFalse(tp.compareTo(otherDt) == 0);
+ otherDt.setDescription("A Description");
+ assertFalse(tp.compareTo(otherDt) == 0);
+ otherDt.setRequired(false);
+ assertFalse(tp.compareTo(otherDt) == 0);
+ otherDt.setDefaultValue(tdefaultKey);
+ assertFalse(tp.compareTo(otherDt) == 0);
+ otherDt.setStatus(ToscaProperty.Status.SUPPORTED);
+ assertFalse(tp.compareTo(otherDt) == 0);
+ assertFalse(tp.compareTo(otherDt) == 0);
+ otherDt.setConstraints(constraints);
+ assertFalse(tp.compareTo(otherDt) == 0);
+ otherDt.setEntrySchema(tes);
+ assertEquals(0, tp.compareTo(otherDt));
+
+ otherDt.setRequired(true);
+ assertFalse(tp.compareTo(otherDt) == 0);
+ otherDt.setRequired(false);
+ assertEquals(0, tp.compareTo(otherDt));
+
+ otherDt.setStatus(ToscaProperty.Status.UNSUPPORTED);
+ assertFalse(tp.compareTo(otherDt) == 0);
+ otherDt.setStatus(ToscaProperty.Status.SUPPORTED);
+ assertEquals(0, tp.compareTo(otherDt));
+
+ try {
+ tp.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(6, tp.getKeys().size());
+ assertEquals(2, new ToscaProperty().getKeys().size());
+
+ new ToscaProperty().clean();
+ tp.clean();
+ assertEquals(tdtClone0, tp);
+
+ assertFalse(new ToscaProperty().validate(new PfValidationResult()).isValid());
+ assertTrue(tp.validate(new PfValidationResult()).isValid());
+
+ tp.setDescription(null);
+ assertTrue(tp.validate(new PfValidationResult()).isValid());
+ tp.setDescription("");
+ assertFalse(tp.validate(new PfValidationResult()).isValid());
+ tp.setDescription("A Description");
+ assertTrue(tp.validate(new PfValidationResult()).isValid());
+
+ tp.setType(null);
+ assertFalse(tp.validate(new PfValidationResult()).isValid());
+ tp.setType(typeKey);
+ assertTrue(tp.validate(new PfValidationResult()).isValid());
+
+ tp.setType(PfConceptKey.getNullKey());
+ assertFalse(tp.validate(new PfValidationResult()).isValid());
+ tp.setType(typeKey);
+ assertTrue(tp.validate(new PfValidationResult()).isValid());
+
+ tp.setDefaultValue(null);
+ assertTrue(tp.validate(new PfValidationResult()).isValid());
+ tp.setDefaultValue(tdefaultKey);
+ assertTrue(tp.validate(new PfValidationResult()).isValid());
+
+ tp.setDefaultValue(PfConceptKey.getNullKey());
+ assertFalse(tp.validate(new PfValidationResult()).isValid());
+ tp.setDefaultValue(tdefaultKey);
+ assertTrue(tp.validate(new PfValidationResult()).isValid());
+
+ tp.getConstraints().add(null);
+ assertFalse(tp.validate(new PfValidationResult()).isValid());
+ tp.getConstraints().remove(null);
+ assertTrue(tp.validate(new PfValidationResult()).isValid());
+
+ try {
+ tp.setStatus(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("status is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ tp.validate(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
+ }
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplateTest.java
new file mode 100644
index 000000000..0fc7a0bf3
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplateTest.java
@@ -0,0 +1,170 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfValidationResult;
+
+/**
+ * DAO test for ToscaDatatype.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaServiceTemplateTest {
+
+ @Test
+ public void testServiceTemplatePojo() {
+ assertNotNull(new ToscaServiceTemplate());
+ assertNotNull(new ToscaServiceTemplate(new PfConceptKey()));
+ assertNotNull(new ToscaServiceTemplate(new PfConceptKey(), ""));
+ assertNotNull(new ToscaServiceTemplate(new ToscaServiceTemplate()));
+
+ try {
+ new ToscaServiceTemplate((PfConceptKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaServiceTemplate(null, null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaServiceTemplate(null, "");
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaServiceTemplate(new PfConceptKey(), null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("toscaDefinitionsVersion is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaServiceTemplate((ToscaServiceTemplate) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ PfConceptKey tstKey = new PfConceptKey("tst", "0.0.1");
+ ToscaServiceTemplate tst = new ToscaServiceTemplate(tstKey, "Tosca Version");
+
+ PfConceptKey dataTypeKey = new PfConceptKey("DataType", "0.0.1");
+ ToscaDataType dataType0 = new ToscaDataType(dataTypeKey);
+ PfConceptKey dtsKey = new PfConceptKey("dts", "0.0.1");
+ Map<PfConceptKey, ToscaDataType> dataTypeMap = new TreeMap<>();
+ dataTypeMap.put(dataTypeKey, dataType0);
+ ToscaDataTypes dataTypes = new ToscaDataTypes(dtsKey, dataTypeMap);
+ tst.setDataTypes(dataTypes);
+ assertEquals(dataTypes, tst.getDataTypes());
+
+ PfConceptKey policyTypeKey = new PfConceptKey("DataType", "0.0.1");
+ ToscaPolicyType policyType0 = new ToscaPolicyType(policyTypeKey);
+ PfConceptKey ptsKey = new PfConceptKey("dts", "0.0.1");
+ Map<PfConceptKey, ToscaPolicyType> policyTypeMap = new TreeMap<>();
+ policyTypeMap.put(policyTypeKey, policyType0);
+ ToscaPolicyTypes policyTypes = new ToscaPolicyTypes(ptsKey, policyTypeMap);
+ tst.setPolicyTypes(policyTypes);
+ assertEquals(policyTypes, tst.getPolicyTypes());
+
+ PfConceptKey tttKey = new PfConceptKey("TopologyTemplate", "0.0.1");
+ ToscaTopologyTemplate ttt = new ToscaTopologyTemplate(tttKey);
+ tst.setTopologyTemplate(ttt);
+ assertEquals(ttt, tst.getTopologyTemplate());
+
+ ToscaServiceTemplate tttClone0 = new ToscaServiceTemplate(tst);
+ assertEquals(tst, tttClone0);
+ assertEquals(0, tst.compareTo(tttClone0));
+
+ ToscaServiceTemplate tttClone1 = new ToscaServiceTemplate();
+ tst.copyTo(tttClone1);
+ assertEquals(tst, tttClone1);
+ assertEquals(0, tst.compareTo(tttClone1));
+
+ assertEquals(-1, tst.compareTo(null));
+ assertEquals(0, tst.compareTo(tst));
+ assertFalse(tst.compareTo(tst.getKey()) == 0);
+
+ PfConceptKey otherDtKey = new PfConceptKey("otherDt", "0.0.1");
+ ToscaServiceTemplate otherDt = new ToscaServiceTemplate(otherDtKey);
+
+ assertFalse(tst.compareTo(otherDt) == 0);
+ otherDt.setKey(tstKey);
+ assertFalse(tst.compareTo(otherDt) == 0);
+ otherDt.setToscaDefinitionsVersion("Tosca Version");
+ assertFalse(tst.compareTo(otherDt) == 0);
+ otherDt.setDataTypes(dataTypes);
+ assertFalse(tst.compareTo(otherDt) == 0);
+ otherDt.setPolicyTypes(policyTypes);
+ assertFalse(tst.compareTo(otherDt) == 0);
+ otherDt.setTopologyTemplate(ttt);
+ assertEquals(0, tst.compareTo(otherDt));
+
+ try {
+ tst.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(6, tst.getKeys().size());
+ assertEquals(1, new ToscaServiceTemplate().getKeys().size());
+
+ new ToscaServiceTemplate().clean();
+ tst.clean();
+ assertEquals(tttClone0, tst);
+
+ assertFalse(new ToscaServiceTemplate().validate(new PfValidationResult()).isValid());
+ assertTrue(tst.validate(new PfValidationResult()).isValid());
+
+ tst.setDescription(null);
+ assertTrue(tst.validate(new PfValidationResult()).isValid());
+ tst.setDescription("");
+ assertFalse(tst.validate(new PfValidationResult()).isValid());
+ tst.setDescription("A Description");
+ assertTrue(tst.validate(new PfValidationResult()).isValid());
+
+ try {
+ tst.validate(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
+ }
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplatesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplatesTest.java
new file mode 100644
index 000000000..c866f11c7
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplatesTest.java
@@ -0,0 +1,76 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.util.TreeMap;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+
+public class ToscaServiceTemplatesTest {
+
+ @Test
+ public void testServiceTemplates() {
+ assertNotNull(new ToscaServiceTemplates());
+ assertNotNull(new ToscaServiceTemplates(new PfConceptKey()));
+ assertNotNull(new ToscaServiceTemplates(new PfConceptKey(), new TreeMap<PfConceptKey, ToscaServiceTemplate>()));
+ assertNotNull(new ToscaServiceTemplates(new ToscaServiceTemplates()));
+
+ try {
+ new ToscaServiceTemplates((PfConceptKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaServiceTemplates((ToscaServiceTemplates) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaServiceTemplates(null, null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaServiceTemplates(new PfConceptKey(), null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("conceptMap is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaServiceTemplates(null, new TreeMap<PfConceptKey, ToscaServiceTemplate>());
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTimeIntervalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTimeIntervalTest.java
new file mode 100644
index 000000000..33af68343
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTimeIntervalTest.java
@@ -0,0 +1,181 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Date;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfValidationResult;
+
+/**
+ * DAO test for ToscaTimeInterval.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaTimeIntervalTest {
+
+ @Test
+ public void testTimeIntervalPojo() {
+ assertNotNull(new ToscaTimeInterval());
+ assertNotNull(new ToscaTimeInterval(new PfReferenceKey()));
+ assertNotNull(new ToscaTimeInterval(new PfReferenceKey(), new Date(), new Date()));
+ assertNotNull(new ToscaTimeInterval(new ToscaTimeInterval()));
+
+ try {
+ new ToscaTimeInterval((PfReferenceKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTimeInterval(null, null, null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTimeInterval(null, null, new Date());
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTimeInterval(null, new Date(), null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTimeInterval(null, new Date(), new Date());
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTimeInterval(new PfReferenceKey(), null, null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("startTime is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTimeInterval(new PfReferenceKey(), null, new Date());
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("startTime is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTimeInterval(new PfReferenceKey(), new Date(), null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("endTime is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTimeInterval((ToscaTimeInterval) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ PfConceptKey ttiParentKey = new PfConceptKey("tParentKey", "0.0.1");
+ PfReferenceKey ttiKey = new PfReferenceKey(ttiParentKey, "trigger0");
+ Date startTime = new Date(1000);
+ Date endTime = new Date(2000);
+ ToscaTimeInterval tti = new ToscaTimeInterval(ttiKey, startTime, endTime);
+
+ ToscaTimeInterval tdtClone0 = new ToscaTimeInterval(tti);
+ assertEquals(tti, tdtClone0);
+ assertEquals(0, tti.compareTo(tdtClone0));
+
+ ToscaTimeInterval tdtClone1 = new ToscaTimeInterval();
+ tti.copyTo(tdtClone1);
+ assertEquals(tti, tdtClone1);
+ assertEquals(0, tti.compareTo(tdtClone1));
+
+ assertEquals(-1, tti.compareTo(null));
+ assertEquals(0, tti.compareTo(tti));
+ assertFalse(tti.compareTo(tti.getKey()) == 0);
+
+ PfReferenceKey otherDtKey = new PfReferenceKey("otherDt", "0.0.1", "OtherTimeInterval");
+ ToscaTimeInterval otherDt = new ToscaTimeInterval(otherDtKey);
+
+ assertFalse(tti.compareTo(otherDt) == 0);
+ otherDt.setKey(ttiKey);
+ assertFalse(tti.compareTo(otherDt) == 0);
+ otherDt.setStartTime(startTime);
+ assertFalse(tti.compareTo(otherDt) == 0);
+ otherDt.setEndTime(endTime);
+ assertEquals(0, tti.compareTo(otherDt));
+
+ try {
+ tti.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(1, tti.getKeys().size());
+ assertEquals(1, new ToscaTimeInterval().getKeys().size());
+
+ new ToscaTimeInterval().clean();
+ tti.clean();
+ assertEquals(tdtClone0, tti);
+
+ assertFalse(new ToscaTimeInterval().validate(new PfValidationResult()).isValid());
+ assertTrue(tti.validate(new PfValidationResult()).isValid());
+
+ tti.setStartTime(null);
+ assertFalse(tti.validate(new PfValidationResult()).isValid());
+ tti.setStartTime(new Date(endTime.getTime() + 1));
+ assertFalse(tti.validate(new PfValidationResult()).isValid());
+ tti.setStartTime(startTime);
+ assertTrue(tti.validate(new PfValidationResult()).isValid());
+
+ tti.setEndTime(null);
+ assertFalse(tti.validate(new PfValidationResult()).isValid());
+ tti.setEndTime(new Date(startTime.getTime() - 1));
+ assertFalse(tti.validate(new PfValidationResult()).isValid());
+ tti.setEndTime(endTime);
+ assertTrue(tti.validate(new PfValidationResult()).isValid());
+
+ try {
+ tti.validate(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
+ }
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplateTest.java
new file mode 100644
index 000000000..4a288f183
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplateTest.java
@@ -0,0 +1,134 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Map;
+import java.util.TreeMap;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfValidationResult;
+
+/**
+ * DAO test for ToscaDatatype.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaTopologyTemplateTest {
+
+ @Test
+ public void testTopologyTemplatePojo() {
+ assertNotNull(new ToscaTopologyTemplate());
+ assertNotNull(new ToscaTopologyTemplate(new PfConceptKey()));
+ assertNotNull(new ToscaTopologyTemplate(new ToscaTopologyTemplate()));
+
+ try {
+ new ToscaTopologyTemplate((PfConceptKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTopologyTemplate((ToscaTopologyTemplate) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ PfConceptKey tttKey = new PfConceptKey("ttt", "0.0.1");
+ ToscaTopologyTemplate ttt = new ToscaTopologyTemplate(tttKey);
+
+ ttt.setDescription("A Description");
+ assertEquals("A Description", ttt.getDescription());
+
+ PfConceptKey policy0TypeKey = new PfConceptKey("Policy0Type", "0.0.1");
+ PfConceptKey policy0Key = new PfConceptKey("Policy0", "0.0.1");
+
+ ToscaPolicy policy0 = new ToscaPolicy(policy0Key, policy0TypeKey);
+ PfConceptKey polsKey = new PfConceptKey("pols", "0.0.1");
+ Map<PfConceptKey, ToscaPolicy> policyMap = new TreeMap<>();
+ policyMap.put(policy0Key, policy0);
+ ToscaPolicies policies = new ToscaPolicies(polsKey, policyMap);
+ ttt.setPolicies(policies);
+
+ ToscaTopologyTemplate tttClone0 = new ToscaTopologyTemplate(ttt);
+ assertEquals(ttt, tttClone0);
+ assertEquals(0, ttt.compareTo(tttClone0));
+
+ ToscaTopologyTemplate tttClone1 = new ToscaTopologyTemplate();
+ ttt.copyTo(tttClone1);
+ assertEquals(ttt, tttClone1);
+ assertEquals(0, ttt.compareTo(tttClone1));
+
+ assertEquals(-1, ttt.compareTo(null));
+ assertEquals(0, ttt.compareTo(ttt));
+ assertFalse(ttt.compareTo(ttt.getKey()) == 0);
+
+ PfConceptKey otherDtKey = new PfConceptKey("otherDt", "0.0.1");
+ ToscaTopologyTemplate otherDt = new ToscaTopologyTemplate(otherDtKey);
+
+ assertFalse(ttt.compareTo(otherDt) == 0);
+ otherDt.setKey(tttKey);
+ assertFalse(ttt.compareTo(otherDt) == 0);
+ otherDt.setDescription("A Description");
+ assertFalse(ttt.compareTo(otherDt) == 0);
+ otherDt.setPolicies(policies);
+ assertEquals(0, ttt.compareTo(otherDt));
+
+ try {
+ ttt.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(4, ttt.getKeys().size());
+ assertEquals(1, new ToscaTopologyTemplate().getKeys().size());
+
+ new ToscaTopologyTemplate().clean();
+ ttt.clean();
+ assertEquals(tttClone0, ttt);
+
+ assertFalse(new ToscaTopologyTemplate().validate(new PfValidationResult()).isValid());
+ assertTrue(ttt.validate(new PfValidationResult()).isValid());
+
+ ttt.setDescription(null);
+ assertTrue(ttt.validate(new PfValidationResult()).isValid());
+ ttt.setDescription("");
+ assertFalse(ttt.validate(new PfValidationResult()).isValid());
+ ttt.setDescription("A Description");
+ assertTrue(ttt.validate(new PfValidationResult()).isValid());
+
+ try {
+ ttt.validate(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
+ }
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTriggerTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTriggerTest.java
new file mode 100644
index 000000000..d1423a6a4
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTriggerTest.java
@@ -0,0 +1,228 @@
+/*-
+ * ============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.models.tosca.concepts;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.time.Duration;
+import java.util.Date;
+
+import org.junit.Test;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfValidationResult;
+import org.onap.policy.models.tosca.concepts.ToscaConstraintLogical.Operation;
+
+/**
+ * DAO test for ToscaTrigger.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaTriggerTest {
+
+ @Test
+ public void testTriggerPojo() {
+ assertNotNull(new ToscaTrigger());
+ assertNotNull(new ToscaTrigger(new PfReferenceKey()));
+ assertNotNull(new ToscaTrigger(new PfReferenceKey(), "EventType", "Action"));
+ assertNotNull(new ToscaTrigger(new ToscaTrigger()));
+
+ try {
+ new ToscaTrigger((PfReferenceKey) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTrigger(null, null, null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTrigger(null, "EventType", null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTrigger(null, "EventType", "Action");
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTrigger(null, null, "Action");
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("key is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTrigger(new PfReferenceKey(), null, null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("eventType is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTrigger(new PfReferenceKey(), "EventType", null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("action is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTrigger(new PfReferenceKey(), null, "Action");
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("eventType is marked @NonNull but is null", exc.getMessage());
+ }
+
+ try {
+ new ToscaTrigger((ToscaTrigger) null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
+ }
+
+ PfConceptKey tparentKey = new PfConceptKey("tParentKey", "0.0.1");
+ PfReferenceKey tkey = new PfReferenceKey(tparentKey, "trigger0");
+ ToscaTrigger tdt = new ToscaTrigger(tkey, "EventType", "Action");
+
+ ToscaTimeInterval schedule = new ToscaTimeInterval(new PfReferenceKey(tkey, "sched"), new Date(), new Date());
+ tdt.setSchedule(schedule);
+
+ ToscaEventFilter targetFilter =
+ new ToscaEventFilter(new PfReferenceKey(tkey, "filter"), new PfConceptKey("NodeName", "0.0.1"));
+ tdt.setTargetFilter(targetFilter);
+
+ ToscaConstraintLogicalString lsc =
+ new ToscaConstraintLogicalString(new PfReferenceKey(tkey, "sc"), Operation.EQ, "hello");
+ tdt.setCondition(lsc);
+ assertEquals(lsc, tdt.getCondition());
+ tdt.setConstraint(lsc);
+ assertEquals(lsc, tdt.getConstraint());
+
+ tdt.setPeriod(Duration.ZERO);
+ assertEquals(Duration.ZERO, tdt.getPeriod());
+
+ tdt.setDescription("A Description");
+ assertEquals("A Description", tdt.getDescription());
+
+ tdt.setMethod("A Method");
+ assertEquals("A Method", tdt.getMethod());
+
+ ToscaTrigger tdtClone0 = new ToscaTrigger(tdt);
+ assertEquals(tdt, tdtClone0);
+ assertEquals(0, tdt.compareTo(tdtClone0));
+
+ ToscaTrigger tdtClone1 = new ToscaTrigger();
+ tdt.copyTo(tdtClone1);
+ assertEquals(tdt, tdtClone1);
+ assertEquals(0, tdt.compareTo(tdtClone1));
+
+ assertEquals(-1, tdt.compareTo(null));
+ assertEquals(0, tdt.compareTo(tdt));
+ assertFalse(tdt.compareTo(tdt.getKey()) == 0);
+
+ PfReferenceKey otherDtKey = new PfReferenceKey("otherDt", "0.0.1", "OtherTrigger");
+ ToscaTrigger otherDt = new ToscaTrigger(otherDtKey);
+
+ assertFalse(tdt.compareTo(otherDt) == 0);
+ otherDt.setKey(tkey);
+ assertFalse(tdt.compareTo(otherDt) == 0);
+ otherDt.setDescription("A Description");
+ assertFalse(tdt.compareTo(otherDt) == 0);
+ otherDt.setEventType("EventType");
+ assertFalse(tdt.compareTo(otherDt) == 0);
+ otherDt.setSchedule(schedule);
+ assertFalse(tdt.compareTo(otherDt) == 0);
+ otherDt.setTargetFilter(targetFilter);
+ assertFalse(tdt.compareTo(otherDt) == 0);
+ otherDt.setCondition(lsc);
+ assertFalse(tdt.compareTo(otherDt) == 0);
+ otherDt.setConstraint(lsc);
+ assertFalse(tdt.compareTo(otherDt) == 0);
+ otherDt.setPeriod(Duration.ZERO);
+ assertFalse(tdt.compareTo(otherDt) == 0);
+ otherDt.setMethod("A Method");
+ assertFalse(tdt.compareTo(otherDt) == 0);
+ otherDt.setAction("Action");
+ assertEquals(0, tdt.compareTo(otherDt));
+
+ otherDt.setEvaluations(100);
+ assertFalse(tdt.compareTo(otherDt) == 0);
+ otherDt.setEvaluations(0);
+ assertEquals(0, tdt.compareTo(otherDt));
+
+ try {
+ tdt.copyTo(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("target is marked @NonNull but is null", exc.getMessage());
+ }
+
+ assertEquals(6, tdt.getKeys().size());
+ assertEquals(1, new ToscaTrigger().getKeys().size());
+
+ new ToscaTrigger().clean();
+ tdt.clean();
+ assertEquals(tdtClone0, tdt);
+
+ assertFalse(new ToscaTrigger().validate(new PfValidationResult()).isValid());
+ assertTrue(tdt.validate(new PfValidationResult()).isValid());
+
+ tdt.setDescription(null);
+ assertTrue(tdt.validate(new PfValidationResult()).isValid());
+ tdt.setDescription("");
+ assertFalse(tdt.validate(new PfValidationResult()).isValid());
+ tdt.setDescription("A Description");
+ assertTrue(tdt.validate(new PfValidationResult()).isValid());
+
+ tdt.setEvaluations(-1);
+ assertFalse(tdt.validate(new PfValidationResult()).isValid());
+ tdt.setEvaluations(100);
+ assertTrue(tdt.validate(new PfValidationResult()).isValid());
+
+ tdt.setMethod(null);
+ assertTrue(tdt.validate(new PfValidationResult()).isValid());
+ tdt.setMethod("");
+ assertFalse(tdt.validate(new PfValidationResult()).isValid());
+ tdt.setMethod("A Method");
+ assertTrue(tdt.validate(new PfValidationResult()).isValid());
+
+ try {
+ tdt.validate(null);
+ fail("test should throw an exception");
+ } catch (Exception exc) {
+ assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
+ }
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/testconcepts/DummyToscaConstraint.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/testconcepts/DummyToscaConstraint.java
new file mode 100644
index 000000000..3b27e1565
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/testconcepts/DummyToscaConstraint.java
@@ -0,0 +1,62 @@
+/*-
+ * ============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.models.tosca.concepts.testconcepts;
+
+import javax.ws.rs.core.Response;
+
+import org.onap.policy.models.base.PfModelRuntimeException;
+import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.tosca.concepts.ToscaConstraint;
+
+/**
+ * Dummy constraint to test abstract ToscaConstraint class.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class DummyToscaConstraint extends ToscaConstraint {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The Default Constructor creates a {@link DummyToscaConstraint} object with a null key.
+ */
+ public DummyToscaConstraint() {
+ super(new PfReferenceKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link DummyToscaConstraint} object with the given concept key.
+ *
+ * @param key the key of the constraint
+ */
+ public DummyToscaConstraint(final PfReferenceKey key) {
+ super(key);
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public DummyToscaConstraint(final DummyToscaConstraint copyConcept) {
+ super(copyConcept);
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+ }
+}
diff --git a/pom.xml b/pom.xml
index 6277849cf..ee5092eae 100644
--- a/pom.xml
+++ b/pom.xml
@@ -40,6 +40,7 @@
<properties>
<derby.version>10.13.1.1</derby.version>
+ <javax.ws.rs-api.version>2.0.1</javax.ws.rs-api.version>
<policy.common.version>1.4.0-SNAPSHOT</policy.common.version>
<!-- sonar/jacoco overrides -->
@@ -54,6 +55,7 @@
<module>models-dao</module>
<module>models-tosca</module>
<module>models-pap</module>
+ <module>models-provider</module>
</modules>
<distributionManagement>
@@ -86,6 +88,12 @@
</dependency>
<dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <version>${javax.ws.rs-api.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
@@ -95,7 +103,6 @@
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
</dependency>
-
</dependencies>
<dependencyManagement>