From 7d5da7ae76db4266da40ce01b0bfd3b09d7796a6 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Sun, 17 Mar 2019 22:33:51 +0000 Subject: Implement Legacy to TOSCA Mapping This first patch set is a rough first draft of how translation will work. Issue-ID: POLICY-1195 Change-Id: I4a57b049f5756dc6d1e2f4d458d9dd770f928eb2 Signed-off-by: liamfallon --- .../models/tosca/concepts/ToscaConstraint.java | 125 -------- .../tosca/concepts/ToscaConstraintLogical.java | 119 -------- .../tosca/concepts/ToscaConstraintLogicalKey.java | 155 ---------- .../concepts/ToscaConstraintLogicalString.java | 137 --------- .../models/tosca/concepts/ToscaDataType.java | 246 --------------- .../models/tosca/concepts/ToscaDataTypes.java | 86 ------ .../models/tosca/concepts/ToscaEntityType.java | 217 ------------- .../models/tosca/concepts/ToscaEntrySchema.java | 228 -------------- .../models/tosca/concepts/ToscaEventFilter.java | 197 ------------ .../policy/models/tosca/concepts/ToscaModel.java | 160 ---------- .../models/tosca/concepts/ToscaPolicies.java | 86 ------ .../policy/models/tosca/concepts/ToscaPolicy.java | 273 ----------------- .../models/tosca/concepts/ToscaPolicyType.java | 294 ------------------ .../models/tosca/concepts/ToscaPolicyTypes.java | 86 ------ .../models/tosca/concepts/ToscaProperty.java | 308 ------------------- .../tosca/concepts/ToscaServiceTemplate.java | 222 -------------- .../tosca/concepts/ToscaServiceTemplates.java | 86 ------ .../models/tosca/concepts/ToscaTimeInterval.java | 188 ------------ .../tosca/concepts/ToscaTopologyTemplate.java | 178 ----------- .../policy/models/tosca/concepts/ToscaTrigger.java | 335 --------------------- .../tosca/legacy/concepts/LegacyGuardPolicy.java | 43 +++ .../legacy/concepts/LegacyOperationalPolicy.java | 43 +++ .../mapping/LegacyOperationalPolicyMapper.java | 89 ++++++ .../legacy/LegacyGuardMessageBodyHandler.java | 56 ---- .../serialization/legacy/LegacyGuardPolicy.java | 43 --- .../LegacyOperationalMessageBodyHandler.java | 56 ---- .../legacy/LegacyOperationalPolicy.java | 40 --- .../simple/ToscaPoliciesJsonAdapter.java | 72 ----- .../simple/ToscaPolicyJsonAdapter.java | 85 ------ .../simple/ToscaServiceTemplateJsonAdapter.java | 75 ----- .../ToscaServiceTemplateMessageBodyHandler.java | 64 ---- .../simple/ToscaTopologyTemplateJsonAdapter.java | 72 ----- .../tosca/simple/concepts/ToscaConstraint.java | 125 ++++++++ .../simple/concepts/ToscaConstraintLogical.java | 119 ++++++++ .../simple/concepts/ToscaConstraintLogicalKey.java | 155 ++++++++++ .../concepts/ToscaConstraintLogicalString.java | 137 +++++++++ .../tosca/simple/concepts/ToscaDataType.java | 246 +++++++++++++++ .../tosca/simple/concepts/ToscaDataTypes.java | 86 ++++++ .../tosca/simple/concepts/ToscaEntityType.java | 217 +++++++++++++ .../tosca/simple/concepts/ToscaEntrySchema.java | 228 ++++++++++++++ .../tosca/simple/concepts/ToscaEventFilter.java | 197 ++++++++++++ .../models/tosca/simple/concepts/ToscaModel.java | 160 ++++++++++ .../tosca/simple/concepts/ToscaPolicies.java | 86 ++++++ .../models/tosca/simple/concepts/ToscaPolicy.java | 260 ++++++++++++++++ .../tosca/simple/concepts/ToscaPolicyType.java | 294 ++++++++++++++++++ .../tosca/simple/concepts/ToscaPolicyTypes.java | 86 ++++++ .../tosca/simple/concepts/ToscaProperty.java | 308 +++++++++++++++++++ .../simple/concepts/ToscaServiceTemplate.java | 222 ++++++++++++++ .../simple/concepts/ToscaServiceTemplates.java | 86 ++++++ .../tosca/simple/concepts/ToscaTimeInterval.java | 188 ++++++++++++ .../simple/concepts/ToscaTopologyTemplate.java | 178 +++++++++++ .../models/tosca/simple/concepts/ToscaTrigger.java | 335 +++++++++++++++++++++ .../simple/mapping/ToscaServiceTemplateMapper.java | 49 +++ .../serialization/ToscaPoliciesJsonAdapter.java | 72 +++++ .../serialization/ToscaPolicyJsonAdapter.java | 85 ++++++ .../ToscaServiceTemplateJsonAdapter.java | 75 +++++ .../ToscaServiceTemplateMessageBodyHandler.java | 64 ++++ .../ToscaTopologyTemplateJsonAdapter.java | 72 +++++ .../policy/models/tosca/concepts/TestPojos.java | 53 ---- .../concepts/ToscaConstraintLogicalKeyTest.java | 134 --------- .../concepts/ToscaConstraintLogicalStringTest.java | 133 -------- .../tosca/concepts/ToscaConstraintLogicalTest.java | 166 ---------- .../models/tosca/concepts/ToscaDataTypeTest.java | 140 --------- .../models/tosca/concepts/ToscaDataTypesTest.java | 76 ----- .../tosca/concepts/ToscaEntrySchemaTest.java | 147 --------- .../tosca/concepts/ToscaEventFilterTest.java | 165 ---------- .../models/tosca/concepts/ToscaModelTest.java | 142 --------- .../models/tosca/concepts/ToscaPoliciesTest.java | 76 ----- .../models/tosca/concepts/ToscaPolicyTest.java | 162 ---------- .../models/tosca/concepts/ToscaPolicyTypeTest.java | 208 ------------- .../tosca/concepts/ToscaPolicyTypesTest.java | 76 ----- .../models/tosca/concepts/ToscaPropertyTest.java | 223 -------------- .../tosca/concepts/ToscaServiceTemplateTest.java | 171 ----------- .../tosca/concepts/ToscaServiceTemplatesTest.java | 76 ----- .../tosca/concepts/ToscaTimeIntervalTest.java | 181 ----------- .../tosca/concepts/ToscaTopologyTemplateTest.java | 135 --------- .../models/tosca/concepts/ToscaTriggerTest.java | 228 -------------- .../testconcepts/DummyToscaConstraint.java | 62 ---- .../legacy/concepts/LegacyGuardPolicyTest.java | 52 ++++ .../concepts/LegacyOperationalPolicyTest.java | 44 +++ .../LegacyOperationalPolicySerializationTest.java | 74 +++++ .../MonitoringPolicySerializationTest.java | 94 ------ .../legacy/LegacyGuardPolicyTest.java | 51 ---- .../legacy/LegacyOperationalPolicyTest.java | 43 --- .../models/tosca/simple/concepts/TestPojos.java | 53 ++++ .../concepts/ToscaConstraintLogicalKeyTest.java | 135 +++++++++ .../concepts/ToscaConstraintLogicalStringTest.java | 134 +++++++++ .../concepts/ToscaConstraintLogicalTest.java | 167 ++++++++++ .../tosca/simple/concepts/ToscaDataTypeTest.java | 144 +++++++++ .../tosca/simple/concepts/ToscaDataTypesTest.java | 78 +++++ .../simple/concepts/ToscaEntrySchemaTest.java | 150 +++++++++ .../simple/concepts/ToscaEventFilterTest.java | 166 ++++++++++ .../tosca/simple/concepts/ToscaModelTest.java | 145 +++++++++ .../tosca/simple/concepts/ToscaPoliciesTest.java | 78 +++++ .../tosca/simple/concepts/ToscaPolicyTest.java | 174 +++++++++++ .../tosca/simple/concepts/ToscaPolicyTypeTest.java | 212 +++++++++++++ .../simple/concepts/ToscaPolicyTypesTest.java | 78 +++++ .../tosca/simple/concepts/ToscaPropertyTest.java | 227 ++++++++++++++ .../simple/concepts/ToscaServiceTemplateTest.java | 177 +++++++++++ .../simple/concepts/ToscaServiceTemplatesTest.java | 78 +++++ .../simple/concepts/ToscaTimeIntervalTest.java | 182 +++++++++++ .../simple/concepts/ToscaTopologyTemplateTest.java | 138 +++++++++ .../tosca/simple/concepts/ToscaTriggerTest.java | 232 ++++++++++++++ .../testconcepts/DummyToscaConstraint.java | 62 ++++ .../MonitoringPolicySerializationTest.java | 94 ++++++ 105 files changed, 7379 insertions(+), 7231 deletions(-) delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraint.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogical.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalKey.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalString.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataType.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataTypes.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntityType.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntrySchema.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEventFilter.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaModel.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicies.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicy.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyType.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypes.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaProperty.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplate.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplates.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTimeInterval.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplate.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTrigger.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicy.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicy.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardMessageBodyHandler.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardPolicy.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalMessageBodyHandler.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalPolicy.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaPoliciesJsonAdapter.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaPolicyJsonAdapter.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaServiceTemplateJsonAdapter.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaServiceTemplateMessageBodyHandler.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaTopologyTemplateJsonAdapter.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraint.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogical.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalKey.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalString.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataType.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypes.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntityType.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntrySchema.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEventFilter.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaModel.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicies.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicy.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyType.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypes.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaProperty.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplate.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplates.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTimeInterval.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTopologyTemplate.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTrigger.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/mapping/ToscaServiceTemplateMapper.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPoliciesJsonAdapter.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyJsonAdapter.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateJsonAdapter.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateMessageBodyHandler.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaTopologyTemplateJsonAdapter.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/TestPojos.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalKeyTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalStringTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaDataTypeTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaDataTypesTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaEntrySchemaTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaEventFilterTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaModelTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPoliciesTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypeTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypesTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPropertyTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplateTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplatesTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTimeIntervalTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplateTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTriggerTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/testconcepts/DummyToscaConstraint.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicyTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/serialization/LegacyOperationalPolicySerializationTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/serialization/MonitoringPolicySerializationTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardPolicyTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalPolicyTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/TestPojos.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalKeyTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalStringTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypeTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypesTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntrySchemaTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaEventFilterTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaModelTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPoliciesTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypeTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypesTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPropertyTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplateTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplatesTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaTimeIntervalTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaTopologyTemplateTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaTriggerTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java (limited to 'models-tosca') 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 deleted file mode 100644 index dadad6fd6..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraint.java +++ /dev/null @@ -1,125 +0,0 @@ -/*- - * ============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 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 deleted file mode 100644 index f186d8525..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogical.java +++ /dev/null @@ -1,119 +0,0 @@ -/*- - * ============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 deleted file mode 100644 index 1a63f30c8..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalKey.java +++ /dev/null @@ -1,155 +0,0 @@ -/*- - * ============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 getKeys() { - final List 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 deleted file mode 100644 index c786d626b..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalString.java +++ /dev/null @@ -1,137 +0,0 @@ -/*- - * ============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 deleted file mode 100644 index 5af24d6ed..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataType.java +++ /dev/null @@ -1,246 +0,0 @@ -/*- - * ============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 constraints; - - @ElementCollection - private List 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 getKeys() { - final List 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 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 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 deleted file mode 100644 index 61c3500cb..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaDataTypes.java +++ /dev/null @@ -1,86 +0,0 @@ -/*- - * ============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 { - 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()); - } - - /** - * 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 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/concepts/ToscaEntityType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntityType.java deleted file mode 100644 index b0dc58d93..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntityType.java +++ /dev/null @@ -1,217 +0,0 @@ -/*- - * ============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 java.util.Map; -import java.util.Map.Entry; -import java.util.TreeMap; - -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.OneToMany; -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.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. - */ -@Entity -@Table(name = "ToscaEntityType") -@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) -@Data -@EqualsAndHashCode(callSuper = false) -public class ToscaEntityType extends PfConcept { - private static final long serialVersionUID = -1330661834220739393L; - - @EmbeddedId - private PfConceptKey key; - - @SerializedName("derived_from") - @Column(name = "derivedFrom") - private PfConceptKey derivedFrom; - - @OneToMany(cascade = CascadeType.ALL) - private Map metadata; - - @Column(name = "description") - private String description; - - /** - * The Default Constructor creates a {@link ToscaEntityType} object with a null key. - */ - public ToscaEntityType() { - this(new PfConceptKey()); - } - - /** - * The Key Constructor creates a {@link ToscaEntityType} object with the given concept key. - * - * @param key the key - */ - public ToscaEntityType(@NonNull final PfConceptKey key) { - this.key = key; - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public ToscaEntityType(final ToscaEntityType copyConcept) { - super(copyConcept); - } - - @Override - public List getKeys() { - final List keyList = getKey().getKeys(); - if (derivedFrom != null) { - keyList.addAll(derivedFrom.getKeys()); - } - return keyList; - } - - @Override - public void clean() { - key.clean(); - - if (derivedFrom != null) { - derivedFrom.clean(); - } - - if (metadata != null) { - for (Entry metadataEntry : metadata.entrySet()) { - metadataEntry.setValue(metadataEntry.getValue().trim()); - } - } - - 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 (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 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 - 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 ToscaEntityType other = (ToscaEntityType) otherConcept; - if (!key.equals(other.key)) { - return key.compareTo(other.key); - } - - int result = ObjectUtils.compare(derivedFrom, other.derivedFrom); - if (result != 0) { - return result; - } - - result = PfUtils.compareObjects(metadata, other.metadata); - if (result != 0) { - return result; - } - - return ObjectUtils.compare(description, other.description); - } - - @Override - public PfConcept copyTo(@NonNull PfConcept target) { - final Object copyObject = target; - Assertions.instanceOf(copyObject, PfConcept.class); - - final ToscaEntityType copy = ((ToscaEntityType) copyObject); - copy.setKey(new PfConceptKey(key)); - copy.setDerivedFrom(derivedFrom != null ? new PfConceptKey(derivedFrom) : null); - - if (metadata != null) { - final Map newMatadata = new TreeMap<>(); - for (final Entry metadataEntry : metadata.entrySet()) { - newMatadata.put(metadataEntry.getKey(), metadataEntry.getValue()); - } - copy.setMetadata(newMatadata); - } - - 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 deleted file mode 100644 index 72bedbd9e..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEntrySchema.java +++ /dev/null @@ -1,228 +0,0 @@ -/*- - * ============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 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 getKeys() { - final List 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 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 deleted file mode 100644 index 4e2d73763..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaEventFilter.java +++ /dev/null @@ -1,197 +0,0 @@ -/*- - * ============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 getKeys() { - final List 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 deleted file mode 100644 index 9169e6778..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaModel.java +++ /dev/null @@ -1,160 +0,0 @@ -/*- - * ============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. - * - *

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 getKeys() { - final List 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 deleted file mode 100644 index 7209fd081..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicies.java +++ /dev/null @@ -1,86 +0,0 @@ -/*- - * ============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 { - 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()); - } - - /** - * 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 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 deleted file mode 100644 index 3e1fddd31..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicy.java +++ /dev/null @@ -1,273 +0,0 @@ -/*- - * ============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 properties; - - @ElementCollection - private List 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 getKeys() { - final List 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 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 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 deleted file mode 100644 index dbd011468..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyType.java +++ /dev/null @@ -1,294 +0,0 @@ -/*- - * ============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 properties; - - @ElementCollection - private List targets; - - @ElementCollection - private List 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 getKeys() { - final List 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 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 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 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 deleted file mode 100644 index e33e6c0c9..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypes.java +++ /dev/null @@ -1,86 +0,0 @@ -/*- - * ============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 { - 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()); - } - - /** - * 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 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 deleted file mode 100644 index ab72ff60e..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaProperty.java +++ /dev/null @@ -1,308 +0,0 @@ -/*- - * ============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 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 getKeys() { - final List 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 deleted file mode 100644 index acf231a3e..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplate.java +++ /dev/null @@ -1,222 +0,0 @@ -/*- - * ============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 getKeys() { - final List 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 deleted file mode 100644 index bd1620747..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplates.java +++ /dev/null @@ -1,86 +0,0 @@ -/*- - * ============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 { - 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()); - } - - /** - * 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 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 deleted file mode 100644 index 10ee6cc7d..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTimeInterval.java +++ /dev/null @@ -1,188 +0,0 @@ -/*- - * ============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 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 deleted file mode 100644 index aed181f94..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplate.java +++ /dev/null @@ -1,178 +0,0 @@ -/*- - * ============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.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; - -/** - * 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 PfReferenceKey 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 PfReferenceKey()); - } - - /** - * The Key Constructor creates a {@link ToscaTopologyTemplate} object with the given concept - * key. - * - * @param key the key - */ - public ToscaTopologyTemplate(@NonNull final PfReferenceKey key) { - this.key = key; - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public ToscaTopologyTemplate(final ToscaTopologyTemplate copyConcept) { - super(copyConcept); - } - - @Override - public List getKeys() { - final List 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 PfReferenceKey(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 deleted file mode 100644 index 5f3b6392f..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/concepts/ToscaTrigger.java +++ /dev/null @@ -1,335 +0,0 @@ -/*- - * ============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 getKeys() { - final List 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/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicy.java new file mode 100644 index 000000000..2454b51be --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicy.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * Modifications 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.legacy.concepts; + +import java.util.List; +import java.util.Map; + +import lombok.Data; + +/** + * Definition of a legacy guard policy stored as a TOSCA policy. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +@Data +public class LegacyGuardPolicy { + + private String policyId; + + private String policyVersion; + + private List> content; + +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicy.java new file mode 100644 index 000000000..60a1e454d --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicy.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * Modifications 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.legacy.concepts; + +import com.google.gson.annotations.SerializedName; + +import lombok.Data; + +/** + * Definition of a legacy operational policy stored as a TOSCA policy. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +@Data +public class LegacyOperationalPolicy { + + @SerializedName("policy-id") + private String policyId; + + private String policyVersion; + + private String content; + +} \ No newline at end of file diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java new file mode 100644 index 000000000..781602a7e --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapper.java @@ -0,0 +1,89 @@ +/*- + * ============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.legacy.mapping; + +import java.util.HashMap; +import java.util.Map; + +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfReferenceKey; +import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate; +import org.onap.policy.models.tosca.simple.mapping.ToscaServiceTemplateMapper; + +/** + * This class maps a legacy operational policy to and from a TOSCA service template. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class LegacyOperationalPolicyMapper + implements ToscaServiceTemplateMapper { + + // TODO: Do this correctly with an atomic integer + private static int nextVersion = 1; + + @Override + public ToscaServiceTemplate toToscaServiceTemplate(LegacyOperationalPolicy legacyOperationalPolicy) { + PfConceptKey policyKey = + new PfConceptKey(legacyOperationalPolicy.getPolicyId(), getNextVersion()); + + ToscaPolicy toscaPolicy = new ToscaPolicy(policyKey); + + // TODO: Find out how to parse the PolicyType from the content + // TODO: Check if this is the correct way to set the policy type version + toscaPolicy.setType(new PfConceptKey("SomeDerivedPolicyType", "1.0.0")); + + Map propertyMap = new HashMap<>(); + toscaPolicy.setProperties(propertyMap); + toscaPolicy.getProperties().put("Content", legacyOperationalPolicy.getContent()); + + PfConceptKey serviceTemplateKey = new PfConceptKey("ServiceTemplate", "1.0.0"); + ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(serviceTemplateKey); + serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_0"); + + PfReferenceKey topologyTemplateKey = new PfReferenceKey(serviceTemplateKey, "TopolocyTemplate"); + serviceTemplate.setTopologyTemplate(new ToscaTopologyTemplate(topologyTemplateKey)); + + PfConceptKey policiesKey = new PfConceptKey("Policies", "1.0.0"); + serviceTemplate.getTopologyTemplate().setPolicies(new ToscaPolicies(policiesKey)); + serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policyKey, toscaPolicy); + + return serviceTemplate; + } + + @Override + public LegacyOperationalPolicy fromToscaServiceTemplate(ToscaServiceTemplate serviceTemplate) { + // TODO Auto-generated method stub + return null; + } + + /** + * Get the next policy version. + * + * @return the next version + */ + private static String getNextVersion() { + return "1.0." + nextVersion++; + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardMessageBodyHandler.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardMessageBodyHandler.java deleted file mode 100644 index b343c9e66..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardMessageBodyHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.models.tosca.serialization.legacy; - -import com.google.gson.GsonBuilder; - -import org.onap.policy.common.gson.GsonMessageBodyHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Provider used to serialize and deserialize TOSCA objects using GSON. - */ -public class LegacyGuardMessageBodyHandler extends GsonMessageBodyHandler { - - public static final Logger logger = LoggerFactory.getLogger(LegacyGuardMessageBodyHandler.class); - - /** - * Constructs the object. - */ - public LegacyGuardMessageBodyHandler() { - this(new GsonBuilder()); - - logger.info("Using GSON with TOSCA for REST calls"); - } - - /** - * Constructs the object. - * - * @param builder builder to use to create the gson object - */ - public LegacyGuardMessageBodyHandler(final GsonBuilder builder) { - // @formatter:off - super(builder - .create() - ); - // @formatter:on - } - -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardPolicy.java deleted file mode 100644 index 30e62eb93..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardPolicy.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * Modifications 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.serialization.legacy; - -import java.util.List; -import java.util.Map; - -import lombok.Data; - -/** - * Definition of a legacy guard policy stored as a TOSCA policy. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -@Data -public class LegacyGuardPolicy { - - private String policyId; - - private String policyVersion; - - private List> content; - -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalMessageBodyHandler.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalMessageBodyHandler.java deleted file mode 100644 index f51a427f0..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalMessageBodyHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.models.tosca.serialization.legacy; - -import com.google.gson.GsonBuilder; - -import org.onap.policy.common.gson.GsonMessageBodyHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Provider used to serialize and deserialize TOSCA objects using GSON. - */ -public class LegacyOperationalMessageBodyHandler extends GsonMessageBodyHandler { - - public static final Logger logger = LoggerFactory.getLogger(LegacyOperationalMessageBodyHandler.class); - - /** - * Constructs the object. - */ - public LegacyOperationalMessageBodyHandler() { - this(new GsonBuilder()); - - logger.info("Using GSON with TOSCA for REST calls"); - } - - /** - * Constructs the object. - * - * @param builder builder to use to create the gson object - */ - public LegacyOperationalMessageBodyHandler(final GsonBuilder builder) { - // @formatter:off - super(builder - .create() - ); - // @formatter:on - } - -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalPolicy.java deleted file mode 100644 index 358d70247..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalPolicy.java +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * Modifications 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.serialization.legacy; - -import lombok.Data; - -/** - * Definition of a legacy operational policy stored as a TOSCA policy. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -@Data -public class LegacyOperationalPolicy { - - private String policyId; - - private String policyVersion; - - private String content; - -} \ No newline at end of file diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaPoliciesJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaPoliciesJsonAdapter.java deleted file mode 100644 index a12ba8be9..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaPoliciesJsonAdapter.java +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * ============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.serialization.simple; - -import com.google.gson.JsonArray; -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import java.lang.reflect.Type; -import java.util.Iterator; - -import lombok.NonNull; - -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.tosca.concepts.ToscaPolicies; -import org.onap.policy.models.tosca.concepts.ToscaPolicy; - -/** - * GSON type adapter for TOSCA policies. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -public class ToscaPoliciesJsonAdapter implements JsonSerializer, JsonDeserializer { - @Override - public ToscaPolicies deserialize(@NonNull final JsonElement policiesElement, @NonNull final Type type, - @NonNull final JsonDeserializationContext context) { - // The incoming JSON - final JsonArray policiesJsonArray = policiesElement.getAsJsonArray(); - - // The outgoing object - final PfConceptKey policiesKey = new PfConceptKey("IncomingPolicies", "0.0.1"); - final ToscaPolicies policies = new ToscaPolicies(policiesKey); - - // Get the policies - for (Iterator policiesIterator = policiesJsonArray.iterator(); policiesIterator.hasNext(); ) { - ToscaPolicy policy = new ToscaPolicyJsonAdapter() - .deserialize(policiesIterator.next(), ToscaPolicy.class, context); - - policies.getConceptMap().put(policy.getKey(), policy); - } - - return policies; - } - - @Override - public JsonElement serialize(@NonNull final ToscaPolicies policy, @NonNull final Type type, - @NonNull final JsonSerializationContext context) { - - return null; - } -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaPolicyJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaPolicyJsonAdapter.java deleted file mode 100644 index ae5e596ba..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaPolicyJsonAdapter.java +++ /dev/null @@ -1,85 +0,0 @@ -/*- - * ============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.serialization.simple; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import java.lang.reflect.Type; - -import javax.ws.rs.core.Response; - -import lombok.NonNull; - -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfModelRuntimeException; -import org.onap.policy.models.tosca.concepts.ToscaPolicy; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * GSON type adapter for TOSCA policies. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -public class ToscaPolicyJsonAdapter implements JsonSerializer, JsonDeserializer { - // Logger for this class - private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyJsonAdapter.class); - - @Override - public ToscaPolicy deserialize(@NonNull final JsonElement policyElement, @NonNull final Type type, - @NonNull final JsonDeserializationContext context) { - - // The incoming JSON - final JsonObject policyJsonMapObject = policyElement.getAsJsonObject(); - - // We should only have a single entry for the policy - if (policyJsonMapObject.entrySet().size() != 1) { - String errorMessage = "a policy list entry may only contain one and only one policy"; - LOGGER.debug(errorMessage); - throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, errorMessage); - } - - String policyName = policyJsonMapObject.entrySet().iterator().next().getKey(); - JsonObject policyJsonObject = policyJsonMapObject.entrySet().iterator().next().getValue().getAsJsonObject(); - - PfConceptKey policyKey = new PfConceptKey(policyName, policyJsonObject.get("version").getAsString()); - PfConceptKey policyTypeKey = new PfConceptKey( - policyJsonObject.get("type").getAsString(), - policyJsonObject.get("version").getAsString()); - ToscaPolicy policy = new ToscaPolicy(policyKey, policyTypeKey); - - // TODO: Rest of parsing - - return policy; - } - - @Override - public JsonElement serialize(@NonNull final ToscaPolicy policy, @NonNull final Type type, - @NonNull final JsonSerializationContext context) { - - return null; - } -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaServiceTemplateJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaServiceTemplateJsonAdapter.java deleted file mode 100644 index b08a33d64..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaServiceTemplateJsonAdapter.java +++ /dev/null @@ -1,75 +0,0 @@ -/*- - * ============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.serialization.simple; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import java.lang.reflect.Type; - -import lombok.NonNull; - -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.concepts.ToscaTopologyTemplate; - -/** - * GSON type adapter for TOSCA policies. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -public class ToscaServiceTemplateJsonAdapter - implements JsonSerializer, JsonDeserializer { - @Override - public ToscaServiceTemplate deserialize(@NonNull final JsonElement serviceTemplateElement, @NonNull final Type type, - @NonNull final JsonDeserializationContext context) { - - // The incoming JSON - final JsonObject serviceTemplateJsonObject = serviceTemplateElement.getAsJsonObject(); - - // The outgoing object - final PfConceptKey serviceTemplateKey = new PfConceptKey("IncomingServiceTemplate", "0.0.1"); - final ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(serviceTemplateKey); - serviceTemplate - .setToscaDefinitionsVersion(serviceTemplateJsonObject.get("tosca_definitions_version").getAsString()); - - if (serviceTemplateJsonObject.has("topology_template")) { - serviceTemplate.setTopologyTemplate(new ToscaTopologyTemplateJsonAdapter().deserialize( - serviceTemplateJsonObject.get("topology_template"), ToscaTopologyTemplate.class, context)); - } - - // Set the parent key of the topology template to be this service template - serviceTemplate.getTopologyTemplate().getKey().setParentConceptKey(serviceTemplateKey); - - return serviceTemplate; - } - - @Override - public JsonElement serialize(@NonNull final ToscaServiceTemplate serviceTemplate, @NonNull final Type type, - @NonNull final JsonSerializationContext context) { - - return null; - } -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaServiceTemplateMessageBodyHandler.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaServiceTemplateMessageBodyHandler.java deleted file mode 100644 index 9abbf1c72..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaServiceTemplateMessageBodyHandler.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============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. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.models.tosca.serialization.simple; - -import com.google.gson.GsonBuilder; - -import org.onap.policy.common.gson.GsonMessageBodyHandler; -import org.onap.policy.models.tosca.concepts.ToscaPolicies; -import org.onap.policy.models.tosca.concepts.ToscaPolicy; -import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.concepts.ToscaTopologyTemplate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Provider used to serialize and deserialize TOSCA objects using GSON. - */ -public class ToscaServiceTemplateMessageBodyHandler extends GsonMessageBodyHandler { - - public static final Logger logger = LoggerFactory.getLogger(ToscaServiceTemplateMessageBodyHandler.class); - - /** - * Constructs the object. - */ - public ToscaServiceTemplateMessageBodyHandler() { - this(new GsonBuilder()); - - logger.info("Using GSON with TOSCA for REST calls"); - } - - /** - * Constructs the object. - * - * @param builder builder to use to create the gson object - */ - public ToscaServiceTemplateMessageBodyHandler(final GsonBuilder builder) { - // @formatter:off - super(builder - .registerTypeAdapter(ToscaServiceTemplate.class, new ToscaServiceTemplateJsonAdapter()) - .registerTypeAdapter(ToscaTopologyTemplate.class, new ToscaTopologyTemplateJsonAdapter()) - .registerTypeAdapter(ToscaPolicies.class, new ToscaPoliciesJsonAdapter()) - .registerTypeAdapter(ToscaPolicy.class, new ToscaPolicyJsonAdapter()) - .create() - ); - // @formatter:on - } - -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaTopologyTemplateJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaTopologyTemplateJsonAdapter.java deleted file mode 100644 index 4f2f590b7..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/serialization/simple/ToscaTopologyTemplateJsonAdapter.java +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * ============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.serialization.simple; - -import com.google.gson.JsonDeserializationContext; -import com.google.gson.JsonDeserializer; -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonSerializationContext; -import com.google.gson.JsonSerializer; - -import java.lang.reflect.Type; - -import lombok.NonNull; - -import org.onap.policy.models.base.PfConceptKey; -import org.onap.policy.models.base.PfReferenceKey; -import org.onap.policy.models.tosca.concepts.ToscaPolicies; -import org.onap.policy.models.tosca.concepts.ToscaTopologyTemplate; - -/** - * GSON type adapter for TOSCA policies. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -public class ToscaTopologyTemplateJsonAdapter - implements JsonSerializer, JsonDeserializer { - - @Override - public ToscaTopologyTemplate deserialize(@NonNull final JsonElement toplogyTemplateElement, - @NonNull final Type type, @NonNull final JsonDeserializationContext context) { - - // The incoming JSON - final JsonObject topologyTemplateJsonObject = toplogyTemplateElement.getAsJsonObject(); - - // The outgoing object - final PfReferenceKey topologyTemplateKey = new PfReferenceKey(new PfConceptKey(), "IncomingTopologyTemplate"); - final ToscaTopologyTemplate topologyTemplate = new ToscaTopologyTemplate(topologyTemplateKey); - - if (topologyTemplateJsonObject.has("policies")) { - topologyTemplate.setPolicies(new ToscaPoliciesJsonAdapter() - .deserialize(topologyTemplateJsonObject.get("policies"), ToscaPolicies.class, context)); - } - - return topologyTemplate; - } - - @Override - public JsonElement serialize(@NonNull final ToscaTopologyTemplate topologyTemplate, @NonNull final Type type, - @NonNull final JsonSerializationContext context) { - - return null; - } -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraint.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraint.java new file mode 100644 index 000000000..ee153a295 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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 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/simple/concepts/ToscaConstraintLogical.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogical.java new file mode 100644 index 000000000..25a03c9e1 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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/simple/concepts/ToscaConstraintLogicalKey.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalKey.java new file mode 100644 index 000000000..0fe50dd71 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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 getKeys() { + final List 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/simple/concepts/ToscaConstraintLogicalString.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalString.java new file mode 100644 index 000000000..fbf036004 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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/simple/concepts/ToscaDataType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataType.java new file mode 100644 index 000000000..e7d91ea40 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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 constraints; + + @ElementCollection + private List 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 getKeys() { + final List 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 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 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/simple/concepts/ToscaDataTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypes.java new file mode 100644 index 000000000..cbf0e3844 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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 { + 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()); + } + + /** + * 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 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/simple/concepts/ToscaEntityType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntityType.java new file mode 100644 index 000000000..8b6dd40d6 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntityType.java @@ -0,0 +1,217 @@ +/*- + * ============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.simple.concepts; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; + +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.OneToMany; +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.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. + */ +@Entity +@Table(name = "ToscaEntityType") +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +@Data +@EqualsAndHashCode(callSuper = false) +public class ToscaEntityType extends PfConcept { + private static final long serialVersionUID = -1330661834220739393L; + + @EmbeddedId + private PfConceptKey key; + + @SerializedName("derived_from") + @Column(name = "derivedFrom") + private PfConceptKey derivedFrom; + + @OneToMany(cascade = CascadeType.ALL) + private Map metadata; + + @Column(name = "description") + private String description; + + /** + * The Default Constructor creates a {@link ToscaEntityType} object with a null key. + */ + public ToscaEntityType() { + this(new PfConceptKey()); + } + + /** + * The Key Constructor creates a {@link ToscaEntityType} object with the given concept key. + * + * @param key the key + */ + public ToscaEntityType(@NonNull final PfConceptKey key) { + this.key = key; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public ToscaEntityType(final ToscaEntityType copyConcept) { + super(copyConcept); + } + + @Override + public List getKeys() { + final List keyList = getKey().getKeys(); + if (derivedFrom != null) { + keyList.addAll(derivedFrom.getKeys()); + } + return keyList; + } + + @Override + public void clean() { + key.clean(); + + if (derivedFrom != null) { + derivedFrom.clean(); + } + + if (metadata != null) { + for (Entry metadataEntry : metadata.entrySet()) { + metadataEntry.setValue(metadataEntry.getValue().trim()); + } + } + + 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 (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 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 + 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 ToscaEntityType other = (ToscaEntityType) otherConcept; + if (!key.equals(other.key)) { + return key.compareTo(other.key); + } + + int result = ObjectUtils.compare(derivedFrom, other.derivedFrom); + if (result != 0) { + return result; + } + + result = PfUtils.compareObjects(metadata, other.metadata); + if (result != 0) { + return result; + } + + return ObjectUtils.compare(description, other.description); + } + + @Override + public PfConcept copyTo(@NonNull PfConcept target) { + final Object copyObject = target; + Assertions.instanceOf(copyObject, PfConcept.class); + + final ToscaEntityType copy = ((ToscaEntityType) copyObject); + copy.setKey(new PfConceptKey(key)); + copy.setDerivedFrom(derivedFrom != null ? new PfConceptKey(derivedFrom) : null); + + if (metadata != null) { + final Map newMatadata = new TreeMap<>(); + for (final Entry metadataEntry : metadata.entrySet()) { + newMatadata.put(metadataEntry.getKey(), metadataEntry.getValue()); + } + copy.setMetadata(newMatadata); + } + + copy.setDescription(description); + + return copy; + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntrySchema.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntrySchema.java new file mode 100644 index 000000000..2dca1ef55 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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 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 getKeys() { + final List 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 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/simple/concepts/ToscaEventFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEventFilter.java new file mode 100644 index 000000000..e2e5488e0 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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 getKeys() { + final List 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/simple/concepts/ToscaModel.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaModel.java new file mode 100644 index 000000000..a7852976d --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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. + * + *

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 getKeys() { + final List 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/simple/concepts/ToscaPolicies.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicies.java new file mode 100644 index 000000000..9dd12ec88 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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 { + 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()); + } + + /** + * 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 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/simple/concepts/ToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicy.java new file mode 100644 index 000000000..af94af08d --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicy.java @@ -0,0 +1,260 @@ +/*- + * ============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.simple.concepts; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +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.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 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 Map properties; + + @ElementCollection + private List 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 getKeys() { + final List keyList = super.getKeys(); + + keyList.addAll(type.getKeys()); + + if (targets != null) { + keyList.addAll(targets); + } + + return keyList; + } + + @Override + public void clean() { + super.clean(); + + type.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 (Entry propertyEntry : properties.entrySet()) { + if (!ParameterValidationUtils.validateStringParameter(propertyEntry.getKey())) { + result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, + "policy property key may not be null ")); + } else if (propertyEntry.getValue() == null) { + result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID, + "policy property value may not be null ")); + } + } + 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 { + copy.setProperties(properties); + } + + if (targets == null) { + copy.setTargets(null); + } else { + final List 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/simple/concepts/ToscaPolicyType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyType.java new file mode 100644 index 000000000..b155192cb --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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 properties; + + @ElementCollection + private List targets; + + @ElementCollection + private List 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 getKeys() { + final List 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 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 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 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/simple/concepts/ToscaPolicyTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypes.java new file mode 100644 index 000000000..23159ccfa --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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 { + 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()); + } + + /** + * 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 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/simple/concepts/ToscaProperty.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaProperty.java new file mode 100644 index 000000000..da13877c6 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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 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 getKeys() { + final List 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/simple/concepts/ToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplate.java new file mode 100644 index 000000000..fd8b134ce --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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 getKeys() { + final List 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/simple/concepts/ToscaServiceTemplates.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplates.java new file mode 100644 index 000000000..33d774889 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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 { + 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()); + } + + /** + * 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 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/simple/concepts/ToscaTimeInterval.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTimeInterval.java new file mode 100644 index 000000000..69c7c6c97 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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 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/simple/concepts/ToscaTopologyTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTopologyTemplate.java new file mode 100644 index 000000000..9d156c3df --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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.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; + +/** + * 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 PfReferenceKey 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 PfReferenceKey()); + } + + /** + * The Key Constructor creates a {@link ToscaTopologyTemplate} object with the given concept + * key. + * + * @param key the key + */ + public ToscaTopologyTemplate(@NonNull final PfReferenceKey key) { + this.key = key; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public ToscaTopologyTemplate(final ToscaTopologyTemplate copyConcept) { + super(copyConcept); + } + + @Override + public List getKeys() { + final List 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 PfReferenceKey(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/simple/concepts/ToscaTrigger.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTrigger.java new file mode 100644 index 000000000..d772d554e --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.simple.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 getKeys() { + final List 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/main/java/org/onap/policy/models/tosca/simple/mapping/ToscaServiceTemplateMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/mapping/ToscaServiceTemplateMapper.java new file mode 100644 index 000000000..6dcbfe694 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/mapping/ToscaServiceTemplateMapper.java @@ -0,0 +1,49 @@ +/*- + * ============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.simple.mapping; + +import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; + +/** + * This interface is used to map legacy and proprietary policies into and out of TOSCA service templates. + * + * @author Liam Fallon (liam.fallon@est.tech) + * @param the type for the incoming policy definition + * @param the type for the outgoing policy definition + */ +public interface ToscaServiceTemplateMapper { + + /** + * Translate from the other format to a TOSCA service template. + * + * @param otherPolicyType the other policy type + * @return the TOSCA service template + */ + public ToscaServiceTemplate toToscaServiceTemplate(final I otherPolicyType); + + /** + * Translate to the other format from a TOSCA service template. + * + * @param serviceTemplate the TOSCA service template + * @return the policy in the other format + */ + public O fromToscaServiceTemplate(final ToscaServiceTemplate serviceTemplate); +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPoliciesJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPoliciesJsonAdapter.java new file mode 100644 index 000000000..2b61b6861 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPoliciesJsonAdapter.java @@ -0,0 +1,72 @@ +/*- + * ============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.simple.serialization; + +import com.google.gson.JsonArray; +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; +import java.util.Iterator; + +import lombok.NonNull; + +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy; + +/** + * GSON type adapter for TOSCA policies. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class ToscaPoliciesJsonAdapter implements JsonSerializer, JsonDeserializer { + @Override + public ToscaPolicies deserialize(@NonNull final JsonElement policiesElement, @NonNull final Type type, + @NonNull final JsonDeserializationContext context) { + // The incoming JSON + final JsonArray policiesJsonArray = policiesElement.getAsJsonArray(); + + // The outgoing object + final PfConceptKey policiesKey = new PfConceptKey("IncomingPolicies", "0.0.1"); + final ToscaPolicies policies = new ToscaPolicies(policiesKey); + + // Get the policies + for (Iterator policiesIterator = policiesJsonArray.iterator(); policiesIterator.hasNext(); ) { + ToscaPolicy policy = new ToscaPolicyJsonAdapter() + .deserialize(policiesIterator.next(), ToscaPolicy.class, context); + + policies.getConceptMap().put(policy.getKey(), policy); + } + + return policies; + } + + @Override + public JsonElement serialize(@NonNull final ToscaPolicies policy, @NonNull final Type type, + @NonNull final JsonSerializationContext context) { + + return null; + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyJsonAdapter.java new file mode 100644 index 000000000..075445d01 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyJsonAdapter.java @@ -0,0 +1,85 @@ +/*- + * ============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.simple.serialization; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +import javax.ws.rs.core.Response; + +import lombok.NonNull; + +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfModelRuntimeException; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * GSON type adapter for TOSCA policies. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class ToscaPolicyJsonAdapter implements JsonSerializer, JsonDeserializer { + // Logger for this class + private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyJsonAdapter.class); + + @Override + public ToscaPolicy deserialize(@NonNull final JsonElement policyElement, @NonNull final Type type, + @NonNull final JsonDeserializationContext context) { + + // The incoming JSON + final JsonObject policyJsonMapObject = policyElement.getAsJsonObject(); + + // We should only have a single entry for the policy + if (policyJsonMapObject.entrySet().size() != 1) { + String errorMessage = "a policy list entry may only contain one and only one policy"; + LOGGER.debug(errorMessage); + throw new PfModelRuntimeException(Response.Status.NOT_ACCEPTABLE, errorMessage); + } + + String policyName = policyJsonMapObject.entrySet().iterator().next().getKey(); + JsonObject policyJsonObject = policyJsonMapObject.entrySet().iterator().next().getValue().getAsJsonObject(); + + PfConceptKey policyKey = new PfConceptKey(policyName, policyJsonObject.get("version").getAsString()); + PfConceptKey policyTypeKey = new PfConceptKey( + policyJsonObject.get("type").getAsString(), + policyJsonObject.get("version").getAsString()); + ToscaPolicy policy = new ToscaPolicy(policyKey, policyTypeKey); + + // TODO: Rest of parsing + + return policy; + } + + @Override + public JsonElement serialize(@NonNull final ToscaPolicy policy, @NonNull final Type type, + @NonNull final JsonSerializationContext context) { + + return null; + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateJsonAdapter.java new file mode 100644 index 000000000..286bb7492 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateJsonAdapter.java @@ -0,0 +1,75 @@ +/*- + * ============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.simple.serialization; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +import lombok.NonNull; + +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate; + +/** + * GSON type adapter for TOSCA policies. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class ToscaServiceTemplateJsonAdapter + implements JsonSerializer, JsonDeserializer { + @Override + public ToscaServiceTemplate deserialize(@NonNull final JsonElement serviceTemplateElement, @NonNull final Type type, + @NonNull final JsonDeserializationContext context) { + + // The incoming JSON + final JsonObject serviceTemplateJsonObject = serviceTemplateElement.getAsJsonObject(); + + // The outgoing object + final PfConceptKey serviceTemplateKey = new PfConceptKey("IncomingServiceTemplate", "0.0.1"); + final ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(serviceTemplateKey); + serviceTemplate + .setToscaDefinitionsVersion(serviceTemplateJsonObject.get("tosca_definitions_version").getAsString()); + + if (serviceTemplateJsonObject.has("topology_template")) { + serviceTemplate.setTopologyTemplate(new ToscaTopologyTemplateJsonAdapter().deserialize( + serviceTemplateJsonObject.get("topology_template"), ToscaTopologyTemplate.class, context)); + } + + // Set the parent key of the topology template to be this service template + serviceTemplate.getTopologyTemplate().getKey().setParentConceptKey(serviceTemplateKey); + + return serviceTemplate; + } + + @Override + public JsonElement serialize(@NonNull final ToscaServiceTemplate serviceTemplate, @NonNull final Type type, + @NonNull final JsonSerializationContext context) { + + return null; + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateMessageBodyHandler.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateMessageBodyHandler.java new file mode 100644 index 000000000..a386a9cc5 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaServiceTemplateMessageBodyHandler.java @@ -0,0 +1,64 @@ +/*- + * ============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. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.tosca.simple.serialization; + +import com.google.gson.GsonBuilder; + +import org.onap.policy.common.gson.GsonMessageBodyHandler; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Provider used to serialize and deserialize TOSCA objects using GSON. + */ +public class ToscaServiceTemplateMessageBodyHandler extends GsonMessageBodyHandler { + + public static final Logger logger = LoggerFactory.getLogger(ToscaServiceTemplateMessageBodyHandler.class); + + /** + * Constructs the object. + */ + public ToscaServiceTemplateMessageBodyHandler() { + this(new GsonBuilder()); + + logger.info("Using GSON with TOSCA for REST calls"); + } + + /** + * Constructs the object. + * + * @param builder builder to use to create the gson object + */ + public ToscaServiceTemplateMessageBodyHandler(final GsonBuilder builder) { + // @formatter:off + super(builder + .registerTypeAdapter(ToscaServiceTemplate.class, new ToscaServiceTemplateJsonAdapter()) + .registerTypeAdapter(ToscaTopologyTemplate.class, new ToscaTopologyTemplateJsonAdapter()) + .registerTypeAdapter(ToscaPolicies.class, new ToscaPoliciesJsonAdapter()) + .registerTypeAdapter(ToscaPolicy.class, new ToscaPolicyJsonAdapter()) + .create() + ); + // @formatter:on + } + +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaTopologyTemplateJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaTopologyTemplateJsonAdapter.java new file mode 100644 index 000000000..c76b9b027 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaTopologyTemplateJsonAdapter.java @@ -0,0 +1,72 @@ +/*- + * ============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.simple.serialization; + +import com.google.gson.JsonDeserializationContext; +import com.google.gson.JsonDeserializer; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import com.google.gson.JsonSerializationContext; +import com.google.gson.JsonSerializer; + +import java.lang.reflect.Type; + +import lombok.NonNull; + +import org.onap.policy.models.base.PfConceptKey; +import org.onap.policy.models.base.PfReferenceKey; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate; + +/** + * GSON type adapter for TOSCA policies. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class ToscaTopologyTemplateJsonAdapter + implements JsonSerializer, JsonDeserializer { + + @Override + public ToscaTopologyTemplate deserialize(@NonNull final JsonElement toplogyTemplateElement, + @NonNull final Type type, @NonNull final JsonDeserializationContext context) { + + // The incoming JSON + final JsonObject topologyTemplateJsonObject = toplogyTemplateElement.getAsJsonObject(); + + // The outgoing object + final PfReferenceKey topologyTemplateKey = new PfReferenceKey(new PfConceptKey(), "IncomingTopologyTemplate"); + final ToscaTopologyTemplate topologyTemplate = new ToscaTopologyTemplate(topologyTemplateKey); + + if (topologyTemplateJsonObject.has("policies")) { + topologyTemplate.setPolicies(new ToscaPoliciesJsonAdapter() + .deserialize(topologyTemplateJsonObject.get("policies"), ToscaPolicies.class, context)); + } + + return topologyTemplate; + } + + @Override + public JsonElement serialize(@NonNull final ToscaTopologyTemplate topologyTemplate, @NonNull final Type type, + @NonNull final JsonSerializationContext context) { + + return null; + } +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/TestPojos.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/TestPojos.java deleted file mode 100644 index d5b5f55b3..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/TestPojos.java +++ /dev/null @@ -1,53 +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.concepts; - -import com.openpojo.reflection.filters.FilterPackageInfo; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.rule.impl.GetterMustExistRule; -import com.openpojo.validation.rule.impl.SetterMustExistRule; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; - -import org.junit.Test; -import org.onap.policy.common.utils.validation.ToStringTester; - -/** - * Class to perform unit tests of all pojos. - * - * @author Chenfei Gao (cgao@research.att.com) - * - */ -public class TestPojos { - - private static final String POJO_PACKAGE = "org.onap.policy.models.tosca.concepts"; - - @Test - public void testPojos() { - final Validator validator = ValidatorBuilder.create().with(new ToStringTester()) - .with(new SetterMustExistRule()).with(new GetterMustExistRule()).with(new SetterTester()) - .with(new GetterTester()).build(); - validator.validate(POJO_PACKAGE, new FilterPackageInfo()); - } -} 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 deleted file mode 100644 index 60c6eb976..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalKeyTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/*- - * ============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 deleted file mode 100644 index 5d0fe9332..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalStringTest.java +++ /dev/null @@ -1,133 +0,0 @@ -/*- - * ============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 deleted file mode 100644 index fc623f1dd..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaConstraintLogicalTest.java +++ /dev/null @@ -1,166 +0,0 @@ -/*- - * ============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 deleted file mode 100644 index d0b9c7d9b..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaDataTypeTest.java +++ /dev/null @@ -1,140 +0,0 @@ -/*- - * ============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 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 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 deleted file mode 100644 index cd9c53e7c..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaDataTypesTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============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())); - 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()); - 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 deleted file mode 100644 index 97d71a203..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaEntrySchemaTest.java +++ /dev/null @@ -1,147 +0,0 @@ -/*- - * ============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 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 deleted file mode 100644 index a45d65d69..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaEventFilterTest.java +++ /dev/null @@ -1,165 +0,0 @@ -/*- - * ============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 deleted file mode 100644 index ca6445f13..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaModelTest.java +++ /dev/null @@ -1,142 +0,0 @@ -/*- - * ============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 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 deleted file mode 100644 index 76fdd538b..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPoliciesTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============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())); - 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()); - 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 deleted file mode 100644 index 295c0f2fd..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/*- - * ============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 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 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 deleted file mode 100644 index 7926bfe78..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypeTest.java +++ /dev/null @@ -1,208 +0,0 @@ -/*- - * ============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 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 properties = new ArrayList<>(); - ToscaProperty tp = new ToscaProperty(new PfReferenceKey(ptKey, "aProp"), propTypeKey); - properties.add(tp); - tpt.setProperties(properties); - assertEquals(properties, tpt.getProperties()); - - List targets = new ArrayList<>(); - PfConceptKey target = new PfConceptKey("target", "0.0.1"); - targets.add(target); - tpt.setTargets(targets); - assertEquals(targets, tpt.getTargets()); - - List 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 deleted file mode 100644 index 069346331..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPolicyTypesTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============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())); - 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()); - 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 deleted file mode 100644 index d0563fd26..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaPropertyTest.java +++ /dev/null @@ -1,223 +0,0 @@ -/*- - * ============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 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 deleted file mode 100644 index 5d8615814..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplateTest.java +++ /dev/null @@ -1,171 +0,0 @@ -/*- - * ============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.PfReferenceKey; -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 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 policyTypeMap = new TreeMap<>(); - policyTypeMap.put(policyTypeKey, policyType0); - ToscaPolicyTypes policyTypes = new ToscaPolicyTypes(ptsKey, policyTypeMap); - tst.setPolicyTypes(policyTypes); - assertEquals(policyTypes, tst.getPolicyTypes()); - - PfReferenceKey tttKey = new PfReferenceKey(tstKey, "TopologyTemplate"); - 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 deleted file mode 100644 index c866f11c7..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaServiceTemplatesTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/*- - * ============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())); - 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()); - 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 deleted file mode 100644 index 33af68343..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTimeIntervalTest.java +++ /dev/null @@ -1,181 +0,0 @@ -/*- - * ============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 deleted file mode 100644 index 97bbdbe71..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTopologyTemplateTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/*- - * ============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.PfReferenceKey; -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 PfReferenceKey())); - assertNotNull(new ToscaTopologyTemplate(new ToscaTopologyTemplate())); - - try { - new ToscaTopologyTemplate((PfReferenceKey) 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()); - } - - PfReferenceKey tttKey = new PfReferenceKey("tst", "0.0.1", "ttt"); - 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 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); - - PfReferenceKey otherDtKey = new PfReferenceKey("otherSt", "0.0.1", "otherDt"); - 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 deleted file mode 100644 index d1423a6a4..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/ToscaTriggerTest.java +++ /dev/null @@ -1,228 +0,0 @@ -/*- - * ============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 deleted file mode 100644 index 3b27e1565..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/concepts/testconcepts/DummyToscaConstraint.java +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * ============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/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java new file mode 100644 index 000000000..d2b2216e7 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java @@ -0,0 +1,52 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.models.tosca.legacy.concepts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +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.tosca.legacy.concepts.LegacyGuardPolicy; + +public class LegacyGuardPolicyTest { + + @Test + public void test() { + LegacyGuardPolicy guard = new LegacyGuardPolicy(); + assertNotNull(guard); + guard.setPolicyId("guard.frequency"); + assertEquals("guard.frequency", guard.getPolicyId()); + guard.setPolicyVersion("1"); + assertEquals("1", guard.getPolicyVersion()); + Map body = new HashMap<>(); + body.put("actor", "SO"); + List> content = new ArrayList<>(); + content.add(body); + guard.setContent(content); + assertEquals(1, guard.getContent().size()); + } + +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicyTest.java new file mode 100644 index 000000000..36cea6372 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyOperationalPolicyTest.java @@ -0,0 +1,44 @@ +/*- + * ============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========================================================= + */ + +package org.onap.policy.models.tosca.legacy.concepts; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; + +public class LegacyOperationalPolicyTest { + + @Test + public void test() { + LegacyOperationalPolicy policy = new LegacyOperationalPolicy(); + assertNotNull(policy); + policy.setPolicyId("onap.scaleout"); + assertEquals("onap.scaleout", policy.getPolicyId()); + policy.setPolicyVersion("1"); + assertEquals("1", policy.getPolicyVersion()); + policy.setContent("controlLoop%3A%0A%20%20"); + assertTrue(policy.getContent().length() > 0); + } + +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/serialization/LegacyOperationalPolicySerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/serialization/LegacyOperationalPolicySerializationTest.java new file mode 100644 index 000000000..76721046e --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/serialization/LegacyOperationalPolicySerializationTest.java @@ -0,0 +1,74 @@ +/*- + * ============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.legacy.serialization; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.common.utils.resources.TextFileUtils; +import org.onap.policy.models.base.PfValidationResult; +import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; +import org.onap.policy.models.tosca.legacy.mapping.LegacyOperationalPolicyMapper; +import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Test serialization of monitoring policies. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class LegacyOperationalPolicySerializationTest { + // Logger for this class + private static final Logger LOGGER = LoggerFactory.getLogger(LegacyOperationalPolicySerializationTest.class); + + private Gson gson; + + @Before + public void setUp() { + gson = new Gson(); + } + + @Test + public void testJsonDeserialization() throws JsonSyntaxException, IOException { + LegacyOperationalPolicy legacyOperationalPolicy = gson.fromJson( + TextFileUtils.getTextFileAsString("src/test/resources/policies/vCPE.policy.operational.input.json"), + LegacyOperationalPolicy.class); + + ToscaServiceTemplate serviceTemplate = + new LegacyOperationalPolicyMapper().toToscaServiceTemplate(legacyOperationalPolicy); + + assertNotNull(serviceTemplate); + LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString()); + assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid()); + + assertEquals("operational.restart:1.0.1", + serviceTemplate.getTopologyTemplate().getPolicies().get("operational.restart").getId()); + } +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/serialization/MonitoringPolicySerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/serialization/MonitoringPolicySerializationTest.java deleted file mode 100644 index 8d0c8d440..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/serialization/MonitoringPolicySerializationTest.java +++ /dev/null @@ -1,94 +0,0 @@ -/*- - * ============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.serialization; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import com.google.gson.Gson; -import com.google.gson.JsonSyntaxException; - -import java.io.IOException; - -import org.junit.Before; -import org.junit.Test; -import org.onap.policy.common.utils.resources.TextFileUtils; -import org.onap.policy.models.base.PfValidationResult; -import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.serialization.simple.ToscaServiceTemplateMessageBodyHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.yaml.snakeyaml.Yaml; - -/** - * Test serialization of monitoring policies. - * - * @author Liam Fallon (liam.fallon@est.tech) - */ -public class MonitoringPolicySerializationTest { - // Logger for this class - private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringPolicySerializationTest.class); - - private Gson gson; - - @Before - public void setUp() { - gson = new ToscaServiceTemplateMessageBodyHandler().getGson(); - } - - @Test - public void testJsonDeserialization() throws JsonSyntaxException, IOException { - ToscaServiceTemplate serviceTemplate = gson.fromJson( - TextFileUtils - .getTextFileAsString("src/test/resources/policies/vCPE.policy.monitoring.input.tosca.json"), - ToscaServiceTemplate.class); - - assertNotNull(serviceTemplate); - LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString()); - assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid()); - - assertEquals("onap.restart.tca:1.0.0", - serviceTemplate.getTopologyTemplate().getPolicies().get("onap.restart.tca").getId()); - assertEquals("onap.restart.tca:1.0.0", - serviceTemplate.getTopologyTemplate().getPolicies().get("onap.restart.tca").getId()); - } - - @Test - public void testYamlDeserialization() throws JsonSyntaxException, IOException { - Yaml yaml = new Yaml(); - Object yamlObject = yaml.load(TextFileUtils - .getTextFileAsString("src/test/resources/policies/vCPE.policy.monitoring.input.tosca.yaml")); - - String yamlAsJsonString = new Gson().toJson(yamlObject); - - ToscaServiceTemplate serviceTemplate = gson.fromJson(yamlAsJsonString, ToscaServiceTemplate.class); - - assertNotNull(serviceTemplate); - LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString()); - assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid()); - - assertEquals("onap.restart.tca:1.0.0", - serviceTemplate.getTopologyTemplate().getPolicies().get("onap.restart.tca").getId()); - assertEquals("onap.restart.tca:1.0.0", - serviceTemplate.getTopologyTemplate().getPolicies().get("onap.restart.tca").getId()); - } -} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardPolicyTest.java deleted file mode 100644 index fa082331a..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/serialization/legacy/LegacyGuardPolicyTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============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========================================================= - */ - -package org.onap.policy.models.tosca.serialization.legacy; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Test; - -public class LegacyGuardPolicyTest { - - @Test - public void test() { - LegacyGuardPolicy guard = new LegacyGuardPolicy(); - assertNotNull(guard); - guard.setPolicyId("guard.frequency"); - assertEquals("guard.frequency", guard.getPolicyId()); - guard.setPolicyVersion("1"); - assertEquals("1", guard.getPolicyVersion()); - Map body = new HashMap<>(); - body.put("actor", "SO"); - List> content = new ArrayList<>(); - content.add(body); - guard.setContent(content); - assertEquals(1, guard.getContent().size()); - } - -} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalPolicyTest.java deleted file mode 100644 index 13da63247..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/serialization/legacy/LegacyOperationalPolicyTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/*- - * ============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========================================================= - */ - -package org.onap.policy.models.tosca.serialization.legacy; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -public class LegacyOperationalPolicyTest { - - @Test - public void test() { - LegacyOperationalPolicy policy = new LegacyOperationalPolicy(); - assertNotNull(policy); - policy.setPolicyId("onap.scaleout"); - assertEquals("onap.scaleout", policy.getPolicyId()); - policy.setPolicyVersion("1"); - assertEquals("1", policy.getPolicyVersion()); - policy.setContent("controlLoop%3A%0A%20%20"); - assertTrue(policy.getContent().length() > 0); - } - -} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/TestPojos.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/TestPojos.java new file mode 100644 index 000000000..b3bdedf1c --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/TestPojos.java @@ -0,0 +1,53 @@ +/*- + * ============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.simple.concepts; + +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +import org.junit.Test; +import org.onap.policy.common.utils.validation.ToStringTester; + +/** + * Class to perform unit tests of all pojos. + * + * @author Chenfei Gao (cgao@research.att.com) + * + */ +public class TestPojos { + + private static final String POJO_PACKAGE = "org.onap.policy.models.tosca.simple.concepts"; + + @Test + public void testPojos() { + final Validator validator = ValidatorBuilder.create().with(new ToStringTester()) + .with(new SetterMustExistRule()).with(new GetterMustExistRule()).with(new SetterTester()) + .with(new GetterTester()).build(); + validator.validate(POJO_PACKAGE, new FilterPackageInfo()); + } +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalKeyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalKeyTest.java new file mode 100644 index 000000000..35a1c0a99 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalKeyTest.java @@ -0,0 +1,135 @@ +/*- + * ============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.simple.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.simple.concepts.ToscaConstraintLogicalKey; + +/** + * 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/simple/concepts/ToscaConstraintLogicalStringTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalStringTest.java new file mode 100644 index 000000000..764a6f46b --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalStringTest.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.simple.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.simple.concepts.ToscaConstraintLogicalString; + +/** + * 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/simple/concepts/ToscaConstraintLogicalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalTest.java new file mode 100644 index 000000000..d1617204a --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalTest.java @@ -0,0 +1,167 @@ +/*- + * ============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.simple.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.simple.concepts.ToscaConstraintLogical; +import org.onap.policy.models.tosca.simple.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/simple/concepts/ToscaDataTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypeTest.java new file mode 100644 index 000000000..5adeece5b --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypeTest.java @@ -0,0 +1,144 @@ +/*- + * ============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.simple.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.simple.concepts.ToscaConstraint; +import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogical.Operation; +import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogicalString; +import org.onap.policy.models.tosca.simple.concepts.ToscaDataType; +import org.onap.policy.models.tosca.simple.concepts.ToscaProperty; + +/** + * 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 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 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/simple/concepts/ToscaDataTypesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypesTest.java new file mode 100644 index 000000000..b92b6b08a --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypesTest.java @@ -0,0 +1,78 @@ +/*- + * ============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.simple.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; +import org.onap.policy.models.tosca.simple.concepts.ToscaDataType; +import org.onap.policy.models.tosca.simple.concepts.ToscaDataTypes; + +public class ToscaDataTypesTest { + + @Test + public void testDataTypes() { + assertNotNull(new ToscaDataTypes()); + assertNotNull(new ToscaDataTypes(new PfConceptKey())); + assertNotNull(new ToscaDataTypes(new PfConceptKey(), new TreeMap())); + 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()); + 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/simple/concepts/ToscaEntrySchemaTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntrySchemaTest.java new file mode 100644 index 000000000..e1a9f0c6f --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntrySchemaTest.java @@ -0,0 +1,150 @@ +/*- + * ============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.simple.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.simple.concepts.ToscaConstraint; +import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogical.Operation; +import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogicalString; +import org.onap.policy.models.tosca.simple.concepts.ToscaEntrySchema; + +/** + * 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 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/simple/concepts/ToscaEventFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaEventFilterTest.java new file mode 100644 index 000000000..b1fb33fce --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaEventFilterTest.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.simple.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.simple.concepts.ToscaEventFilter; + +/** + * 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/simple/concepts/ToscaModelTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaModelTest.java new file mode 100644 index 000000000..af8cc2d3b --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaModelTest.java @@ -0,0 +1,145 @@ +/*- + * ============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.simple.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; +import org.onap.policy.models.tosca.simple.concepts.ToscaModel; +import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplates; + +/** + * 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 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/simple/concepts/ToscaPoliciesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPoliciesTest.java new file mode 100644 index 000000000..127aac4f4 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPoliciesTest.java @@ -0,0 +1,78 @@ +/*- + * ============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.simple.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; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy; + +public class ToscaPoliciesTest { + + @Test + public void testPolicies() { + assertNotNull(new ToscaPolicies()); + assertNotNull(new ToscaPolicies(new PfConceptKey())); + assertNotNull(new ToscaPolicies(new PfConceptKey(), new TreeMap())); + 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()); + 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/simple/concepts/ToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTest.java new file mode 100644 index 000000000..7af5cc754 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTest.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.tosca.simple.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.PfValidationResult; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy; + +/** + * 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); + + Map propertyMap = new HashMap<>(); + propertyMap.put("Property", "Property Value"); + tp.setProperties(propertyMap); + assertEquals(propertyMap, tp.getProperties()); + + List 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(propertyMap); + 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(3, tp.getKeys().size()); + assertEquals(2, new ToscaPolicy().getKeys().size()); + + new ToscaPolicy().clean(); + tp.clean(); + assertEquals(tdtClone0, tp); + + assertFalse(new ToscaPolicy().validate(new PfValidationResult()).isValid()); + System.err.println(tp.validate(new PfValidationResult())); + assertTrue(tp.validate(new PfValidationResult()).isValid()); + + tp.getProperties().put(null, null); + assertFalse(tp.validate(new PfValidationResult()).isValid()); + tp.getProperties().remove(null); + assertTrue(tp.validate(new PfValidationResult()).isValid()); + + tp.getProperties().put("Key", null); + assertFalse(tp.validate(new PfValidationResult()).isValid()); + tp.getProperties().remove("Key"); + assertTrue(tp.validate(new PfValidationResult()).isValid()); + + tp.getProperties().put(null, "Value"); + 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/simple/concepts/ToscaPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypeTest.java new file mode 100644 index 000000000..3be0cff3d --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypeTest.java @@ -0,0 +1,212 @@ +/*- + * ============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.simple.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; +import org.onap.policy.models.tosca.simple.concepts.ToscaEntityType; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicyType; +import org.onap.policy.models.tosca.simple.concepts.ToscaProperty; +import org.onap.policy.models.tosca.simple.concepts.ToscaTrigger; + +/** + * 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 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 properties = new ArrayList<>(); + ToscaProperty tp = new ToscaProperty(new PfReferenceKey(ptKey, "aProp"), propTypeKey); + properties.add(tp); + tpt.setProperties(properties); + assertEquals(properties, tpt.getProperties()); + + List targets = new ArrayList<>(); + PfConceptKey target = new PfConceptKey("target", "0.0.1"); + targets.add(target); + tpt.setTargets(targets); + assertEquals(targets, tpt.getTargets()); + + List 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/simple/concepts/ToscaPolicyTypesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypesTest.java new file mode 100644 index 000000000..a85c8285e --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypesTest.java @@ -0,0 +1,78 @@ +/*- + * ============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.simple.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; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicyType; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicyTypes; + +public class ToscaPolicyTypesTest { + + @Test + public void testPolicyTypes() { + assertNotNull(new ToscaPolicyTypes()); + assertNotNull(new ToscaPolicyTypes(new PfConceptKey())); + assertNotNull(new ToscaPolicyTypes(new PfConceptKey(), new TreeMap())); + 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()); + 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/simple/concepts/ToscaPropertyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPropertyTest.java new file mode 100644 index 000000000..a33da605e --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPropertyTest.java @@ -0,0 +1,227 @@ +/*- + * ============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.simple.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.simple.concepts.ToscaConstraint; +import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogical.Operation; +import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogicalString; +import org.onap.policy.models.tosca.simple.concepts.ToscaEntrySchema; +import org.onap.policy.models.tosca.simple.concepts.ToscaProperty; + +/** + * 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 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/simple/concepts/ToscaServiceTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplateTest.java new file mode 100644 index 000000000..aad410e89 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplateTest.java @@ -0,0 +1,177 @@ +/*- + * ============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.simple.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.PfReferenceKey; +import org.onap.policy.models.base.PfValidationResult; +import org.onap.policy.models.tosca.simple.concepts.ToscaDataType; +import org.onap.policy.models.tosca.simple.concepts.ToscaDataTypes; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicyType; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicyTypes; +import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate; + +/** + * 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 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 policyTypeMap = new TreeMap<>(); + policyTypeMap.put(policyTypeKey, policyType0); + ToscaPolicyTypes policyTypes = new ToscaPolicyTypes(ptsKey, policyTypeMap); + tst.setPolicyTypes(policyTypes); + assertEquals(policyTypes, tst.getPolicyTypes()); + + PfReferenceKey tttKey = new PfReferenceKey(tstKey, "TopologyTemplate"); + 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/simple/concepts/ToscaServiceTemplatesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplatesTest.java new file mode 100644 index 000000000..2864be829 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplatesTest.java @@ -0,0 +1,78 @@ +/*- + * ============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.simple.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; +import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplates; + +public class ToscaServiceTemplatesTest { + + @Test + public void testServiceTemplates() { + assertNotNull(new ToscaServiceTemplates()); + assertNotNull(new ToscaServiceTemplates(new PfConceptKey())); + assertNotNull(new ToscaServiceTemplates(new PfConceptKey(), new TreeMap())); + 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()); + 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/simple/concepts/ToscaTimeIntervalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaTimeIntervalTest.java new file mode 100644 index 000000000..cbfde2d11 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaTimeIntervalTest.java @@ -0,0 +1,182 @@ +/*- + * ============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.simple.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; +import org.onap.policy.models.tosca.simple.concepts.ToscaTimeInterval; + +/** + * 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/simple/concepts/ToscaTopologyTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaTopologyTemplateTest.java new file mode 100644 index 000000000..3ea225d19 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaTopologyTemplateTest.java @@ -0,0 +1,138 @@ +/*- + * ============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.simple.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.PfReferenceKey; +import org.onap.policy.models.base.PfValidationResult; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy; +import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate; + +/** + * 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 PfReferenceKey())); + assertNotNull(new ToscaTopologyTemplate(new ToscaTopologyTemplate())); + + try { + new ToscaTopologyTemplate((PfReferenceKey) 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()); + } + + PfReferenceKey tttKey = new PfReferenceKey("tst", "0.0.1", "ttt"); + 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 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); + + PfReferenceKey otherDtKey = new PfReferenceKey("otherSt", "0.0.1", "otherDt"); + 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/simple/concepts/ToscaTriggerTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaTriggerTest.java new file mode 100644 index 000000000..be60165ff --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaTriggerTest.java @@ -0,0 +1,232 @@ +/*- + * ============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.simple.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.simple.concepts.ToscaConstraintLogical.Operation; +import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogicalString; +import org.onap.policy.models.tosca.simple.concepts.ToscaEventFilter; +import org.onap.policy.models.tosca.simple.concepts.ToscaTimeInterval; +import org.onap.policy.models.tosca.simple.concepts.ToscaTrigger; + +/** + * 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/simple/concepts/testconcepts/DummyToscaConstraint.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java new file mode 100644 index 000000000..2e03fd215 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/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.simple.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.simple.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/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java new file mode 100644 index 000000000..9977f3b72 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java @@ -0,0 +1,94 @@ +/*- + * ============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.simple.serialization; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import com.google.gson.Gson; +import com.google.gson.JsonSyntaxException; + +import java.io.IOException; + +import org.junit.Before; +import org.junit.Test; +import org.onap.policy.common.utils.resources.TextFileUtils; +import org.onap.policy.models.base.PfValidationResult; +import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; + +/** + * Test serialization of monitoring policies. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class MonitoringPolicySerializationTest { + // Logger for this class + private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringPolicySerializationTest.class); + + private Gson gson; + + @Before + public void setUp() { + gson = new ToscaServiceTemplateMessageBodyHandler().getGson(); + } + + @Test + public void testJsonDeserialization() throws JsonSyntaxException, IOException { + ToscaServiceTemplate serviceTemplate = gson.fromJson( + TextFileUtils + .getTextFileAsString("src/test/resources/policies/vCPE.policy.monitoring.input.tosca.json"), + ToscaServiceTemplate.class); + + assertNotNull(serviceTemplate); + LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString()); + assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid()); + + assertEquals("onap.restart.tca:1.0.0", + serviceTemplate.getTopologyTemplate().getPolicies().get("onap.restart.tca").getId()); + assertEquals("onap.restart.tca:1.0.0", + serviceTemplate.getTopologyTemplate().getPolicies().get("onap.restart.tca").getId()); + } + + @Test + public void testYamlDeserialization() throws JsonSyntaxException, IOException { + Yaml yaml = new Yaml(); + Object yamlObject = yaml.load(TextFileUtils + .getTextFileAsString("src/test/resources/policies/vCPE.policy.monitoring.input.tosca.yaml")); + + String yamlAsJsonString = new Gson().toJson(yamlObject); + + ToscaServiceTemplate serviceTemplate = gson.fromJson(yamlAsJsonString, ToscaServiceTemplate.class); + + assertNotNull(serviceTemplate); + LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString()); + assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid()); + + assertEquals("onap.restart.tca:1.0.0", + serviceTemplate.getTopologyTemplate().getPolicies().get("onap.restart.tca").getId()); + assertEquals("onap.restart.tca:1.0.0", + serviceTemplate.getTopologyTemplate().getPolicies().get("onap.restart.tca").getId()); + } +} -- cgit 1.2.3-korg