From 8054d6dcff521c460954b9e9e203faf65924bfee Mon Sep 17 00:00:00 2001 From: liamfallon Date: Tue, 2 Apr 2019 23:32:32 +0000 Subject: Add persistence for PDP concepts This review adds the JPA annotations to PDP group/subgroup and PDP for persisting to the database. It also updates the Provider API as requested by other team members. Issue-ID: POLICY-1095 Change-Id: I8188afb763849ede9680f3751b464d9d76c27196 Signed-off-by: liamfallon --- .../impl/DatabasePolicyModelsProviderTest.java | 16 +++++++----- .../models/provider/impl/DummyBadProviderImpl.java | 30 ++++++++++------------ .../impl/DummyPolicyModelsProviderTest.java | 10 +++++--- .../impl/PolicyLegacyGuardPersistenceTest.java | 1 - .../PolicyLegacyOperationalPersistenceTest.java | 1 - .../provider/impl/PolicyPersistenceTest.java | 1 - .../provider/impl/PolicyToscaPersistenceTest.java | 1 - .../src/test/resources/META-INF/persistence.xml | 7 +++++ 8 files changed, 36 insertions(+), 31 deletions(-) (limited to 'models-provider/src/test') 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 d9253334a..7ad221721 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 @@ -24,11 +24,11 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; +import java.util.ArrayList; import java.util.Base64; import org.junit.Before; import org.junit.Test; -import org.onap.policy.models.pdp.concepts.PdpGroups; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.provider.PolicyModelsProviderParameters; @@ -69,6 +69,7 @@ public class DatabasePolicyModelsProviderTest { parameters.setDatabaseUrl("jdbc://www.acmecorp.nonexist"); assertThatThrownBy(() -> { + databaseProvider.close(); databaseProvider.init(); }).hasMessage("could not connect to database with URL \"jdbc://www.acmecorp.nonexist\""); @@ -116,7 +117,6 @@ public class DatabasePolicyModelsProviderTest { public void testProviderMethodsNull() throws Exception { PolicyModelsProvider databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); - databaseProvider.init(); assertThatThrownBy(() -> { databaseProvider.getPolicyTypes(null, null); @@ -235,6 +235,8 @@ public class DatabasePolicyModelsProviderTest { PolicyModelsProvider databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); + databaseProvider.close(); + assertThatThrownBy(() -> { databaseProvider.getPolicyTypes("name", "version"); }).hasMessage("policy models provider is not initilaized"); @@ -244,7 +246,6 @@ public class DatabasePolicyModelsProviderTest { public void testProviderMethods() { try (PolicyModelsProvider databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) { - databaseProvider.init(); assertThatThrownBy(() -> { databaseProvider.getPolicyTypes("name", "version"); @@ -310,9 +311,12 @@ public class DatabasePolicyModelsProviderTest { databaseProvider.deleteGuardPolicy("policy_id"); }).hasMessage("no policy found for policy ID: policy_id"); - assertNotNull(databaseProvider.getPdpGroups("name", "version")); - assertNotNull(databaseProvider.createPdpGroups(new PdpGroups())); - assertNotNull(databaseProvider.updatePdpGroups(new PdpGroups())); + assertThatThrownBy(() -> { + databaseProvider.getPdpGroups("name", "version"); + }).hasMessage("PDP group not found: name:version"); + + assertNotNull(databaseProvider.createPdpGroups(new ArrayList<>())); + assertNotNull(databaseProvider.updatePdpGroups(new ArrayList<>())); assertNotNull(databaseProvider.deletePdpGroup("name", "version")); } catch (Exception exc) { 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 9320df57f..c64603d9a 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 @@ -31,7 +31,6 @@ import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.models.base.PfModelException; import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.pdp.concepts.PdpGroup; -import org.onap.policy.models.pdp.concepts.PdpGroups; import org.onap.policy.models.pdp.concepts.PdpStatistics; import org.onap.policy.models.pdp.concepts.PdpSubGroup; import org.onap.policy.models.provider.PolicyModelsProvider; @@ -53,7 +52,7 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public void close() throws Exception {} + public void close() throws PfModelException {} @Override public void init() throws PfModelException {} @@ -86,14 +85,12 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public ToscaServiceTemplate createPolicies(@NonNull ToscaServiceTemplate serviceTemplate) - throws PfModelException { + public ToscaServiceTemplate createPolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException { return null; } @Override - public ToscaServiceTemplate updatePolicies(@NonNull ToscaServiceTemplate serviceTemplate) - throws PfModelException { + public ToscaServiceTemplate updatePolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException { return null; } @@ -147,17 +144,17 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public PdpGroups getPdpGroups(String name, String version) throws PfModelException { + public List getPdpGroups(String name, String version) throws PfModelException { return null; } @Override - public PdpGroups createPdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException { + public List createPdpGroups(@NonNull List pdpGroups) throws PfModelException { return null; } @Override - public PdpGroups updatePdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException { + public List updatePdpGroups(@NonNull List pdpGroups) throws PfModelException { return null; } @@ -187,7 +184,8 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public List getPolicyList4PolicyType(@NonNull String policyTypeName) throws PfModelException { + public List getPolicyList4PolicyType(@NonNull String policyTypeName, final String policyTypeVersion) + throws PfModelException { return null; } @@ -202,20 +200,19 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public PdpGroups getLatestPdpGroups(String name) throws PfModelException { + public List getLatestPdpGroups(String name) throws PfModelException { return null; } @Override - public PdpGroups getFilteredPdpGroups(@NonNull String pdpType, + public List getFilteredPdpGroups(@NonNull String pdpType, @NonNull List> supportedPolicyTypes) { return null; } @Override public void updatePdpSubGroup(@NonNull String pdpGroupName, @NonNull String pdpGroupVersion, - @NonNull PdpSubGroup pdpSubGroup) throws PfModelException { - } + @NonNull PdpSubGroup pdpSubGroup) throws PfModelException {} @Override public List getPdpStatistics(String name, String version) throws PfModelException { @@ -224,11 +221,10 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { @Override public void updatePdpStatistics(@NonNull String pdpGroupName, @NonNull String pdpGroupVersion, - @NonNull String pdpType, @NonNull String pdpInstanceId, @NonNull PdpStatistics pdppStatistics) { - } + @NonNull String pdpType, @NonNull String pdpInstanceId, @NonNull PdpStatistics pdppStatistics) {} @Override - public Map> getDeployedPolicyList(String name) throws PfModelException { + public Map, List> getDeployedPolicyList(String name) throws PfModelException { return 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 a0b4857de..01da44924 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 @@ -24,10 +24,12 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.util.ArrayList; + import org.junit.Test; -import org.onap.policy.models.pdp.concepts.PdpGroups; import org.onap.policy.models.provider.PolicyModelsProvider; import org.onap.policy.models.provider.PolicyModelsProviderFactory; import org.onap.policy.models.provider.PolicyModelsProviderParameters; @@ -91,9 +93,9 @@ public class DummyPolicyModelsProviderTest { assertNotNull(dummyProvider.updateGuardPolicy(new LegacyGuardPolicyInput())); assertNotNull(dummyProvider.deleteGuardPolicy("policy_id")); - assertNull(dummyProvider.getPdpGroups("name", "version")); - assertNull(dummyProvider.createPdpGroups(new PdpGroups())); - assertNull(dummyProvider.updatePdpGroups(new PdpGroups())); + assertTrue(dummyProvider.getPdpGroups("name", "version").isEmpty()); + assertTrue(dummyProvider.createPdpGroups(new ArrayList<>()).isEmpty()); + assertTrue(dummyProvider.updatePdpGroups(new ArrayList<>()).isEmpty()); assertNull(dummyProvider.deletePdpGroup("name", "version")); diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java index 2cb787d00..47f099a73 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java @@ -82,7 +82,6 @@ public class PolicyLegacyGuardPersistenceTest { parameters.setPersistenceUnit("ToscaConceptTest"); databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); - databaseProvider.init(); } /** diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java index 60d577cb9..65e6a2f54 100644 --- a/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java +++ b/models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java @@ -82,7 +82,6 @@ public class PolicyLegacyOperationalPersistenceTest { parameters.setPersistenceUnit("ToscaConceptTest"); databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); - databaseProvider.init(); } /** 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 b29e1d642..468d4d74b 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 @@ -90,7 +90,6 @@ public class PolicyPersistenceTest { parameters.setPersistenceUnit("ToscaConceptTest"); databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); - databaseProvider.init(); } /** 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 f2b867604..bf48292fd 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 @@ -89,7 +89,6 @@ public class PolicyToscaPersistenceTest { parameters.setPersistenceUnit("ToscaConceptTest"); databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters); - databaseProvider.init(); } /** diff --git a/models-provider/src/test/resources/META-INF/persistence.xml b/models-provider/src/test/resources/META-INF/persistence.xml index 23e8567f1..c7d6d1e4b 100644 --- a/models-provider/src/test/resources/META-INF/persistence.xml +++ b/models-provider/src/test/resources/META-INF/persistence.xml @@ -28,6 +28,9 @@ org.onap.policy.models.base.PfConceptKey org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy + org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup + org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup + org.onap.policy.models.pdp.persistence.concepts.JpaPdp @@ -46,7 +49,11 @@ org.onap.policy.models.dao.converters.CDataConditioner org.onap.policy.models.dao.converters.Uuid2String org.onap.policy.models.base.PfConceptKey + org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy + org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup + org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup + org.onap.policy.models.pdp.persistence.concepts.JpaPdp -- cgit 1.2.3-korg