Store policy type version in policy before DB write 80/87380/1
authorliamfallon <liam.fallon@est.tech>
Thu, 9 May 2019 15:54:41 +0000 (15:54 +0000)
committerliamfallon <liam.fallon@est.tech>
Thu, 9 May 2019 15:54:41 +0000 (15:54 +0000)
The policy type version must be updated on a policy before it is stored
to the database, otherwise the database value is incorrect.

Issue-ID: POLICY-1738
Change-Id: I0a7f2da3837497dd999141f40466d6507c26159b
Signed-off-by: liamfallon <liam.fallon@est.tech>
models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java
models-tosca/src/main/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProvider.java

index a855d5d..7fa21b0 100644 (file)
@@ -86,6 +86,8 @@ public class PolicyPersistenceTest {
      */
     @Before
     public void setupParameters() throws PfModelException, CoderException {
+        // H2, use "org.mariadb.jdbc.Driver" and "jdbc:mariadb://localhost:3306/policy" for locally installed MariaDB
+
         PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
         parameters.setDatabaseDriver("org.h2.Driver");
         parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
index 81a41aa..761a47c 100644 (file)
@@ -195,7 +195,6 @@ public class SimpleToscaProvider {
 
         for (JpaToscaPolicy policy : serviceTemplate.getTopologyTemplate().getPolicies().getAll(null)) {
             verifyPolicyTypeForPolicy(dao, policy);
-
             dao.create(policy);
         }
 
@@ -226,6 +225,7 @@ public class SimpleToscaProvider {
         ToscaUtils.assertPoliciesExist(serviceTemplate);
 
         for (JpaToscaPolicy policy : serviceTemplate.getTopologyTemplate().getPolicies().getAll(null)) {
+            verifyPolicyTypeForPolicy(dao, policy);
             dao.update(policy);
         }
 
@@ -288,6 +288,7 @@ public class SimpleToscaProvider {
 
         if (PfKey.NULL_KEY_VERSION.equals(policyTypeKey.getVersion())) {
             policyType = getLatestPolicyTypeVersion(dao, policyTypeKey.getName());
+            policy.getType().setVersion(policyType.getKey().getVersion());
         } else {
             policyType = dao.get(JpaToscaPolicyType.class, policyTypeKey);
         }