aboutsummaryrefslogtreecommitdiffstats
path: root/models-tosca/src/test
diff options
context:
space:
mode:
authorliamfallon <liam.fallon@est.tech>2020-02-04 15:45:58 +0000
committerliamfallon <liam.fallon@est.tech>2020-02-05 09:13:53 +0000
commit60344d720eef9fc24dc86d7a6adc5f4530f9d099 (patch)
treedb61c601d9769ee47e63c5a3fea5765585caa068 /models-tosca/src/test
parent274178e2cb32c173fa93b18285b747786609f50b (diff)
Add vaidation for entity hierarchies
This change brings in proper hierarchical checks for service templates, making sure that all parents of data types, policy types, and policies must be in place. Issue-ID: POLICY-1402 Change-Id: I61b1b556403f74aeaa092f0d4d6ed19bf6a0b715 Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-tosca/src/test')
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyFilterTest.java8
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java4
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeFilterTest.java6
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeTest.java4
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraintTest.java9
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypeTest.java13
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaDataTypesTest.java63
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntrySchemaTest.java14
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java16
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModelTest.java15
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPoliciesTest.java67
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTest.java20
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypeTest.java16
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicyTypesTest.java63
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPropertyTest.java21
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplateTest.java17
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplatesTest.java16
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTimeIntervalTest.java26
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplateTest.java11
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTriggerTest.java26
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java1
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java106
22 files changed, 400 insertions, 142 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 df935626c..64c3b1365 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,10 +27,12 @@ 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;
@@ -128,7 +130,7 @@ public class ToscaPolicyFilterTest {
assertThatThrownBy(() -> {
filter.filter(null);
- }).hasMessage("originalList is marked @NonNull but is null");
+ }).hasMessageMatching("originalList is marked .*on.*ull but is null");
}
@Test
@@ -237,7 +239,7 @@ public class ToscaPolicyFilterTest {
assertEquals(2, filteredList.size());
filter = ToscaPolicyFilter.builder().type("onap.policies.controlloop.Operational").typeVersion(VERSION_000)
- .build();
+ .build();
filteredList = filter.filter(policyList);
assertEquals(1, filteredList.size());
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java
index 8ee74233b..08035008f 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTest.java
@@ -3,6 +3,7 @@
* ONAP Policy Models
* ================================================================================
* Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -36,8 +37,7 @@ public class ToscaPolicyTest {
public void testGetIdentifier_testGetTypeIdentifier() {
assertThatThrownBy(() -> {
new ToscaPolicy(null);
- }).hasMessage("copyObject is marked @NonNull but is null");
-
+ }).hasMessageMatching("copyObject is marked .*on.*ull but is null");
ToscaPolicy policy = new ToscaPolicy();
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 f4f822c20..30696ce9d 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,10 +27,12 @@ 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;
@@ -123,7 +125,7 @@ public class ToscaPolicyTypeFilterTest {
assertThatThrownBy(() -> {
filter.filter(null);
- }).hasMessage("originalList is marked @NonNull but is null");
+ }).hasMessageMatching("originalList is marked .*on.*ull but is null");
}
@Test
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeTest.java
index 59a5a3336..69fae4583 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeTest.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ public class ToscaPolicyTypeTest {
public void testToscaPolicyType() {
assertThatThrownBy(() -> {
new ToscaPolicyType(null);
- }).hasMessage("copyObject is marked @NonNull but is null");
+ }).hasMessageMatching("copyObject is marked .*on.*ull but is null");
ToscaPolicyType tpt = new ToscaPolicyType();
tpt.setName("AType");
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 ce5ace1c0..2987814a6 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertNotNull;
import java.util.ArrayList;
import java.util.List;
+
import org.junit.Test;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
@@ -45,13 +46,13 @@ public class JpaToscaConstraintTest {
assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, CONSTRAINT));
assertThatThrownBy(() -> new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, null))
- .hasMessage("operation is marked @NonNull but is null");
+ .hasMessageMatching("operation is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaConstraintLogical((JpaToscaConstraintOperation) null, "Hello"))
- .hasMessage("operation is marked @NonNull but is null");
+ .hasMessageMatching("operation is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, null))
- .hasMessage("compareTo is marked @NonNull but is null");
+ .hasMessageMatching("compareTo is marked .*on.*ull but is null");
assertNotNull(new JpaToscaConstraintLogical(JpaToscaConstraintOperation.EQ, CONSTRAINT));
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 281ddfcee..499cf72fb 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 Nordix Foundation.
+ * Copyright (C) 2019=-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,9 +38,6 @@ import org.onap.policy.models.base.PfReferenceKey;
import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaConstraint;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaDataType;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaProperty;
/**
* DAO test for ToscaDatatype.
@@ -60,10 +57,10 @@ public class JpaToscaDataTypeTest {
assertThatThrownBy(() -> {
new JpaToscaDataType((PfConceptKey) null);
- }).hasMessage("key is marked @NonNull but is null");
+ }).hasMessageMatching("key is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaDataType((JpaToscaDataType) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
PfConceptKey dtKey = new PfConceptKey("tdt", VERSION_001);
JpaToscaDataType tdt = new JpaToscaDataType(dtKey);
@@ -76,7 +73,7 @@ public class JpaToscaDataTypeTest {
Map<String, JpaToscaProperty> properties = new LinkedHashMap<>();
JpaToscaProperty tp =
- new JpaToscaProperty(new PfReferenceKey(dtKey, "pr"), new PfConceptKey("type", VERSION_001));
+ new JpaToscaProperty(new PfReferenceKey(dtKey, "pr"), new PfConceptKey("type", VERSION_001));
properties.put(tp.getKey().getLocalName(), tp);
tdt.setProperties(properties);
assertEquals(properties, tdt.getProperties());
@@ -126,7 +123,7 @@ public class JpaToscaDataTypeTest {
assertThatThrownBy(() -> {
tdt.validate(null);
- }).hasMessage("resultIn is marked @NonNull but is null");
+ }).hasMessageMatching("resultIn is marked .*on.*ull but is null");
ToscaDataType dat = new ToscaDataType();
dat.setName("name");
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 5421b953e..9a8b29d09 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 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,21 +21,26 @@
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
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.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
public class JpaToscaDataTypesTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
@Test
public void testDataTypes() {
@@ -44,22 +49,64 @@ public class JpaToscaDataTypesTest {
assertNotNull(new JpaToscaDataTypes(new PfConceptKey(), new TreeMap<PfConceptKey, JpaToscaDataType>()));
assertNotNull(new JpaToscaDataTypes(new JpaToscaDataTypes()));
- assertThatThrownBy(() -> new JpaToscaDataTypes((PfConceptKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaDataTypes((PfConceptKey) null)).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaDataTypes((JpaToscaDataTypes) null))
- .hasMessage("copyConcept is marked @NonNull but is null");
+ .hasMessageMatching("copyConcept is marked .*on.*ull but is null");
- assertThatThrownBy(() -> new JpaToscaDataTypes(null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaDataTypes(null, null)).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaDataTypes(new PfConceptKey(), null))
- .hasMessage("conceptMap is marked @NonNull but is null");
+ .hasMessageMatching("conceptMap is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaDataTypes(null, new TreeMap<PfConceptKey, JpaToscaDataType>()))
- .hasMessage(KEY_IS_NULL);
+ .hasMessageMatching(KEY_IS_NULL);
List<Map<String, ToscaDataType>> dtMapList = new ArrayList<>();
dtMapList.add(new LinkedHashMap<>());
- dtMapList.get(0).put("policyType", new ToscaDataType());
+
+ ToscaDataType dt0 = new ToscaDataType();
+ dt0.setName("dt0");
+ dt0.setVersion("0.0.1");
+ dt0.setDescription("dt0 description");
+
+ dtMapList.get(0).put("dt0", dt0);
assertNotNull(new JpaToscaDataTypes(dtMapList));
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+ assertThatThrownBy(() -> new JpaToscaDataTypes(dtMapList).validate(null))
+ .hasMessageMatching("resultIn is marked .*on.*ull but is null");
+
+ dt0.setDerivedFrom(null);
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+
+ dt0.setDerivedFrom("tosca.datatypes.Root");
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+
+ dt0.setDerivedFrom("some.other.Thing");
+ PfValidationResult result = new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult());
+ assertFalse(result.isValid());
+ assertThat(result.toString()).contains("parent some.other.Thing:0.0.0 of entity not found");
+
+ dt0.setDerivedFrom(null);
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+
+ ToscaDataType dt1 = new ToscaDataType();
+ dt1.setName("dt1");
+ dt1.setVersion("0.0.1");
+ dt1.setDescription("dt1 description");
+
+ dtMapList.get(0).put("dt1", dt1);
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+
+ dt1.setDerivedFrom("dt0");
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
+
+ dt1.setDerivedFrom("dt2");
+ result = new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult());
+ assertFalse(result.isValid());
+ assertThat(result.toString()).contains("parent dt2:0.0.0 of entity not found");
+
+ dt1.setDerivedFrom("dt0");
+ assertTrue(new JpaToscaDataTypes(dtMapList).validate(new PfValidationResult()).isValid());
}
}
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 b306685d0..79fa086c0 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,6 +29,7 @@ import static org.junit.Assert.assertTrue;
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;
@@ -48,10 +49,10 @@ public class JpaToscaEntrySchemaTest {
assertNotNull(new JpaToscaEntrySchema(new JpaToscaEntrySchema(new PfConceptKey())));
assertThatThrownBy(() -> new JpaToscaEntrySchema((PfConceptKey) null))
- .hasMessage("type is marked @NonNull but is null");
+ .hasMessageMatching("type is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaEntrySchema((JpaToscaEntrySchema) null))
- .hasMessage("copyConcept is marked @NonNull but is null");
+ .hasMessageMatching("copyConcept is marked .*on.*ull but is null");
PfConceptKey typeKey = new PfConceptKey("type", "0.0.1");
JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey);
@@ -86,7 +87,7 @@ public class JpaToscaEntrySchemaTest {
otherEs.setConstraints(constraints);
assertEquals(0, tes.compareTo(otherEs));
- assertThatThrownBy(() -> tes.copyTo(null)).hasMessage("target is marked @NonNull but is null");
+ assertThatThrownBy(() -> tes.copyTo(null)).hasMessageMatching("target is marked .*on.*ull but is null");
assertEquals(1, tes.getKeys().size());
assertEquals(1, new JpaToscaEntrySchema(typeKey).getKeys().size());
@@ -105,7 +106,8 @@ public class JpaToscaEntrySchemaTest {
tes.setType(typeKey);
assertTrue(tes.validate(new PfValidationResult()).isValid());
- tes.setDescription("");;
+ tes.setDescription("");
+
assertFalse(tes.validate(new PfValidationResult()).isValid());
tes.setDescription(A_DESCRIPTION);
assertTrue(tes.validate(new PfValidationResult()).isValid());
@@ -115,6 +117,6 @@ public class JpaToscaEntrySchemaTest {
tes.getConstraints().remove(null);
assertTrue(tes.validate(new PfValidationResult()).isValid());
- assertThatThrownBy(() -> tes.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> tes.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull 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 7d34a73eb..498a768ff 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 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -39,7 +39,7 @@ import org.onap.policy.models.base.PfValidationResult;
*/
public class JpaToscaEventFilterTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull 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";
@@ -51,17 +51,17 @@ public class JpaToscaEventFilterTest {
assertNotNull(new JpaToscaEventFilter(new PfReferenceKey(), new PfConceptKey()));
assertNotNull(new JpaToscaEventFilter(new JpaToscaEventFilter()));
- assertThatThrownBy(() -> new JpaToscaEventFilter((PfReferenceKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaEventFilter((PfReferenceKey) null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaEventFilter(null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaEventFilter(null, null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaEventFilter(null, new PfConceptKey())).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaEventFilter(null, new PfConceptKey())).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaEventFilter(new PfReferenceKey(), null))
- .hasMessage("node is marked @NonNull but is null");
+ .hasMessageMatching("node is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaEventFilter((JpaToscaEventFilter) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
PfConceptKey efParentKey = new PfConceptKey("tParentKey", VERSION_001);
PfReferenceKey efKey = new PfReferenceKey(efParentKey, "trigger0");
@@ -130,6 +130,6 @@ public class JpaToscaEventFilterTest {
tef.setNode(nodeKey);
assertTrue(tef.validate(new PfValidationResult()).isValid());
- assertThatThrownBy(() -> tef.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> tef.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull 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 839f0f8ca..3e8569117 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
@@ -42,7 +42,7 @@ import org.onap.policy.models.base.PfValidationResult;
*/
public class JpaToscaModelTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
private static final String VERSION_001 = "0.0.1";
@Test
@@ -52,17 +52,18 @@ public class JpaToscaModelTest {
assertNotNull(new JpaToscaModel(new PfConceptKey(), new JpaToscaServiceTemplates()));
assertNotNull(new JpaToscaModel(new JpaToscaModel()));
- assertThatThrownBy(() -> new JpaToscaModel((PfConceptKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaModel((PfConceptKey) null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaModel(null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaModel(null, null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaModel(null, new JpaToscaServiceTemplates())).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaModel(null, new JpaToscaServiceTemplates()))
+ .hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaModel(new PfConceptKey(), null))
- .hasMessage("serviceTemplates is marked @NonNull but is null");
+ .hasMessageMatching("serviceTemplates is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaModel((JpaToscaModel) null))
- .hasMessage("copyConcept is marked @NonNull but is null");
+ .hasMessageMatching("copyConcept is marked .*on.*ull but is null");
PfConceptKey tstsKey = new PfConceptKey("tsts", VERSION_001);
Map<PfConceptKey, JpaToscaServiceTemplate> tstMap = new TreeMap<>();
@@ -107,6 +108,6 @@ public class JpaToscaModelTest {
assertTrue(PfModelService.existsModel(tm.getServiceTemplates().getId()));
PfModelService.deregisterModel(tm.getServiceTemplates().getId());
- assertThatThrownBy(() -> tm.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> tm.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull 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 10616f2eb..968aa95c2 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,21 +21,26 @@
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
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.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
public class JpaToscaPoliciesTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
@Test
public void testPolicies() {
@@ -44,22 +49,68 @@ public class JpaToscaPoliciesTest {
assertNotNull(new JpaToscaPolicies(new PfConceptKey(), new TreeMap<PfConceptKey, JpaToscaPolicy>()));
assertNotNull(new JpaToscaPolicies(new JpaToscaPolicies()));
- assertThatThrownBy(() -> new JpaToscaPolicies((PfConceptKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaPolicies((PfConceptKey) null)).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaPolicies((JpaToscaPolicies) null))
- .hasMessage("copyConcept is marked @NonNull but is null");
+ .hasMessageMatching("copyConcept is marked .*on.*ull but is null");
- assertThatThrownBy(() -> new JpaToscaPolicies(null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaPolicies(null, null)).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaPolicies(new PfConceptKey(), null))
- .hasMessage("conceptMap is marked @NonNull but is null");
+ .hasMessageMatching("conceptMap is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaPolicies(null, new TreeMap<PfConceptKey, JpaToscaPolicy>()))
- .hasMessage(KEY_IS_NULL);
+ .hasMessageMatching(KEY_IS_NULL);
List<Map<String, ToscaPolicy>> polMapList = new ArrayList<>();
polMapList.add(new LinkedHashMap<>());
- polMapList.get(0).put("policyType", new ToscaPolicy());
+
+ ToscaPolicy pol0 = new ToscaPolicy();
+ pol0.setName("pol0");
+ pol0.setVersion("0.0.1");
+ pol0.setDescription("pol0 description");
+ pol0.setType("pt0");
+ pol0.setTypeVersion("0.0.1");
+
+ polMapList.get(0).put("pol0", pol0);
assertNotNull(new JpaToscaPolicies(polMapList));
+ assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+ assertThatThrownBy(() -> new JpaToscaPolicies(polMapList).validate(null))
+ .hasMessageMatching("resultIn is marked .*on.*ull but is null");
+
+ pol0.setDerivedFrom(null);
+ assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+
+ pol0.setDerivedFrom("tosca.Policies.Root");
+ assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+
+ pol0.setDerivedFrom("some.other.Thing");
+ PfValidationResult result = new JpaToscaPolicies(polMapList).validate(new PfValidationResult());
+ assertFalse(result.isValid());
+ assertThat(result.toString()).contains("parent some.other.Thing:0.0.0 of entity not found");
+
+ pol0.setDerivedFrom(null);
+ assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+
+ ToscaPolicy pol1 = new ToscaPolicy();
+ pol1.setName("pol1");
+ pol1.setVersion("0.0.1");
+ pol1.setDescription("pol1 description");
+ pol1.setType("pt0");
+ pol1.setTypeVersion("0.0.1");
+
+ polMapList.get(0).put("pol1", pol1);
+ assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+
+ pol1.setDerivedFrom("pol0");
+ assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
+
+ pol1.setDerivedFrom("pol2");
+ result = new JpaToscaPolicies(polMapList).validate(new PfValidationResult());
+ assertFalse(result.isValid());
+ assertThat(result.toString()).contains("parent pol2:0.0.0 of entity not found");
+
+ pol1.setDerivedFrom("pol0");
+ assertTrue(new JpaToscaPolicies(polMapList).validate(new PfValidationResult()).isValid());
}
}
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 73e5066c1..c5952546a 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -37,7 +37,6 @@ import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
/**
* DAO test for ToscaPolicy.
@@ -46,7 +45,7 @@ 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 KEY_IS_NULL = "key is marked .*on.*ull but is null";
private static final String VERSION_001 = "0.0.1";
@Test
@@ -62,22 +61,21 @@ public class JpaToscaPolicyTest {
assertThatThrownBy(() -> {
new JpaToscaPolicy((PfConceptKey) null);
- }).hasMessage(KEY_IS_NULL);
+ }).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> {
new JpaToscaPolicy(null, null);
- }).hasMessage(KEY_IS_NULL);
+ }).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> {
new JpaToscaPolicy(new PfConceptKey(), null);
- }).hasMessage("type is marked @NonNull but is null");
+ }).hasMessageMatching("type is marked .*on.*ull but is null");
assertThatThrownBy(() -> {
new JpaToscaPolicy(null, new PfConceptKey());
- }).hasMessage(KEY_IS_NULL);
+ }).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaPolicy((JpaToscaPolicy) null))
- .isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> new JpaToscaPolicy((JpaToscaPolicy) null)).isInstanceOf(NullPointerException.class);
PfConceptKey tpKey = new PfConceptKey("tdt", VERSION_001);
PfConceptKey ptKey = new PfConceptKey("policyType", VERSION_001);
@@ -160,7 +158,7 @@ public class JpaToscaPolicyTest {
assertThatThrownBy(() -> {
tp.validate(null);
- }).hasMessage("resultIn is marked @NonNull but is null");
+ }).hasMessageMatching("resultIn is marked .*on.*ull but is null");
assertNotNull(tp.toAuthorative());
tp.getType().setVersion(PfKey.NULL_KEY_VERSION);
@@ -170,7 +168,7 @@ public class JpaToscaPolicyTest {
assertThatThrownBy(() -> {
tp.fromAuthorative(null);
- }).hasMessage("toscaPolicy is marked @NonNull but is null");
+ }).hasMessageMatching("toscaPolicy is marked .*on.*ull but is null");
pol = new ToscaPolicy();
pol.setName("policy");
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 1f2a4e111..2ed03fa8d 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,6 +32,7 @@ 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;
@@ -55,10 +56,10 @@ public class JpaToscaPolicyTypeTest {
assertNotNull(new JpaToscaPolicyType(new JpaToscaPolicyType()));
assertThatThrownBy(() -> new JpaToscaPolicyType((PfConceptKey) null))
- .hasMessage("key is marked @NonNull but is null");
+ .hasMessageMatching("key is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaPolicyType((JpaToscaPolicyType) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
PfConceptKey ptKey = new PfConceptKey("tdt", VERSION_001);
JpaToscaPolicyType tpt = new JpaToscaPolicyType(ptKey);
@@ -158,7 +159,8 @@ public class JpaToscaPolicyTypeTest {
tpt.getMetadata().remove("nullKey");
assertTrue(tpt.validate(new PfValidationResult()).isValid());
- tpt.setDescription("");;
+ tpt.setDescription("");
+
assertFalse(tpt.validate(new PfValidationResult()).isValid());
tpt.setDescription(A_DESCRIPTION);
assertTrue(tpt.validate(new PfValidationResult()).isValid());
@@ -168,13 +170,13 @@ public class JpaToscaPolicyTypeTest {
tpt.setDerivedFrom(derivedFromKey);
assertTrue(tpt.validate(new PfValidationResult()).isValid());
- assertThatThrownBy(() -> tpt.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> tpt.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaEntityType<ToscaPolicy>((PfConceptKey) null))
- .hasMessage("key is marked @NonNull but is null");
+ .hasMessageMatching("key is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaEntityType<ToscaPolicy>((JpaToscaEntityType<ToscaPolicy>) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
JpaToscaEntityType<ToscaPolicy> tet = new JpaToscaEntityType<>(tpt.getKey());
assertEquals(-1, tet.compareTo(null));
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 8288fd80b..f62adbb5e 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,21 +21,26 @@
package org.onap.policy.models.tosca.simple.concepts;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
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.base.PfValidationResult;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
public class JpaToscaPolicyTypesTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
@Test
public void testPolicyTypes() {
@@ -44,22 +49,64 @@ public class JpaToscaPolicyTypesTest {
assertNotNull(new JpaToscaPolicyTypes(new PfConceptKey(), new TreeMap<PfConceptKey, JpaToscaPolicyType>()));
assertNotNull(new JpaToscaPolicyTypes(new JpaToscaPolicyTypes()));
- assertThatThrownBy(() -> new JpaToscaPolicyTypes((PfConceptKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaPolicyTypes((PfConceptKey) null)).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaPolicyTypes((JpaToscaPolicyTypes) null))
- .hasMessage("copyConcept is marked @NonNull but is null");
+ .hasMessageMatching("copyConcept is marked .*on.*ull but is null");
- assertThatThrownBy(() -> new JpaToscaPolicyTypes(null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaPolicyTypes(null, null)).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaPolicyTypes(new PfConceptKey(), null))
- .hasMessage("conceptMap is marked @NonNull but is null");
+ .hasMessageMatching("conceptMap is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaPolicyTypes(null, new TreeMap<PfConceptKey, JpaToscaPolicyType>()))
- .hasMessage(KEY_IS_NULL);
+ .hasMessageMatching(KEY_IS_NULL);
List<Map<String, ToscaPolicyType>> ptMapList = new ArrayList<>();
ptMapList.add(new LinkedHashMap<>());
- ptMapList.get(0).put("policyType", new ToscaPolicyType());
+
+ ToscaPolicyType pt0 = new ToscaPolicyType();
+ pt0.setName("pt0");
+ pt0.setVersion("0.0.1");
+ pt0.setDescription("pt0 description");
+
+ ptMapList.get(0).put("pt0", pt0);
assertNotNull(new JpaToscaPolicyTypes(ptMapList));
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+ assertThatThrownBy(() -> new JpaToscaPolicyTypes(ptMapList).validate(null))
+ .hasMessageMatching("resultIn is marked .*on.*ull but is null");
+
+ pt0.setDerivedFrom(null);
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+
+ pt0.setDerivedFrom("tosca.PolicyTypes.Root");
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+
+ pt0.setDerivedFrom("some.other.Thing");
+ PfValidationResult result = new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult());
+ assertFalse(result.isValid());
+ assertThat(result.toString()).contains("parent some.other.Thing:0.0.0 of entity not found");
+
+ pt0.setDerivedFrom(null);
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+
+ ToscaPolicyType pt1 = new ToscaPolicyType();
+ pt1.setName("pt1");
+ pt1.setVersion("0.0.1");
+ pt1.setDescription("pt1 description");
+
+ ptMapList.get(0).put("pt1", pt1);
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+
+ pt1.setDerivedFrom("pt0");
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
+
+ pt1.setDerivedFrom("pt2");
+ result = new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult());
+ assertFalse(result.isValid());
+ assertThat(result.toString()).contains("parent pt2:0.0.0 of entity not found");
+
+ pt1.setDerivedFrom("pt0");
+ assertTrue(new JpaToscaPolicyTypes(ptMapList).validate(new PfValidationResult()).isValid());
}
}
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 18837d45d..49e508abc 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -31,6 +31,7 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
+
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
@@ -44,7 +45,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
*/
public class JpaToscaPropertyTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull 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";
@@ -56,14 +57,14 @@ public class JpaToscaPropertyTest {
assertNotNull(new JpaToscaProperty(new PfReferenceKey(), new PfConceptKey()));
assertNotNull(new JpaToscaProperty(new JpaToscaProperty()));
- assertThatThrownBy(() -> new JpaToscaProperty((PfReferenceKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaProperty((PfReferenceKey) null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaProperty(null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaProperty(null, null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaProperty(null, new PfConceptKey())).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaProperty(null, new PfConceptKey())).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaProperty(new PfReferenceKey(), null))
- .hasMessage("type is marked @NonNull but is null");
+ .hasMessageMatching("type is marked .*on.*ull but is null");
PfConceptKey pparentKey = new PfConceptKey("tParentKey", VERSION_001);
PfReferenceKey pkey = new PfReferenceKey(pparentKey, "trigger0");
@@ -92,7 +93,7 @@ public class JpaToscaPropertyTest {
JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey);
tp.setEntrySchema(tes);
- TreeMap<String,String> metadata = new TreeMap<>();
+ TreeMap<String, String> metadata = new TreeMap<>();
metadata.put("metaA", "dataA");
metadata.put("metaB", "dataB");
tp.setMetadata(metadata);
@@ -145,7 +146,7 @@ public class JpaToscaPropertyTest {
assertEquals(0, tp.compareTo(otherDt));
assertThatThrownBy(() -> new JpaToscaProperty((JpaToscaProperty) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
assertEquals(3, tp.getKeys().size());
assertEquals(2, new JpaToscaProperty().getKeys().size());
@@ -189,7 +190,7 @@ public class JpaToscaPropertyTest {
tp.setMetadata(null);
assertTrue(tp.validate(new PfValidationResult()).isValid());
- assertThatThrownBy(() -> tp.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> tp.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
}
@Test
@@ -221,7 +222,7 @@ public class JpaToscaPropertyTest {
JpaToscaEntrySchema tes = new JpaToscaEntrySchema(typeKey);
tp.setEntrySchema(tes);
- TreeMap<String,String> metadata = new TreeMap<>();
+ TreeMap<String, String> metadata = new TreeMap<>();
metadata.put("metaA", "dataA");
metadata.put("metaB", "dataB");
tp.setMetadata(metadata);
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 911f4a1bf..95c51e912 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,6 +29,7 @@ import static org.junit.Assert.assertTrue;
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;
@@ -41,7 +42,7 @@ import org.onap.policy.models.base.PfValidationResult;
*/
public class JpaToscaServiceTemplateTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
private static final String VERSION_001 = "0.0.1";
@Test
@@ -51,17 +52,17 @@ public class JpaToscaServiceTemplateTest {
assertNotNull(new JpaToscaServiceTemplate(new PfConceptKey(), ""));
assertNotNull(new JpaToscaServiceTemplate(new JpaToscaServiceTemplate()));
- assertThatThrownBy(() -> new JpaToscaServiceTemplate((PfConceptKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaServiceTemplate((PfConceptKey) null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaServiceTemplate(null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaServiceTemplate(null, null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaServiceTemplate(null, "")).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaServiceTemplate(null, "")).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaServiceTemplate(new PfConceptKey(), null))
- .hasMessage("toscaDefinitionsVersion is marked @NonNull but is null");
+ .hasMessageMatching("toscaDefinitionsVersion is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaServiceTemplate((JpaToscaServiceTemplate) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
PfConceptKey tstKey = new PfConceptKey("tst", VERSION_001);
JpaToscaServiceTemplate tst = new JpaToscaServiceTemplate(tstKey, "Tosca Version");
@@ -133,6 +134,6 @@ public class JpaToscaServiceTemplateTest {
tst.setDescription("A Description");
assertTrue(tst.validate(new PfValidationResult()).isValid());
- assertThatThrownBy(() -> tst.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> tst.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull 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 075087774..596640f22 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,12 +33,10 @@ import java.util.TreeMap;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
-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";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
@Test
public void testServiceTemplates() {
@@ -50,23 +48,23 @@ public class JpaToscaServiceTemplatesTest {
assertThatThrownBy(() -> {
new JpaToscaServiceTemplates((PfConceptKey) null);
- }).hasMessage(KEY_IS_NULL);
+ }).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> {
new JpaToscaServiceTemplates((JpaToscaServiceTemplates) null);
- }).hasMessage("copyConcept is marked @NonNull but is null");
+ }).hasMessageMatching("copyConcept is marked .*on.*ull but is null");
assertThatThrownBy(() -> {
new JpaToscaServiceTemplates(null, null);
- }).hasMessage(KEY_IS_NULL);
+ }).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> {
new JpaToscaServiceTemplates(new PfConceptKey(), null);
- }).hasMessage("conceptMap is marked @NonNull but is null");
+ }).hasMessageMatching("conceptMap is marked .*on.*ull but is null");
assertThatThrownBy(() -> {
new JpaToscaServiceTemplates(null, new TreeMap<PfConceptKey, JpaToscaServiceTemplate>());
- }).hasMessage(KEY_IS_NULL);
+ }).hasMessageMatching(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 49cf18e28..ca4cac85f 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Date;
+
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfReferenceKey;
@@ -40,7 +41,7 @@ import org.onap.policy.models.base.PfValidationResult;
*/
public class JpaToscaTimeIntervalTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
@Test
public void testTimeIntervalPojo() {
@@ -49,27 +50,28 @@ public class JpaToscaTimeIntervalTest {
assertNotNull(new JpaToscaTimeInterval(new PfReferenceKey(), new Date(), new Date()));
assertNotNull(new JpaToscaTimeInterval(new JpaToscaTimeInterval()));
- assertThatThrownBy(() -> new JpaToscaTimeInterval((PfReferenceKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTimeInterval((PfReferenceKey) null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaTimeInterval(null, null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTimeInterval(null, null, null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaTimeInterval(null, null, new Date())).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTimeInterval(null, null, new Date())).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaTimeInterval(null, new Date(), null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTimeInterval(null, new Date(), null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaTimeInterval(null, new Date(), new Date())).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTimeInterval(null, new Date(), new Date()))
+ .hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaTimeInterval(new PfReferenceKey(), null, null))
- .hasMessage("startTime is marked @NonNull but is null");
+ .hasMessageMatching("startTime is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaTimeInterval(new PfReferenceKey(), null, new Date()))
- .hasMessage("startTime is marked @NonNull but is null");
+ .hasMessageMatching("startTime is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaTimeInterval(new PfReferenceKey(), new Date(), null))
- .hasMessage("endTime is marked @NonNull but is null");
+ .hasMessageMatching("endTime is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaServiceTemplate((JpaToscaServiceTemplate) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
PfConceptKey ttiParentKey = new PfConceptKey("tParentKey", "0.0.1");
PfReferenceKey ttiKey = new PfReferenceKey(ttiParentKey, "trigger0");
@@ -124,6 +126,6 @@ public class JpaToscaTimeIntervalTest {
tti.setEndTime(endTime);
assertTrue(tti.validate(new PfValidationResult()).isValid());
- assertThatThrownBy(() -> tti.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> tti.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull 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 94525f0a9..b0450da64 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 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,6 +29,7 @@ import static org.junit.Assert.assertTrue;
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;
@@ -53,10 +54,10 @@ public class JpaToscaTopologyTemplateTest {
assertNotNull(new JpaToscaTopologyTemplate(new ToscaTopologyTemplate()));
assertThatThrownBy(() -> new JpaToscaTopologyTemplate((PfReferenceKey) null))
- .hasMessage("key is marked @NonNull but is null");
+ .hasMessageMatching("key is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaTopologyTemplate((JpaToscaTopologyTemplate) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
PfReferenceKey tttKey = new PfReferenceKey("tst", VERSION_001, "ttt");
JpaToscaTopologyTemplate ttt = new JpaToscaTopologyTemplate(tttKey);
@@ -98,7 +99,7 @@ public class JpaToscaTopologyTemplateTest {
assertEquals(0, ttt.compareTo(otherDt));
assertThatThrownBy(() -> new JpaToscaTopologyTemplate((JpaToscaTopologyTemplate) null))
- .isInstanceOf(NullPointerException.class);
+ .isInstanceOf(NullPointerException.class);
assertEquals(4, ttt.getKeys().size());
assertEquals(1, new JpaToscaTopologyTemplate().getKeys().size());
@@ -122,6 +123,6 @@ public class JpaToscaTopologyTemplateTest {
ttt.setDescription(A_DESCRIPTION);
assertTrue(ttt.validate(new PfValidationResult()).isValid());
- assertThatThrownBy(() -> ttt.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> ttt.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull 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 0baf1e5e2..a7a754f93 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,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
* Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -29,6 +29,7 @@ import static org.junit.Assert.assertTrue;
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;
@@ -41,7 +42,7 @@ import org.onap.policy.models.base.PfValidationResult;
*/
public class JpaToscaTriggerTest {
- private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+ private static final String KEY_IS_NULL = "key is marked .*on.*ull but is null";
private static final String EVENT_TYPE = "EventType";
private static final String ACTION = "Action";
private static final String A_METHOD = "A Method";
@@ -55,27 +56,26 @@ public class JpaToscaTriggerTest {
assertNotNull(new JpaToscaTrigger(new PfReferenceKey(), EVENT_TYPE, ACTION));
assertNotNull(new JpaToscaTrigger(new JpaToscaTrigger()));
- assertThatThrownBy(() -> new JpaToscaTrigger((PfReferenceKey) null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTrigger((PfReferenceKey) null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaTrigger(null, null, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTrigger(null, null, null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaTrigger(null, EVENT_TYPE, null)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTrigger(null, EVENT_TYPE, null)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaTrigger(null, EVENT_TYPE, ACTION)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTrigger(null, EVENT_TYPE, ACTION)).hasMessageMatching(KEY_IS_NULL);
- assertThatThrownBy(() -> new JpaToscaTrigger(null, null, ACTION)).hasMessage(KEY_IS_NULL);
+ assertThatThrownBy(() -> new JpaToscaTrigger(null, null, ACTION)).hasMessageMatching(KEY_IS_NULL);
assertThatThrownBy(() -> new JpaToscaTrigger(new PfReferenceKey(), null, null))
- .hasMessage("eventType is marked @NonNull but is null");
+ .hasMessageMatching("eventType is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaTrigger(new PfReferenceKey(), EVENT_TYPE, null))
- .hasMessage("action is marked @NonNull but is null");
+ .hasMessageMatching("action is marked .*on.*ull but is null");
assertThatThrownBy(() -> new JpaToscaTrigger(new PfReferenceKey(), null, ACTION))
- .hasMessage("eventType is marked @NonNull but is null");
+ .hasMessageMatching("eventType is marked .*on.*ull but is null");
- assertThatThrownBy(() -> new JpaToscaTrigger((JpaToscaTrigger) null))
- .isInstanceOf(NullPointerException.class);
+ assertThatThrownBy(() -> new JpaToscaTrigger((JpaToscaTrigger) null)).isInstanceOf(NullPointerException.class);
PfConceptKey tparentKey = new PfConceptKey("tParentKey", VERSION_001);
PfReferenceKey tkey = new PfReferenceKey(tparentKey, "trigger0");
@@ -175,6 +175,6 @@ public class JpaToscaTriggerTest {
tdt.setMethod(A_METHOD);
assertTrue(tdt.validate(new PfValidationResult()).isValid());
- assertThatThrownBy(() -> tdt.validate(null)).hasMessage("resultIn is marked @NonNull but is null");
+ assertThatThrownBy(() -> tdt.validate(null)).hasMessageMatching("resultIn is marked .*on.*ull but is null");
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java
index cc6f8f0d0..ca46de1c3 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaServiceTemplateUtilsTest.java
@@ -201,6 +201,5 @@ public class ToscaServiceTemplateUtilsTest {
assertEquals(dt1, dtIterator.next());
assertEquals(pt0, compositeTemplate05.getPolicyTypes().getAll(null).iterator().next());
assertEquals(p0, compositeTemplate05.getTopologyTemplate().getPolicies().getAll(null).iterator().next());
-
}
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java
index 82636940c..ecd066a14 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/utils/ToscaUtilsTest.java
@@ -28,6 +28,9 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfKey;
+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.JpaToscaPolicies;
import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyTypes;
@@ -137,4 +140,107 @@ public class ToscaUtilsTest {
ToscaUtils.assertPoliciesExist(jpaToscaServiceTemplate);
}).doesNotThrowAnyException();
}
+
+ @Test
+ public void testGetentityTypeAncestors() {
+ assertThatThrownBy(() -> {
+ ToscaUtils.getEntityTypeAncestors(null, null, null);
+ }).hasMessageMatching("entityTypes is marked .*on.*ull but is null");
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.getEntityTypeAncestors(null, null, new PfValidationResult());
+ }).hasMessageMatching("entityTypes is marked .*on.*ull but is null");
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.getEntityTypeAncestors(null, new JpaToscaDataType(), null);
+ }).hasMessageMatching("entityTypes is marked .*on.*ull but is null");
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.getEntityTypeAncestors(null, new JpaToscaDataType(), new PfValidationResult());
+ }).hasMessageMatching("entityTypes is marked .*on.*ull but is null");
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.getEntityTypeAncestors(new JpaToscaDataTypes(), null, null);
+ }).hasMessageMatching("entityType is marked .*on.*ull but is null");
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.getEntityTypeAncestors(new JpaToscaDataTypes(), null, new PfValidationResult());
+ }).hasMessageMatching("entityType is marked .*on.*ull but is null");
+
+ assertThatThrownBy(() -> {
+ ToscaUtils.getEntityTypeAncestors(new JpaToscaDataTypes(), new JpaToscaDataType(), null);
+ }).hasMessageMatching("result is marked .*on.*ull but is null");
+
+ JpaToscaDataTypes dataTypes = new JpaToscaDataTypes();
+ JpaToscaDataType dt0 = new JpaToscaDataType();
+ dt0.setKey(new PfConceptKey("dt0", "0.0.1"));
+ dt0.setDescription("dt0 description");
+ PfValidationResult result = new PfValidationResult();
+
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+
+ dataTypes.getConceptMap().put(dt0.getKey(), dt0);
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertTrue(result.isValid());
+
+ dt0.setDerivedFrom(null);
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertTrue(result.isValid());
+
+ dt0.setDerivedFrom(new PfConceptKey("tosca.datatyps.Root", PfKey.NULL_KEY_VERSION));
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertTrue(result.isValid());
+
+ dt0.setDerivedFrom(new PfConceptKey("some.thing.Else", PfKey.NULL_KEY_VERSION));
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertFalse(result.isValid());
+ assertTrue(result.toString().contains("parent some.thing.Else:0.0.0 of entity not found"));
+
+ result = new PfValidationResult();
+ dt0.setDerivedFrom(new PfConceptKey("tosca.datatyps.Root", PfKey.NULL_KEY_VERSION));
+
+ JpaToscaDataType dt1 = new JpaToscaDataType();
+ dt1.setKey(new PfConceptKey("dt1", "0.0.1"));
+ dt1.setDescription("dt1 description");
+ dataTypes.getConceptMap().put(dt1.getKey(), dt1);
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).isEmpty());
+ assertTrue(result.isValid());
+
+ dt1.setDerivedFrom(dt0.getKey());
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).isEmpty());
+ assertEquals(1, ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).size());
+ assertTrue(result.isValid());
+
+ JpaToscaDataType dt2 = new JpaToscaDataType();
+ dt2.setKey(new PfConceptKey("dt2", "0.0.1"));
+ dt2.setDescription("dt2 description");
+ dataTypes.getConceptMap().put(dt2.getKey(), dt2);
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).isEmpty());
+ assertEquals(1, ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).size());
+ assertTrue(result.isValid());
+
+ dt2.setDerivedFrom(dt1.getKey());
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).isEmpty());
+ assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).isEmpty());
+ assertEquals(1, ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).size());
+ assertEquals(2, ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).size());
+ assertTrue(result.isValid());
+
+ dt1.setDerivedFrom(new PfConceptKey("tosca.datatyps.Root", PfKey.NULL_KEY_VERSION));
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt0, result).isEmpty());
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).isEmpty());
+ assertFalse(ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).isEmpty());
+ assertEquals(0, ToscaUtils.getEntityTypeAncestors(dataTypes, dt1, result).size());
+ assertEquals(1, ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).size());
+ assertTrue(result.isValid());
+
+ dataTypes.getConceptMap().remove(dt1.getKey());
+ assertTrue(ToscaUtils.getEntityTypeAncestors(dataTypes, dt2, result).isEmpty());
+ assertFalse(result.isValid());
+ assertTrue(result.toString().contains("parent dt1:0.0.1 of entity not found"));
+ }
}