aboutsummaryrefslogtreecommitdiffstats
path: root/models-provider
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-03-24 12:41:04 +0000
committerGerrit Code Review <gerrit@onap.org>2021-03-24 12:41:04 +0000
commit2d52d7da138050735cd54d2c1c2ee03d1e473262 (patch)
treeefd56c81b1a40bb6452332b0377bf0802cf92678 /models-provider
parentb0fc73fd9ff6d9727c0f93a7ad0a742b704b4c9d (diff)
parent7a03b4a98e74635ba9cf75ac360be0749c1d98cf (diff)
Merge "Fix sonar issues for tests in policy-models"
Diffstat (limited to 'models-provider')
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java20
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/impl/DummyPolicyModelsProviderTest.java24
-rw-r--r--models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java166
3 files changed, 107 insertions, 103 deletions
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 0cdd1bc40..d3b20b901 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
@@ -192,6 +192,13 @@ public class DatabasePolicyModelsProviderTest {
assertThatThrownBy(() -> {
databaseProvider.deletePolicy("aaa", null);
}).hasMessageMatching("^version is marked .*on.*ull but is null$");
+ }
+
+ @Test
+ public void testProviderMethodsNullGroup() throws Exception {
+
+ PolicyModelsProvider databaseProvider =
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
assertThatThrownBy(() -> {
databaseProvider.getFilteredPdpGroups(null);
@@ -344,7 +351,10 @@ public class DatabasePolicyModelsProviderTest {
assertNotNull(databaseProvider.createPdpGroups(new ArrayList<>()));
assertNotNull(databaseProvider.updatePdpGroups(new ArrayList<>()));
+ }
+ @Test
+ public void testProviderMethodsInGroups() throws PfModelException {
PdpGroup pdpGroup = new PdpGroup();
pdpGroup.setName(GROUP);
pdpGroup.setVersion("1.2.3");
@@ -376,6 +386,9 @@ public class DatabasePolicyModelsProviderTest {
ArrayList<PdpStatistics> statisticsArrayList = new ArrayList<>();
statisticsArrayList.add(pdpStatistics);
+ PolicyModelsProvider databaseProvider =
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+
assertEquals(123,
databaseProvider.createPdpGroups(groupList).get(0).getPdpSubgroups().get(0).getDesiredInstanceCount());
assertEquals(1, databaseProvider.getPdpGroups(GROUP).size());
@@ -401,6 +414,13 @@ public class DatabasePolicyModelsProviderTest {
assertEquals(0, databaseProvider.getPdpStatistics(null, null).size());
assertEquals(1, databaseProvider.createPdpStatistics(statisticsArrayList).size());
assertEquals(1, databaseProvider.updatePdpStatistics(statisticsArrayList).size());
+ }
+
+
+ @Test
+ public void testProviderMethodsStatistics() throws PfModelException {
+ PolicyModelsProvider databaseProvider =
+ new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
assertEquals(NAME, databaseProvider.getPdpStatistics(null, null).get(0).getPdpInstanceId());
assertEquals(NAME, databaseProvider.getFilteredPdpStatistics(null, GROUP, 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 428aecc36..67a1449f6 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,6 +33,7 @@ import static org.junit.Assert.assertTrue;
import java.time.Instant;
import java.util.ArrayList;
import org.junit.Test;
+import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.pdp.concepts.Pdp;
import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
import org.onap.policy.models.pdp.concepts.PdpSubGroup;
@@ -76,12 +77,7 @@ public class DummyPolicyModelsProviderTest {
@Test
public void testProviderMethods() throws Exception {
- PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
- parameters.setImplementation(DummyPolicyModelsProviderImpl.class.getName());
- parameters.setDatabaseUrl("jdbc:dummy");
- parameters.setPersistenceUnit("dummy");
-
- PolicyModelsProvider dummyProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+ PolicyModelsProvider dummyProvider = setUpDummyProvider();
dummyProvider.init();
assertNotNull(dummyProvider.getPolicyTypes("name", VERSION));
@@ -105,6 +101,12 @@ public class DummyPolicyModelsProviderTest {
assertTrue(dummyProvider.createPdpGroups(new ArrayList<>()).isEmpty());
assertTrue(dummyProvider.updatePdpGroups(new ArrayList<>()).isEmpty());
assertNull(dummyProvider.deletePdpGroup("name"));
+ }
+
+ @Test
+ public void testProviderMethodsParameters() throws Exception {
+ PolicyModelsProvider dummyProvider = setUpDummyProvider();
+ dummyProvider.init();
dummyProvider.updatePdpSubGroup("name", new PdpSubGroup());
dummyProvider.updatePdp("name", "type", new Pdp());
@@ -138,4 +140,14 @@ public class DummyPolicyModelsProviderTest {
assertThatThrownBy(resp::getBadDummyResponse2).hasMessage("error serializing object");
}
}
+
+ private PolicyModelsProvider setUpDummyProvider() throws PfModelException {
+ PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
+ parameters.setImplementation(DummyPolicyModelsProviderImpl.class.getName());
+ parameters.setDatabaseUrl("jdbc:dummy");
+ parameters.setPersistenceUnit("dummy");
+
+ PolicyModelsProvider dummyProvider = new PolicyModelsProviderFactory().createPolicyModelsProvider(parameters);
+ return dummyProvider;
+ }
}
diff --git a/models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java b/models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java
index c107f1273..1590b38c5 100644
--- a/models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java
+++ b/models-provider/src/test/java/org/onap/policy/models/provider/revisionhierarchy/HierarchyFetchTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
+ * Copyright (C) 2020-2021 Nordix Foundation.
* Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -80,33 +80,30 @@ public class HierarchyFetchTest {
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(1, fetchedServiceTemplate.getPolicyTypes().size());
ToscaPolicyType fetchedPolicyType = fetchedServiceTemplate.getPolicyTypes().values().iterator().next();
- assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
- assertEquals(3, countReturnedPolicies(fetchedServiceTemplate));
+ checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0",
+ "3.0.0", fetchedServiceTemplate, 3);
+
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0", "1.0.0");
assertOldDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(1, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyType = fetchedServiceTemplate.getPolicyTypes().values().iterator().next();
- assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
- assertEquals("1.0.0", fetchedPolicyType.getVersion());
- assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+ checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0",
+ "1.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0", "1.1.0");
assertOldDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(1, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyType = fetchedServiceTemplate.getPolicyTypes().values().iterator().next();
- assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
- assertEquals("2.0.0", fetchedPolicyType.getVersion());
- assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+ checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0",
+ "2.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0", "1.2.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(1, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyType = fetchedServiceTemplate.getPolicyTypes().values().iterator().next();
- assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
- assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+ checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0",
+ "3.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1", null);
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
@@ -114,184 +111,159 @@ public class HierarchyFetchTest {
Iterator<ToscaPolicyType> fetchedPolicyTypeIterator =
fetchedServiceTemplate.getPolicyTypes().values().iterator();
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
- assertEquals(3, countReturnedPolicies(fetchedServiceTemplate));
+ checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1",
+ "3.0.0", fetchedServiceTemplate, 3);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1", "1.0.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(2, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
- assertEquals("1.0.0", fetchedPolicyType.getVersion());
- assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+ checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1",
+ "1.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1", "1.1.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(2, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
- assertEquals("2.0.0", fetchedPolicyType.getVersion());
- assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+ checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1",
+ "2.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1", "1.2.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(2, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
- assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+ checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1",
+ "3.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2", null);
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(3, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1.2", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
- assertEquals(3, countReturnedPolicies(fetchedServiceTemplate));
+ checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2",
+ "3.0.0", fetchedServiceTemplate, 3);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2", "1.0.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(3, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1.2", fetchedPolicyType.getName());
- assertEquals("1.0.0", fetchedPolicyType.getVersion());
- assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+ checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2",
+ "1.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2", "1.1.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(3, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1.2", fetchedPolicyType.getName());
- assertEquals("2.0.0", fetchedPolicyType.getVersion());
- assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+ checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2",
+ "2.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2", "1.2.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(3, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1.2", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
- assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+ checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2",
+ "3.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2.3", null);
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(4, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1.2", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1.2.3", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
- assertEquals(3, countReturnedPolicies(fetchedServiceTemplate));
+ checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2.3",
+ "3.0.0", fetchedServiceTemplate, 3);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2.3", "1.0.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(4, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1.2", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1.2.3", fetchedPolicyType.getName());
- assertEquals("1.0.0", fetchedPolicyType.getVersion());
- assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+ checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2.3",
+ "1.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2.3", "1.1.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(4, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1.2", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1.2.3", fetchedPolicyType.getName());
- assertEquals("2.0.0", fetchedPolicyType.getVersion());
- assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+ checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2.3",
+ "2.0.0", fetchedServiceTemplate, 1);
fetchedServiceTemplate = databaseProvider.getPolicies("onap.policies.PolicyLevel0.1.2.3", "1.2.0");
assertLatestDataTypesAreReturned(fetchedServiceTemplate);
assertEquals(4, fetchedServiceTemplate.getPolicyTypes().size());
fetchedPolicyTypeIterator = fetchedServiceTemplate.getPolicyTypes().values().iterator();
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1.2", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
+ checkNameVersion(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2", "3.0.0");
fetchedPolicyType = fetchedPolicyTypeIterator.next();
- assertEquals("onap.policies.PolicyTypeLevel0.1.2.3", fetchedPolicyType.getName());
- assertEquals("3.0.0", fetchedPolicyType.getVersion());
- assertEquals(1, countReturnedPolicies(fetchedServiceTemplate));
+ checkEqualsPolicyType(fetchedPolicyType, "onap.policies.PolicyTypeLevel0.1.2.3",
+ "3.0.0", fetchedServiceTemplate, 1);
databaseProvider.close();
}
+ private void checkNameVersion(ToscaPolicyType fetchedPolicyType, String name, String ver) {
+ assertEquals(name, fetchedPolicyType.getName());
+ assertEquals(ver, fetchedPolicyType.getVersion());
+ }
+
+ private void checkEqualsPolicyType(ToscaPolicyType fetchedPolicyType, String name, String ver,
+ ToscaServiceTemplate fetchedServiceTemplate, int policies) {
+ checkNameVersion(fetchedPolicyType, name, ver);
+ assertEquals(policies, countReturnedPolicies(fetchedServiceTemplate));
+ }
+
private void assertOldDataTypesAreReturned(final ToscaServiceTemplate fetchedServiceTemplate) {
assertEquals(6, fetchedServiceTemplate.getDataTypes().size());
assertEquals("1.0.0", fetchedServiceTemplate.getDataTypes().get("policy.data.DataType0").getVersion());