summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlapentafd <francesco.lapenta@est.tech>2021-03-09 15:13:05 +0000
committerlapentafd <francesco.lapenta@est.tech>2021-03-15 11:01:09 +0000
commit0f18850ed482e71db9d61fa2656e5e84c2f61f74 (patch)
tree548374da12956cf2c385ad598421d81832919657
parent1c3fb9a68d8d27c4bdc3e177550a031b8b3ec5b0 (diff)
Fix Sonar Issues on policy-models-tosca
Tests refactoring to reduce number of assertions Removed lines 167-169 in PfKeyImplTest Issue-ID: POLICY-3094 Change-Id: I94ef11068811c81108b0fbf3e5b878d02ab25306 Signed-off-by: lapentafd <francesco.lapenta@est.tech>
-rw-r--r--models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java5
-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
8 files changed, 93 insertions, 35 deletions
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java
index 54edc8710..2afc94b53 100644
--- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java
+++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyImplTest.java
@@ -26,7 +26,6 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
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.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -164,10 +163,6 @@ public class PfKeyImplTest {
assertEquals(0, someKey0.compareTo(someKey0));
assertEquals(-36, someKey0.compareTo(new DummyPfKey()));
- assertNotEquals(someKey0, null);
- assertEquals(someKey0, (Object) someKey0);
- assertNotEquals(someKey0, (Object) new DummyPfKey());
-
MyKey someKey8 = new MyKey();
someKey8.setVersion(VERSION001);
assertFalse(someKey8.isNullKey());
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);