aboutsummaryrefslogtreecommitdiffstats
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
parentb0fc73fd9ff6d9727c0f93a7ad0a742b704b4c9d (diff)
parent7a03b4a98e74635ba9cf75ac360be0749c1d98cf (diff)
Merge "Fix sonar issues for tests in policy-models"
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java23
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java24
-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
5 files changed, 141 insertions, 116 deletions
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java
index de328e9f2..ce1c3e888 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -42,7 +42,7 @@ public class PfReferenceKeyTest {
private static final String VERSION001 = "0.0.1";
@Test
- public void testPfReferenceKey() {
+ public void testPfReferenceKeyNotNull() {
assertNotNull(new PfReferenceKey());
assertNotNull(new PfReferenceKey(new PfConceptKey()));
assertNotNull(new PfReferenceKey(new PfConceptKey(), LOCAL_NAME));
@@ -57,7 +57,10 @@ public class PfReferenceKeyTest {
assertThatThrownBy(() -> new PfReferenceKey(new PfConceptKey(), null))
.hasMessage("parameter \"localName\" is null");
+ }
+ @Test
+ public void testPfReferenceKey() {
PfReferenceKey testReferenceKey = new PfReferenceKey();
testReferenceKey.setParentConceptKey(new PfConceptKey("PN", VERSION001));
assertEquals("PN:0.0.1", testReferenceKey.getParentConceptKey().getId());
@@ -96,7 +99,11 @@ public class PfReferenceKeyTest {
assertEquals(PfKey.Compatibility.IDENTICAL, testReferenceKey.getCompatibility(testReferenceKey));
assertTrue(testReferenceKey.validate("").isValid());
+ }
+ @Test
+ public void testMultiplePfReferenceKey() {
+ PfReferenceKey testReferenceKey = setTestReferenceKey();
testReferenceKey.clean();
PfReferenceKey clonedReferenceKey = new PfReferenceKey(testReferenceKey);
@@ -172,4 +179,16 @@ public class PfReferenceKeyTest {
assertThat(validationResult4.getResult()).contains("\"localName\"")
.contains("does not match regular expression [A-Za-z0-9\\-_\\.]+|^$");
}
+
+ private PfReferenceKey setTestReferenceKey() {
+ PfReferenceKey testReferenceKey = new PfReferenceKey();
+ testReferenceKey.setParentConceptKey(new PfConceptKey("PN", VERSION001));
+ testReferenceKey.setParentReferenceKey(new PfReferenceKey("PN", VERSION001, "LN"));
+ testReferenceKey.setParentKeyName("NPKN");
+ testReferenceKey.setParentKeyVersion(VERSION001);
+ testReferenceKey.setParentLocalName(NPKLN);
+ testReferenceKey.setLocalName("NLN");
+
+ return testReferenceKey;
+ }
}
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java
index 4afdadff3..79f271c9c 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java
@@ -59,17 +59,6 @@ public class PfTimestampKeyTest {
assertEquals(someKey2, someKey1.getKey());
assertEquals(1, someKey1.getKeys().size());
-
- assertThatThrownBy(() -> new PfTimestampKey((PfTimestampKey) null)).isInstanceOf(NullPointerException.class)
- .hasMessageMatching(CONCEPT_IS_NULL);
- assertThatThrownBy(() -> new PfTimestampKey(null, null, null)).isInstanceOf(NullPointerException.class)
- .hasMessageMatching(NAME_IS_NULL);
- assertThatThrownBy(() -> new PfTimestampKey("my-name", null, null)).isInstanceOf(NullPointerException.class)
- .hasMessageMatching(VERSION_IS_NULL);
- assertThatThrownBy(() -> new PfTimestampKey("my-name", VERSION001, null))
- .isInstanceOf(NullPointerException.class)
- .hasMessageMatching("^instant is marked .*on.*ull but is null$");
-
assertThatThrownBy(() -> someKey0.setName(null)).isInstanceOf(NullPointerException.class)
.hasMessageMatching(NAME_IS_NULL);
assertThatThrownBy(() -> someKey0.setVersion(null)).isInstanceOf(NullPointerException.class)
@@ -94,4 +83,17 @@ public class PfTimestampKeyTest {
assertFalse(someKey4.isNullKey());
assertFalse(someKey1.isNullKey());
}
+
+ @Test
+ public void testTimestampKeyErrors() {
+ assertThatThrownBy(() -> new PfTimestampKey((PfTimestampKey) null)).isInstanceOf(NullPointerException.class)
+ .hasMessageMatching(CONCEPT_IS_NULL);
+ assertThatThrownBy(() -> new PfTimestampKey(null, null, null)).isInstanceOf(NullPointerException.class)
+ .hasMessageMatching(NAME_IS_NULL);
+ assertThatThrownBy(() -> new PfTimestampKey("my-name", null, null)).isInstanceOf(NullPointerException.class)
+ .hasMessageMatching(VERSION_IS_NULL);
+ assertThatThrownBy(() -> new PfTimestampKey("my-name", VERSION001, null))
+ .isInstanceOf(NullPointerException.class)
+ .hasMessageMatching("^instant is marked .*on.*ull but is null$");
+ }
}
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());