aboutsummaryrefslogtreecommitdiffstats
path: root/models-tosca
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-03-15 16:39:21 +0000
committerGerrit Code Review <gerrit@onap.org>2021-03-15 16:39:21 +0000
commitc060c361ada331e2c728b28ddb80a6d720d295a7 (patch)
tree273f3907e3eaf5ab11e2a7a40b1d407e5d16d9d1 /models-tosca
parenta3e38403301a296bb110c1219b140126b4434349 (diff)
parent0f18850ed482e71db9d61fa2656e5e84c2f61f74 (diff)
Merge "Fix Sonar Issues on policy-models-tosca"
Diffstat (limited to 'models-tosca')
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java14
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java20
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java5
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java26
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java30
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java23
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java5
7 files changed, 93 insertions, 30 deletions
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 088e8e847..a322e0610 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
@@ -220,22 +220,19 @@ public class AuthorativeToscaProviderPolicyTypeTest {
ToscaEntityFilter.<ToscaPolicyType>builder().build());
ToscaPolicyType gotPolicyType = gotServiceTemplate.getPolicyTypes().get(policyTypeKey.getName());
- assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
- assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription()));
+ checkEqualsNameDescription(beforePolicyType, gotPolicyType);
gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao,
ToscaEntityFilter.<ToscaPolicyType>builder().name(policyTypeKey.getName()).build());
gotPolicyType = gotServiceTemplate.getPolicyTypes().get(policyTypeKey.getName());
- assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
- assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription()));
+ checkEqualsNameDescription(beforePolicyType, gotPolicyType);
gotServiceTemplate = new AuthorativeToscaProvider().getFilteredPolicyTypes(pfDao, ToscaEntityFilter
.<ToscaPolicyType>builder().name(policyTypeKey.getName()).version(VERSION_001).build());
gotPolicyType = gotServiceTemplate.getPolicyTypes().get(policyTypeKey.getName());
- assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
- assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription()));
+ checkEqualsNameDescription(beforePolicyType, gotPolicyType);
List<ToscaPolicyType> gotPolicyTypeList =
new AuthorativeToscaProvider().getPolicyTypeList(pfDao, POLICY_NO_VERSION, VERSION_001);
@@ -263,6 +260,11 @@ public class AuthorativeToscaProviderPolicyTypeTest {
assertEquals(true, beforePolicyType.getName().equals(gotPolicyType.getName()));
}
+ private void checkEqualsNameDescription(ToscaPolicyType beforePolicyType, ToscaPolicyType gotPolicyType) {
+ assertEquals(beforePolicyType.getName(), gotPolicyType.getName());
+ assertEquals(0, ObjectUtils.compare(beforePolicyType.getDescription(), gotPolicyType.getDescription()));
+ }
+
@Test
public void testPolicyTypesCreate() throws Exception {
assertThatThrownBy(() -> {
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 44bc5346b..7399fdc33 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -61,7 +61,10 @@ public class JpaToscaDataTypeTest {
assertThatThrownBy(() -> new JpaToscaDataType((JpaToscaDataType) null))
.isInstanceOf(NullPointerException.class);
+ }
+ @Test
+ public void testDataTypeProperties() {
PfConceptKey dtKey = new PfConceptKey("tdt", VERSION_001);
JpaToscaDataType tdt = new JpaToscaDataType(dtKey);
@@ -109,6 +112,14 @@ public class JpaToscaDataTypeTest {
assertEquals(tdtClone0, tdt);
assertFalse(new JpaToscaDataType().validate("").isValid());
+ validateJpaToscaDataTypeOperations(tdt);
+
+ assertThatThrownBy(() -> {
+ tdt.validate(null);
+ }).hasMessageMatching("fieldName is marked .*on.*ull but is null");
+ }
+
+ private void validateJpaToscaDataTypeOperations(JpaToscaDataType tdt) {
assertTrue(tdt.validate("").isValid());
tdt.getConstraints().add(null);
@@ -120,11 +131,10 @@ public class JpaToscaDataTypeTest {
assertFalse(tdt.validate("").isValid());
tdt.getProperties().remove(null);
assertTrue(tdt.validate("").isValid());
+ }
- assertThatThrownBy(() -> {
- tdt.validate(null);
- }).hasMessageMatching("fieldName is marked .*on.*ull but is null");
-
+ @Test
+ public void testDataTypeConstraints() {
ToscaDataType dat = new ToscaDataType();
dat.setName("name");
dat.setVersion("1.2.3");
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 83d040398..8f339ef7f 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -61,7 +61,10 @@ public class JpaToscaDataTypesTest {
assertThatThrownBy(() -> new JpaToscaDataTypes(null, new TreeMap<PfConceptKey, JpaToscaDataType>()))
.hasMessageMatching(KEY_IS_NULL);
+ }
+ @Test
+ public void testDerivedDataTypes() {
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/JpaToscaEventFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java
index ecffec877..280f1b855 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -62,7 +62,10 @@ public class JpaToscaEventFilterTest {
assertThatThrownBy(() -> new JpaToscaEventFilter((JpaToscaEventFilter) null))
.isInstanceOf(NullPointerException.class);
+ }
+ @Test
+ public void testEventFilter() {
PfConceptKey efParentKey = new PfConceptKey("tParentKey", VERSION_001);
PfReferenceKey efKey = new PfReferenceKey(efParentKey, "trigger0");
PfConceptKey nodeKey = new PfConceptKey("tParentKey", VERSION_001);
@@ -75,12 +78,10 @@ public class JpaToscaEventFilterTest {
assertEquals(A_CAPABILITY, tef.getCapability());
JpaToscaEventFilter tdtClone0 = new JpaToscaEventFilter(tef);
- assertEquals(tef, tdtClone0);
- assertEquals(0, tef.compareTo(tdtClone0));
+ checkEqualsEventFilter(tef, tdtClone0);
JpaToscaEventFilter tdtClone1 = new JpaToscaEventFilter(tef);
- assertEquals(tef, tdtClone1);
- assertEquals(0, tef.compareTo(tdtClone1));
+ checkEqualsEventFilter(tef, tdtClone1);
assertEquals(-1, tef.compareTo(null));
assertEquals(0, tef.compareTo(tef));
@@ -101,6 +102,21 @@ public class JpaToscaEventFilterTest {
assertEquals(2, tef.getKeys().size());
assertEquals(2, new JpaToscaEventFilter().getKeys().size());
+ }
+
+ private void checkEqualsEventFilter(JpaToscaEventFilter tef1, JpaToscaEventFilter tef2) {
+ assertEquals(tef1, tef2);
+ assertEquals(0, tef1.compareTo(tef2));
+ }
+
+ @Test
+ public void testValidationEventFilter() {
+ PfConceptKey efParentKey = new PfConceptKey("tParentKey", VERSION_001);
+ PfReferenceKey efKey = new PfReferenceKey(efParentKey, "trigger0");
+ PfConceptKey nodeKey = new PfConceptKey("tParentKey", VERSION_001);
+ JpaToscaEventFilter tef = new JpaToscaEventFilter(efKey, nodeKey);
+
+ JpaToscaEventFilter tdtClone0 = new JpaToscaEventFilter(tef);
new JpaToscaEventFilter().clean();
tef.clean();
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 714b6722c..3790329b9 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -58,6 +58,12 @@ public class JpaToscaTopologyTemplateTest {
assertThatThrownBy(() -> new JpaToscaTopologyTemplate((JpaToscaTopologyTemplate) null))
.isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> new JpaToscaTopologyTemplate((JpaToscaTopologyTemplate) null))
+ .isInstanceOf(NullPointerException.class);
+ }
+
+ @Test
+ public void testTopologyTemplates() {
PfReferenceKey tttKey = new PfReferenceKey("tst", VERSION_001, "ttt");
JpaToscaTopologyTemplate ttt = new JpaToscaTopologyTemplate(tttKey);
@@ -75,12 +81,10 @@ public class JpaToscaTopologyTemplateTest {
ttt.setPolicies(policies);
JpaToscaTopologyTemplate tttClone0 = new JpaToscaTopologyTemplate(ttt);
- assertEquals(ttt, tttClone0);
- assertEquals(0, ttt.compareTo(tttClone0));
+ checkEqualsTopologyTemplate(ttt, tttClone0);
JpaToscaTopologyTemplate tttClone1 = new JpaToscaTopologyTemplate(ttt);
- assertEquals(ttt, tttClone1);
- assertEquals(0, ttt.compareTo(tttClone1));
+ checkEqualsTopologyTemplate(ttt, tttClone1);
assertEquals(-1, ttt.compareTo(null));
assertEquals(0, ttt.compareTo(ttt));
@@ -97,11 +101,16 @@ public class JpaToscaTopologyTemplateTest {
otherDt.setPolicies(policies);
assertEquals(0, ttt.compareTo(otherDt));
- assertThatThrownBy(() -> new JpaToscaTopologyTemplate((JpaToscaTopologyTemplate) null))
- .isInstanceOf(NullPointerException.class);
-
assertEquals(4, ttt.getKeys().size());
assertEquals(1, new JpaToscaTopologyTemplate().getKeys().size());
+ }
+
+ @Test
+ public void testTopologyTemplateValidation() {
+ PfReferenceKey tttKey = new PfReferenceKey("tst", VERSION_001, "ttt");
+ JpaToscaTopologyTemplate ttt = new JpaToscaTopologyTemplate(tttKey);
+
+ JpaToscaTopologyTemplate tttClone0 = new JpaToscaTopologyTemplate(ttt);
new JpaToscaTopologyTemplate().clean();
ttt.clean();
@@ -124,4 +133,9 @@ public class JpaToscaTopologyTemplateTest {
assertThatThrownBy(() -> ttt.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null");
}
+
+ private void checkEqualsTopologyTemplate(JpaToscaTopologyTemplate ttt1, JpaToscaTopologyTemplate ttt2) {
+ assertEquals(ttt1, ttt2);
+ assertEquals(0, ttt1.compareTo(ttt2));
+ }
}
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 38be5f6a6..597ce0c4d 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
@@ -75,7 +75,10 @@ public class JpaToscaTriggerTest {
.hasMessageMatching("eventType is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaTrigger((JpaToscaTrigger) null)).isInstanceOf(NullPointerException.class);
+ }
+ @Test
+ public void testTriggerConstraints() {
PfConceptKey tparentKey = new PfConceptKey("tParentKey", VERSION_001);
PfReferenceKey tkey = new PfReferenceKey(tparentKey, "trigger0");
JpaToscaTrigger tdt = new JpaToscaTrigger(tkey, EVENT_TYPE, ACTION);
@@ -104,12 +107,10 @@ public class JpaToscaTriggerTest {
assertEquals(A_METHOD, tdt.getMethod());
JpaToscaTrigger tdtClone0 = new JpaToscaTrigger(tdt);
- assertEquals(tdt, tdtClone0);
- assertEquals(0, tdt.compareTo(tdtClone0));
+ checkEqualsToscaTriggers(tdt, tdtClone0);
JpaToscaTrigger tdtClone1 = new JpaToscaTrigger(tdt);
- assertEquals(tdt, tdtClone1);
- assertEquals(0, tdt.compareTo(tdtClone1));
+ checkEqualsToscaTriggers(tdt, tdtClone1);
assertEquals(-1, tdt.compareTo(null));
assertEquals(0, tdt.compareTo(tdt));
@@ -147,6 +148,15 @@ public class JpaToscaTriggerTest {
assertEquals(4, tdt.getKeys().size());
assertEquals(1, new JpaToscaTrigger().getKeys().size());
+ }
+
+ @Test
+ public void testCloneToscaTrigger() {
+ PfConceptKey tparentKey = new PfConceptKey("tParentKey", VERSION_001);
+ PfReferenceKey tkey = new PfReferenceKey(tparentKey, "trigger0");
+ JpaToscaTrigger tdt = new JpaToscaTrigger(tkey, EVENT_TYPE, ACTION);
+
+ JpaToscaTrigger tdtClone0 = new JpaToscaTrigger(tdt);
new JpaToscaTrigger().clean();
tdt.clean();
@@ -176,4 +186,9 @@ public class JpaToscaTriggerTest {
assertThatThrownBy(() -> tdt.validate(null)).hasMessageMatching("fieldName is marked .*on.*ull but is null");
}
+
+ private void checkEqualsToscaTriggers(JpaToscaTrigger tdt1, JpaToscaTrigger tdt2) {
+ assertEquals(tdt1, tdt2);
+ assertEquals(0, tdt1.compareTo(tdt2));
+ }
}
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 07624aeee..69c1839c8 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
@@ -705,7 +705,7 @@ public class SimpleToscaProviderTest {
}
@Test
- public void testNonNulls() {
+ public void testNonNullsDataType() {
assertThatThrownBy(() -> {
new SimpleToscaProvider().getServiceTemplate(null);
}).hasMessageMatching(DAO_IS_NULL);
@@ -761,7 +761,10 @@ public class SimpleToscaProviderTest {
assertThatThrownBy(() -> {
new SimpleToscaProvider().deleteDataType(pfDao, null);
}).hasMessageMatching("^dataTypeKey is marked .*on.*ull but is null$");
+ }
+ @Test
+ public void testNotNullsPolicyTypes() {
assertThatThrownBy(() -> {
new SimpleToscaProvider().getPolicyTypes(null, null, null);
}).hasMessageMatching(DAO_IS_NULL);