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 --- .../impl/DatabasePolicyModelsProviderTest.java | 10 +++++----- .../models/provider/impl/DummyBadProviderImpl.java | 20 +++++++++++--------- .../impl/DummyPolicyModelsProviderSubImpl.java | 6 +++--- .../provider/impl/DummyPolicyModelsProviderTest.java | 12 ++++++------ .../models/provider/impl/PolicyPersistenceTest.java | 10 +++++----- .../provider/impl/PolicyToscaPersistenceTest.java | 10 +++++----- 6 files changed, 35 insertions(+), 33 deletions(-) (limited to 'models-provider/src/test/java') diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java index 1631d9bb1..335233476 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java @@ -35,7 +35,7 @@ import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.provider.PolicyModelsProviderParameters; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; -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; @@ -225,11 +225,11 @@ public class DatabasePolicyModelsProviderTest { }).hasMessage("policy type not found: NULL:0.0.0"); assertThatThrownBy(() -> { - databaseProvider.createPolicyTypes(new ToscaServiceTemplate()); + databaseProvider.createPolicyTypes(new JpaToscaServiceTemplate()); }).hasMessage("no policy types specified on service template"); assertThatThrownBy(() -> { - databaseProvider.updatePolicyTypes(new ToscaServiceTemplate()); + databaseProvider.updatePolicyTypes(new JpaToscaServiceTemplate()); }).hasMessage("no policy types specified on service template"); assertThatThrownBy(() -> { @@ -241,11 +241,11 @@ public class DatabasePolicyModelsProviderTest { }).hasMessage("policy not found: NULL:0.0.0"); assertThatThrownBy(() -> { - databaseProvider.createPolicies(new ToscaServiceTemplate()); + databaseProvider.createPolicies(new JpaToscaServiceTemplate()); }).hasMessage("topology template not specified on service template"); assertThatThrownBy(() -> { - databaseProvider.updatePolicies(new ToscaServiceTemplate()); + databaseProvider.updatePolicies(new JpaToscaServiceTemplate()); }).hasMessage("topology template not specified on service template"); assertThatThrownBy(() -> { diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java index f8602e65c..2ee210c13 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyBadProviderImpl.java @@ -34,7 +34,7 @@ import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; -import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; /** * Dummy implementation of {@link PolicyModelsProvider} with bad constructor. @@ -53,44 +53,46 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { public void init() throws PfModelException {} @Override - public ToscaServiceTemplate getPolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException { + public JpaToscaServiceTemplate getPolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException { return null; } @Override - public ToscaServiceTemplate createPolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate) + public JpaToscaServiceTemplate createPolicyTypes(@NonNull JpaToscaServiceTemplate serviceTemplate) throws PfModelException { return null; } @Override - public ToscaServiceTemplate updatePolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate) + public JpaToscaServiceTemplate updatePolicyTypes(@NonNull JpaToscaServiceTemplate serviceTemplate) throws PfModelException { return null; } @Override - public ToscaServiceTemplate deletePolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException { + public JpaToscaServiceTemplate deletePolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException { return null; } @Override - public ToscaServiceTemplate getPolicies(@NonNull PfConceptKey policyKey) throws PfModelException { + public JpaToscaServiceTemplate getPolicies(@NonNull PfConceptKey policyKey) throws PfModelException { return null; } @Override - public ToscaServiceTemplate createPolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException { + public JpaToscaServiceTemplate createPolicies(@NonNull JpaToscaServiceTemplate serviceTemplate) + throws PfModelException { return null; } @Override - public ToscaServiceTemplate updatePolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException { + public JpaToscaServiceTemplate updatePolicies(@NonNull JpaToscaServiceTemplate serviceTemplate) + throws PfModelException { return null; } @Override - public ToscaServiceTemplate deletePolicies(@NonNull PfConceptKey policyKey) throws PfModelException { + public JpaToscaServiceTemplate deletePolicies(@NonNull PfConceptKey policyKey) throws PfModelException { return null; } diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderSubImpl.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderSubImpl.java index 9b68dd037..66c7762f8 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderSubImpl.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderSubImpl.java @@ -23,7 +23,7 @@ package org.onap.policy.models.provider.impl; import lombok.NonNull; import org.onap.policy.models.provider.PolicyModelsProviderParameters; -import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; /** * Sub class to check getDummyResponse() method in base class. @@ -40,11 +40,11 @@ public class DummyPolicyModelsProviderSubImpl extends DummyPolicyModelsProviderI super(parameters); } - public ToscaServiceTemplate getBadDummyResponse1() { + public JpaToscaServiceTemplate getBadDummyResponse1() { return super.getDummyResponse("/i/dont/exist"); } - public ToscaServiceTemplate getBadDummyResponse2() { + public JpaToscaServiceTemplate getBadDummyResponse2() { return super.getDummyResponse(null); } } diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java index de61dc0ab..af76edbcb 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java @@ -33,7 +33,7 @@ import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.provider.PolicyModelsProviderParameters; import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput; import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy; -import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate; +import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate; /** * Test the dummy models provider implementation. @@ -53,7 +53,7 @@ public class DummyPolicyModelsProviderTest { dummyProvider.init(); - ToscaServiceTemplate serviceTemplate = dummyProvider.getPolicies(new PfConceptKey()); + JpaToscaServiceTemplate serviceTemplate = dummyProvider.getPolicies(new PfConceptKey()); assertNotNull(serviceTemplate); assertEquals("onap.vcpe.tca:1.0.0", serviceTemplate.getTopologyTemplate().getPolicies().get("onap.vcpe.tca").getId()); @@ -72,13 +72,13 @@ public class DummyPolicyModelsProviderTest { dummyProvider.init(); assertNotNull(dummyProvider.getPolicyTypes(new PfConceptKey())); - assertNotNull(dummyProvider.createPolicyTypes(new ToscaServiceTemplate())); - assertNotNull(dummyProvider.updatePolicyTypes(new ToscaServiceTemplate())); + assertNotNull(dummyProvider.createPolicyTypes(new JpaToscaServiceTemplate())); + assertNotNull(dummyProvider.updatePolicyTypes(new JpaToscaServiceTemplate())); assertNotNull(dummyProvider.deletePolicyTypes(new PfConceptKey())); assertNotNull(dummyProvider.getPolicies(new PfConceptKey())); - assertNotNull(dummyProvider.createPolicies(new ToscaServiceTemplate())); - assertNotNull(dummyProvider.updatePolicies(new ToscaServiceTemplate())); + assertNotNull(dummyProvider.createPolicies(new JpaToscaServiceTemplate())); + assertNotNull(dummyProvider.updatePolicies(new JpaToscaServiceTemplate())); assertNotNull(dummyProvider.deletePolicies(new PfConceptKey())); assertNotNull(dummyProvider.getOperationalPolicy("policy_id")); diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java index de299772f..e0aba8a9e 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java @@ -42,8 +42,8 @@ import org.onap.policy.models.base.PfValidationResult; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.provider.PolicyModelsProviderParameters; -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; @@ -141,7 +141,7 @@ public class PolicyPersistenceTest { * @throws Exception any exception thrown */ public void testJsonStringPolicyPersistence(@NonNull final String policyString) throws Exception { - ToscaServiceTemplate serviceTemplate = gson.fromJson(policyString, ToscaServiceTemplate.class); + JpaToscaServiceTemplate serviceTemplate = gson.fromJson(policyString, JpaToscaServiceTemplate.class); assertNotNull(serviceTemplate); LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString()); @@ -150,8 +150,8 @@ public class PolicyPersistenceTest { databaseProvider.createPolicies(serviceTemplate); for (PfConceptKey policyKey : serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().keySet()) { - ToscaPolicy incomingPolicy = serviceTemplate.getTopologyTemplate().getPolicies().get(policyKey); - ToscaPolicy databasePolicy = + JpaToscaPolicy incomingPolicy = serviceTemplate.getTopologyTemplate().getPolicies().get(policyKey); + JpaToscaPolicy databasePolicy = databaseProvider.getPolicies(policyKey).getTopologyTemplate().getPolicies().get(policyKey); assertEquals(incomingPolicy, databasePolicy); } diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java index a4b1dcd03..bd85358b3 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java @@ -42,8 +42,8 @@ import org.onap.policy.models.base.PfValidationResult; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.provider.PolicyModelsProviderParameters; -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; @@ -141,7 +141,7 @@ public class PolicyToscaPersistenceTest { * @throws Exception any exception thrown */ public void testJsonStringPolicyPersistence(@NonNull final String policyString) throws Exception { - ToscaServiceTemplate serviceTemplate = gson.fromJson(policyString, ToscaServiceTemplate.class); + JpaToscaServiceTemplate serviceTemplate = gson.fromJson(policyString, JpaToscaServiceTemplate.class); assertNotNull(serviceTemplate); LOGGER.info(serviceTemplate.validate(new PfValidationResult()).toString()); @@ -150,8 +150,8 @@ public class PolicyToscaPersistenceTest { databaseProvider.createPolicies(serviceTemplate); for (PfConceptKey policyKey : serviceTemplate.getTopologyTemplate().getPolicies().getConceptMap().keySet()) { - ToscaPolicy incomingPolicy = serviceTemplate.getTopologyTemplate().getPolicies().get(policyKey); - ToscaPolicy databasePolicy = + JpaToscaPolicy incomingPolicy = serviceTemplate.getTopologyTemplate().getPolicies().get(policyKey); + JpaToscaPolicy databasePolicy = databaseProvider.getPolicies(policyKey).getTopologyTemplate().getPolicies().get(policyKey); assertEquals(incomingPolicy, databasePolicy); } -- cgit 1.2.3-korg