aboutsummaryrefslogtreecommitdiffstats
path: root/models-tosca/src
diff options
context:
space:
mode:
Diffstat (limited to 'models-tosca/src')
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java71
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/utils/ToscaUtils.java5
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java2
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java4
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java27
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java2
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java35
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java28
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java1
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java23
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java2
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java6
12 files changed, 187 insertions, 19 deletions
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 ef8ac05ec..81a41aa05 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
@@ -20,15 +20,21 @@
package org.onap.policy.models.tosca.simple.provider;
+import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import javax.ws.rs.core.Response;
+
import lombok.NonNull;
import org.onap.policy.models.base.PfConcept;
+import org.onap.policy.models.base.PfConceptFilter;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
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.JpaToscaPolicies;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
@@ -37,6 +43,8 @@ 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;
/**
* This class provides the provision of information on TOSCA concepts in the database to callers.
@@ -44,6 +52,8 @@ import org.onap.policy.models.tosca.utils.ToscaUtils;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class SimpleToscaProvider {
+ private static final Logger LOGGER = LoggerFactory.getLogger(SimpleToscaProvider.class);
+
/**
* Get policy types.
*
@@ -184,6 +194,8 @@ public class SimpleToscaProvider {
ToscaUtils.assertPoliciesExist(serviceTemplate);
for (JpaToscaPolicy policy : serviceTemplate.getTopologyTemplate().getPolicies().getAll(null)) {
+ verifyPolicyTypeForPolicy(dao, policy);
+
dao.create(policy);
}
@@ -262,4 +274,63 @@ public class SimpleToscaProvider {
return conceptMap;
}
+
+ /**
+ * Verify the policy type for a policy exists.
+ *
+ * @param dao the DAO to use to access policy types in the database
+ * @param policy the policy to check the policy type for
+ */
+ private void verifyPolicyTypeForPolicy(final PfDao dao, final JpaToscaPolicy policy) {
+ PfConceptKey policyTypeKey = policy.getType();
+
+ JpaToscaPolicyType policyType = null;
+
+ if (PfKey.NULL_KEY_VERSION.equals(policyTypeKey.getVersion())) {
+ policyType = getLatestPolicyTypeVersion(dao, policyTypeKey.getName());
+ } else {
+ policyType = dao.get(JpaToscaPolicyType.class, policyTypeKey);
+ }
+
+ if (policyType == null) {
+ String errorMessage =
+ "policy type " + policyTypeKey.getId() + " for policy " + policy.getId() + " does not exist";
+ LOGGER.warn(errorMessage);
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ }
+ }
+
+ /**
+ * Get the latest version of the policy type for the given policy type name.
+ *
+ * @param dao the DAO to use to access policy types in the database
+ * @param policyTypeName the name of the policy type
+ * @return the latest policy type
+ */
+ private JpaToscaPolicyType getLatestPolicyTypeVersion(final PfDao dao, final String policyTypeName) {
+ // Policy type version is not specified, get the latest version from the database
+ List<JpaToscaPolicyType> jpaPolicyTypeList =
+ dao.getFiltered(JpaToscaPolicyType.class, policyTypeName, null);
+
+ if (jpaPolicyTypeList.isEmpty()) {
+ return null;
+ }
+
+ // Create a filter to get the latest version of the policy type
+ PfConceptFilter pfConceptFilter = PfConceptFilter.builder().version(PfConceptFilter.LATEST_VERSION).build();
+
+ // FIlter the returned policy type list
+ List<PfConcept> policyTypeKeyList = new ArrayList<>(jpaPolicyTypeList);
+ List<PfConcept> filterdPolicyTypeList = pfConceptFilter.filter(policyTypeKeyList);
+
+ // We should have one and only one returned entry
+ if (filterdPolicyTypeList.size() != 1 ) {
+ String errorMessage =
+ "search for lates policy type " + policyTypeName + " returned more than one entry";
+ LOGGER.warn(errorMessage);
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
+ }
+
+ return (JpaToscaPolicyType) filterdPolicyTypeList.get(0);
+ }
}
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 93333c4e3..a73fb85e9 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
@@ -38,8 +38,7 @@ public final class ToscaUtils {
/**
* Private constructor to prevent subclassing.
*/
- private ToscaUtils() {
- }
+ private ToscaUtils() {}
/**
* Check if policy types have been specified is initialized.
@@ -80,6 +79,4 @@ public final class ToscaUtils {
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
}
}
-
-
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java
index f7c9c7ef0..cba3fe591 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java
@@ -211,7 +211,7 @@ public class ToscaPolicyFilterTest {
filter = ToscaPolicyFilter.builder().type("onap.policies.monitoring.cdap.tca.hi.lo.app").build();
filteredList = filter.filter(policyList);
- assertEquals(2, filteredList.size());
+ assertEquals(3, filteredList.size());
filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.NonOperational").build();
filteredList = filter.filter(policyList);
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 12d81ed53..e0143e676 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
@@ -63,7 +63,7 @@ public class ToscaPolicyTypeFilterTest {
"policytypes/onap.policies.optimization.SubscriberPolicy.yaml",
"policytypes/onap.policies.optimization.Vim_fit.yaml",
"policytypes/onap.policies.optimization.VnfPolicy.yaml",
- "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.yaml"
+ "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"
};
// @formatter:on
@@ -152,7 +152,7 @@ public class ToscaPolicyTypeFilterTest {
List<ToscaPolicyType> filteredList = filter.filter(typeList);
assertEquals(2, filteredList.size());
- filter = ToscaPolicyTypeFilter.builder().name("onap.policy.monitoring.cdap.tca.hi.lo.app").build();
+ filter = ToscaPolicyTypeFilter.builder().name("onap.policies.monitoring.cdap.tca.hi.lo.app").build();
filteredList = filter.filter(typeList);
assertEquals(1, filteredList.size());
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 5ad314ae6..a7f3761a5 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
@@ -33,6 +33,7 @@ import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
@@ -45,6 +46,7 @@ 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;
import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
+import org.yaml.snakeyaml.Yaml;
/**
* Test of the {@link AuthorativeToscaProvider} class.
@@ -75,7 +77,7 @@ public class AuthorativeToscaProviderPolicyTest {
jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, "org.h2.Driver");
jdbcProperties.setProperty(PersistenceUnitProperties.JDBC_URL, "jdbc:h2:mem:testdb");
- daoParameters.setJdbcProperties(jdbcProperties );
+ daoParameters.setJdbcProperties(jdbcProperties);
pfDao = new PfDaoFactory().createPfDao(daoParameters);
pfDao.init(daoParameters);
@@ -104,6 +106,8 @@ public class AuthorativeToscaProviderPolicyTest {
new AuthorativeToscaProvider().getPolicyList(null, null, null);
}).hasMessage("dao is marked @NonNull but is null");
+ createPolicyTypes();
+
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
@@ -176,6 +180,8 @@ public class AuthorativeToscaProviderPolicyTest {
new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, null);
}).hasMessage("filter is marked @NonNull but is null");
+ createPolicyTypes();
+
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
@@ -250,6 +256,8 @@ public class AuthorativeToscaProviderPolicyTest {
new AuthorativeToscaProvider().createPolicies(pfDao, null);
}).hasMessage("serviceTemplate is marked @NonNull but is null");
+ createPolicyTypes();
+
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
@@ -268,7 +276,6 @@ public class AuthorativeToscaProviderPolicyTest {
assertTrue(beforePolicy.getType().equals(createdPolicy.getType()));
}
-
@Test
public void testPolicyUpdate() throws Exception {
assertThatThrownBy(() -> {
@@ -287,6 +294,8 @@ public class AuthorativeToscaProviderPolicyTest {
new AuthorativeToscaProvider().updatePolicies(pfDao, null);
}).hasMessage("serviceTemplate is marked @NonNull but is null");
+ createPolicyTypes();
+
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
@@ -343,6 +352,8 @@ public class AuthorativeToscaProviderPolicyTest {
new AuthorativeToscaProvider().deletePolicy(pfDao, "name", null);
}).hasMessage("version is marked @NonNull but is null");
+ createPolicyTypes();
+
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
@@ -396,4 +407,16 @@ public class AuthorativeToscaProviderPolicyTest {
new AuthorativeToscaProvider().createPolicies(pfDao, testServiceTemplate);
}).hasMessage("An incoming list of concepts must have at least one entry");
}
+
+ private void createPolicyTypes() throws CoderException, PfModelException {
+ Object yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"));
+ String yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ ToscaServiceTemplate toscaServiceTemplatePolicyType =
+ standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);
+ }
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java
index a4458a874..b44853428 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java
@@ -82,7 +82,7 @@ public class ToscaServiceTemplateMappingTest {
try {
Yaml yaml = new Yaml();
String inputYaml = ResourceUtils.getResourceAsString(
- "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.yaml");
+ "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml");
Object yamlObject = yaml.load(inputYaml);
String yamlAsJsonString = standardCoder.encode(yamlObject);
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java
index 71254ec6f..6ddf1aeeb 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java
@@ -31,15 +31,20 @@ import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.models.base.PfModelException;
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.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider;
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.yaml.snakeyaml.Yaml;
/**
* Test the {@link LegacyProvider} class for legacy guard policies.
@@ -108,6 +113,8 @@ public class LegacyProvider4LegacyGuardTest {
new LegacyProvider().getGuardPolicy(pfDao, "I Dont Exist");
}).hasMessage("no policy found for policy ID: I Dont Exist");
+ createPolicyTypes();
+
LegacyGuardPolicyInput originalGip = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"),
LegacyGuardPolicyInput.class);
@@ -148,6 +155,8 @@ public class LegacyProvider4LegacyGuardTest {
new LegacyProvider().createGuardPolicy(pfDao, null);
}).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
+ createPolicyTypes();
+
LegacyGuardPolicyInput originalGip = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"),
LegacyGuardPolicyInput.class);
@@ -174,7 +183,6 @@ public class LegacyProvider4LegacyGuardTest {
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
}
-
@Test
public void testPolicyUpdate() throws Exception {
assertThatThrownBy(() -> {
@@ -193,6 +201,8 @@ public class LegacyProvider4LegacyGuardTest {
new LegacyProvider().updateGuardPolicy(pfDao, new LegacyGuardPolicyInput());
}).hasMessage("policy type for guard policy \"null\" unknown");
+ createPolicyTypes();
+
LegacyGuardPolicyInput originalGip = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"),
LegacyGuardPolicyInput.class);
@@ -246,6 +256,8 @@ public class LegacyProvider4LegacyGuardTest {
new LegacyProvider().deleteGuardPolicy(pfDao, "I Dont Exist");
}).hasMessage("no policy found for policy ID: I Dont Exist");
+ createPolicyTypes();
+
LegacyGuardPolicyInput originalGip = standardCoder.decode(
ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"),
LegacyGuardPolicyInput.class);
@@ -294,4 +306,25 @@ public class LegacyProvider4LegacyGuardTest {
new LegacyProvider().getGuardPolicy(pfDao, originalGip.getPolicyId());
}).hasMessage("no policy found for policy ID: guard.frequency.scaleout");
}
+
+ private void createPolicyTypes() throws CoderException, PfModelException {
+ Object yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.guard.FrequencyLimiter.yaml"));
+ String yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ ToscaServiceTemplate toscaServiceTemplatePolicyType =
+ standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);
+
+ yamlObject = new Yaml()
+ .load(ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.guard.Blacklist.yaml"));
+ yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ toscaServiceTemplatePolicyType = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);
+ }
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java
index c018aae7b..7ab5c581e 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java
@@ -30,13 +30,18 @@ import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
+import org.onap.policy.models.base.PfModelException;
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.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider;
import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
+import org.yaml.snakeyaml.Yaml;
/**
* Test the {@link LegacyProvider} class for legacy operational policies.
@@ -104,6 +109,8 @@ public class LegacyProvider4LegacyOperationalTest {
new LegacyProvider().getOperationalPolicy(pfDao, "I Dont Exist");
}).hasMessage("no policy found for policy ID: I Dont Exist");
+ createPolicyTypes();
+
LegacyOperationalPolicy originalLop =
standardCoder.decode(ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"),
LegacyOperationalPolicy.class);
@@ -142,6 +149,8 @@ public class LegacyProvider4LegacyOperationalTest {
new LegacyProvider().createOperationalPolicy(pfDao, null);
}).hasMessage("legacyOperationalPolicy is marked @NonNull but is null");
+ createPolicyTypes();
+
LegacyOperationalPolicy originalLop =
standardCoder.decode(ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"),
LegacyOperationalPolicy.class);
@@ -162,7 +171,6 @@ public class LegacyProvider4LegacyOperationalTest {
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
}
-
@Test
public void testPolicyUpdate() throws Exception {
assertThatThrownBy(() -> {
@@ -181,6 +189,8 @@ public class LegacyProvider4LegacyOperationalTest {
new LegacyProvider().updateOperationalPolicy(pfDao, new LegacyOperationalPolicy());
}).hasMessage("no policy found for policy ID: null");
+ createPolicyTypes();
+
LegacyOperationalPolicy originalLop =
standardCoder.decode(ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"),
LegacyOperationalPolicy.class);
@@ -203,7 +213,6 @@ public class LegacyProvider4LegacyOperationalTest {
assertEquals("Some New Content", gotUpdatedLop.getContent());
}
-
@Test
public void testPoliciesDelete() throws Exception {
assertThatThrownBy(() -> {
@@ -212,17 +221,19 @@ public class LegacyProvider4LegacyOperationalTest {
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(null, "");
+
}).hasMessage("dao is marked @NonNull but is null");
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(pfDao, null);
}).hasMessage("policyId is marked @NonNull but is null");
-
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(pfDao, "I Dont Exist");
}).hasMessage("no policy found for policy ID: I Dont Exist");
+ createPolicyTypes();
+
LegacyOperationalPolicy originalLop =
standardCoder.decode(ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"),
LegacyOperationalPolicy.class);
@@ -260,6 +271,17 @@ public class LegacyProvider4LegacyOperationalTest {
assertThatThrownBy(() -> {
new LegacyProvider().getOperationalPolicy(pfDao, originalLop.getPolicyId());
}).hasMessage("no policy found for policy ID: operational.restart");
+ }
+
+ private void createPolicyTypes() throws CoderException, PfModelException {
+ Object yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.controlloop.Operational.yaml"));
+ String yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ ToscaServiceTemplate toscaServiceTemplatePolicyType =
+ standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+ assertNotNull(toscaServiceTemplatePolicyType);
+ new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);
}
}
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
index ae38ab916..924cdab53 100644
--- 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
@@ -129,7 +129,6 @@ public class JpaToscaPolicyTest {
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);
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 1f582cf84..4d71d0ddd 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
@@ -32,6 +32,7 @@ import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
@@ -41,9 +42,11 @@ 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.ToscaServiceTemplate;
+import org.onap.policy.models.tosca.authorative.provider.AuthorativeToscaProvider;
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.yaml.snakeyaml.Yaml;
/**
* Test the {@link SimpleToscaProvider} class.
@@ -99,6 +102,8 @@ public class SimpleToscaProviderTest {
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
+ createPolicyTypes();
+
JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
@@ -124,6 +129,8 @@ public class SimpleToscaProviderTest {
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
+ createPolicyTypes();
+
JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
@@ -140,6 +147,8 @@ public class SimpleToscaProviderTest {
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
+ createPolicyTypes();
+
JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
@@ -156,6 +165,8 @@ public class SimpleToscaProviderTest {
ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
ToscaServiceTemplate.class);
+ createPolicyTypes();
+
JpaToscaServiceTemplate originalServiceTemplate = new JpaToscaServiceTemplate();
originalServiceTemplate.fromAuthorative(toscaServiceTemplate);
@@ -288,4 +299,16 @@ public class SimpleToscaProviderTest {
new SimpleToscaProvider().deletePolicy(pfDao, null);
}).hasMessage("policyKey is marked @NonNull but is null");
}
+
+ private void createPolicyTypes() throws CoderException, PfModelException {
+ Object yamlObject = new Yaml().load(
+ ResourceUtils.getResourceAsString("policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml"));
+ String yamlAsJsonString = new StandardCoder().encode(yamlObject);
+
+ ToscaServiceTemplate toscaServiceTemplatePolicyType =
+ standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
+
+ assertNotNull(toscaServiceTemplatePolicyType);
+ new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplatePolicyType);
+ }
}
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 9d9ee608d..f05e2e6ef 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
@@ -297,7 +297,7 @@ public class MonitoringPolicySerializationTest {
JsonObject policy = policiesJsonArray.iterator().next().getAsJsonObject();
assertNotNull(policy.get("onap.vfirewall.tca"));
JsonObject policyVal = policy.get("onap.vfirewall.tca").getAsJsonObject();
- assertEquals("onap.policy.monitoring.cdap.tca.hi.lo.app", policyVal.get("type").getAsString());
+ assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", policyVal.get("type").getAsString());
assertEquals("1.0.0", policyVal.get("version").getAsString());
assertEquals("onap.vfirewall.tca", policyVal.get("metadata").getAsJsonObject().get("policy-id")
.getAsString());
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 569e1ad41..0e053f182 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
@@ -57,7 +57,7 @@ public class MonitoringPolicyTypeSerializationTest {
private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringPolicyTypeSerializationTest.class);
- private static final String MONITORING_TCA_YAML = "policytypes/onap.policy.monitoring.cdap.tca.hi.lo.app.yaml";
+ private static final String MONITORING_TCA_YAML = "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml";
private static final String MONITORING_COLLECTORS_YAML =
"policytypes/onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server.yaml";
@@ -155,13 +155,13 @@ public class MonitoringPolicyTypeSerializationTest {
firstPolicyType.getValue().getDescription());
Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next();
- assertEquals("onap.policy.monitoring.cdap.tca.hi.lo.app", secondPolicyType.getKey().getName());
+ assertEquals("onap.policies.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);
JpaToscaProperty property = secondPolicyType.getValue().getProperties().values().iterator().next();
- assertEquals("onap.policy.monitoring.cdap.tca.hi.lo.app", property.getKey().getParentKeyName());
+ assertEquals("onap.policies.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());