summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-06-14 18:20:38 -0400
committerJim Hahn <jrh3@att.com>2019-06-17 11:17:17 -0400
commit556c59a7b57e91d7c6c8fbbf5bb6966bdfc1578c (patch)
tree191ea79c4fc49b8f5bca26d09281986d15cbf5c9
parentf59ec395bf1e41df894f884e70ff3185280668c0 (diff)
Fix simple sonar issues in models-tosca
Change-Id: I36a91fbbd95df7aff2656a97dd09b778cdbb798f Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn <jrh3@att.com>
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java68
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java3
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java1
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java50
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java1
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java81
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java78
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java67
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java4
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java3
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java60
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java47
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java13
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintTest.java37
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java10
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java47
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchemaTest.java46
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java92
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java77
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java47
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java18
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java85
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java47
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java93
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java86
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplatesTest.java9
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java104
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java62
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java143
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java3
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java79
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java166
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java148
33 files changed, 787 insertions, 1088 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java
index cba3fe591..bf9f92e28 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java
@@ -27,12 +27,10 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import com.google.gson.GsonBuilder;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.common.utils.coder.CoderException;
@@ -49,6 +47,10 @@ import org.yaml.snakeyaml.Yaml;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class ToscaPolicyFilterTest {
+ private static final String VERSION_100 = "1.0.0";
+
+ private static final String VERSION_000 = "0.0.0";
+
// Logger for this class
private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyFilterTest.class);
@@ -91,22 +93,7 @@ public class ToscaPolicyFilterTest {
assertNotNull(serviceTemplate);
for (Map<String, ToscaPolicy> foundPolicyMap : serviceTemplate.getToscaTopologyTemplate().getPolicies()) {
- for (Entry<String, ToscaPolicy> policyEntry : foundPolicyMap.entrySet()) {
- ToscaPolicy policy = policyEntry.getValue();
- if (policy.getName() == null) {
- policy.setName(policyEntry.getKey());
- }
-
- if (policy.getVersion() == null) {
- policy.setVersion(PfKey.NULL_KEY_VERSION);
- }
- if (policy.getTypeVersion() == null) {
- policy.setTypeVersion(PfKey.NULL_KEY_VERSION);
- }
- if (!policyList.contains(policy)) {
- policyList.add(policy);
- }
- }
+ addPolicies(foundPolicyMap);
}
}
@@ -116,6 +103,25 @@ public class ToscaPolicyFilterTest {
}
}
+ private static void addPolicies(Map<String, ToscaPolicy> foundPolicyMap) {
+ for (Entry<String, ToscaPolicy> policyEntry : foundPolicyMap.entrySet()) {
+ ToscaPolicy policy = policyEntry.getValue();
+ if (policy.getName() == null) {
+ policy.setName(policyEntry.getKey());
+ }
+
+ if (policy.getVersion() == null) {
+ policy.setVersion(PfKey.NULL_KEY_VERSION);
+ }
+ if (policy.getTypeVersion() == null) {
+ policy.setTypeVersion(PfKey.NULL_KEY_VERSION);
+ }
+ if (!policyList.contains(policy)) {
+ policyList.add(policy);
+ }
+ }
+ }
+
@Test
public void testNullList() {
ToscaPolicyFilter filter = ToscaPolicyFilter.builder().build();
@@ -139,8 +145,8 @@ public class ToscaPolicyFilterTest {
List<ToscaPolicy> filteredList = filter.filter(policyList);
assertEquals(15, filteredList.size());
- assertEquals("1.0.0", filteredList.get(7).getVersion());
- assertEquals("1.0.0", filteredList.get(12).getVersion());
+ assertEquals(VERSION_100, filteredList.get(7).getVersion());
+ assertEquals(VERSION_100, filteredList.get(12).getVersion());
assertEquals(17, policyList.size());
assertEquals(15, filteredList.size());
@@ -152,12 +158,12 @@ public class ToscaPolicyFilterTest {
assertEquals("2.0.0", filteredList.get(7).getVersion());
assertEquals("3.4.5", filteredList.get(12).getVersion());
- policyList.get(10).setVersion("1.0.0");
- policyList.get(16).setVersion("1.0.0");
+ policyList.get(10).setVersion(VERSION_100);
+ policyList.get(16).setVersion(VERSION_100);
filteredList = filter.filter(policyList);
assertEquals(15, filteredList.size());
- assertEquals("1.0.0", filteredList.get(7).getVersion());
- assertEquals("1.0.0", filteredList.get(12).getVersion());
+ assertEquals(VERSION_100, filteredList.get(7).getVersion());
+ assertEquals(VERSION_100, filteredList.get(12).getVersion());
}
@Test
@@ -174,15 +180,15 @@ public class ToscaPolicyFilterTest {
filteredList = filter.filter(policyList);
assertEquals(0, filteredList.size());
- filter = ToscaPolicyFilter.builder().version("1.0.0").build();
+ filter = ToscaPolicyFilter.builder().version(VERSION_100).build();
filteredList = filter.filter(policyList);
assertEquals(17, filteredList.size());
- filter = ToscaPolicyFilter.builder().name("OSDF_CASABLANCA.SubscriberPolicy_v1").version("1.0.0").build();
+ filter = ToscaPolicyFilter.builder().name("OSDF_CASABLANCA.SubscriberPolicy_v1").version(VERSION_100).build();
filteredList = filter.filter(policyList);
assertEquals(1, filteredList.size());
- filter = ToscaPolicyFilter.builder().name("operational.modifyconfig").version("1.0.0").build();
+ filter = ToscaPolicyFilter.builder().name("operational.modifyconfig").version(VERSION_100).build();
filteredList = filter.filter(policyList);
assertEquals(2, filteredList.size());
}
@@ -217,15 +223,17 @@ public class ToscaPolicyFilterTest {
filteredList = filter.filter(policyList);
assertEquals(0, filteredList.size());
- filter = ToscaPolicyFilter.builder().typeVersion("0.0.0").build();
+ filter = ToscaPolicyFilter.builder().typeVersion(VERSION_000).build();
filteredList = filter.filter(policyList);
assertEquals(17, filteredList.size());
- filter = ToscaPolicyFilter.builder().type("onap.policies.optimization.HpaPolicy").typeVersion("0.0.0").build();
+ filter = ToscaPolicyFilter.builder().type("onap.policies.optimization.HpaPolicy").typeVersion(VERSION_000)
+ .build();
filteredList = filter.filter(policyList);
assertEquals(1, filteredList.size());
- filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.Operational").typeVersion("0.0.0").build();
+ filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.Operational").typeVersion(VERSION_000)
+ .build();
filteredList = filter.filter(policyList);
assertEquals(4, filteredList.size());
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java
index 2ec2422a9..0b43173ad 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java
@@ -65,7 +65,7 @@ public class ToscaPolicyIdentifierOptVersionTest extends ToscaIdentifierTestBase
}
@Test
- public void testCopyToscaPolicyIdentifierConstructor() throws Exception {
+ public void testCopyToscaPolicyIdentifierConstructor() {
assertThatThrownBy(() -> new ToscaPolicyIdentifierOptVersion((ToscaPolicyIdentifier) null))
.isInstanceOf(NullPointerException.class);
@@ -85,6 +85,7 @@ public class ToscaPolicyIdentifierOptVersionTest extends ToscaIdentifierTestBase
}
@Test
+ @Override
public void testCompareTo() throws Exception {
super.testCompareTo();
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java
index f31abf837..cc40e2410 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java
@@ -85,6 +85,7 @@ public class ToscaPolicyIdentifierTest extends ToscaIdentifierTestBase<ToscaPoli
}
@Test
+ @Override
public void testCompareTo() throws Exception {
super.testCompareTo();
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java
index e0143e676..5fbad5559 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,6 +49,10 @@ import org.yaml.snakeyaml.Yaml;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class ToscaPolicyTypeFilterTest {
+ private static final String VERSION_100 = "1.0.0";
+
+ private static final String VERSION_000 = "0.0.0";
+
// Logger for this class
private static final Logger LOGGER = LoggerFactory.getLogger(ToscaPolicyTypeFilterTest.class);
@@ -86,18 +91,7 @@ public class ToscaPolicyTypeFilterTest {
assertNotNull(serviceTemplate);
for (Map<String, ToscaPolicyType> foundPolicyTypeMap : serviceTemplate.getPolicyTypes()) {
- for (Entry<String, ToscaPolicyType> policyTypeEntry : foundPolicyTypeMap.entrySet()) {
- ToscaPolicyType policyType = policyTypeEntry.getValue();
- if (policyType.getName() == null) {
- policyType.setName(policyTypeEntry.getKey());
- }
- if (policyType.getVersion() == null) {
- policyType.setVersion(PfKey.NULL_KEY_VERSION);
- }
- if (!typeList.contains(policyType)) {
- typeList.add(policyType);
- }
- }
+ addPolicyTypes(foundPolicyTypeMap);
}
}
@@ -106,6 +100,21 @@ public class ToscaPolicyTypeFilterTest {
}
}
+ private static void addPolicyTypes(Map<String, ToscaPolicyType> foundPolicyTypeMap) {
+ for (Entry<String, ToscaPolicyType> policyTypeEntry : foundPolicyTypeMap.entrySet()) {
+ ToscaPolicyType policyType = policyTypeEntry.getValue();
+ if (policyType.getName() == null) {
+ policyType.setName(policyTypeEntry.getKey());
+ }
+ if (policyType.getVersion() == null) {
+ policyType.setVersion(PfKey.NULL_KEY_VERSION);
+ }
+ if (!typeList.contains(policyType)) {
+ typeList.add(policyType);
+ }
+ }
+ }
+
@Test
public void testNullList() {
ToscaPolicyTypeFilter filter = ToscaPolicyTypeFilter.builder().build();
@@ -130,20 +139,20 @@ public class ToscaPolicyTypeFilterTest {
List<ToscaPolicyType> filteredList = filter.filter(typeList);
assertEquals(13, filteredList.size());
- assertEquals("1.0.0", filteredList.get(0).getVersion());
- assertEquals("0.0.0", filteredList.get(4).getVersion());
+ assertEquals(VERSION_100, filteredList.get(0).getVersion());
+ assertEquals(VERSION_000, filteredList.get(4).getVersion());
typeList.get(12).setVersion("2.0.0");
filteredList = filter.filter(typeList);
assertEquals(13, filteredList.size());
assertEquals("2.0.0", filteredList.get(0).getVersion());
- assertEquals("0.0.0", filteredList.get(4).getVersion());
+ assertEquals(VERSION_000, filteredList.get(4).getVersion());
- typeList.get(12).setVersion("1.0.0");
+ typeList.get(12).setVersion(VERSION_100);
filteredList = filter.filter(typeList);
assertEquals(13, filteredList.size());
- assertEquals("1.0.0", filteredList.get(0).getVersion());
- assertEquals("0.0.0", filteredList.get(4).getVersion());
+ assertEquals(VERSION_100, filteredList.get(0).getVersion());
+ assertEquals(VERSION_000, filteredList.get(4).getVersion());
}
@Test
@@ -160,11 +169,12 @@ public class ToscaPolicyTypeFilterTest {
filteredList = filter.filter(typeList);
assertEquals(0, filteredList.size());
- filter = ToscaPolicyTypeFilter.builder().version("0.0.0").build();
+ filter = ToscaPolicyTypeFilter.builder().version(VERSION_000).build();
filteredList = filter.filter(typeList);
assertEquals(9, filteredList.size());
- filter = ToscaPolicyTypeFilter.builder().name("onap.policies.optimization.Vim_fit").version("0.0.0").build();
+ filter = ToscaPolicyTypeFilter.builder().name("onap.policies.optimization.Vim_fit").version(VERSION_000)
+ .build();
filteredList = filter.filter(typeList);
assertEquals(1, filteredList.size());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java
index e440dd6da..a5e0431b2 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java
@@ -85,6 +85,7 @@ public class ToscaPolicyTypeIdentifierTest extends ToscaIdentifierTestBase<Tosca
}
@Test
+ @Override
public void testCompareTo() throws Exception {
super.testCompareTo();
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java
index 10f3b0db2..6c87d7681 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,6 +56,12 @@ import org.yaml.snakeyaml.Yaml;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class AuthorativeToscaProviderPolicyTest {
+ private static final String VERSION = "version";
+ private static final String VCPE_JSON = "policies/vCPE.policy.monitoring.input.tosca.json";
+ private static final String POLICY_AND_VERSION = "onap.restart.tca:1.0.0";
+ private static final String POLICY1 = "onap.restart.tca";
+ private static final String DAO_IS_NULL = "dao is marked @NonNull but is null";
+ private static final String VERSION_100 = "1.0.0";
private PfDao pfDao;
private StandardCoder standardCoder;
@@ -93,7 +100,7 @@ public class AuthorativeToscaProviderPolicyTest {
}
@After
- public void teardown() throws Exception {
+ public void teardown() {
pfDao.close();
}
@@ -101,23 +108,23 @@ public class AuthorativeToscaProviderPolicyTest {
public void testPoliciesGet() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getPolicies(null, null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getPolicyList(null, null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
createPolicyTypes();
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+ ResourceUtils.getResourceAsString(VCPE_JSON),
ToscaServiceTemplate.class);
assertNotNull(toscaServiceTemplate);
ToscaServiceTemplate createdServiceTemplate =
new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
- PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
+ PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION);
ToscaPolicy beforePolicy =
toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
@@ -135,11 +142,11 @@ public class AuthorativeToscaProviderPolicyTest {
assertTrue(beforePolicy.getType().equals(gotPolicy.getType()));
List<ToscaPolicy> gotPolicyList =
- new AuthorativeToscaProvider().getPolicyList(pfDao, "onap.restart.tca", "1.0.0");
+ new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100);
assertEquals(1, gotPolicyList.size());
assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
- gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, "onap.restart.tca", null);
+ gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, null);
assertEquals(1, gotPolicyList.size());
assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
@@ -147,11 +154,11 @@ public class AuthorativeToscaProviderPolicyTest {
assertEquals(1, gotPolicyList.size());
assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
- gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, null, "1.0.0");
+ gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, null, VERSION_100);
assertEquals(1, gotPolicyList.size());
assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
- gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, "Nonexistant", "1.0.0");
+ gotPolicyList = new AuthorativeToscaProvider().getPolicyList(pfDao, "Nonexistant", VERSION_100);
assertEquals(0, gotPolicyList.size());
}
@@ -159,11 +166,11 @@ public class AuthorativeToscaProviderPolicyTest {
public void testPoliciesGetFiltered() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicies(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicies(null, ToscaPolicyFilter.builder().build());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicies(pfDao, null);
@@ -171,11 +178,11 @@ public class AuthorativeToscaProviderPolicyTest {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyList(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyList(null, ToscaPolicyFilter.builder().build());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyList(pfDao, null);
@@ -184,14 +191,14 @@ public class AuthorativeToscaProviderPolicyTest {
createPolicyTypes();
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+ ResourceUtils.getResourceAsString(VCPE_JSON),
ToscaServiceTemplate.class);
assertNotNull(toscaServiceTemplate);
ToscaServiceTemplate createdServiceTemplate =
new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
- PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
+ PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION);
ToscaPolicy beforePolicy =
toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
@@ -216,14 +223,14 @@ public class AuthorativeToscaProviderPolicyTest {
assertTrue(beforePolicy.getType().equals(gotPolicy.getType()));
gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicies(pfDao,
- ToscaPolicyFilter.builder().name(policyKey.getName()).version("1.0.0").build());
+ ToscaPolicyFilter.builder().name(policyKey.getName()).version(VERSION_100).build());
gotPolicy = gotServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicy));
assertTrue(beforePolicy.getType().equals(gotPolicy.getType()));
List<ToscaPolicy> gotPolicyList =
- new AuthorativeToscaProvider().getPolicyList(pfDao, "onap.restart.tca", "1.0.0");
+ new AuthorativeToscaProvider().getPolicyList(pfDao, POLICY1, VERSION_100);
assertEquals(1, gotPolicyList.size());
assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
@@ -238,7 +245,7 @@ public class AuthorativeToscaProviderPolicyTest {
assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
gotPolicyList = new AuthorativeToscaProvider().getFilteredPolicyList(pfDao,
- ToscaPolicyFilter.builder().name(policyKey.getName()).version("1.0.0").build());
+ ToscaPolicyFilter.builder().name(policyKey.getName()).version(VERSION_100).build());
assertEquals(1, gotPolicyList.size());
assertEquals(0, beforePolicy.compareNameVersion(beforePolicy, gotPolicyList.get(0)));
}
@@ -247,11 +254,11 @@ public class AuthorativeToscaProviderPolicyTest {
public void testPolicyCreate() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicies(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicies(null, new ToscaServiceTemplate());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicies(pfDao, null);
@@ -260,14 +267,14 @@ public class AuthorativeToscaProviderPolicyTest {
createPolicyTypes();
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+ ResourceUtils.getResourceAsString(VCPE_JSON),
ToscaServiceTemplate.class);
assertNotNull(toscaServiceTemplate);
ToscaServiceTemplate createdServiceTemplate =
new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
- PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
+ PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION);
ToscaPolicy beforePolicy =
toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
@@ -281,15 +288,15 @@ public class AuthorativeToscaProviderPolicyTest {
public void testPolicyUpdate() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicies(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().updatePolicies(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().updatePolicies(null, new ToscaServiceTemplate());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().updatePolicies(pfDao, null);
@@ -298,14 +305,14 @@ public class AuthorativeToscaProviderPolicyTest {
createPolicyTypes();
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+ ResourceUtils.getResourceAsString(VCPE_JSON),
ToscaServiceTemplate.class);
assertNotNull(toscaServiceTemplate);
ToscaServiceTemplate createdServiceTemplate =
new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
- PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
+ PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION);
ToscaPolicy beforePolicy =
toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
@@ -327,26 +334,26 @@ public class AuthorativeToscaProviderPolicyTest {
public void testPoliciesDelete() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicy(null, null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
- new AuthorativeToscaProvider().deletePolicy(null, null, "version");
- }).hasMessage("dao is marked @NonNull but is null");
+ new AuthorativeToscaProvider().deletePolicy(null, null, VERSION);
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicy(null, "name", null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
- new AuthorativeToscaProvider().deletePolicy(null, "name", "version");
- }).hasMessage("dao is marked @NonNull but is null");
+ new AuthorativeToscaProvider().deletePolicy(null, "name", VERSION);
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicy(pfDao, null, null);
}).hasMessage("name is marked @NonNull but is null");
assertThatThrownBy(() -> {
- new AuthorativeToscaProvider().deletePolicy(pfDao, null, "version");
+ new AuthorativeToscaProvider().deletePolicy(pfDao, null, VERSION);
}).hasMessage("name is marked @NonNull but is null");
assertThatThrownBy(() -> {
@@ -356,14 +363,14 @@ public class AuthorativeToscaProviderPolicyTest {
createPolicyTypes();
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+ ResourceUtils.getResourceAsString(VCPE_JSON),
ToscaServiceTemplate.class);
assertNotNull(toscaServiceTemplate);
ToscaServiceTemplate createdServiceTemplate =
new AuthorativeToscaProvider().createPolicies(pfDao, toscaServiceTemplate);
- PfConceptKey policyKey = new PfConceptKey("onap.restart.tca:1.0.0");
+ PfConceptKey policyKey = new PfConceptKey(POLICY_AND_VERSION);
ToscaPolicy beforePolicy =
toscaServiceTemplate.getToscaTopologyTemplate().getPolicies().get(0).get(policyKey.getName());
@@ -387,7 +394,7 @@ public class AuthorativeToscaProviderPolicyTest {
}
@Test
- public void testAssertPoliciesExist() throws PfModelException {
+ public void testAssertPoliciesExist() {
ToscaServiceTemplate testServiceTemplate = new ToscaServiceTemplate();
assertThatThrownBy(() -> {
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java
index ded2cdee2..e360dcda8 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,11 +27,9 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import com.google.gson.GsonBuilder;
-
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
-
import org.apache.commons.lang3.ObjectUtils;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.junit.After;
@@ -40,7 +39,6 @@ import org.junit.Test;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.dao.DaoParameters;
import org.onap.policy.models.dao.PfDao;
import org.onap.policy.models.dao.PfDaoFactory;
@@ -57,6 +55,12 @@ import org.yaml.snakeyaml.Yaml;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class AuthorativeToscaProviderPolicyTypeTest {
+ private static final String VERSION = "version";
+ private static final String POLICY_AFFINITY_VERSION0 = "onap.policies.optimization.AffinityPolicy:0.0.0";
+ private static final String POLICY_AFFINITY = "onap.policies.optimization.AffinityPolicy";
+ private static final String MISSING_POLICY_TYPES = "no policy types specified on service template";
+ private static final String DAO_IS_NULL = "dao is marked @NonNull but is null";
+ private static final String VERSION_000 = "0.0.0";
private static String yamlAsJsonString;
private PfDao pfDao;
private StandardCoder standardCoder;
@@ -111,7 +115,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
}
@After
- public void teardown() throws Exception {
+ public void teardown() {
pfDao.close();
}
@@ -119,11 +123,11 @@ public class AuthorativeToscaProviderPolicyTypeTest {
public void testPolicyTypesGet() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getPolicyTypes(null, null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getPolicyList(null, null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(yamlAsJsonString, ToscaServiceTemplate.class);
@@ -131,7 +135,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
ToscaServiceTemplate createdServiceTemplate =
new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate);
- PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0");
+ PfConceptKey policyTypeKey = new PfConceptKey(POLICY_AFFINITY_VERSION0);
ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
@@ -146,12 +150,12 @@ public class AuthorativeToscaProviderPolicyTypeTest {
assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), createdPolicyType.getDescription()));
List<ToscaPolicyType> gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao,
- "onap.policies.optimization.AffinityPolicy", "0.0.0");
+ POLICY_AFFINITY, VERSION_000);
assertEquals(1, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao,
- "onap.policies.optimization.AffinityPolicy", null);
+ POLICY_AFFINITY, null);
assertEquals(1, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
@@ -159,7 +163,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
assertEquals(2, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
- gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, null, "0.0.0");
+ gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao, null, VERSION_000);
assertEquals(2, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
}
@@ -169,11 +173,11 @@ public class AuthorativeToscaProviderPolicyTypeTest {
public void testPolicyTypesGetFiltered() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyTypes(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyTypes(null, ToscaPolicyTypeFilter.builder().build());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, null);
@@ -181,11 +185,11 @@ public class AuthorativeToscaProviderPolicyTypeTest {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyTypeList(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyTypeList(null, ToscaPolicyTypeFilter.builder().build());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao, null);
@@ -197,7 +201,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
ToscaServiceTemplate createdServiceTemplate =
new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate);
- PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0");
+ PfConceptKey policyTypeKey = new PfConceptKey(POLICY_AFFINITY_VERSION0);
ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
@@ -219,14 +223,14 @@ public class AuthorativeToscaProviderPolicyTypeTest {
assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription()));
gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao,
- ToscaPolicyTypeFilter.builder().name(policyTypeKey.getName()).version("0.0.0").build());
+ ToscaPolicyTypeFilter.builder().name(policyTypeKey.getName()).version(VERSION_000).build());
gotPolicyType = gotServiceTemplate.getPolicyTypes().get(0).get(policyTypeKey.getName());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription()));
List<ToscaPolicyType> gotPolicyTypeList = new AuthorativeToscaProvider().getPolicyTypeList(pfDao,
- "onap.policies.optimization.AffinityPolicy", "0.0.0");
+ POLICY_AFFINITY, VERSION_000);
assertEquals(1, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
@@ -241,7 +245,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
gotPolicyTypeList = new AuthorativeToscaProvider().getFilteredPolicyTypeList(pfDao,
- ToscaPolicyTypeFilter.builder().name(policyTypeKey.getName()).version("0.0.0").build());
+ ToscaPolicyTypeFilter.builder().name(policyTypeKey.getName()).version(VERSION_000).build());
assertEquals(1, gotPolicyTypeList.size());
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
@@ -255,11 +259,11 @@ public class AuthorativeToscaProviderPolicyTypeTest {
public void testPolicyTypesCreate() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicyTypes(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicyTypes(null, new ToscaServiceTemplate());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicyTypes(pfDao, null);
@@ -268,7 +272,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
ToscaServiceTemplate testToscaServiceTemplate = new ToscaServiceTemplate();
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicyTypes(pfDao, testToscaServiceTemplate);
- }).hasMessage("no policy types specified on service template");
+ }).hasMessage(MISSING_POLICY_TYPES);
testToscaServiceTemplate.setPolicyTypes(new ArrayList<>());
assertThatThrownBy(() -> {
@@ -281,7 +285,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
ToscaServiceTemplate createdServiceTemplate =
new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate);
- PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0");
+ PfConceptKey policyTypeKey = new PfConceptKey(POLICY_AFFINITY_VERSION0);
ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
@@ -293,15 +297,15 @@ public class AuthorativeToscaProviderPolicyTypeTest {
public void testPolicyTypesUpdate() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicyTypes(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().updatePolicyTypes(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().updatePolicyTypes(null, new ToscaServiceTemplate());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().updatePolicyTypes(pfDao, null);
@@ -313,7 +317,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
ToscaServiceTemplate createdServiceTemplate =
new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate);
- PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0");
+ PfConceptKey policyTypeKey = new PfConceptKey(POLICY_AFFINITY_VERSION0);
ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
@@ -332,26 +336,26 @@ public class AuthorativeToscaProviderPolicyTypeTest {
public void testPolicyTypesDelete() throws Exception {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicyType(null, null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
- new AuthorativeToscaProvider().deletePolicyType(null, null, "version");
- }).hasMessage("dao is marked @NonNull but is null");
+ new AuthorativeToscaProvider().deletePolicyType(null, null, VERSION);
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicyType(null, "name", null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
- new AuthorativeToscaProvider().deletePolicyType(null, "name", "version");
- }).hasMessage("dao is marked @NonNull but is null");
+ new AuthorativeToscaProvider().deletePolicyType(null, "name", VERSION);
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().deletePolicyType(pfDao, null, null);
}).hasMessage("name is marked @NonNull but is null");
assertThatThrownBy(() -> {
- new AuthorativeToscaProvider().deletePolicyType(pfDao, null, "version");
+ new AuthorativeToscaProvider().deletePolicyType(pfDao, null, VERSION);
}).hasMessage("name is marked @NonNull but is null");
assertThatThrownBy(() -> {
@@ -364,7 +368,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
ToscaServiceTemplate createdServiceTemplate =
new AuthorativeToscaProvider().createPolicyTypes(pfDao, toscaServiceTemplate);
- PfConceptKey policyTypeKey = new PfConceptKey("onap.policies.optimization.AffinityPolicy:0.0.0");
+ PfConceptKey policyTypeKey = new PfConceptKey(POLICY_AFFINITY_VERSION0);
ToscaPolicyType beforePolicyType = toscaServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
ToscaPolicyType createdPolicyType = createdServiceTemplate.getPolicyTypes().get(1).get(policyTypeKey.getName());
@@ -385,7 +389,7 @@ public class AuthorativeToscaProviderPolicyTypeTest {
}
@Test
- public void testAssertPoliciesExist() throws PfModelException {
+ public void testAssertPoliciesExist() {
ToscaServiceTemplate testServiceTemplate = new ToscaServiceTemplate();
assertThatThrownBy(() -> {
@@ -394,12 +398,12 @@ public class AuthorativeToscaProviderPolicyTypeTest {
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicyTypes(pfDao, testServiceTemplate);
- }).hasMessage("no policy types specified on service template");
+ }).hasMessage(MISSING_POLICY_TYPES);
testServiceTemplate.setToscaTopologyTemplate(new ToscaTopologyTemplate());
assertThatThrownBy(() -> {
new AuthorativeToscaProvider().createPolicyTypes(pfDao, testServiceTemplate);
- }).hasMessage("no policy types specified on service template");
+ }).hasMessage(MISSING_POLICY_TYPES);
testServiceTemplate.setPolicyTypes(new ArrayList<>());
assertThatThrownBy(() -> {
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java
index b44853428..82f75a721 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/ToscaServiceTemplateMappingTest.java
@@ -25,7 +25,6 @@ package org.onap.policy.models.tosca.authorative.provider;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
@@ -35,8 +34,6 @@ import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;
/**
@@ -45,7 +42,6 @@ import org.yaml.snakeyaml.Yaml;
* @author Chenfei Gao (cgao@research.att.com)
*/
public class ToscaServiceTemplateMappingTest {
- private static final Logger LOGGER = LoggerFactory.getLogger(ToscaServiceTemplateMappingTest.class);
private StandardCoder standardCoder;
@@ -56,51 +52,38 @@ public class ToscaServiceTemplateMappingTest {
@Test
public void testPlainToscaPolicies() throws Exception {
- try {
- String inputJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json");
+ String inputJson = ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json");
- ToscaServiceTemplate plainPolicies = standardCoder.decode(inputJson, ToscaServiceTemplate.class);
- JpaToscaServiceTemplate internalPolicies = new JpaToscaServiceTemplate();
- internalPolicies.fromAuthorative(plainPolicies);
+ ToscaServiceTemplate plainPolicies = standardCoder.decode(inputJson, ToscaServiceTemplate.class);
+ JpaToscaServiceTemplate internalPolicies = new JpaToscaServiceTemplate();
+ internalPolicies.fromAuthorative(plainPolicies);
- assertTrue(internalPolicies.validate(new PfValidationResult()).isValid());
- ToscaServiceTemplate plainPolicies2 = internalPolicies.toAuthorative();
+ assertTrue(internalPolicies.validate(new PfValidationResult()).isValid());
+ ToscaServiceTemplate plainPolicies2 = internalPolicies.toAuthorative();
- ToscaPolicy pp1 = plainPolicies.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
- ToscaPolicy pp2 = plainPolicies2.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
+ ToscaPolicy pp1 = plainPolicies.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
+ ToscaPolicy pp2 = plainPolicies2.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
- assertEquals(pp1.getProperties().keySet(), pp2.getProperties().keySet());
-
- } catch (Exception e) {
- LOGGER.warn("no exception should be thrown", e);
- fail("no exception should be thrown");
- }
+ assertEquals(pp1.getProperties().keySet(), pp2.getProperties().keySet());
}
@Test
public void testPlainToscaPolicyTypes() throws Exception {
- try {
- Yaml yaml = new Yaml();
- String inputYaml = ResourceUtils.getResourceAsString(
- "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml");
- Object yamlObject = yaml.load(inputYaml);
- String yamlAsJsonString = standardCoder.encode(yamlObject);
-
- ToscaServiceTemplate plainPolicyTypes = standardCoder.decode(yamlAsJsonString,
- ToscaServiceTemplate.class);
- JpaToscaServiceTemplate internalPolicyTypes = new JpaToscaServiceTemplate();
- internalPolicyTypes.fromAuthorative(plainPolicyTypes);
- assertTrue(internalPolicyTypes.validate(new PfValidationResult()).isValid());
- ToscaServiceTemplate plainPolicyTypes2 = internalPolicyTypes.toAuthorative();
- JpaToscaServiceTemplate internalPolicyTypes2 = new JpaToscaServiceTemplate();
- internalPolicyTypes2.fromAuthorative(plainPolicyTypes2);
- assertTrue(internalPolicyTypes2.validate(new PfValidationResult()).isValid());
- assertTrue(internalPolicyTypes.compareTo(internalPolicyTypes2) == 0);
-
- } catch (Exception e) {
- LOGGER.warn("no exception should be thrown", e);
- fail("no exception should be thrown");
- }
-
+ Yaml yaml = new Yaml();
+ String inputYaml = ResourceUtils.getResourceAsString(
+ "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml");
+ Object yamlObject = yaml.load(inputYaml);
+ String yamlAsJsonString = standardCoder.encode(yamlObject);
+
+ ToscaServiceTemplate plainPolicyTypes = standardCoder.decode(yamlAsJsonString,
+ ToscaServiceTemplate.class);
+ JpaToscaServiceTemplate internalPolicyTypes = new JpaToscaServiceTemplate();
+ internalPolicyTypes.fromAuthorative(plainPolicyTypes);
+ assertTrue(internalPolicyTypes.validate(new PfValidationResult()).isValid());
+ ToscaServiceTemplate plainPolicyTypes2 = internalPolicyTypes.toAuthorative();
+ JpaToscaServiceTemplate internalPolicyTypes2 = new JpaToscaServiceTemplate();
+ internalPolicyTypes2.fromAuthorative(plainPolicyTypes2);
+ assertTrue(internalPolicyTypes2.validate(new PfValidationResult()).isValid());
+ assertTrue(internalPolicyTypes.compareTo(internalPolicyTypes2) == 0);
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java
index 9c2344080..e06692ab0 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/concepts/LegacyGuardPolicyTest.java
@@ -49,8 +49,6 @@ public class LegacyGuardPolicyTest {
assertEquals("SO", guard.getContent().getActor());
DummyBadLegacyGuardPolicyContent dblgpc = new DummyBadLegacyGuardPolicyContent();
- assertThatThrownBy(() -> {
- dblgpc.getAsPropertyMap();
- }).hasMessage("could not convert content to a property map");
+ assertThatThrownBy(dblgpc::getAsPropertyMap).hasMessage("could not convert content to a property map");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java
index 4df62aff0..e9761c669 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/mapping/LegacyOperationalPolicyMapperTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -77,7 +78,7 @@ public class LegacyOperationalPolicyMapperTest {
}
@Test
- public void testOperationalPolicyMapper() throws Exception {
+ public void testOperationalPolicyMapper() {
JpaToscaServiceTemplate serviceTemplate = new JpaToscaServiceTemplate();
serviceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
serviceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java
index be5fa5dc3..59605ed5b 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -52,6 +53,11 @@ import org.yaml.snakeyaml.Yaml;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class LegacyProvider4LegacyGuardTest {
+ private static final String POLICY_ID_IS_NULL = "policyId is marked @NonNull but is null";
+ private static final String VDNS_OUTPUT_JSON = "policies/vDNS.policy.guard.frequency.output.json";
+ private static final String VDNS_INPUT_JSON = "policies/vDNS.policy.guard.frequency.input.json";
+ private static final String LEGACY_POLICY_IS_NULL = "legacyGuardPolicy is marked @NonNull but is null";
+ private static final String DAO_IS_NULL = "dao is marked @NonNull but is null";
private PfDao pfDao;
private StandardCoder standardCoder;
@@ -91,7 +97,7 @@ public class LegacyProvider4LegacyGuardTest {
}
@After
- public void teardown() throws Exception {
+ public void teardown() {
pfDao.close();
}
@@ -99,15 +105,15 @@ public class LegacyProvider4LegacyGuardTest {
public void testPoliciesGet() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().getGuardPolicy(null, null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().getGuardPolicy(null, null, "");
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().getGuardPolicy(pfDao, null, null);
- }).hasMessage("policyId is marked @NonNull but is null");
+ }).hasMessage(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().getGuardPolicy(pfDao, "I Dont Exist", null);
@@ -116,7 +122,7 @@ public class LegacyProvider4LegacyGuardTest {
createPolicyTypes();
LegacyGuardPolicyInput originalGip = standardCoder.decode(
- ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"),
+ ResourceUtils.getResourceAsString(VDNS_INPUT_JSON),
LegacyGuardPolicyInput.class);
assertNotNull(originalGip);
@@ -135,7 +141,7 @@ public class LegacyProvider4LegacyGuardTest {
gotGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next());
String expectedJsonOutput =
- ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.output.json");
+ ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON);
String actualJsonOutput = standardCoder.encode(gotGopm);
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
@@ -159,20 +165,20 @@ public class LegacyProvider4LegacyGuardTest {
public void testPolicyCreate() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().createGuardPolicy(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().createGuardPolicy(null, new LegacyGuardPolicyInput());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().createGuardPolicy(pfDao, null);
- }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
+ }).hasMessage(LEGACY_POLICY_IS_NULL);
createPolicyTypes();
LegacyGuardPolicyInput originalGip = standardCoder.decode(
- ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"),
+ ResourceUtils.getResourceAsString(VDNS_INPUT_JSON),
LegacyGuardPolicyInput.class);
assertNotNull(originalGip);
@@ -191,7 +197,7 @@ public class LegacyProvider4LegacyGuardTest {
gotGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next());
String expectedJsonOutput =
- ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.output.json");
+ ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON);
String actualJsonOutput = standardCoder.encode(gotGopm);
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
@@ -201,20 +207,20 @@ public class LegacyProvider4LegacyGuardTest {
public void testPolicyCreateBad() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().createGuardPolicy(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().createGuardPolicy(null, new LegacyGuardPolicyInput());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().createGuardPolicy(pfDao, null);
- }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
+ }).hasMessage(LEGACY_POLICY_IS_NULL);
createPolicyTypes();
LegacyGuardPolicyInput originalGip = standardCoder.decode(
- ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"),
+ ResourceUtils.getResourceAsString(VDNS_INPUT_JSON),
LegacyGuardPolicyInput.class);
assertNotNull(originalGip);
@@ -230,15 +236,15 @@ public class LegacyProvider4LegacyGuardTest {
public void testPolicyUpdate() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().updateGuardPolicy(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().updateGuardPolicy(null, new LegacyGuardPolicyInput());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().updateGuardPolicy(pfDao, null);
- }).hasMessage("legacyGuardPolicy is marked @NonNull but is null");
+ }).hasMessage(LEGACY_POLICY_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().updateGuardPolicy(pfDao, new LegacyGuardPolicyInput());
@@ -247,7 +253,7 @@ public class LegacyProvider4LegacyGuardTest {
createPolicyTypes();
LegacyGuardPolicyInput originalGip = standardCoder.decode(
- ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"),
+ ResourceUtils.getResourceAsString(VDNS_INPUT_JSON),
LegacyGuardPolicyInput.class);
assertNotNull(originalGip);
@@ -284,27 +290,27 @@ public class LegacyProvider4LegacyGuardTest {
public void testPoliciesDelete() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().deleteGuardPolicy(null, null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteGuardPolicy(null, null, "");
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteGuardPolicy(null, "", null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteGuardPolicy(null, "", "");
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteGuardPolicy(pfDao, null, null);
- }).hasMessage("policyId is marked @NonNull but is null");
+ }).hasMessage(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteGuardPolicy(pfDao, null, "");
- }).hasMessage("policyId is marked @NonNull but is null");
+ }).hasMessage(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteGuardPolicy(pfDao, "", null);
@@ -317,7 +323,7 @@ public class LegacyProvider4LegacyGuardTest {
createPolicyTypes();
LegacyGuardPolicyInput originalGip = standardCoder.decode(
- ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.input.json"),
+ ResourceUtils.getResourceAsString(VDNS_INPUT_JSON),
LegacyGuardPolicyInput.class);
assertNotNull(originalGip);
@@ -335,7 +341,7 @@ public class LegacyProvider4LegacyGuardTest {
gotGopm.get(originalGip.getPolicyId()).getProperties().values().iterator().next());
String expectedJsonOutput =
- ResourceUtils.getResourceAsString("policies/vDNS.policy.guard.frequency.output.json");
+ ResourceUtils.getResourceAsString(VDNS_OUTPUT_JSON);
String actualJsonOutput = standardCoder.encode(gotGopm);
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java
index 636063641..dfbba4497 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,6 +50,10 @@ import org.yaml.snakeyaml.Yaml;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class LegacyProvider4LegacyOperationalTest {
+ private static final String POLICY_ID_IS_NULL = "policyId is marked @NonNull but is null";
+ private static final String VCPE_OUTPUT_JSON = "policies/vCPE.policy.operational.output.json";
+ private static final String VCPE_INPUT_JSON = "policies/vCPE.policy.operational.input.json";
+ private static final String DAO_IS_NULL = "dao is marked @NonNull but is null";
private PfDao pfDao;
private StandardCoder standardCoder;
@@ -87,7 +92,7 @@ public class LegacyProvider4LegacyOperationalTest {
}
@After
- public void teardown() throws Exception {
+ public void teardown() {
pfDao.close();
}
@@ -95,15 +100,15 @@ public class LegacyProvider4LegacyOperationalTest {
public void testPoliciesGet() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().getOperationalPolicy(null, null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().getOperationalPolicy(null, "", null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().getOperationalPolicy(pfDao, null, null);
- }).hasMessage("policyId is marked @NonNull but is null");
+ }).hasMessage(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().getOperationalPolicy(pfDao, "I Dont Exist", null);
@@ -112,7 +117,7 @@ public class LegacyProvider4LegacyOperationalTest {
createPolicyTypes();
LegacyOperationalPolicy originalLop =
- standardCoder.decode(ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"),
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON),
LegacyOperationalPolicy.class);
assertNotNull(originalLop);
@@ -126,7 +131,7 @@ public class LegacyProvider4LegacyOperationalTest {
assertEquals(gotLop, originalLop);
- String expectedJsonOutput = ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.output.json");
+ String expectedJsonOutput = ResourceUtils.getResourceAsString(VCPE_OUTPUT_JSON);
String actualJsonOutput = standardCoder.encode(gotLop);
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
@@ -141,11 +146,11 @@ public class LegacyProvider4LegacyOperationalTest {
public void testPolicyCreate() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().createOperationalPolicy(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().createOperationalPolicy(null, new LegacyOperationalPolicy());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().createOperationalPolicy(pfDao, null);
@@ -154,7 +159,7 @@ public class LegacyProvider4LegacyOperationalTest {
createPolicyTypes();
LegacyOperationalPolicy originalLop =
- standardCoder.decode(ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"),
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON),
LegacyOperationalPolicy.class);
assertNotNull(originalLop);
@@ -168,7 +173,7 @@ public class LegacyProvider4LegacyOperationalTest {
assertEquals(gotLop, originalLop);
- String expectedJsonOutput = ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.output.json");
+ String expectedJsonOutput = ResourceUtils.getResourceAsString(VCPE_OUTPUT_JSON);
String actualJsonOutput = standardCoder.encode(gotLop);
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
@@ -178,11 +183,11 @@ public class LegacyProvider4LegacyOperationalTest {
public void testPolicyUpdate() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().updateOperationalPolicy(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().updateOperationalPolicy(null, new LegacyOperationalPolicy());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().updateOperationalPolicy(pfDao, null);
@@ -195,7 +200,7 @@ public class LegacyProvider4LegacyOperationalTest {
createPolicyTypes();
LegacyOperationalPolicy originalLop =
- standardCoder.decode(ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"),
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON),
LegacyOperationalPolicy.class);
assertNotNull(originalLop);
@@ -221,29 +226,29 @@ public class LegacyProvider4LegacyOperationalTest {
public void testPoliciesDelete() throws Exception {
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(null, null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(null, null, "");
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(null, "", null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(null, "", "");
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(pfDao, null, null);
- }).hasMessage("policyId is marked @NonNull but is null");
+ }).hasMessage(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(pfDao, null, "");
- }).hasMessage("policyId is marked @NonNull but is null");
+ }).hasMessage(POLICY_ID_IS_NULL);
assertThatThrownBy(() -> {
new LegacyProvider().deleteOperationalPolicy(pfDao, "", null);
@@ -256,7 +261,7 @@ public class LegacyProvider4LegacyOperationalTest {
createPolicyTypes();
LegacyOperationalPolicy originalLop =
- standardCoder.decode(ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.input.json"),
+ standardCoder.decode(ResourceUtils.getResourceAsString(VCPE_INPUT_JSON),
LegacyOperationalPolicy.class);
assertNotNull(originalLop);
@@ -269,7 +274,7 @@ public class LegacyProvider4LegacyOperationalTest {
assertEquals(gotLop, originalLop);
- String expectedJsonOutput = ResourceUtils.getResourceAsString("policies/vCPE.policy.operational.output.json");
+ String expectedJsonOutput = ResourceUtils.getResourceAsString(VCPE_OUTPUT_JSON);
String actualJsonOutput = standardCoder.encode(gotLop);
assertEquals(expectedJsonOutput.replaceAll("\\s+", ""), actualJsonOutput.replaceAll("\\s+", ""));
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java
index d3239da73..e48f5f895 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintLogicalTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,30 +37,32 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
*/
public class JpaToscaConstraintLogicalTest {
+ private static final String HELLO = "Hello";
+
@Test
public void testLogicalConstraint() {
ToscaConstraint c0 = new ToscaConstraint();
- c0.setEqual("Hello");
+ c0.setEqual(HELLO);
JpaToscaConstraintLogical jc0 = new JpaToscaConstraintLogical(c0);
assertEquals(c0, jc0.toAuthorative());
ToscaConstraint c1 = new ToscaConstraint();
- c1.setGreaterOrEqual("Hello");
+ c1.setGreaterOrEqual(HELLO);
JpaToscaConstraintLogical jc1 = new JpaToscaConstraintLogical(c1);
assertEquals(c1, jc1.toAuthorative());
ToscaConstraint c2 = new ToscaConstraint();
- c2.setGreaterThan("Hello");
+ c2.setGreaterThan(HELLO);
JpaToscaConstraintLogical jc2 = new JpaToscaConstraintLogical(c2);
assertEquals(c2, jc2.toAuthorative());
ToscaConstraint c3 = new ToscaConstraint();
- c3.setLessOrEqual("Hello");
+ c3.setLessOrEqual(HELLO);
JpaToscaConstraintLogical jc3 = new JpaToscaConstraintLogical(c3);
assertEquals(c3, jc3.toAuthorative());
ToscaConstraint c4 = new ToscaConstraint();
- c4.setLessThan("Hello");
+ c4.setLessThan(HELLO);
JpaToscaConstraintLogical jc4 = new JpaToscaConstraintLogical(c4);
assertEquals(c4, jc4.toAuthorative());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintTest.java
index ff4187a47..ce5ace1c0 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,17 +21,15 @@
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
-
import org.junit.Test;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical;
/**
* DAO test for ToscaConstraintLogicalString.
@@ -39,32 +38,22 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraintLogical;
*/
public class JpaToscaConstraintTest {
+ private static final String CONSTRAINT = "Constraint";
+
@Test
public void testConstraintLogicalStringPojo() {
- assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint"));
+ assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, CONSTRAINT));
- try {
- new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("operation is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, null))
+ .hasMessage("operation is marked @NonNull but is null");
- try {
- new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, "Hello");
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("operation is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, "Hello"))
+ .hasMessage("operation is marked @NonNull but is null");
- try {
- new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("compareTo is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, null))
+ .hasMessage("compareTo is marked @NonNull but is null");
- assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint"));
+ assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, CONSTRAINT));
assertEquals(0, new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "")
.compareTo(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "")));
@@ -78,7 +67,7 @@ public class JpaToscaConstraintTest {
JpaToscaConstraintValidValues cvv0 = new JpaToscaConstraintValidValues(validValues);
assertEquals(-1, cvv0.compareTo(null));
assertEquals(0, cvv0.compareTo(cvv0));
- assertNotEquals(0, cvv0.compareTo(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "Constraint")));
+ assertNotEquals(0, cvv0.compareTo(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, CONSTRAINT)));
JpaToscaConstraintValidValues cvv1 = new JpaToscaConstraintValidValues(validValues);
assertEquals(0, cvv0.compareTo(cvv1));
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java
index 66cde51fc..591c65518 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,6 +49,8 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
*/
public class JpaToscaDataTypeTest {
+ private static final String VERSION_001 = "0.0.1";
+
@Test
public void testDataTypePojo() {
assertNotNull(new JpaToscaDataType());
@@ -63,7 +66,7 @@ public class JpaToscaDataTypeTest {
new JpaToscaDataType((JpaToscaDataType) null);
}).hasMessage("copyConcept is marked @NonNull but is null");
- PfConceptKey dtKey = new PfConceptKey("tdt", "0.0.1");
+ PfConceptKey dtKey = new PfConceptKey("tdt", VERSION_001);
JpaToscaDataType tdt = new JpaToscaDataType(dtKey);
List<JpaToscaConstraint> constraints = new ArrayList<>();
@@ -73,7 +76,8 @@ public class JpaToscaDataTypeTest {
assertEquals(constraints, tdt.getConstraints());
Map<String, JpaToscaProperty> properties = new LinkedHashMap<>();
- JpaToscaProperty tp = new JpaToscaProperty(new PfReferenceKey(dtKey, "pr"), new PfConceptKey("type", "0.0.1"));
+ JpaToscaProperty tp =
+ new JpaToscaProperty(new PfReferenceKey(dtKey, "pr"), new PfConceptKey("type", VERSION_001));
properties.put(tp.getKey().getLocalName(), tp);
tdt.setProperties(properties);
assertEquals(properties, tdt.getProperties());
@@ -91,7 +95,7 @@ public class JpaToscaDataTypeTest {
assertEquals(0, tdt.compareTo(tdt));
assertFalse(tdt.compareTo(tdt.getKey()) == 0);
- PfConceptKey otherDtKey = new PfConceptKey("otherDt", "0.0.1");
+ PfConceptKey otherDtKey = new PfConceptKey("otherDt", VERSION_001);
JpaToscaDataType otherDt = new JpaToscaDataType(otherDtKey);
assertFalse(tdt.compareTo(otherDt) == 0);
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java
index c732fa604..5421b953e 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,24 +21,22 @@
package org.onap.policy.models.tosca.simple.concepts;
-import static org.junit.Assert.assertEquals;
+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.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
public class JpaToscaDataTypesTest {
+ private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+
@Test
public void testDataTypes() {
assertNotNull(new JpaToscaDataTypes());
@@ -45,40 +44,18 @@ public class JpaToscaDataTypesTest {
assertNotNull(new JpaToscaDataTypes(new PfConceptKey(), new TreeMap<PfConceptKey, JpaToscaDataType>()));
assertNotNull(new JpaToscaDataTypes(new JpaToscaDataTypes()));
- try {
- new JpaToscaDataTypes((PfConceptKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaDataTypes((PfConceptKey) null)).hasMessage(KEY_IS_NULL);
- try {
- new JpaToscaDataTypes((JpaToscaDataTypes) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaDataTypes((JpaToscaDataTypes) null))
+ .hasMessage("copyConcept is marked @NonNull but is null");
- try {
- new JpaToscaDataTypes(null, null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaDataTypes(null, null)).hasMessage(KEY_IS_NULL);
- try {
- new JpaToscaDataTypes(new PfConceptKey(), null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("conceptMap is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaDataTypes(new PfConceptKey(), null))
+ .hasMessage("conceptMap is marked @NonNull but is null");
- try {
- new JpaToscaDataTypes(null, new TreeMap<PfConceptKey, JpaToscaDataType>());
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaDataTypes(null, new TreeMap<PfConceptKey, JpaToscaDataType>()))
+ .hasMessage(KEY_IS_NULL);
List<Map<String, ToscaDataType>> dtMapList = new ArrayList<>();
dtMapList.add(new LinkedHashMap<>());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchemaTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchemaTest.java
index 4a9bdbe2e..b306685d0 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchemaTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchemaTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,20 +21,17 @@
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
-
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema;
/**
* DAO test for ToscaEntrySchema.
@@ -42,30 +40,24 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntrySchema;
*/
public class JpaToscaEntrySchemaTest {
+ private static final String A_DESCRIPTION = "A Description";
+
@Test
public void testEntrySchemaPojo() {
assertNotNull(new JpaToscaEntrySchema(new PfConceptKey()));
assertNotNull(new JpaToscaEntrySchema(new JpaToscaEntrySchema(new PfConceptKey())));
- try {
- new JpaToscaEntrySchema((PfConceptKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("type is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaEntrySchema((PfConceptKey) null))
+ .hasMessage("type is marked @NonNull but is null");
- try {
- new JpaToscaEntrySchema((JpaToscaEntrySchema) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaEntrySchema((JpaToscaEntrySchema) null))
+ .hasMessage("copyConcept is marked @NonNull but is null");
PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey);
- tes.setDescription("A Description");
- assertEquals("A Description", tes.getDescription());
+ tes.setDescription(A_DESCRIPTION);
+ assertEquals(A_DESCRIPTION, tes.getDescription());
List<JpaToscaConstraint> constraints = new ArrayList<>();
JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
@@ -89,17 +81,12 @@ public class JpaToscaEntrySchemaTest {
assertFalse(tes.compareTo(otherEs) == 0);
otherEs.setType(typeKey);
assertFalse(tes.compareTo(otherEs) == 0);
- otherEs.setDescription("A Description");
+ otherEs.setDescription(A_DESCRIPTION);
assertFalse(tes.compareTo(otherEs) == 0);
otherEs.setConstraints(constraints);
assertEquals(0, tes.compareTo(otherEs));
- try {
- tes.copyTo(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("target is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> tes.copyTo(null)).hasMessage("target is marked @NonNull but is null");
assertEquals(1, tes.getKeys().size());
assertEquals(1, new JpaToscaEntrySchema(typeKey).getKeys().size());
@@ -120,7 +107,7 @@ public class JpaToscaEntrySchemaTest {
tes.setDescription("");;
assertFalse(tes.validate(new PfValidationResult()).isValid());
- tes.setDescription("A Description");
+ tes.setDescription(A_DESCRIPTION);
assertTrue(tes.validate(new PfValidationResult()).isValid());
tes.getConstraints().add(null);
@@ -128,11 +115,6 @@ public class JpaToscaEntrySchemaTest {
tes.getConstraints().remove(null);
assertTrue(tes.validate(new PfValidationResult()).isValid());
- try {
- tes.validate(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> tes.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java
index 19846a0cc..602985dda 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,17 +21,16 @@
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaEventFilter;
/**
* DAO test for ToscaEventFilter.
@@ -39,6 +39,11 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaEventFilter;
*/
public class JpaToscaEventFilterTest {
+ private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String A_REQUREMENT = "A Requrement";
+ private static final String A_CAPABILITY = "A Capability";
+ private static final String VERSION_001 = "0.0.1";
+
@Test
public void testEventFilterPojo() {
assertNotNull(new JpaToscaEventFilter());
@@ -46,51 +51,28 @@ public class JpaToscaEventFilterTest {
assertNotNull(new JpaToscaEventFilter(new PfReferenceKey(), new PfConceptKey()));
assertNotNull(new JpaToscaEventFilter(new JpaToscaEventFilter()));
- try {
- new JpaToscaEventFilter((PfReferenceKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaEventFilter(null, null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaEventFilter(null, new PfConceptKey());
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaEventFilter(new PfReferenceKey(), null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("node is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaEventFilter((JpaToscaEventFilter) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
- }
-
- PfConceptKey efParentKey = new PfConceptKey("tParentKey", "0.0.1");
+ assertThatThrownBy(() -> new JpaToscaEventFilter((PfReferenceKey) null)).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaEventFilter(null, null)).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaEventFilter(null, new PfConceptKey())).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaEventFilter(new PfReferenceKey(), null))
+ .hasMessage("node is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> new JpaToscaEventFilter((JpaToscaEventFilter) null))
+ .hasMessage("copyConcept is marked @NonNull but is null");
+
+ PfConceptKey efParentKey = new PfConceptKey("tParentKey", VERSION_001);
PfReferenceKey efKey = new PfReferenceKey(efParentKey, "trigger0");
- PfConceptKey nodeKey = new PfConceptKey("tParentKey", "0.0.1");
+ PfConceptKey nodeKey = new PfConceptKey("tParentKey", VERSION_001);
JpaToscaEventFilter tef = new JpaToscaEventFilter(efKey, nodeKey);
- tef.setRequirement("A Requrement");
- assertEquals("A Requrement", tef.getRequirement());
+ tef.setRequirement(A_REQUREMENT);
+ assertEquals(A_REQUREMENT, tef.getRequirement());
- tef.setCapability("A Capability");
- assertEquals("A Capability", tef.getCapability());
+ tef.setCapability(A_CAPABILITY);
+ assertEquals(A_CAPABILITY, tef.getCapability());
JpaToscaEventFilter tdtClone0 = new JpaToscaEventFilter(tef);
assertEquals(tef, tdtClone0);
@@ -105,7 +87,7 @@ public class JpaToscaEventFilterTest {
assertEquals(0, tef.compareTo(tef));
assertFalse(tef.compareTo(tef.getKey()) == 0);
- PfReferenceKey otherDtKey = new PfReferenceKey("otherDt", "0.0.1", "OtherEventFilter");
+ PfReferenceKey otherDtKey = new PfReferenceKey("otherDt", VERSION_001, "OtherEventFilter");
JpaToscaEventFilter otherDt = new JpaToscaEventFilter(otherDtKey);
assertFalse(tef.compareTo(otherDt) == 0);
@@ -113,17 +95,12 @@ public class JpaToscaEventFilterTest {
assertFalse(tef.compareTo(otherDt) == 0);
otherDt.setNode(nodeKey);
assertFalse(tef.compareTo(otherDt) == 0);
- otherDt.setRequirement("A Requrement");
+ otherDt.setRequirement(A_REQUREMENT);
assertFalse(tef.compareTo(otherDt) == 0);
- otherDt.setCapability("A Capability");
+ otherDt.setCapability(A_CAPABILITY);
assertEquals(0, tef.compareTo(otherDt));
- try {
- tef.copyTo(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("target is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> tef.copyTo(null)).hasMessage("target is marked @NonNull but is null");
assertEquals(2, tef.getKeys().size());
assertEquals(2, new JpaToscaEventFilter().getKeys().size());
@@ -139,14 +116,14 @@ public class JpaToscaEventFilterTest {
assertTrue(tef.validate(new PfValidationResult()).isValid());
tef.setRequirement("");
assertFalse(tef.validate(new PfValidationResult()).isValid());
- tef.setRequirement("A Requrement");
+ tef.setRequirement(A_REQUREMENT);
assertTrue(tef.validate(new PfValidationResult()).isValid());
tef.setCapability(null);
assertTrue(tef.validate(new PfValidationResult()).isValid());
tef.setCapability("");
assertFalse(tef.validate(new PfValidationResult()).isValid());
- tef.setCapability("A Capability");
+ tef.setCapability(A_CAPABILITY);
assertTrue(tef.validate(new PfValidationResult()).isValid());
tef.setNode(null);
@@ -156,11 +133,6 @@ public class JpaToscaEventFilterTest {
tef.setNode(nodeKey);
assertTrue(tef.validate(new PfValidationResult()).isValid());
- try {
- tef.validate(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> tef.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java
index a62c79956..40fbc0515 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,22 +21,18 @@
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Map;
import java.util.TreeMap;
-
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfModelService;
import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaModel;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplates;
/**
* DAO test for ToscaDatatype.
@@ -44,6 +41,9 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplates;
*/
public class JpaToscaModelTest {
+ private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String VERSION_001 = "0.0.1";
+
@Test
public void testModelPojo() {
assertNotNull(new JpaToscaModel());
@@ -51,45 +51,22 @@ public class JpaToscaModelTest {
assertNotNull(new JpaToscaModel(new PfConceptKey(), new JpaToscaServiceTemplates()));
assertNotNull(new JpaToscaModel(new JpaToscaModel()));
- try {
- new JpaToscaModel((PfConceptKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaModel(null, null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaModel(null, new JpaToscaServiceTemplates());
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaModel(new PfConceptKey(), null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("serviceTemplates is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaModel((JpaToscaModel) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
- }
-
- PfConceptKey tstsKey = new PfConceptKey("tsts", "0.0.1");
+ assertThatThrownBy(() -> new JpaToscaModel((PfConceptKey) null)).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaModel(null, null)).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaModel(null, new JpaToscaServiceTemplates())).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaModel(new PfConceptKey(), null))
+ .hasMessage("serviceTemplates is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> new JpaToscaModel((JpaToscaModel) null))
+ .hasMessage("copyConcept is marked @NonNull but is null");
+
+ PfConceptKey tstsKey = new PfConceptKey("tsts", VERSION_001);
Map<PfConceptKey, JpaToscaServiceTemplate> tstMap = new TreeMap<>();
JpaToscaServiceTemplates tsts = new JpaToscaServiceTemplates(tstsKey, tstMap);
- PfConceptKey tmKey = new PfConceptKey("tst", "0.0.1");
+ PfConceptKey tmKey = new PfConceptKey("tst", VERSION_001);
JpaToscaModel tm = new JpaToscaModel(tmKey, tsts);
JpaToscaModel tttClone0 = new JpaToscaModel(tm);
@@ -105,7 +82,7 @@ public class JpaToscaModelTest {
assertEquals(0, tm.compareTo(tm));
assertFalse(tm.compareTo(tm.getKey()) == 0);
- PfConceptKey otherDtKey = new PfConceptKey("otherDt", "0.0.1");
+ PfConceptKey otherDtKey = new PfConceptKey("otherDt", VERSION_001);
JpaToscaModel otherDt = new JpaToscaModel(otherDtKey);
assertFalse(tm.compareTo(otherDt) == 0);
@@ -114,12 +91,7 @@ public class JpaToscaModelTest {
otherDt.setServiceTemplates(tsts);
assertEquals(0, tm.compareTo(otherDt));
- try {
- tm.copyTo(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("targetObject is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> tm.copyTo(null)).hasMessage("targetObject is marked @NonNull but is null");
assertEquals(2, tm.getKeys().size());
assertEquals(2, new JpaToscaModel().getKeys().size());
@@ -135,11 +107,6 @@ public class JpaToscaModelTest {
assertTrue(PfModelService.existsModel(tm.getServiceTemplates().getId()));
PfModelService.deregisterModel(tm.getServiceTemplates().getId());
- try {
- tm.validate(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> tm.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java
index db3635ecb..10616f2eb 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,24 +21,22 @@
package org.onap.policy.models.tosca.simple.concepts;
-import static org.junit.Assert.assertEquals;
+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.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
public class JpaToscaPoliciesTest {
+ private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+
@Test
public void testPolicies() {
assertNotNull(new JpaToscaPolicies());
@@ -45,40 +44,18 @@ public class JpaToscaPoliciesTest {
assertNotNull(new JpaToscaPolicies(new PfConceptKey(), new TreeMap<PfConceptKey, JpaToscaPolicy>()));
assertNotNull(new JpaToscaPolicies(new JpaToscaPolicies()));
- try {
- new JpaToscaPolicies((PfConceptKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaPolicies((PfConceptKey) null)).hasMessage(KEY_IS_NULL);
- try {
- new JpaToscaPolicies((JpaToscaPolicies) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaPolicies((JpaToscaPolicies) null))
+ .hasMessage("copyConcept is marked @NonNull but is null");
- try {
- new JpaToscaPolicies(null, null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaPolicies(null, null)).hasMessage(KEY_IS_NULL);
- try {
- new JpaToscaPolicies(new PfConceptKey(), null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("conceptMap is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaPolicies(new PfConceptKey(), null))
+ .hasMessage("conceptMap is marked @NonNull but is null");
- try {
- new JpaToscaPolicies(null, new TreeMap<PfConceptKey, JpaToscaPolicy>());
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaPolicies(null, new TreeMap<PfConceptKey, JpaToscaPolicy>()))
+ .hasMessage(KEY_IS_NULL);
List<Map<String, ToscaPolicy>> polMapList = new ArrayList<>();
polMapList.add(new LinkedHashMap<>());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
index 924cdab53..bb961783c 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -45,6 +46,9 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
*/
public class JpaToscaPolicyTest {
+ private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String VERSION_001 = "0.0.1";
+
@Test
public void testPolicyPojo() {
assertNotNull(new JpaToscaPolicy());
@@ -58,11 +62,11 @@ public class JpaToscaPolicyTest {
assertThatThrownBy(() -> {
new JpaToscaPolicy((PfConceptKey) null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessage(KEY_IS_NULL);
assertThatThrownBy(() -> {
new JpaToscaPolicy(null, null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessage(KEY_IS_NULL);
assertThatThrownBy(() -> {
new JpaToscaPolicy(new PfConceptKey(), null);
@@ -70,14 +74,14 @@ public class JpaToscaPolicyTest {
assertThatThrownBy(() -> {
new JpaToscaPolicy(null, new PfConceptKey());
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessage(KEY_IS_NULL);
assertThatThrownBy(() -> {
new JpaToscaPolicy((JpaToscaPolicy) null);
}).hasMessage("copyConcept is marked @NonNull but is null");
- PfConceptKey tpKey = new PfConceptKey("tdt", "0.0.1");
- PfConceptKey ptKey = new PfConceptKey("policyType", "0.0.1");
+ PfConceptKey tpKey = new PfConceptKey("tdt", VERSION_001);
+ PfConceptKey ptKey = new PfConceptKey("policyType", VERSION_001);
JpaToscaPolicy tp = new JpaToscaPolicy(tpKey, ptKey);
Map<String, String> propertyMap = new HashMap<>();
@@ -86,7 +90,7 @@ public class JpaToscaPolicyTest {
assertEquals(propertyMap, tp.getProperties());
List<PfConceptKey> targets = new ArrayList<>();
- PfConceptKey target = new PfConceptKey("target", "0.0.1");
+ PfConceptKey target = new PfConceptKey("target", VERSION_001);
targets.add(target);
tp.setTargets(targets);
assertEquals(targets, tp.getTargets());
@@ -104,7 +108,7 @@ public class JpaToscaPolicyTest {
assertEquals(0, tp.compareTo(tp));
assertFalse(tp.compareTo(tp.getKey()) == 0);
- PfConceptKey otherDtKey = new PfConceptKey("otherDt", "0.0.1");
+ PfConceptKey otherDtKey = new PfConceptKey("otherDt", VERSION_001);
JpaToscaPolicy otherDt = new JpaToscaPolicy(otherDtKey);
assertFalse(tp.compareTo(otherDt) == 0);
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java
index 3cdcd9552..eb94a5ecc 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,28 +21,23 @@
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaEntityType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger;
/**
* DAO test for ToscaPolicyType.
@@ -49,30 +45,25 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class JpaToscaPolicyTypeTest {
+ private static final String A_DESCRIPTION = "A Description";
+ private static final String VERSION_001 = "0.0.1";
+
@Test
public void testPolicyTypePojo() {
assertNotNull(new JpaToscaPolicyType());
assertNotNull(new JpaToscaPolicyType(new PfConceptKey()));
assertNotNull(new JpaToscaPolicyType(new JpaToscaPolicyType()));
- try {
- new JpaToscaPolicyType((PfConceptKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaPolicyType((JpaToscaPolicyType) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
- }
-
- PfConceptKey ptKey = new PfConceptKey("tdt", "0.0.1");
+ assertThatThrownBy(() -> new JpaToscaPolicyType((PfConceptKey) null))
+ .hasMessage("key is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> new JpaToscaPolicyType((JpaToscaPolicyType) null))
+ .hasMessage("copyConcept is marked @NonNull but is null");
+
+ PfConceptKey ptKey = new PfConceptKey("tdt", VERSION_001);
JpaToscaPolicyType tpt = new JpaToscaPolicyType(ptKey);
- PfConceptKey derivedFromKey = new PfConceptKey("deriveFrom", "0.0.1");
+ PfConceptKey derivedFromKey = new PfConceptKey("deriveFrom", VERSION_001);
tpt.setDerivedFrom(derivedFromKey);
Map<String, String> metadata = new HashMap<>();
@@ -80,9 +71,9 @@ public class JpaToscaPolicyTypeTest {
tpt.setMetadata(metadata);
assertEquals(metadata, tpt.getMetadata());
- tpt.setDescription("A Description");
+ tpt.setDescription(A_DESCRIPTION);
- PfConceptKey propTypeKey = new PfConceptKey("propType", "0.0.1");
+ PfConceptKey propTypeKey = new PfConceptKey("propType", VERSION_001);
Map<String, JpaToscaProperty> properties = new LinkedHashMap<>();
JpaToscaProperty tp = new JpaToscaProperty(new PfReferenceKey(ptKey, "aProp"), propTypeKey);
properties.put(tp.getKey().getLocalName(), tp);
@@ -90,7 +81,7 @@ public class JpaToscaPolicyTypeTest {
assertEquals(properties, tpt.getProperties());
List<PfConceptKey> targets = new ArrayList<>();
- PfConceptKey target = new PfConceptKey("target", "0.0.1");
+ PfConceptKey target = new PfConceptKey("target", VERSION_001);
targets.add(target);
tpt.setTargets(targets);
assertEquals(targets, tpt.getTargets());
@@ -114,7 +105,7 @@ public class JpaToscaPolicyTypeTest {
assertEquals(0, tpt.compareTo(tpt));
assertFalse(tpt.compareTo(tpt.getKey()) == 0);
- PfConceptKey otherDtKey = new PfConceptKey("otherDt", "0.0.1");
+ PfConceptKey otherDtKey = new PfConceptKey("otherDt", VERSION_001);
JpaToscaPolicyType otherDt = new JpaToscaPolicyType(otherDtKey);
assertFalse(tpt.compareTo(otherDt) == 0);
@@ -124,7 +115,7 @@ public class JpaToscaPolicyTypeTest {
assertFalse(tpt.compareTo(otherDt) == 0);
otherDt.setMetadata(metadata);
assertFalse(tpt.compareTo(otherDt) == 0);
- otherDt.setDescription("A Description");
+ otherDt.setDescription(A_DESCRIPTION);
assertFalse(tpt.compareTo(otherDt) == 0);
otherDt.setProperties(properties);
assertFalse(tpt.compareTo(otherDt) == 0);
@@ -133,12 +124,7 @@ public class JpaToscaPolicyTypeTest {
otherDt.setTriggers(triggers);
assertEquals(0, tpt.compareTo(otherDt));
- try {
- tpt.copyTo(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("target is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> tpt.copyTo(null)).hasMessage("target is marked @NonNull but is null");
assertEquals(6, tpt.getKeys().size());
assertEquals(1, new JpaToscaPolicyType().getKeys().size());
@@ -177,7 +163,7 @@ public class JpaToscaPolicyTypeTest {
tpt.setDescription("");;
assertFalse(tpt.validate(new PfValidationResult()).isValid());
- tpt.setDescription("A Description");
+ tpt.setDescription(A_DESCRIPTION);
assertTrue(tpt.validate(new PfValidationResult()).isValid());
tpt.setDerivedFrom(PfConceptKey.getNullKey());
@@ -185,28 +171,15 @@ public class JpaToscaPolicyTypeTest {
tpt.setDerivedFrom(derivedFromKey);
assertTrue(tpt.validate(new PfValidationResult()).isValid());
- try {
- tpt.validate(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaEntityType<ToscaPolicy>((PfConceptKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaEntityType<ToscaPolicy>((JpaToscaEntityType<ToscaPolicy>) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
- }
-
- JpaToscaEntityType<ToscaPolicy> tet = new JpaToscaEntityType<ToscaPolicy>(tpt.getKey());
+ assertThatThrownBy(() -> tpt.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> new JpaToscaEntityType<ToscaPolicy>((PfConceptKey) null))
+ .hasMessage("key is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> new JpaToscaEntityType<ToscaPolicy>((JpaToscaEntityType<ToscaPolicy>) null))
+ .hasMessage("copyConcept is marked @NonNull but is null");
+
+ JpaToscaEntityType<ToscaPolicy> tet = new JpaToscaEntityType<>(tpt.getKey());
assertEquals(-1, tet.compareTo(null));
assertEquals(0, tet.compareTo(tet));
assertFalse(tet.compareTo(tet.getKey()) == 0);
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java
index e02df235f..8288fd80b 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,24 +21,22 @@
package org.onap.policy.models.tosca.simple.concepts;
-import static org.junit.Assert.assertEquals;
+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.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
public class JpaToscaPolicyTypesTest {
+ private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+
@Test
public void testPolicyTypes() {
assertNotNull(new JpaToscaPolicyTypes());
@@ -45,40 +44,18 @@ public class JpaToscaPolicyTypesTest {
assertNotNull(new JpaToscaPolicyTypes(new PfConceptKey(), new TreeMap<PfConceptKey, JpaToscaPolicyType>()));
assertNotNull(new JpaToscaPolicyTypes(new JpaToscaPolicyTypes()));
- try {
- new JpaToscaPolicyTypes((PfConceptKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaPolicyTypes((PfConceptKey) null)).hasMessage(KEY_IS_NULL);
- try {
- new JpaToscaPolicyTypes((JpaToscaPolicyTypes) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaPolicyTypes((JpaToscaPolicyTypes) null))
+ .hasMessage("copyConcept is marked @NonNull but is null");
- try {
- new JpaToscaPolicyTypes(null, null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaPolicyTypes(null, null)).hasMessage(KEY_IS_NULL);
- try {
- new JpaToscaPolicyTypes(new PfConceptKey(), null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("conceptMap is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaPolicyTypes(new PfConceptKey(), null))
+ .hasMessage("conceptMap is marked @NonNull but is null");
- try {
- new JpaToscaPolicyTypes(null, new TreeMap<PfConceptKey, JpaToscaPolicyType>());
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaPolicyTypes(null, new TreeMap<PfConceptKey, JpaToscaPolicyType>()))
+ .hasMessage(KEY_IS_NULL);
List<Map<String, ToscaPolicyType>> ptMapList = new ArrayList<>();
ptMapList.add(new LinkedHashMap<>());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java
index 706011bcf..70018b62a 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,21 +21,19 @@
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.ArrayList;
import java.util.List;
-
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
/**
* DAO test for ToscaProperty.
@@ -43,6 +42,11 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
*/
public class JpaToscaPropertyTest {
+ private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String DEFAULT_KEY = "defaultKey";
+ private static final String A_DESCRIPTION = "A Description";
+ private static final String VERSION_001 = "0.0.1";
+
@Test
public void testPropertyPojo() {
assertNotNull(new JpaToscaProperty());
@@ -50,53 +54,30 @@ public class JpaToscaPropertyTest {
assertNotNull(new JpaToscaProperty(new PfReferenceKey(), new PfConceptKey()));
assertNotNull(new JpaToscaProperty(new JpaToscaProperty()));
- try {
- new JpaToscaProperty((PfReferenceKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaProperty(null, null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaProperty(null, new PfConceptKey());
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaProperty(new PfReferenceKey(), null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("type is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaProperty((JpaToscaProperty) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
- }
-
- PfConceptKey pparentKey = new PfConceptKey("tParentKey", "0.0.1");
+ assertThatThrownBy(() -> new JpaToscaProperty((PfReferenceKey) null)).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaProperty(null, null)).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaProperty(null, new PfConceptKey())).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaProperty(new PfReferenceKey(), null))
+ .hasMessage("type is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> new JpaToscaProperty((JpaToscaProperty) null))
+ .hasMessage("copyConcept is marked @NonNull but is null");
+
+ PfConceptKey pparentKey = new PfConceptKey("tParentKey", VERSION_001);
PfReferenceKey pkey = new PfReferenceKey(pparentKey, "trigger0");
- PfConceptKey ptypeKey = new PfConceptKey("TTypeKey", "0.0.1");
+ PfConceptKey ptypeKey = new PfConceptKey("TTypeKey", VERSION_001);
JpaToscaProperty tp = new JpaToscaProperty(pkey, ptypeKey);
- tp.setDescription("A Description");
- assertEquals("A Description", tp.getDescription());
+ tp.setDescription(A_DESCRIPTION);
+ assertEquals(A_DESCRIPTION, tp.getDescription());
tp.setRequired(false);
assertFalse(tp.isRequired());
- tp.setDefaultValue("defaultKey");
+ tp.setDefaultValue(DEFAULT_KEY);
tp.setStatus(ToscaProperty.Status.SUPPORTED);
@@ -106,7 +87,7 @@ public class JpaToscaPropertyTest {
tp.setConstraints(constraints);
assertEquals(constraints, tp.getConstraints());
- PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
+ PfConceptKey typeKey = new PfConceptKey("type", VERSION_001);
JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey);
tp.setEntrySchema(tes);
@@ -123,7 +104,7 @@ public class JpaToscaPropertyTest {
assertEquals(0, tp.compareTo(tp));
assertFalse(tp.compareTo(tp.getKey()) == 0);
- PfReferenceKey otherDtKey = new PfReferenceKey("otherDt", "0.0.1", "OtherProperty");
+ PfReferenceKey otherDtKey = new PfReferenceKey("otherDt", VERSION_001, "OtherProperty");
JpaToscaProperty otherDt = new JpaToscaProperty(otherDtKey);
assertFalse(tp.compareTo(otherDt) == 0);
@@ -131,11 +112,11 @@ public class JpaToscaPropertyTest {
assertFalse(tp.compareTo(otherDt) == 0);
otherDt.setType(ptypeKey);
assertFalse(tp.compareTo(otherDt) == 0);
- otherDt.setDescription("A Description");
+ otherDt.setDescription(A_DESCRIPTION);
assertFalse(tp.compareTo(otherDt) == 0);
otherDt.setRequired(false);
assertFalse(tp.compareTo(otherDt) == 0);
- otherDt.setDefaultValue("defaultKey");
+ otherDt.setDefaultValue(DEFAULT_KEY);
assertFalse(tp.compareTo(otherDt) == 0);
otherDt.setStatus(ToscaProperty.Status.SUPPORTED);
assertFalse(tp.compareTo(otherDt) == 0);
@@ -155,12 +136,7 @@ public class JpaToscaPropertyTest {
otherDt.setStatus(ToscaProperty.Status.SUPPORTED);
assertEquals(0, tp.compareTo(otherDt));
- try {
- tp.copyTo(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("target is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> tp.copyTo(null)).hasMessage("target is marked @NonNull but is null");
assertEquals(3, tp.getKeys().size());
assertEquals(2, new JpaToscaProperty().getKeys().size());
@@ -176,7 +152,7 @@ public class JpaToscaPropertyTest {
assertTrue(tp.validate(new PfValidationResult()).isValid());
tp.setDescription("");
assertFalse(tp.validate(new PfValidationResult()).isValid());
- tp.setDescription("A Description");
+ tp.setDescription(A_DESCRIPTION);
assertTrue(tp.validate(new PfValidationResult()).isValid());
tp.setType(null);
@@ -193,7 +169,7 @@ public class JpaToscaPropertyTest {
assertTrue(tp.validate(new PfValidationResult()).isValid());
tp.setDefaultValue("");
assertFalse(tp.validate(new PfValidationResult()).isValid());
- tp.setDefaultValue("defaultKey");
+ tp.setDefaultValue(DEFAULT_KEY);
assertTrue(tp.validate(new PfValidationResult()).isValid());
tp.getConstraints().add(null);
@@ -201,11 +177,6 @@ public class JpaToscaPropertyTest {
tp.getConstraints().remove(null);
assertTrue(tp.validate(new PfValidationResult()).isValid());
- try {
- tp.validate(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> tp.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java
index a2a418ef9..df72ce57b 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,25 +21,18 @@
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Map;
import java.util.TreeMap;
-
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataTypes;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
/**
* DAO test for ToscaDatatype.
@@ -47,6 +41,9 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
*/
public class JpaToscaServiceTemplateTest {
+ private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String VERSION_001 = "0.0.1";
+
@Test
public void testServiceTemplatePojo() {
assertNotNull(new JpaToscaServiceTemplate());
@@ -54,56 +51,33 @@ public class JpaToscaServiceTemplateTest {
assertNotNull(new JpaToscaServiceTemplate(new PfConceptKey(), ""));
assertNotNull(new JpaToscaServiceTemplate(new JpaToscaServiceTemplate()));
- try {
- new JpaToscaServiceTemplate((PfConceptKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaServiceTemplate(null, null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaServiceTemplate(null, "");
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaServiceTemplate(new PfConceptKey(), null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("toscaDefinitionsVersion is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaServiceTemplate((JpaToscaServiceTemplate) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
- }
-
- PfConceptKey tstKey = new PfConceptKey("tst", "0.0.1");
+ assertThatThrownBy(() -> new JpaToscaServiceTemplate((PfConceptKey) null)).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaServiceTemplate(null, null)).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaServiceTemplate(null, "")).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaServiceTemplate(new PfConceptKey(), null))
+ .hasMessage("toscaDefinitionsVersion is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> new JpaToscaServiceTemplate((JpaToscaServiceTemplate) null))
+ .hasMessage("copyConcept is marked @NonNull but is null");
+
+ PfConceptKey tstKey = new PfConceptKey("tst", VERSION_001);
JpaToscaServiceTemplate tst = new JpaToscaServiceTemplate(tstKey, "Tosca Version");
- PfConceptKey dataTypeKey = new PfConceptKey("DataType", "0.0.1");
+ PfConceptKey dataTypeKey = new PfConceptKey("DataType", VERSION_001);
JpaToscaDataType dataType0 = new JpaToscaDataType(dataTypeKey);
- PfConceptKey dtsKey = new PfConceptKey("dts", "0.0.1");
+ PfConceptKey dtsKey = new PfConceptKey("dts", VERSION_001);
Map<PfConceptKey, JpaToscaDataType> dataTypeMap = new TreeMap<>();
dataTypeMap.put(dataTypeKey, dataType0);
JpaToscaDataTypes dataTypes = new JpaToscaDataTypes(dtsKey, dataTypeMap);
tst.setDataTypes(dataTypes);
assertEquals(dataTypes, tst.getDataTypes());
- PfConceptKey policyTypeKey = new PfConceptKey("DataType", "0.0.1");
+ PfConceptKey policyTypeKey = new PfConceptKey("DataType", VERSION_001);
JpaToscaPolicyType policyType0 = new JpaToscaPolicyType(policyTypeKey);
- PfConceptKey ptsKey = new PfConceptKey("dts", "0.0.1");
+ PfConceptKey ptsKey = new PfConceptKey("dts", VERSION_001);
Map<PfConceptKey, JpaToscaPolicyType> policyTypeMap = new TreeMap<>();
policyTypeMap.put(policyTypeKey, policyType0);
JpaToscaPolicyTypes policyTypes = new JpaToscaPolicyTypes(ptsKey, policyTypeMap);
@@ -128,7 +102,7 @@ public class JpaToscaServiceTemplateTest {
assertEquals(0, tst.compareTo(tst));
assertFalse(tst.compareTo(tst.getKey()) == 0);
- PfConceptKey otherDtKey = new PfConceptKey("otherDt", "0.0.1");
+ PfConceptKey otherDtKey = new PfConceptKey("otherDt", VERSION_001);
JpaToscaServiceTemplate otherDt = new JpaToscaServiceTemplate(otherDtKey);
assertFalse(tst.compareTo(otherDt) == 0);
@@ -143,12 +117,7 @@ public class JpaToscaServiceTemplateTest {
otherDt.setTopologyTemplate(ttt);
assertEquals(0, tst.compareTo(otherDt));
- try {
- tst.copyTo(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("target is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> tst.copyTo(null)).hasMessage("target is marked @NonNull but is null");
assertEquals(6, tst.getKeys().size());
assertEquals(1, new JpaToscaServiceTemplate().getKeys().size());
@@ -167,11 +136,6 @@ public class JpaToscaServiceTemplateTest {
tst.setDescription("A Description");
assertTrue(tst.validate(new PfValidationResult()).isValid());
- try {
- tst.validate(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> tst.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplatesTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplatesTest.java
index 354fe8b78..075087774 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplatesTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplatesTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,6 +38,8 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplates;
public class JpaToscaServiceTemplatesTest {
+ private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+
@Test
public void testServiceTemplates() {
assertNotNull(new JpaToscaServiceTemplates());
@@ -47,7 +50,7 @@ public class JpaToscaServiceTemplatesTest {
assertThatThrownBy(() -> {
new JpaToscaServiceTemplates((PfConceptKey) null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessage(KEY_IS_NULL);
assertThatThrownBy(() -> {
new JpaToscaServiceTemplates((JpaToscaServiceTemplates) null);
@@ -55,7 +58,7 @@ public class JpaToscaServiceTemplatesTest {
assertThatThrownBy(() -> {
new JpaToscaServiceTemplates(null, null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessage(KEY_IS_NULL);
assertThatThrownBy(() -> {
new JpaToscaServiceTemplates(new PfConceptKey(), null);
@@ -63,7 +66,7 @@ public class JpaToscaServiceTemplatesTest {
assertThatThrownBy(() -> {
new JpaToscaServiceTemplates(null, new TreeMap<PfConceptKey, JpaToscaServiceTemplate>());
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessage(KEY_IS_NULL);
List<Map<String, ToscaServiceTemplate>> tsMapList = new ArrayList<>();
tsMapList.add(new LinkedHashMap<>());
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java
index 707e66dfd..e77f12062 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,19 +21,17 @@
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Date;
-
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaTimeInterval;
/**
* DAO test for ToscaTimeInterval.
@@ -41,6 +40,8 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaTimeInterval;
*/
public class JpaToscaTimeIntervalTest {
+ private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+
@Test
public void testTimeIntervalPojo() {
assertNotNull(new JpaToscaTimeInterval());
@@ -48,68 +49,27 @@ public class JpaToscaTimeIntervalTest {
assertNotNull(new JpaToscaTimeInterval(new PfReferenceKey(), new Date(), new Date()));
assertNotNull(new JpaToscaTimeInterval(new JpaToscaTimeInterval()));
- try {
- new JpaToscaTimeInterval((PfReferenceKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTimeInterval(null, null, null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTimeInterval(null, null, new Date());
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTimeInterval(null, new Date(), null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTimeInterval(null, new Date(), new Date());
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTimeInterval(new PfReferenceKey(), null, null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("startTime is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTimeInterval(new PfReferenceKey(), null, new Date());
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("startTime is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTimeInterval(new PfReferenceKey(), new Date(), null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("endTime is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTimeInterval((JpaToscaTimeInterval) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> new JpaToscaTimeInterval((PfReferenceKey) null)).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaTimeInterval(null, null, null)).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaTimeInterval(null, null, new Date())).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaTimeInterval(null, new Date(), null)).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaTimeInterval(null, new Date(), new Date())).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaTimeInterval(new PfReferenceKey(), null, null))
+ .hasMessage("startTime is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> new JpaToscaTimeInterval(new PfReferenceKey(), null, new Date()))
+ .hasMessage("startTime is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> new JpaToscaTimeInterval(new PfReferenceKey(), new Date(), null))
+ .hasMessage("endTime is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> new JpaToscaTimeInterval((JpaToscaTimeInterval) null))
+ .hasMessage("copyConcept is marked @NonNull but is null");
PfConceptKey ttiParentKey = new PfConceptKey("tParentKey", "0.0.1");
PfReferenceKey ttiKey = new PfReferenceKey(ttiParentKey, "trigger0");
@@ -141,12 +101,7 @@ public class JpaToscaTimeIntervalTest {
otherDt.setEndTime(endTime);
assertEquals(0, tti.compareTo(otherDt));
- try {
- tti.copyTo(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("target is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> tti.copyTo(null)).hasMessage("target is marked @NonNull but is null");
assertEquals(1, tti.getKeys().size());
assertEquals(1, new JpaToscaTimeInterval().getKeys().size());
@@ -172,11 +127,6 @@ public class JpaToscaTimeIntervalTest {
tti.setEndTime(endTime);
assertTrue(tti.validate(new PfValidationResult()).isValid());
- try {
- tti.validate(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> tti.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java
index 61ce3d077..7712a64c0 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,23 +21,19 @@
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Map;
import java.util.TreeMap;
-
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicies;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
/**
* DAO test for ToscaDatatype.
@@ -45,6 +42,9 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
*/
public class JpaToscaTopologyTemplateTest {
+ private static final String A_DESCRIPTION = "A Description";
+ private static final String VERSION_001 = "0.0.1";
+
@Test
public void testTopologyTemplatePojo() {
assertNotNull(new JpaToscaTopologyTemplate());
@@ -52,31 +52,23 @@ public class JpaToscaTopologyTemplateTest {
assertNotNull(new JpaToscaTopologyTemplate(new JpaToscaTopologyTemplate()));
assertNotNull(new JpaToscaTopologyTemplate(new ToscaTopologyTemplate()));
- try {
- new JpaToscaTopologyTemplate((PfReferenceKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTopologyTemplate((JpaToscaTopologyTemplate) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
- }
-
- PfReferenceKey tttKey = new PfReferenceKey("tst", "0.0.1", "ttt");
+ assertThatThrownBy(() -> new JpaToscaTopologyTemplate((PfReferenceKey) null))
+ .hasMessage("key is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> new JpaToscaTopologyTemplate((JpaToscaTopologyTemplate) null))
+ .hasMessage("copyConcept is marked @NonNull but is null");
+
+ PfReferenceKey tttKey = new PfReferenceKey("tst", VERSION_001, "ttt");
JpaToscaTopologyTemplate ttt = new JpaToscaTopologyTemplate(tttKey);
- ttt.setDescription("A Description");
- assertEquals("A Description", ttt.getDescription());
+ ttt.setDescription(A_DESCRIPTION);
+ assertEquals(A_DESCRIPTION, ttt.getDescription());
- PfConceptKey policy0TypeKey = new PfConceptKey("Policy0Type", "0.0.1");
- PfConceptKey policy0Key = new PfConceptKey("Policy0", "0.0.1");
+ PfConceptKey policy0TypeKey = new PfConceptKey("Policy0Type", VERSION_001);
+ PfConceptKey policy0Key = new PfConceptKey("Policy0", VERSION_001);
JpaToscaPolicy policy0 = new JpaToscaPolicy(policy0Key, policy0TypeKey);
- PfConceptKey polsKey = new PfConceptKey("pols", "0.0.1");
+ PfConceptKey polsKey = new PfConceptKey("pols", VERSION_001);
Map<PfConceptKey, JpaToscaPolicy> policyMap = new TreeMap<>();
policyMap.put(policy0Key, policy0);
JpaToscaPolicies policies = new JpaToscaPolicies(polsKey, policyMap);
@@ -95,23 +87,18 @@ public class JpaToscaTopologyTemplateTest {
assertEquals(0, ttt.compareTo(ttt));
assertFalse(ttt.compareTo(ttt.getKey()) == 0);
- PfReferenceKey otherDtKey = new PfReferenceKey("otherSt", "0.0.1", "otherDt");
+ PfReferenceKey otherDtKey = new PfReferenceKey("otherSt", VERSION_001, "otherDt");
JpaToscaTopologyTemplate otherDt = new JpaToscaTopologyTemplate(otherDtKey);
assertFalse(ttt.compareTo(otherDt) == 0);
otherDt.setKey(tttKey);
assertFalse(ttt.compareTo(otherDt) == 0);
- otherDt.setDescription("A Description");
+ otherDt.setDescription(A_DESCRIPTION);
assertFalse(ttt.compareTo(otherDt) == 0);
otherDt.setPolicies(policies);
assertEquals(0, ttt.compareTo(otherDt));
- try {
- ttt.copyTo(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("target is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> ttt.copyTo(null)).hasMessage("target is marked @NonNull but is null");
assertEquals(4, ttt.getKeys().size());
assertEquals(1, new JpaToscaTopologyTemplate().getKeys().size());
@@ -132,14 +119,9 @@ public class JpaToscaTopologyTemplateTest {
assertTrue(ttt.validate(new PfValidationResult()).isValid());
ttt.setDescription("");
assertFalse(ttt.validate(new PfValidationResult()).isValid());
- ttt.setDescription("A Description");
+ ttt.setDescription(A_DESCRIPTION);
assertTrue(ttt.validate(new PfValidationResult()).isValid());
- try {
- ttt.validate(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> ttt.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java
index 0f69cb3c9..97c1b6fb7 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,22 +21,18 @@
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.time.Duration;
import java.util.Date;
-
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaEventFilter;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaTimeInterval;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger;
/**
* DAO test for ToscaTrigger.
@@ -44,86 +41,52 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaTrigger;
*/
public class JpaToscaTriggerTest {
+ private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String EVENT_TYPE = "EventType";
+ private static final String ACTION = "Action";
+ private static final String A_METHOD = "A Method";
+ private static final String A_DESCRIPTION = "A Description";
+ private static final String VERSION_001 = "0.0.1";
+
@Test
public void testTriggerPojo() {
assertNotNull(new JpaToscaTrigger());
assertNotNull(new JpaToscaTrigger(new PfReferenceKey()));
- assertNotNull(new JpaToscaTrigger(new PfReferenceKey(), "EventType", "Action"));
+ assertNotNull(new JpaToscaTrigger(new PfReferenceKey(), EVENT_TYPE, ACTION));
assertNotNull(new JpaToscaTrigger(new JpaToscaTrigger()));
- try {
- new JpaToscaTrigger((PfReferenceKey) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTrigger(null, null, null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTrigger(null, "EventType", null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTrigger(null, "EventType", "Action");
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTrigger(null, null, "Action");
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("key is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTrigger(new PfReferenceKey(), null, null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("eventType is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTrigger(new PfReferenceKey(), "EventType", null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("action is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTrigger(new PfReferenceKey(), null, "Action");
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("eventType is marked @NonNull but is null", exc.getMessage());
- }
-
- try {
- new JpaToscaTrigger((JpaToscaTrigger) null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage());
- }
-
- PfConceptKey tparentKey = new PfConceptKey("tParentKey", "0.0.1");
+ assertThatThrownBy(() -> new JpaToscaTrigger((PfReferenceKey) null)).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaTrigger(null, null, null)).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaTrigger(null, EVENT_TYPE, null)).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaTrigger(null, EVENT_TYPE, ACTION)).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaTrigger(null, null, ACTION)).hasMessage(KEY_IS_NULL);
+
+ assertThatThrownBy(() -> new JpaToscaTrigger(new PfReferenceKey(), null, null))
+ .hasMessage("eventType is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> new JpaToscaTrigger(new PfReferenceKey(), EVENT_TYPE, null))
+ .hasMessage("action is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> new JpaToscaTrigger(new PfReferenceKey(), null, ACTION))
+ .hasMessage("eventType is marked @NonNull but is null");
+
+ assertThatThrownBy(() -> new JpaToscaTrigger((JpaToscaTrigger) null))
+ .hasMessage("copyConcept is marked @NonNull but is null");
+
+ PfConceptKey tparentKey = new PfConceptKey("tParentKey", VERSION_001);
PfReferenceKey tkey = new PfReferenceKey(tparentKey, "trigger0");
- JpaToscaTrigger tdt = new JpaToscaTrigger(tkey, "EventType", "Action");
+ JpaToscaTrigger tdt = new JpaToscaTrigger(tkey, EVENT_TYPE, ACTION);
JpaToscaTimeInterval schedule =
new JpaToscaTimeInterval(new PfReferenceKey(tkey, "sched"), new Date(), new Date());
tdt.setSchedule(schedule);
JpaToscaEventFilter targetFilter =
- new JpaToscaEventFilter(new PfReferenceKey(tkey, "filter"), new PfConceptKey("NodeName", "0.0.1"));
+ new JpaToscaEventFilter(new PfReferenceKey(tkey, "filter"), new PfConceptKey("NodeName", VERSION_001));
tdt.setTargetFilter(targetFilter);
JpaToscaConstraintLogical lsc = new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, "hello");
@@ -135,11 +98,11 @@ public class JpaToscaTriggerTest {
tdt.setPeriod(Duration.ZERO);
assertEquals(Duration.ZERO, tdt.getPeriod());
- tdt.setDescription("A Description");
- assertEquals("A Description", tdt.getDescription());
+ tdt.setDescription(A_DESCRIPTION);
+ assertEquals(A_DESCRIPTION, tdt.getDescription());
- tdt.setMethod("A Method");
- assertEquals("A Method", tdt.getMethod());
+ tdt.setMethod(A_METHOD);
+ assertEquals(A_METHOD, tdt.getMethod());
JpaToscaTrigger tdtClone0 = new JpaToscaTrigger(tdt);
assertEquals(tdt, tdtClone0);
@@ -154,15 +117,15 @@ public class JpaToscaTriggerTest {
assertEquals(0, tdt.compareTo(tdt));
assertFalse(tdt.compareTo(tdt.getKey()) == 0);
- PfReferenceKey otherDtKey = new PfReferenceKey("otherDt", "0.0.1", "OtherTrigger");
+ PfReferenceKey otherDtKey = new PfReferenceKey("otherDt", VERSION_001, "OtherTrigger");
JpaToscaTrigger otherDt = new JpaToscaTrigger(otherDtKey);
assertFalse(tdt.compareTo(otherDt) == 0);
otherDt.setKey(tkey);
assertFalse(tdt.compareTo(otherDt) == 0);
- otherDt.setDescription("A Description");
+ otherDt.setDescription(A_DESCRIPTION);
assertFalse(tdt.compareTo(otherDt) == 0);
- otherDt.setEventType("EventType");
+ otherDt.setEventType(EVENT_TYPE);
assertFalse(tdt.compareTo(otherDt) == 0);
otherDt.setSchedule(schedule);
assertFalse(tdt.compareTo(otherDt) == 0);
@@ -174,9 +137,9 @@ public class JpaToscaTriggerTest {
assertFalse(tdt.compareTo(otherDt) == 0);
otherDt.setPeriod(Duration.ZERO);
assertFalse(tdt.compareTo(otherDt) == 0);
- otherDt.setMethod("A Method");
+ otherDt.setMethod(A_METHOD);
assertFalse(tdt.compareTo(otherDt) == 0);
- otherDt.setAction("Action");
+ otherDt.setAction(ACTION);
assertEquals(0, tdt.compareTo(otherDt));
otherDt.setEvaluations(100);
@@ -184,12 +147,7 @@ public class JpaToscaTriggerTest {
otherDt.setEvaluations(0);
assertEquals(0, tdt.compareTo(otherDt));
- try {
- tdt.copyTo(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("target is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> tdt.copyTo(null)).hasMessage("target is marked @NonNull but is null");
assertEquals(4, tdt.getKeys().size());
assertEquals(1, new JpaToscaTrigger().getKeys().size());
@@ -205,7 +163,7 @@ public class JpaToscaTriggerTest {
assertTrue(tdt.validate(new PfValidationResult()).isValid());
tdt.setDescription("");
assertFalse(tdt.validate(new PfValidationResult()).isValid());
- tdt.setDescription("A Description");
+ tdt.setDescription(A_DESCRIPTION);
assertTrue(tdt.validate(new PfValidationResult()).isValid());
tdt.setEvaluations(-1);
@@ -217,14 +175,9 @@ public class JpaToscaTriggerTest {
assertTrue(tdt.validate(new PfValidationResult()).isValid());
tdt.setMethod("");
assertFalse(tdt.validate(new PfValidationResult()).isValid());
- tdt.setMethod("A Method");
+ tdt.setMethod(A_METHOD);
assertTrue(tdt.validate(new PfValidationResult()).isValid());
- try {
- tdt.validate(null);
- fail("test should throw an exception");
- } catch (Exception exc) {
- assertEquals("resultIn is marked @NonNull but is null", exc.getMessage());
- }
+ assertThatThrownBy(() -> tdt.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java
index f8e422160..4603a168f 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/testconcepts/DummyToscaConstraint.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,6 +36,7 @@ public class DummyToscaConstraint extends JpaToscaConstraint {
* The Default Constructor creates a {@link DummyToscaConstraint} object with a null key.
*/
public DummyToscaConstraint() {
+ // do nothing
}
@Override
@@ -44,6 +46,7 @@ public class DummyToscaConstraint extends JpaToscaConstraint {
@Override
public void fromAuthorative(ToscaConstraint authorativeConcept) {
+ // do nothing
}
@Override
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
index 4d71d0ddd..5e7e8fd5c 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,10 +25,8 @@ 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.assertTrue;
-import static org.junit.Assert.fail;
import java.util.Properties;
-
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.junit.After;
import org.junit.Before;
@@ -54,6 +53,9 @@ import org.yaml.snakeyaml.Yaml;
* @author Liam Fallon (liam.fallon@est.tech)
*/
public class SimpleToscaProviderTest {
+ private static final String TEMPLATE_IS_NULL = "serviceTemplate is marked @NonNull but is null";
+ private static final String VCPE_INPUT_JSON = "policies/vCPE.policy.monitoring.input.tosca.json";
+ private static final String DAO_IS_NULL = "dao is marked @NonNull but is null";
private PfDao pfDao;
private StandardCoder standardCoder;
@@ -92,14 +94,14 @@ public class SimpleToscaProviderTest {
}
@After
- public void teardown() throws Exception {
+ public void teardown() {
pfDao.close();
}
@Test
public void testPoliciesGet() throws Exception {
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+ ResourceUtils.getResourceAsString(VCPE_INPUT_JSON),
ToscaServiceTemplate.class);
createPolicyTypes();
@@ -126,7 +128,7 @@ public class SimpleToscaProviderTest {
@Test
public void testPolicyCreate() throws Exception {
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+ ResourceUtils.getResourceAsString(VCPE_INPUT_JSON),
ToscaServiceTemplate.class);
createPolicyTypes();
@@ -144,7 +146,7 @@ public class SimpleToscaProviderTest {
@Test
public void testPolicyUpdate() throws Exception {
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+ ResourceUtils.getResourceAsString(VCPE_INPUT_JSON),
ToscaServiceTemplate.class);
createPolicyTypes();
@@ -162,7 +164,7 @@ public class SimpleToscaProviderTest {
@Test
public void testPoliciesDelete() throws Exception {
ToscaServiceTemplate toscaServiceTemplate = standardCoder.decode(
- ResourceUtils.getResourceAsString("policies/vCPE.policy.monitoring.input.tosca.json"),
+ ResourceUtils.getResourceAsString(VCPE_INPUT_JSON),
ToscaServiceTemplate.class);
createPolicyTypes();
@@ -189,71 +191,58 @@ public class SimpleToscaProviderTest {
}
@Test
- public void testAssertPoliciesExist() throws PfModelException {
+ public void testAssertPoliciesExist() {
JpaToscaServiceTemplate testServiceTemplate = new JpaToscaServiceTemplate();
- try {
- new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate);
- fail("test should throw an exception here");
- } catch (Exception exc) {
- assertEquals("topology template not specified on service template", exc.getMessage());
- }
+ assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate))
+ .hasMessage("topology template not specified on service template");
testServiceTemplate.setTopologyTemplate(new JpaToscaTopologyTemplate());
- try {
- new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate);
- fail("test should throw an exception here");
- } catch (Exception exc) {
- assertEquals("no policies specified on topology template of service template", exc.getMessage());
- }
+ assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate))
+ .hasMessage("no policies specified on topology template of service template");
testServiceTemplate.getTopologyTemplate().setPolicies(new JpaToscaPolicies());
- try {
- new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate);
- fail("test should throw an exception here");
- } catch (Exception exc) {
- assertEquals("list of policies specified on topology template of service template is empty",
- exc.getMessage());
- }
+ assertThatThrownBy(() -> new SimpleToscaProvider().createPolicies(pfDao, testServiceTemplate))
+ .hasMessage("list of policies specified on topology template of service template is empty");
}
@Test
public void testNonNulls() {
assertThatThrownBy(() -> {
new SimpleToscaProvider().getPolicyTypes(null, null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicyTypes(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicyTypes(null, new JpaToscaServiceTemplate());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicyTypes(pfDao, null);
- }).hasMessage("serviceTemplate is marked @NonNull but is null");
+ }).hasMessage(TEMPLATE_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().updatePolicyTypes(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().updatePolicyTypes(null, new JpaToscaServiceTemplate());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().updatePolicyTypes(pfDao, null);
- }).hasMessage("serviceTemplate is marked @NonNull but is null");
+ }).hasMessage(TEMPLATE_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().deletePolicyType(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().deletePolicyType(null, new PfConceptKey());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().deletePolicyType(pfDao, null);
@@ -261,39 +250,39 @@ public class SimpleToscaProviderTest {
assertThatThrownBy(() -> {
new SimpleToscaProvider().getPolicies(null, null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicies(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicies(null, new JpaToscaServiceTemplate());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().createPolicies(pfDao, null);
- }).hasMessage("serviceTemplate is marked @NonNull but is null");
+ }).hasMessage(TEMPLATE_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().updatePolicies(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().updatePolicies(null, new JpaToscaServiceTemplate());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().updatePolicies(pfDao, null);
- }).hasMessage("serviceTemplate is marked @NonNull but is null");
+ }).hasMessage(TEMPLATE_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().deletePolicy(null, null);
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().deletePolicy(null, new PfConceptKey());
- }).hasMessage("dao is marked @NonNull but is null");
+ }).hasMessage(DAO_IS_NULL);
assertThatThrownBy(() -> {
new SimpleToscaProvider().deletePolicy(pfDao, null);
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java
index f05e2e6ef..f5722dded 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicySerializationTest.java
@@ -53,6 +53,34 @@ import org.yaml.snakeyaml.Yaml;
*/
public class MonitoringPolicySerializationTest {
+ private static final String VERSION = "version";
+
+ private static final String YAML_VERSION = "tosca_simple_yaml_1_0_0";
+
+ private static final String DEFINITION_VERSION = "tosca_definitions_version";
+
+ private static final String TOPOLOGY_TEMPLATE = "topology_template";
+
+ private static final String TCA_POLICY = "tca_policy";
+
+ private static final String PROPERTIES2 = "properties";
+
+ private static final String POLICY_ID = "policy-id";
+
+ private static final String POLICIES = "policies";
+
+ private static final String POLICY3 = "onap.vfirewall.tca";
+
+ private static final String POLICY2 = "onap.scaleout.tca";
+
+ private static final String POLICY1 = "onap.restart.tca";
+
+ private static final String TYPE1 = "onap.policies.monitoring.cdap.tca.hi.lo.app";
+
+ private static final String METADATA = "metadata";
+
+ private static final String VERSION_100 = "1.0.0";
+
private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringPolicySerializationTest.class);
private static final String VCPE_MON_INPUT_JSON = "policies/vCPE.policy.monitoring.input.tosca.json";
@@ -70,30 +98,24 @@ public class MonitoringPolicySerializationTest {
}
@Test
- public void testDeserialization() {
- try {
- // vCPE
- JpaToscaServiceTemplate serviceTemplateFromJson = deserializeMonitoringInputJson(VCPE_MON_INPUT_JSON);
- verifyVcpeMonitoringInputDeserialization(serviceTemplateFromJson);
- JpaToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(VCPE_MON_INPUT_YAML);
- assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0);
-
- // vDNS
- serviceTemplateFromJson = deserializeMonitoringInputJson(VDNS_MON_INPUT_JSON);
- verifyVdnsMonitoringInputDeserialization(serviceTemplateFromJson);
- serviceTemplateFromYaml = deserializeMonitoringInputYaml(VDNS_MON_INPUT_YAML);
- assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0);
-
- // vFirewall
- serviceTemplateFromJson = deserializeMonitoringInputJson(VFW_MON_INPUT_JSON);
- verifyVfwMonitoringInputDeserialization(serviceTemplateFromJson);
- serviceTemplateFromYaml = deserializeMonitoringInputYaml(VFW_MON_INPUT_YAML);
- assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0);
-
- } catch (Exception e) {
- LOGGER.warn("No exception should be thrown", e);
- fail("No exception should be thrown");
- }
+ public void testDeserialization() throws Exception {
+ // vCPE
+ JpaToscaServiceTemplate serviceTemplateFromJson = deserializeMonitoringInputJson(VCPE_MON_INPUT_JSON);
+ verifyVcpeMonitoringInputDeserialization(serviceTemplateFromJson);
+ JpaToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(VCPE_MON_INPUT_YAML);
+ assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0);
+
+ // vDNS
+ serviceTemplateFromJson = deserializeMonitoringInputJson(VDNS_MON_INPUT_JSON);
+ verifyVdnsMonitoringInputDeserialization(serviceTemplateFromJson);
+ serviceTemplateFromYaml = deserializeMonitoringInputYaml(VDNS_MON_INPUT_YAML);
+ assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0);
+
+ // vFirewall
+ serviceTemplateFromJson = deserializeMonitoringInputJson(VFW_MON_INPUT_JSON);
+ verifyVfwMonitoringInputDeserialization(serviceTemplateFromJson);
+ serviceTemplateFromYaml = deserializeMonitoringInputYaml(VFW_MON_INPUT_YAML);
+ assertTrue(serviceTemplateFromJson.compareTo(serviceTemplateFromYaml) == 0);
}
@Test
@@ -156,7 +178,7 @@ public class MonitoringPolicySerializationTest {
assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
// Check tosca_definitions_version
- assertEquals("tosca_simple_yaml_1_0_0",
+ assertEquals(YAML_VERSION,
serviceTemplate.getToscaDefinitionsVersion());
Map<PfConceptKey, JpaToscaPolicy> policiesConceptMap = serviceTemplate.getTopologyTemplate()
@@ -164,20 +186,20 @@ public class MonitoringPolicySerializationTest {
// Check policies
assertTrue(policiesConceptMap.size() == 1);
- assertEquals("onap.restart.tca", policiesConceptMap.keySet().iterator().next().getName());
+ assertEquals(POLICY1, policiesConceptMap.keySet().iterator().next().getName());
assertEquals("onap.restart.tca:1.0.0",
- serviceTemplate.getTopologyTemplate().getPolicies().get("onap.restart.tca").getId());
+ serviceTemplate.getTopologyTemplate().getPolicies().get(POLICY1).getId());
JpaToscaPolicy policyVal = policiesConceptMap.values().iterator().next();
// Check metadata
assertTrue(policyVal.getMetadata().size() == 2);
- assertEquals("policy-id", policyVal.getMetadata().entrySet().iterator().next().getKey());
- assertEquals("onap.restart.tca", policyVal.getMetadata().entrySet().iterator().next().getValue());
+ assertEquals(POLICY_ID, policyVal.getMetadata().entrySet().iterator().next().getKey());
+ assertEquals(POLICY1, policyVal.getMetadata().entrySet().iterator().next().getValue());
// Check properties
assertTrue(policiesConceptMap.values().iterator().next().getProperties().size() == 1);
- assertEquals("tca_policy", policyVal.getProperties().keySet().iterator().next());
+ assertEquals(TCA_POLICY, policyVal.getProperties().keySet().iterator().next());
assertNotNull(policyVal.getProperties().values().iterator().next());
}
@@ -189,7 +211,7 @@ public class MonitoringPolicySerializationTest {
assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
// Check tosca_definitions_version
- assertEquals("tosca_simple_yaml_1_0_0",
+ assertEquals(YAML_VERSION,
serviceTemplate.getToscaDefinitionsVersion());
Map<PfConceptKey, JpaToscaPolicy> policiesConceptMap = serviceTemplate.getTopologyTemplate()
@@ -197,20 +219,20 @@ public class MonitoringPolicySerializationTest {
// Check policies
assertTrue(policiesConceptMap.size() == 1);
- assertEquals("onap.scaleout.tca", policiesConceptMap.keySet().iterator().next().getName());
+ assertEquals(POLICY2, policiesConceptMap.keySet().iterator().next().getName());
assertEquals("onap.scaleout.tca:1.0.0",
- serviceTemplate.getTopologyTemplate().getPolicies().get("onap.scaleout.tca").getId());
+ serviceTemplate.getTopologyTemplate().getPolicies().get(POLICY2).getId());
JpaToscaPolicy policyVal = policiesConceptMap.values().iterator().next();
// Check metadata
assertTrue(policyVal.getMetadata().size() == 2);
- assertEquals("policy-id", policyVal.getMetadata().entrySet().iterator().next().getKey());
- assertEquals("onap.scaleout.tca", policyVal.getMetadata().entrySet().iterator().next().getValue());
+ assertEquals(POLICY_ID, policyVal.getMetadata().entrySet().iterator().next().getKey());
+ assertEquals(POLICY2, policyVal.getMetadata().entrySet().iterator().next().getValue());
// Check properties
assertTrue(policiesConceptMap.values().iterator().next().getProperties().size() == 1);
- assertEquals("tca_policy", policyVal.getProperties().keySet().iterator().next());
+ assertEquals(TCA_POLICY, policyVal.getProperties().keySet().iterator().next());
assertNotNull(policyVal.getProperties().values().iterator().next());
}
@@ -222,7 +244,7 @@ public class MonitoringPolicySerializationTest {
assertTrue(serviceTemplate.validate(new PfValidationResult()).isValid());
// Check tosca_definitions_version
- assertEquals("tosca_simple_yaml_1_0_0",
+ assertEquals(YAML_VERSION,
serviceTemplate.getToscaDefinitionsVersion());
Map<PfConceptKey, JpaToscaPolicy> policiesConceptMap = serviceTemplate.getTopologyTemplate()
@@ -230,78 +252,78 @@ public class MonitoringPolicySerializationTest {
// Check policies
assertTrue(policiesConceptMap.size() == 1);
- assertEquals("onap.vfirewall.tca", policiesConceptMap.keySet().iterator().next().getName());
+ assertEquals(POLICY3, policiesConceptMap.keySet().iterator().next().getName());
assertEquals("onap.vfirewall.tca:1.0.0",
- serviceTemplate.getTopologyTemplate().getPolicies().get("onap.vfirewall.tca").getId());
+ serviceTemplate.getTopologyTemplate().getPolicies().get(POLICY3).getId());
JpaToscaPolicy policyVal = policiesConceptMap.values().iterator().next();
// Check metadata
assertTrue(policyVal.getMetadata().size() == 2);
- assertEquals("policy-id", policyVal.getMetadata().entrySet().iterator().next().getKey());
- assertEquals("onap.vfirewall.tca", policyVal.getMetadata().entrySet().iterator().next().getValue());
+ assertEquals(POLICY_ID, policyVal.getMetadata().entrySet().iterator().next().getKey());
+ assertEquals(POLICY3, policyVal.getMetadata().entrySet().iterator().next().getValue());
// Check properties
assertTrue(policiesConceptMap.values().iterator().next().getProperties().size() == 1);
- assertEquals("tca_policy", policyVal.getProperties().keySet().iterator().next());
+ assertEquals(TCA_POLICY, policyVal.getProperties().keySet().iterator().next());
assertNotNull(policyVal.getProperties().values().iterator().next());
}
private void verifyVcpeMonitoringOutputserialization(String serializedServiceTemplate) {
JsonObject serviceTemplateJsonObject = new JsonParser().parse(serializedServiceTemplate).getAsJsonObject();
- assertEquals("tosca_simple_yaml_1_0_0", serviceTemplateJsonObject.get("tosca_definitions_version")
+ assertEquals(YAML_VERSION, serviceTemplateJsonObject.get(DEFINITION_VERSION)
.getAsString());
- JsonObject topologyTemplateJsonObject = serviceTemplateJsonObject.get("topology_template")
+ JsonObject topologyTemplateJsonObject = serviceTemplateJsonObject.get(TOPOLOGY_TEMPLATE)
.getAsJsonObject();
- JsonArray policiesJsonArray = topologyTemplateJsonObject.get("policies").getAsJsonArray();
+ JsonArray policiesJsonArray = topologyTemplateJsonObject.get(POLICIES).getAsJsonArray();
assertTrue(policiesJsonArray.size() == 1);
JsonObject policy = policiesJsonArray.iterator().next().getAsJsonObject();
- assertNotNull(policy.get("onap.restart.tca"));
- JsonObject policyVal = policy.get("onap.restart.tca").getAsJsonObject();
- assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", policyVal.get("type").getAsString());
- assertEquals("1.0.0", policyVal.get("version").getAsString());
- assertEquals("onap.restart.tca", policyVal.get("metadata").getAsJsonObject().get("policy-id")
+ assertNotNull(policy.get(POLICY1));
+ JsonObject policyVal = policy.get(POLICY1).getAsJsonObject();
+ assertEquals(TYPE1, policyVal.get("type").getAsString());
+ assertEquals(VERSION_100, policyVal.get(VERSION).getAsString());
+ assertEquals(POLICY1, policyVal.get(METADATA).getAsJsonObject().get(POLICY_ID)
.getAsString());
- JsonObject properties = policyVal.get("properties").getAsJsonObject();
- assertNotNull(properties.get("tca_policy"));
+ JsonObject properties = policyVal.get(PROPERTIES2).getAsJsonObject();
+ assertNotNull(properties.get(TCA_POLICY));
}
private void verifyVdnsMonitoringOutputserialization(String serializedServiceTemplate) {
JsonObject serviceTemplateJsonObject = new JsonParser().parse(serializedServiceTemplate).getAsJsonObject();
- assertEquals("tosca_simple_yaml_1_0_0", serviceTemplateJsonObject.get("tosca_definitions_version")
+ assertEquals(YAML_VERSION, serviceTemplateJsonObject.get(DEFINITION_VERSION)
.getAsString());
- JsonObject topologyTemplateJsonObject = serviceTemplateJsonObject.get("topology_template").getAsJsonObject();
- JsonArray policiesJsonArray = topologyTemplateJsonObject.get("policies").getAsJsonArray();
+ JsonObject topologyTemplateJsonObject = serviceTemplateJsonObject.get(TOPOLOGY_TEMPLATE).getAsJsonObject();
+ JsonArray policiesJsonArray = topologyTemplateJsonObject.get(POLICIES).getAsJsonArray();
assertTrue(policiesJsonArray.size() == 1);
JsonObject policy = policiesJsonArray.iterator().next().getAsJsonObject();
- assertNotNull(policy.get("onap.scaleout.tca"));
- JsonObject policyVal = policy.get("onap.scaleout.tca").getAsJsonObject();
- assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", policyVal.get("type").getAsString());
- assertEquals("1.0.0", policyVal.get("version").getAsString());
- assertEquals("onap.scaleout.tca", policyVal.get("metadata").getAsJsonObject().get("policy-id")
+ assertNotNull(policy.get(POLICY2));
+ JsonObject policyVal = policy.get(POLICY2).getAsJsonObject();
+ assertEquals(TYPE1, policyVal.get("type").getAsString());
+ assertEquals(VERSION_100, policyVal.get(VERSION).getAsString());
+ assertEquals(POLICY2, policyVal.get(METADATA).getAsJsonObject().get(POLICY_ID)
.getAsString());
- JsonObject properties = policyVal.get("properties").getAsJsonObject();
- assertNotNull(properties.get("tca_policy"));
+ JsonObject properties = policyVal.get(PROPERTIES2).getAsJsonObject();
+ assertNotNull(properties.get(TCA_POLICY));
}
private void verifyVfwMonitoringOutputserialization(String serializedServiceTemplate) {
JsonObject serviceTemplateJsonObject = new JsonParser().parse(serializedServiceTemplate).getAsJsonObject();
- assertEquals("tosca_simple_yaml_1_0_0", serviceTemplateJsonObject.get("tosca_definitions_version")
+ assertEquals(YAML_VERSION, serviceTemplateJsonObject.get(DEFINITION_VERSION)
.getAsString());
- JsonObject topologyTemplateJsonObject = serviceTemplateJsonObject.get("topology_template").getAsJsonObject();
- JsonArray policiesJsonArray = topologyTemplateJsonObject.get("policies").getAsJsonArray();
+ JsonObject topologyTemplateJsonObject = serviceTemplateJsonObject.get(TOPOLOGY_TEMPLATE).getAsJsonObject();
+ JsonArray policiesJsonArray = topologyTemplateJsonObject.get(POLICIES).getAsJsonArray();
assertTrue(policiesJsonArray.size() == 1);
JsonObject policy = policiesJsonArray.iterator().next().getAsJsonObject();
- assertNotNull(policy.get("onap.vfirewall.tca"));
- JsonObject policyVal = policy.get("onap.vfirewall.tca").getAsJsonObject();
- assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", policyVal.get("type").getAsString());
- assertEquals("1.0.0", policyVal.get("version").getAsString());
- assertEquals("onap.vfirewall.tca", policyVal.get("metadata").getAsJsonObject().get("policy-id")
+ assertNotNull(policy.get(POLICY3));
+ JsonObject policyVal = policy.get(POLICY3).getAsJsonObject();
+ assertEquals(TYPE1, policyVal.get("type").getAsString());
+ assertEquals(VERSION_100, policyVal.get(VERSION).getAsString());
+ assertEquals(POLICY3, policyVal.get(METADATA).getAsJsonObject().get(POLICY_ID)
.getAsString());
- JsonObject properties = policyVal.get("properties").getAsJsonObject();
- assertNotNull(properties.get("tca_policy"));
+ JsonObject properties = policyVal.get(PROPERTIES2).getAsJsonObject();
+ assertNotNull(properties.get(TCA_POLICY));
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java
index 0e053f182..aa4fc952c 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/serialization/MonitoringPolicyTypeSerializationTest.java
@@ -55,6 +55,24 @@ import org.yaml.snakeyaml.Yaml;
*/
public class MonitoringPolicyTypeSerializationTest {
+ private static final String DATATYPE_ROOT = "tosca.datatypes.Root";
+
+ private static final String STRING_TEXT = "string";
+
+ private static final String DCAE = "onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server";
+
+ private static final String MONITORING = "onap.policies.Monitoring";
+
+ private static final String THRESHOLDS = "onap.datatypes.monitoring.thresholds";
+
+ private static final String TCA = "onap.datatypes.monitoring.tca_policy";
+
+ private static final String METRICS = "onap.datatypes.monitoring.metricsPerEventName";
+
+ private static final String VERSION_100 = "1.0.0";
+
+ private static final String VERSION_000 = "0.0.0";
+
private static final Logger LOGGER = LoggerFactory.getLogger(MonitoringPolicyTypeSerializationTest.class);
private static final String MONITORING_TCA_YAML = "policytypes/onap.policies.monitoring.cdap.tca.hi.lo.app.yaml";
@@ -69,20 +87,14 @@ public class MonitoringPolicyTypeSerializationTest {
}
@Test
- public void testDeserialization() {
- try {
- // TCA
- JpaToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML);
- verifyTcaInputDeserialization(serviceTemplateFromYaml);
-
- // Collector
- serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML);
- verifyCollectorInputDeserialization(serviceTemplateFromYaml);
-
- } catch (Exception e) {
- LOGGER.warn("No exception should be thrown", e);
- fail("No exception should be thrown");
- }
+ public void testDeserialization() throws Exception {
+ // TCA
+ JpaToscaServiceTemplate serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_TCA_YAML);
+ verifyTcaInputDeserialization(serviceTemplateFromYaml);
+
+ // Collector
+ serviceTemplateFromYaml = deserializeMonitoringInputYaml(MONITORING_COLLECTORS_YAML);
+ verifyCollectorInputDeserialization(serviceTemplateFromYaml);
}
@Test
@@ -148,27 +160,27 @@ public class MonitoringPolicyTypeSerializationTest {
Iterator<Entry<PfConceptKey, JpaToscaPolicyType>> policyTypesIter = policyTypesConceptMap.entrySet().iterator();
Entry<PfConceptKey, JpaToscaPolicyType> firstPolicyType = policyTypesIter.next();
- assertEquals("onap.policies.Monitoring", firstPolicyType.getKey().getName());
- assertEquals("0.0.0", firstPolicyType.getKey().getVersion());
+ assertEquals(MONITORING, firstPolicyType.getKey().getName());
+ assertEquals(VERSION_000, firstPolicyType.getKey().getVersion());
assertEquals("tosca.policies.Root", firstPolicyType.getValue().getDerivedFrom().getName());
assertEquals("a base policy type for all policies that governs monitoring provisioning",
firstPolicyType.getValue().getDescription());
Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next();
assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", secondPolicyType.getKey().getName());
- assertEquals("1.0.0", secondPolicyType.getKey().getVersion());
- assertEquals("onap.policies.Monitoring", secondPolicyType.getValue().getDerivedFrom().getName());
+ assertEquals(VERSION_100, secondPolicyType.getKey().getVersion());
+ assertEquals(MONITORING, secondPolicyType.getValue().getDerivedFrom().getName());
assertTrue(secondPolicyType.getValue().getProperties().size() == 1);
JpaToscaProperty property = secondPolicyType.getValue().getProperties().values().iterator().next();
assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", property.getKey().getParentKeyName());
- assertEquals("1.0.0", property.getKey().getParentKeyVersion());
+ assertEquals(VERSION_100, property.getKey().getParentKeyVersion());
assertEquals("tca_policy", property.getKey().getLocalName());
assertEquals("map", property.getType().getName());
assertEquals("TCA Policy JSON", property.getDescription());
JpaToscaEntrySchema entrySchema = property.getEntrySchema();
- assertEquals("onap.datatypes.monitoring.tca_policy", entrySchema.getType().getName());
+ assertEquals(TCA, entrySchema.getType().getName());
// Check data_types
Map<PfConceptKey, JpaToscaDataType> dataTypesConceptMap = serviceTemplate.getDataTypes().getConceptMap();
@@ -176,18 +188,18 @@ public class MonitoringPolicyTypeSerializationTest {
Iterator<Entry<PfConceptKey, JpaToscaDataType>> dataTypesIter = dataTypesConceptMap.entrySet().iterator();
Entry<PfConceptKey, JpaToscaDataType> firstDataType = dataTypesIter.next();
- assertEquals("onap.datatypes.monitoring.metricsPerEventName", firstDataType.getKey().getName());
+ assertEquals(METRICS, firstDataType.getKey().getName());
JpaToscaDataType firstDataTypeVal = firstDataType.getValue();
- assertEquals("tosca.datatypes.Root", firstDataTypeVal.getDerivedFrom().getName());
- assertEquals("0.0.0", firstDataTypeVal.getDerivedFrom().getVersion());
+ assertEquals(DATATYPE_ROOT, firstDataTypeVal.getDerivedFrom().getName());
+ assertEquals(VERSION_000, firstDataTypeVal.getDerivedFrom().getVersion());
assertTrue(firstDataTypeVal.getProperties().size() == 6);
Iterator<JpaToscaProperty> firstDataTypePropertiesIter = firstDataTypeVal.getProperties().values().iterator();
JpaToscaProperty firstDataTypeFirstProperty = firstDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+ assertEquals(METRICS,
firstDataTypeFirstProperty.getKey().getParentKeyName());
assertEquals("controlLoopSchemaType", firstDataTypeFirstProperty.getKey().getLocalName());
- assertEquals("string", firstDataTypeFirstProperty.getType().getName());
+ assertEquals(STRING_TEXT, firstDataTypeFirstProperty.getType().getName());
assertTrue(firstDataTypeFirstProperty.isRequired());
assertEquals("Specifies Control Loop Schema Type for the event Name e.g. VNF, VM",
firstDataTypeFirstProperty.getDescription());
@@ -198,60 +210,60 @@ public class MonitoringPolicyTypeSerializationTest {
.getValidValues().size() == 2);
JpaToscaProperty firstDataTypeSecondProperty = firstDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+ assertEquals(METRICS,
firstDataTypeSecondProperty.getKey().getParentKeyName());
assertEquals("eventName", firstDataTypeSecondProperty.getKey().getLocalName());
- assertEquals("string", firstDataTypeSecondProperty.getType().getName());
+ assertEquals(STRING_TEXT, firstDataTypeSecondProperty.getType().getName());
assertTrue(firstDataTypeSecondProperty.isRequired());
assertEquals("Event name to which thresholds need to be applied", firstDataTypeSecondProperty.getDescription());
JpaToscaProperty firstDataTypeThirdProperty = firstDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+ assertEquals(METRICS,
firstDataTypeThirdProperty.getKey().getParentKeyName());
assertEquals("policyName", firstDataTypeThirdProperty.getKey().getLocalName());
- assertEquals("string", firstDataTypeThirdProperty.getType().getName());
+ assertEquals(STRING_TEXT, firstDataTypeThirdProperty.getType().getName());
assertTrue(firstDataTypeThirdProperty.isRequired());
assertEquals("TCA Policy Scope Name", firstDataTypeThirdProperty.getDescription());
JpaToscaProperty firstDataTypeFourthProperty = firstDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+ assertEquals(METRICS,
firstDataTypeFourthProperty.getKey().getParentKeyName());
assertEquals("policyScope", firstDataTypeFourthProperty.getKey().getLocalName());
- assertEquals("string", firstDataTypeFourthProperty.getType().getName());
+ assertEquals(STRING_TEXT, firstDataTypeFourthProperty.getType().getName());
assertTrue(firstDataTypeFourthProperty.isRequired());
assertEquals("TCA Policy Scope", firstDataTypeFourthProperty.getDescription());
JpaToscaProperty firstDataTypeFifthProperty = firstDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+ assertEquals(METRICS,
firstDataTypeFifthProperty.getKey().getParentKeyName());
assertEquals("policyVersion", firstDataTypeFifthProperty.getKey().getLocalName());
- assertEquals("string", firstDataTypeFifthProperty.getType().getName());
+ assertEquals(STRING_TEXT, firstDataTypeFifthProperty.getType().getName());
assertTrue(firstDataTypeFifthProperty.isRequired());
assertEquals("TCA Policy Scope Version", firstDataTypeFifthProperty.getDescription());
JpaToscaProperty firstDataTypeSixthProperty = firstDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+ assertEquals(METRICS,
firstDataTypeSixthProperty.getKey().getParentKeyName());
assertEquals("thresholds", firstDataTypeSixthProperty.getKey().getLocalName());
assertEquals("list", firstDataTypeSixthProperty.getType().getName());
assertTrue(firstDataTypeSixthProperty.isRequired());
assertEquals("Thresholds associated with eventName", firstDataTypeSixthProperty.getDescription());
assertNotNull(firstDataTypeSixthProperty.getEntrySchema());
- assertEquals("onap.datatypes.monitoring.thresholds",
+ assertEquals(THRESHOLDS,
firstDataTypeSixthProperty.getEntrySchema().getType().getName());
Entry<PfConceptKey, JpaToscaDataType> secondDataType = dataTypesIter.next();
- assertEquals("onap.datatypes.monitoring.tca_policy", secondDataType.getKey().getName());
+ assertEquals(TCA, secondDataType.getKey().getName());
JpaToscaDataType secondDataTypeVal = secondDataType.getValue();
- assertEquals("tosca.datatypes.Root", secondDataTypeVal.getDerivedFrom().getName());
- assertEquals("0.0.0", secondDataTypeVal.getDerivedFrom().getVersion());
+ assertEquals(DATATYPE_ROOT, secondDataTypeVal.getDerivedFrom().getName());
+ assertEquals(VERSION_000, secondDataTypeVal.getDerivedFrom().getVersion());
assertTrue(secondDataTypeVal.getProperties().size() == 2);
Iterator<JpaToscaProperty> secondDataTypePropertiesIter = secondDataTypeVal.getProperties().values().iterator();
JpaToscaProperty secondDataTypeFirstProperty = secondDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.tca_policy", secondDataTypeFirstProperty.getKey().getParentKeyName());
+ assertEquals(TCA, secondDataTypeFirstProperty.getKey().getParentKeyName());
assertEquals("domain", secondDataTypeFirstProperty.getKey().getLocalName());
- assertEquals("string", secondDataTypeFirstProperty.getType().getName());
+ assertEquals(STRING_TEXT, secondDataTypeFirstProperty.getType().getName());
assertTrue(secondDataTypeFirstProperty.isRequired());
assertEquals("Domain name to which TCA needs to be applied", secondDataTypeFirstProperty.getDescription());
assertEquals("measurementsForVfScaling", secondDataTypeFirstProperty.getDefaultValue());
@@ -262,36 +274,36 @@ public class MonitoringPolicyTypeSerializationTest {
.getCompareTo());
JpaToscaProperty secondDataTypeSecondProperty = secondDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.tca_policy", secondDataTypeSecondProperty.getKey().getParentKeyName());
+ assertEquals(TCA, secondDataTypeSecondProperty.getKey().getParentKeyName());
assertEquals("metricsPerEventName", secondDataTypeSecondProperty.getKey().getLocalName());
assertEquals("list", secondDataTypeSecondProperty.getType().getName());
assertTrue(secondDataTypeSecondProperty.isRequired());
assertEquals("Contains eventName and threshold details that need to be applied to given eventName",
secondDataTypeSecondProperty.getDescription());
assertNotNull(secondDataTypeSecondProperty.getEntrySchema());
- assertEquals("onap.datatypes.monitoring.metricsPerEventName",
+ assertEquals(METRICS,
secondDataTypeSecondProperty.getEntrySchema().getType().getName());
Entry<PfConceptKey, JpaToscaDataType> thirdDataType = dataTypesIter.next();
- assertEquals("onap.datatypes.monitoring.thresholds", thirdDataType.getKey().getName());
+ assertEquals(THRESHOLDS, thirdDataType.getKey().getName());
JpaToscaDataType thirdDataTypeVal = thirdDataType.getValue();
- assertEquals("tosca.datatypes.Root", thirdDataTypeVal.getDerivedFrom().getName());
- assertEquals("0.0.0", thirdDataTypeVal.getDerivedFrom().getVersion());
+ assertEquals(DATATYPE_ROOT, thirdDataTypeVal.getDerivedFrom().getName());
+ assertEquals(VERSION_000, thirdDataTypeVal.getDerivedFrom().getVersion());
assertTrue(thirdDataTypeVal.getProperties().size() == 7);
Iterator<JpaToscaProperty> thirdDataTypePropertiesIter = thirdDataTypeVal.getProperties().values().iterator();
JpaToscaProperty thirdDataTypeFirstProperty = thirdDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeFirstProperty.getKey().getParentKeyName());
+ assertEquals(THRESHOLDS, thirdDataTypeFirstProperty.getKey().getParentKeyName());
assertEquals("closedLoopControlName", thirdDataTypeFirstProperty.getKey().getLocalName());
- assertEquals("string", thirdDataTypeFirstProperty.getType().getName());
+ assertEquals(STRING_TEXT, thirdDataTypeFirstProperty.getType().getName());
assertTrue(thirdDataTypeFirstProperty.isRequired());
assertEquals("Closed Loop Control Name associated with the threshold",
thirdDataTypeFirstProperty.getDescription());
JpaToscaProperty thirdDataTypeSecondProperty = thirdDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeSecondProperty.getKey().getParentKeyName());
+ assertEquals(THRESHOLDS, thirdDataTypeSecondProperty.getKey().getParentKeyName());
assertEquals("closedLoopEventStatus", thirdDataTypeSecondProperty.getKey().getLocalName());
- assertEquals("string", thirdDataTypeSecondProperty.getType().getName());
+ assertEquals(STRING_TEXT, thirdDataTypeSecondProperty.getType().getName());
assertTrue(thirdDataTypeSecondProperty.isRequired());
assertEquals("Closed Loop Event Status of the threshold", thirdDataTypeSecondProperty.getDescription());
assertNotNull(thirdDataTypeSecondProperty.getConstraints());
@@ -304,9 +316,9 @@ public class MonitoringPolicyTypeSerializationTest {
.getValidValues().size() == 2);
JpaToscaProperty thirdDataTypeThirdProperty = thirdDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeThirdProperty.getKey().getParentKeyName());
+ assertEquals(THRESHOLDS, thirdDataTypeThirdProperty.getKey().getParentKeyName());
assertEquals("direction", thirdDataTypeThirdProperty.getKey().getLocalName());
- assertEquals("string", thirdDataTypeThirdProperty.getType().getName());
+ assertEquals(STRING_TEXT, thirdDataTypeThirdProperty.getType().getName());
assertTrue(thirdDataTypeThirdProperty.isRequired());
assertEquals("Direction of the threshold", thirdDataTypeThirdProperty.getDescription());
assertNotNull(thirdDataTypeThirdProperty.getConstraints());
@@ -318,9 +330,9 @@ public class MonitoringPolicyTypeSerializationTest {
.getValidValues().size() == 5);
JpaToscaProperty thirdDataTypeFourthProperty = thirdDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeFourthProperty.getKey().getParentKeyName());
+ assertEquals(THRESHOLDS, thirdDataTypeFourthProperty.getKey().getParentKeyName());
assertEquals("fieldPath", thirdDataTypeFourthProperty.getKey().getLocalName());
- assertEquals("string", thirdDataTypeFourthProperty.getType().getName());
+ assertEquals(STRING_TEXT, thirdDataTypeFourthProperty.getType().getName());
assertTrue(thirdDataTypeFourthProperty.isRequired());
assertEquals("Json field Path as per CEF message which needs to be analyzed for TCA",
thirdDataTypeFourthProperty.getDescription());
@@ -330,9 +342,9 @@ public class MonitoringPolicyTypeSerializationTest {
.getValidValues().size() == 43);
JpaToscaProperty thirdDataTypeFifthProperty = thirdDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeFifthProperty.getKey().getParentKeyName());
+ assertEquals(THRESHOLDS, thirdDataTypeFifthProperty.getKey().getParentKeyName());
assertEquals("severity", thirdDataTypeFifthProperty.getKey().getLocalName());
- assertEquals("string", thirdDataTypeFifthProperty.getType().getName());
+ assertEquals(STRING_TEXT, thirdDataTypeFifthProperty.getType().getName());
assertTrue(thirdDataTypeFifthProperty.isRequired());
assertEquals("Threshold Event Severity", thirdDataTypeFifthProperty.getDescription());
assertNotNull(thirdDataTypeFifthProperty.getConstraints());
@@ -343,7 +355,7 @@ public class MonitoringPolicyTypeSerializationTest {
.getValidValues().size() == 5);;
JpaToscaProperty thirdDataTypeSixthProperty = thirdDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeSixthProperty.getKey().getParentKeyName());
+ assertEquals(THRESHOLDS, thirdDataTypeSixthProperty.getKey().getParentKeyName());
assertEquals("thresholdValue", thirdDataTypeSixthProperty.getKey().getLocalName());
assertEquals("integer", thirdDataTypeSixthProperty.getType().getName());
assertTrue(thirdDataTypeSixthProperty.isRequired());
@@ -351,9 +363,9 @@ public class MonitoringPolicyTypeSerializationTest {
thirdDataTypeSixthProperty.getDescription());
JpaToscaProperty thirdDataTypeSeventhProperty = thirdDataTypePropertiesIter.next();
- assertEquals("onap.datatypes.monitoring.thresholds", thirdDataTypeSeventhProperty.getKey().getParentKeyName());
+ assertEquals(THRESHOLDS, thirdDataTypeSeventhProperty.getKey().getParentKeyName());
assertEquals("version", thirdDataTypeSeventhProperty.getKey().getLocalName());
- assertEquals("string", thirdDataTypeSeventhProperty.getType().getName());
+ assertEquals(STRING_TEXT, thirdDataTypeSeventhProperty.getType().getName());
assertTrue(thirdDataTypeSeventhProperty.isRequired());
assertEquals("Version number associated with the threshold", thirdDataTypeSeventhProperty.getDescription());
}
@@ -374,35 +386,35 @@ public class MonitoringPolicyTypeSerializationTest {
Iterator<Entry<PfConceptKey, JpaToscaPolicyType>> policyTypesIter = policyTypesConceptMap.entrySet().iterator();
Entry<PfConceptKey, JpaToscaPolicyType> firstPolicyType = policyTypesIter.next();
- assertEquals("onap.policies.Monitoring", firstPolicyType.getKey().getName());
- assertEquals("1.0.0", firstPolicyType.getKey().getVersion());
+ assertEquals(MONITORING, firstPolicyType.getKey().getName());
+ assertEquals(VERSION_100, firstPolicyType.getKey().getVersion());
assertEquals("tosca.policies.Root", firstPolicyType.getValue().getDerivedFrom().getName());
assertEquals("a base policy type for all policies that govern monitoring provision",
firstPolicyType.getValue().getDescription());
Entry<PfConceptKey, JpaToscaPolicyType> secondPolicyType = policyTypesIter.next();
- assertEquals("onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server",
+ assertEquals(DCAE,
secondPolicyType.getKey().getName());
- assertEquals("1.0.0", secondPolicyType.getKey().getVersion());
+ assertEquals(VERSION_100, secondPolicyType.getKey().getVersion());
assertEquals("policy.nodes.Root", secondPolicyType.getValue().getDerivedFrom().getName());
assertTrue(secondPolicyType.getValue().getProperties().size() == 2);
Iterator<JpaToscaProperty> propertiesIter = secondPolicyType.getValue().getProperties().values().iterator();
JpaToscaProperty firstProperty = propertiesIter.next();
- assertEquals("onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server",
+ assertEquals(DCAE,
firstProperty.getKey().getParentKeyName());
- assertEquals("1.0.0", firstProperty.getKey().getParentKeyVersion());
+ assertEquals(VERSION_100, firstProperty.getKey().getParentKeyVersion());
assertEquals("buscontroller_feed_publishing_endpoint", firstProperty.getKey().getLocalName());
- assertEquals("string", firstProperty.getType().getName());
+ assertEquals(STRING_TEXT, firstProperty.getType().getName());
assertEquals("DMAAP Bus Controller feed endpoint", firstProperty.getDescription());
JpaToscaProperty secondProperty = propertiesIter.next();
- assertEquals("onap.policies.monitoring.dcaegen2.collectors.datafile.datafile-app-server",
+ assertEquals(DCAE,
secondProperty.getKey().getParentKeyName());
- assertEquals("1.0.0", secondProperty.getKey().getParentKeyVersion());
+ assertEquals(VERSION_100, secondProperty.getKey().getParentKeyVersion());
assertEquals("datafile.policy", secondProperty.getKey().getLocalName());
- assertEquals("string", secondProperty.getType().getName());
+ assertEquals(STRING_TEXT, secondProperty.getType().getName());
assertEquals("datafile Policy JSON as string", secondProperty.getDescription());
}