diff options
author | liamfallon <liam.fallon@est.tech> | 2019-04-05 21:19:37 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2019-04-05 21:19:37 +0000 |
commit | 52229882d7ee3e934641de0bd2df74ed1268130e (patch) | |
tree | ddc60f59d53d0cc9136bf0e07467393b93d6f41b /models-base/src/test | |
parent | 3f51a8aba42c15ba84296b6477597499bec49322 (diff) |
Add unit tests for models-base
Brings coverage in models-base up over 99%
Issue-ID: POLICY-1095
Change-Id: Ie1c9f3f132715275f44f349a415a8bb34a0115c9
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-base/src/test')
3 files changed, 41 insertions, 5 deletions
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 3ae7c4c9d..55f59f640 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,6 +48,7 @@ import org.onap.policy.models.base.testconcepts.DummyPfConceptSub; */ public class PfConceptContainerTest { + @SuppressWarnings({ "unchecked", "rawtypes" }) @Test public void testConceptContainer() { DummyPfConceptContainer container = new DummyPfConceptContainer(); @@ -63,6 +64,13 @@ public class PfConceptContainerTest { 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) { @@ -190,7 +198,7 @@ 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("name1", "1.2.3", "Hi")); + dacMap.put("name1", new DummyAuthorativeConcept(null, null, "Hi")); dacMap.put("name2", new DummyAuthorativeConcept("name2", "1.2.3", "Howdy")); List<Map<String, DummyAuthorativeConcept>> authorativeList = new ArrayList<>(); @@ -200,12 +208,14 @@ public class PfConceptContainerTest { container.fromAuthorative(authorativeList); assertEquals("Hello", container.getConceptMap().get(new PfConceptKey("name0:1.2.3")).getDescription()); - assertEquals("Hi", container.getConceptMap().get(new PfConceptKey("name1:1.2.3")).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()); List<Map<String, DummyAuthorativeConcept>> outMapList = container.toAuthorative(); - assertEquals(dacMap, outMapList.get(0)); + assertEquals(dacMap.get("name0"), outMapList.get(0).get("name0")); + assertEquals(dacMap.get("name1").getDescription(), outMapList.get(0).get("name1").getDescription()); + assertEquals(dacMap.get("name2"), outMapList.get(0).get("name2")); DummyBadPfConceptContainer badContainer = new DummyBadPfConceptContainer(); assertThatThrownBy(() -> { 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 a4c504788..797dba0cf 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 @@ -48,6 +48,13 @@ public class PfKeyTest { 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()); + } + PfConceptKey someKey0 = new PfConceptKey(); assertEquals(PfConceptKey.getNullKey(), someKey0); @@ -56,6 +63,7 @@ public class PfKeyTest { PfConceptKey someKey3 = new PfConceptKey(someKey1.getId()); assertEquals(someKey1, someKey2); assertEquals(someKey1, someKey3); + assertFalse(someKey1.isNullVersion()); assertEquals(someKey2, someKey1.getKey()); assertEquals(1, someKey1.getKeys().size()); 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 72df28f04..68494309c 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,4 +1,4 @@ -/* +/*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. * ================================================================================ @@ -41,7 +41,7 @@ public class PfKeyUseTest { assertNotNull(new PfKeyUse(new PfReferenceKey())); try { - new PfKeyUse((PfKeyUse)null); + new PfKeyUse((PfKeyUse) null); fail("test should throw an exception"); } catch (Exception exc) { assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage()); @@ -56,6 +56,14 @@ public class PfKeyUseTest { assertFalse(keyUse.isNullKey()); 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()); + } + assertTrue(keyUse.isCompatible(key)); keyUse.clean(); @@ -132,6 +140,16 @@ public class PfKeyUseTest { 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()); + } + + assertEquals(false, testKeyUse.isNewerThan(keyUse)); + assertEquals(false, testKeyUse.isNewerThan(testKeyUse)); + assertEquals(0, testKeyUse.getMajorVersion()); assertEquals(0, testKeyUse.getMinorVersion()); assertEquals(0, testKeyUse.getPatchVersion()); |