summaryrefslogtreecommitdiffstats
path: root/models-tosca
diff options
context:
space:
mode:
authorLiam Fallon <liam.fallon@est.tech>2020-12-23 18:28:33 +0000
committerGerrit Code Review <gerrit@onap.org>2020-12-23 18:28:33 +0000
commit8ad3f95cdcec48b8315a5febfd4ec07bae7aabba (patch)
treeec81ba946cee1c4c440abe04db9cf276c8eb36a9 /models-tosca
parent7b5adac8cdcf61522644e201c50bb2ff6c4c72c8 (diff)
parentb87e0242ce1a957740ee988bec3b82e3628adbed (diff)
Merge "Add Service Template TOSCA handling"
Diffstat (limited to 'models-tosca')
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java16
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateComparator.java34
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilter.java63
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplates.java40
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java159
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java11
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilterTest.java125
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderGenericTest.java42
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java17
-rw-r--r--models-tosca/src/test/resources/servicetemplates/TestServiceTemplates.yaml185
10 files changed, 605 insertions, 87 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java
index 10d3b7a14..5c1167c7d 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntity.java
@@ -32,6 +32,7 @@ import javax.ws.rs.core.Response;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
+import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.base.PfNameVersion;
@@ -43,8 +44,8 @@ import org.onap.policy.models.base.PfNameVersion;
@Data
@NoArgsConstructor
public class ToscaEntity implements PfNameVersion {
- private String name;
- private String version;
+ private String name = PfKey.NULL_KEY_NAME;
+ private String version = PfKey.NULL_KEY_VERSION;
@ApiModelProperty(name = "derived_from")
@SerializedName("derived_from")
@@ -81,6 +82,16 @@ public class ToscaEntity implements PfNameVersion {
return new ToscaEntityKey(name, version);
}
+ @Override
+ public String getDefinedName() {
+ return (PfKey.NULL_KEY_NAME.equals(name) ? null : name);
+ }
+
+ @Override
+ public String getDefinedVersion() {
+ return (PfKey.NULL_KEY_VERSION.equals(version) ? null : version);
+ }
+
/**
* Convert a list of maps of TOSCA entities into a regular map.
*
@@ -129,5 +140,4 @@ public class ToscaEntity implements PfNameVersion {
return entityMap;
}
-
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateComparator.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateComparator.java
new file mode 100644
index 000000000..015c10bdd
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateComparator.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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.authorative.concepts;
+
+import java.util.Comparator;
+
+/**
+ * Compare two ToscaServiceTemplate objects.
+ */
+public class ToscaServiceTemplateComparator implements Comparator<ToscaServiceTemplate> {
+
+ @Override
+ public int compare(final ToscaServiceTemplate left, final ToscaServiceTemplate right) {
+ return left.compareNameVersion(left, right);
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilter.java
new file mode 100644
index 000000000..75b13969d
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilter.java
@@ -0,0 +1,63 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 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.authorative.concepts;
+
+import java.util.List;
+import java.util.stream.Collectors;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NonNull;
+import org.onap.policy.models.base.PfObjectFilter;
+
+/**
+ * Filter class for searches for {@link ToscaServiceTemplate} instances. If any fields are null, they are ignored.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+@Builder
+@Data
+public class ToscaServiceTemplateFilter implements PfObjectFilter<ToscaServiceTemplate> {
+ public static final String LATEST_VERSION = "LATEST";
+
+ // Regular expression
+ private String name;
+
+ // Regular Expression, set to LATEST_VERRSION to get the latest version
+ private String version;
+
+ @Override
+ public List<ToscaServiceTemplate> filter(@NonNull final List<ToscaServiceTemplate> originalList) {
+
+ // @formatter:off
+ List<ToscaServiceTemplate> returnList = originalList.stream()
+ .filter(p -> filterString(p.getName(), name))
+ .filter(p -> LATEST_VERSION.equals(version)
+ || filterString(p.getVersion(), version))
+ .collect(Collectors.toList());
+ // @formatter:off
+
+ if (LATEST_VERSION.equals(version)) {
+ return this.latestVersionFilter(returnList, new ToscaServiceTemplateComparator());
+ } else {
+ return returnList;
+ }
+ }
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplates.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplates.java
new file mode 100644
index 000000000..912cfd580
--- /dev/null
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplates.java
@@ -0,0 +1,40 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Model
+ * ================================================================================
+ * Copyright (C) 2020 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.authorative.concepts;
+
+import com.google.gson.annotations.SerializedName;
+import io.swagger.annotations.ApiModelProperty;
+import java.util.List;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * Class to represent a map of TOSCA service templates.
+ */
+@Data
+@EqualsAndHashCode
+public class ToscaServiceTemplates {
+ @ApiModelProperty(name = "service_templates")
+ @SerializedName("service_templates")
+ private List<ToscaServiceTemplate> serviceTemplates;
+}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
index e8f99f742..d20f5d080 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProvider.java
@@ -39,6 +39,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplateFilter;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
import org.onap.policy.models.tosca.utils.ToscaServiceTemplateUtils;
@@ -57,29 +58,59 @@ public class AuthorativeToscaProvider {
private static final Object providerLockObject = "providerLockObject";
/**
- * Get a service template.
+ * Get service templates.
*
* @param dao the DAO to use to access the database
- * @param name the name of the control loop to get.
- * @param version the version of the control loop to get.
- * @return the control loops found
- * @throws PfModelException on errors getting control loops
+ * @param name the name of the service template to get.
+ * @param version the version of the service template to get.
+ * @return the service templates found
+ * @throws PfModelException on errors getting service templates
*/
- public ToscaServiceTemplate getServiceTemplate(@NonNull final PfDao dao, final String name, final String version)
- throws PfModelException {
+ public List<ToscaServiceTemplate> getServiceTemplateList(PfDao dao, String name, String version)
+ throws PfModelException {
synchronized (providerLockObject) {
- LOGGER.debug("->getServiceTemplate: name={}, version={}", name, version);
+ LOGGER.debug("->getServiceTemplateList: name={}, version={}", name, version);
- ToscaServiceTemplate gotServiceTemplate = new SimpleToscaProvider().getServiceTemplate(dao).toAuthorative();
+ List<ToscaServiceTemplate> serviceTemplateList = new ArrayList<>();
- LOGGER.debug("<-getServiceTemplate: name={}, version={}, gotServiceTemplate={}", name, version,
- gotServiceTemplate);
- return gotServiceTemplate;
+ try {
+ ToscaServiceTemplate serviceTemplate =
+ new SimpleToscaProvider().getServiceTemplate(dao).toAuthorative();
+ serviceTemplateList.add(serviceTemplate);
+ } catch (PfModelRuntimeException pfme) {
+ return handlePfModelRuntimeException(pfme);
+ }
+
+ LOGGER.debug("<-getServiceTemplateList: name={}, version={}, serviceTemplateList={}", name, version,
+ serviceTemplateList);
+ return serviceTemplateList;
}
}
/**
+ * Get filtered service templates.
+ *
+ * @param pfDao the DAO to use to access the database
+ * @param filter the filter for the service templates to get
+ * @return the service templates found
+ * @throws PfModelException on errors getting service templates
+ */
+ public List<ToscaServiceTemplate> getFilteredServiceTemplateList(PfDao pfDao,
+ @NonNull ToscaServiceTemplateFilter filter) throws PfModelException {
+
+ LOGGER.debug("->getFilteredServiceTemplateList: filter={}", filter);
+
+ List<ToscaServiceTemplate> filteredServiceTemplateList =
+ filter.filter(getServiceTemplateList(pfDao, null, null));
+
+ LOGGER.debug("<-getFilteredServiceTemplateList: filter={}, filteredServiceTemplateList={}", filter,
+ filteredServiceTemplateList);
+
+ return filteredServiceTemplateList;
+ }
+
+ /**
* Create a service template.
*
* @param dao the DAO to use to access the database
@@ -88,13 +119,13 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors creating the service template
*/
public ToscaServiceTemplate createServiceTemplate(@NonNull final PfDao dao,
- @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+ @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
synchronized (providerLockObject) {
LOGGER.debug("->createServiceTemplate: serviceTemplate={}", serviceTemplate);
ToscaServiceTemplate createdServiceTemplate = new SimpleToscaProvider()
- .appendToServiceTemplate(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
+ .appendToServiceTemplate(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
LOGGER.debug("<-createServiceTemplate: createdServiceTemplate={}", createdServiceTemplate);
return createdServiceTemplate;
@@ -102,6 +133,28 @@ public class AuthorativeToscaProvider {
}
/**
+ * Update a service template.
+ *
+ * @param dao the DAO to use to access the database
+ * @param serviceTemplate the service template to be updated.
+ * @return the TOSCA service template that was updated
+ * @throws PfModelException on errors updating the service template
+ */
+ public ToscaServiceTemplate updateServiceTemplate(@NonNull final PfDao dao,
+ @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+
+ synchronized (providerLockObject) {
+ LOGGER.debug("->updateServiceTemplate: serviceTemplate={}", serviceTemplate);
+
+ ToscaServiceTemplate updatedServiceTemplate = new SimpleToscaProvider()
+ .appendToServiceTemplate(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
+
+ LOGGER.debug("<-updateServiceTemplate: updatedServiceTemplate={}", updatedServiceTemplate);
+ return updatedServiceTemplate;
+ }
+ }
+
+ /**
* Delete a service template.
*
* @param dao the DAO to use to access the database
@@ -111,16 +164,16 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors deleting the control loop
*/
public ToscaServiceTemplate deleteServiceTemplate(@NonNull final PfDao dao, @NonNull final String name,
- @NonNull final String version) throws PfModelException {
+ @NonNull final String version) throws PfModelException {
synchronized (providerLockObject) {
LOGGER.debug("->deleteServiceTemplate: name={}, version={}", name, version);
ToscaServiceTemplate deletedServiceTemplate =
- new SimpleToscaProvider().deleteServiceTemplate(dao).toAuthorative();
+ new SimpleToscaProvider().deleteServiceTemplate(dao).toAuthorative();
LOGGER.debug("<-deleteServiceTemplate: name={}, version={}, deletedServiceTemplate={}", name, version,
- deletedServiceTemplate);
+ deletedServiceTemplate);
return deletedServiceTemplate;
}
}
@@ -135,7 +188,7 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors getting policy types
*/
public ToscaServiceTemplate getPolicyTypes(@NonNull final PfDao dao, final String name, final String version)
- throws PfModelException {
+ throws PfModelException {
synchronized (providerLockObject) {
LOGGER.debug("->getPolicyTypes: name={}, version={}", name, version);
@@ -159,7 +212,7 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors getting policy types
*/
public List<ToscaPolicyType> getPolicyTypeList(@NonNull final PfDao dao, final String name, final String version)
- throws PfModelException {
+ throws PfModelException {
synchronized (providerLockObject) {
LOGGER.debug("->getPolicyTypeList: name={}, version={}", name, version);
@@ -168,7 +221,7 @@ public class AuthorativeToscaProvider {
try {
policyTypeList = new ArrayList<>(new SimpleToscaProvider().getPolicyTypes(dao, name, version)
- .toAuthorative().getPolicyTypes().values());
+ .toAuthorative().getPolicyTypes().values());
} catch (PfModelRuntimeException pfme) {
return handlePfModelRuntimeException(pfme);
}
@@ -187,7 +240,7 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors getting policy types
*/
public ToscaServiceTemplate getFilteredPolicyTypes(@NonNull final PfDao dao,
- @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException {
+ @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException {
synchronized (providerLockObject) {
LOGGER.debug("->getFilteredPolicyTypes: filter={}", filter);
@@ -200,17 +253,17 @@ public class AuthorativeToscaProvider {
if (CollectionUtils.isEmpty(filteredPolicyTypes)) {
throw new PfModelRuntimeException(Response.Status.NOT_FOUND,
- "policy types for filter " + filter.toString() + " do not exist");
+ "policy types for filter " + filter.toString() + " do not exist");
}
JpaToscaServiceTemplate filteredServiceTemplate = new JpaToscaServiceTemplate();
for (ToscaPolicyType policyType : filteredPolicyTypes) {
JpaToscaServiceTemplate cascadedServiceTemplate = simpleToscaProvider
- .getCascadedPolicyTypes(dbServiceTemplate, policyType.getName(), policyType.getVersion());
+ .getCascadedPolicyTypes(dbServiceTemplate, policyType.getName(), policyType.getVersion());
filteredServiceTemplate =
- ToscaServiceTemplateUtils.addFragment(filteredServiceTemplate, cascadedServiceTemplate);
+ ToscaServiceTemplateUtils.addFragment(filteredServiceTemplate, cascadedServiceTemplate);
}
ToscaServiceTemplate returnServiceTemplate = filteredServiceTemplate.toAuthorative();
@@ -229,14 +282,14 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors getting policy types
*/
public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull final PfDao dao,
- @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException {
+ @NonNull final ToscaPolicyTypeFilter filter) throws PfModelException {
LOGGER.debug("->getFilteredPolicyTypeList: filter={}", filter);
List<ToscaPolicyType> filteredPolicyTypeList = filter.filter(getPolicyTypeList(dao, null, null));
LOGGER.debug("<-getFilteredPolicyTypeList: filter={}, filteredPolicyTypeList={}", filter,
- filteredPolicyTypeList);
+ filteredPolicyTypeList);
return filteredPolicyTypeList;
}
@@ -250,13 +303,13 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors creating policy types
*/
public ToscaServiceTemplate createPolicyTypes(@NonNull final PfDao dao,
- @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+ @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
synchronized (providerLockObject) {
LOGGER.debug("->createPolicyTypes: serviceTemplate={}", serviceTemplate);
ToscaServiceTemplate createdServiceTemplate = new SimpleToscaProvider()
- .createPolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
+ .createPolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
LOGGER.debug("<-createPolicyTypes: createdServiceTemplate={}", createdServiceTemplate);
return createdServiceTemplate;
@@ -272,13 +325,13 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors updating policy types
*/
public ToscaServiceTemplate updatePolicyTypes(@NonNull final PfDao dao,
- @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+ @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
synchronized (providerLockObject) {
LOGGER.debug("->updatePolicyTypes: serviceTemplate={}", serviceTemplate);
ToscaServiceTemplate updatedServiceTemplate = new SimpleToscaProvider()
- .updatePolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
+ .updatePolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
LOGGER.debug("<-updatePolicyTypes: updatedServiceTemplate={}", updatedServiceTemplate);
return updatedServiceTemplate;
@@ -295,16 +348,16 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors deleting policy types
*/
public ToscaServiceTemplate deletePolicyType(@NonNull final PfDao dao, @NonNull final String name,
- @NonNull final String version) throws PfModelException {
+ @NonNull final String version) throws PfModelException {
synchronized (providerLockObject) {
LOGGER.debug("->deletePolicyType: name={}, version={}", name, version);
ToscaServiceTemplate deletedServiceTemplate =
- new SimpleToscaProvider().deletePolicyType(dao, new PfConceptKey(name, version)).toAuthorative();
+ new SimpleToscaProvider().deletePolicyType(dao, new PfConceptKey(name, version)).toAuthorative();
LOGGER.debug("<-deletePolicyType: name={}, version={}, deletedServiceTemplate={}", name, version,
- deletedServiceTemplate);
+ deletedServiceTemplate);
return deletedServiceTemplate;
}
}
@@ -319,16 +372,16 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors getting policies
*/
public ToscaServiceTemplate getPolicies(@NonNull final PfDao dao, final String name, final String version)
- throws PfModelException {
+ throws PfModelException {
synchronized (providerLockObject) {
LOGGER.debug("->getPolicies: name={}, version={}", name, version);
ToscaServiceTemplate gotServiceTemplate =
- new SimpleToscaProvider().getPolicies(dao, name, version).toAuthorative();
+ new SimpleToscaProvider().getPolicies(dao, name, version).toAuthorative();
LOGGER.debug("<-getPolicies: name={}, version={}, gotServiceTemplate={}", name, version,
- gotServiceTemplate);
+ gotServiceTemplate);
return gotServiceTemplate;
}
}
@@ -343,7 +396,7 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors getting policies
*/
public List<ToscaPolicy> getPolicyList(@NonNull final PfDao dao, final String name, final String version)
- throws PfModelException {
+ throws PfModelException {
synchronized (providerLockObject) {
LOGGER.debug("->getPolicyList: name={}, version={}", name, version);
@@ -352,7 +405,7 @@ public class AuthorativeToscaProvider {
try {
policyList = asConceptList(new SimpleToscaProvider().getPolicies(dao, name, version).toAuthorative()
- .getToscaTopologyTemplate().getPolicies());
+ .getToscaTopologyTemplate().getPolicies());
} catch (PfModelRuntimeException pfme) {
return handlePfModelRuntimeException(pfme);
}
@@ -371,7 +424,7 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors getting policies
*/
public ToscaServiceTemplate getFilteredPolicies(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter)
- throws PfModelException {
+ throws PfModelException {
synchronized (providerLockObject) {
LOGGER.debug("->getFilteredPolicies: filter={}", filter);
@@ -379,25 +432,25 @@ public class AuthorativeToscaProvider {
SimpleToscaProvider simpleToscaProvider = new SimpleToscaProvider();
final JpaToscaServiceTemplate dbServiceTemplate =
- simpleToscaProvider.getPolicies(dao, filter.getName(), version);
+ simpleToscaProvider.getPolicies(dao, filter.getName(), version);
List<ToscaPolicy> filteredPolicies =
- dbServiceTemplate.getTopologyTemplate().getPolicies().toAuthorativeList();
+ dbServiceTemplate.getTopologyTemplate().getPolicies().toAuthorativeList();
filteredPolicies = filter.filter(filteredPolicies);
if (CollectionUtils.isEmpty(filteredPolicies)) {
throw new PfModelRuntimeException(Response.Status.NOT_FOUND,
- "policies for filter " + filter.toString() + " do not exist");
+ "policies for filter " + filter.toString() + " do not exist");
}
JpaToscaServiceTemplate filteredServiceTemplate = new JpaToscaServiceTemplate();
for (ToscaPolicy policy : filteredPolicies) {
- JpaToscaServiceTemplate cascadedServiceTemplate =
- simpleToscaProvider.getCascadedPolicies(dbServiceTemplate, policy.getName(), policy.getVersion());
+ JpaToscaServiceTemplate cascadedServiceTemplate = simpleToscaProvider
+ .getCascadedPolicies(dbServiceTemplate, policy.getName(), policy.getVersion());
filteredServiceTemplate =
- ToscaServiceTemplateUtils.addFragment(filteredServiceTemplate, cascadedServiceTemplate);
+ ToscaServiceTemplateUtils.addFragment(filteredServiceTemplate, cascadedServiceTemplate);
}
ToscaServiceTemplate returnServiceTemplate = filteredServiceTemplate.toAuthorative();
@@ -416,7 +469,7 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors getting policies
*/
public List<ToscaPolicy> getFilteredPolicyList(@NonNull final PfDao dao, @NonNull final ToscaPolicyFilter filter)
- throws PfModelException {
+ throws PfModelException {
LOGGER.debug("->getFilteredPolicyList: filter={}", filter);
String version = ToscaPolicyFilter.LATEST_VERSION.equals(filter.getVersion()) ? null : filter.getVersion();
@@ -436,13 +489,13 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors creating policies
*/
public ToscaServiceTemplate createPolicies(@NonNull final PfDao dao,
- @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+ @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
synchronized (providerLockObject) {
LOGGER.debug("->createPolicies: serviceTemplate={}", serviceTemplate);
ToscaServiceTemplate createdServiceTemplate = new SimpleToscaProvider()
- .createPolicies(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
+ .createPolicies(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
LOGGER.debug("<-createPolicies: createdServiceTemplate={}", createdServiceTemplate);
return createdServiceTemplate;
@@ -458,13 +511,13 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors updating policies
*/
public ToscaServiceTemplate updatePolicies(@NonNull final PfDao dao,
- @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
+ @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
synchronized (providerLockObject) {
LOGGER.debug("->updatePolicies: serviceTemplate={}", serviceTemplate);
ToscaServiceTemplate updatedServiceTemplate = new SimpleToscaProvider()
- .updatePolicies(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
+ .updatePolicies(dao, new JpaToscaServiceTemplate(serviceTemplate)).toAuthorative();
LOGGER.debug("<-updatePolicies: updatedServiceTemplate={}", updatedServiceTemplate);
return updatedServiceTemplate;
@@ -481,16 +534,16 @@ public class AuthorativeToscaProvider {
* @throws PfModelException on errors deleting policies
*/
public ToscaServiceTemplate deletePolicy(@NonNull final PfDao dao, @NonNull final String name,
- @NonNull final String version) throws PfModelException {
+ @NonNull final String version) throws PfModelException {
synchronized (providerLockObject) {
LOGGER.debug("->deletePolicy: name={}, version={}", name, version);
ToscaServiceTemplate deletedServiceTemplate =
- new SimpleToscaProvider().deletePolicy(dao, new PfConceptKey(name, version)).toAuthorative();
+ new SimpleToscaProvider().deletePolicy(dao, new PfConceptKey(name, version)).toAuthorative();
LOGGER.debug("<-deletePolicy: name={}, version={}, deletedServiceTemplate={}", name, version,
- deletedServiceTemplate);
+ deletedServiceTemplate);
return deletedServiceTemplate;
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java
index 439ec6282..031fceb9a 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java
@@ -47,13 +47,12 @@ import org.yaml.snakeyaml.Yaml;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class ToscaPolicyTypeFilterTest {
- private static final String VERSION_100 = "1.0.0";
-
- private static final String VERSION_000 = "0.0.0";
-
// Logger for this class
private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyTypeFilterTest.class);
+ private static final String VERSION_100 = "1.0.0";
+ private static final String VERSION_000 = "0.0.0";
+
// @formatter:off
private static final String[] policyTypeResourceNames = {
"policytypes/onap.policies.optimization.resource.DistancePolicy.yaml",
@@ -151,11 +150,11 @@ public class ToscaPolicyTypeFilterTest {
// got changed - perhaps we change this test to find a specific name
// to test for vs an index which never remains consistent?
//
- //assertEquals("2.0.0", filteredList.get(18).getVersion());
+ // assertEquals("2.0.0", filteredList.get(18).getVersion());
//
// And now this index changes again??
//
- //assertEquals(VERSION_100, filteredList.get(17).getVersion());
+ // assertEquals(VERSION_100, filteredList.get(17).getVersion());
typeList.get(12).setVersion(VERSION_100);
filteredList = filter.filter(typeList);
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilterTest.java
new file mode 100644
index 000000000..ba72e621b
--- /dev/null
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaServiceTemplateFilterTest.java
@@ -0,0 +1,125 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.authorative.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.util.List;
+import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardYamlCoder;
+import org.onap.policy.models.base.PfKey;
+
+/**
+ * Test of the {@link ToscaServiceTemplateFilter} class.
+ *
+ * @author Liam Fallon (liam.fallon@est.tech)
+ */
+public class ToscaServiceTemplateFilterTest {
+ @Test
+ public void testNullList() {
+ ToscaServiceTemplateFilter filter = ToscaServiceTemplateFilter.builder().build();
+
+ assertThatThrownBy(() -> {
+ filter.filter(null);
+ }).hasMessageMatching("originalList is marked .*on.*ull but is null");
+ }
+
+ @Test
+ public void testFilterNothing() throws CoderException {
+ ToscaServiceTemplates serviceTemplates = new StandardYamlCoder().decode(
+ new File("src/test/resources/servicetemplates/TestServiceTemplates.yaml"), ToscaServiceTemplates.class);
+
+ ToscaServiceTemplateFilter filter = ToscaServiceTemplateFilter.builder().build();
+
+ List<ToscaServiceTemplate> filteredList = filter.filter(serviceTemplates.getServiceTemplates());
+ assertTrue(filteredList.containsAll(serviceTemplates.getServiceTemplates()));
+ }
+
+ @Test
+ public void testFilterLatestVersion() throws CoderException {
+ ToscaServiceTemplates serviceTemplates = new StandardYamlCoder().decode(
+ new File("src/test/resources/servicetemplates/TestServiceTemplates.yaml"), ToscaServiceTemplates.class);
+
+ ToscaServiceTemplateFilter filter =
+ ToscaServiceTemplateFilter.builder().version(ToscaServiceTemplateFilter.LATEST_VERSION).build();
+
+ List<ToscaServiceTemplate> filteredList = filter.filter(serviceTemplates.getServiceTemplates());
+ assertEquals(4, filteredList.size());
+ assertEquals("0.0.0", filteredList.get(0).getVersion());
+ assertEquals("1.2.8", filteredList.get(1).getVersion());
+ assertEquals("1.2.3", filteredList.get(2).getVersion());
+ assertEquals("1.8.3", filteredList.get(3).getVersion());
+
+ filter = ToscaServiceTemplateFilter.builder().version("1.2.3").build();
+ filteredList = filter.filter(serviceTemplates.getServiceTemplates());
+ assertEquals(3, filteredList.size());
+ filter = ToscaServiceTemplateFilter.builder().version(PfKey.NULL_KEY_VERSION).build();
+ filteredList = filter.filter(serviceTemplates.getServiceTemplates());
+ assertEquals(6, filteredList.size());
+
+ serviceTemplates.getServiceTemplates().get(12).setVersion("0.0.0");
+ filteredList = filter.filter(serviceTemplates.getServiceTemplates());
+ assertEquals(7, filteredList.size());
+ assertEquals(PfKey.NULL_KEY_VERSION, filteredList.get(0).getVersion());
+ assertEquals(PfKey.NULL_KEY_VERSION, filteredList.get(6).getVersion());
+ }
+
+ @Test
+ public void testFilterNameVersion() throws CoderException {
+ ToscaServiceTemplates serviceTemplates = new StandardYamlCoder().decode(
+ new File("src/test/resources/servicetemplates/TestServiceTemplates.yaml"), ToscaServiceTemplates.class);
+
+ ToscaServiceTemplateFilter filter = ToscaServiceTemplateFilter.builder().name("name0").build();
+ List<ToscaServiceTemplate> filteredList = filter.filter(serviceTemplates.getServiceTemplates());
+ assertEquals(13, filteredList.size());
+
+ filter = ToscaServiceTemplateFilter.builder().name("not.found").build();
+ filteredList = filter.filter(serviceTemplates.getServiceTemplates());
+ assertEquals(0, filteredList.size());
+
+ filter = ToscaServiceTemplateFilter.builder().name(PfKey.NULL_KEY_NAME).build();
+ filteredList = filter.filter(serviceTemplates.getServiceTemplates());
+ assertEquals(2, filteredList.size());
+
+ filter = ToscaServiceTemplateFilter.builder().version(PfKey.NULL_KEY_VERSION).build();
+ filteredList = filter.filter(serviceTemplates.getServiceTemplates());
+ assertEquals(6, filteredList.size());
+
+ filter = ToscaServiceTemplateFilter.builder().name(PfKey.NULL_KEY_NAME).version(PfKey.NULL_KEY_VERSION).build();
+ filteredList = filter.filter(serviceTemplates.getServiceTemplates());
+ assertEquals(2, filteredList.size());
+
+ filter = ToscaServiceTemplateFilter.builder().name("name2").build();
+ filteredList = filter.filter(serviceTemplates.getServiceTemplates());
+ assertEquals(1, filteredList.size());
+
+ filter = ToscaServiceTemplateFilter.builder().name("name2").version("1.8.3").build();
+ filteredList = filter.filter(serviceTemplates.getServiceTemplates());
+ assertEquals(1, filteredList.size());
+ assertEquals("name2", filteredList.get(0).getName());
+ assertEquals("1.8.3", filteredList.get(0).getVersion());
+ }
+}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderGenericTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderGenericTest.java
index 53e8311ee..dc0115486 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderGenericTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderGenericTest.java
@@ -114,14 +114,14 @@ public class AuthorativeToscaProviderGenericTest {
@Test
public void testCreateGetDelete() throws Exception {
assertThatThrownBy(() -> {
- new AuthorativeToscaProvider().getServiceTemplate(null, null, null);
+ new AuthorativeToscaProvider().getServiceTemplateList(null, null, null);
}).hasMessageMatching(DAO_IS_NULL);
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
assertNotNull(toscaServiceTemplate);
ToscaServiceTemplate createdServiceTemplate =
- new AuthorativeToscaProvider().createServiceTemplate(pfDao, toscaServiceTemplate);
+ new AuthorativeToscaProvider().createServiceTemplate(pfDao, toscaServiceTemplate);
PfConceptKey policyTypeKey = new PfConceptKey(POLICY_NO_VERSION_VERSION1);
@@ -130,14 +130,15 @@ public class AuthorativeToscaProviderGenericTest {
assertEquals(true, beforePolicyType.getName().equals(createdPolicyType.getName()));
assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription()));
- ToscaServiceTemplate gotServiceTemplate = new AuthorativeToscaProvider().getServiceTemplate(pfDao, null, null);
+ List<ToscaServiceTemplate> gotServiceTemplateList =
+ new AuthorativeToscaProvider().getServiceTemplateList(pfDao, null, null);
- ToscaPolicyType gotPolicyType = gotServiceTemplate.getPolicyTypes().get(policyTypeKey.getName());
+ ToscaPolicyType gotPolicyType = gotServiceTemplateList.get(0).getPolicyTypes().get(policyTypeKey.getName());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription()));
List<ToscaPolicyType> gotPolicyTypeList =
- new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_001);
+ new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_001);
assertEquals(2, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
@@ -153,50 +154,49 @@ public class AuthorativeToscaProviderGenericTest {
assertEquals(2, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
- assertThatThrownBy(
- () -> new AuthorativeToscaProvider().getPolicyTypeList(new DefaultPfDao(), POLICY_NO_VERSION, VERSION_001))
- .hasMessageContaining("Policy Framework DAO has not been initialized");
+ assertThatThrownBy(() -> new AuthorativeToscaProvider().getPolicyTypeList(new DefaultPfDao(), POLICY_NO_VERSION,
+ VERSION_001)).hasMessageContaining("Policy Framework DAO has not been initialized");
assertTrue(new AuthorativeToscaProvider().getPolicyTypeList(pfDao, "i.dont.Exist", VERSION_001).isEmpty());
ToscaServiceTemplate deletedServiceTemplate =
- new AuthorativeToscaProvider().deleteServiceTemplate(pfDao, "Dummy", "0.0.1");
+ new AuthorativeToscaProvider().deleteServiceTemplate(pfDao, "Dummy", "0.0.1");
assertEquals(2, deletedServiceTemplate.getPolicyTypes().size());
}
@Test
public void testNullParameters() throws Exception {
- assertThatThrownBy(() -> new AuthorativeToscaProvider().getServiceTemplate(null, null, null))
- .hasMessageMatching("^dao is marked .*on.*ull but is null$");
+ assertThatThrownBy(() -> new AuthorativeToscaProvider().getServiceTemplateList(null, null, null))
+ .hasMessageMatching("^dao is marked .*on.*ull but is null$");
assertThatThrownBy(() -> new AuthorativeToscaProvider().createServiceTemplate(null, null))
- .hasMessageMatching("^dao is marked .*on.*ull but is null$");
+ .hasMessageMatching("^dao is marked .*on.*ull but is null$");
assertThatThrownBy(() -> new AuthorativeToscaProvider().createServiceTemplate(pfDao, null))
- .hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$");
+ .hasMessageMatching("^serviceTemplate is marked .*on.*ull but is null$");
assertThatThrownBy(() -> new AuthorativeToscaProvider().createServiceTemplate(null, new ToscaServiceTemplate()))
- .hasMessageMatching("^dao is marked .*on.*ull but is null$");
+ .hasMessageMatching("^dao is marked .*on.*ull but is null$");
assertThatThrownBy(() -> new AuthorativeToscaProvider().deleteServiceTemplate(null, null, null))
- .hasMessageMatching("^dao is marked .*on.*ull but is null$");
+ .hasMessageMatching("^dao is marked .*on.*ull but is null$");
assertThatThrownBy(() -> new AuthorativeToscaProvider().deleteServiceTemplate(null, null, "0.0.1"))
- .hasMessageMatching("^dao is marked .*on.*ull but is null$");
+ .hasMessageMatching("^dao is marked .*on.*ull but is null$");
assertThatThrownBy(() -> new AuthorativeToscaProvider().deleteServiceTemplate(null, "Dummy", null))
- .hasMessageMatching("^dao is marked .*on.*ull but is null$");
+ .hasMessageMatching("^dao is marked .*on.*ull but is null$");
assertThatThrownBy(() -> new AuthorativeToscaProvider().deleteServiceTemplate(null, "Dummy", "0.0.1"))
- .hasMessageMatching("^dao is marked .*on.*ull but is null$");
+ .hasMessageMatching("^dao is marked .*on.*ull but is null$");
assertThatThrownBy(() -> new AuthorativeToscaProvider().deleteServiceTemplate(pfDao, null, null))
- .hasMessageMatching("^name is marked .*on.*ull but is null$");
+ .hasMessageMatching("^name is marked .*on.*ull but is null$");
assertThatThrownBy(() -> new AuthorativeToscaProvider().deleteServiceTemplate(pfDao, null, "0.0.1"))
- .hasMessageMatching("^name is marked .*on.*ull but is null$");
+ .hasMessageMatching("^name is marked .*on.*ull but is null$");
assertThatThrownBy(() -> new AuthorativeToscaProvider().deleteServiceTemplate(pfDao, "Dummy", null))
- .hasMessageMatching("^version is marked .*on.*ull but is null$");
+ .hasMessageMatching("^version is marked .*on.*ull but is null$");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java
index 7d900ab3a..f66a8e8a5 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java
@@ -43,6 +43,7 @@ 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.authorative.concepts.ToscaDataType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -410,8 +411,8 @@ public class AuthorativeToscaProviderPolicyTest {
@Test
public void testEntityMaps() throws CoderException, PfModelException {
- Object yamlObject = new Yaml().load(
- ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.tcagen2.yaml"));
+ Object yamlObject =
+ new Yaml().load(ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.tcagen2.yaml"));
String yamlAsJsonString = new StandardCoder().encode(yamlObject);
ToscaServiceTemplate toscaServiceTemplatePolicyType =
@@ -449,11 +450,19 @@ public class AuthorativeToscaProviderPolicyTest {
assertThatThrownBy(() -> {
createdServiceTemplate.getToscaTopologyTemplate().getPoliciesAsMap();
}).hasMessageContaining("list of map of entities contains more than one entity with key");
+
+
+ ToscaDataType duplDataType = toscaServiceTemplatePolicyType.getDataTypes().values().iterator().next();
+ toscaServiceTemplatePolicyType.getDataTypes().put("DuplicateDataType", duplDataType);
+
+ assertThatThrownBy(() -> {
+ toscaServiceTemplatePolicyType.getDataTypesAsMap();
+ }).hasMessageContaining("list of map of entities contains more than one entity with key");
}
private void createPolicyTypes() throws CoderException, PfModelException {
- Object yamlObject = new Yaml().load(
- ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.tcagen2.yaml"));
+ Object yamlObject =
+ new Yaml().load(ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.tcagen2.yaml"));
String yamlAsJsonString = new StandardCoder().encode(yamlObject);
ToscaServiceTemplate toscaServiceTemplatePolicyType =
diff --git a/models-tosca/src/test/resources/servicetemplates/TestServiceTemplates.yaml b/models-tosca/src/test/resources/servicetemplates/TestServiceTemplates.yaml
new file mode 100644
index 000000000..d2aea5819
--- /dev/null
+++ b/models-tosca/src/test/resources/servicetemplates/TestServiceTemplates.yaml
@@ -0,0 +1,185 @@
+service_templates:
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ policy_types:
+ onap.policies.Policytype0:
+ derived_from: tosca.policies.Root
+ version: 1.0.0
+ name: onap.policies.Policytype0
+ description: a policy type
+ properties:
+ policytype0.property0:
+ type: onap.datatypes.datatype0
+ description: a property
+ required: true
+ data_types:
+ onap.datatypes.datatype0:
+ derived_from: tosca.datatypes.Root
+ properties:
+ domain0:
+ type: string
+ required: true
+ description: Domain name
+ default: domainDefault
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ policy_types:
+ onap.policies.Policytype1:
+ derived_from: tosca.policies.Root
+ version: 1.0.0
+ name: onap.policies.Policytype1
+ description: a policy type
+ properties:
+ policytype1.property1:
+ type: onap.datatypes.datatype1
+ description: a property
+ required: true
+ data_types:
+ onap.datatypes.datatype1:
+ derived_from: tosca.datatypes.Root
+ properties:
+ domain1:
+ type: string
+ required: true
+ description: Domain name
+ default: domainDefault
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ name: name0
+ policy_types:
+ onap.policies.Policytype2:
+ derived_from: tosca.policies.Root
+ version: 1.0.0
+ name: onap.policies.Policytype2
+ description: a policy type
+ properties:
+ policytype2.property2:
+ type: onap.datatypes.datatype2
+ description: a property
+ required: true
+ data_types:
+ onap.datatypes.datatype2:
+ derived_from: tosca.datatypes.Root
+ properties:
+ domain2:
+ type: string
+ required: true
+ description: Domain name
+ default: domainDefault
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ name: name0
+ policy_types:
+ onap.policies.Policytype3:
+ derived_from: tosca.policies.Root
+ version: 1.0.0
+ name: onap.policies.Policytype3
+ description: a policy type
+ properties:
+ policytype3.property3:
+ type: onap.datatypes.datatype3
+ description: a property
+ required: true
+ data_types:
+ onap.datatypes.datatype3:
+ derived_from: tosca.datatypes.Root
+ properties:
+ domain3:
+ type: string
+ required: true
+ description: Domain name
+ default: domainDefault
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ name: name0
+ policy_types:
+ onap.policies.Policytype4:
+ derived_from: tosca.policies.Root
+ version: 1.0.0
+ name: onap.policies.Policytype4
+ description: a policy type
+ properties:
+ policytype4.property4:
+ type: onap.datatypes.datatype4
+ description: a property
+ required: true
+ data_types:
+ onap.datatypes.datatype4:
+ derived_from: tosca.datatypes.Root
+ properties:
+ domain4:
+ type: string
+ required: true
+ description: Domain name
+ default: domainDefault
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ name: name0
+ vesion: 1.2.3
+ policy_types:
+ onap.policies.Policytype5:
+ derived_from: tosca.policies.Root
+ version: 1.0.0
+ name: onap.policies.Policytype5
+ description: a policy type
+ properties:
+ policytype5.property5:
+ type: onap.datatypes.datatype5
+ description: a property
+ required: true
+ data_types:
+ onap.datatypes.datatype5:
+ derived_from: tosca.datatypes.Root
+ properties:
+ domain5:
+ type: string
+ required: true
+ description: Domain name
+ default: domainDefault
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ name: name0
+ version: 1.2.3
+ policy_types:
+ onap.policies.Policytype6:
+ derived_from: tosca.policies.Root
+ version: 1.0.0
+ name: onap.policies.Policytype6
+ description: a policy type
+ properties:
+ policytype6.property6:
+ type: onap.datatypes.datatype6
+ description: a property
+ required: true
+ data_types:
+ onap.datatypes.datatype6:
+ derived_from: tosca.datatypes.Root
+ properties:
+ domain6:
+ type: string
+ required: true
+ description: Domain name
+ default: domainDefault
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ name: name0
+ version: 1.2.3
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ name: name0
+ version: 1.2.4
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ name: name0
+ version: 1.2.5
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ name: name0
+ version: 1.2.6
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ name: name0
+ version: 1.2.7
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ name: name0
+ version: 1.2.8
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ name: name0
+ version: 1.2.8
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ name: name0
+ version: 1.2.8
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ name: name1
+ version: 1.2.3
+- tosca_definitions_version: tosca_simple_yaml_1_1_0
+ name: name2
+ version: 1.8.3