From cc5b96bfd33cd7d91fe6994d348e8d6a0ebb54fa Mon Sep 17 00:00:00 2001 From: liamfallon Date: Fri, 29 Mar 2019 10:31:22 +0000 Subject: Restructure for authorative models Use authorative models instead of the JPA stored models as the venacular models in the Policy Framework. The next step is to pass the authorative objects over the provider interface rather than the JPA obejcts. This change will be made in the next review. Minor changes to pdp objects to remove JPA things from them. These object will be the authorative in-memory obejcts on the PDP side and new JPA entity object will be introduced in a future review to persist them. Issue-ID: POLICY-1095 Change-Id: I40e7b713903980cb41bb315417111b67a9b17307 Signed-off-by: liamfallon --- .../authorative/concepts/PlainToscaConstraint.java | 41 --- .../authorative/concepts/PlainToscaDataType.java | 47 --- .../concepts/PlainToscaEntrySchema.java | 41 --- .../authorative/concepts/PlainToscaPolicy.java | 45 --- .../authorative/concepts/PlainToscaPolicyType.java | 47 --- .../authorative/concepts/PlainToscaProperty.java | 50 --- .../concepts/PlainToscaServiceTemplate.java | 49 --- .../concepts/PlainToscaTopologyTemplate.java | 40 --- .../authorative/concepts/ToscaConstraint.java | 41 +++ .../tosca/authorative/concepts/ToscaDataType.java | 47 +++ .../authorative/concepts/ToscaEntrySchema.java | 41 +++ .../tosca/authorative/concepts/ToscaPolicy.java | 62 ++++ .../authorative/concepts/ToscaPolicyType.java | 47 +++ .../tosca/authorative/concepts/ToscaProperty.java | 50 +++ .../authorative/concepts/ToscaServiceTemplate.java | 49 +++ .../concepts/ToscaTopologyTemplate.java | 40 +++ .../mapping/PlainToscaServiceTemplateMapper.java | 16 +- .../legacy/mapping/LegacyGuardPolicyMapper.java | 28 +- .../mapping/LegacyOperationalPolicyMapper.java | 26 +- .../tosca/legacy/provider/LegacyProvider.java | 80 ++--- .../tosca/simple/concepts/JpaToscaConstraint.java | 125 ++++++++ .../simple/concepts/JpaToscaConstraintLogical.java | 119 ++++++++ .../concepts/JpaToscaConstraintLogicalKey.java | 155 ++++++++++ .../concepts/JpaToscaConstraintLogicalString.java | 137 +++++++++ .../concepts/JpaToscaConstraintValidValues.java | 121 ++++++++ .../tosca/simple/concepts/JpaToscaDataType.java | 246 +++++++++++++++ .../tosca/simple/concepts/JpaToscaDataTypes.java | 89 ++++++ .../tosca/simple/concepts/JpaToscaEntityType.java | 218 ++++++++++++++ .../tosca/simple/concepts/JpaToscaEntrySchema.java | 228 ++++++++++++++ .../tosca/simple/concepts/JpaToscaEventFilter.java | 197 ++++++++++++ .../tosca/simple/concepts/JpaToscaModel.java | 160 ++++++++++ .../tosca/simple/concepts/JpaToscaPolicies.java | 89 ++++++ .../tosca/simple/concepts/JpaToscaPolicy.java | 271 +++++++++++++++++ .../tosca/simple/concepts/JpaToscaPolicyType.java | 294 ++++++++++++++++++ .../tosca/simple/concepts/JpaToscaPolicyTypes.java | 89 ++++++ .../tosca/simple/concepts/JpaToscaProperty.java | 304 +++++++++++++++++++ .../simple/concepts/JpaToscaServiceTemplate.java | 225 ++++++++++++++ .../simple/concepts/JpaToscaServiceTemplates.java | 87 ++++++ .../simple/concepts/JpaToscaTimeInterval.java | 188 ++++++++++++ .../simple/concepts/JpaToscaTopologyTemplate.java | 181 +++++++++++ .../tosca/simple/concepts/JpaToscaTrigger.java | 335 +++++++++++++++++++++ .../tosca/simple/concepts/ToscaConstraint.java | 125 -------- .../simple/concepts/ToscaConstraintLogical.java | 119 -------- .../simple/concepts/ToscaConstraintLogicalKey.java | 155 ---------- .../concepts/ToscaConstraintLogicalString.java | 137 --------- .../concepts/ToscaConstraintValidValues.java | 121 -------- .../tosca/simple/concepts/ToscaDataType.java | 246 --------------- .../tosca/simple/concepts/ToscaDataTypes.java | 89 ------ .../tosca/simple/concepts/ToscaEntityType.java | 218 -------------- .../tosca/simple/concepts/ToscaEntrySchema.java | 228 -------------- .../tosca/simple/concepts/ToscaEventFilter.java | 197 ------------ .../models/tosca/simple/concepts/ToscaModel.java | 160 ---------- .../tosca/simple/concepts/ToscaPolicies.java | 89 ------ .../models/tosca/simple/concepts/ToscaPolicy.java | 271 ----------------- .../tosca/simple/concepts/ToscaPolicyType.java | 294 ------------------ .../tosca/simple/concepts/ToscaPolicyTypes.java | 89 ------ .../tosca/simple/concepts/ToscaProperty.java | 304 ------------------- .../simple/concepts/ToscaServiceTemplate.java | 225 -------------- .../simple/concepts/ToscaServiceTemplates.java | 86 ------ .../tosca/simple/concepts/ToscaTimeInterval.java | 188 ------------ .../simple/concepts/ToscaTopologyTemplate.java | 181 ----------- .../models/tosca/simple/concepts/ToscaTrigger.java | 335 --------------------- .../mapping/JpaToscaServiceTemplateMapper.java | 49 +++ .../simple/mapping/ToscaServiceTemplateMapper.java | 49 --- .../tosca/simple/provider/SimpleToscaProvider.java | 87 +++--- .../serialization/ToscaDataTypeJsonAdapter.java | 14 +- .../serialization/ToscaDataTypesJsonAdapter.java | 21 +- .../serialization/ToscaPoliciesJsonAdapter.java | 18 +- .../serialization/ToscaPolicyJsonAdapter.java | 10 +- .../serialization/ToscaPolicyTypeJsonAdapter.java | 29 +- .../serialization/ToscaPolicyTypesJsonAdapter.java | 20 +- .../serialization/ToscaPropertiesJsonAdapter.java | 52 ++-- .../ToscaServiceTemplateJsonAdapter.java | 24 +- .../ToscaServiceTemplateMessageBodyHandler.java | 32 +- .../ToscaTopologyTemplateJsonAdapter.java | 14 +- .../onap/policy/models/tosca/utils/ToscaUtils.java | 6 +- .../PlainToscaServiceTemplateMapperTest.java | 20 +- .../LegacyOperationalPolicySerializationTest.java | 4 +- .../concepts/JpaToscaConstraintLogicalKeyTest.java | 136 +++++++++ .../JpaToscaConstraintLogicalStringTest.java | 135 +++++++++ .../concepts/JpaToscaConstraintLogicalTest.java | 168 +++++++++++ .../simple/concepts/JpaToscaDataTypeTest.java | 144 +++++++++ .../simple/concepts/JpaToscaDataTypesTest.java | 78 +++++ .../simple/concepts/JpaToscaEntrySchemaTest.java | 150 +++++++++ .../simple/concepts/JpaToscaEventFilterTest.java | 166 ++++++++++ .../tosca/simple/concepts/JpaToscaModelTest.java | 145 +++++++++ .../simple/concepts/JpaToscaPoliciesTest.java | 78 +++++ .../tosca/simple/concepts/JpaToscaPolicyTest.java | 174 +++++++++++ .../simple/concepts/JpaToscaPolicyTypeTest.java | 212 +++++++++++++ .../simple/concepts/JpaToscaPolicyTypesTest.java | 78 +++++ .../simple/concepts/JpaToscaPropertyTest.java | 221 ++++++++++++++ .../concepts/JpaToscaServiceTemplateTest.java | 177 +++++++++++ .../concepts/JpaToscaServiceTemplatesTest.java | 79 +++++ .../simple/concepts/JpaToscaTimeIntervalTest.java | 182 +++++++++++ .../concepts/JpaToscaTopologyTemplateTest.java | 138 +++++++++ .../tosca/simple/concepts/JpaToscaTriggerTest.java | 233 ++++++++++++++ .../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 | 221 -------------- .../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 | 4 +- .../simple/provider/SimpleToscaProviderTest.java | 44 +-- .../MonitoringPolicySerializationTest.java | 62 ++-- .../MonitoringPolicyTypeSerializationTest.java | 130 ++++---- .../src/test/resources/META-INF/persistence.xml | 6 +- 119 files changed, 7354 insertions(+), 7326 deletions(-) delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaConstraint.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaDataType.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaEntrySchema.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaPolicy.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaPolicyType.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaProperty.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaServiceTemplate.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaTopologyTemplate.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConstraint.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaDataType.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntrySchema.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicy.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaProperty.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplate.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTopologyTemplate.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogical.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKey.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalString.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintValidValues.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypes.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchema.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilter.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicies.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypes.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplates.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java create mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTrigger.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraint.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogical.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalKey.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalString.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintValidValues.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataType.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypes.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntityType.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntrySchema.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEventFilter.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaModel.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicies.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicy.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyType.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypes.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaProperty.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplate.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplates.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTimeInterval.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTopologyTemplate.java delete 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/JpaToscaServiceTemplateMapper.java delete mode 100644 models-tosca/src/main/java/org/onap/policy/models/tosca/simple/mapping/ToscaServiceTemplateMapper.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKeyTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalStringTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchemaTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplatesTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java create mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalKeyTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalStringTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypeTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypesTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntrySchemaTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaEventFilterTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaModelTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPoliciesTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypeTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypesTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPropertyTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplateTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplatesTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaTimeIntervalTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaTopologyTemplateTest.java delete mode 100644 models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaTriggerTest.java (limited to 'models-tosca') diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaConstraint.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaConstraint.java deleted file mode 100644 index 85d0b5009..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaConstraint.java +++ /dev/null @@ -1,41 +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.authorative.concepts; - -import com.google.gson.annotations.SerializedName; -import java.util.List; -import lombok.Data; - -/** - * Class to represent TOSCA constraint matching input/output from/to client. - * - * @author Chenfei Gao (cgao@research.att.com) - */ -@Data -public class PlainToscaConstraint { - - @SerializedName("valid_values") - private List validValues; - - private String equal; -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaDataType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaDataType.java deleted file mode 100644 index 0581a7da1..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaDataType.java +++ /dev/null @@ -1,47 +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.authorative.concepts; - -import com.google.gson.annotations.SerializedName; -import java.util.Map; -import lombok.Data; - -/** - * Class to represent TOSCA data type matching input/output from/to client. - * - * @author Chenfei Gao (cgao@research.att.com) - */ -@Data -public class PlainToscaDataType { - - @SerializedName("derived_from") - private String derivedFrom; - - private String version; - - private Map metadata; - - private String description; - - private Map properties; -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaEntrySchema.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaEntrySchema.java deleted file mode 100644 index ab9051aa9..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaEntrySchema.java +++ /dev/null @@ -1,41 +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.authorative.concepts; - -import java.util.List; -import lombok.Data; - -/** - * Class to represent TOSCA entry schema matching input/output from/to client. - * - * @author Chenfei Gao (cgao@research.att.com) - */ -@Data -public class PlainToscaEntrySchema { - - private String type; - - private String description; - - private List constraints; -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaPolicy.java deleted file mode 100644 index 02ebe6537..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaPolicy.java +++ /dev/null @@ -1,45 +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.authorative.concepts; - -import java.util.Map; -import lombok.Data; - -/** - * Class to represent TOSCA policy matching input/output from/to client. - * - * @author Chenfei Gao (cgao@research.att.com) - */ -@Data -public class PlainToscaPolicy { - - private String type; - - private String version; - - private String description; - - private Map metadata; - - private Map properties; -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaPolicyType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaPolicyType.java deleted file mode 100644 index 499e2dd25..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaPolicyType.java +++ /dev/null @@ -1,47 +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.authorative.concepts; - -import com.google.gson.annotations.SerializedName; -import java.util.Map; -import lombok.Data; - -/** - * Class to represent TOSCA policy type matching input/output from/to client. - * - * @author Chenfei Gao (cgao@research.att.com) - */ -@Data -public class PlainToscaPolicyType { - - @SerializedName("derived_from") - private String derivedFrom; - - private String version; - - private Map metadata; - - private String description; - - private Map properties; -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaProperty.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaProperty.java deleted file mode 100644 index e5e282a95..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaProperty.java +++ /dev/null @@ -1,50 +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.authorative.concepts; - -import com.google.gson.annotations.SerializedName; -import java.util.List; -import lombok.Data; - -/** - * Class to represent TOSCA property matching input/output from/to client. - * - * @author Chenfei Gao (cgao@research.att.com) - */ -@Data -public class PlainToscaProperty { - - private String type; - - private String description; - - private boolean required = false; - - @SerializedName("default") - private String defaultValue; - - @SerializedName("entry_schema") - private PlainToscaEntrySchema entrySchema; - - private List constraints; -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaServiceTemplate.java deleted file mode 100644 index cf5e2d9d6..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaServiceTemplate.java +++ /dev/null @@ -1,49 +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.authorative.concepts; - -import com.google.gson.annotations.SerializedName; -import java.util.List; -import java.util.Map; -import lombok.Data; - -/** - * Class to represent TOSCA service template matching input/output from/to client. - * - * @author Chenfei Gao (cgao@research.att.com) - */ -@Data -public class PlainToscaServiceTemplate { - - @SerializedName("tosca_definitions_version") - private String toscaDefinitionsVersion; - - @SerializedName("topology_template") - private PlainToscaTopologyTemplate toscaTopologyTemplate; - - @SerializedName("policy_types") - private List> policyTypes; - - @SerializedName("data_types") - private List> dataTypes; -} \ No newline at end of file diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaTopologyTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaTopologyTemplate.java deleted file mode 100644 index 16c1da05e..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/PlainToscaTopologyTemplate.java +++ /dev/null @@ -1,40 +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.authorative.concepts; - -import java.util.List; -import java.util.Map; -import lombok.Data; - -/** - * Class to represent TOSCA topology template matching input/output from/to client. - * - * @author Chenfei Gao (cgao@research.att.com) - */ -@Data -public class PlainToscaTopologyTemplate { - - private String description; - - private List> policies; -} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConstraint.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConstraint.java new file mode 100644 index 000000000..13b4adf23 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaConstraint.java @@ -0,0 +1,41 @@ +/*- + * ============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.authorative.concepts; + +import com.google.gson.annotations.SerializedName; +import java.util.List; +import lombok.Data; + +/** + * Class to represent TOSCA constraint matching input/output from/to client. + * + * @author Chenfei Gao (cgao@research.att.com) + */ +@Data +public class ToscaConstraint { + + @SerializedName("valid_values") + private List validValues; + + private String equal; +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaDataType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaDataType.java new file mode 100644 index 000000000..9aae32040 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaDataType.java @@ -0,0 +1,47 @@ +/*- + * ============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.authorative.concepts; + +import com.google.gson.annotations.SerializedName; +import java.util.Map; +import lombok.Data; + +/** + * Class to represent TOSCA data type matching input/output from/to client. + * + * @author Chenfei Gao (cgao@research.att.com) + */ +@Data +public class ToscaDataType { + + @SerializedName("derived_from") + private String derivedFrom; + + private String version; + + private Map metadata; + + private String description; + + private Map properties; +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntrySchema.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntrySchema.java new file mode 100644 index 000000000..a3526f757 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntrySchema.java @@ -0,0 +1,41 @@ +/*- + * ============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.authorative.concepts; + +import java.util.List; +import lombok.Data; + +/** + * Class to represent TOSCA entry schema matching input/output from/to client. + * + * @author Chenfei Gao (cgao@research.att.com) + */ +@Data +public class ToscaEntrySchema { + + private String type; + + private String description; + + private List constraints; +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicy.java new file mode 100644 index 000000000..e8616061d --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicy.java @@ -0,0 +1,62 @@ +/*- + * ============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.authorative.concepts; + +import java.util.LinkedHashMap; +import java.util.Map; +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.NonNull; + +/** + * Class to represent TOSCA policy matching input/output from/to client. + * + * @author Chenfei Gao (cgao@research.att.com) + */ +@Data +@NoArgsConstructor +public class ToscaPolicy { + + private String type; + + private String version; + + private String description; + + private Map metadata; + + private Map properties; + + /** + * Copy constructor. + * + * @param copyObject the obejct to copy from. + */ + public ToscaPolicy(@NonNull ToscaPolicy copyObject) { + this.type = copyObject.type; + this.version = copyObject.version; + this.description = copyObject.description; + this.metadata = (metadata != null ? new LinkedHashMap<>(copyObject.metadata) : null); + this.properties = (properties != null ? new LinkedHashMap<>(copyObject.properties) : null); + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java new file mode 100644 index 000000000..c46402ba1 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyType.java @@ -0,0 +1,47 @@ +/*- + * ============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.authorative.concepts; + +import com.google.gson.annotations.SerializedName; +import java.util.Map; +import lombok.Data; + +/** + * Class to represent TOSCA policy type matching input/output from/to client. + * + * @author Chenfei Gao (cgao@research.att.com) + */ +@Data +public class ToscaPolicyType { + + @SerializedName("derived_from") + private String derivedFrom; + + private String version; + + private Map metadata; + + private String description; + + private Map properties; +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaProperty.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaProperty.java new file mode 100644 index 000000000..9eda83b90 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaProperty.java @@ -0,0 +1,50 @@ +/*- + * ============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.authorative.concepts; + +import com.google.gson.annotations.SerializedName; +import java.util.List; +import lombok.Data; + +/** + * Class to represent TOSCA property matching input/output from/to client. + * + * @author Chenfei Gao (cgao@research.att.com) + */ +@Data +public class ToscaProperty { + + private String type; + + private String description; + + private boolean required = false; + + @SerializedName("default") + private String defaultValue; + + @SerializedName("entry_schema") + private ToscaEntrySchema entrySchema; + + private List constraints; +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplate.java new file mode 100644 index 000000000..3d1b96313 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplate.java @@ -0,0 +1,49 @@ +/*- + * ============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.authorative.concepts; + +import com.google.gson.annotations.SerializedName; +import java.util.List; +import java.util.Map; +import lombok.Data; + +/** + * Class to represent TOSCA service template matching input/output from/to client. + * + * @author Chenfei Gao (cgao@research.att.com) + */ +@Data +public class ToscaServiceTemplate { + + @SerializedName("tosca_definitions_version") + private String toscaDefinitionsVersion; + + @SerializedName("topology_template") + private ToscaTopologyTemplate toscaTopologyTemplate; + + @SerializedName("policy_types") + private List> policyTypes; + + @SerializedName("data_types") + private List> dataTypes; +} \ No newline at end of file diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTopologyTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTopologyTemplate.java new file mode 100644 index 000000000..ebb53e177 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTopologyTemplate.java @@ -0,0 +1,40 @@ +/*- + * ============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.authorative.concepts; + +import java.util.List; +import java.util.Map; +import lombok.Data; + +/** + * Class to represent TOSCA topology template matching input/output from/to client. + * + * @author Chenfei Gao (cgao@research.att.com) + */ +@Data +public class ToscaTopologyTemplate { + + private String description; + + private List> policies; +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/mapping/PlainToscaServiceTemplateMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/mapping/PlainToscaServiceTemplateMapper.java index aa7ca23b2..cef83486d 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/mapping/PlainToscaServiceTemplateMapper.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/mapping/PlainToscaServiceTemplateMapper.java @@ -23,9 +23,9 @@ package org.onap.policy.models.tosca.authorative.mapping; import com.google.gson.Gson; -import org.onap.policy.models.tosca.authorative.concepts.PlainToscaServiceTemplate; -import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; -import org.onap.policy.models.tosca.simple.mapping.ToscaServiceTemplateMapper; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.mapping.JpaToscaServiceTemplateMapper; import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler; /** @@ -34,23 +34,23 @@ import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMes * @author Chenfei Gao (cgao@research.att.com) */ public class PlainToscaServiceTemplateMapper - implements ToscaServiceTemplateMapper { + implements JpaToscaServiceTemplateMapper { private Gson defaultGson = new Gson(); private Gson customGson = new ToscaServiceTemplateMessageBodyHandler().getGson(); @Override - public ToscaServiceTemplate toToscaServiceTemplate(PlainToscaServiceTemplate otherPolicy) { + public JpaToscaServiceTemplate toToscaServiceTemplate(ToscaServiceTemplate otherPolicy) { String serializedServiceTemplate = defaultGson.toJson(otherPolicy); - return customGson.fromJson(serializedServiceTemplate, ToscaServiceTemplate.class); + return customGson.fromJson(serializedServiceTemplate, JpaToscaServiceTemplate.class); } @Override - public PlainToscaServiceTemplate fromToscaServiceTemplate(ToscaServiceTemplate serviceTemplate) { + public ToscaServiceTemplate fromToscaServiceTemplate(JpaToscaServiceTemplate serviceTemplate) { String serializedServiceTemplate = customGson.toJson(serviceTemplate); - return defaultGson.fromJson(serializedServiceTemplate, PlainToscaServiceTemplate.class); + return defaultGson.fromJson(serializedServiceTemplate, ToscaServiceTemplate.class); } } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java index 141b4e783..cc37338e4 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/mapping/LegacyGuardPolicyMapper.java @@ -30,11 +30,11 @@ import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyContent; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput; -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; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; +import org.onap.policy.models.tosca.simple.mapping.JpaToscaServiceTemplateMapper; import org.onap.policy.models.tosca.utils.ToscaUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,7 +45,7 @@ import org.slf4j.LoggerFactory; * @author Liam Fallon (liam.fallon@est.tech) */ public class LegacyGuardPolicyMapper - implements ToscaServiceTemplateMapper> { + implements JpaToscaServiceTemplateMapper> { private static final Logger LOGGER = LoggerFactory.getLogger(LegacyGuardPolicyMapper.class); private static final Map GUARD_POLICY_TYPE_MAP = new LinkedHashMap<>(); @@ -62,7 +62,7 @@ public class LegacyGuardPolicyMapper } @Override - public ToscaServiceTemplate toToscaServiceTemplate(final LegacyGuardPolicyInput legacyGuardPolicyInput) { + public JpaToscaServiceTemplate toToscaServiceTemplate(final LegacyGuardPolicyInput legacyGuardPolicyInput) { PfConceptKey guardPolicyType = GUARD_POLICY_TYPE_MAP.get(legacyGuardPolicyInput.getPolicyId()); if (guardPolicyType == null) { String errorMessage = @@ -80,28 +80,30 @@ public class LegacyGuardPolicyMapper PfConceptKey policyKey = new PfConceptKey(legacyGuardPolicyInput.getPolicyId(), version); - final ToscaPolicy toscaPolicy = new ToscaPolicy(policyKey); + final JpaToscaPolicy toscaPolicy = new JpaToscaPolicy(policyKey); toscaPolicy.setType(guardPolicyType); toscaPolicy.setProperties(legacyGuardPolicyInput.getContent().getAsPropertyMap()); - final ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); + final JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); serviceTemplate.setToscaDefinitionsVersion("tosca_simimport java.util.HashMap;\n" + "ple_yaml_1_0"); - serviceTemplate.setTopologyTemplate(new ToscaTopologyTemplate()); + serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); - serviceTemplate.getTopologyTemplate().setPolicies(new ToscaPolicies()); + serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policyKey, toscaPolicy); return serviceTemplate; } @Override - public Map fromToscaServiceTemplate(final ToscaServiceTemplate serviceTemplate) { + public Map fromToscaServiceTemplate( + final JpaToscaServiceTemplate serviceTemplate) { ToscaUtils.assertPoliciesExist(serviceTemplate); final Map legacyGuardPolicyOutputMap = new LinkedHashMap<>(); - for (ToscaPolicy toscaPolicy : serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().values()) { + for (JpaToscaPolicy toscaPolicy : serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap() + .values()) { final LegacyGuardPolicyOutput legacyGuardPolicyOutput = new LegacyGuardPolicyOutput(); legacyGuardPolicyOutput.setType(toscaPolicy.getType().getName()); 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 index 65f477572..4ddcd60cc 100644 --- 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 @@ -28,11 +28,11 @@ import javax.ws.rs.core.Response; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfModelRuntimeException; 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; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; +import org.onap.policy.models.tosca.simple.mapping.JpaToscaServiceTemplateMapper; import org.onap.policy.models.tosca.utils.ToscaUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,14 +43,14 @@ import org.slf4j.LoggerFactory; * @author Liam Fallon (liam.fallon@est.tech) */ public class LegacyOperationalPolicyMapper - implements ToscaServiceTemplateMapper { + implements JpaToscaServiceTemplateMapper { private static final Logger LOGGER = LoggerFactory.getLogger(LegacyOperationalPolicyMapper.class); private static final PfConceptKey LEGACY_OPERATIONAL_TYPE = new PfConceptKey("onap.policies.controlloop.Operational", "1.0.0"); @Override - public ToscaServiceTemplate toToscaServiceTemplate(final LegacyOperationalPolicy legacyOperationalPolicy) { + public JpaToscaServiceTemplate toToscaServiceTemplate(final LegacyOperationalPolicy legacyOperationalPolicy) { String incomingVersion = legacyOperationalPolicy.getPolicyVersion(); if (incomingVersion == null) { incomingVersion = "1"; @@ -58,7 +58,7 @@ public class LegacyOperationalPolicyMapper PfConceptKey policyKey = new PfConceptKey(legacyOperationalPolicy.getPolicyId(), incomingVersion + ".0.0"); - final ToscaPolicy toscaPolicy = new ToscaPolicy(policyKey); + final JpaToscaPolicy toscaPolicy = new JpaToscaPolicy(policyKey); toscaPolicy.setType(LEGACY_OPERATIONAL_TYPE); @@ -66,19 +66,19 @@ public class LegacyOperationalPolicyMapper toscaPolicy.setProperties(propertyMap); toscaPolicy.getProperties().put("Content", legacyOperationalPolicy.getContent()); - final ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); + final JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); serviceTemplate.setToscaDefinitionsVersion("tosca_simple_yaml_1_0"); - serviceTemplate.setTopologyTemplate(new ToscaTopologyTemplate()); + serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); - serviceTemplate.getTopologyTemplate().setPolicies(new ToscaPolicies()); + serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policyKey, toscaPolicy); return serviceTemplate; } @Override - public LegacyOperationalPolicy fromToscaServiceTemplate(final ToscaServiceTemplate serviceTemplate) { + public LegacyOperationalPolicy fromToscaServiceTemplate(final JpaToscaServiceTemplate serviceTemplate) { ToscaUtils.assertPoliciesExist(serviceTemplate); if (serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().size() > 1) { @@ -88,7 +88,7 @@ public class LegacyOperationalPolicyMapper } // Get the policy - final ToscaPolicy toscaPolicy = + final JpaToscaPolicy toscaPolicy = serviceTemplate.getTopologyTemplate().getPolicies().getAll(null).iterator().next(); final LegacyOperationalPolicy legacyOperationalPolicy = new LegacyOperationalPolicy(); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java index 04a010f08..a394cec3e 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider.java @@ -36,10 +36,10 @@ import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; import org.onap.policy.models.tosca.legacy.mapping.LegacyGuardPolicyMapper; import org.onap.policy.models.tosca.legacy.mapping.LegacyOperationalPolicyMapper; -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.concepts.JpaToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,7 +68,7 @@ public class LegacyProvider { public LegacyOperationalPolicy getOperationalPolicy(@NonNull final PfDao dao, @NonNull final String policyId) throws PfModelException { - ToscaPolicy newestPolicy = getLatestPolicy(dao, policyId); + JpaToscaPolicy newestPolicy = getLatestPolicy(dao, policyId); if (newestPolicy == null) { String errorMessage = NO_POLICY_FOUND_FOR_POLICY_ID + policyId; @@ -77,9 +77,9 @@ public class LegacyProvider { } // Create the structure of the TOSCA service template to contain the policy type - ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); - serviceTemplate.setTopologyTemplate(new ToscaTopologyTemplate()); - serviceTemplate.getTopologyTemplate().setPolicies(new ToscaPolicies()); + JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); + serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); + serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(newestPolicy.getKey(), newestPolicy); return new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(serviceTemplate); @@ -98,7 +98,7 @@ public class LegacyProvider { // We need to find the latest policy and update the major version, if there is no policy with this ID, then // we set it to the first version - ToscaPolicy newestPolicy = getLatestPolicy(dao, legacyOperationalPolicy.getPolicyId()); + JpaToscaPolicy newestPolicy = getLatestPolicy(dao, legacyOperationalPolicy.getPolicyId()); if (newestPolicy == null) { legacyOperationalPolicy.setPolicyVersion(FIRST_POLICY_VERSION); @@ -106,9 +106,9 @@ public class LegacyProvider { legacyOperationalPolicy.setPolicyVersion(Integer.toString(newestPolicy.getKey().getMajorVersion() + 1)); } - ToscaServiceTemplate incomingServiceTemplate = + JpaToscaServiceTemplate incomingServiceTemplate = new LegacyOperationalPolicyMapper().toToscaServiceTemplate(legacyOperationalPolicy); - ToscaServiceTemplate outgoingingServiceTemplate = + JpaToscaServiceTemplate outgoingingServiceTemplate = new SimpleToscaProvider().createPolicies(dao, incomingServiceTemplate); return new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(outgoingingServiceTemplate); @@ -127,7 +127,7 @@ public class LegacyProvider { // We need to find the latest policy and use the major version, if there is no policy with this ID, then // we have an error - ToscaPolicy newestPolicy = getLatestPolicy(dao, legacyOperationalPolicy.getPolicyId()); + JpaToscaPolicy newestPolicy = getLatestPolicy(dao, legacyOperationalPolicy.getPolicyId()); if (newestPolicy == null) { String errorMessage = NO_POLICY_FOUND_FOR_POLICY_ID + legacyOperationalPolicy.getPolicyId(); @@ -137,9 +137,9 @@ public class LegacyProvider { legacyOperationalPolicy.setPolicyVersion(Integer.toString(newestPolicy.getKey().getMajorVersion())); } - ToscaServiceTemplate incomingServiceTemplate = + JpaToscaServiceTemplate incomingServiceTemplate = new LegacyOperationalPolicyMapper().toToscaServiceTemplate(legacyOperationalPolicy); - ToscaServiceTemplate outgoingingServiceTemplate = + JpaToscaServiceTemplate outgoingingServiceTemplate = new SimpleToscaProvider().createPolicies(dao, incomingServiceTemplate); return new LegacyOperationalPolicyMapper().fromToscaServiceTemplate(outgoingingServiceTemplate); @@ -157,12 +157,12 @@ public class LegacyProvider { throws PfModelException { // Get all the policies in the database and check the policy ID against the policies returned - List policyList = dao.getAll(ToscaPolicy.class); + List policyList = dao.getAll(JpaToscaPolicy.class); // Find the latest policy that matches the ID - List policyDeleteList = new ArrayList<>(); + List policyDeleteList = new ArrayList<>(); - for (ToscaPolicy policy : policyList) { + for (JpaToscaPolicy policy : policyList) { if (policyId.equals(policy.getKey().getName())) { policyDeleteList.add(policy); } @@ -175,11 +175,11 @@ public class LegacyProvider { } // Create the structure of the TOSCA service template to contain the policy type - ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); - serviceTemplate.setTopologyTemplate(new ToscaTopologyTemplate()); - serviceTemplate.getTopologyTemplate().setPolicies(new ToscaPolicies()); + JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); + serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); + serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); - for (ToscaPolicy deletePolicy : policyDeleteList) { + for (JpaToscaPolicy deletePolicy : policyDeleteList) { dao.delete(deletePolicy); serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(deletePolicy.getKey(), deletePolicy); @@ -199,7 +199,7 @@ public class LegacyProvider { public Map getGuardPolicy(@NonNull final PfDao dao, @NonNull final String policyId) throws PfModelException { - ToscaPolicy newestPolicy = getLatestPolicy(dao, policyId); + JpaToscaPolicy newestPolicy = getLatestPolicy(dao, policyId); if (newestPolicy == null) { String errorMessage = NO_POLICY_FOUND_FOR_POLICY_ID + policyId; @@ -208,9 +208,9 @@ public class LegacyProvider { } // Create the structure of the TOSCA service template to contain the policy type - ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); - serviceTemplate.setTopologyTemplate(new ToscaTopologyTemplate()); - serviceTemplate.getTopologyTemplate().setPolicies(new ToscaPolicies()); + JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); + serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); + serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(newestPolicy.getKey(), newestPolicy); return new LegacyGuardPolicyMapper().fromToscaServiceTemplate(serviceTemplate); @@ -227,9 +227,9 @@ public class LegacyProvider { public Map createGuardPolicy(@NonNull final PfDao dao, @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException { - ToscaServiceTemplate incomingServiceTemplate = + JpaToscaServiceTemplate incomingServiceTemplate = new LegacyGuardPolicyMapper().toToscaServiceTemplate(legacyGuardPolicy); - ToscaServiceTemplate outgoingingServiceTemplate = + JpaToscaServiceTemplate outgoingingServiceTemplate = new SimpleToscaProvider().createPolicies(dao, incomingServiceTemplate); return new LegacyGuardPolicyMapper().fromToscaServiceTemplate(outgoingingServiceTemplate); @@ -246,9 +246,9 @@ public class LegacyProvider { public Map updateGuardPolicy(@NonNull final PfDao dao, @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException { - ToscaServiceTemplate incomingServiceTemplate = + JpaToscaServiceTemplate incomingServiceTemplate = new LegacyGuardPolicyMapper().toToscaServiceTemplate(legacyGuardPolicy); - ToscaServiceTemplate outgoingingServiceTemplate = + JpaToscaServiceTemplate outgoingingServiceTemplate = new SimpleToscaProvider().createPolicies(dao, incomingServiceTemplate); return new LegacyGuardPolicyMapper().fromToscaServiceTemplate(outgoingingServiceTemplate); @@ -267,12 +267,12 @@ public class LegacyProvider { @NonNull final String policyId) throws PfModelException { // Get all the policies in the database and check the policy ID against the policies returned - List policyList = dao.getAll(ToscaPolicy.class); + List policyList = dao.getAll(JpaToscaPolicy.class); // Find the latest policy that matches the ID - List policyDeleteList = new ArrayList<>(); + List policyDeleteList = new ArrayList<>(); - for (ToscaPolicy policy : policyList) { + for (JpaToscaPolicy policy : policyList) { if (policyId.equals(policy.getKey().getName())) { policyDeleteList.add(policy); } @@ -285,11 +285,11 @@ public class LegacyProvider { } // Create the structure of the TOSCA service template to contain the policy type - ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); - serviceTemplate.setTopologyTemplate(new ToscaTopologyTemplate()); - serviceTemplate.getTopologyTemplate().setPolicies(new ToscaPolicies()); + JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); + serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); + serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); - for (ToscaPolicy deletePolicy : policyDeleteList) { + for (JpaToscaPolicy deletePolicy : policyDeleteList) { dao.delete(deletePolicy); serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(deletePolicy.getKey(), deletePolicy); @@ -305,14 +305,14 @@ public class LegacyProvider { * @param policyId the ID of the policy * @return the policy */ - private ToscaPolicy getLatestPolicy(final PfDao dao, final String policyId) { + private JpaToscaPolicy getLatestPolicy(final PfDao dao, final String policyId) { // Get all the policies in the database and check the policy ID against the policies returned - List policyList = dao.getAll(ToscaPolicy.class); + List policyList = dao.getAll(JpaToscaPolicy.class); // Find the latest policy that matches the ID - ToscaPolicy newestPolicy = null; + JpaToscaPolicy newestPolicy = null; - for (ToscaPolicy policy : policyList) { + for (JpaToscaPolicy policy : policyList) { if (!policyId.equals(policy.getKey().getName())) { continue; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java new file mode 100644 index 000000000..bde53c351 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.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 JpaToscaConstraint extends PfConcept { + private static final long serialVersionUID = 6426438089914347734L; + + @EmbeddedId + private final PfReferenceKey key; + + /** + * The Default Constructor creates a {@link JpaToscaConstraint} object with a null key. + */ + public JpaToscaConstraint() { + this(new PfReferenceKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaConstraint} object with the given concept key. + * + * @param key the key + */ + public JpaToscaConstraint(@NonNull final PfReferenceKey key) { + this.key = key; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaConstraint(@NonNull final JpaToscaConstraint 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 JpaToscaConstraint other = (JpaToscaConstraint) 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/JpaToscaConstraintLogical.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogical.java new file mode 100644 index 000000000..231e26188 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogical.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 JpaToscaConstraintLogical extends JpaToscaConstraint { + 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 JpaToscaConstraintLogical} object with a null key. + */ + public JpaToscaConstraintLogical() { + this(new PfReferenceKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaConstraintLogical} object with the given concept key. + * + * @param key the key of the constraint + */ + public JpaToscaConstraintLogical(final PfReferenceKey key) { + this(key, Operation.EQ); + } + + /** + * The Key Constructor creates a {@link JpaToscaConstraintLogical} object with the given concept key and operation. + * + * @param key the key of the constraint + * @param operation the logical operation of the constraint + * + */ + public JpaToscaConstraintLogical(final PfReferenceKey key, @NonNull final Operation operation) { + super(key); + this.operation = operation; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaConstraintLogical(@NonNull final JpaToscaConstraintLogical 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 JpaToscaConstraintLogical other = (JpaToscaConstraintLogical) 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/JpaToscaConstraintLogicalKey.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKey.java new file mode 100644 index 000000000..13902db19 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKey.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 JpaToscaConstraintLogicalKey extends JpaToscaConstraintLogical { + private static final long serialVersionUID = -2420828090326264341L; + + @Column + @NonNull + @Getter + private final PfKey compareToKey; + + /** + * The Default Constructor creates a {@link JpaToscaConstraintLogicalKey} object with a null key. + */ + public JpaToscaConstraintLogicalKey() { + this(new PfReferenceKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaConstraintLogicalKey} object with the given concept + * key. + * + * @param key the key of the constraint + */ + public JpaToscaConstraintLogicalKey(final PfReferenceKey key) { + this(key, Operation.EQ, PfConceptKey.getNullKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaConstraintLogicalKey} 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 JpaToscaConstraintLogicalKey(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 JpaToscaConstraintLogicalKey(@NonNull final JpaToscaConstraintLogical 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 JpaToscaConstraintLogicalKey other = (JpaToscaConstraintLogicalKey) 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/JpaToscaConstraintLogicalString.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalString.java new file mode 100644 index 000000000..512127343 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalString.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 JpaToscaConstraintLogicalString extends JpaToscaConstraintLogical { + private static final long serialVersionUID = 8167550632122339195L; + + @Column + @NonNull + @Getter + private final String compareToString; + + /** + * The Default Constructor creates a {@link JpaToscaConstraintLogicalString} object with a null key. + */ + public JpaToscaConstraintLogicalString() { + this(new PfReferenceKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaConstraintLogicalString} object with the given concept + * key. + * + * @param key the key of the constraint + */ + public JpaToscaConstraintLogicalString(final PfReferenceKey key) { + this(key, Operation.EQ, ""); + } + + /** + * The Key Constructor creates a {@link JpaToscaConstraintLogicalString} 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 JpaToscaConstraintLogicalString(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 JpaToscaConstraintLogicalString(@NonNull final JpaToscaConstraintLogical 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 JpaToscaConstraintLogicalString other = (JpaToscaConstraintLogicalString) 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/JpaToscaConstraintValidValues.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintValidValues.java new file mode 100644 index 000000000..608605f4e --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintValidValues.java @@ -0,0 +1,121 @@ +/*- + * ============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.simple.concepts; + +import com.google.gson.annotations.SerializedName; + +import java.util.LinkedList; +import java.util.List; +import javax.persistence.ElementCollection; +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.PfModelRuntimeException; +import org.onap.policy.models.base.PfReferenceKey; + +/** + * This class represents valid_values TOSCA constraint. + * + * @author Chenfei Gao (cgao@research.att.com) + */ +@EqualsAndHashCode(callSuper = false) +@Data +public class JpaToscaConstraintValidValues extends JpaToscaConstraint { + private static final long serialVersionUID = 3152323457560746844L; + + @SerializedName("valid_values") + @NonNull + @ElementCollection + private final List validValues; + + /** + * The Default Constructor creates a {@link JpaToscaConstraintValidValues} object with a null key. + */ + public JpaToscaConstraintValidValues() { + this(new PfReferenceKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaConstraintValidValues} object with the given concept key. + * + * @param key the key of the constraint + */ + public JpaToscaConstraintValidValues(final PfReferenceKey key) { + super(key); + validValues = new LinkedList<>(); + } + + /** + * The Key Constructor creates a {@link JpaToscaConstraintLogical} object with the given concept key + * and valid values list. + * + * @param key the key of the constraint + * @param validValues the valid values list of the constraint + * + */ + public JpaToscaConstraintValidValues(final PfReferenceKey key, @NonNull final List validValues) { + super(key); + this.validValues = validValues; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaConstraintValidValues(@NonNull final JpaToscaConstraintValidValues 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 JpaToscaConstraintValidValues other = (JpaToscaConstraintValidValues) otherConcept; + + int result = super.compareTo(other); + if (result != 0) { + return result; + } + + if (validValues.equals(other.validValues)) { + return 0; + } + return -1; + } + + @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/JpaToscaDataType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.java new file mode 100644 index 000000000..0035eb015 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataType.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 JpaToscaDataType extends JpaToscaEntityType { + private static final long serialVersionUID = -3922690413436539164L; + + @ElementCollection + private List constraints; + + @ElementCollection + private List properties; + + /** + * The Default Constructor creates a {@link JpaToscaDataType} object with a null key. + */ + public JpaToscaDataType() { + this(new PfConceptKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaDataType} object with the given concept key. + * + * @param key the key + */ + public JpaToscaDataType(@NonNull final PfConceptKey key) { + super(key); + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaDataType(final JpaToscaDataType copyConcept) { + super(copyConcept); + } + + @Override + public List getKeys() { + final List keyList = super.getKeys(); + + if (constraints != null) { + for (JpaToscaConstraint constraint : constraints) { + keyList.addAll(constraint.getKeys()); + } + } + + if (properties != null) { + for (JpaToscaProperty property : properties) { + keyList.addAll(property.getKeys()); + } + } + + return keyList; + } + + @Override + public void clean() { + super.clean(); + + if (constraints != null) { + for (JpaToscaConstraint constraint : constraints) { + constraint.clean(); + } + } + + if (properties != null) { + for (JpaToscaProperty 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 (JpaToscaConstraint 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 (JpaToscaProperty 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 JpaToscaDataType other = (JpaToscaDataType) 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 JpaToscaDataType copy = ((JpaToscaDataType) copyObject); + super.copyTo(target); + + if (constraints == null) { + copy.setConstraints(null); + } + else { + final List newConstraints = new ArrayList<>(); + for (final JpaToscaConstraint 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 JpaToscaProperty property : properties) { + newProperties.add(new JpaToscaProperty(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/JpaToscaDataTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypes.java new file mode 100644 index 000000000..7fedd063c --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypes.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.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 JpaToscaDataTypes extends PfConceptContainer { + private static final long serialVersionUID = 2941102271022190348L; + + public static final String DEFAULT_NAME = "ToscaDataTypesSimple"; + public static final String DEFAULT_VERSION = "1.0.0"; + + /** + * The Default Constructor creates a {@link JpaToscaDataTypes} object with a null artifact key + * and creates an empty concept map. + */ + public JpaToscaDataTypes() { + super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION)); + } + + /** + * The Key Constructor creates a {@link JpaToscaDataTypes} object with the given artifact key + * and creates an empty concept map. + * + * @param key the concept key + */ + public JpaToscaDataTypes(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 JpaToscaDataTypes(final PfConceptKey key, final Map conceptMap) { + super(key, conceptMap); + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaDataTypes(final JpaToscaDataTypes copyConcept) { + super(copyConcept); + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java new file mode 100644 index 000000000..e7d51a500 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java @@ -0,0 +1,218 @@ +/*- + * ============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 java.util.Map; +import java.util.Map.Entry; +import java.util.TreeMap; + +import javax.persistence.AttributeOverride; +import javax.persistence.AttributeOverrides; +import javax.persistence.Column; +import javax.persistence.ElementCollection; +import javax.persistence.EmbeddedId; +import javax.persistence.MappedSuperclass; + +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. + */ +@MappedSuperclass +@Data +@EqualsAndHashCode(callSuper = false) +public class JpaToscaEntityType extends PfConcept { + private static final long serialVersionUID = -1330661834220739393L; + + @EmbeddedId + private PfConceptKey key; + + // @formatter:off + @Column + @AttributeOverrides({ + @AttributeOverride(name = "name", + column = @Column(name = "derived_from_name")), + @AttributeOverride(name = "version", + column = @Column(name = "derived_from_version")) + }) + private PfConceptKey derivedFrom; + + @ElementCollection + private Map metadata; + + @Column + private String description; + // @formatter:on + + /** + * The Default Constructor creates a {@link JpaToscaEntityType} object with a null key. + */ + public JpaToscaEntityType() { + this(new PfConceptKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaEntityType} object with the given concept key. + * + * @param key the key + */ + public JpaToscaEntityType(@NonNull final PfConceptKey key) { + this.key = key; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaEntityType(final JpaToscaEntityType 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 JpaToscaEntityType other = (JpaToscaEntityType) 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 JpaToscaEntityType copy = ((JpaToscaEntityType) 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/JpaToscaEntrySchema.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchema.java new file mode 100644 index 000000000..e5ae20e84 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchema.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 JpaToscaEntrySchema 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 JpaToscaEntrySchema} object with a null key. + */ + public JpaToscaEntrySchema() { + this(new PfReferenceKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaEntrySchema} object with the given concept key. + * + * @param key the key + */ + public JpaToscaEntrySchema(@NonNull final PfReferenceKey key) { + this(key, new PfConceptKey()); + } + + /** + * The full constructor creates a {@link JpaToscaEntrySchema} object with mandatory fields. + * + * @param key the key + * @param type the type of the entry schema + */ + public JpaToscaEntrySchema(@NonNull final PfReferenceKey key, @NonNull final PfConceptKey type) { + this.key = key; + this.type = type; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaEntrySchema(final JpaToscaEntrySchema copyConcept) { + super(copyConcept); + } + + @Override + public List getKeys() { + final List keyList = getKey().getKeys(); + + keyList.addAll(type.getKeys()); + + if (constraints != null) { + for (JpaToscaConstraint 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 (JpaToscaConstraint 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 (JpaToscaConstraint 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 JpaToscaEntrySchema other = (JpaToscaEntrySchema) 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, JpaToscaEntrySchema.class); + + final JpaToscaEntrySchema copy = ((JpaToscaEntrySchema) target); + copy.setKey(new PfReferenceKey(key)); + copy.setType(new PfConceptKey(type)); + copy.setDescription(description); + + if (constraints != null) { + final List newConstraints = new ArrayList<>(); + for (final JpaToscaConstraint 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/JpaToscaEventFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilter.java new file mode 100644 index 000000000..3907a1b0c --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilter.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 JpaToscaEventFilter 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 JpaToscaEventFilter} object with a null key. + */ + public JpaToscaEventFilter() { + this(new PfReferenceKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaEventFilter} object with the given concept key. + * + * @param key the key + */ + public JpaToscaEventFilter(@NonNull final PfReferenceKey key) { + this(key, new PfConceptKey()); + } + + /** + * The full Constructor creates a {@link JpaToscaEventFilter} object with the given concept key and node. + * + * @param key the key + */ + public JpaToscaEventFilter(@NonNull final PfReferenceKey key, @NonNull final PfConceptKey node) { + this.key = key; + this.node = node; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaEventFilter(final JpaToscaEventFilter 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 JpaToscaEventFilter other = (JpaToscaEventFilter) 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, JpaToscaEventFilter.class); + + final JpaToscaEventFilter copy = ((JpaToscaEventFilter) 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/JpaToscaModel.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java new file mode 100644 index 000000000..a322c167f --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.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 JpaToscaModel} 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 JpaToscaModel extends PfModel { + private static final long serialVersionUID = 8800599637708309945L; + + @OneToOne(cascade = CascadeType.ALL) + private JpaToscaServiceTemplates serviceTemplates; + + /** + * The Default Constructor creates a {@link JpaToscaModel} object with a null concept key and + * creates an empty TOSCA model. + */ + public JpaToscaModel() { + this(new PfConceptKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaModel} object with the given concept key and + * creates an empty TOSCA model. + * + * @param key the TOSCA model key + */ + public JpaToscaModel(final PfConceptKey key) { + this(key, new JpaToscaServiceTemplates(new PfConceptKey())); + } + + /** + * Constructor that initiates a {@link JpaToscaModel} with all its fields. + * + * @param key the TOSCA model key + * @param serviceTemplates the service templates in the event model + */ + public JpaToscaModel(@NonNull final PfConceptKey key, @NonNull final JpaToscaServiceTemplates serviceTemplates) { + super(key); + this.serviceTemplates = serviceTemplates; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaModel(@NonNull final JpaToscaModel 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 JpaToscaModel other = (JpaToscaModel) 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, JpaToscaModel.class); + + final JpaToscaModel copy = ((JpaToscaModel) targetObject); + super.copyTo(targetObject); + copy.setServiceTemplates(new JpaToscaServiceTemplates(serviceTemplates)); + + return copy; + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicies.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicies.java new file mode 100644 index 000000000..d59f470dd --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicies.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.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 JpaToscaPolicies extends PfConceptContainer { + private static final long serialVersionUID = -7526648702327776101L; + + public static final String DEFAULT_NAME = "ToscaPoliciesSimple"; + public static final String DEFAULT_VERSION = "1.0.0"; + + /** + * The Default Constructor creates a {@link JpaToscaPolicies} object with a null artifact key and + * creates an empty concept map. + */ + public JpaToscaPolicies() { + super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION)); + } + + /** + * The Key Constructor creates a {@link JpaToscaPolicies} object with the given artifact key and + * creates an empty concept map. + * + * @param key the concept key + */ + public JpaToscaPolicies(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 JpaToscaPolicies(final PfConceptKey key, final Map conceptMap) { + super(key, conceptMap); + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaPolicies(final JpaToscaPolicies copyConcept) { + super(copyConcept); + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java new file mode 100644 index 000000000..e889192d8 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java @@ -0,0 +1,271 @@ +/*- + * ============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.AttributeOverride; +import javax.persistence.AttributeOverrides; +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 JpaToscaPolicy extends JpaToscaEntityType { + private static final long serialVersionUID = 3265174757061982805L; + + // @formatter:off + @Column + @AttributeOverrides({ + @AttributeOverride(name = "name", + column = @Column(name = "type_name")), + @AttributeOverride(name = "version", + column = @Column(name = "type_version")) + }) + private PfConceptKey type; + + @ElementCollection + @Column(length = 10000) + private Map properties; + + @ElementCollection + private List targets; + // @formatter:on + + /** + * The Default Constructor creates a {@link JpaToscaPolicy} object with a null key. + */ + public JpaToscaPolicy() { + this(new PfConceptKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaPolicy} object with the given concept key. + * + * @param key the key + */ + public JpaToscaPolicy(@NonNull final PfConceptKey key) { + this(key, new PfConceptKey()); + } + + /** + * The full Constructor creates a {@link JpaToscaPolicy} object with all mandatory fields. + * + * @param key the key + * @param type the type of the policy + */ + public JpaToscaPolicy(@NonNull final PfConceptKey key, @NonNull final PfConceptKey type) { + super(key); + this.type = type; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaPolicy(@NonNull final JpaToscaPolicy 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 JpaToscaPolicy other = (JpaToscaPolicy) 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 JpaToscaPolicy copy = ((JpaToscaPolicy) 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/JpaToscaPolicyType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.java new file mode 100644 index 000000000..610987ccb --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyType.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 JpaToscaPolicyType extends JpaToscaEntityType { + private static final long serialVersionUID = -563659852901842616L; + + @ElementCollection + private List properties; + + @ElementCollection + private List targets; + + @ElementCollection + private List triggers; + + /** + * The Default Constructor creates a {@link JpaToscaPolicyType} object with a null key. + */ + public JpaToscaPolicyType() { + this(new PfConceptKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaPolicyType} object with the given concept key. + * + * @param key the key + */ + public JpaToscaPolicyType(@NonNull final PfConceptKey key) { + super(key); + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaPolicyType(final JpaToscaPolicyType copyConcept) { + super(copyConcept); + } + + + @Override + public List getKeys() { + final List keyList = super.getKeys(); + + if (properties != null) { + for (JpaToscaProperty property : properties) { + keyList.addAll(property.getKeys()); + } + } + + if (targets != null) { + keyList.addAll(targets); + } + + if (triggers != null) { + for (JpaToscaTrigger trigger : triggers) { + keyList.addAll(trigger.getKeys()); + } + } + + return keyList; + } + + @Override + public void clean() { + super.clean(); + + if (properties != null) { + for (JpaToscaProperty property : properties) { + property.clean(); + } + } + + if (targets != null) { + for (PfConceptKey target : targets) { + target.clean(); + } + } + + if (triggers != null) { + for (JpaToscaTrigger 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 (JpaToscaProperty 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 (JpaToscaTrigger 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 JpaToscaPolicyType other = (JpaToscaPolicyType) 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 JpaToscaPolicyType copy = ((JpaToscaPolicyType) copyObject); + super.copyTo(target); + + final List newProperties = new ArrayList<>(); + + if (properties == null) { + copy.setProperties(null); + } else { + for (final JpaToscaProperty property : properties) { + newProperties.add(new JpaToscaProperty(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 JpaToscaTrigger trigger : triggers) { + newTriggers.add(new JpaToscaTrigger(trigger)); + } + copy.setTriggers(newTriggers); + } + + return copy; + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypes.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypes.java new file mode 100644 index 000000000..ce3a8130d --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypes.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.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 JpaToscaPolicyTypes extends PfConceptContainer { + private static final long serialVersionUID = -4157979965271220098L; + + public static final String DEFAULT_NAME = "ToscaPolicyTypesSimple"; + public static final String DEFAULT_VERSION = "1.0.0"; + + /** + * The Default Constructor creates a {@link JpaToscaPolicyTypes} object with a null artifact key + * and creates an empty concept map. + */ + public JpaToscaPolicyTypes() { + super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION)); + } + + /** + * The Key Constructor creates a {@link JpaToscaPolicyTypes} object with the given artifact key and + * creates an empty concept map. + * + * @param key the concept key + */ + public JpaToscaPolicyTypes(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 JpaToscaPolicyTypes(final PfConceptKey key, final Map conceptMap) { + super(key, conceptMap); + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaPolicyTypes(final JpaToscaPolicyTypes copyConcept) { + super(copyConcept); + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java new file mode 100644 index 000000000..376c2b3b2 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaProperty.java @@ -0,0 +1,304 @@ +/*- + * ============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 JpaToscaProperty 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 String defaultValue; + + @Column + @NonNull + private Status status = Status.SUPPORTED; + + @ElementCollection + private List constraints; + + @Column + @SerializedName("entry_schema") + private JpaToscaEntrySchema entrySchema; + + /** + * The Default Constructor creates a {@link JpaToscaProperty} object with a null key. + */ + public JpaToscaProperty() { + this(new PfReferenceKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaProperty} object with the given concept key. + * + * @param key the key + */ + public JpaToscaProperty(@NonNull final PfReferenceKey key) { + this(key, new PfConceptKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaProperty} object with the given concept key. + * + * @param key the key + * @param type the key of the property type + */ + public JpaToscaProperty(@NonNull final PfReferenceKey key, @NonNull final PfConceptKey type) { + this.key = key; + this.type = type; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaProperty(final JpaToscaProperty copyConcept) { + super(copyConcept); + } + + @Override + public List getKeys() { + final List keyList = getKey().getKeys(); + + keyList.addAll(type.getKeys()); + + if (constraints != null) { + for (JpaToscaConstraint 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 = defaultValue.trim(); + } + + if (constraints != null) { + for (JpaToscaConstraint 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.trim().length() == 0) { + result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, + "property default value may not be null")); + } + + if (constraints != null) { + for (JpaToscaConstraint 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 JpaToscaProperty other = (JpaToscaProperty) 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 JpaToscaProperty 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, JpaToscaProperty.class); + + final JpaToscaProperty copy = ((JpaToscaProperty) 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 JpaToscaEntrySchema(entrySchema) : null); + + return copy; + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java new file mode 100644 index 000000000..fa2d2aac7 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java @@ -0,0 +1,225 @@ +/*- + * ============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 JpaToscaServiceTemplate extends JpaToscaEntityType { + private static final long serialVersionUID = 8084846046148349401L; + + public static final String DEFAULT_NAME = "ToscaServiceTemplateSimple"; + public static final String DEFAULT_VERSION = "1.0.0"; + + @Column + @SerializedName("tosca_definitions_version") + private String toscaDefinitionsVersion; + + @OneToOne(cascade = CascadeType.ALL) + @SerializedName("data_types") + private JpaToscaDataTypes dataTypes; + + @OneToOne(cascade = CascadeType.ALL) + @SerializedName("policy_types") + private JpaToscaPolicyTypes policyTypes; + + @SerializedName("topology_template") + private JpaToscaTopologyTemplate topologyTemplate; + + + /** + * The Default Constructor creates a {@link JpaToscaServiceTemplate} object with a null key. + */ + public JpaToscaServiceTemplate() { + this(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION)); + } + + /** + * The Key Constructor creates a {@link JpaToscaServiceTemplate} object with the given concept key. + * + * @param key the key + */ + public JpaToscaServiceTemplate(@NonNull final PfConceptKey key) { + this(key, ""); + } + + /** + * The full constructor creates a {@link JpaToscaServiceTemplate} object with all mandatory + * parameters. + * + * @param key the key + * @param toscaDefinitionsVersion the TOSCA version string + */ + public JpaToscaServiceTemplate(@NonNull final PfConceptKey key, @NonNull final String toscaDefinitionsVersion) { + super(key); + this.toscaDefinitionsVersion = toscaDefinitionsVersion; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaServiceTemplate(final JpaToscaServiceTemplate 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 JpaToscaServiceTemplate other = (JpaToscaServiceTemplate) 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 JpaToscaServiceTemplate copy = ((JpaToscaServiceTemplate) copyObject); + super.copyTo(target); + copy.setToscaDefinitionsVersion(toscaDefinitionsVersion); + + copy.setDataTypes(dataTypes != null ? new JpaToscaDataTypes(dataTypes) : null); + copy.setPolicyTypes(policyTypes != null ? new JpaToscaPolicyTypes(policyTypes) : null); + copy.setTopologyTemplate(topologyTemplate != null ? new JpaToscaTopologyTemplate(topologyTemplate) : null); + + return copy; + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplates.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplates.java new file mode 100644 index 000000000..39e553144 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplates.java @@ -0,0 +1,87 @@ +/*- + * ============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 JpaToscaServiceTemplates extends PfConceptContainer { + private static final long serialVersionUID = -3053257884307604114L; + + /** + * The Default Constructor creates a {@link JpaToscaServiceTemplates} object with a null artifact key and creates an + * empty concept map. + */ + public JpaToscaServiceTemplates() { + super(new PfConceptKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaServiceTemplates} object with the given artifact key and creates an + * empty concept map. + * + * @param key the concept key + */ + public JpaToscaServiceTemplates(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 JpaToscaServiceTemplates(final PfConceptKey key, + final Map conceptMap) { + super(key, conceptMap); + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaServiceTemplates(final JpaToscaServiceTemplates copyConcept) { + super(copyConcept); + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.java new file mode 100644 index 000000000..369aa03c1 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeInterval.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 JpaToscaTimeInterval 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 JpaToscaTimeInterval} object with a null key. + */ + public JpaToscaTimeInterval() { + this(new PfReferenceKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaTimeInterval} object with the given concept key. + * + * @param key the key + */ + public JpaToscaTimeInterval(@NonNull final PfReferenceKey key) { + this(key, new Date(0), new Date(0)); + } + + /** + * The full constructor creates a {@link JpaToscaTimeInterval} object with all fields. + * + * @param key the key + */ + public JpaToscaTimeInterval(@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 JpaToscaTimeInterval(final JpaToscaTimeInterval 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 JpaToscaTimeInterval other = (JpaToscaTimeInterval) 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, JpaToscaTimeInterval.class); + + final JpaToscaTimeInterval copy = ((JpaToscaTimeInterval) 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/JpaToscaTopologyTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java new file mode 100644 index 000000000..095435a7f --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.models.tosca.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 JpaToscaTopologyTemplate extends PfConcept { + private static final long serialVersionUID = 8969698734673232603L; + + public static final String DEFAULT_LOCAL_NAME = "ToscaTopologyTemplateSimple"; + + @EmbeddedId + private PfReferenceKey key; + + @Column(name = "description") + private String description; + + @OneToOne(cascade = CascadeType.ALL) + private JpaToscaPolicies policies; + + /** + * The Default Constructor creates a {@link JpaToscaTopologyTemplate} object with a null key. + */ + public JpaToscaTopologyTemplate() { + this(new PfReferenceKey(JpaToscaServiceTemplate.DEFAULT_NAME, JpaToscaServiceTemplate.DEFAULT_VERSION, + DEFAULT_LOCAL_NAME)); + } + + /** + * The Key Constructor creates a {@link JpaToscaTopologyTemplate} object with the given concept + * key. + * + * @param key the key + */ + public JpaToscaTopologyTemplate(@NonNull final PfReferenceKey key) { + this.key = key; + } + + /** + * Copy constructor. + * + * @param copyConcept the concept to copy from + */ + public JpaToscaTopologyTemplate(final JpaToscaTopologyTemplate 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 JpaToscaTopologyTemplate other = (JpaToscaTopologyTemplate) 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 JpaToscaTopologyTemplate copy = ((JpaToscaTopologyTemplate) copyObject); + copy.setKey(new PfReferenceKey(key)); + copy.setDescription(description); + copy.setPolicies(policies != null ? new JpaToscaPolicies(policies) : null); + + return copy; + } +} diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTrigger.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTrigger.java new file mode 100644 index 000000000..0a32701c9 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTrigger.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 JpaToscaTrigger 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 JpaToscaTimeInterval schedule; + + @Column + @SerializedName("target_filter") + private JpaToscaEventFilter targetFilter; + + @Column + private JpaToscaConstraint condition; + + @Column + private JpaToscaConstraint 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 JpaToscaTrigger} object with a null key. + */ + public JpaToscaTrigger() { + this(new PfReferenceKey()); + } + + /** + * The Key Constructor creates a {@link JpaToscaTrigger} object with the given concept key. + * + * @param key the key + */ + public JpaToscaTrigger(@NonNull final PfReferenceKey key) { + this(key, "", ""); + } + + /** + * The full Constructor creates a {@link JpaToscaTrigger} object with all mandatory objects. + * + * @param key the key + * @param eventType the event type + * @param action the trigger action + */ + public JpaToscaTrigger(@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 JpaToscaTrigger(final JpaToscaTrigger 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 JpaToscaTrigger other = (JpaToscaTrigger) 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 JpaToscaTrigger 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, JpaToscaTrigger.class); + + final JpaToscaTrigger copy = ((JpaToscaTrigger) target); + copy.setKey(new PfReferenceKey(key)); + copy.setDescription(description); + copy.setEventType(eventType); + copy.setSchedule(schedule != null ? new JpaToscaTimeInterval(schedule) : null); + copy.setTargetFilter(targetFilter != null ? new JpaToscaEventFilter(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/concepts/ToscaConstraint.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraint.java deleted file mode 100644 index ee153a295..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.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 deleted file mode 100644 index 25a03c9e1..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.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 deleted file mode 100644 index 0fe50dd71..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.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 deleted file mode 100644 index fbf036004..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.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/ToscaConstraintValidValues.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintValidValues.java deleted file mode 100644 index 98629a603..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintValidValues.java +++ /dev/null @@ -1,121 +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.simple.concepts; - -import com.google.gson.annotations.SerializedName; - -import java.util.LinkedList; -import java.util.List; -import javax.persistence.ElementCollection; -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.PfModelRuntimeException; -import org.onap.policy.models.base.PfReferenceKey; - -/** - * This class represents valid_values TOSCA constraint. - * - * @author Chenfei Gao (cgao@research.att.com) - */ -@EqualsAndHashCode(callSuper = false) -@Data -public class ToscaConstraintValidValues extends ToscaConstraint { - private static final long serialVersionUID = 3152323457560746844L; - - @SerializedName("valid_values") - @NonNull - @ElementCollection - private final List validValues; - - /** - * The Default Constructor creates a {@link ToscaConstraintValidValues} object with a null key. - */ - public ToscaConstraintValidValues() { - this(new PfReferenceKey()); - } - - /** - * The Key Constructor creates a {@link ToscaConstraintValidValues} object with the given concept key. - * - * @param key the key of the constraint - */ - public ToscaConstraintValidValues(final PfReferenceKey key) { - super(key); - validValues = new LinkedList<>(); - } - - /** - * The Key Constructor creates a {@link ToscaConstraintLogical} object with the given concept key - * and valid values list. - * - * @param key the key of the constraint - * @param validValues the valid values list of the constraint - * - */ - public ToscaConstraintValidValues(final PfReferenceKey key, @NonNull final List validValues) { - super(key); - this.validValues = validValues; - } - - /** - * Copy constructor. - * - * @param copyConcept the concept to copy from - */ - public ToscaConstraintValidValues(@NonNull final ToscaConstraintValidValues 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 ToscaConstraintValidValues other = (ToscaConstraintValidValues) otherConcept; - - int result = super.compareTo(other); - if (result != 0) { - return result; - } - - if (validValues.equals(other.validValues)) { - return 0; - } - return -1; - } - - @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 deleted file mode 100644 index e7d91ea40..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.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 deleted file mode 100644 index eae98a1bc..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypes.java +++ /dev/null @@ -1,89 +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.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; - - public static final String DEFAULT_NAME = "ToscaDataTypesSimple"; - public static final String DEFAULT_VERSION = "1.0.0"; - - /** - * The Default Constructor creates a {@link ToscaDataTypes} object with a null artifact key - * and creates an empty concept map. - */ - public ToscaDataTypes() { - super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION)); - } - - /** - * 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 deleted file mode 100644 index f2ae05119..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntityType.java +++ /dev/null @@ -1,218 +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.simple.concepts; - -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.TreeMap; - -import javax.persistence.AttributeOverride; -import javax.persistence.AttributeOverrides; -import javax.persistence.Column; -import javax.persistence.ElementCollection; -import javax.persistence.EmbeddedId; -import javax.persistence.MappedSuperclass; - -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. - */ -@MappedSuperclass -@Data -@EqualsAndHashCode(callSuper = false) -public class ToscaEntityType extends PfConcept { - private static final long serialVersionUID = -1330661834220739393L; - - @EmbeddedId - private PfConceptKey key; - - // @formatter:off - @Column - @AttributeOverrides({ - @AttributeOverride(name = "name", - column = @Column(name = "derived_from_name")), - @AttributeOverride(name = "version", - column = @Column(name = "derived_from_version")) - }) - private PfConceptKey derivedFrom; - - @ElementCollection - private Map metadata; - - @Column - private String description; - // @formatter:on - - /** - * 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 deleted file mode 100644 index 2dca1ef55..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.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 deleted file mode 100644 index e2e5488e0..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.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 deleted file mode 100644 index a7852976d..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.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 deleted file mode 100644 index f318bb6be..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicies.java +++ /dev/null @@ -1,89 +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.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; - - public static final String DEFAULT_NAME = "ToscaPoliciesSimple"; - public static final String DEFAULT_VERSION = "1.0.0"; - - /** - * The Default Constructor creates a {@link ToscaPolicies} object with a null artifact key and - * creates an empty concept map. - */ - public ToscaPolicies() { - super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION)); - } - - /** - * 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 deleted file mode 100644 index e08079c40..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicy.java +++ /dev/null @@ -1,271 +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.simple.concepts; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; - -import javax.persistence.AttributeOverride; -import javax.persistence.AttributeOverrides; -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; - - // @formatter:off - @Column - @AttributeOverrides({ - @AttributeOverride(name = "name", - column = @Column(name = "type_name")), - @AttributeOverride(name = "version", - column = @Column(name = "type_version")) - }) - private PfConceptKey type; - - @ElementCollection - @Column(length = 10000) - private Map properties; - - @ElementCollection - private List targets; - // @formatter:on - - /** - * 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 deleted file mode 100644 index b155192cb..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.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 deleted file mode 100644 index 277291364..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypes.java +++ /dev/null @@ -1,89 +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.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; - - public static final String DEFAULT_NAME = "ToscaPolicyTypesSimple"; - public static final String DEFAULT_VERSION = "1.0.0"; - - /** - * The Default Constructor creates a {@link ToscaPolicyTypes} object with a null artifact key - * and creates an empty concept map. - */ - public ToscaPolicyTypes() { - super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION)); - } - - /** - * 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 deleted file mode 100644 index 2276f5a7a..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaProperty.java +++ /dev/null @@ -1,304 +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.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 String 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 (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 = defaultValue.trim(); - } - - 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.trim().length() == 0) { - 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 deleted file mode 100644 index c3bb9165e..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplate.java +++ /dev/null @@ -1,225 +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.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; - - public static final String DEFAULT_NAME = "ToscaServiceTemplateSimple"; - public static final String DEFAULT_VERSION = "1.0.0"; - - @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(DEFAULT_NAME, DEFAULT_VERSION)); - } - - /** - * 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 deleted file mode 100644 index 33d774889..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.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 deleted file mode 100644 index 69c7c6c97..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.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 deleted file mode 100644 index 5b21ca0c1..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/ToscaTopologyTemplate.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.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; - - public static final String DEFAULT_LOCAL_NAME = "ToscaTopologyTemplateSimple"; - - @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(ToscaServiceTemplate.DEFAULT_NAME, ToscaServiceTemplate.DEFAULT_VERSION, - DEFAULT_LOCAL_NAME)); - } - - /** - * 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 deleted file mode 100644 index d772d554e..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/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.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/JpaToscaServiceTemplateMapper.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/mapping/JpaToscaServiceTemplateMapper.java new file mode 100644 index 000000000..e7a4056f7 --- /dev/null +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/mapping/JpaToscaServiceTemplateMapper.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.JpaToscaServiceTemplate; + +/** + * 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 JpaToscaServiceTemplateMapper { + + /** + * Translate from the other format to a TOSCA service template. + * + * @param otherPolicyType the other policy type + * @return the TOSCA service template + */ + public JpaToscaServiceTemplate 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 JpaToscaServiceTemplate serviceTemplate); +} 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 deleted file mode 100644 index 6dcbfe694..000000000 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/mapping/ToscaServiceTemplateMapper.java +++ /dev/null @@ -1,49 +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.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/provider/SimpleToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java index c7984c5ea..6e356d0ab 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java @@ -28,12 +28,12 @@ import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.dao.PfDao; -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.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; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; import org.onap.policy.models.tosca.utils.ToscaUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -55,15 +55,15 @@ public class SimpleToscaProvider { * @return the policy types found * @throws PfModelException on errors getting policy types */ - public ToscaServiceTemplate getPolicyTypes(@NonNull final PfDao dao, @NonNull final PfConceptKey policyTypeKey) + public JpaToscaServiceTemplate getPolicyTypes(@NonNull final PfDao dao, @NonNull final PfConceptKey policyTypeKey) throws PfModelException { // Create the structure of the TOSCA service template to contain the policy type - ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); - serviceTemplate.setPolicyTypes(new ToscaPolicyTypes()); + JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); + serviceTemplate.setPolicyTypes(new JpaToscaPolicyTypes()); // Add the policy type to the TOSCA service template - ToscaPolicyType policyType = dao.get(ToscaPolicyType.class, policyTypeKey); + JpaToscaPolicyType policyType = dao.get(JpaToscaPolicyType.class, policyTypeKey); if (policyType != null) { serviceTemplate.getPolicyTypes().getConceptMap().put(policyTypeKey, policyType); return serviceTemplate; @@ -82,23 +82,23 @@ public class SimpleToscaProvider { * @return the TOSCA service template containing the created policy types * @throws PfModelException on errors creating policy types */ - public ToscaServiceTemplate createPolicyTypes(@NonNull final PfDao dao, - @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { + public JpaToscaServiceTemplate createPolicyTypes(@NonNull final PfDao dao, + @NonNull final JpaToscaServiceTemplate serviceTemplate) throws PfModelException { ToscaUtils.assertPolicyTypesExist(serviceTemplate); - for (ToscaPolicyType policyType : serviceTemplate.getPolicyTypes().getAll(null)) { + for (JpaToscaPolicyType policyType : serviceTemplate.getPolicyTypes().getAll(null)) { dao.create(policyType); } // Return the created policy types - ToscaPolicyTypes returnPolicyTypes = new ToscaPolicyTypes(); + JpaToscaPolicyTypes returnPolicyTypes = new JpaToscaPolicyTypes(); for (PfConceptKey policyTypeKey : serviceTemplate.getPolicyTypes().getConceptMap().keySet()) { - returnPolicyTypes.getConceptMap().put(policyTypeKey, dao.get(ToscaPolicyType.class, policyTypeKey)); + returnPolicyTypes.getConceptMap().put(policyTypeKey, dao.get(JpaToscaPolicyType.class, policyTypeKey)); } - ToscaServiceTemplate returnServiceTemplate = new ToscaServiceTemplate(); + JpaToscaServiceTemplate returnServiceTemplate = new JpaToscaServiceTemplate(); returnServiceTemplate.setPolicyTypes(returnPolicyTypes); return returnServiceTemplate; @@ -112,23 +112,23 @@ public class SimpleToscaProvider { * @return the TOSCA service template containing the modified policy types * @throws PfModelException on errors updating policy types */ - public ToscaServiceTemplate updatePolicyTypes(@NonNull final PfDao dao, - @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { + public JpaToscaServiceTemplate updatePolicyTypes(@NonNull final PfDao dao, + @NonNull final JpaToscaServiceTemplate serviceTemplate) throws PfModelException { ToscaUtils.assertPolicyTypesExist(serviceTemplate); - for (ToscaPolicyType policyType : serviceTemplate.getPolicyTypes().getAll(null)) { + for (JpaToscaPolicyType policyType : serviceTemplate.getPolicyTypes().getAll(null)) { dao.update(policyType); } // Return the created policy types - ToscaPolicyTypes returnPolicyTypes = new ToscaPolicyTypes(); + JpaToscaPolicyTypes returnPolicyTypes = new JpaToscaPolicyTypes(); for (PfConceptKey policyTypeKey : serviceTemplate.getPolicyTypes().getConceptMap().keySet()) { - returnPolicyTypes.getConceptMap().put(policyTypeKey, dao.get(ToscaPolicyType.class, policyTypeKey)); + returnPolicyTypes.getConceptMap().put(policyTypeKey, dao.get(JpaToscaPolicyType.class, policyTypeKey)); } - ToscaServiceTemplate returnServiceTemplate = new ToscaServiceTemplate(); + JpaToscaServiceTemplate returnServiceTemplate = new JpaToscaServiceTemplate(); returnServiceTemplate.setPolicyTypes(returnPolicyTypes); return returnServiceTemplate; @@ -143,12 +143,13 @@ public class SimpleToscaProvider { * @return the TOSCA service template containing the policy types that were deleted * @throws PfModelException on errors deleting policy types */ - public ToscaServiceTemplate deletePolicyTypes(@NonNull final PfDao dao, @NonNull final PfConceptKey policyTypeKey) + public JpaToscaServiceTemplate deletePolicyTypes(@NonNull final PfDao dao, + @NonNull final PfConceptKey policyTypeKey) throws PfModelException { - ToscaServiceTemplate serviceTemplate = getPolicyTypes(dao, policyTypeKey); + JpaToscaServiceTemplate serviceTemplate = getPolicyTypes(dao, policyTypeKey); - dao.delete(ToscaPolicyType.class, policyTypeKey); + dao.delete(JpaToscaPolicyType.class, policyTypeKey); return serviceTemplate; } @@ -162,16 +163,16 @@ public class SimpleToscaProvider { * @return the policies found * @throws PfModelException on errors getting policies */ - public ToscaServiceTemplate getPolicies(@NonNull final PfDao dao, @NonNull final PfConceptKey policyKey) + public JpaToscaServiceTemplate getPolicies(@NonNull final PfDao dao, @NonNull final PfConceptKey policyKey) throws PfModelException { // Create the structure of the TOSCA service template to contain the policy type - ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); - serviceTemplate.setTopologyTemplate(new ToscaTopologyTemplate()); - serviceTemplate.getTopologyTemplate().setPolicies(new ToscaPolicies()); + JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); + serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); + serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); // Add the policy to the TOSCA service template - ToscaPolicy policy = dao.get(ToscaPolicy.class, policyKey); + JpaToscaPolicy policy = dao.get(JpaToscaPolicy.class, policyKey); if (policy != null) { serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().put(policyKey, policy); return serviceTemplate; @@ -190,21 +191,21 @@ public class SimpleToscaProvider { * @return the TOSCA service template containing the policy types that were created * @throws PfModelException on errors creating policies */ - public ToscaServiceTemplate createPolicies(@NonNull final PfDao dao, - @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { + public JpaToscaServiceTemplate createPolicies(@NonNull final PfDao dao, + @NonNull final JpaToscaServiceTemplate serviceTemplate) throws PfModelException { ToscaUtils.assertPoliciesExist(serviceTemplate); - for (ToscaPolicy policy : serviceTemplate.getTopologyTemplate().getPolicies().getAll(null)) { + for (JpaToscaPolicy policy : serviceTemplate.getTopologyTemplate().getPolicies().getAll(null)) { dao.create(policy); } // Return the created policy types - ToscaPolicies returnPolicies = new ToscaPolicies(); + JpaToscaPolicies returnPolicies = new JpaToscaPolicies(); returnPolicies.setKey(serviceTemplate.getTopologyTemplate().getPolicies().getKey()); for (PfConceptKey policyKey : serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().keySet()) { - returnPolicies.getConceptMap().put(policyKey, dao.get(ToscaPolicy.class, policyKey)); + returnPolicies.getConceptMap().put(policyKey, dao.get(JpaToscaPolicy.class, policyKey)); } serviceTemplate.getTopologyTemplate().setPolicies(returnPolicies); @@ -220,21 +221,21 @@ public class SimpleToscaProvider { * @return the TOSCA service template containing the policies that were updated * @throws PfModelException on errors updating policies */ - public ToscaServiceTemplate updatePolicies(@NonNull final PfDao dao, - @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException { + public JpaToscaServiceTemplate updatePolicies(@NonNull final PfDao dao, + @NonNull final JpaToscaServiceTemplate serviceTemplate) throws PfModelException { ToscaUtils.assertPoliciesExist(serviceTemplate); - for (ToscaPolicy policy : serviceTemplate.getTopologyTemplate().getPolicies().getAll(null)) { + for (JpaToscaPolicy policy : serviceTemplate.getTopologyTemplate().getPolicies().getAll(null)) { dao.update(policy); } // Return the created policy types - ToscaPolicies returnPolicies = new ToscaPolicies(); + JpaToscaPolicies returnPolicies = new JpaToscaPolicies(); returnPolicies.setKey(serviceTemplate.getTopologyTemplate().getPolicies().getKey()); for (PfConceptKey policyKey : serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().keySet()) { - returnPolicies.getConceptMap().put(policyKey, dao.get(ToscaPolicy.class, policyKey)); + returnPolicies.getConceptMap().put(policyKey, dao.get(JpaToscaPolicy.class, policyKey)); } serviceTemplate.getTopologyTemplate().setPolicies(returnPolicies); @@ -250,12 +251,12 @@ public class SimpleToscaProvider { * @return the TOSCA service template containing the policies that were deleted * @throws PfModelException on errors deleting policies */ - public ToscaServiceTemplate deletePolicies(@NonNull final PfDao dao, @NonNull final PfConceptKey policyKey) + public JpaToscaServiceTemplate deletePolicies(@NonNull final PfDao dao, @NonNull final PfConceptKey policyKey) throws PfModelException { - ToscaServiceTemplate serviceTemplate = getPolicies(dao, policyKey); + JpaToscaServiceTemplate serviceTemplate = getPolicies(dao, policyKey); - dao.delete(ToscaPolicy.class, policyKey); + dao.delete(JpaToscaPolicy.class, policyKey); return serviceTemplate; } diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaDataTypeJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaDataTypeJsonAdapter.java index 65e3d4ebf..6b00b20b6 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaDataTypeJsonAdapter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaDataTypeJsonAdapter.java @@ -34,8 +34,8 @@ 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.ToscaDataType; -import org.onap.policy.models.tosca.simple.concepts.ToscaProperty; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,7 +44,7 @@ import org.slf4j.LoggerFactory; * * @author Chenfei Gao (cgao@research.att.com) */ -public class ToscaDataTypeJsonAdapter implements JsonSerializer, JsonDeserializer { +public class ToscaDataTypeJsonAdapter implements JsonSerializer, JsonDeserializer { private static final Logger LOGGER = LoggerFactory.getLogger(ToscaDataTypeJsonAdapter.class); @@ -55,7 +55,7 @@ public class ToscaDataTypeJsonAdapter implements JsonSerializer, private static final String DEFAULT_VERSION = "1.0.0"; @Override - public ToscaDataType deserialize(@NonNull final JsonElement dataTypeElement, @NonNull final Type type, + public JpaToscaDataType deserialize(@NonNull final JsonElement dataTypeElement, @NonNull final Type type, @NonNull final JsonDeserializationContext context) { // The incoming JSON @@ -79,7 +79,7 @@ public class ToscaDataTypeJsonAdapter implements JsonSerializer, } else { dataTypeKey = new PfConceptKey(dataTypeName, dataTypeJsonObject.get(VERSION).getAsString()); } - ToscaDataType dataType = new ToscaDataType(dataTypeKey); + JpaToscaDataType dataType = new JpaToscaDataType(dataTypeKey); // Set derived_from dataType.setDerivedFrom(new PfConceptKey(dataTypeJsonObject.get(DERIVED_FROM).getAsString(), @@ -95,7 +95,7 @@ public class ToscaDataTypeJsonAdapter implements JsonSerializer, if (dataTypeJsonObject.has(PROPERTIES)) { dataType.setProperties( new ToscaPropertiesJsonAdapter().deserializeProperties(dataTypeJsonObject.get(PROPERTIES))); - for (ToscaProperty property : dataType.getProperties()) { + for (JpaToscaProperty property : dataType.getProperties()) { property.getKey().setParentConceptKey(dataTypeKey); property.getType().setVersion(dataType.getKey().getVersion()); } @@ -105,7 +105,7 @@ public class ToscaDataTypeJsonAdapter implements JsonSerializer, } @Override - public JsonElement serialize(@NonNull final ToscaDataType dataType, @NonNull final Type type, + public JsonElement serialize(@NonNull final JpaToscaDataType dataType, @NonNull final Type type, @NonNull final JsonSerializationContext context) { JsonObject dataTypeValJsonObject = new JsonObject(); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaDataTypesJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaDataTypesJsonAdapter.java index 387b499cf..6131581ad 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaDataTypesJsonAdapter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaDataTypesJsonAdapter.java @@ -34,8 +34,8 @@ 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.ToscaDataType; -import org.onap.policy.models.tosca.simple.concepts.ToscaDataTypes; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,12 +44,13 @@ import org.slf4j.LoggerFactory; * * @author Chenfei Gao (cgao@research.att.com) */ -public class ToscaDataTypesJsonAdapter implements JsonSerializer, JsonDeserializer { +public class ToscaDataTypesJsonAdapter + implements JsonSerializer, JsonDeserializer { private static final Logger LOGGER = LoggerFactory.getLogger(ToscaDataTypesJsonAdapter.class); @Override - public ToscaDataTypes deserialize(@NonNull final JsonElement dataTypesElement, @NonNull final Type type, + public JpaToscaDataTypes deserialize(@NonNull final JsonElement dataTypesElement, @NonNull final Type type, @NonNull final JsonDeserializationContext context) { // The incoming JSON @@ -57,13 +58,13 @@ public class ToscaDataTypesJsonAdapter implements JsonSerializer // The outgoing object final PfConceptKey dataTypesKey = new PfConceptKey("IncomingDataTypes", "0.0.1"); - final ToscaDataTypes dataTypes = new ToscaDataTypes(dataTypesKey); + final JpaToscaDataTypes dataTypes = new JpaToscaDataTypes(dataTypesKey); // Get the dataTypes Iterator dataTypesIterator = dataTypesJsonArray.iterator(); while (dataTypesIterator.hasNext()) { - ToscaDataType dataType = new ToscaDataTypeJsonAdapter() - .deserialize(dataTypesIterator.next(), ToscaDataType.class, context); + JpaToscaDataType dataType = new ToscaDataTypeJsonAdapter().deserialize(dataTypesIterator.next(), + JpaToscaDataType.class, context); dataTypes.getConceptMap().put(dataType.getKey(), dataType); } @@ -72,7 +73,7 @@ public class ToscaDataTypesJsonAdapter implements JsonSerializer } @Override - public JsonElement serialize(@NonNull final ToscaDataTypes dataTypes, @NonNull final Type type, + public JsonElement serialize(@NonNull final JpaToscaDataTypes dataTypes, @NonNull final Type type, @NonNull final JsonSerializationContext context) { JsonArray dataTypesJsonArray = new JsonArray(); @@ -83,8 +84,8 @@ public class ToscaDataTypesJsonAdapter implements JsonSerializer throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage); } - for (ToscaDataType dataType: dataTypes.getConceptMap().values()) { - JsonElement dataTypeEntry = new ToscaDataTypeJsonAdapter().serialize(dataType, type, context); + for (JpaToscaDataType dataType : dataTypes.getConceptMap().values()) { + JsonElement dataTypeEntry = new ToscaDataTypeJsonAdapter().serialize(dataType, type, context); dataTypesJsonArray.add(dataTypeEntry); } 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 index 4b1b53c79..ca0e3d937 100644 --- 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 @@ -33,8 +33,8 @@ 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; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; /** * GSON type adapter for TOSCA policies. @@ -42,22 +42,22 @@ import org.onap.policy.models.tosca.simple.concepts.ToscaPolicy; * @author Liam Fallon (liam.fallon@est.tech) * @author Chenfei Gao (cgao@research.att.com) */ -public class ToscaPoliciesJsonAdapter implements JsonSerializer, JsonDeserializer { +public class ToscaPoliciesJsonAdapter implements JsonSerializer, JsonDeserializer { @Override - public ToscaPolicies deserialize(@NonNull final JsonElement policiesElement, @NonNull final Type type, + public JpaToscaPolicies 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); + final JpaToscaPolicies policies = new JpaToscaPolicies(policiesKey); // Get the policies for (Iterator policiesIterator = policiesJsonArray.iterator(); policiesIterator.hasNext(); ) { - ToscaPolicy policy = new ToscaPolicyJsonAdapter() - .deserialize(policiesIterator.next(), ToscaPolicy.class, context); + JpaToscaPolicy policy = new ToscaPolicyJsonAdapter() + .deserialize(policiesIterator.next(), JpaToscaPolicy.class, context); policies.getConceptMap().put(policy.getKey(), policy); } @@ -66,12 +66,12 @@ public class ToscaPoliciesJsonAdapter implements JsonSerializer, } @Override - public JsonElement serialize(@NonNull final ToscaPolicies policies, @NonNull final Type type, + public JsonElement serialize(@NonNull final JpaToscaPolicies policies, @NonNull final Type type, @NonNull final JsonSerializationContext context) { JsonArray policiesJsonArray = new JsonArray(); - for (ToscaPolicy policy: policies.getConceptMap().values()) { + for (JpaToscaPolicy policy: policies.getConceptMap().values()) { policiesJsonArray.add(new ToscaPolicyJsonAdapter().serialize(policy, type, context)); } return policiesJsonArray; 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 index b52634b83..6b666e214 100644 --- 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 @@ -40,7 +40,7 @@ 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.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,7 +50,7 @@ import org.slf4j.LoggerFactory; * @author Liam Fallon (liam.fallon@est.tech) * @author Chenfei Gao (cgao@research.att.com) */ -public class ToscaPolicyJsonAdapter implements JsonSerializer, JsonDeserializer { +public class ToscaPolicyJsonAdapter implements JsonSerializer, JsonDeserializer { // Logger for this class private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyJsonAdapter.class); @@ -63,7 +63,7 @@ public class ToscaPolicyJsonAdapter implements JsonSerializer, Json private final Gson gson = new GsonBuilder().setPrettyPrinting().create(); @Override - public ToscaPolicy deserialize(@NonNull final JsonElement policyElement, @NonNull final Type type, + public JpaToscaPolicy deserialize(@NonNull final JsonElement policyElement, @NonNull final Type type, @NonNull final JsonDeserializationContext context) { // The incoming JSON @@ -85,7 +85,7 @@ public class ToscaPolicyJsonAdapter implements JsonSerializer, Json PfConceptKey policyTypeKey = new PfConceptKey( policyJsonObject.get(TYPE).getAsString(), policyJsonObject.get(VERSION).getAsString()); - ToscaPolicy policy = new ToscaPolicy(policyKey, policyTypeKey); + JpaToscaPolicy policy = new JpaToscaPolicy(policyKey, policyTypeKey); // Set description if (policyJsonObject.has(DESCRIPTION)) { @@ -121,7 +121,7 @@ public class ToscaPolicyJsonAdapter implements JsonSerializer, Json } @Override - public JsonElement serialize(@NonNull final ToscaPolicy policy, @NonNull final Type type, + public JsonElement serialize(@NonNull final JpaToscaPolicy policy, @NonNull final Type type, @NonNull final JsonSerializationContext context) { JsonObject policyValJsonObject = new JsonObject(); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyTypeJsonAdapter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyTypeJsonAdapter.java index 3bf98572f..a96642261 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyTypeJsonAdapter.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/serialization/ToscaPolicyTypeJsonAdapter.java @@ -33,8 +33,8 @@ 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.ToscaPolicyType; -import org.onap.policy.models.tosca.simple.concepts.ToscaProperty; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,7 +43,8 @@ import org.slf4j.LoggerFactory; * * @author Chenfei Gao (cgao@research.att.com) */ -public class ToscaPolicyTypeJsonAdapter implements JsonSerializer, JsonDeserializer { +public class ToscaPolicyTypeJsonAdapter + implements JsonSerializer, JsonDeserializer { private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyTypeJsonAdapter.class); @@ -54,7 +55,7 @@ public class ToscaPolicyTypeJsonAdapter implements JsonSerializer, - JsonDeserializer { +public class ToscaPolicyTypesJsonAdapter implements JsonSerializer, + JsonDeserializer { private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyTypesJsonAdapter.class); @Override - public ToscaPolicyTypes deserialize(@NonNull final JsonElement policyTypesElement, @NonNull final Type type, + public JpaToscaPolicyTypes deserialize(@NonNull final JsonElement policyTypesElement, @NonNull final Type type, @NonNull final JsonDeserializationContext context) { // The incoming JSON @@ -58,13 +58,13 @@ public class ToscaPolicyTypesJsonAdapter implements JsonSerializer policyTypesIterator = policyTypesJsonArray.iterator(); while (policyTypesIterator.hasNext()) { - ToscaPolicyType policyType = new ToscaPolicyTypeJsonAdapter() - .deserialize(policyTypesIterator.next(), ToscaPolicyType.class, context); + JpaToscaPolicyType policyType = new ToscaPolicyTypeJsonAdapter() + .deserialize(policyTypesIterator.next(), JpaToscaPolicyType.class, context); policyTypes.getConceptMap().put(policyType.getKey(), policyType); } @@ -73,7 +73,7 @@ public class ToscaPolicyTypesJsonAdapter implements JsonSerializer deserializeProperties(JsonElement propertiesElement) { + public List deserializeProperties(JsonElement propertiesElement) { final JsonObject propertiesMapObject = propertiesElement.getAsJsonObject(); - List properties = new LinkedList<>(); + List properties = new LinkedList<>(); for (Entry entry : propertiesMapObject.entrySet()) { final String propertyEntryKey = entry.getKey(); final JsonElement propertyEntryVal = entry.getValue(); // Set property: key and type - ToscaProperty property = new ToscaProperty( + JpaToscaProperty property = new JpaToscaProperty( new PfReferenceKey(new PfConceptKey(), propertyEntryKey), new PfConceptKey(propertyEntryVal.getAsJsonObject().get(TYPE).getAsString(), DEFAULT_VERSION)); @@ -110,7 +110,7 @@ public class ToscaPropertiesJsonAdapter { // Set property: constraints if (propertyJsonObject.has(CONSTRAINTS)) { property.setConstraints(deserializeConstraints(propertyJsonObject.get(CONSTRAINTS))); - for (ToscaConstraint c : property.getConstraints()) { + for (JpaToscaConstraint c : property.getConstraints()) { c.getKey().setParentConceptKey(property.getType()); } } @@ -129,11 +129,11 @@ public class ToscaPropertiesJsonAdapter { * * @return serialized JsonElement */ - public JsonElement serializeProperties(List properties) { + public JsonElement serializeProperties(List properties) { JsonObject propertiesJsonObject = new JsonObject(); - for (ToscaProperty property : properties) { + for (JpaToscaProperty property : properties) { JsonObject propertyValJsonObject = new JsonObject(); // Add type @@ -168,23 +168,23 @@ public class ToscaPropertiesJsonAdapter { return propertiesJsonObject; } - private JsonElement serializeConstraints(List constraints) { + private JsonElement serializeConstraints(List constraints) { JsonArray constraintsValJsonArray = new JsonArray(); - for (ToscaConstraint c : constraints) { + for (JpaToscaConstraint c : constraints) { JsonObject constraintJsonObject = new JsonObject(); // Check which type of constraint it is // TODO: here we only support valid_values and equal - if (c instanceof ToscaConstraintValidValues) { + if (c instanceof JpaToscaConstraintValidValues) { JsonArray validValuesJsonArray = new JsonArray(); - for (String validValue : ((ToscaConstraintValidValues)c).getValidValues()) { + for (String validValue : ((JpaToscaConstraintValidValues)c).getValidValues()) { validValuesJsonArray.add(validValue); } constraintJsonObject.add(VALID_VALUES, validValuesJsonArray); - } else if (c instanceof ToscaConstraintLogicalString) { - constraintJsonObject.addProperty(EQUAL, ((ToscaConstraintLogicalString)c).getCompareToString()); + } else if (c instanceof JpaToscaConstraintLogicalString) { + constraintJsonObject.addProperty(EQUAL, ((JpaToscaConstraintLogicalString)c).getCompareToString()); } else { String errorMessage = "constraint is neither valid_values nor equal"; LOGGER.debug(errorMessage); @@ -197,7 +197,7 @@ public class ToscaPropertiesJsonAdapter { return constraintsValJsonArray; } - private JsonElement serializeEntrySchema(ToscaEntrySchema entrySchema) { + private JsonElement serializeEntrySchema(JpaToscaEntrySchema entrySchema) { JsonObject entrySchemaValJsonObject = new JsonObject(); @@ -217,12 +217,12 @@ public class ToscaPropertiesJsonAdapter { return entrySchemaValJsonObject; } - private ToscaEntrySchema deserializeEntrySchema(JsonElement entrySchemaElement) { + private JpaToscaEntrySchema deserializeEntrySchema(JsonElement entrySchemaElement) { JsonObject entrySchemaJsonObject = entrySchemaElement.getAsJsonObject(); // Set entry_schema: key and type - ToscaEntrySchema entrySchema = new ToscaEntrySchema( + JpaToscaEntrySchema entrySchema = new JpaToscaEntrySchema( new PfReferenceKey(new PfConceptKey(), ENTRY_SCHEMA), new PfConceptKey(entrySchemaJsonObject.get(TYPE).getAsString(), DEFAULT_VERSION)); @@ -234,7 +234,7 @@ public class ToscaPropertiesJsonAdapter { // Set entry_schema: constraints if (entrySchemaJsonObject.has(CONSTRAINTS)) { entrySchema.setConstraints(deserializeConstraints(entrySchemaJsonObject.get(CONSTRAINTS))); - for (ToscaConstraint c : entrySchema.getConstraints()) { + for (JpaToscaConstraint c : entrySchema.getConstraints()) { c.getKey().setParentConceptKey(entrySchema.getType()); } } @@ -242,10 +242,10 @@ public class ToscaPropertiesJsonAdapter { return entrySchema; } - private List deserializeConstraints(JsonElement constraintsElement) { + private List deserializeConstraints(JsonElement constraintsElement) { JsonArray constraintsJsonArray = constraintsElement.getAsJsonArray(); - List constraints = new LinkedList<>(); + List constraints = new LinkedList<>(); for (Iterator constraintsIter = constraintsJsonArray.iterator(); constraintsIter.hasNext(); ) { JsonObject constraintJsonObject = constraintsIter.next().getAsJsonObject(); @@ -257,11 +257,11 @@ public class ToscaPropertiesJsonAdapter { .iterator(); validValuesIter.hasNext(); ) { validValues.add(validValuesIter.next().getAsString()); } - ToscaConstraint constraint = new ToscaConstraintValidValues( + JpaToscaConstraint constraint = new JpaToscaConstraintValidValues( new PfReferenceKey(new PfConceptKey(), VALID_VALUES), validValues); constraints.add(constraint); } else if (constraintJsonObject.get(EQUAL) != null) { - ToscaConstraint constraint = new ToscaConstraintLogicalString(new PfReferenceKey( + JpaToscaConstraint constraint = new JpaToscaConstraintLogicalString(new PfReferenceKey( new PfConceptKey(), EQUAL), Operation.EQ, constraintJsonObject.get(EQUAL).getAsString()); constraints.add(constraint); } else { 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 index 78f3153e2..bb2ace87e 100644 --- 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 @@ -32,10 +32,10 @@ import java.lang.reflect.Type; import lombok.NonNull; -import org.onap.policy.models.tosca.simple.concepts.ToscaDataTypes; -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; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; /** * GSON type adapter for TOSCA policies. @@ -44,7 +44,7 @@ import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate; * @author Chenfei Gao (cgao@research.att.com) */ public class ToscaServiceTemplateJsonAdapter - implements JsonSerializer, JsonDeserializer { + implements JsonSerializer, JsonDeserializer { private static final String TOPOLOGY_TEMPLATE = "topology_template"; private static final String TOSCA_DEFINITIONS_VERSION = "tosca_definitions_version"; @@ -52,40 +52,40 @@ public class ToscaServiceTemplateJsonAdapter private static final String DATA_TYPES = "data_types"; @Override - public ToscaServiceTemplate deserialize(@NonNull final JsonElement serviceTemplateElement, @NonNull final Type type, - @NonNull final JsonDeserializationContext context) { + public JpaToscaServiceTemplate 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 ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate(); + final JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate(); serviceTemplate .setToscaDefinitionsVersion(serviceTemplateJsonObject.get(TOSCA_DEFINITIONS_VERSION).getAsString()); // Set topology_template if (serviceTemplateJsonObject.has(TOPOLOGY_TEMPLATE)) { serviceTemplate.setTopologyTemplate(new ToscaTopologyTemplateJsonAdapter().deserialize( - serviceTemplateJsonObject.get(TOPOLOGY_TEMPLATE), ToscaTopologyTemplate.class, context)); + serviceTemplateJsonObject.get(TOPOLOGY_TEMPLATE), JpaToscaTopologyTemplate.class, context)); } // Set policy_types if (serviceTemplateJsonObject.has(POLICY_TYPES)) { serviceTemplate.setPolicyTypes(new ToscaPolicyTypesJsonAdapter() - .deserialize(serviceTemplateJsonObject.get(POLICY_TYPES), ToscaPolicyTypes.class, context)); + .deserialize(serviceTemplateJsonObject.get(POLICY_TYPES), JpaToscaPolicyTypes.class, context)); } // Set data_types if (serviceTemplateJsonObject.has(DATA_TYPES)) { serviceTemplate.setDataTypes(new ToscaDataTypesJsonAdapter() - .deserialize(serviceTemplateJsonObject.get(DATA_TYPES), ToscaDataTypes.class, context)); + .deserialize(serviceTemplateJsonObject.get(DATA_TYPES), JpaToscaDataTypes.class, context)); } return serviceTemplate; } @Override - public JsonElement serialize(@NonNull final ToscaServiceTemplate serviceTemplate, @NonNull final Type type, + public JsonElement serialize(@NonNull final JpaToscaServiceTemplate serviceTemplate, @NonNull final Type type, @NonNull final JsonSerializationContext context) { JsonObject serviceTemplateJsonObject = new JsonObject(); 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 index c7e78a524..b15a83016 100644 --- 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 @@ -21,14 +21,14 @@ 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.ToscaDataType; -import org.onap.policy.models.tosca.simple.concepts.ToscaDataTypes; -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.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; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,14 +56,14 @@ public class ToscaServiceTemplateMessageBodyHandler extends GsonMessageBodyHandl 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()) - .registerTypeAdapter(ToscaPolicyTypes.class, new ToscaPolicyTypesJsonAdapter()) - .registerTypeAdapter(ToscaPolicyType.class, new ToscaPolicyTypeJsonAdapter()) - .registerTypeAdapter(ToscaDataTypes.class, new ToscaDataTypesJsonAdapter()) - .registerTypeAdapter(ToscaDataType.class, new ToscaDataTypeJsonAdapter()) + .registerTypeAdapter(JpaToscaServiceTemplate.class, new ToscaServiceTemplateJsonAdapter()) + .registerTypeAdapter(JpaToscaTopologyTemplate.class, new ToscaTopologyTemplateJsonAdapter()) + .registerTypeAdapter(JpaToscaPolicies.class, new ToscaPoliciesJsonAdapter()) + .registerTypeAdapter(JpaToscaPolicy.class, new ToscaPolicyJsonAdapter()) + .registerTypeAdapter(JpaToscaPolicyTypes.class, new ToscaPolicyTypesJsonAdapter()) + .registerTypeAdapter(JpaToscaPolicyType.class, new ToscaPolicyTypeJsonAdapter()) + .registerTypeAdapter(JpaToscaDataTypes.class, new ToscaDataTypesJsonAdapter()) + .registerTypeAdapter(JpaToscaDataType.class, new ToscaDataTypeJsonAdapter()) .setPrettyPrinting() .create() ); 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 index d302b7e6c..df8ebb556 100644 --- 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 @@ -34,8 +34,8 @@ 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; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; /** * GSON type adapter for TOSCA policies. @@ -44,13 +44,13 @@ import org.onap.policy.models.tosca.simple.concepts.ToscaTopologyTemplate; * @author Chenfei Gao (cgao@research.att.com) */ public class ToscaTopologyTemplateJsonAdapter - implements JsonSerializer, JsonDeserializer { + implements JsonSerializer, JsonDeserializer { private static final String POLICIES = "policies"; private static final String DESCRIPTION = "description"; @Override - public ToscaTopologyTemplate deserialize(@NonNull final JsonElement toplogyTemplateElement, + public JpaToscaTopologyTemplate deserialize(@NonNull final JsonElement toplogyTemplateElement, @NonNull final Type type, @NonNull final JsonDeserializationContext context) { // The incoming JSON @@ -58,7 +58,7 @@ public class ToscaTopologyTemplateJsonAdapter // The outgoing object final PfReferenceKey topologyTemplateKey = new PfReferenceKey(new PfConceptKey(), "IncomingTopologyTemplate"); - final ToscaTopologyTemplate topologyTemplate = new ToscaTopologyTemplate(topologyTemplateKey); + final JpaToscaTopologyTemplate topologyTemplate = new JpaToscaTopologyTemplate(topologyTemplateKey); if (topologyTemplateJsonObject.has(DESCRIPTION)) { topologyTemplate.setDescription(topologyTemplateJsonObject.get(DESCRIPTION).getAsString()); @@ -66,14 +66,14 @@ public class ToscaTopologyTemplateJsonAdapter if (topologyTemplateJsonObject.has(POLICIES)) { topologyTemplate.setPolicies(new ToscaPoliciesJsonAdapter() - .deserialize(topologyTemplateJsonObject.get(POLICIES), ToscaPolicies.class, context)); + .deserialize(topologyTemplateJsonObject.get(POLICIES), JpaToscaPolicies.class, context)); } return topologyTemplate; } @Override - public JsonElement serialize(@NonNull final ToscaTopologyTemplate topologyTemplate, @NonNull final Type type, + public JsonElement serialize(@NonNull final JpaToscaTopologyTemplate topologyTemplate, @NonNull final Type type, @NonNull final JsonSerializationContext context) { JsonObject topologyTemplateJsonObject = new JsonObject(); diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java index a02bfa4b7..93333c4e3 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java @@ -23,7 +23,7 @@ package org.onap.policy.models.tosca.utils; import javax.ws.rs.core.Response; import org.onap.policy.models.base.PfModelRuntimeException; -import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,7 +44,7 @@ public final class ToscaUtils { /** * Check if policy types have been specified is initialized. */ - public static void assertPolicyTypesExist(final ToscaServiceTemplate serviceTemplate) { + public static void assertPolicyTypesExist(final JpaToscaServiceTemplate serviceTemplate) { if (serviceTemplate.getPolicyTypes() == null) { String errorMessage = "no policy types specified on service template"; LOGGER.warn(errorMessage); @@ -61,7 +61,7 @@ public final class ToscaUtils { /** * Check if policy types have been specified is initialized. */ - public static void assertPoliciesExist(final ToscaServiceTemplate serviceTemplate) { + public static void assertPoliciesExist(final JpaToscaServiceTemplate serviceTemplate) { if (serviceTemplate.getTopologyTemplate() == null) { String errorMessage = "topology template not specified on service template"; LOGGER.warn(errorMessage); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/mapping/PlainToscaServiceTemplateMapperTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/mapping/PlainToscaServiceTemplateMapperTest.java index 74b88e790..6ec91238f 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/mapping/PlainToscaServiceTemplateMapperTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/mapping/PlainToscaServiceTemplateMapperTest.java @@ -30,8 +30,8 @@ import org.junit.Test; import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfValidationResult; -import org.onap.policy.models.tosca.authorative.concepts.PlainToscaServiceTemplate; -import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; import org.yaml.snakeyaml.Yaml; /** @@ -55,10 +55,10 @@ public class PlainToscaServiceTemplateMapperTest { try { String inputJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"); - PlainToscaServiceTemplate plainPolicies = standardCoder.decode(inputJson, PlainToscaServiceTemplate.class); - ToscaServiceTemplate internalPolicies = mapper.toToscaServiceTemplate(plainPolicies); + ToscaServiceTemplate plainPolicies = standardCoder.decode(inputJson, ToscaServiceTemplate.class); + JpaToscaServiceTemplate internalPolicies = mapper.toToscaServiceTemplate(plainPolicies); assertTrue(internalPolicies.validate(new PfValidationResult()).isValid()); - PlainToscaServiceTemplate plainPolicies2 = mapper.fromToscaServiceTemplate(internalPolicies); + ToscaServiceTemplate plainPolicies2 = mapper.fromToscaServiceTemplate(internalPolicies); assertTrue(plainPolicies.equals(plainPolicies2)); } catch (Exception e) { @@ -75,12 +75,12 @@ public class PlainToscaServiceTemplateMapperTest { Object yamlObject = yaml.load(inputYaml); String yamlAsJsonString = standardCoder.encode(yamlObject); - PlainToscaServiceTemplate plainPolicyTypes = standardCoder.decode(yamlAsJsonString, - PlainToscaServiceTemplate.class); - ToscaServiceTemplate internalPolicyTypes = mapper.toToscaServiceTemplate(plainPolicyTypes); + ToscaServiceTemplate plainPolicyTypes = standardCoder.decode(yamlAsJsonString, + ToscaServiceTemplate.class); + JpaToscaServiceTemplate internalPolicyTypes = mapper.toToscaServiceTemplate(plainPolicyTypes); assertTrue(internalPolicyTypes.validate(new PfValidationResult()).isValid()); - PlainToscaServiceTemplate plainPolicyTypes2 = mapper.fromToscaServiceTemplate(internalPolicyTypes); - ToscaServiceTemplate internalPolicyTypes2 = mapper.toToscaServiceTemplate(plainPolicyTypes2); + ToscaServiceTemplate plainPolicyTypes2 = mapper.fromToscaServiceTemplate(internalPolicyTypes); + JpaToscaServiceTemplate internalPolicyTypes2 = mapper.toToscaServiceTemplate(plainPolicyTypes2); assertTrue(internalPolicyTypes2.validate(new PfValidationResult()).isValid()); assertTrue(internalPolicyTypes.compareTo(internalPolicyTypes2) == 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 index c13583178..26242611b 100644 --- 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 @@ -31,7 +31,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils; 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.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,7 +58,7 @@ public class LegacyOperationalPolicySerializationTest { LegacyOperationalPolicy legacyOperationalPolicy = standardCoder.decode(vcpePolicyJson, LegacyOperationalPolicy.class); - ToscaServiceTemplate serviceTemplate = + JpaToscaServiceTemplate serviceTemplate = new LegacyOperationalPolicyMapper().toToscaServiceTemplate(legacyOperationalPolicy); assertNotNull(serviceTemplate); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKeyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKeyTest.java new file mode 100644 index 000000000..98d7dcfea --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalKeyTest.java @@ -0,0 +1,136 @@ +/*- + * ============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.JpaToscaConstraintLogicalKey; + +/** + * DAO test for ToscaConstraintLogicalKey. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class JpaToscaConstraintLogicalKeyTest { + + @Test + public void testConstraintLogicalKeyPojo() { + assertNotNull(new JpaToscaConstraintLogicalKey()); + assertNotNull(new JpaToscaConstraintLogicalKey(new PfReferenceKey())); + assertNotNull(new JpaToscaConstraintLogicalKey(new PfReferenceKey(), JpaToscaConstraintLogicalKey.Operation.EQ, + new PfConceptKey())); + + try { + new JpaToscaConstraintLogicalKey((PfReferenceKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaConstraintLogicalKey((JpaToscaConstraintLogicalKey) 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"); + JpaToscaConstraintLogicalKey tcl = + new JpaToscaConstraintLogicalKey(tclKey, JpaToscaConstraintLogicalKey.Operation.EQ, constraintKey); + + try { + new JpaToscaConstraintLogicalKey(tcl); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("cannot copy an immutable constraint", exc.getMessage()); + } + + JpaToscaConstraintLogicalKey tclClone1 = new JpaToscaConstraintLogicalKey(); + try { + tcl.copyTo(tclClone1); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("cannot copy an immutable constraint", exc.getMessage()); + } + tclClone1 = new JpaToscaConstraintLogicalKey(tclKey, JpaToscaConstraintLogicalKey.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); + + JpaToscaConstraintLogicalKey differentTcl = new JpaToscaConstraintLogicalKey(new PfReferenceKey(), + JpaToscaConstraintLogicalKey.Operation.EQ, constraintKey); + assertFalse(tcl.compareTo(differentTcl) == 0); + + JpaToscaConstraintLogicalKey otherTc = + new JpaToscaConstraintLogicalKey(tclKey, JpaToscaConstraintLogicalKey.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 JpaToscaConstraintLogicalKey().getKeys().size()); + + new JpaToscaConstraintLogicalKey().clean(); + tcl.clean(); + assertEquals(tclClone1, tcl); + + assertFalse(new JpaToscaConstraintLogicalKey().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 JpaToscaConstraintLogicalKey(tclKey, JpaToscaConstraintLogicalKey.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 JpaToscaConstraintLogicalKey(tclKey, JpaToscaConstraintLogicalKey.Operation.EQ, new PfConceptKey()) + .validate(new PfValidationResult()).isValid()); + } +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalStringTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalStringTest.java new file mode 100644 index 000000000..c27ec2660 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalStringTest.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.JpaToscaConstraintLogicalString; + +/** + * DAO test for ToscaConstraintLogicalString. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class JpaToscaConstraintLogicalStringTest { + + @Test + public void testConstraintLogicalStringPojo() { + assertNotNull(new JpaToscaConstraintLogicalString()); + assertNotNull(new JpaToscaConstraintLogicalString(new PfReferenceKey())); + assertNotNull(new JpaToscaConstraintLogicalString(new PfReferenceKey(), + JpaToscaConstraintLogicalString.Operation.EQ, "Constraint")); + + try { + new JpaToscaConstraintLogicalString((PfReferenceKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaConstraintLogicalString((JpaToscaConstraintLogicalString) 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"); + JpaToscaConstraintLogicalString tcl = + new JpaToscaConstraintLogicalString(tclKey, JpaToscaConstraintLogicalString.Operation.EQ, "Constraint"); + + try { + new JpaToscaConstraintLogicalString(tcl); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("cannot copy an immutable constraint", exc.getMessage()); + } + + JpaToscaConstraintLogicalString tclClone1 = new JpaToscaConstraintLogicalString(); + try { + tcl.copyTo(tclClone1); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("cannot copy an immutable constraint", exc.getMessage()); + } + tclClone1 = + new JpaToscaConstraintLogicalString(tclKey, JpaToscaConstraintLogicalString.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); + + JpaToscaConstraintLogicalString differentTcl = new JpaToscaConstraintLogicalString(new PfReferenceKey(), + JpaToscaConstraintLogicalString.Operation.EQ, "Constraint"); + assertFalse(tcl.compareTo(differentTcl) == 0); + + JpaToscaConstraintLogicalString otherTc = + new JpaToscaConstraintLogicalString(tclKey, JpaToscaConstraintLogicalString.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 JpaToscaConstraintLogicalString().getKeys().size()); + + new JpaToscaConstraintLogicalString().clean(); + tcl.clean(); + assertEquals(tclClone1, tcl); + + assertFalse(new JpaToscaConstraintLogicalString().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 JpaToscaConstraintLogicalString(tclKey, JpaToscaConstraintLogicalString.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 JpaToscaConstraintLogicalString(tclKey, JpaToscaConstraintLogicalString.Operation.EQ, "") + .validate(new PfValidationResult()).isValid()); + } +} diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java new file mode 100644 index 000000000..2da46a71e --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java @@ -0,0 +1,168 @@ +/*- + * ============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.JpaToscaConstraintLogical; +import org.onap.policy.models.tosca.simple.concepts.testconcepts.DummyToscaConstraint; + +/** + * DAO test for ToscaConstraintLogical. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class JpaToscaConstraintLogicalTest { + + @Test + public void testConstraintLogicalPojo() { + assertNotNull(new JpaToscaConstraintLogical()); + assertNotNull(new JpaToscaConstraintLogical(new PfReferenceKey())); + + try { + new JpaToscaConstraintLogical((PfReferenceKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaConstraintLogical((JpaToscaConstraintLogical) 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"); + JpaToscaConstraintLogical tcl = new JpaToscaConstraintLogical(tclKey, JpaToscaConstraintLogical.Operation.EQ); + + try { + new JpaToscaConstraintLogical(tcl); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("cannot copy an immutable constraint", exc.getMessage()); + } + + JpaToscaConstraintLogical tclClone1 = new JpaToscaConstraintLogical(); + try { + tcl.copyTo(tclClone1); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("cannot copy an immutable constraint", exc.getMessage()); + } + tclClone1 = new JpaToscaConstraintLogical(tclKey, JpaToscaConstraintLogical.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); + + JpaToscaConstraintLogical differentTcl = + new JpaToscaConstraintLogical(new PfReferenceKey(), JpaToscaConstraintLogical.Operation.EQ); + assertFalse(tcl.compareTo(differentTcl) == 0); + + JpaToscaConstraintLogical otherTc = + new JpaToscaConstraintLogical(tclKey, JpaToscaConstraintLogical.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 JpaToscaConstraintLogical().getKeys().size()); + + JpaToscaConstraintLogical tclClone0 = new JpaToscaConstraintLogical(); + new JpaToscaConstraintLogical().clean(); + tcl.clean(); + assertEquals(tclClone0, tcl); + + assertFalse(new JpaToscaConstraintLogical().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/JpaToscaDataTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java new file mode 100644 index 000000000..bf710e881 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.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.JpaToscaConstraint; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical.Operation; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty; + +/** + * DAO test for ToscaDatatype. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class JpaToscaDataTypeTest { + + @Test + public void testDataTypePojo() { + assertNotNull(new JpaToscaDataType()); + assertNotNull(new JpaToscaDataType(new PfConceptKey())); + assertNotNull(new JpaToscaDataType(new JpaToscaDataType())); + + try { + new JpaToscaDataType((PfConceptKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaDataType((JpaToscaDataType) 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"); + JpaToscaDataType tdt = new JpaToscaDataType(dtKey); + + List constraints = new ArrayList<>(); + JpaToscaConstraintLogicalString lsc = + new JpaToscaConstraintLogicalString(new PfReferenceKey(dtKey, "sc"), Operation.EQ, "hello"); + constraints.add(lsc); + tdt.setConstraints(constraints); + assertEquals(constraints, tdt.getConstraints()); + + List properties = new ArrayList<>(); + JpaToscaProperty tp = new JpaToscaProperty(new PfReferenceKey(dtKey, "pr"), new PfConceptKey("type", "0.0.1")); + properties.add(tp); + tdt.setProperties(properties); + assertEquals(properties, tdt.getProperties()); + + JpaToscaDataType tdtClone0 = new JpaToscaDataType(tdt); + assertEquals(tdt, tdtClone0); + assertEquals(0, tdt.compareTo(tdtClone0)); + + JpaToscaDataType tdtClone1 = new JpaToscaDataType(); + 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"); + JpaToscaDataType otherDt = new JpaToscaDataType(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 JpaToscaDataType().getKeys().size()); + + new JpaToscaDataType().clean(); + tdt.clean(); + assertEquals(tdtClone0, tdt); + + assertFalse(new JpaToscaDataType().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/JpaToscaDataTypesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java new file mode 100644 index 000000000..ce90e372c --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.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.JpaToscaDataType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes; + +public class JpaToscaDataTypesTest { + + @Test + public void testDataTypes() { + assertNotNull(new JpaToscaDataTypes()); + assertNotNull(new JpaToscaDataTypes(new PfConceptKey())); + assertNotNull(new JpaToscaDataTypes(new PfConceptKey(), new TreeMap())); + assertNotNull(new JpaToscaDataTypes(new JpaToscaDataTypes())); + + try { + new JpaToscaDataTypes((PfConceptKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaDataTypes((JpaToscaDataTypes) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaDataTypes(null, null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaDataTypes(new PfConceptKey(), null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("conceptMap is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaDataTypes(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/JpaToscaEntrySchemaTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchemaTest.java new file mode 100644 index 000000000..a69b9a777 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchemaTest.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.JpaToscaConstraint; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical.Operation; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema; + +/** + * DAO test for ToscaEntrySchema. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class JpaToscaEntrySchemaTest { + + @Test + public void testEntrySchemaPojo() { + assertNotNull(new JpaToscaEntrySchema()); + assertNotNull(new JpaToscaEntrySchema(new PfReferenceKey())); + assertNotNull(new JpaToscaEntrySchema(new PfReferenceKey(), new PfConceptKey())); + assertNotNull(new JpaToscaEntrySchema(new JpaToscaEntrySchema())); + + try { + new JpaToscaEntrySchema((PfReferenceKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaEntrySchema((JpaToscaEntrySchema) 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"); + JpaToscaEntrySchema tes = new JpaToscaEntrySchema(esKey, typeKey); + + tes.setDescription("A Description"); + assertEquals("A Description", tes.getDescription()); + + List constraints = new ArrayList<>(); + JpaToscaConstraintLogicalString lsc = + new JpaToscaConstraintLogicalString(new PfReferenceKey(esKey, "sc"), Operation.EQ, "hello"); + constraints.add(lsc); + tes.setConstraints(constraints); + assertEquals(constraints, tes.getConstraints()); + + JpaToscaEntrySchema tdtClone0 = new JpaToscaEntrySchema(tes); + assertEquals(tes, tdtClone0); + assertEquals(0, tes.compareTo(tdtClone0)); + + JpaToscaEntrySchema tdtClone1 = new JpaToscaEntrySchema(); + 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"); + JpaToscaEntrySchema otherEs = new JpaToscaEntrySchema(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 JpaToscaEntrySchema().getKeys().size()); + + new JpaToscaEntrySchema().clean(); + tes.clean(); + assertEquals(tdtClone0, tes); + + assertFalse(new JpaToscaEntrySchema().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/JpaToscaEventFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java new file mode 100644 index 000000000..19846a0cc --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.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.JpaToscaEventFilter; + +/** + * DAO test for ToscaEventFilter. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class JpaToscaEventFilterTest { + + @Test + public void testEventFilterPojo() { + assertNotNull(new JpaToscaEventFilter()); + assertNotNull(new JpaToscaEventFilter(new PfReferenceKey())); + assertNotNull(new JpaToscaEventFilter(new PfReferenceKey(), new PfConceptKey())); + assertNotNull(new JpaToscaEventFilter(new JpaToscaEventFilter())); + + try { + new JpaToscaEventFilter((PfReferenceKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaEventFilter(null, null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaEventFilter(null, new PfConceptKey()); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaEventFilter(new PfReferenceKey(), null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("node is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaEventFilter((JpaToscaEventFilter) 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"); + JpaToscaEventFilter tef = new JpaToscaEventFilter(efKey, nodeKey); + + tef.setRequirement("A Requrement"); + assertEquals("A Requrement", tef.getRequirement()); + + tef.setCapability("A Capability"); + assertEquals("A Capability", tef.getCapability()); + + JpaToscaEventFilter tdtClone0 = new JpaToscaEventFilter(tef); + assertEquals(tef, tdtClone0); + assertEquals(0, tef.compareTo(tdtClone0)); + + JpaToscaEventFilter tdtClone1 = new JpaToscaEventFilter(); + 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"); + JpaToscaEventFilter otherDt = new JpaToscaEventFilter(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 JpaToscaEventFilter().getKeys().size()); + + new JpaToscaEventFilter().clean(); + tef.clean(); + assertEquals(tdtClone0, tef); + + assertFalse(new JpaToscaEventFilter().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/JpaToscaModelTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java new file mode 100644 index 000000000..a62c79956 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.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.JpaToscaModel; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplates; + +/** + * DAO test for ToscaDatatype. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class JpaToscaModelTest { + + @Test + public void testModelPojo() { + assertNotNull(new JpaToscaModel()); + assertNotNull(new JpaToscaModel(new PfConceptKey())); + assertNotNull(new JpaToscaModel(new PfConceptKey(), new JpaToscaServiceTemplates())); + assertNotNull(new JpaToscaModel(new JpaToscaModel())); + + try { + new JpaToscaModel((PfConceptKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaModel(null, null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaModel(null, new JpaToscaServiceTemplates()); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaModel(new PfConceptKey(), null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("serviceTemplates is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaModel((JpaToscaModel) 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<>(); + JpaToscaServiceTemplates tsts = new JpaToscaServiceTemplates(tstsKey, tstMap); + PfConceptKey tmKey = new PfConceptKey("tst", "0.0.1"); + JpaToscaModel tm = new JpaToscaModel(tmKey, tsts); + + JpaToscaModel tttClone0 = new JpaToscaModel(tm); + assertEquals(tm, tttClone0); + assertEquals(0, tm.compareTo(tttClone0)); + + JpaToscaModel tttClone1 = new JpaToscaModel(); + 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"); + JpaToscaModel otherDt = new JpaToscaModel(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 JpaToscaModel().getKeys().size()); + + new JpaToscaModel().clean(); + tm.clean(); + assertEquals(tttClone0, tm); + + assertFalse(new JpaToscaModel().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/JpaToscaPoliciesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java new file mode 100644 index 000000000..6f6141c5b --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.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.JpaToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; + +public class JpaToscaPoliciesTest { + + @Test + public void testPolicies() { + assertNotNull(new JpaToscaPolicies()); + assertNotNull(new JpaToscaPolicies(new PfConceptKey())); + assertNotNull(new JpaToscaPolicies(new PfConceptKey(), new TreeMap())); + assertNotNull(new JpaToscaPolicies(new JpaToscaPolicies())); + + try { + new JpaToscaPolicies((PfConceptKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaPolicies((JpaToscaPolicies) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaPolicies(null, null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaPolicies(new PfConceptKey(), null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("conceptMap is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaPolicies(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/JpaToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java new file mode 100644 index 000000000..ec8e6da8f --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.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.JpaToscaPolicy; + +/** + * DAO test for ToscaPolicy. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class JpaToscaPolicyTest { + + @Test + public void testPolicyPojo() { + assertNotNull(new JpaToscaPolicy()); + assertNotNull(new JpaToscaPolicy(new PfConceptKey())); + assertNotNull(new JpaToscaPolicy(new PfConceptKey(), new PfConceptKey())); + assertNotNull(new JpaToscaPolicy(new JpaToscaPolicy())); + + try { + new JpaToscaPolicy((PfConceptKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaPolicy(null, null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaPolicy(new PfConceptKey(), null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("type is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaPolicy(null, new PfConceptKey()); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaPolicy((JpaToscaPolicy) 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"); + JpaToscaPolicy tp = new JpaToscaPolicy(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()); + + JpaToscaPolicy tdtClone0 = new JpaToscaPolicy(tp); + assertEquals(tp, tdtClone0); + assertEquals(0, tp.compareTo(tdtClone0)); + + JpaToscaPolicy tdtClone1 = new JpaToscaPolicy(); + 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"); + JpaToscaPolicy otherDt = new JpaToscaPolicy(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 JpaToscaPolicy().getKeys().size()); + + new JpaToscaPolicy().clean(); + tp.clean(); + assertEquals(tdtClone0, tp); + + assertFalse(new JpaToscaPolicy().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()); + } + } +} \ No newline at end of file diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java new file mode 100644 index 000000000..7dac2684f --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.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.JpaToscaEntityType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger; + +/** + * DAO test for ToscaPolicyType. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class JpaToscaPolicyTypeTest { + + @Test + public void testPolicyTypePojo() { + assertNotNull(new JpaToscaPolicyType()); + assertNotNull(new JpaToscaPolicyType(new PfConceptKey())); + assertNotNull(new JpaToscaPolicyType(new JpaToscaPolicyType())); + + try { + new JpaToscaPolicyType((PfConceptKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaPolicyType((JpaToscaPolicyType) 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"); + JpaToscaPolicyType tpt = new JpaToscaPolicyType(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<>(); + JpaToscaProperty tp = new JpaToscaProperty(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<>(); + JpaToscaTrigger trigger = new JpaToscaTrigger(new PfReferenceKey(ptKey, "aTrigger"), "EventType", "Action"); + triggers.add(trigger); + tpt.setTriggers(triggers); + assertEquals(triggers, tpt.getTriggers()); + + JpaToscaPolicyType tdtClone0 = new JpaToscaPolicyType(tpt); + assertEquals(tpt, tdtClone0); + assertEquals(0, tpt.compareTo(tdtClone0)); + + JpaToscaPolicyType tdtClone1 = new JpaToscaPolicyType(); + 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"); + JpaToscaPolicyType otherDt = new JpaToscaPolicyType(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 JpaToscaPolicyType().getKeys().size()); + + new JpaToscaPolicyType().clean(); + tpt.clean(); + assertEquals(tdtClone0, tpt); + + assertFalse(new JpaToscaPolicyType().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 JpaToscaEntityType((PfConceptKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaEntityType((JpaToscaEntityType) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage()); + } + + JpaToscaEntityType tet = new JpaToscaEntityType(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/JpaToscaPolicyTypesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java new file mode 100644 index 000000000..d0ea1782f --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.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.JpaToscaPolicyType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes; + +public class JpaToscaPolicyTypesTest { + + @Test + public void testPolicyTypes() { + assertNotNull(new JpaToscaPolicyTypes()); + assertNotNull(new JpaToscaPolicyTypes(new PfConceptKey())); + assertNotNull(new JpaToscaPolicyTypes(new PfConceptKey(), new TreeMap())); + assertNotNull(new JpaToscaPolicyTypes(new JpaToscaPolicyTypes())); + + try { + new JpaToscaPolicyTypes((PfConceptKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaPolicyTypes((JpaToscaPolicyTypes) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaPolicyTypes(null, null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaPolicyTypes(new PfConceptKey(), null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("conceptMap is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaPolicyTypes(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/JpaToscaPropertyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java new file mode 100644 index 000000000..8d46c9533 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java @@ -0,0 +1,221 @@ +/*- + * ============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.JpaToscaConstraint; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical.Operation; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty; + +/** + * DAO test for ToscaProperty. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class JpaToscaPropertyTest { + + @Test + public void testPropertyPojo() { + assertNotNull(new JpaToscaProperty()); + assertNotNull(new JpaToscaProperty(new PfReferenceKey())); + assertNotNull(new JpaToscaProperty(new PfReferenceKey(), new PfConceptKey())); + assertNotNull(new JpaToscaProperty(new JpaToscaProperty())); + + try { + new JpaToscaProperty((PfReferenceKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaProperty(null, null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaProperty(null, new PfConceptKey()); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaProperty(new PfReferenceKey(), null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("type is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaProperty((JpaToscaProperty) 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"); + JpaToscaProperty tp = new JpaToscaProperty(pkey, ptypeKey); + + tp.setDescription("A Description"); + assertEquals("A Description", tp.getDescription()); + + tp.setRequired(false); + assertFalse(tp.isRequired()); + + tp.setDefaultValue("defaultKey"); + + tp.setStatus(JpaToscaProperty.Status.SUPPORTED); + + List constraints = new ArrayList<>(); + JpaToscaConstraintLogicalString lsc = + new JpaToscaConstraintLogicalString(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"); + JpaToscaEntrySchema tes = new JpaToscaEntrySchema(esKey, typeKey); + tp.setEntrySchema(tes); + + JpaToscaProperty tdtClone0 = new JpaToscaProperty(tp); + assertEquals(tp, tdtClone0); + assertEquals(0, tp.compareTo(tdtClone0)); + + JpaToscaProperty tdtClone1 = new JpaToscaProperty(); + 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"); + JpaToscaProperty otherDt = new JpaToscaProperty(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("defaultKey"); + assertFalse(tp.compareTo(otherDt) == 0); + otherDt.setStatus(JpaToscaProperty.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(JpaToscaProperty.Status.UNSUPPORTED); + assertFalse(tp.compareTo(otherDt) == 0); + otherDt.setStatus(JpaToscaProperty.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(5, tp.getKeys().size()); + assertEquals(2, new JpaToscaProperty().getKeys().size()); + + new JpaToscaProperty().clean(); + tp.clean(); + assertEquals(tdtClone0, tp); + + assertFalse(new JpaToscaProperty().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("defaultKey"); + 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/JpaToscaServiceTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java new file mode 100644 index 000000000..4569d42ff --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.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.JpaToscaDataType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; + +/** + * DAO test for ToscaDatatype. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class JpaToscaServiceTemplateTest { + + @Test + public void testServiceTemplatePojo() { + assertNotNull(new JpaToscaServiceTemplate()); + assertNotNull(new JpaToscaServiceTemplate(new PfConceptKey())); + assertNotNull(new JpaToscaServiceTemplate(new PfConceptKey(), "")); + assertNotNull(new JpaToscaServiceTemplate(new JpaToscaServiceTemplate())); + + try { + new JpaToscaServiceTemplate((PfConceptKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaServiceTemplate(null, null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaServiceTemplate(null, ""); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaServiceTemplate(new PfConceptKey(), null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("toscaDefinitionsVersion is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaServiceTemplate((JpaToscaServiceTemplate) 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"); + JpaToscaServiceTemplate tst = new JpaToscaServiceTemplate(tstKey, "Tosca Version"); + + PfConceptKey dataTypeKey = new PfConceptKey("DataType", "0.0.1"); + JpaToscaDataType dataType0 = new JpaToscaDataType(dataTypeKey); + PfConceptKey dtsKey = new PfConceptKey("dts", "0.0.1"); + Map dataTypeMap = new TreeMap<>(); + dataTypeMap.put(dataTypeKey, dataType0); + JpaToscaDataTypes dataTypes = new JpaToscaDataTypes(dtsKey, dataTypeMap); + tst.setDataTypes(dataTypes); + assertEquals(dataTypes, tst.getDataTypes()); + + PfConceptKey policyTypeKey = new PfConceptKey("DataType", "0.0.1"); + JpaToscaPolicyType policyType0 = new JpaToscaPolicyType(policyTypeKey); + PfConceptKey ptsKey = new PfConceptKey("dts", "0.0.1"); + Map policyTypeMap = new TreeMap<>(); + policyTypeMap.put(policyTypeKey, policyType0); + JpaToscaPolicyTypes policyTypes = new JpaToscaPolicyTypes(ptsKey, policyTypeMap); + tst.setPolicyTypes(policyTypes); + assertEquals(policyTypes, tst.getPolicyTypes()); + + PfReferenceKey tttKey = new PfReferenceKey(tstKey, "TopologyTemplate"); + JpaToscaTopologyTemplate ttt = new JpaToscaTopologyTemplate(tttKey); + tst.setTopologyTemplate(ttt); + assertEquals(ttt, tst.getTopologyTemplate()); + + JpaToscaServiceTemplate tttClone0 = new JpaToscaServiceTemplate(tst); + assertEquals(tst, tttClone0); + assertEquals(0, tst.compareTo(tttClone0)); + + JpaToscaServiceTemplate tttClone1 = new JpaToscaServiceTemplate(); + 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"); + JpaToscaServiceTemplate otherDt = new JpaToscaServiceTemplate(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 JpaToscaServiceTemplate().getKeys().size()); + + new JpaToscaServiceTemplate().clean(); + tst.clean(); + assertEquals(tttClone0, tst); + + assertFalse(new JpaToscaServiceTemplate().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/JpaToscaServiceTemplatesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplatesTest.java new file mode 100644 index 000000000..91d6d0bd3 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplatesTest.java @@ -0,0 +1,79 @@ +/*- + * ============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.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplates; + +public class JpaToscaServiceTemplatesTest { + + @Test + public void testServiceTemplates() { + assertNotNull(new JpaToscaServiceTemplates()); + assertNotNull(new JpaToscaServiceTemplates(new PfConceptKey())); + assertNotNull( + new JpaToscaServiceTemplates(new PfConceptKey(), new TreeMap())); + assertNotNull(new JpaToscaServiceTemplates(new JpaToscaServiceTemplates())); + + try { + new JpaToscaServiceTemplates((PfConceptKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaServiceTemplates((JpaToscaServiceTemplates) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaServiceTemplates(null, null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaServiceTemplates(new PfConceptKey(), null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("conceptMap is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaServiceTemplates(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/JpaToscaTimeIntervalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java new file mode 100644 index 000000000..707e66dfd --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.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.JpaToscaTimeInterval; + +/** + * DAO test for ToscaTimeInterval. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class JpaToscaTimeIntervalTest { + + @Test + public void testTimeIntervalPojo() { + assertNotNull(new JpaToscaTimeInterval()); + assertNotNull(new JpaToscaTimeInterval(new PfReferenceKey())); + assertNotNull(new JpaToscaTimeInterval(new PfReferenceKey(), new Date(), new Date())); + assertNotNull(new JpaToscaTimeInterval(new JpaToscaTimeInterval())); + + try { + new JpaToscaTimeInterval((PfReferenceKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaTimeInterval(null, null, null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaTimeInterval(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 JpaToscaTimeInterval(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 JpaToscaTimeInterval(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 JpaToscaTimeInterval(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 JpaToscaTimeInterval(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 JpaToscaTimeInterval(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 JpaToscaTimeInterval((JpaToscaTimeInterval) 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); + JpaToscaTimeInterval tti = new JpaToscaTimeInterval(ttiKey, startTime, endTime); + + JpaToscaTimeInterval tdtClone0 = new JpaToscaTimeInterval(tti); + assertEquals(tti, tdtClone0); + assertEquals(0, tti.compareTo(tdtClone0)); + + JpaToscaTimeInterval tdtClone1 = new JpaToscaTimeInterval(); + 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"); + JpaToscaTimeInterval otherDt = new JpaToscaTimeInterval(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 JpaToscaTimeInterval().getKeys().size()); + + new JpaToscaTimeInterval().clean(); + tti.clean(); + assertEquals(tdtClone0, tti); + + assertFalse(new JpaToscaTimeInterval().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/JpaToscaTopologyTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java new file mode 100644 index 000000000..417f202f5 --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.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.JpaToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; + +/** + * DAO test for ToscaDatatype. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class JpaToscaTopologyTemplateTest { + + @Test + public void testTopologyTemplatePojo() { + assertNotNull(new JpaToscaTopologyTemplate()); + assertNotNull(new JpaToscaTopologyTemplate(new PfReferenceKey())); + assertNotNull(new JpaToscaTopologyTemplate(new JpaToscaTopologyTemplate())); + + try { + new JpaToscaTopologyTemplate((PfReferenceKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaTopologyTemplate((JpaToscaTopologyTemplate) 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"); + JpaToscaTopologyTemplate ttt = new JpaToscaTopologyTemplate(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"); + + JpaToscaPolicy policy0 = new JpaToscaPolicy(policy0Key, policy0TypeKey); + PfConceptKey polsKey = new PfConceptKey("pols", "0.0.1"); + Map policyMap = new TreeMap<>(); + policyMap.put(policy0Key, policy0); + JpaToscaPolicies policies = new JpaToscaPolicies(polsKey, policyMap); + ttt.setPolicies(policies); + + JpaToscaTopologyTemplate tttClone0 = new JpaToscaTopologyTemplate(ttt); + assertEquals(ttt, tttClone0); + assertEquals(0, ttt.compareTo(tttClone0)); + + JpaToscaTopologyTemplate tttClone1 = new JpaToscaTopologyTemplate(); + 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"); + JpaToscaTopologyTemplate otherDt = new JpaToscaTopologyTemplate(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 JpaToscaTopologyTemplate().getKeys().size()); + + new JpaToscaTopologyTemplate().clean(); + ttt.clean(); + assertEquals(tttClone0, ttt); + + assertTrue(new JpaToscaTopologyTemplate().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/JpaToscaTriggerTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java new file mode 100644 index 000000000..661882a3f --- /dev/null +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java @@ -0,0 +1,233 @@ +/*- + * ============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.JpaToscaConstraintLogical.Operation; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaEventFilter; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTimeInterval; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger; + +/** + * DAO test for ToscaTrigger. + * + * @author Liam Fallon (liam.fallon@est.tech) + */ +public class JpaToscaTriggerTest { + + @Test + public void testTriggerPojo() { + assertNotNull(new JpaToscaTrigger()); + assertNotNull(new JpaToscaTrigger(new PfReferenceKey())); + assertNotNull(new JpaToscaTrigger(new PfReferenceKey(), "EventType", "Action")); + assertNotNull(new JpaToscaTrigger(new JpaToscaTrigger())); + + try { + new JpaToscaTrigger((PfReferenceKey) null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaTrigger(null, null, null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaTrigger(null, "EventType", null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaTrigger(null, "EventType", "Action"); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaTrigger(null, null, "Action"); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("key is marked @NonNull but is null", exc.getMessage()); + } + + try { + new JpaToscaTrigger(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 JpaToscaTrigger(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 JpaToscaTrigger(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 JpaToscaTrigger((JpaToscaTrigger) 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"); + JpaToscaTrigger tdt = new JpaToscaTrigger(tkey, "EventType", "Action"); + + JpaToscaTimeInterval schedule = + new JpaToscaTimeInterval(new PfReferenceKey(tkey, "sched"), new Date(), new Date()); + tdt.setSchedule(schedule); + + JpaToscaEventFilter targetFilter = + new JpaToscaEventFilter(new PfReferenceKey(tkey, "filter"), new PfConceptKey("NodeName", "0.0.1")); + tdt.setTargetFilter(targetFilter); + + JpaToscaConstraintLogicalString lsc = + new JpaToscaConstraintLogicalString(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()); + + JpaToscaTrigger tdtClone0 = new JpaToscaTrigger(tdt); + assertEquals(tdt, tdtClone0); + assertEquals(0, tdt.compareTo(tdtClone0)); + + JpaToscaTrigger tdtClone1 = new JpaToscaTrigger(); + 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"); + JpaToscaTrigger otherDt = new JpaToscaTrigger(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 JpaToscaTrigger().getKeys().size()); + + new JpaToscaTrigger().clean(); + tdt.clean(); + assertEquals(tdtClone0, tdt); + + assertFalse(new JpaToscaTrigger().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/ToscaConstraintLogicalKeyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalKeyTest.java deleted file mode 100644 index 35a1c0a99..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalKeyTest.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.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 deleted file mode 100644 index 764a6f46b..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalStringTest.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.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 deleted file mode 100644 index d1617204a..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaConstraintLogicalTest.java +++ /dev/null @@ -1,167 +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.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 deleted file mode 100644 index 5adeece5b..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypeTest.java +++ /dev/null @@ -1,144 +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.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 deleted file mode 100644 index b92b6b08a..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaDataTypesTest.java +++ /dev/null @@ -1,78 +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.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 deleted file mode 100644 index e1a9f0c6f..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaEntrySchemaTest.java +++ /dev/null @@ -1,150 +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.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 deleted file mode 100644 index b1fb33fce..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaEventFilterTest.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.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 deleted file mode 100644 index af8cc2d3b..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaModelTest.java +++ /dev/null @@ -1,145 +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.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 deleted file mode 100644 index 127aac4f4..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPoliciesTest.java +++ /dev/null @@ -1,78 +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.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 deleted file mode 100644 index 01c1377b9..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTest.java +++ /dev/null @@ -1,174 +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.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 ToscaPolicy. - * - * @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()); - } - } -} \ No newline at end of file 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 deleted file mode 100644 index 3be0cff3d..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypeTest.java +++ /dev/null @@ -1,212 +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.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 deleted file mode 100644 index a85c8285e..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPolicyTypesTest.java +++ /dev/null @@ -1,78 +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.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 deleted file mode 100644 index 0fcf96a89..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaPropertyTest.java +++ /dev/null @@ -1,221 +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.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()); - - tp.setDefaultValue("defaultKey"); - - 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("defaultKey"); - 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(5, 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("defaultKey"); - 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 deleted file mode 100644 index aad410e89..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplateTest.java +++ /dev/null @@ -1,177 +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.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 deleted file mode 100644 index 2864be829..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaServiceTemplatesTest.java +++ /dev/null @@ -1,78 +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.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 deleted file mode 100644 index cbfde2d11..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaTimeIntervalTest.java +++ /dev/null @@ -1,182 +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.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 deleted file mode 100644 index d35c3d661..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaTopologyTemplateTest.java +++ /dev/null @@ -1,138 +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.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); - - assertTrue(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 deleted file mode 100644 index be60165ff..000000000 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/ToscaTriggerTest.java +++ /dev/null @@ -1,232 +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.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 index 2e03fd215..a743e2834 100644 --- 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 @@ -24,14 +24,14 @@ 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; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint; /** * Dummy constraint to test abstract ToscaConstraint class. * * @author Liam Fallon (liam.fallon@est.tech) */ -public class DummyToscaConstraint extends ToscaConstraint { +public class DummyToscaConstraint extends JpaToscaConstraint { private static final long serialVersionUID = 1L; /** diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java index ed25a7a25..029c7a7e1 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java @@ -39,9 +39,9 @@ import org.onap.policy.models.dao.DaoParameters; import org.onap.policy.models.dao.PfDao; import org.onap.policy.models.dao.PfDaoFactory; import org.onap.policy.models.dao.impl.DefaultPfDao; -import org.onap.policy.models.tosca.simple.concepts.ToscaPolicies; -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.concepts.JpaToscaPolicies; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate; import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler; /** @@ -114,19 +114,19 @@ public class SimpleToscaProviderTest { assertEquals("policyKey is marked @NonNull but is null", exc.getMessage()); } - ToscaServiceTemplate originalServiceTemplate = + JpaToscaServiceTemplate originalServiceTemplate = gson.fromJson(ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), - ToscaServiceTemplate.class); + JpaToscaServiceTemplate.class); assertNotNull(originalServiceTemplate); - ToscaServiceTemplate createdServiceTemplate = + JpaToscaServiceTemplate createdServiceTemplate = new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate, createdServiceTemplate); PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0"); - ToscaServiceTemplate gotServiceTemplate = + JpaToscaServiceTemplate gotServiceTemplate = new SimpleToscaProvider().getPolicies(pfDao, new PfConceptKey(policyKey)); assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey), @@ -144,7 +144,7 @@ public class SimpleToscaProviderTest { } try { - new SimpleToscaProvider().createPolicies(null, new ToscaServiceTemplate()); + new SimpleToscaProvider().createPolicies(null, new JpaToscaServiceTemplate()); fail("test should throw an exception here"); } catch (Exception exc) { assertEquals("dao is marked @NonNull but is null", exc.getMessage()); @@ -157,12 +157,12 @@ public class SimpleToscaProviderTest { assertEquals("serviceTemplate is marked @NonNull but is null", exc.getMessage()); } - ToscaServiceTemplate originalServiceTemplate = + JpaToscaServiceTemplate originalServiceTemplate = gson.fromJson(ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), - ToscaServiceTemplate.class); + JpaToscaServiceTemplate.class); assertNotNull(originalServiceTemplate); - ToscaServiceTemplate createdServiceTemplate = + JpaToscaServiceTemplate createdServiceTemplate = new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate, createdServiceTemplate); @@ -178,7 +178,7 @@ public class SimpleToscaProviderTest { } try { - new SimpleToscaProvider().updatePolicies(null, new ToscaServiceTemplate()); + new SimpleToscaProvider().updatePolicies(null, new JpaToscaServiceTemplate()); fail("test should throw an exception here"); } catch (Exception exc) { assertEquals("dao is marked @NonNull but is null", exc.getMessage()); @@ -191,12 +191,12 @@ public class SimpleToscaProviderTest { assertEquals("serviceTemplate is marked @NonNull but is null", exc.getMessage()); } - ToscaServiceTemplate originalServiceTemplate = + JpaToscaServiceTemplate originalServiceTemplate = gson.fromJson(ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), - ToscaServiceTemplate.class); + JpaToscaServiceTemplate.class); assertNotNull(originalServiceTemplate); - ToscaServiceTemplate updatedServiceTemplate = + JpaToscaServiceTemplate updatedServiceTemplate = new SimpleToscaProvider().updatePolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate, updatedServiceTemplate); @@ -225,19 +225,19 @@ public class SimpleToscaProviderTest { assertEquals("policyKey is marked @NonNull but is null", exc.getMessage()); } - ToscaServiceTemplate originalServiceTemplate = + JpaToscaServiceTemplate originalServiceTemplate = gson.fromJson(ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"), - ToscaServiceTemplate.class); + JpaToscaServiceTemplate.class); assertNotNull(originalServiceTemplate); - ToscaServiceTemplate createdServiceTemplate = + JpaToscaServiceTemplate createdServiceTemplate = new SimpleToscaProvider().createPolicies(pfDao, originalServiceTemplate); assertEquals(originalServiceTemplate, createdServiceTemplate); PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0"); - ToscaServiceTemplate deletedServiceTemplate = + JpaToscaServiceTemplate deletedServiceTemplate = new SimpleToscaProvider().deletePolicies(pfDao, new PfConceptKey(policyKey)); assertEquals(originalServiceTemplate.getTopologyTemplate().getPolicies().get(policyKey), @@ -253,7 +253,7 @@ public class SimpleToscaProviderTest { @Test public void testAssertPoliciesExist() throws PfModelException { - ToscaServiceTemplate testServiceTemplate = new ToscaServiceTemplate(); + JpaToscaServiceTemplate testServiceTemplate = new JpaToscaServiceTemplate(); try { new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate); @@ -262,7 +262,7 @@ public class SimpleToscaProviderTest { assertEquals("topology template not specified on service template", exc.getMessage()); } - testServiceTemplate.setTopologyTemplate(new ToscaTopologyTemplate()); + testServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate()); try { new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate); fail("test should throw an exception here"); @@ -270,7 +270,7 @@ public class SimpleToscaProviderTest { assertEquals("no policies specified on topology template of service template", exc.getMessage()); } - testServiceTemplate.getTopologyTemplate().setPolicies(new ToscaPolicies()); + testServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies()); try { new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate); fail("test should throw an exception here"); 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 index 833e06a82..1f17a43bf 100644 --- 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 @@ -40,8 +40,8 @@ import org.onap.policy.common.utils.coder.StandardCoder; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfValidationResult; -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.JpaToscaPolicy; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -57,12 +57,12 @@ public class MonitoringPolicySerializationTest { private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringPolicySerializationTest.class); - private static final String VCPE_MONITORING_INPUT_JSON = "policies/vCPE.policy.monitoring.input.tosca.json"; - private static final String VCPE_MONITORING_INPUT_YAML = "policies/vCPE.policy.monitoring.input.tosca.yaml"; - private static final String VDNS_MONITORING_INPUT_JSON = "policies/vDNS.policy.monitoring.input.tosca.json"; - private static final String VDNS_MONITORING_INPUT_YAML = "policies/vDNS.policy.monitoring.input.tosca.yaml"; - private static final String VFW_MONITORING_INPUT_JSON = "policies/vFirewall.policy.monitoring.input.tosca.json"; - private static final String VFW_MONITORING_INPUT_YAML = "policies/vFirewall.policy.monitoring.input.tosca.yaml"; + private static final String VCPE_MON_INPUT_JSON = "policies/vCPE.policy.monitoring.input.tosca.json"; + private static final String VCPE_MON_INPUT_YAML = "policies/vCPE.policy.monitoring.input.tosca.yaml"; + private static final String VDNS_MON_INPUT_JSON = "policies/vDNS.policy.monitoring.input.tosca.json"; + private static final String VDNS_MON_INPUT_YAML = "policies/vDNS.policy.monitoring.input.tosca.yaml"; + private static final String VFW_MON_INPUT_JSON = "policies/vFirewall.policy.monitoring.input.tosca.json"; + private static final String VFW_MON_INPUT_YAML = "policies/vFirewall.policy.monitoring.input.tosca.yaml"; private Gson gson; @@ -75,21 +75,21 @@ public class MonitoringPolicySerializationTest { public void testDeserialization() { try { // vCPE - ToscaServiceTemplate serviceTemplateFromJson = deserializeMonitoringInputJson(VCPE_MONITORING_INPUT_JSON); + JpaToscaServiceTemplate serviceTemplateFromJson = deserializeMonitoringInputJson(VCPE_MON_INPUT_JSON); verifyVcpeMonitoringInputDeserialization(serviceTemplateFromJson); - ToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(VCPE_MONITORING_INPUT_YAML); + JpaToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(VCPE_MON_INPUT_YAML); assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0); // vDNS - serviceTemplateFromJson = deserializeMonitoringInputJson(VDNS_MONITORING_INPUT_JSON); + serviceTemplateFromJson = deserializeMonitoringInputJson(VDNS_MON_INPUT_JSON); verifyVdnsMonitoringInputDeserialization(serviceTemplateFromJson); - serviceTemplateFromYaml = deserializeMonitoringInputYaml(VDNS_MONITORING_INPUT_YAML); + serviceTemplateFromYaml = deserializeMonitoringInputYaml(VDNS_MON_INPUT_YAML); assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0); // vFirewall - serviceTemplateFromJson = deserializeMonitoringInputJson(VFW_MONITORING_INPUT_JSON); + serviceTemplateFromJson = deserializeMonitoringInputJson(VFW_MON_INPUT_JSON); verifyVfwMonitoringInputDeserialization(serviceTemplateFromJson); - serviceTemplateFromYaml = deserializeMonitoringInputYaml(VFW_MONITORING_INPUT_YAML); + serviceTemplateFromYaml = deserializeMonitoringInputYaml(VFW_MON_INPUT_YAML); assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0); } catch (Exception e) { @@ -101,17 +101,17 @@ public class MonitoringPolicySerializationTest { public void testSerialization() { try { // vCPE - ToscaServiceTemplate serviceTemplate = deserializeMonitoringInputJson(VCPE_MONITORING_INPUT_JSON); + JpaToscaServiceTemplate serviceTemplate = deserializeMonitoringInputJson(VCPE_MON_INPUT_JSON); String serializedServiceTemplate = serializeMonitoringServiceTemplate(serviceTemplate); verifyVcpeMonitoringOutputserialization(serializedServiceTemplate); // vDNS - serviceTemplate = deserializeMonitoringInputJson(VDNS_MONITORING_INPUT_JSON); + serviceTemplate = deserializeMonitoringInputJson(VDNS_MON_INPUT_JSON); serializedServiceTemplate = serializeMonitoringServiceTemplate(serviceTemplate); verifyVdnsMonitoringOutputserialization(serializedServiceTemplate); // vFirewall - serviceTemplate = deserializeMonitoringInputJson(VFW_MONITORING_INPUT_JSON); + serviceTemplate = deserializeMonitoringInputJson(VFW_MON_INPUT_JSON); serializedServiceTemplate = serializeMonitoringServiceTemplate(serviceTemplate); verifyVfwMonitoringOutputserialization(serializedServiceTemplate); @@ -121,30 +121,30 @@ public class MonitoringPolicySerializationTest { } } - private ToscaServiceTemplate deserializeMonitoringInputJson(String resourcePath) + private JpaToscaServiceTemplate deserializeMonitoringInputJson(String resourcePath) throws JsonSyntaxException, IOException { String policyJson = ResourceUtils.getResourceAsString(resourcePath); - ToscaServiceTemplate serviceTemplate = gson.fromJson(policyJson, ToscaServiceTemplate.class); + JpaToscaServiceTemplate serviceTemplate = gson.fromJson(policyJson, JpaToscaServiceTemplate.class); return serviceTemplate; } - private ToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath) + private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath) throws Exception { Yaml yaml = new Yaml(); String policyYaml = ResourceUtils.getResourceAsString(resourcePath); Object yamlObject = yaml.load(policyYaml); String yamlAsJsonString = new StandardCoder().encode(yamlObject); - ToscaServiceTemplate serviceTemplate = gson.fromJson(yamlAsJsonString, ToscaServiceTemplate.class); + JpaToscaServiceTemplate serviceTemplate = gson.fromJson(yamlAsJsonString, JpaToscaServiceTemplate.class); return serviceTemplate; } - private String serializeMonitoringServiceTemplate(ToscaServiceTemplate serviceTemplate) { + private String serializeMonitoringServiceTemplate(JpaToscaServiceTemplate serviceTemplate) { return gson.toJson(serviceTemplate); } - private void verifyVcpeMonitoringInputDeserialization(ToscaServiceTemplate serviceTemplate) { + private void verifyVcpeMonitoringInputDeserialization(JpaToscaServiceTemplate serviceTemplate) { // Sanity check the entire structure assertNotNull(serviceTemplate); @@ -155,7 +155,7 @@ public class MonitoringPolicySerializationTest { assertEquals("tosca_simple_yaml_1_0_0", serviceTemplate.getToscaDefinitionsVersion()); - Map policiesConceptMap = serviceTemplate.getTopologyTemplate() + Map policiesConceptMap = serviceTemplate.getTopologyTemplate() .getPolicies().getConceptMap(); // Check policies @@ -164,7 +164,7 @@ public class MonitoringPolicySerializationTest { assertEquals("onap.restart.tca:1.0.0", serviceTemplate.getTopologyTemplate().getPolicies().get("onap.restart.tca").getId()); - ToscaPolicy policyVal = policiesConceptMap.values().iterator().next(); + JpaToscaPolicy policyVal = policiesConceptMap.values().iterator().next(); // Check metadata assertTrue(policyVal.getMetadata().size() == 1); @@ -177,7 +177,7 @@ public class MonitoringPolicySerializationTest { assertNotNull(policyVal.getProperties().values().iterator().next()); } - private void verifyVdnsMonitoringInputDeserialization(ToscaServiceTemplate serviceTemplate) { + private void verifyVdnsMonitoringInputDeserialization(JpaToscaServiceTemplate serviceTemplate) { // Sanity check the entire structure assertNotNull(serviceTemplate); @@ -188,7 +188,7 @@ public class MonitoringPolicySerializationTest { assertEquals("tosca_simple_yaml_1_0_0", serviceTemplate.getToscaDefinitionsVersion()); - Map policiesConceptMap = serviceTemplate.getTopologyTemplate() + Map policiesConceptMap = serviceTemplate.getTopologyTemplate() .getPolicies().getConceptMap(); // Check policies @@ -197,7 +197,7 @@ public class MonitoringPolicySerializationTest { assertEquals("onap.scaleout.tca:1.0.0", serviceTemplate.getTopologyTemplate().getPolicies().get("onap.scaleout.tca").getId()); - ToscaPolicy policyVal = policiesConceptMap.values().iterator().next(); + JpaToscaPolicy policyVal = policiesConceptMap.values().iterator().next(); // Check metadata assertTrue(policyVal.getMetadata().size() == 1); @@ -210,7 +210,7 @@ public class MonitoringPolicySerializationTest { assertNotNull(policyVal.getProperties().values().iterator().next()); } - private void verifyVfwMonitoringInputDeserialization(ToscaServiceTemplate serviceTemplate) { + private void verifyVfwMonitoringInputDeserialization(JpaToscaServiceTemplate serviceTemplate) { // Sanity check the entire structure assertNotNull(serviceTemplate); @@ -221,7 +221,7 @@ public class MonitoringPolicySerializationTest { assertEquals("tosca_simple_yaml_1_0_0", serviceTemplate.getToscaDefinitionsVersion()); - Map policiesConceptMap = serviceTemplate.getTopologyTemplate() + Map policiesConceptMap = serviceTemplate.getTopologyTemplate() .getPolicies().getConceptMap(); // Check policies @@ -230,7 +230,7 @@ public class MonitoringPolicySerializationTest { assertEquals("onap.vfirewall.tca:1.0.0", serviceTemplate.getTopologyTemplate().getPolicies().get("onap.vfirewall.tca").getId()); - ToscaPolicy policyVal = policiesConceptMap.values().iterator().next(); + JpaToscaPolicy policyVal = policiesConceptMap.values().iterator().next(); // Check metadata assertTrue(policyVal.getMetadata().size() == 1); diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java index c40b32e3c..b494199e8 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java @@ -38,13 +38,13 @@ import org.junit.Test; import org.onap.policy.common.utils.resources.ResourceUtils; import org.onap.policy.models.base.PfConceptKey; import org.onap.policy.models.base.PfValidationResult; -import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintLogicalString; -import org.onap.policy.models.tosca.simple.concepts.ToscaConstraintValidValues; -import org.onap.policy.models.tosca.simple.concepts.ToscaDataType; -import org.onap.policy.models.tosca.simple.concepts.ToscaEntrySchema; -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.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogicalString; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintValidValues; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -74,7 +74,7 @@ public class MonitoringPolicyTypeSerializationTest { public void testDeserialization() { try { // TCA - ToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML); + JpaToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML); verifyTcaInputDeserialization(serviceTemplateFromYaml); // Collector @@ -90,17 +90,17 @@ public class MonitoringPolicyTypeSerializationTest { public void testSerialization() { try { // TCA - ToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML); + JpaToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML); String serializedServiceTemplate1 = serializeMonitoringServiceTemplate(serviceTemplateFromYaml); - ToscaServiceTemplate serviceTemplateFromJson = gson.fromJson(serializedServiceTemplate1, - ToscaServiceTemplate.class); + JpaToscaServiceTemplate serviceTemplateFromJson = gson.fromJson(serializedServiceTemplate1, + JpaToscaServiceTemplate.class); String serializedServiceTemplate2 = serializeMonitoringServiceTemplate(serviceTemplateFromJson); assertEquals(serializedServiceTemplate1, serializedServiceTemplate2); // Collector serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML); serializedServiceTemplate1 = serializeMonitoringServiceTemplate(serviceTemplateFromYaml); - serviceTemplateFromJson = gson.fromJson(serializedServiceTemplate1, ToscaServiceTemplate.class); + serviceTemplateFromJson = gson.fromJson(serializedServiceTemplate1, JpaToscaServiceTemplate.class); serializedServiceTemplate2 = serializeMonitoringServiceTemplate(serviceTemplateFromJson); assertEquals(serializedServiceTemplate1, serializedServiceTemplate2); @@ -109,18 +109,18 @@ public class MonitoringPolicyTypeSerializationTest { } } - private ToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath) + private JpaToscaServiceTemplate deserializeMonitoringInputYaml(String resourcePath) throws JsonSyntaxException, IOException { Yaml yaml = new Yaml(); String policyTypeYaml = ResourceUtils.getResourceAsString(resourcePath); Object yamlObject = yaml.load(policyTypeYaml); String yamlAsJsonString = new Gson().toJson(yamlObject); - ToscaServiceTemplate serviceTemplate = gson.fromJson(yamlAsJsonString, ToscaServiceTemplate.class); + JpaToscaServiceTemplate serviceTemplate = gson.fromJson(yamlAsJsonString, JpaToscaServiceTemplate.class); return serviceTemplate; } - private void verifyTcaInputDeserialization(ToscaServiceTemplate serviceTemplate) { + private void verifyTcaInputDeserialization(JpaToscaServiceTemplate serviceTemplate) { // Sanity check the entire structure assertNotNull(serviceTemplate); @@ -131,50 +131,50 @@ public class MonitoringPolicyTypeSerializationTest { assertEquals("tosca_simple_yaml_1_0_0", serviceTemplate.getToscaDefinitionsVersion()); // Check policy_types - Map policyTypesConceptMap = serviceTemplate.getPolicyTypes().getConceptMap(); + Map policyTypesConceptMap = serviceTemplate.getPolicyTypes().getConceptMap(); assertTrue(policyTypesConceptMap.size() == 2); - Iterator> policyTypesIter = policyTypesConceptMap.entrySet().iterator(); + Iterator> policyTypesIter = policyTypesConceptMap.entrySet().iterator(); - Entry firstPolicyType = policyTypesIter.next(); + Entry firstPolicyType = policyTypesIter.next(); assertEquals("onap.policies.Monitoring", firstPolicyType.getKey().getName()); assertEquals("1.0.0", firstPolicyType.getKey().getVersion()); assertEquals("tosca.policies.Root", firstPolicyType.getValue().getDerivedFrom().getName()); assertEquals("a base policy type for all policies that governs monitoring provisioning", firstPolicyType.getValue().getDescription()); - Entry secondPolicyType = policyTypesIter.next(); + Entry secondPolicyType = policyTypesIter.next(); assertEquals("onap.policy.monitoring.cdap.tca.hi.lo.app", secondPolicyType.getKey().getName()); assertEquals("1.0.0", secondPolicyType.getKey().getVersion()); assertEquals("onap.policies.Monitoring", secondPolicyType.getValue().getDerivedFrom().getName()); assertTrue(secondPolicyType.getValue().getProperties().size() == 1); - ToscaProperty property = secondPolicyType.getValue().getProperties().iterator().next(); + JpaToscaProperty property = secondPolicyType.getValue().getProperties().iterator().next(); assertEquals("onap.policy.monitoring.cdap.tca.hi.lo.app", property.getKey().getParentKeyName()); assertEquals("1.0.0", property.getKey().getParentKeyVersion()); assertEquals("tca_policy", property.getKey().getLocalName()); assertEquals("map", property.getType().getName()); assertEquals("TCA Policy JSON", property.getDescription()); - ToscaEntrySchema entrySchema = property.getEntrySchema(); + JpaToscaEntrySchema entrySchema = property.getEntrySchema(); assertEquals("map", entrySchema.getKey().getParentKeyName()); assertEquals("1.0.0", entrySchema.getKey().getParentKeyVersion()); assertEquals("entry_schema", entrySchema.getKey().getLocalName()); assertEquals("onap.datatypes.monitoring.tca_policy", entrySchema.getType().getName()); // Check data_types - Map dataTypesConceptMap = serviceTemplate.getDataTypes().getConceptMap(); + Map dataTypesConceptMap = serviceTemplate.getDataTypes().getConceptMap(); assertTrue(dataTypesConceptMap.size() == 3); - Iterator> dataTypesIter = dataTypesConceptMap.entrySet().iterator(); + Iterator> dataTypesIter = dataTypesConceptMap.entrySet().iterator(); - Entry firstDataType = dataTypesIter.next(); + Entry firstDataType = dataTypesIter.next(); assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataType.getKey().getName()); - ToscaDataType firstDataTypeVal = firstDataType.getValue(); + JpaToscaDataType firstDataTypeVal = firstDataType.getValue(); assertEquals("tosca.datatypes.Root", firstDataTypeVal.getDerivedFrom().getName()); assertEquals("1.0.0", firstDataTypeVal.getDerivedFrom().getVersion()); assertTrue(firstDataTypeVal.getProperties().size() == 6); - Iterator firstDataTypePropertiesIter = firstDataTypeVal.getProperties().iterator(); + Iterator firstDataTypePropertiesIter = firstDataTypeVal.getProperties().iterator(); - ToscaProperty firstDataTypeFirstProperty = firstDataTypePropertiesIter.next(); + JpaToscaProperty firstDataTypeFirstProperty = firstDataTypePropertiesIter.next(); assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeFirstProperty.getKey() .getParentKeyName()); assertEquals("controlLoopSchemaType", firstDataTypeFirstProperty.getKey().getLocalName()); @@ -188,11 +188,11 @@ public class MonitoringPolicyTypeSerializationTest { assertEquals("string", firstDataTypeFirstProperty.getConstraints().iterator().next().getKey() .getParentKeyName()); assertTrue(firstDataTypeFirstProperty.getConstraints().iterator().next() - instanceof ToscaConstraintValidValues); - assertTrue(((ToscaConstraintValidValues)(firstDataTypeFirstProperty.getConstraints().iterator().next())) + instanceof JpaToscaConstraintValidValues); + assertTrue(((JpaToscaConstraintValidValues)(firstDataTypeFirstProperty.getConstraints().iterator().next())) .getValidValues().size() == 2); - ToscaProperty firstDataTypeSecondProperty = firstDataTypePropertiesIter.next(); + JpaToscaProperty firstDataTypeSecondProperty = firstDataTypePropertiesIter.next(); assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeSecondProperty.getKey() .getParentKeyName()); assertEquals("eventName", firstDataTypeSecondProperty.getKey().getLocalName()); @@ -201,7 +201,7 @@ public class MonitoringPolicyTypeSerializationTest { assertEquals("Event name to which thresholds need to be applied", firstDataTypeSecondProperty .getDescription()); - ToscaProperty firstDataTypeThirdProperty = firstDataTypePropertiesIter.next(); + JpaToscaProperty firstDataTypeThirdProperty = firstDataTypePropertiesIter.next(); assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeThirdProperty.getKey() .getParentKeyName()); assertEquals("policyName", firstDataTypeThirdProperty.getKey().getLocalName()); @@ -209,7 +209,7 @@ public class MonitoringPolicyTypeSerializationTest { assertTrue(firstDataTypeThirdProperty.isRequired()); assertEquals("TCA Policy Scope Name", firstDataTypeThirdProperty.getDescription()); - ToscaProperty firstDataTypeFourthProperty = firstDataTypePropertiesIter.next(); + JpaToscaProperty firstDataTypeFourthProperty = firstDataTypePropertiesIter.next(); assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeFourthProperty.getKey() .getParentKeyName()); assertEquals("policyScope", firstDataTypeFourthProperty.getKey().getLocalName()); @@ -217,7 +217,7 @@ public class MonitoringPolicyTypeSerializationTest { assertTrue(firstDataTypeFourthProperty.isRequired()); assertEquals("TCA Policy Scope", firstDataTypeFourthProperty.getDescription()); - ToscaProperty firstDataTypeFifthProperty = firstDataTypePropertiesIter.next(); + JpaToscaProperty firstDataTypeFifthProperty = firstDataTypePropertiesIter.next(); assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeFifthProperty.getKey() .getParentKeyName()); assertEquals("policyVersion", firstDataTypeFifthProperty.getKey().getLocalName()); @@ -225,7 +225,7 @@ public class MonitoringPolicyTypeSerializationTest { assertTrue(firstDataTypeFifthProperty.isRequired()); assertEquals("TCA Policy Scope Version", firstDataTypeFifthProperty.getDescription()); - ToscaProperty firstDataTypeSixthProperty = firstDataTypePropertiesIter.next(); + JpaToscaProperty firstDataTypeSixthProperty = firstDataTypePropertiesIter.next(); assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataTypeSixthProperty.getKey() .getParentKeyName()); assertEquals("thresholds", firstDataTypeSixthProperty.getKey().getLocalName()); @@ -238,15 +238,15 @@ public class MonitoringPolicyTypeSerializationTest { assertEquals("onap.datatypes.monitoring.thresholds", firstDataTypeSixthProperty.getEntrySchema().getType() .getName()); - Entry secondDataType = dataTypesIter.next(); + Entry secondDataType = dataTypesIter.next(); assertEquals("onap.datatypes.monitoring.tca_policy", secondDataType.getKey().getName()); - ToscaDataType secondDataTypeVal = secondDataType.getValue(); + JpaToscaDataType secondDataTypeVal = secondDataType.getValue(); assertEquals("tosca.datatypes.Root", secondDataTypeVal.getDerivedFrom().getName()); assertEquals("1.0.0", secondDataTypeVal.getDerivedFrom().getVersion()); assertTrue(secondDataTypeVal.getProperties().size() == 2); - Iterator secondDataTypePropertiesIter = secondDataTypeVal.getProperties().iterator(); + Iterator secondDataTypePropertiesIter = secondDataTypeVal.getProperties().iterator(); - ToscaProperty secondDataTypeFirstProperty = secondDataTypePropertiesIter.next(); + JpaToscaProperty secondDataTypeFirstProperty = secondDataTypePropertiesIter.next(); assertEquals("onap.datatypes.monitoring.tca_policy", secondDataTypeFirstProperty.getKey().getParentKeyName()); assertEquals("domain", secondDataTypeFirstProperty.getKey().getLocalName()); assertEquals("string", secondDataTypeFirstProperty.getType().getName()); @@ -258,11 +258,11 @@ public class MonitoringPolicyTypeSerializationTest { .getParentKeyName()); assertEquals("equal", secondDataTypeFirstProperty.getConstraints().iterator().next().getKey().getLocalName()); assertTrue(secondDataTypeFirstProperty.getConstraints().iterator().next() - instanceof ToscaConstraintLogicalString); - assertEquals("measurementsForVfScaling", ((ToscaConstraintLogicalString)(secondDataTypeFirstProperty + instanceof JpaToscaConstraintLogicalString); + assertEquals("measurementsForVfScaling", ((JpaToscaConstraintLogicalString)(secondDataTypeFirstProperty .getConstraints().iterator().next())).getCompareToString()); - ToscaProperty secondDataTypeSecondProperty = secondDataTypePropertiesIter.next(); + JpaToscaProperty secondDataTypeSecondProperty = secondDataTypePropertiesIter.next(); assertEquals("onap.datatypes.monitoring.tca_policy", secondDataTypeSecondProperty.getKey().getParentKeyName()); assertEquals("metricsPerEventName", secondDataTypeSecondProperty.getKey().getLocalName()); assertEquals("list", secondDataTypeSecondProperty.getType().getName()); @@ -275,15 +275,15 @@ public class MonitoringPolicyTypeSerializationTest { secondDataTypeSecondProperty.getEntrySchema().getType().getName()); assertEquals("entry_schema", secondDataTypeSecondProperty.getEntrySchema().getKey().getLocalName()); - Entry thirdDataType = dataTypesIter.next(); + Entry thirdDataType = dataTypesIter.next(); assertEquals("onap.datatypes.monitoring.thresholds", thirdDataType.getKey().getName()); - ToscaDataType thirdDataTypeVal = thirdDataType.getValue(); + JpaToscaDataType thirdDataTypeVal = thirdDataType.getValue(); assertEquals("tosca.datatypes.Root", thirdDataTypeVal.getDerivedFrom().getName()); assertEquals("1.0.0", thirdDataTypeVal.getDerivedFrom().getVersion()); assertTrue(thirdDataTypeVal.getProperties().size() == 7); - Iterator thirdDataTypePropertiesIter = thirdDataTypeVal.getProperties().iterator(); + Iterator thirdDataTypePropertiesIter = thirdDataTypeVal.getProperties().iterator(); - ToscaProperty thirdDataTypeFirstProperty = thirdDataTypePropertiesIter.next(); + JpaToscaProperty thirdDataTypeFirstProperty = thirdDataTypePropertiesIter.next(); assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeFirstProperty.getKey().getParentKeyName()); assertEquals("closedLoopControlName", thirdDataTypeFirstProperty.getKey().getLocalName()); assertEquals("string", thirdDataTypeFirstProperty.getType().getName()); @@ -291,7 +291,7 @@ public class MonitoringPolicyTypeSerializationTest { assertEquals("Closed Loop Control Name associated with the threshold", thirdDataTypeFirstProperty .getDescription()); - ToscaProperty thirdDataTypeSecondProperty = thirdDataTypePropertiesIter.next(); + JpaToscaProperty thirdDataTypeSecondProperty = thirdDataTypePropertiesIter.next(); assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeSecondProperty.getKey().getParentKeyName()); assertEquals("closedLoopEventStatus", thirdDataTypeSecondProperty.getKey().getLocalName()); assertEquals("string", thirdDataTypeSecondProperty.getType().getName()); @@ -304,11 +304,11 @@ public class MonitoringPolicyTypeSerializationTest { assertEquals("valid_values", thirdDataTypeSecondProperty.getConstraints().iterator().next().getKey() .getLocalName()); assertTrue(thirdDataTypeSecondProperty.getConstraints().iterator().next() - instanceof ToscaConstraintValidValues); - assertTrue(((ToscaConstraintValidValues)(thirdDataTypeSecondProperty.getConstraints().iterator().next())) + instanceof JpaToscaConstraintValidValues); + assertTrue(((JpaToscaConstraintValidValues)(thirdDataTypeSecondProperty.getConstraints().iterator().next())) .getValidValues().size() == 2); - ToscaProperty thirdDataTypeThirdProperty = thirdDataTypePropertiesIter.next(); + JpaToscaProperty thirdDataTypeThirdProperty = thirdDataTypePropertiesIter.next(); assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeThirdProperty.getKey().getParentKeyName()); assertEquals("direction", thirdDataTypeThirdProperty.getKey().getLocalName()); assertEquals("string", thirdDataTypeThirdProperty.getType().getName()); @@ -320,10 +320,10 @@ public class MonitoringPolicyTypeSerializationTest { .getParentKeyName()); assertEquals("valid_values", thirdDataTypeThirdProperty.getConstraints().iterator().next().getKey() .getLocalName()); - assertTrue(((ToscaConstraintValidValues)(thirdDataTypeThirdProperty.getConstraints().iterator().next())) + assertTrue(((JpaToscaConstraintValidValues)(thirdDataTypeThirdProperty.getConstraints().iterator().next())) .getValidValues().size() == 5); - ToscaProperty thirdDataTypeFourthProperty = thirdDataTypePropertiesIter.next(); + JpaToscaProperty thirdDataTypeFourthProperty = thirdDataTypePropertiesIter.next(); assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeFourthProperty.getKey().getParentKeyName()); assertEquals("fieldPath", thirdDataTypeFourthProperty.getKey().getLocalName()); assertEquals("string", thirdDataTypeFourthProperty.getType().getName()); @@ -336,10 +336,10 @@ public class MonitoringPolicyTypeSerializationTest { .getParentKeyName()); assertEquals("valid_values", thirdDataTypeFourthProperty.getConstraints().iterator().next().getKey() .getLocalName()); - assertTrue(((ToscaConstraintValidValues)(thirdDataTypeFourthProperty.getConstraints().iterator().next())) + assertTrue(((JpaToscaConstraintValidValues)(thirdDataTypeFourthProperty.getConstraints().iterator().next())) .getValidValues().size() == 43); - ToscaProperty thirdDataTypeFifthProperty = thirdDataTypePropertiesIter.next(); + JpaToscaProperty thirdDataTypeFifthProperty = thirdDataTypePropertiesIter.next(); assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeFifthProperty.getKey().getParentKeyName()); assertEquals("severity", thirdDataTypeFifthProperty.getKey().getLocalName()); assertEquals("string", thirdDataTypeFifthProperty.getType().getName()); @@ -351,10 +351,10 @@ public class MonitoringPolicyTypeSerializationTest { .getParentKeyName()); assertEquals("valid_values", thirdDataTypeFifthProperty.getConstraints().iterator().next().getKey() .getLocalName()); - assertTrue(((ToscaConstraintValidValues)(thirdDataTypeFifthProperty.getConstraints().iterator().next())) + assertTrue(((JpaToscaConstraintValidValues)(thirdDataTypeFifthProperty.getConstraints().iterator().next())) .getValidValues().size() == 5);; - ToscaProperty thirdDataTypeSixthProperty = thirdDataTypePropertiesIter.next(); + JpaToscaProperty thirdDataTypeSixthProperty = thirdDataTypePropertiesIter.next(); assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeSixthProperty.getKey().getParentKeyName()); assertEquals("thresholdValue", thirdDataTypeSixthProperty.getKey().getLocalName()); assertEquals("integer", thirdDataTypeSixthProperty.getType().getName()); @@ -362,7 +362,7 @@ public class MonitoringPolicyTypeSerializationTest { assertEquals("Threshold value for the field Path inside CEF message", thirdDataTypeSixthProperty .getDescription()); - ToscaProperty thirdDataTypeSeventhProperty = thirdDataTypePropertiesIter.next(); + JpaToscaProperty thirdDataTypeSeventhProperty = thirdDataTypePropertiesIter.next(); assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeSeventhProperty.getKey().getParentKeyName()); assertEquals("version", thirdDataTypeSeventhProperty.getKey().getLocalName()); assertEquals("string", thirdDataTypeSeventhProperty.getType().getName()); @@ -370,7 +370,7 @@ public class MonitoringPolicyTypeSerializationTest { assertEquals("Version number associated with the threshold", thirdDataTypeSeventhProperty.getDescription()); } - private void verifyCollectorInputDeserialization(ToscaServiceTemplate serviceTemplate) { + private void verifyCollectorInputDeserialization(JpaToscaServiceTemplate serviceTemplate) { // Sanity check the entire structure assertNotNull(serviceTemplate); @@ -381,27 +381,27 @@ public class MonitoringPolicyTypeSerializationTest { assertEquals("tosca_simple_yaml_1_0_0", serviceTemplate.getToscaDefinitionsVersion()); // Check policy_types - Map policyTypesConceptMap = serviceTemplate.getPolicyTypes().getConceptMap(); + Map policyTypesConceptMap = serviceTemplate.getPolicyTypes().getConceptMap(); assertTrue(policyTypesConceptMap.size() == 2); - Iterator> policyTypesIter = policyTypesConceptMap.entrySet().iterator(); + Iterator> policyTypesIter = policyTypesConceptMap.entrySet().iterator(); - Entry firstPolicyType = policyTypesIter.next(); + Entry firstPolicyType = policyTypesIter.next(); assertEquals("onap.policies.Monitoring", firstPolicyType.getKey().getName()); assertEquals("1.0.0", firstPolicyType.getKey().getVersion()); assertEquals("tosca.policies.Root", firstPolicyType.getValue().getDerivedFrom().getName()); assertEquals("a base policy type for all policies that govern monitoring provision", firstPolicyType.getValue().getDescription()); - Entry secondPolicyType = policyTypesIter.next(); + Entry secondPolicyType = policyTypesIter.next(); assertEquals("onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server", secondPolicyType.getKey().getName()); assertEquals("1.0.0", secondPolicyType.getKey().getVersion()); assertEquals("policy.nodes.Root", secondPolicyType.getValue().getDerivedFrom().getName()); assertTrue(secondPolicyType.getValue().getProperties().size() == 2); - Iterator propertiesIter = secondPolicyType.getValue().getProperties().iterator(); + Iterator propertiesIter = secondPolicyType.getValue().getProperties().iterator(); - ToscaProperty firstProperty = propertiesIter.next(); + JpaToscaProperty firstProperty = propertiesIter.next(); assertEquals("onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server", firstProperty.getKey().getParentKeyName()); assertEquals("1.0.0", firstProperty.getKey().getParentKeyVersion()); @@ -409,7 +409,7 @@ public class MonitoringPolicyTypeSerializationTest { assertEquals("string", firstProperty.getType().getName()); assertEquals("DMAAP Bus Controller feed endpoint", firstProperty.getDescription()); - ToscaProperty secondProperty = propertiesIter.next(); + JpaToscaProperty secondProperty = propertiesIter.next(); assertEquals("onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server", secondProperty.getKey().getParentKeyName()); assertEquals("1.0.0", secondProperty.getKey().getParentKeyVersion()); @@ -418,7 +418,7 @@ public class MonitoringPolicyTypeSerializationTest { assertEquals("datafile Policy JSON as string", secondProperty.getDescription()); } - private String serializeMonitoringServiceTemplate(ToscaServiceTemplate serviceTemplate) { + private String serializeMonitoringServiceTemplate(JpaToscaServiceTemplate serviceTemplate) { return gson.toJson(serviceTemplate); } } \ No newline at end of file diff --git a/models-tosca/src/test/resources/META-INF/persistence.xml b/models-tosca/src/test/resources/META-INF/persistence.xml index 68340901b..23e8567f1 100644 --- a/models-tosca/src/test/resources/META-INF/persistence.xml +++ b/models-tosca/src/test/resources/META-INF/persistence.xml @@ -26,8 +26,8 @@ org.onap.policy.models.dao.converters.CDataConditioner org.onap.policy.models.dao.converters.Uuid2String org.onap.policy.models.base.PfConceptKey - org.onap.policy.models.tosca.simple.concepts.ToscaPolicyType - org.onap.policy.models.tosca.simple.concepts.ToscaPolicy + org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType + org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy @@ -46,7 +46,7 @@ org.onap.policy.models.dao.converters.CDataConditioner org.onap.policy.models.dao.converters.Uuid2String org.onap.policy.models.base.PfConceptKey - org.onap.policy.models.tosca.simple.concepts.ToscaPolicy + org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy -- cgit 1.2.3-korg