diff options
Diffstat (limited to 'models-base/src/test')
9 files changed, 145 insertions, 124 deletions
diff --git a/models-base/src/test/java/org/onap/policy/models/base/ModelServiceTest.java b/models-base/src/test/java/org/onap/policy/models/base/ModelServiceTest.java index 1b7a996ed..60ae85dd8 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/ModelServiceTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/ModelServiceTest.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,7 +31,7 @@ import org.onap.policy.models.base.testconcepts.DummyPfModel; public class ModelServiceTest { - private static final String MODEL_KEY_IS_NULL = "modelKey is marked @NonNull but is null"; + private static final String MODEL_KEY_IS_NULL = "modelKey is marked .*on.*ull but is null$"; private static final String MODEL_NAME = "ModelName"; @Test @@ -40,7 +40,7 @@ public class ModelServiceTest { assertFalse(PfModelService.existsModel("NonExistantName")); assertThatThrownBy(() -> PfModelService.getModel("NonExistantName")) - .hasMessage("Model for name NonExistantName not found in model service"); + .hasMessage("Model for name NonExistantName not found in model service"); PfModelService.registerModel(MODEL_NAME, new DummyPfModel()); assertTrue(PfModelService.existsModel(MODEL_NAME)); @@ -50,7 +50,7 @@ public class ModelServiceTest { assertFalse(PfModelService.existsModel(MODEL_NAME)); assertThatThrownBy(() -> PfModelService.getModel(MODEL_NAME)) - .hasMessage("Model for name ModelName not found in model service"); + .hasMessage("Model for name ModelName not found in model service"); PfModelService.registerModel(MODEL_NAME, new DummyPfModel()); assertTrue(PfModelService.existsModel(MODEL_NAME)); @@ -59,20 +59,18 @@ public class ModelServiceTest { PfModelService.clear(); assertFalse(PfModelService.existsModel(MODEL_NAME)); assertThatThrownBy(() -> PfModelService.getModel(MODEL_NAME)) - .hasMessage("Model for name ModelName not found in model service"); + .hasMessage("Model for name ModelName not found in model service"); - assertThatThrownBy(() -> PfModelService.registerModel(null, null)) - .hasMessage(MODEL_KEY_IS_NULL); + assertThatThrownBy(() -> PfModelService.registerModel(null, null)).hasMessageMatching(MODEL_KEY_IS_NULL); assertThatThrownBy(() -> PfModelService.registerModel("nullModelName", null)) - .hasMessage("model is marked @NonNull but is null"); + .hasMessageMatching("^model is marked .*on.*ull but is null$"); assertThatThrownBy(() -> PfModelService.registerModel(null, new DummyPfModel())) - .hasMessage(MODEL_KEY_IS_NULL); + .hasMessageMatching(MODEL_KEY_IS_NULL); - assertThatThrownBy(() -> PfModelService.deregisterModel(null)) - .hasMessage(MODEL_KEY_IS_NULL); + assertThatThrownBy(() -> PfModelService.deregisterModel(null)).hasMessageMatching(MODEL_KEY_IS_NULL); - assertThatThrownBy(() -> PfModelService.getModel(null)).hasMessage(MODEL_KEY_IS_NULL); + assertThatThrownBy(() -> PfModelService.getModel(null)).hasMessageMatching(MODEL_KEY_IS_NULL); } } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java index b760e17c0..8234741f6 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptContainerTest.java @@ -48,12 +48,14 @@ import org.onap.policy.models.base.testconcepts.DummyPfConceptSub; */ public class PfConceptContainerTest { - private static final String NAME2 = "name2"; - private static final String NAME1 = "name1"; private static final String NAME0 = "name0"; - private static final String KEY_IS_NULL = "key is marked @NonNull but is null"; + private static final String NAME1 = "name1"; + private static final String NAME2 = "name2"; + private static final String NAME3 = "name3"; + private static final String ID3 = "name3:0.0.1"; + private static final String VERSION0_0_1 = "0.0.1"; + private static final String KEY_IS_NULL = "^key is marked .*on.*ull but is null$"; private static final String DUMMY_VALUE = "Dummy"; - private static final String VERSION0 = "0.0.1"; @SuppressWarnings({"unchecked", "rawtypes"}) @Test @@ -70,15 +72,16 @@ public class PfConceptContainerTest { container = new DummyPfConceptContainer(new PfConceptKey(), new TreeMap<PfConceptKey, DummyPfConcept>()); assertNotNull(container); - assertThatThrownBy(() -> new PfConceptContainer((PfConceptKey) null, null)).hasMessage(KEY_IS_NULL); + assertThatThrownBy(() -> new PfConceptContainer((PfConceptKey) null, null)).hasMessageMatching(KEY_IS_NULL); - assertThatThrownBy(() -> new DummyPfConceptContainer((PfConceptKey) null, null)).hasMessage(KEY_IS_NULL); + assertThatThrownBy(() -> new DummyPfConceptContainer((PfConceptKey) null, null)) + .hasMessageMatching(KEY_IS_NULL); assertThatThrownBy(() -> new DummyPfConceptContainer(new PfConceptKey(), null)) - .hasMessage("conceptMap is marked @NonNull but is null"); + .hasMessageMatching("^conceptMap is marked .*on.*ull but is null$"); assertThatThrownBy(() -> new DummyPfConceptContainer(null, new TreeMap<PfConceptKey, DummyPfConcept>())) - .hasMessage(KEY_IS_NULL); + .hasMessageMatching(KEY_IS_NULL); container.getKey().setName(DUMMY_VALUE); DummyPfConceptContainer clonedContainer = new DummyPfConceptContainer(container); @@ -86,12 +89,12 @@ public class PfConceptContainerTest { assertEquals(DUMMY_VALUE, clonedContainer.getKey().getName()); assertThatThrownBy(() -> new DummyPfConceptContainer((DummyPfConceptContainer) null)) - .hasMessage("copyConcept is marked @NonNull but is null"); + .hasMessageMatching("^copyConcept is marked .*on.*ull but is null$"); List<PfKey> keyList = container.getKeys(); assertEquals(1, keyList.size()); - PfConceptKey conceptKey = new PfConceptKey("Key", VERSION0); + PfConceptKey conceptKey = new PfConceptKey("Key", VERSION0_0_1); Map<PfConceptKey, DummyPfConcept> conceptMap = new TreeMap<>(); conceptMap.put(conceptKey, new DummyPfConcept(conceptKey)); @@ -115,7 +118,7 @@ public class PfConceptContainerTest { assertEquals(0, container.compareTo(clonedContainer)); assertThatThrownBy(() -> new DummyPfConceptContainer((DummyPfConceptContainer) null)) - .isInstanceOf(NullPointerException.class); + .isInstanceOf(NullPointerException.class); assertFalse(container.compareTo(null) == 0); assertEquals(0, container.compareTo(container)); @@ -127,16 +130,17 @@ public class PfConceptContainerTest { testContainer.getKey().setVersion(container.getKey().getVersion()); assertEquals(0, container.compareTo(testContainer)); - PfConceptKey testConceptKey = new PfConceptKey("TestKey", VERSION0); + PfConceptKey testConceptKey = new PfConceptKey("TestKey", VERSION0_0_1); testContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey)); assertFalse(container.compareTo(testContainer) == 0); final DummyPfConceptContainer container3 = container; - assertThatThrownBy(() -> container3.validate(null)).hasMessage("resultIn is marked @NonNull but is null"); + assertThatThrownBy(() -> container3.validate(null)) + .hasMessageMatching("^resultIn is marked .*on.*ull but is null$"); DummyPfConceptContainer validateContainer = new DummyPfConceptContainer(); assertFalse(validateContainer.validate(new PfValidationResult()).isOk()); - validateContainer.setKey(new PfConceptKey("VCKey", VERSION0)); + validateContainer.setKey(new PfConceptKey("VCKey", VERSION0_0_1)); assertTrue(validateContainer.validate(new PfValidationResult()).isOk()); validateContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey)); @@ -174,32 +178,51 @@ public class PfConceptContainerTest { public void testAuthorative() { Map<String, DummyAuthorativeConcept> dacMap = new LinkedHashMap<>(); dacMap.put(NAME0, new DummyAuthorativeConcept(NAME0, "1.2.3", "Hello")); - dacMap.put(NAME1, new DummyAuthorativeConcept(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION, "Hi")); + dacMap.put(NAME1, new DummyAuthorativeConcept("IncorrectName", PfKey.NULL_KEY_VERSION, "Hi")); dacMap.put(NAME2, new DummyAuthorativeConcept(NAME2, "1.2.3", "Howdy")); + dacMap.put(ID3, new DummyAuthorativeConcept(NAME3, "9.9.9", "Ciao")); + dacMap.put("name4:1.2.3", new DummyAuthorativeConcept(null, null, "Slan")); + dacMap.put("name5", new DummyAuthorativeConcept(null, null, "Bye")); List<Map<String, DummyAuthorativeConcept>> authorativeList = new ArrayList<>(); authorativeList.add(dacMap); DummyPfConceptContainer container = new DummyPfConceptContainer(); + + assertThatThrownBy(() -> container.fromAuthorative(authorativeList)) + .hasMessage("Key name1:0.0.0 field name1 does not match the value IncorrectName in the concept field"); + + dacMap.put(NAME1, new DummyAuthorativeConcept(NAME1, PfKey.NULL_KEY_VERSION, "Hi")); + + assertThatThrownBy(() -> container.fromAuthorative(authorativeList)) + .hasMessage("Key name3:0.0.1 field 0.0.1 does not match the value 9.9.9 in the concept field"); + + dacMap.put(ID3, new DummyAuthorativeConcept(NAME3, "0.0.1", "Ciao")); + container.fromAuthorative(authorativeList); assertEquals("Hello", container.getConceptMap().get(new PfConceptKey("name0:1.2.3")).getDescription()); - assertEquals("Hi", container.getConceptMap().get(new PfConceptKey("NULL:0.0.0")).getDescription()); + assertEquals("Hi", container.getConceptMap().get(new PfConceptKey("name1:0.0.0")).getDescription()); assertEquals("Howdy", container.getConceptMap().get(new PfConceptKey("name2:1.2.3")).getDescription()); + assertEquals("Ciao", container.getConceptMap().get(new PfConceptKey("name3:0.0.1")).getDescription()); + assertEquals("name4", container.getConceptMap().get(new PfConceptKey("name4:1.2.3")).getName()); + assertEquals("1.2.3", container.getConceptMap().get(new PfConceptKey("name4:1.2.3")).getVersion()); + assertEquals("0.0.0", container.getConceptMap().get(new PfConceptKey("name5:0.0.0")).getVersion()); List<Map<String, DummyAuthorativeConcept>> outMapList = container.toAuthorative(); - assertEquals(dacMap.get(NAME1), outMapList.get(0).get("NULL")); - assertEquals(dacMap.get(NAME0).getDescription(), outMapList.get(1).get(NAME0).getDescription()); + assertEquals(dacMap.get(NAME0), outMapList.get(0).get(NAME0)); + assertEquals(dacMap.get(NAME1).getDescription(), outMapList.get(1).get(NAME1).getDescription()); assertEquals(dacMap.get(NAME2), outMapList.get(2).get(NAME2)); + assertEquals(dacMap.get(NAME3), outMapList.get(2).get(NAME3)); DummyBadPfConceptContainer badContainer = new DummyBadPfConceptContainer(); assertThatThrownBy(() -> badContainer.fromAuthorative(authorativeList)) - .hasMessage("failed to instantiate instance of container concept class"); + .hasMessage("failed to instantiate instance of container concept class"); authorativeList.clear(); assertThatThrownBy(() -> container.fromAuthorative(authorativeList)) - .hasMessage("An incoming list of concepts must have at least one entry"); + .hasMessage("An incoming list of concepts must have at least one entry"); } @Test(expected = NullPointerException.class) diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfConceptKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptKeyTest.java index a29858393..62d8d2bb3 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfConceptKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptKeyTest.java @@ -1,5 +1,6 @@ /*- * ============LICENSE_START======================================================= + * 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,7 +33,7 @@ import org.onap.policy.models.base.testconcepts.DummyPfConcept; public class PfConceptKeyTest { private static final String VERSION001 = "0.0.1"; - private static final String ID_IS_NULL = "id is marked @NonNull but is null"; + private static final String ID_IS_NULL = "id is marked .*on.*ull but is null$"; @Test public void testConceptKey() { @@ -47,6 +48,7 @@ public class PfConceptKeyTest { assertEquals(someKey1, someKey2); assertEquals(someKey1, someKey3); assertFalse(someKey1.isNullVersion()); + assertFalse(someKey1.isNullName()); assertEquals("PfConceptKey(name=my-name, version=0.0.1)", someKey1.toString()); assertEquals("my-name", someKey1.getName()); @@ -55,7 +57,6 @@ public class PfConceptKeyTest { assertEquals(someKey2, someKey1.getKey()); assertEquals(1, someKey1.getKeys().size()); - PfConcept pfc = new DummyPfConcept(); assertEquals(PfConceptKey.getNullKey().getId(), pfc.getId()); @@ -63,16 +64,16 @@ public class PfConceptKeyTest { assertTrue(PfConceptKey.getNullKey().isNullKey()); - assertThatThrownBy(() -> PfConceptKey.getNullKey().matchesId(null)).hasMessage(ID_IS_NULL); + assertThatThrownBy(() -> PfConceptKey.getNullKey().matchesId(null)).hasMessageMatching(ID_IS_NULL); assertThatThrownBy(() -> someKey0.setName(null)).isInstanceOf(NullPointerException.class) - .hasMessage("name is marked @NonNull but is null"); + .hasMessageMatching("^name is marked .*on.*ull but is null$"); assertThatThrownBy(() -> someKey0.setVersion(null)).isInstanceOf(NullPointerException.class) - .hasMessage("version is marked @NonNull but is null"); + .hasMessageMatching("^version is marked .*on.*ull but is null$"); assertThatIllegalArgumentException().isThrownBy(() -> new PfConceptKey("my-name.*", VERSION001)).withMessage( - "parameter 'name': value 'my-name.*', does not match regular expression '^[A-Za-z0-9\\-_\\.]+$'" - .replace('\'', '"')); + "parameter 'name': value 'my-name.*', does not match regular expression '^[A-Za-z0-9\\-_\\.]+$'" + .replace('\'', '"')); } } 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 f467ec35a..4210bc607 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 @@ -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,18 +29,20 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.lang.reflect.Field; + import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; + import org.junit.Test; import org.onap.policy.models.base.PfKey.Compatibility; import org.onap.policy.models.base.testconcepts.DummyPfKey; public class PfKeyImplTest { - private static final String OTHER_IS_NULL = "otherKey is marked @NonNull but is null"; - private static final String ID_IS_NULL = "id is marked @NonNull but is null"; + private static final String OTHER_IS_NULL = "^otherKey is marked .*on.*ull but is null$"; + private static final String ID_IS_NULL = "^id is marked .*on.*ull but is null$"; private static final String VERSION123 = "1.2.3"; private static final String VERSION100 = "1.0.0"; private static final String VERSION001 = "0.0.1"; @@ -48,11 +50,11 @@ public class PfKeyImplTest { @Test public void testConceptKey() { assertThatIllegalArgumentException().isThrownBy(() -> new MyKey("some bad key id")) - .withMessage("parameter \"id\": value \"some bad key id\", " - + "does not match regular expression \"" + PfKey.KEY_ID_REGEXP + "\""); + .withMessage("parameter \"id\": value \"some bad key id\", " + "does not match regular expression \"" + + PfKey.KEY_ID_REGEXP + "\""); assertThatThrownBy(() -> new MyKey((MyKey) null)) - .hasMessage("copyConcept is marked @NonNull but is null"); + .hasMessageMatching("^copyConcept is marked .*on.*ull but is null$"); MyKey someKey0 = new MyKey(); assertTrue(someKey0.isNullKey()); @@ -89,7 +91,7 @@ public class PfKeyImplTest { assertEquals("name:0.1.2", someKey4.getId()); assertThatThrownBy(() -> someKey0.getCompatibility(null)).isInstanceOf(NullPointerException.class) - .hasMessage("otherKey is marked @NonNull but is null"); + .hasMessageMatching("^otherKey is marked .*on.*ull but is null$"); assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(new DummyPfKey())); assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(someKey1)); @@ -109,19 +111,19 @@ public class PfKeyImplTest { assertFalse(someKey1.isCompatible(new DummyPfKey())); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey0.validate(new PfValidationResult()).getValidationResult()); + someKey0.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey1.validate(new PfValidationResult()).getValidationResult()); + someKey1.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey2.validate(new PfValidationResult()).getValidationResult()); + someKey2.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey3.validate(new PfValidationResult()).getValidationResult()); + someKey3.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey4.validate(new PfValidationResult()).getValidationResult()); + someKey4.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey5.validate(new PfValidationResult()).getValidationResult()); + someKey5.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey6.validate(new PfValidationResult()).getValidationResult()); + someKey6.validate(new PfValidationResult()).getValidationResult()); someKey0.clean(); assertNotNull(someKey0.toString()); @@ -132,7 +134,7 @@ public class PfKeyImplTest { assertEquals(-12, someKey7.compareTo(someKey0)); assertThatThrownBy(() -> someKey0.compareTo(null)).isInstanceOf(NullPointerException.class) - .hasMessage("otherObj is marked @NonNull but is null"); + .hasMessageMatching("^otherObj is marked .*on.*ull but is null$"); assertEquals(0, someKey0.compareTo(someKey0)); assertEquals(-36, someKey0.compareTo(new DummyPfKey())); @@ -148,18 +150,20 @@ public class PfKeyImplTest { @Test public void testNullArguments() { - assertThatThrownBy(() -> new MyKey((String) null)).hasMessage(ID_IS_NULL); + assertThatThrownBy(() -> new MyKey((String) null)).hasMessageMatching(ID_IS_NULL); assertThatThrownBy(() -> new MyKey((MyKey) null)) - .hasMessage("copyConcept is marked @NonNull but is null"); + .hasMessageMatching("^copyConcept is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> new MyKey(null, null)).hasMessage("name is marked @NonNull but is null"); + assertThatThrownBy(() -> new MyKey(null, null)).hasMessageMatching("name is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> new MyKey("name", null)).hasMessage("version is marked @NonNull but is null"); + assertThatThrownBy(() -> new MyKey("name", null)) + .hasMessageMatching("^version is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> new MyKey(null, VERSION001)).hasMessage("name is marked @NonNull but is null"); + assertThatThrownBy(() -> new MyKey(null, VERSION001)) + .hasMessageMatching("^name is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> new MyKey("AKey", VERSION001).isCompatible(null)).hasMessage(OTHER_IS_NULL); + assertThatThrownBy(() -> new MyKey("AKey", VERSION001).isCompatible(null)).hasMessageMatching(OTHER_IS_NULL); } @Test @@ -174,10 +178,8 @@ public class PfKeyImplTest { testKey.validate(validationResult); nameField.set(testKey, "TheKey"); nameField.setAccessible(false); - assertEquals( - "name invalid-parameter name with value Key Name " - + "does not match regular expression " + PfKey.NAME_REGEXP, - validationResult.getMessageList().get(0).getMessage()); + assertEquals("name invalid-parameter name with value Key Name " + "does not match regular expression " + + PfKey.NAME_REGEXP, validationResult.getMessageList().get(0).getMessage()); Field versionField = testKey.getClass().getDeclaredField("version"); versionField.setAccessible(true); @@ -186,21 +188,18 @@ public class PfKeyImplTest { testKey.validate(validationResult2); versionField.set(testKey, VERSION001); versionField.setAccessible(false); - assertEquals( - "version invalid-parameter version with value Key Version " - + "does not match regular expression " + PfKey.VERSION_REGEXP, - validationResult2.getMessageList().get(0).getMessage()); + assertEquals("version invalid-parameter version with value Key Version " + "does not match regular expression " + + PfKey.VERSION_REGEXP, validationResult2.getMessageList().get(0).getMessage()); } @Test public void testkeynewerThan() { MyKey key1 = new MyKey("Key1", VERSION123); - assertThatThrownBy(() -> key1.isNewerThan(null)).hasMessage(OTHER_IS_NULL); + assertThatThrownBy(() -> key1.isNewerThan(null)).hasMessageMatching(OTHER_IS_NULL); - assertThatThrownBy(() -> key1.isNewerThan(new PfReferenceKey())) - .hasMessage("org.onap.policy.models.base.PfReferenceKey is not " - + "an instance of " + PfKeyImpl.class.getName()); + assertThatThrownBy(() -> key1.isNewerThan(new PfReferenceKey())).hasMessage( + "org.onap.policy.models.base.PfReferenceKey is not " + "an instance of " + PfKeyImpl.class.getName()); assertFalse(key1.isNewerThan(key1)); @@ -241,10 +240,10 @@ public class PfKeyImplTest { PfReferenceKey refKey = new PfReferenceKey(); - assertThatThrownBy(() -> refKey.isNewerThan(null)).hasMessage(OTHER_IS_NULL); + assertThatThrownBy(() -> refKey.isNewerThan(null)).hasMessageMatching(OTHER_IS_NULL); assertThatThrownBy(() -> refKey.isNewerThan(new MyKey())) - .hasMessage(MyKey.class.getName() + " is not an instance of " + PfReferenceKey.class.getName()); + .hasMessage(MyKey.class.getName() + " is not an instance of " + PfReferenceKey.class.getName()); assertFalse(refKey.isNewerThan(refKey)); } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java index 3e5d738bd..46a00664f 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.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"); @@ -34,7 +34,7 @@ import org.onap.policy.models.base.testconcepts.DummyPfConceptKeySub; public class PfKeyUseTest { - private static final String OTHER_KEY_IS_NULL = "otherKey is marked @NonNull but is null"; + private static final String OTHER_KEY_IS_NULL = "^otherKey is marked .*on.*ull but is null$"; @Test public void testKeyUse() { @@ -43,7 +43,7 @@ public class PfKeyUseTest { assertNotNull(new PfKeyUse(new PfReferenceKey())); assertThatThrownBy(() -> new PfKeyUse((PfKeyUse) null)) - .hasMessage("copyConcept is marked @NonNull but is null"); + .hasMessageMatching("^copyConcept is marked .*on.*ull but is null$"); PfConceptKey key = new PfConceptKey("Key", "0.0.1"); PfKeyUse keyUse = new PfKeyUse(); @@ -55,7 +55,7 @@ public class PfKeyUseTest { assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key)); - assertThatThrownBy(() -> key.getCompatibility(null)).hasMessage(OTHER_KEY_IS_NULL); + assertThatThrownBy(() -> key.getCompatibility(null)).hasMessageMatching(OTHER_KEY_IS_NULL); assertTrue(keyUse.isCompatible(key)); @@ -87,20 +87,20 @@ public class PfKeyUseTest { PfValidationResult resultNull = new PfValidationResult(); assertEquals(false, keyUseNull.validate(resultNull).isValid()); - assertThatThrownBy(() -> keyUse.setKey(null)).hasMessage("key is marked @NonNull but is null"); + assertThatThrownBy(() -> keyUse.setKey(null)).hasMessageMatching("^key is marked .*on.*ull but is null$"); - assertThatThrownBy(() -> keyUse.getCompatibility(null)).hasMessage(OTHER_KEY_IS_NULL); + assertThatThrownBy(() -> keyUse.getCompatibility(null)).hasMessageMatching(OTHER_KEY_IS_NULL); - assertThatThrownBy(() -> keyUse.isCompatible(null)).hasMessage(OTHER_KEY_IS_NULL); + assertThatThrownBy(() -> keyUse.isCompatible(null)).hasMessageMatching(OTHER_KEY_IS_NULL); - assertThatThrownBy(() -> keyUse.validate(null)).hasMessage("result is marked @NonNull but is null"); + assertThatThrownBy(() -> keyUse.validate(null)).hasMessageMatching("^result is marked .*on.*ull but is null$"); PfKeyUse testKeyUse = new PfKeyUse(new DummyPfConceptKeySub(new PfConceptKey())); assertEquals(testKeyUse, new PfKeyUse(testKeyUse)); assertThatThrownBy(() -> new PfKeyUse((PfKeyUse) null)).isInstanceOf(NullPointerException.class); - assertThatThrownBy(() -> keyUse.isNewerThan(null)).hasMessage(OTHER_KEY_IS_NULL); + assertThatThrownBy(() -> keyUse.isNewerThan(null)).hasMessageMatching(OTHER_KEY_IS_NULL); assertEquals(false, testKeyUse.isNewerThan(keyUse)); assertEquals(false, testKeyUse.isNewerThan(testKeyUse)); diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java index 9b1a778ac..c124393fe 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfModelTest.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"); @@ -46,10 +46,10 @@ public class PfModelTest { assertNotNull(new DummyPfModel(new DummyPfModel())); assertThatThrownBy(() -> new DummyPfModel((PfConceptKey) null)) - .hasMessage("key is marked @NonNull but is null"); + .hasMessageMatching("^key is marked .*on.*ull but is null$"); assertThatThrownBy(() -> new DummyPfModel((DummyPfModel) null)) - .hasMessage("copyConcept is marked @NonNull but is null"); + .hasMessageMatching("^copyConcept is marked .*on.*ull but is null$"); DummyPfModel dpm = new DummyPfModel(new PfConceptKey("modelKey", VERSION001)); DummyPfModel dpmClone = new DummyPfModel(dpm); @@ -74,7 +74,7 @@ public class PfModelTest { DummyPfModel dpm = new DummyPfModel(dpmKey); assertTrue(dpm.validate(new PfValidationResult()).isValid()); - assertThatThrownBy(() -> dpm.validate(null)).hasMessage("resultIn is marked @NonNull but is null"); + assertThatThrownBy(() -> dpm.validate(null)).hasMessageMatching("^resultIn is marked .*on.*ull but is null$"); dpm.setKey(PfConceptKey.getNullKey()); assertFalse(dpm.validate(new PfValidationResult()).isValid()); diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java index b12ce4de0..ba36b9e8f 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 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.assertNotNull; import static org.junit.Assert.assertTrue; import java.lang.reflect.Field; + import org.junit.Test; public class PfReferenceKeyTest { @@ -54,7 +55,7 @@ public class PfReferenceKeyTest { assertEquals("NULL:0.0.0:NULL:NULL", PfReferenceKey.getNullKey().getId()); assertThatThrownBy(() -> new PfReferenceKey(new PfConceptKey(), null)) - .hasMessage("parameter \"localName\" is null"); + .hasMessage("parameter \"localName\" is null"); PfReferenceKey testReferenceKey = new PfReferenceKey(); testReferenceKey.setParentConceptKey(new PfConceptKey("PN", VERSION001)); @@ -83,7 +84,7 @@ public class PfReferenceKeyTest { assertEquals("NLN", testReferenceKey.getLocalName()); assertThatThrownBy(() -> testReferenceKey.isCompatible(null)) - .hasMessage("otherKey is marked @NonNull but is null"); + .hasMessageMatching("^otherKey is marked .*on.*ull but is null$"); assertFalse(testReferenceKey.isCompatible(PfConceptKey.getNullKey())); assertFalse(testReferenceKey.isCompatible(PfReferenceKey.getNullKey())); @@ -101,7 +102,7 @@ public class PfReferenceKeyTest { PfReferenceKey clonedReferenceKey = new PfReferenceKey(testReferenceKey); assertEquals("PfReferenceKey(parentKeyName=NPKN, parentKeyVersion=0.0.1, parentLocalName=NPKLN, localName=NLN)", - clonedReferenceKey.toString()); + clonedReferenceKey.toString()); assertFalse(testReferenceKey.hashCode() == 0); @@ -144,9 +145,9 @@ public class PfReferenceKeyTest { parentNameField.set(testReferenceKey, "ParentName"); parentNameField.setAccessible(false); assertEquals( - "parentKeyName invalid-parameter parentKeyName with value Parent Name " - + "does not match regular expression " + PfKey.NAME_REGEXP, - validationResult.getMessageList().get(0).getMessage()); + "parentKeyName invalid-parameter parentKeyName with value Parent Name " + + "does not match regular expression " + PfKey.NAME_REGEXP, + validationResult.getMessageList().get(0).getMessage()); Field parentVersionField = testReferenceKey.getClass().getDeclaredField("parentKeyVersion"); parentVersionField.setAccessible(true); @@ -156,9 +157,9 @@ public class PfReferenceKeyTest { parentVersionField.set(testReferenceKey, VERSION001); parentVersionField.setAccessible(false); assertEquals( - "parentKeyVersion invalid-parameter parentKeyVersion with value Parent Version " - + "does not match regular expression " + PfKey.VERSION_REGEXP, - validationResult2.getMessageList().get(0).getMessage()); + "parentKeyVersion invalid-parameter parentKeyVersion with value Parent Version " + + "does not match regular expression " + PfKey.VERSION_REGEXP, + validationResult2.getMessageList().get(0).getMessage()); Field parentLocalNameField = testReferenceKey.getClass().getDeclaredField("parentLocalName"); parentLocalNameField.setAccessible(true); @@ -168,9 +169,9 @@ public class PfReferenceKeyTest { parentLocalNameField.set(testReferenceKey, PARENT_LOCAL_NAME); parentLocalNameField.setAccessible(false); assertEquals( - "parentLocalName invalid-parameter parentLocalName with value " - + "Parent Local Name does not match regular expression [A-Za-z0-9\\-_\\.]+|^$", - validationResult3.getMessageList().get(0).getMessage()); + "parentLocalName invalid-parameter parentLocalName with value " + + "Parent Local Name does not match regular expression [A-Za-z0-9\\-_\\.]+|^$", + validationResult3.getMessageList().get(0).getMessage()); Field localNameField = testReferenceKey.getClass().getDeclaredField("localName"); localNameField.setAccessible(true); @@ -180,8 +181,8 @@ public class PfReferenceKeyTest { localNameField.set(testReferenceKey, LOCAL_NAME); localNameField.setAccessible(false); assertEquals( - "localName invalid-parameter localName with value Local Name " - + "does not match regular expression [A-Za-z0-9\\-_\\.]+|^$", - validationResult4.getMessageList().get(0).getMessage()); + "localName invalid-parameter localName with value Local Name " + + "does not match regular expression [A-Za-z0-9\\-_\\.]+|^$", + validationResult4.getMessageList().get(0).getMessage()); } } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfSearchableKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfSearchableKeyTest.java index 942f47c1d..e3a0e3338 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfSearchableKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfSearchableKeyTest.java @@ -1,5 +1,6 @@ /*- * ============LICENSE_START======================================================= + * 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,7 +32,7 @@ import org.onap.policy.models.base.testconcepts.DummyPfConcept; public class PfSearchableKeyTest { private static final String VERSION001 = "0.0.1"; - private static final String ID_IS_NULL = "id is marked @NonNull but is null"; + private static final String ID_IS_NULL = "^id is marked .*on.*ull but is null$"; @Test public void testSearchableKey() { @@ -54,7 +55,6 @@ public class PfSearchableKeyTest { assertEquals(someKey2, someKey1.getKey()); assertEquals(1, someKey1.getKeys().size()); - PfConcept pfc = new DummyPfConcept(); assertEquals(PfSearchableKey.getNullKey().getId(), pfc.getId()); @@ -62,13 +62,13 @@ public class PfSearchableKeyTest { assertTrue(PfSearchableKey.getNullKey().isNullKey()); - assertThatThrownBy(() -> PfSearchableKey.getNullKey().matchesId(null)).hasMessage(ID_IS_NULL); + assertThatThrownBy(() -> PfSearchableKey.getNullKey().matchesId(null)).hasMessageMatching(ID_IS_NULL); assertThatThrownBy(() -> someKey0.setName(null)).isInstanceOf(NullPointerException.class) - .hasMessage("name is marked @NonNull but is null"); + .hasMessageMatching("^name is marked .*on.*ull but is null$"); assertThatThrownBy(() -> someKey0.setVersion(null)).isInstanceOf(NullPointerException.class) - .hasMessage("version is marked @NonNull but is null"); + .hasMessageMatching("^version is marked .*on.*ull but is null$"); PfSearchableKey someKey4 = new PfSearchableKey("my-name.*", VERSION001); assertEquals("my-name.*", someKey4.getName()); diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java index 28b9fd922..1495fca7d 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfTimestampKeyTest.java @@ -1,8 +1,6 @@ /*- * ============LICENSE_START======================================================= - * ONAP Policy Model - * ================================================================================ - * 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. @@ -28,14 +26,15 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import java.util.Date; + import org.junit.Test; public class PfTimestampKeyTest { private static final String VERSION001 = "0.0.1"; - private static final String CONCEPT_IS_NULL = "copyConcept is marked @NonNull but is null"; - private static final String NAME_IS_NULL = "name is marked @NonNull but is null"; - private static final String VERSION_IS_NULL = "version is marked @NonNull but is null"; - private static final String TIMESTAMP_IS_NULL = "timeStamp is marked @NonNull but is null"; + private static final String CONCEPT_IS_NULL = "^copyConcept is marked .*on.*ull but is null$"; + private static final String NAME_IS_NULL = "^name is marked .*on.*ull but is null$"; + private static final String VERSION_IS_NULL = "^version is marked .*on.*ull but is null$"; + private static final String TIMESTAMP_IS_NULL = "^timeStamp is marked .*on.*ull but is null$"; private static final long timeStamp = 1574832537641L; @Test @@ -60,24 +59,24 @@ public class PfTimestampKeyTest { assertEquals(1, someKey1.getKeys().size()); assertThatThrownBy(() -> new PfTimestampKey((PfTimestampKey) null)).isInstanceOf(NullPointerException.class) - .hasMessage(CONCEPT_IS_NULL); + .hasMessageMatching(CONCEPT_IS_NULL); assertThatThrownBy(() -> new PfTimestampKey(null, null, null)).isInstanceOf(NullPointerException.class) - .hasMessage(NAME_IS_NULL); + .hasMessageMatching(NAME_IS_NULL); assertThatThrownBy(() -> new PfTimestampKey("my-name", null, null)).isInstanceOf(NullPointerException.class) - .hasMessage(VERSION_IS_NULL); + .hasMessageMatching(VERSION_IS_NULL); assertThatThrownBy(() -> new PfTimestampKey("my-name", VERSION001, null)) - .isInstanceOf(NullPointerException.class).hasMessage(TIMESTAMP_IS_NULL); + .isInstanceOf(NullPointerException.class).hasMessageMatching(TIMESTAMP_IS_NULL); assertThatThrownBy(() -> someKey0.setName(null)).isInstanceOf(NullPointerException.class) - .hasMessage(NAME_IS_NULL); + .hasMessageMatching(NAME_IS_NULL); assertThatThrownBy(() -> someKey0.setVersion(null)).isInstanceOf(NullPointerException.class) - .hasMessage(VERSION_IS_NULL); + .hasMessageMatching(VERSION_IS_NULL); assertThatThrownBy(() -> someKey0.setTimeStamp(null)).isInstanceOf(NullPointerException.class) - .hasMessage(TIMESTAMP_IS_NULL); + .hasMessageMatching(TIMESTAMP_IS_NULL); assertFalse(someKey1.isNewerThan(someKey2)); assertThatThrownBy(() -> someKey1.isNewerThan((PfKey) null)).isInstanceOf(NullPointerException.class) - .hasMessage("otherKey is marked @NonNull but is null"); + .hasMessageMatching("^otherKey is marked .*on.*ull but is null$"); someKey2.setTimeStamp(new Date(timeStamp + 1)); assertTrue(someKey2.isNewerThan(someKey1)); someKey3.setName("my-name3"); @@ -86,7 +85,7 @@ public class PfTimestampKeyTest { assertEquals(-1, someKey1.compareTo(someKey2)); assertEquals(-1, someKey1.compareTo(someKey3)); assertThatThrownBy(() -> someKey1.compareTo((PfConcept) null)).isInstanceOf(NullPointerException.class) - .hasMessage("otherObj is marked @NonNull but is null"); + .hasMessageMatching("^otherObj is marked .*on.*ull but is null$"); PfTimestampKey someKey4 = new PfTimestampKey("NULL", "0.0.0", new Date(timeStamp)); assertFalse(someKey4.isNullKey()); |