diff options
Diffstat (limited to 'models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java')
-rw-r--r-- | models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java | 92 |
1 files changed, 32 insertions, 60 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java index 19846a0cc..602985dda 100644 --- a/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java +++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEventFilterTest.java @@ -1,6 +1,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,17 +21,16 @@ package org.onap.policy.models.tosca.simple.concepts; +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.PfConceptKey; import org.onap.policy.models.base.PfReferenceKey; import org.onap.policy.models.base.PfValidationResult; -import org.onap.policy.models.tosca.simple.concepts.JpaToscaEventFilter; /** * DAO test for ToscaEventFilter. @@ -39,6 +39,11 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaEventFilter; */ public class JpaToscaEventFilterTest { + private static final String KEY_IS_NULL = "key is marked @NonNull but is null"; + private static final String A_REQUREMENT = "A Requrement"; + private static final String A_CAPABILITY = "A Capability"; + private static final String VERSION_001 = "0.0.1"; + @Test public void testEventFilterPojo() { assertNotNull(new JpaToscaEventFilter()); @@ -46,51 +51,28 @@ public class JpaToscaEventFilterTest { assertNotNull(new JpaToscaEventFilter(new PfReferenceKey(), new PfConceptKey())); assertNotNull(new JpaToscaEventFilter(new JpaToscaEventFilter())); - try { - new JpaToscaEventFilter((PfReferenceKey) null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("key is marked @NonNull but is null", exc.getMessage()); - } - - try { - new JpaToscaEventFilter(null, null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("key is marked @NonNull but is null", exc.getMessage()); - } - - try { - new JpaToscaEventFilter(null, new PfConceptKey()); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("key is marked @NonNull but is null", exc.getMessage()); - } - - try { - new JpaToscaEventFilter(new PfReferenceKey(), null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("node is marked @NonNull but is null", exc.getMessage()); - } - - try { - new JpaToscaEventFilter((JpaToscaEventFilter) null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage()); - } - - PfConceptKey efParentKey = new PfConceptKey("tParentKey", "0.0.1"); + assertThatThrownBy(() -> new JpaToscaEventFilter((PfReferenceKey) null)).hasMessage(KEY_IS_NULL); + + assertThatThrownBy(() -> new JpaToscaEventFilter(null, null)).hasMessage(KEY_IS_NULL); + + assertThatThrownBy(() -> new JpaToscaEventFilter(null, new PfConceptKey())).hasMessage(KEY_IS_NULL); + + assertThatThrownBy(() -> new JpaToscaEventFilter(new PfReferenceKey(), null)) + .hasMessage("node is marked @NonNull but is null"); + + assertThatThrownBy(() -> new JpaToscaEventFilter((JpaToscaEventFilter) null)) + .hasMessage("copyConcept is marked @NonNull but is null"); + + PfConceptKey efParentKey = new PfConceptKey("tParentKey", VERSION_001); PfReferenceKey efKey = new PfReferenceKey(efParentKey, "trigger0"); - PfConceptKey nodeKey = new PfConceptKey("tParentKey", "0.0.1"); + PfConceptKey nodeKey = new PfConceptKey("tParentKey", VERSION_001); JpaToscaEventFilter tef = new JpaToscaEventFilter(efKey, nodeKey); - tef.setRequirement("A Requrement"); - assertEquals("A Requrement", tef.getRequirement()); + tef.setRequirement(A_REQUREMENT); + assertEquals(A_REQUREMENT, tef.getRequirement()); - tef.setCapability("A Capability"); - assertEquals("A Capability", tef.getCapability()); + tef.setCapability(A_CAPABILITY); + assertEquals(A_CAPABILITY, tef.getCapability()); JpaToscaEventFilter tdtClone0 = new JpaToscaEventFilter(tef); assertEquals(tef, tdtClone0); @@ -105,7 +87,7 @@ public class JpaToscaEventFilterTest { assertEquals(0, tef.compareTo(tef)); assertFalse(tef.compareTo(tef.getKey()) == 0); - PfReferenceKey otherDtKey = new PfReferenceKey("otherDt", "0.0.1", "OtherEventFilter"); + PfReferenceKey otherDtKey = new PfReferenceKey("otherDt", VERSION_001, "OtherEventFilter"); JpaToscaEventFilter otherDt = new JpaToscaEventFilter(otherDtKey); assertFalse(tef.compareTo(otherDt) == 0); @@ -113,17 +95,12 @@ public class JpaToscaEventFilterTest { assertFalse(tef.compareTo(otherDt) == 0); otherDt.setNode(nodeKey); assertFalse(tef.compareTo(otherDt) == 0); - otherDt.setRequirement("A Requrement"); + otherDt.setRequirement(A_REQUREMENT); assertFalse(tef.compareTo(otherDt) == 0); - otherDt.setCapability("A Capability"); + otherDt.setCapability(A_CAPABILITY); assertEquals(0, tef.compareTo(otherDt)); - try { - tef.copyTo(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("target is marked @NonNull but is null", exc.getMessage()); - } + assertThatThrownBy(() -> tef.copyTo(null)).hasMessage("target is marked @NonNull but is null"); assertEquals(2, tef.getKeys().size()); assertEquals(2, new JpaToscaEventFilter().getKeys().size()); @@ -139,14 +116,14 @@ public class JpaToscaEventFilterTest { assertTrue(tef.validate(new PfValidationResult()).isValid()); tef.setRequirement(""); assertFalse(tef.validate(new PfValidationResult()).isValid()); - tef.setRequirement("A Requrement"); + tef.setRequirement(A_REQUREMENT); assertTrue(tef.validate(new PfValidationResult()).isValid()); tef.setCapability(null); assertTrue(tef.validate(new PfValidationResult()).isValid()); tef.setCapability(""); assertFalse(tef.validate(new PfValidationResult()).isValid()); - tef.setCapability("A Capability"); + tef.setCapability(A_CAPABILITY); assertTrue(tef.validate(new PfValidationResult()).isValid()); tef.setNode(null); @@ -156,11 +133,6 @@ public class JpaToscaEventFilterTest { tef.setNode(nodeKey); assertTrue(tef.validate(new PfValidationResult()).isValid()); - try { - tef.validate(null); - fail("test should throw an exception"); - } catch (Exception exc) { - assertEquals("resultIn is marked @NonNull but is null", exc.getMessage()); - } + assertThatThrownBy(() -> tef.validate(null)).hasMessage("resultIn is marked @NonNull but is null"); } } |