From d5ed712cf50bcf270fed8cd597d78ff4ff9370a0 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Tue, 21 May 2019 16:11:39 +0000 Subject: Add version on legacy get/delete Issue-ID: POLICY-1777 Change-Id: I5b07ad1acdb4a614a50cb15978130c19bc5786f7 Signed-off-by: liamfallon --- .../impl/DatabasePolicyModelsProviderTest.java | 78 ++++++++++++++++------ .../models/provider/impl/DummyBadProviderImpl.java | 24 ++++--- .../impl/DummyPolicyModelsProviderTest.java | 8 +-- .../impl/PolicyLegacyGuardPersistenceTest.java | 4 +- .../PolicyLegacyOperationalPersistenceTest.java | 4 +- 5 files changed, 81 insertions(+), 37 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 ccdf45af4..6fac58706 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 @@ -190,9 +190,17 @@ public class DatabasePolicyModelsProviderTest { }).hasMessage("version is marked @NonNull but is null"); assertThatThrownBy(() -> { - databaseProvider.getOperationalPolicy(null); + databaseProvider.getOperationalPolicy(null, null); }).hasMessage("policyId is marked @NonNull but is null"); + assertThatThrownBy(() -> { + databaseProvider.getOperationalPolicy(null, ""); + }).hasMessage("policyId is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.getOperationalPolicy("", null); + }).hasMessage("no policy found for policy: :null"); + assertThatThrownBy(() -> { databaseProvider.createOperationalPolicy(null); }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null"); @@ -202,13 +210,29 @@ public class DatabasePolicyModelsProviderTest { }).hasMessage("legacyOperationalPolicy is marked @NonNull but is null"); assertThatThrownBy(() -> { - databaseProvider.deleteOperationalPolicy(null); + databaseProvider.deleteOperationalPolicy(null, null); + }).hasMessage("policyId is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.deleteOperationalPolicy(null, ""); + }).hasMessage("policyId is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.deleteOperationalPolicy("", null); + }).hasMessage("policyVersion is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.getGuardPolicy(null, null); }).hasMessage("policyId is marked @NonNull but is null"); assertThatThrownBy(() -> { - databaseProvider.getGuardPolicy(null); + databaseProvider.getGuardPolicy(null, ""); }).hasMessage("policyId is marked @NonNull but is null"); + assertThatThrownBy(() -> { + databaseProvider.getGuardPolicy("", null); + }).hasMessage("no policy found for policy: :null"); + assertThatThrownBy(() -> { databaseProvider.createGuardPolicy(null); }).hasMessage("legacyGuardPolicy is marked @NonNull but is null"); @@ -218,9 +242,17 @@ public class DatabasePolicyModelsProviderTest { }).hasMessage("legacyGuardPolicy is marked @NonNull but is null"); assertThatThrownBy(() -> { - databaseProvider.deleteGuardPolicy(null); + databaseProvider.deleteGuardPolicy(null, null); + }).hasMessage("policyId is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.deleteGuardPolicy(null, ""); }).hasMessage("policyId is marked @NonNull but is null"); + assertThatThrownBy(() -> { + databaseProvider.deleteGuardPolicy("", null); + }).hasMessage("policyVersion is marked @NonNull but is null"); + assertThatThrownBy(() -> { databaseProvider.getFilteredPdpGroups(null); }).hasMessage("filter is marked @NonNull but is null"); @@ -367,8 +399,8 @@ public class DatabasePolicyModelsProviderTest { try (PolicyModelsProvider databaseProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters)) { - assertEquals(0, databaseProvider.getPolicyTypes("name", "version").getPolicyTypes().get(0).size()); - assertEquals(0, databaseProvider.getPolicyTypeList("name", "version").size()); + assertEquals(0, databaseProvider.getPolicyTypes("name", "1.0.0").getPolicyTypes().get(0).size()); + assertEquals(0, databaseProvider.getPolicyTypeList("name", "1.0.0").size()); assertEquals(0, databaseProvider.getFilteredPolicyTypes(ToscaPolicyTypeFilter.builder().build()) .getPolicyTypes().get(0).size()); assertEquals(0, databaseProvider.getFilteredPolicyTypeList(ToscaPolicyTypeFilter.builder().build()).size()); @@ -381,13 +413,13 @@ public class DatabasePolicyModelsProviderTest { databaseProvider.updatePolicyTypes(new ToscaServiceTemplate()); }).hasMessage("no policy types specified on service template"); - assertEquals(0, databaseProvider.deletePolicyType("name", "version").getPolicyTypes().get(0).size()); + assertEquals(0, databaseProvider.deletePolicyType("name", "1.0.0").getPolicyTypes().get(0).size()); - assertEquals(0, databaseProvider.deletePolicyType("name", "version").getPolicyTypes().get(0).size()); + assertEquals(0, databaseProvider.deletePolicyType("name", "1.0.0").getPolicyTypes().get(0).size()); - assertEquals(0, databaseProvider.getPolicies("name", "version").getToscaTopologyTemplate().getPolicies() + assertEquals(0, databaseProvider.getPolicies("name", "1.0.0").getToscaTopologyTemplate().getPolicies() .get(0).size()); - assertEquals(0, databaseProvider.getPolicyList("name", "version").size()); + assertEquals(0, databaseProvider.getPolicyList("name", "1.0.0").size()); assertEquals(0, databaseProvider.getFilteredPolicies(ToscaPolicyFilter.builder().build()) .getToscaTopologyTemplate().getPolicies().get(0).size()); assertEquals(0, databaseProvider.getFilteredPolicyList(ToscaPolicyFilter.builder().build()).size()); @@ -404,8 +436,12 @@ public class DatabasePolicyModelsProviderTest { .get(0).size()); assertThatThrownBy(() -> { - databaseProvider.getOperationalPolicy("policy_id"); - }).hasMessage("no policy found for policy ID: policy_id"); + databaseProvider.getOperationalPolicy("policy_id", null); + }).hasMessage("no policy found for policy: policy_id:null"); + + assertThatThrownBy(() -> { + databaseProvider.getOperationalPolicy("policy_id", "10.9.8"); + }).hasMessage("no policy found for policy: policy_id:10.9.8"); assertThatThrownBy(() -> { databaseProvider.createOperationalPolicy(new LegacyOperationalPolicy()); @@ -413,15 +449,19 @@ public class DatabasePolicyModelsProviderTest { assertThatThrownBy(() -> { databaseProvider.updateOperationalPolicy(new LegacyOperationalPolicy()); - }).hasMessage("no policy found for policy ID: null"); + }).hasMessage("name is marked @NonNull but is null"); + + assertThatThrownBy(() -> { + databaseProvider.deleteOperationalPolicy("policy_id", "55.44.33"); + }).hasMessage("no policy found for policy: policy_id:55.44.33"); assertThatThrownBy(() -> { - databaseProvider.deleteOperationalPolicy("policy_id"); - }).hasMessage("no policy found for policy ID: policy_id"); + databaseProvider.getGuardPolicy("policy_id", null); + }).hasMessage("no policy found for policy: policy_id:null"); assertThatThrownBy(() -> { - databaseProvider.getGuardPolicy("policy_id"); - }).hasMessage("no policy found for policy ID: policy_id"); + databaseProvider.getGuardPolicy("policy_id", "6.7.5"); + }).hasMessage("no policy found for policy: policy_id:6.7.5"); assertThatThrownBy(() -> { databaseProvider.createGuardPolicy(new LegacyGuardPolicyInput()); @@ -432,8 +472,8 @@ public class DatabasePolicyModelsProviderTest { }).hasMessage("policy type for guard policy \"null\" unknown"); assertThatThrownBy(() -> { - databaseProvider.deleteGuardPolicy("policy_id"); - }).hasMessage("no policy found for policy ID: policy_id"); + databaseProvider.deleteGuardPolicy("policy_id", "33.22.11"); + }).hasMessage("no policy found for policy: policy_id:33.22.11"); assertEquals(0, databaseProvider.getPdpGroups("name").size()); assertEquals(0, databaseProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).size()); 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 3e182c02d..4f4c1c3fb 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 @@ -103,7 +103,8 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public LegacyOperationalPolicy getOperationalPolicy(@NonNull String policyId) throws PfModelException { + public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId, final String policyVersion) + throws PfModelException { return null; } @@ -120,12 +121,14 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull String policyId) throws PfModelException { + public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull String policyId, final String policyVersion) + throws PfModelException { return null; } @Override - public Map getGuardPolicy(@NonNull String policyId) throws PfModelException { + public Map getGuardPolicy(@NonNull String policyId, final String policyVersion) + throws PfModelException { return null; } @@ -142,7 +145,8 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public Map deleteGuardPolicy(@NonNull String policyId) throws PfModelException { + public Map deleteGuardPolicy(@NonNull String policyId, final String policyVersion) + throws PfModelException { return null; } @@ -162,8 +166,8 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpSubGroup, - @NonNull Pdp pdp) throws PfModelException {} + public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpSubGroup, @NonNull Pdp pdp) + throws PfModelException {} @Override public PdpGroup deletePdpGroup(@NonNull String name) throws PfModelException { @@ -207,8 +211,8 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public void updatePdpSubGroup(@NonNull String pdpGroupName, - @NonNull PdpSubGroup pdpSubGroup) throws PfModelException {} + public void updatePdpSubGroup(@NonNull String pdpGroupName, @NonNull PdpSubGroup pdpSubGroup) + throws PfModelException {} @Override public List getPdpStatistics(String name) throws PfModelException { @@ -216,6 +220,6 @@ public class DummyBadProviderImpl implements PolicyModelsProvider { } @Override - public void updatePdpStatistics(@NonNull String pdpGroupName, - @NonNull String pdpType, @NonNull String pdpInstanceId, @NonNull PdpStatistics pdppStatistics) {} + public void updatePdpStatistics(@NonNull String pdpGroupName, @NonNull String pdpType, + @NonNull String pdpInstanceId, @NonNull PdpStatistics pdppStatistics) {} } 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 9f02fd7a4..93cb89165 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 @@ -94,15 +94,15 @@ public class DummyPolicyModelsProviderTest { assertNotNull(dummyProvider.updatePolicies(new ToscaServiceTemplate())); assertNotNull(dummyProvider.deletePolicy("name", "version")); - assertNotNull(dummyProvider.getOperationalPolicy("policy_id")); + assertNotNull(dummyProvider.getOperationalPolicy("policy_id", "1")); assertNotNull(dummyProvider.createOperationalPolicy(new LegacyOperationalPolicy())); assertNotNull(dummyProvider.updateOperationalPolicy(new LegacyOperationalPolicy())); - assertNotNull(dummyProvider.deleteOperationalPolicy("policy_id")); + assertNotNull(dummyProvider.deleteOperationalPolicy("policy_id", "1")); - assertNotNull(dummyProvider.getGuardPolicy("policy_id")); + assertNotNull(dummyProvider.getGuardPolicy("policy_id", "1")); assertNotNull(dummyProvider.createGuardPolicy(new LegacyGuardPolicyInput())); assertNotNull(dummyProvider.updateGuardPolicy(new LegacyGuardPolicyInput())); - assertNotNull(dummyProvider.deleteGuardPolicy("policy_id")); + assertNotNull(dummyProvider.deleteGuardPolicy("policy_id", "1")); assertTrue(dummyProvider.getPdpGroups("name").isEmpty()); assertTrue(dummyProvider.getFilteredPdpGroups(PdpGroupFilter.builder().build()).isEmpty()); 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 c5052dad7..fbbbaed9a 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 @@ -138,7 +138,7 @@ public class PolicyLegacyGuardPersistenceTest { assertEquals(gip.getContent(), createdGopm.get(gip.getPolicyId()).getProperties().values().iterator().next()); - Map gotGopm = databaseProvider.getGuardPolicy(gip.getPolicyId()); + Map gotGopm = databaseProvider.getGuardPolicy(gip.getPolicyId(), null); assertEquals(gip.getPolicyId(), gotGopm.keySet().iterator().next()); assertEquals(gip.getContent(), gotGopm.get(gip.getPolicyId()).getProperties().values().iterator().next()); @@ -148,7 +148,7 @@ public class PolicyLegacyGuardPersistenceTest { assertEquals(gip.getContent(), updatedGopm.get(gip.getPolicyId()).getProperties().values().iterator().next()); - Map deletedGopm = databaseProvider.deleteGuardPolicy(gip.getPolicyId()); + Map deletedGopm = databaseProvider.deleteGuardPolicy(gip.getPolicyId(), "1"); assertEquals(gip.getPolicyId(), deletedGopm.keySet().iterator().next()); assertEquals(gip.getContent(), deletedGopm.get(gip.getPolicyId()).getProperties().values().iterator().next()); 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 c1cda4d05..77a0cac9c 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 @@ -136,13 +136,13 @@ public class PolicyLegacyOperationalPersistenceTest { LegacyOperationalPolicy createdLop = databaseProvider.createOperationalPolicy(lop); assertEquals(createdLop, lop); - LegacyOperationalPolicy gotLop = databaseProvider.getOperationalPolicy(lop.getPolicyId()); + LegacyOperationalPolicy gotLop = databaseProvider.getOperationalPolicy(lop.getPolicyId(), null); assertEquals(gotLop, lop); LegacyOperationalPolicy updatedLop = databaseProvider.updateOperationalPolicy(lop); assertEquals(gotLop, updatedLop); - LegacyOperationalPolicy deletedLop = databaseProvider.deleteOperationalPolicy(lop.getPolicyId()); + LegacyOperationalPolicy deletedLop = databaseProvider.deleteOperationalPolicy(lop.getPolicyId(), "1"); assertEquals(gotLop, deletedLop); String actualRetrievedJson = standardCoder.encode(gotLop); -- cgit 1.2.3-korg