diff options
author | Pamela Dragosh <pdragosh@research.att.com> | 2019-06-18 12:17:01 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-06-18 12:17:01 +0000 |
commit | 348050eb3635e061deb4c21581a274299d7c6e12 (patch) | |
tree | c973760e582f9a5428c01c4399088ef7cde763ea /models-base | |
parent | 40cdc8e01568d9c8950600ca9d9a5f6ff45e36ab (diff) | |
parent | 6347aed1148a9fab8f7f45e46be71b8bdfc52924 (diff) |
Merge "Fix more sonar issues in models: yaml to dao"
Diffstat (limited to 'models-base')
16 files changed, 388 insertions, 579 deletions
diff --git a/models-base/src/test/java/org/onap/policy/models/base/ExceptionsTest.java b/models-base/src/test/java/org/onap/policy/models/base/ExceptionsTest.java index 664e3ddbc..af9e61e2f 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/ExceptionsTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/ExceptionsTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,24 +33,27 @@ import org.onap.policy.models.errors.concepts.ErrorResponse; public class ExceptionsTest { + private static final String STRING_TEXT = "String"; + private static final String MESSAGE = "Message"; + @Test public void test() { - assertNotNull(new PfModelException(Response.Status.OK, "Message")); - assertNotNull(new PfModelException(Response.Status.OK, "Message", "String")); - assertNotNull(new PfModelException(Response.Status.OK, "Message", new IOException())); - assertNotNull(new PfModelException(Response.Status.OK, "Message", new IOException(), "String")); + assertNotNull(new PfModelException(Response.Status.OK, MESSAGE)); + assertNotNull(new PfModelException(Response.Status.OK, MESSAGE, STRING_TEXT)); + assertNotNull(new PfModelException(Response.Status.OK, MESSAGE, new IOException())); + assertNotNull(new PfModelException(Response.Status.OK, MESSAGE, new IOException(), STRING_TEXT)); String key = "A String"; PfModelException ae = - new PfModelException(Response.Status.OK, "Message", new IOException("IO exception message"), key); + new PfModelException(Response.Status.OK, MESSAGE, new IOException("IO exception message"), key); ErrorResponse errorResponse = ae.getErrorResponse(); assertEquals("Message\nIO exception message", String.join("\n", errorResponse.getErrorDetails())); assertEquals(key, ae.getObject()); - assertNotNull(new PfModelRuntimeException(Response.Status.OK, "Message")); - assertNotNull(new PfModelRuntimeException(Response.Status.OK, "Message", "String")); - assertNotNull(new PfModelRuntimeException(Response.Status.OK, "Message", new IOException())); - assertNotNull(new PfModelRuntimeException(Response.Status.OK, "Message", new IOException(), "String")); + assertNotNull(new PfModelRuntimeException(Response.Status.OK, MESSAGE)); + assertNotNull(new PfModelRuntimeException(Response.Status.OK, MESSAGE, STRING_TEXT)); + assertNotNull(new PfModelRuntimeException(Response.Status.OK, MESSAGE, new IOException())); + assertNotNull(new PfModelRuntimeException(Response.Status.OK, MESSAGE, new IOException(), STRING_TEXT)); String rkey = "A String"; PfModelRuntimeException re = new PfModelRuntimeException(Response.Status.OK, "Runtime Message", 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 0e790d3dc..1b7a996ed 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,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,86 +21,58 @@ package org.onap.policy.models.base; -import static org.junit.Assert.assertEquals; +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 static org.junit.Assert.fail; import org.junit.Test; 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_NAME = "ModelName"; + @Test public void testModelService() { PfModelService.clear(); assertFalse(PfModelService.existsModel("NonExistantName")); - try { - PfModelService.getModel("NonExistantName"); - } catch (final Exception e) { - assertEquals("Model for name NonExistantName not found in model service", e.getMessage()); - } + assertThatThrownBy(() -> PfModelService.getModel("NonExistantName")) + .hasMessage("Model for name NonExistantName not found in model service"); - PfModelService.registerModel("ModelName", new DummyPfModel()); - assertTrue(PfModelService.existsModel("ModelName")); - assertNotNull(PfModelService.getModel("ModelName")); + PfModelService.registerModel(MODEL_NAME, new DummyPfModel()); + assertTrue(PfModelService.existsModel(MODEL_NAME)); + assertNotNull(PfModelService.getModel(MODEL_NAME)); - PfModelService.deregisterModel("ModelName"); + PfModelService.deregisterModel(MODEL_NAME); - assertFalse(PfModelService.existsModel("ModelName")); - try { - PfModelService.getModel("ModelName"); - } catch (final Exception e) { - assertEquals("Model for name ModelName not found in model service", e.getMessage()); - } + assertFalse(PfModelService.existsModel(MODEL_NAME)); + assertThatThrownBy(() -> PfModelService.getModel(MODEL_NAME)) + .hasMessage("Model for name ModelName not found in model service"); - PfModelService.registerModel("ModelName", new DummyPfModel()); - assertTrue(PfModelService.existsModel("ModelName")); - assertNotNull(PfModelService.getModel("ModelName")); + PfModelService.registerModel(MODEL_NAME, new DummyPfModel()); + assertTrue(PfModelService.existsModel(MODEL_NAME)); + assertNotNull(PfModelService.getModel(MODEL_NAME)); PfModelService.clear(); - assertFalse(PfModelService.existsModel("ModelName")); - try { - PfModelService.getModel("ModelName"); - } catch (final Exception e) { - assertEquals("Model for name ModelName not found in model service", e.getMessage()); - } - - try { - PfModelService.registerModel(null, null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("modelKey is marked @NonNull but is null", exc.getMessage()); - } - - try { - PfModelService.registerModel("nullModelName", null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("model is marked @NonNull but is null", exc.getMessage()); - } - - try { - PfModelService.registerModel(null, new DummyPfModel()); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("modelKey is marked @NonNull but is null", exc.getMessage()); - } - - try { - PfModelService.deregisterModel(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("modelKey is marked @NonNull but is null", exc.getMessage()); - } - - try { - PfModelService.getModel(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("modelKey is marked @NonNull but is null", exc.getMessage()); - } + assertFalse(PfModelService.existsModel(MODEL_NAME)); + assertThatThrownBy(() -> PfModelService.getModel(MODEL_NAME)) + .hasMessage("Model for name ModelName not found in model service"); + + assertThatThrownBy(() -> PfModelService.registerModel(null, null)) + .hasMessage(MODEL_KEY_IS_NULL); + + assertThatThrownBy(() -> PfModelService.registerModel("nullModelName", null)) + .hasMessage("model is marked @NonNull but is null"); + + assertThatThrownBy(() -> PfModelService.registerModel(null, new DummyPfModel())) + .hasMessage(MODEL_KEY_IS_NULL); + + assertThatThrownBy(() -> PfModelService.deregisterModel(null)) + .hasMessage(MODEL_KEY_IS_NULL); + + assertThatThrownBy(() -> PfModelService.getModel(null)).hasMessage(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 4ad7c0f9e..984d2b9d3 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 @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +26,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -33,7 +33,6 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; - import org.junit.Test; import org.onap.policy.models.base.testconcepts.DummyAuthorativeConcept; import org.onap.policy.models.base.testconcepts.DummyBadPfConceptContainer; @@ -48,6 +47,13 @@ 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 DUMMY_VALUE = "Dummy"; + private static final String VERSION0 = "0.0.1"; + @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testConceptContainer() { @@ -63,51 +69,28 @@ public class PfConceptContainerTest { container = new DummyPfConceptContainer(new PfConceptKey(), new TreeMap<PfConceptKey, DummyPfConcept>()); assertNotNull(container); - try { - new PfConceptContainer((PfConceptKey) null, null); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("key is marked @NonNull but is null", exc.getMessage()); - } - - try { - container = new DummyPfConceptContainer((PfConceptKey) null, null); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("key is marked @NonNull but is null", exc.getMessage()); - } - - try { - container = new DummyPfConceptContainer(new PfConceptKey(), null); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("conceptMap is marked @NonNull but is null", exc.getMessage()); - } - - try { - container = new DummyPfConceptContainer(null, new TreeMap<PfConceptKey, DummyPfConcept>()); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("key is marked @NonNull but is null", exc.getMessage()); - } - - container.getKey().setName("Dummy"); + assertThatThrownBy(() -> new PfConceptContainer((PfConceptKey) null, null)).hasMessage(KEY_IS_NULL); + + assertThatThrownBy(() -> new DummyPfConceptContainer((PfConceptKey) null, null)).hasMessage(KEY_IS_NULL); + + assertThatThrownBy(() -> new DummyPfConceptContainer(new PfConceptKey(), null)) + .hasMessage("conceptMap is marked @NonNull but is null"); + + assertThatThrownBy(() -> new DummyPfConceptContainer(null, new TreeMap<PfConceptKey, DummyPfConcept>())) + .hasMessage(KEY_IS_NULL); + + container.getKey().setName(DUMMY_VALUE); DummyPfConceptContainer clonedContainer = new DummyPfConceptContainer(container); assertNotNull(clonedContainer); - assertEquals("Dummy", clonedContainer.getKey().getName()); + assertEquals(DUMMY_VALUE, clonedContainer.getKey().getName()); - try { - DummyPfConceptContainer conceptContainter = null; - container = new DummyPfConceptContainer(conceptContainter); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage()); - } + assertThatThrownBy(() -> new DummyPfConceptContainer((DummyPfConceptContainer) null)) + .hasMessage("copyConcept is marked @NonNull but is null"); List<PfKey> keyList = container.getKeys(); assertEquals(1, keyList.size()); - PfConceptKey conceptKey = new PfConceptKey("Key", "0.0.1"); + PfConceptKey conceptKey = new PfConceptKey("Key", VERSION0); Map<PfConceptKey, DummyPfConcept> conceptMap = new TreeMap<>(); conceptMap.put(conceptKey, new DummyPfConcept(conceptKey)); @@ -117,7 +100,7 @@ public class PfConceptContainerTest { clonedContainer = new DummyPfConceptContainer(container); assertNotNull(clonedContainer); - assertEquals("Dummy", clonedContainer.getKey().getName()); + assertEquals(DUMMY_VALUE, clonedContainer.getKey().getName()); assertEquals(2, clonedContainer.getKeys().size()); assertEquals(clonedContainer, container); @@ -130,12 +113,8 @@ public class PfConceptContainerTest { assertEquals(0, container.compareTo(clonedContainer)); - try { - container.copyTo(null); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("target is marked @NonNull but is null", exc.getMessage()); - } + final DummyPfConceptContainer container2 = container; + assertThatThrownBy(() -> container2.copyTo(null)).hasMessage("target is marked @NonNull but is null"); assertFalse(container.compareTo(null) == 0); assertEquals(0, container.compareTo(container)); @@ -147,20 +126,16 @@ public class PfConceptContainerTest { testContainer.getKey().setVersion(container.getKey().getVersion()); assertEquals(0, container.compareTo(testContainer)); - PfConceptKey testConceptKey = new PfConceptKey("TestKey", "0.0.1"); + PfConceptKey testConceptKey = new PfConceptKey("TestKey", VERSION0); testContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey)); assertFalse(container.compareTo(testContainer) == 0); - try { - container.validate(null); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("resultIn is marked @NonNull but is null", exc.getMessage()); - } + final DummyPfConceptContainer container3 = container; + assertThatThrownBy(() -> container3.validate(null)).hasMessage("resultIn is marked @NonNull but is null"); DummyPfConceptContainer validateContainer = new DummyPfConceptContainer(); assertFalse(validateContainer.validate(new PfValidationResult()).isOk()); - validateContainer.setKey(new PfConceptKey("VCKey", "0.0.1")); + validateContainer.setKey(new PfConceptKey("VCKey", VERSION0)); assertFalse(validateContainer.validate(new PfValidationResult()).isOk()); validateContainer.getConceptMap().put(testConceptKey, new DummyPfConcept(testConceptKey)); @@ -197,9 +172,9 @@ public class PfConceptContainerTest { @Test 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("name2", new DummyAuthorativeConcept("name2", "1.2.3", "Howdy")); + 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(NAME2, new DummyAuthorativeConcept(NAME2, "1.2.3", "Howdy")); List<Map<String, DummyAuthorativeConcept>> authorativeList = new ArrayList<>(); authorativeList.add(dacMap); @@ -213,19 +188,17 @@ public class PfConceptContainerTest { 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("name2"), outMapList.get(2).get("name2")); + assertEquals(dacMap.get(NAME1), outMapList.get(0).get("NULL")); + assertEquals(dacMap.get(NAME0).getDescription(), outMapList.get(1).get(NAME0).getDescription()); + assertEquals(dacMap.get(NAME2), outMapList.get(2).get(NAME2)); DummyBadPfConceptContainer badContainer = new DummyBadPfConceptContainer(); - assertThatThrownBy(() -> { - badContainer.fromAuthorative(authorativeList); - }).hasMessage("failed to instantiate instance of container concept class"); + assertThatThrownBy(() -> badContainer.fromAuthorative(authorativeList)) + .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"); + assertThatThrownBy(() -> container.fromAuthorative(authorativeList)) + .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/PfConceptGetterImplTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfConceptGetterImplTest.java index ae5b2ff2b..b373e419f 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfConceptGetterImplTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfConceptGetterImplTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,15 +21,14 @@ package org.onap.policy.models.base; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; import java.util.NavigableMap; import java.util.TreeMap; import java.util.TreeSet; - import org.junit.Test; /** @@ -36,6 +36,9 @@ import org.junit.Test; */ public class PfConceptGetterImplTest { + private static final String VERSION002 = "0.0.2"; + private static final String VERSION001 = "0.0.1"; + @Test public void testPfConceptGetterImpl() { NavigableMap<PfConceptKey, PfConceptKey> keyMap = new TreeMap<>(); @@ -43,54 +46,42 @@ public class PfConceptGetterImplTest { PfConceptGetterImpl<PfConceptKey> getter = new PfConceptGetterImpl<>(keyMap); assertNotNull(getter); - PfConceptKey keyA = new PfConceptKey("A", "0.0.1"); + PfConceptKey keyA = new PfConceptKey("A", VERSION001); assertNull(getter.get(keyA)); - try { - getter.get((String)null); - fail("test should throw an exception here"); - } - catch (Exception getException) { - assertEquals("conceptKeyName may not be null", getException.getMessage()); - } + assertThatThrownBy(() -> getter.get((String) null)).hasMessage("conceptKeyName may not be null"); assertNull(getter.get("W")); - PfConceptKey keyZ = new PfConceptKey("Z", "0.0.1"); + PfConceptKey keyZ = new PfConceptKey("Z", VERSION001); keyMap.put(keyZ, keyZ); assertNull(getter.get("W")); - PfConceptKey keyW001 = new PfConceptKey("W", "0.0.1"); + PfConceptKey keyW001 = new PfConceptKey("W", VERSION001); keyMap.put(keyW001, keyW001); assertEquals(keyW001, getter.get("W")); - PfConceptKey keyW002 = new PfConceptKey("W", "0.0.2"); + PfConceptKey keyW002 = new PfConceptKey("W", VERSION002); keyMap.put(keyW002, keyW002); assertEquals(keyW002, getter.get("W")); keyMap.remove(keyZ); assertEquals(keyW002, getter.get("W")); - try { - getter.get((String)null, "0.0.1"); - fail("test should throw an exception here"); - } - catch (Exception getException) { - assertEquals("conceptKeyName may not be null", getException.getMessage()); - } + assertThatThrownBy(() -> getter.get((String) null, VERSION001)).hasMessage("conceptKeyName may not be null"); - assertEquals(keyW002, getter.get("W", "0.0.2")); + assertEquals(keyW002, getter.get("W", VERSION002)); assertEquals(keyW002, getter.get("W", (String)null)); assertEquals(new TreeSet<PfConceptKey>(keyMap.values()), getter.getAll(null)); assertEquals(new TreeSet<PfConceptKey>(keyMap.values()), getter.getAll(null, null)); assertEquals(keyW001, getter.getAll("W", null).iterator().next()); - assertEquals(keyW002, getter.getAll("W", "0.0.2").iterator().next()); + assertEquals(keyW002, getter.getAll("W", VERSION002).iterator().next()); assertEquals(0, getter.getAll("A", null).size()); assertEquals(0, getter.getAll("Z", null).size()); keyMap.put(keyZ, keyZ); - assertEquals(keyW002, getter.getAll("W", "0.0.2").iterator().next()); + assertEquals(keyW002, getter.getAll("W", VERSION002).iterator().next()); } } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java index 13541b84e..9ef1aeb75 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,45 +21,40 @@ package org.onap.policy.models.base; +import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.lang.reflect.Field; - import org.junit.Test; - import org.onap.policy.models.base.PfKey.Compatibility; import org.onap.policy.models.base.testconcepts.DummyPfConcept; import org.onap.policy.models.base.testconcepts.DummyPfKey; public class PfKeyTest { + 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 VERSION123 = "1.2.3"; + private static final String VERSION100 = "1.0.0"; + private static final String VERSION001 = "0.0.1"; + @Test public void testConceptKey() { - try { - new PfConceptKey("some bad key id"); - fail("This test should throw an exception"); - } catch (IllegalArgumentException e) { - assertEquals( - "parameter \"id\": value \"some bad key id\", " - + "does not match regular expression \"" + PfKey.KEY_ID_REGEXP + "\"", - e.getMessage()); - } - - try { - new PfConceptKey((PfConceptKey) null); - fail("This test should throw an exception"); - } catch (Exception e) { - assertEquals("copyConcept is marked @NonNull but is null", e.getMessage()); - } + assertThatIllegalArgumentException().isThrownBy(() -> new PfConceptKey("some bad key id")) + .withMessage("parameter \"id\": value \"some bad key id\", " + + "does not match regular expression \"" + PfKey.KEY_ID_REGEXP + "\""); + + assertThatThrownBy(() -> new PfConceptKey((PfConceptKey) null)) + .hasMessage("copyConcept is marked @NonNull but is null"); PfConceptKey someKey0 = new PfConceptKey(); assertEquals(PfConceptKey.getNullKey(), someKey0); - PfConceptKey someKey1 = new PfConceptKey("name", "0.0.1"); + PfConceptKey someKey1 = new PfConceptKey("name", VERSION001); PfConceptKey someKey2 = new PfConceptKey(someKey1); PfConceptKey someKey3 = new PfConceptKey(someKey1.getId()); assertEquals(someKey1, someKey2); @@ -94,12 +90,7 @@ public class PfKeyTest { assertTrue(PfConceptKey.getNullKey().isNullKey()); - try { - PfConceptKey.getNullKey().matchesId(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("id is marked @NonNull but is null", exc.getMessage()); - } + assertThatThrownBy(() -> PfConceptKey.getNullKey().matchesId(null)).hasMessage(ID_IS_NULL); assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(new DummyPfKey())); assertEquals(Compatibility.DIFFERENT, someKey0.getCompatibility(someKey1)); @@ -141,130 +132,79 @@ public class PfKeyTest { assertEquals(0, someKey7.compareTo(someKey1)); assertEquals(-12, someKey7.compareTo(someKey0)); - try { - someKey0.compareTo(null); - fail("test should throw an exception here"); - } catch (NullPointerException e) { - assertEquals("otherObj is marked @NonNull but is null", e.getMessage()); - } + assertThatThrownBy(() -> someKey0.compareTo(null)).isInstanceOf(NullPointerException.class) + .hasMessage("otherObj is marked @NonNull but is null"); assertEquals(0, someKey0.compareTo(someKey0)); assertEquals(266127751, someKey0.compareTo(new DummyPfKey())); assertFalse(someKey0.equals(null)); assertTrue(someKey0.equals(someKey0)); - assertFalse(((PfKey) someKey0).equals(new DummyPfKey())); + assertFalse(someKey0.equals(new DummyPfKey())); } @Test public void testNullArguments() { - try { - new PfConceptKey((String) null); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("id is marked @NonNull but is null", exc.getMessage()); - } - - try { - new PfConceptKey((PfConceptKey) null); - fail("id is marked @NonNull but is null"); - } catch (Exception exc) { - assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage()); - } - - try { - new PfConceptKey(null, null); - fail("id is marked @NonNull but is null"); - } catch (Exception exc) { - assertEquals("name is marked @NonNull but is null", exc.getMessage()); - } - - try { - new PfConceptKey("name", null); - fail("id is marked @NonNull but is null"); - } catch (Exception exc) { - assertEquals("version is marked @NonNull but is null", exc.getMessage()); - } - - try { - new PfConceptKey(null, "0.0.1"); - fail("id is marked @NonNull but is null"); - } catch (Exception exc) { - assertEquals("name is marked @NonNull but is null", exc.getMessage()); - } - - try { - PfConceptKey key = new PfConceptKey("AKey", "0.0.1"); - key.isCompatible(null); - fail("id is marked @NonNull but is null"); - } catch (Exception exc) { - assertEquals("otherKey is marked @NonNull but is null", exc.getMessage()); - } + assertThatThrownBy(() -> new PfConceptKey((String) null)).hasMessage(ID_IS_NULL); + + assertThatThrownBy(() -> new PfConceptKey((PfConceptKey) null)) + .hasMessage("copyConcept is marked @NonNull but is null"); + + assertThatThrownBy(() -> new PfConceptKey(null, null)).hasMessage("name is marked @NonNull but is null"); + + assertThatThrownBy(() -> new PfConceptKey("name", null)).hasMessage("version is marked @NonNull but is null"); + + assertThatThrownBy(() -> new PfConceptKey(null, VERSION001)).hasMessage("name is marked @NonNull but is null"); + + assertThatThrownBy(() -> new PfConceptKey("AKey", VERSION001).isCompatible(null)).hasMessage(OTHER_IS_NULL); } @Test - public void testValidation() { - PfConceptKey testKey = new PfConceptKey("TheKey", "0.0.1"); + public void testValidation() throws Exception { + PfConceptKey testKey = new PfConceptKey("TheKey", VERSION001); assertEquals("TheKey:0.0.1", testKey.getId()); - try { - Field nameField = testKey.getClass().getDeclaredField("name"); - nameField.setAccessible(true); - nameField.set(testKey, "Key Name"); - PfValidationResult validationResult = new PfValidationResult(); - 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()); - } catch (Exception validationException) { - fail("test should not throw an exception"); - } - - try { - Field versionField = testKey.getClass().getDeclaredField("version"); - versionField.setAccessible(true); - versionField.set(testKey, "Key Version"); - PfValidationResult validationResult = new PfValidationResult(); - testKey.validate(validationResult); - versionField.set(testKey, "0.0.1"); - versionField.setAccessible(false); - assertEquals( - "version invalid-parameter version with value Key Version " - + "does not match regular expression " + PfKey.VERSION_REGEXP, - validationResult.getMessageList().get(0).getMessage()); - } catch (Exception validationException) { - fail("test should not throw an exception"); - } + Field nameField = testKey.getClass().getDeclaredField("name"); + nameField.setAccessible(true); + nameField.set(testKey, "Key Name"); + PfValidationResult validationResult = new PfValidationResult(); + 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()); + + Field versionField = testKey.getClass().getDeclaredField("version"); + versionField.setAccessible(true); + versionField.set(testKey, "Key Version"); + PfValidationResult validationResult2 = new PfValidationResult(); + 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()); } @Test public void testkeynewerThan() { - PfConceptKey key1 = new PfConceptKey("Key1", "1.2.3"); - - try { - key1.isNewerThan(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("otherKey is marked @NonNull but is null", exc.getMessage()); - } - - try { - key1.isNewerThan(new PfReferenceKey()); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("org.onap.policy.models.base.PfReferenceKey is not " - + "an instance of org.onap.policy.models.base.PfConceptKey", exc.getMessage()); - } + PfConceptKey key1 = new PfConceptKey("Key1", VERSION123); + + assertThatThrownBy(() -> key1.isNewerThan(null)).hasMessage(OTHER_IS_NULL); + + assertThatThrownBy(() -> key1.isNewerThan(new PfReferenceKey())) + .hasMessage("org.onap.policy.models.base.PfReferenceKey is not " + + "an instance of org.onap.policy.models.base.PfConceptKey"); assertFalse(key1.isNewerThan(key1)); - PfConceptKey key1a = new PfConceptKey("Key1a", "1.2.3"); + PfConceptKey key1a = new PfConceptKey("Key1a", VERSION123); assertFalse(key1.isNewerThan(key1a)); - PfConceptKey key1b = new PfConceptKey("Key0", "1.2.3"); + PfConceptKey key1b = new PfConceptKey("Key0", VERSION123); assertTrue(key1.isNewerThan(key1b)); key1a.setName("Key1"); @@ -274,51 +214,42 @@ public class PfKeyTest { assertTrue(key1.isNewerThan(key1a)); key1a.setVersion("2.2.3"); assertFalse(key1.isNewerThan(key1a)); - key1a.setVersion("1.2.3"); + key1a.setVersion(VERSION123); assertFalse(key1.isNewerThan(key1a)); key1a.setVersion("1.1.3"); assertTrue(key1.isNewerThan(key1a)); key1a.setVersion("1.3.3"); assertFalse(key1.isNewerThan(key1a)); - key1a.setVersion("1.2.3"); + key1a.setVersion(VERSION123); assertFalse(key1.isNewerThan(key1a)); key1a.setVersion("1.2.2"); assertTrue(key1.isNewerThan(key1a)); key1a.setVersion("1.2.4"); assertFalse(key1.isNewerThan(key1a)); - key1a.setVersion("1.2.3"); + key1a.setVersion(VERSION123); assertFalse(key1.isNewerThan(key1a)); - key1.setVersion("1.0.0"); + key1.setVersion(VERSION100); assertFalse(key1.isNewerThan(key1a)); - key1a.setVersion("1.0.0"); + key1a.setVersion(VERSION100); assertFalse(key1.isNewerThan(key1a)); PfReferenceKey refKey = new PfReferenceKey(); - try { - refKey.isNewerThan(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("otherKey is marked @NonNull but is null", exc.getMessage()); - } - - try { - refKey.isNewerThan(new PfConceptKey()); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("org.onap.policy.models.base.PfConceptKey is not " - + "an instance of org.onap.policy.models.base.PfReferenceKey", exc.getMessage()); - } + assertThatThrownBy(() -> refKey.isNewerThan(null)).hasMessage(OTHER_IS_NULL); + + assertThatThrownBy(() -> refKey.isNewerThan(new PfConceptKey())) + .hasMessage("org.onap.policy.models.base.PfConceptKey is not " + + "an instance of org.onap.policy.models.base.PfReferenceKey"); assertFalse(refKey.isNewerThan(refKey)); } @Test public void testmajorMinorPatch() { - PfConceptKey key = new PfConceptKey("Key", "1.0.0"); + PfConceptKey key = new PfConceptKey("Key", VERSION100); assertEquals(1, key.getMajorVersion()); assertEquals(0, key.getMinorVersion()); assertEquals(0, key.getPatchVersion()); @@ -328,7 +259,7 @@ public class PfKeyTest { assertEquals(2, key.getMinorVersion()); assertEquals(0, key.getPatchVersion()); - key = new PfConceptKey("Key", "1.2.3"); + key = new PfConceptKey("Key", VERSION123); assertEquals(1, key.getMajorVersion()); assertEquals(2, key.getMinorVersion()); assertEquals(3, key.getPatchVersion()); 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 68494309c..f7d1d9a5f 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,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,12 +21,12 @@ package org.onap.policy.models.base; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import org.junit.Test; import org.onap.policy.models.base.PfKey.Compatibility; @@ -33,19 +34,16 @@ import org.onap.policy.models.base.testconcepts.DummyPfConceptKeySub; public class PfKeyUseTest { - @SuppressWarnings("unlikely-arg-type") + private static final String OTHER_KEY_IS_NULL = "otherKey is marked @NonNull but is null"; + @Test public void testKeyUse() { assertNotNull(new PfKeyUse()); assertNotNull(new PfKeyUse(new PfConceptKey())); assertNotNull(new PfKeyUse(new PfReferenceKey())); - try { - new PfKeyUse((PfKeyUse) null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage()); - } + assertThatThrownBy(() -> new PfKeyUse((PfKeyUse) null)) + .hasMessage("copyConcept is marked @NonNull but is null"); PfConceptKey key = new PfConceptKey("Key", "0.0.1"); PfKeyUse keyUse = new PfKeyUse(); @@ -57,12 +55,7 @@ public class PfKeyUseTest { assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key)); - try { - key.getCompatibility(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("otherKey is marked @NonNull but is null", exc.getMessage()); - } + assertThatThrownBy(() -> key.getCompatibility(null)).hasMessage(OTHER_KEY_IS_NULL); assertTrue(keyUse.isCompatible(key)); @@ -94,58 +87,25 @@ public class PfKeyUseTest { PfValidationResult resultNull = new PfValidationResult(); assertEquals(false, keyUseNull.validate(resultNull).isValid()); - try { - keyUse.setKey(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("key is marked @NonNull but is null", exc.getMessage()); - } - - try { - keyUse.getCompatibility(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("otherKey is marked @NonNull but is null", exc.getMessage()); - } - - try { - keyUse.isCompatible(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("otherKey is marked @NonNull but is null", exc.getMessage()); - } - - try { - keyUse.validate(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("result is marked @NonNull but is null", exc.getMessage()); - } + assertThatThrownBy(() -> keyUse.setKey(null)).hasMessage("key is marked @NonNull but is null"); + + assertThatThrownBy(() -> keyUse.getCompatibility(null)).hasMessage(OTHER_KEY_IS_NULL); + + assertThatThrownBy(() -> keyUse.isCompatible(null)).hasMessage(OTHER_KEY_IS_NULL); + + assertThatThrownBy(() -> keyUse.validate(null)).hasMessage("result is marked @NonNull but is null"); PfKeyUse testKeyUse = new PfKeyUse(new DummyPfConceptKeySub(new PfConceptKey())); PfKeyUse targetKeyUse = new PfKeyUse(key); - try { - keyUse.copyTo(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("target is marked @NonNull but is null", exc.getMessage()); - } + assertThatThrownBy(() -> keyUse.copyTo(null)).hasMessage("target is marked @NonNull but is null"); - try { + assertThatThrownBy(() -> { testKeyUse.copyTo(targetKeyUse); keyUse.isCompatible(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("error copying concept key: Some error message", exc.getMessage()); - } - - try { - keyUse.isNewerThan(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("otherKey is marked @NonNull but is null", exc.getMessage()); - } + }).hasMessage("error copying concept key: Some error message"); + + assertThatThrownBy(() -> keyUse.isNewerThan(null)).hasMessage(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 cf7c41f6b..2f4a1beb9 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,7 +1,7 @@ -package org.onap.policy.models.base; /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,13 @@ package org.onap.policy.models.base; * ============LICENSE_END========================================================= */ +package org.onap.policy.models.base; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import org.junit.Test; import org.onap.policy.models.base.testconcepts.DummyPfModel; @@ -35,28 +37,21 @@ import org.onap.policy.models.base.testconcepts.DummyPfModel; */ public class PfModelTest { + private static final String VERSION001 = "0.0.1"; + @Test public void testPfModel() { assertNotNull(new DummyPfModel()); assertNotNull(new DummyPfModel(new PfConceptKey())); assertNotNull(new DummyPfModel(new DummyPfModel())); - try { - new DummyPfModel((PfConceptKey)null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("key is marked @NonNull but is null", exc.getMessage()); - } - - try { - DummyPfModel nullModel = null; - new DummyPfModel(nullModel); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage()); - } - - DummyPfModel dpm = new DummyPfModel(new PfConceptKey("modelKey", "0.0.1")); + assertThatThrownBy(() -> new DummyPfModel((PfConceptKey) null)) + .hasMessage("key is marked @NonNull but is null"); + + assertThatThrownBy(() -> new DummyPfModel((DummyPfModel) null)) + .hasMessage("copyConcept is marked @NonNull but is null"); + + DummyPfModel dpm = new DummyPfModel(new PfConceptKey("modelKey", VERSION001)); DummyPfModel dpmClone = new DummyPfModel(dpm); assertEquals(dpm, dpmClone); @@ -65,12 +60,7 @@ public class PfModelTest { dpmClone.clean(); assertEquals(dpm, dpmClone); - try { - dpm.copyTo(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("target is marked @NonNull but is null", exc.getMessage()); - } + assertThatThrownBy(() -> dpm.copyTo(null)).hasMessage("target is marked @NonNull but is null"); assertEquals(0, dpm.compareTo(dpmClone)); assertEquals(-1, dpm.compareTo(null)); @@ -80,16 +70,11 @@ public class PfModelTest { @Test public void testPfModelValidation() { - PfConceptKey dpmKey = new PfConceptKey("modelKey", "0.0.1"); + PfConceptKey dpmKey = new PfConceptKey("modelKey", VERSION001); DummyPfModel dpm = new DummyPfModel(dpmKey); assertTrue(dpm.validate(new PfValidationResult()).isValid()); - try { - dpm.validate(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("resultIn is marked @NonNull but is null", exc.getMessage()); - } + assertThatThrownBy(() -> dpm.validate(null)).hasMessage("resultIn is marked @NonNull but is null"); dpm.setKey(PfConceptKey.getNullKey()); assertFalse(dpm.validate(new PfValidationResult()).isValid()); @@ -102,7 +87,7 @@ public class PfModelTest { dpm.getKeyList().clear(); assertTrue(dpm.validate(new PfValidationResult()).isValid()); - PfConceptKey goodCKey = new PfConceptKey("goodCKey", "0.0.1"); + PfConceptKey goodCKey = new PfConceptKey("goodCKey", VERSION001); PfReferenceKey goodRKey = new PfReferenceKey(goodCKey, "goodLocalName"); dpm.getKeyList().add(goodCKey); @@ -129,7 +114,7 @@ public class PfModelTest { dpm.getKeyList().add(goodRKeyUse); assertTrue(dpm.validate(new PfValidationResult()).isValid()); - PfConceptKey badCKey = new PfConceptKey("badCKey", "0.0.1"); + PfConceptKey badCKey = new PfConceptKey("badCKey", VERSION001); PfKeyUse badCKeyUse = new PfKeyUse(badCKey); dpm.getKeyList().add(badCKeyUse); assertFalse(dpm.validate(new PfValidationResult()).isValid()); diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java index 291a7d402..d1ba3a418 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfObjectFilterTest.java @@ -42,37 +42,44 @@ import org.onap.policy.models.base.testconcepts.DummyPfObjectFilter; */ public class PfObjectFilterTest { + private static final String NAME1 = "name1"; + private static final String NAME0 = "name0"; + private static final String HELLO = "Hello"; + private static final String DESCRIPTION1 = "Desc 1"; + private static final String VERSION100 = "1.0.0"; + private static final String VERSION002 = "0.0.2"; + @Test public void testPfObjectInterface() { DummyPfObject do0 = new DummyPfObject(); - do0.setName("name0"); - do0.setVersion("1.0.0"); + do0.setName(NAME0); + do0.setVersion(VERSION100); do0.setDescription("desc0 "); DummyPfObject do1 = new DummyPfObject(); - do1.setName("name0"); + do1.setName(NAME0); do1.setVersion("0.0.1"); - do1.setDescription("Desc 1"); + do1.setDescription(DESCRIPTION1); DummyPfObject do2 = new DummyPfObject(); - do2.setName("name0"); - do2.setVersion("0.0.2"); - do2.setDescription("Desc 1"); + do2.setName(NAME0); + do2.setVersion(VERSION002); + do2.setDescription(DESCRIPTION1); DummyPfObject do3 = new DummyPfObject(); - do3.setName("name1"); + do3.setName(NAME1); do3.setVersion("0.0.1"); do3.setDescription("desc0 "); DummyPfObject do4 = new DummyPfObject(); - do4.setName("name1"); + do4.setName(NAME1); do4.setVersion("0.1.2"); - do4.setDescription("Desc 1"); + do4.setDescription(DESCRIPTION1); DummyPfObject do5 = new DummyPfObject(); do5.setName("aaaaa"); - do5.setVersion("0.0.2"); - do5.setDescription("Desc 1"); + do5.setVersion(VERSION002); + do5.setDescription(DESCRIPTION1); List<DummyPfObject> doList = new ArrayList<>(); doList.add(do0); @@ -83,20 +90,20 @@ public class PfObjectFilterTest { doList.add(do5); DummyPfObjectFilter dof = new DummyPfObjectFilter(); - assertFalse(dof.filterString("Hello", "Goodbye")); - assertTrue(dof.filterString("Hello", "Hello")); + assertFalse(dof.filterString(HELLO, "Goodbye")); + assertTrue(dof.filterString(HELLO, HELLO)); - assertEquals(false, dof.filterString("Hello", "Goodbye")); - assertEquals(true, dof.filterString("Hello", "Hello")); - assertEquals(true, dof.filterString("Hello", null)); + assertEquals(false, dof.filterString(HELLO, "Goodbye")); + assertEquals(true, dof.filterString(HELLO, HELLO)); + assertEquals(true, dof.filterString(HELLO, null)); List<DummyPfObject> latestVersionList = dof.latestVersionFilter(doList); assertEquals(3, latestVersionList.size()); assertEquals("aaaaa", latestVersionList.get(0).getName()); - assertEquals("0.0.2", latestVersionList.get(0).getVersion()); - assertEquals("name0", latestVersionList.get(1).getName()); - assertEquals("1.0.0", latestVersionList.get(1).getVersion()); - assertEquals("name1", latestVersionList.get(2).getName()); + assertEquals(VERSION002, latestVersionList.get(0).getVersion()); + assertEquals(NAME0, latestVersionList.get(1).getName()); + assertEquals(VERSION100, latestVersionList.get(1).getVersion()); + assertEquals(NAME1, latestVersionList.get(2).getName()); assertEquals("0.1.2", latestVersionList.get(2).getVersion()); latestVersionList.remove(2); @@ -106,17 +113,17 @@ public class PfObjectFilterTest { MyFilter filter = new MyFilter(); - assertEquals(true, filter.filterString(null, "Hello")); + assertEquals(true, filter.filterString(null, HELLO)); DummyPfObject doNullVersion = new DummyPfObject(); do5.setName("bbbbb"); - assertEquals(false, filter(filter::filterStringPred, DummyPfObject::getVersion, doNullVersion, "1.0.0")); + assertEquals(false, filter(filter::filterStringPred, DummyPfObject::getVersion, doNullVersion, VERSION100)); assertEquals(false, filter(filter::filterStringPred, DummyPfObject::getVersion, do0, "1")); assertEquals(false, filter(filter::filterStringPred, DummyPfObject::getVersion, do0, "2.0.0")); assertEquals(true, filter(filter::filterStringPred, DummyPfObject::getVersion, doNullVersion, null)); assertEquals(true, filter(filter::filterStringPred, DummyPfObject::getVersion, do0, null)); - assertEquals(true, filter(filter::filterStringPred, DummyPfObject::getVersion, do0, "1.0.0")); + assertEquals(true, filter(filter::filterStringPred, DummyPfObject::getVersion, do0, VERSION100)); assertEquals(false, filter(filter::filterPrefixPred, DummyPfObject::getVersion, doNullVersion, "1.")); assertEquals(false, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.1")); @@ -126,7 +133,7 @@ public class PfObjectFilterTest { assertEquals(true, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, null)); assertEquals(true, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.")); assertEquals(true, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.0.")); - assertEquals(true, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, "1.0.0")); + assertEquals(true, filter(filter::filterPrefixPred, DummyPfObject::getVersion, do0, VERSION100)); assertEquals(false, filter(filter::filterRegexpPred, DummyPfObject::getVersion, doNullVersion, "1[.].*")); assertEquals(false, filter(filter::filterRegexpPred, DummyPfObject::getVersion, do0, "2[.].*")); 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 f1d181040..21b82fcf1 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,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,42 +21,43 @@ package org.onap.policy.models.base; +import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import java.lang.reflect.Field; - import org.junit.Test; public class PfReferenceKeyTest { + private static final String PARENT_LOCAL_NAME = "ParentLocalName"; + private static final String NPKLN = "NPKLN"; + private static final String LOCAL_NAME = "LocalName"; + private static final String VERSION002 = "0.0.2"; + private static final String VERSION001 = "0.0.1"; + @Test public void testPfReferenceKey() { assertNotNull(new PfReferenceKey()); assertNotNull(new PfReferenceKey(new PfConceptKey())); - assertNotNull(new PfReferenceKey(new PfConceptKey(), "LocalName")); + assertNotNull(new PfReferenceKey(new PfConceptKey(), LOCAL_NAME)); assertNotNull(new PfReferenceKey(new PfReferenceKey())); - assertNotNull(new PfReferenceKey(new PfReferenceKey(), "LocalName")); - assertNotNull(new PfReferenceKey(new PfConceptKey(), "ParentLocalName", "LocalName")); - assertNotNull(new PfReferenceKey("ParentKeyName", "0.0.1", "LocalName")); - assertNotNull(new PfReferenceKey("ParentKeyName", "0.0.1", "ParentLocalName", "LocalName")); + assertNotNull(new PfReferenceKey(new PfReferenceKey(), LOCAL_NAME)); + assertNotNull(new PfReferenceKey(new PfConceptKey(), PARENT_LOCAL_NAME, LOCAL_NAME)); + assertNotNull(new PfReferenceKey("ParentKeyName", VERSION001, LOCAL_NAME)); + assertNotNull(new PfReferenceKey("ParentKeyName", VERSION001, PARENT_LOCAL_NAME, LOCAL_NAME)); assertNotNull(new PfReferenceKey("ParentKeyName:0.0.1:ParentLocalName:LocalName")); assertEquals(PfReferenceKey.getNullKey().getKey(), PfReferenceKey.getNullKey()); assertEquals("NULL:0.0.0:NULL:NULL", PfReferenceKey.getNullKey().getId()); - try { - new PfReferenceKey(new PfConceptKey(), null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("parameter \"localName\" is null", exc.getMessage()); - } + assertThatThrownBy(() -> new PfReferenceKey(new PfConceptKey(), null)) + .hasMessage("parameter \"localName\" is null"); PfReferenceKey testReferenceKey = new PfReferenceKey(); - testReferenceKey.setParentConceptKey(new PfConceptKey("PN", "0.0.1")); + testReferenceKey.setParentConceptKey(new PfConceptKey("PN", VERSION001)); assertEquals("PN:0.0.1", testReferenceKey.getParentConceptKey().getId()); assertEquals(0, testReferenceKey.getMajorVersion()); @@ -65,27 +67,23 @@ public class PfReferenceKeyTest { assertEquals(1, testReferenceKey.getKeys().size()); assertFalse(testReferenceKey.isNullKey()); - testReferenceKey.setParentReferenceKey(new PfReferenceKey("PN", "0.0.1", "LN")); + testReferenceKey.setParentReferenceKey(new PfReferenceKey("PN", VERSION001, "LN")); assertEquals("PN:0.0.1:NULL:LN", testReferenceKey.getParentReferenceKey().getId()); testReferenceKey.setParentKeyName("NPKN"); assertEquals("NPKN", testReferenceKey.getParentKeyName()); - testReferenceKey.setParentKeyVersion("0.0.1"); - assertEquals("0.0.1", testReferenceKey.getParentKeyVersion()); + testReferenceKey.setParentKeyVersion(VERSION001); + assertEquals(VERSION001, testReferenceKey.getParentKeyVersion()); - testReferenceKey.setParentLocalName("NPKLN"); - assertEquals("NPKLN", testReferenceKey.getParentLocalName()); + testReferenceKey.setParentLocalName(NPKLN); + assertEquals(NPKLN, testReferenceKey.getParentLocalName()); testReferenceKey.setLocalName("NLN"); assertEquals("NLN", testReferenceKey.getLocalName()); - try { - testReferenceKey.isCompatible(null); - fail("test should throw an exception here"); - } catch (Exception exc) { - assertEquals("otherKey is marked @NonNull but is null", exc.getMessage()); - } + assertThatThrownBy(() -> testReferenceKey.isCompatible(null)) + .hasMessage("otherKey is marked @NonNull but is null"); assertFalse(testReferenceKey.isCompatible(PfConceptKey.getNullKey())); assertFalse(testReferenceKey.isCompatible(PfReferenceKey.getNullKey())); @@ -110,110 +108,85 @@ public class PfReferenceKeyTest { assertTrue(testReferenceKey.equals(testReferenceKey)); assertTrue(testReferenceKey.equals(clonedReferenceKey)); assertFalse(testReferenceKey.equals("Hello")); - assertFalse(testReferenceKey.equals(new PfReferenceKey("PKN", "0.0.2", "PLN", "LN"))); - assertFalse(testReferenceKey.equals(new PfReferenceKey("NPKN", "0.0.2", "PLN", "LN"))); - assertFalse(testReferenceKey.equals(new PfReferenceKey("NPKN", "0.0.1", "PLN", "LN"))); - assertFalse(testReferenceKey.equals(new PfReferenceKey("NPKN", "0.0.1", "NPLN", "LN"))); - assertTrue(testReferenceKey.equals(new PfReferenceKey("NPKN", "0.0.1", "NPKLN", "NLN"))); + assertFalse(testReferenceKey.equals(new PfReferenceKey("PKN", VERSION002, "PLN", "LN"))); + assertFalse(testReferenceKey.equals(new PfReferenceKey("NPKN", VERSION002, "PLN", "LN"))); + assertFalse(testReferenceKey.equals(new PfReferenceKey("NPKN", VERSION001, "PLN", "LN"))); + assertFalse(testReferenceKey.equals(new PfReferenceKey("NPKN", VERSION001, "NPLN", "LN"))); + assertTrue(testReferenceKey.equals(new PfReferenceKey("NPKN", VERSION001, NPKLN, "NLN"))); assertEquals(0, testReferenceKey.compareTo(testReferenceKey)); assertEquals(0, testReferenceKey.compareTo(clonedReferenceKey)); assertNotEquals(0, testReferenceKey.compareTo(new PfConceptKey())); - assertNotEquals(0, testReferenceKey.compareTo(new PfReferenceKey("PKN", "0.0.2", "PLN", "LN"))); - assertNotEquals(0, testReferenceKey.compareTo(new PfReferenceKey("NPKN", "0.0.2", "PLN", "LN"))); - assertNotEquals(0, testReferenceKey.compareTo(new PfReferenceKey("NPKN", "0.0.1", "PLN", "LN"))); - assertNotEquals(0, testReferenceKey.compareTo(new PfReferenceKey("NPKN", "0.0.1", "NPLN", "LN"))); - assertEquals(0, testReferenceKey.compareTo(new PfReferenceKey("NPKN", "0.0.1", "NPKLN", "NLN"))); + assertNotEquals(0, testReferenceKey.compareTo(new PfReferenceKey("PKN", VERSION002, "PLN", "LN"))); + assertNotEquals(0, testReferenceKey.compareTo(new PfReferenceKey("NPKN", VERSION002, "PLN", "LN"))); + assertNotEquals(0, testReferenceKey.compareTo(new PfReferenceKey("NPKN", VERSION001, "PLN", "LN"))); + assertNotEquals(0, testReferenceKey.compareTo(new PfReferenceKey("NPKN", VERSION001, "NPLN", "LN"))); + assertEquals(0, testReferenceKey.compareTo(new PfReferenceKey("NPKN", VERSION001, NPKLN, "NLN"))); assertFalse(testReferenceKey.equals(null)); - try { - testReferenceKey.copyTo(null); - fail("test should throw an exception here"); - } catch (Exception iae) { - assertEquals("target may not be null", iae.getMessage()); - } - - try { - testReferenceKey.copyTo(new PfConceptKey("Key", "0.0.1")); - fail("test should throw an exception here"); - } catch (Exception iae) { - assertEquals("org.onap.policy.models.base.PfConceptKey" - + " is not an instance of org.onap.policy.models.base.PfReferenceKey", iae.getMessage()); - } + assertThatThrownBy(() -> testReferenceKey.copyTo(null)).hasMessage("target may not be null"); + + assertThatThrownBy(() -> testReferenceKey.copyTo(new PfConceptKey("Key", VERSION001))) + .hasMessage("org.onap.policy.models.base.PfConceptKey" + + " is not an instance of org.onap.policy.models.base.PfReferenceKey"); PfReferenceKey targetRefKey = new PfReferenceKey(); assertEquals(testReferenceKey, testReferenceKey.copyTo(targetRefKey)); } @Test - public void testValidation() { + public void testValidation() throws Exception { PfReferenceKey testReferenceKey = new PfReferenceKey(); - testReferenceKey.setParentConceptKey(new PfConceptKey("PN", "0.0.1")); + testReferenceKey.setParentConceptKey(new PfConceptKey("PN", VERSION001)); assertEquals("PN:0.0.1", testReferenceKey.getParentConceptKey().getId()); - try { - Field parentNameField = testReferenceKey.getClass().getDeclaredField("parentKeyName"); - parentNameField.setAccessible(true); - parentNameField.set(testReferenceKey, "Parent Name"); - PfValidationResult validationResult = new PfValidationResult(); - testReferenceKey.validate(validationResult); - 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()); - } catch (Exception validationException) { - fail("test should not throw an exception"); - } - - try { - Field parentVersionField = testReferenceKey.getClass().getDeclaredField("parentKeyVersion"); - parentVersionField.setAccessible(true); - parentVersionField.set(testReferenceKey, "Parent Version"); - PfValidationResult validationResult = new PfValidationResult(); - testReferenceKey.validate(validationResult); - parentVersionField.set(testReferenceKey, "0.0.1"); - parentVersionField.setAccessible(false); - assertEquals( - "parentKeyVersion invalid-parameter parentKeyVersion with value Parent Version " - + "does not match regular expression " + PfKey.VERSION_REGEXP, - validationResult.getMessageList().get(0).getMessage()); - } catch (Exception validationException) { - fail("test should not throw an exception"); - } - - try { - Field parentLocalNameField = testReferenceKey.getClass().getDeclaredField("parentLocalName"); - parentLocalNameField.setAccessible(true); - parentLocalNameField.set(testReferenceKey, "Parent Local Name"); - PfValidationResult validationResult = new PfValidationResult(); - testReferenceKey.validate(validationResult); - parentLocalNameField.set(testReferenceKey, "ParentLocalName"); - parentLocalNameField.setAccessible(false); - assertEquals( - "parentLocalName invalid-parameter parentLocalName with value " - + "Parent Local Name does not match regular expression [A-Za-z0-9\\-_\\.]+|^$", - validationResult.getMessageList().get(0).getMessage()); - } catch (Exception validationException) { - fail("test should not throw an exception"); - } - - try { - Field localNameField = testReferenceKey.getClass().getDeclaredField("localName"); - localNameField.setAccessible(true); - localNameField.set(testReferenceKey, "Local Name"); - PfValidationResult validationResult = new PfValidationResult(); - testReferenceKey.validate(validationResult); - localNameField.set(testReferenceKey, "LocalName"); - localNameField.setAccessible(false); - assertEquals( - "localName invalid-parameter localName with value Local Name " - + "does not match regular expression [A-Za-z0-9\\-_\\.]+|^$", - validationResult.getMessageList().get(0).getMessage()); - } catch (Exception validationException) { - fail("test should not throw an exception"); - } + Field parentNameField = testReferenceKey.getClass().getDeclaredField("parentKeyName"); + parentNameField.setAccessible(true); + parentNameField.set(testReferenceKey, "Parent Name"); + PfValidationResult validationResult = new PfValidationResult(); + testReferenceKey.validate(validationResult); + 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()); + + Field parentVersionField = testReferenceKey.getClass().getDeclaredField("parentKeyVersion"); + parentVersionField.setAccessible(true); + parentVersionField.set(testReferenceKey, "Parent Version"); + PfValidationResult validationResult2 = new PfValidationResult(); + testReferenceKey.validate(validationResult2); + 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()); + + Field parentLocalNameField = testReferenceKey.getClass().getDeclaredField("parentLocalName"); + parentLocalNameField.setAccessible(true); + parentLocalNameField.set(testReferenceKey, "Parent Local Name"); + PfValidationResult validationResult3 = new PfValidationResult(); + testReferenceKey.validate(validationResult3); + 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()); + + Field localNameField = testReferenceKey.getClass().getDeclaredField("localName"); + localNameField.setAccessible(true); + localNameField.set(testReferenceKey, "Local Name"); + PfValidationResult validationResult4 = new PfValidationResult(); + testReferenceKey.validate(validationResult4); + 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()); } } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java index 339ee9d1b..bd55dcd9a 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java @@ -36,13 +36,15 @@ import org.junit.Test; */ public class PfUtilsTest { + private static final String HELLO = "hello"; + @Test public void testCompareObjects() { assertEquals(0, PfUtils.compareObjects(null, null)); - assertEquals(-1, PfUtils.compareObjects("hello", null)); - assertEquals(1, PfUtils.compareObjects(null, "hello")); - assertFalse(PfUtils.compareObjects("hello", "goodbye") == 0); - assertEquals(0, PfUtils.compareObjects("hello", "hello")); + assertEquals(-1, PfUtils.compareObjects(HELLO, null)); + assertEquals(1, PfUtils.compareObjects(null, HELLO)); + assertFalse(PfUtils.compareObjects(HELLO, "goodbye") == 0); + assertEquals(0, PfUtils.compareObjects(HELLO, HELLO)); } @Test diff --git a/models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java b/models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java index 391e7333b..120ddbff9 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/ValidatedTest.java @@ -3,6 +3,7 @@ * ONAP Policy Models * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,6 +36,7 @@ import org.junit.Before; import org.junit.Test; public class ValidatedTest { + private static final String COLLECTION_TEXT = "collection"; private static final String ERROR_MESSAGE = "error message"; private static final String COLLECTION_FIELD = "coll"; private static final String VALID_VALUE = "abc123"; @@ -236,7 +238,7 @@ public class ValidatedTest { @Test public void testValidateCollectionNotNull() { PfValidationResult result = new PfValidationResult(); - result = validated.validateCollectionNotNull(this, "collection", null, result); + result = validated.validateCollectionNotNull(this, COLLECTION_TEXT, null, result); assertTrue(result.isValid()); assertEquals(0, result.getMessageList().size()); @@ -273,7 +275,7 @@ public class ValidatedTest { @Test public void testValidateCollection() { PfValidationResult result = new PfValidationResult(); - result = validated.validateCollection(this, "collection", null, result); + result = validated.validateCollection(this, COLLECTION_TEXT, null, result); assertTrue(result.isValid()); assertEquals(0, result.getMessageList().size()); @@ -310,7 +312,7 @@ public class ValidatedTest { @Test public void testValidateConceptCollection() { PfValidationResult result = new PfValidationResult(); - result = validated.validateConceptCollection(this, "collection", null, result); + result = validated.validateConceptCollection(this, COLLECTION_TEXT, null, result); assertTrue(result.isValid()); assertEquals(0, result.getMessageList().size()); diff --git a/models-base/src/test/java/org/onap/policy/models/base/ValidationTest.java b/models-base/src/test/java/org/onap/policy/models/base/ValidationTest.java index 0d4f2a7ee..ef0d8d609 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/ValidationTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/ValidationTest.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,6 +31,9 @@ import org.onap.policy.models.base.PfValidationResult.ValidationResult; public class ValidationTest { + private static final String HELLO = "hello"; + private static final String SOME_MESSAGE = "Some message"; + @Test public void test() { PfValidationResult result = new PfValidationResult(); @@ -43,47 +47,47 @@ public class ValidationTest { assertNotNull(result.getMessageList()); PfValidationMessage vmess0 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class, - ValidationResult.VALID, "Some message"); + ValidationResult.VALID, SOME_MESSAGE); result.addValidationMessage(vmess0); assertTrue(result.isOk()); assertTrue(result.isValid()); assertEquals(PfValidationResult.ValidationResult.VALID, result.getValidationResult()); assertNotNull(result.getMessageList()); - assertNotNull("hello", result.toString()); + assertNotNull(HELLO, result.toString()); PfValidationMessage vmess1 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class, - ValidationResult.OBSERVATION, "Some message"); + ValidationResult.OBSERVATION, SOME_MESSAGE); result.addValidationMessage(vmess1); assertTrue(result.isOk()); assertTrue(result.isValid()); assertEquals(PfValidationResult.ValidationResult.OBSERVATION, result.getValidationResult()); assertNotNull(result.getMessageList()); - assertNotNull("hello", result.toString()); + assertNotNull(HELLO, result.toString()); PfValidationMessage vmess2 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class, - ValidationResult.WARNING, "Some message"); + ValidationResult.WARNING, SOME_MESSAGE); result.addValidationMessage(vmess2); assertFalse(result.isOk()); assertTrue(result.isValid()); assertEquals(PfValidationResult.ValidationResult.WARNING, result.getValidationResult()); assertNotNull(result.getMessageList()); - assertNotNull("hello", result.toString()); + assertNotNull(HELLO, result.toString()); PfValidationMessage vmess3 = new PfValidationMessage(PfConceptKey.getNullKey(), PfConceptKey.class, - ValidationResult.INVALID, "Some message"); + ValidationResult.INVALID, SOME_MESSAGE); result.addValidationMessage(vmess3); assertFalse(result.isOk()); assertFalse(result.isValid()); assertEquals(PfValidationResult.ValidationResult.INVALID, result.getValidationResult()); assertNotNull(result.getMessageList()); - assertNotNull("hello", result.toString()); + assertNotNull(HELLO, result.toString()); assertEquals(PfValidationResult.ValidationResult.INVALID, result.getMessageList().get(3).getValidationResult()); - assertEquals("Some message", result.getMessageList().get(3).getMessage()); + assertEquals(SOME_MESSAGE, result.getMessageList().get(3).getMessage()); assertEquals(PfConceptKey.class.getCanonicalName(), result.getMessageList().get(3).getObservedClass()); assertEquals(PfConceptKey.getNullKey(), result.getMessageList().get(3).getObservedKey()); } diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java index 5e74fb2f9..6cb44e6b5 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java +++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfConcept.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,23 +49,6 @@ public class DummyPfConcept extends PfConcept implements PfAuthorative<DummyAuth private String description; - @Override - public DummyAuthorativeConcept toAuthorative() { - DummyAuthorativeConcept dac = new DummyAuthorativeConcept(); - dac.setName(key.getName()); - dac.setVersion(key.getVersion()); - dac.setDescription(description); - - return dac; - } - - @Override - public void fromAuthorative(DummyAuthorativeConcept dac) { - key.setName(dac.getName()); - key.setVersion(dac.getVersion()); - description = dac.getDescription(); - } - /** * The Default Constructor creates a {@link DummyPfConcept} object with a null key. */ @@ -91,9 +75,25 @@ public class DummyPfConcept extends PfConcept implements PfAuthorative<DummyAuth } @Override + public DummyAuthorativeConcept toAuthorative() { + DummyAuthorativeConcept dac = new DummyAuthorativeConcept(); + dac.setName(key.getName()); + dac.setVersion(key.getVersion()); + dac.setDescription(description); + + return dac; + } + + @Override + public void fromAuthorative(DummyAuthorativeConcept dac) { + key.setName(dac.getName()); + key.setVersion(dac.getVersion()); + description = dac.getDescription(); + } + + @Override public List<PfKey> getKeys() { - final List<PfKey> keyList = getKey().getKeys(); - return keyList; + return getKey().getKeys(); } @Override diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java index f485b0d0f..944c1e602 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java +++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,7 +75,7 @@ public class DummyPfKey extends PfKey { @Override public void clean() { - + // nothing to do } @Override @@ -84,7 +85,7 @@ public class DummyPfKey extends PfKey { @Override public String toString() { - return null; + return ""; } @Override diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfModel.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfModel.java index 199a37f59..4a30f593f 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfModel.java +++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfModel.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -50,7 +51,7 @@ public class DummyPfModel extends PfModel { public DummyPfModel() { super(); super.setKey(new PfConceptKey()); - this.keyList = new ArrayList<PfKey>(); + this.keyList = new ArrayList<>(); } /** @@ -61,7 +62,7 @@ public class DummyPfModel extends PfModel { */ public DummyPfModel(final PfConceptKey key) { super(key); - this.keyList = new ArrayList<PfKey>(); + this.keyList = new ArrayList<>(); } /** @@ -86,6 +87,7 @@ public class DummyPfModel extends PfModel { @Override public void register() { + // nothing to do } @Override diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfNameVersion.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfNameVersion.java index 23179d7de..792ac3c06 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfNameVersion.java +++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfNameVersion.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +32,6 @@ import org.onap.policy.models.base.PfNameVersion; */ @Data public class DummyPfNameVersion implements PfNameVersion { - public String name; - public String version; + private String name; + private String version; } |