diff options
author | Jim Hahn <jrh3@att.com> | 2019-04-07 09:49:41 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2019-04-07 10:07:33 -0400 |
commit | 53bba4720a910d29a99b20f75529a5457485aed2 (patch) | |
tree | 849c0afa089d0c8156f301d73375a0fe142135fa /models-pdp/src/test/java/org/onap | |
parent | 82699a970d5f06c6dc1391d8beb0efe76bf84089 (diff) |
Add PdpMessage.appliesTo()
Added a method to determine if a message is applicable to a particular
PDP. This is a common function that should have been added previously,
as each PDP type has had to create an implementation of it.
Nevertheless, this provides a "reference" implementation.
Change-Id: I54073c77a9d2b4c1f902c5ac0bce9fa5fa485503
Issue-ID: POLICY-1542
Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-pdp/src/test/java/org/onap')
-rw-r--r-- | models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpMessage.java | 133 |
1 files changed, 118 insertions, 15 deletions
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpMessage.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpMessage.java index 515c48385..0d3f591c7 100644 --- a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpMessage.java +++ b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/TestPdpMessage.java @@ -23,35 +23,138 @@ package org.onap.policy.models.pdp.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.assertTrue; import org.junit.Test; import org.onap.policy.models.pdp.enums.PdpMessageType; /** - * Test the copy constructor, as {@link TestModels} tests the other methods. + * Tests methods not already tested by {@link TestModels}. */ public class TestPdpMessage { + private static final String PDP_NAME = "pdpA"; + private static final String PDP_GROUP = "groupA"; + private static final String PDP_SUBGROUP = "subgroupA"; + private static final String DIFFERENT = "differentValue"; + + private PdpMessage message; @Test public void testCopyConstructor() { assertThatThrownBy(() -> new PdpMessage((PdpMessage) null)).isInstanceOf(NullPointerException.class); - PdpMessage orig = new PdpMessage(PdpMessageType.PDP_STATE_CHANGE); - // verify with null values - PdpMessage newmsg = new PdpMessage(orig); - newmsg.setRequestId(orig.getRequestId()); - newmsg.setTimestampMs(orig.getTimestampMs()); - assertEquals(orig.toString(), newmsg.toString()); + message = new PdpMessage(PdpMessageType.PDP_STATE_CHANGE); + PdpMessage newmsg = new PdpMessage(message); + newmsg.setRequestId(message.getRequestId()); + newmsg.setTimestampMs(message.getTimestampMs()); + assertEquals(message.toString(), newmsg.toString()); // verify with all values - orig.setName("my-name"); - orig.setPdpGroup("my-group"); - orig.setPdpSubgroup("my-subgroup"); - - newmsg = new PdpMessage(orig); - newmsg.setRequestId(orig.getRequestId()); - newmsg.setTimestampMs(orig.getTimestampMs()); - assertEquals(orig.toString(), newmsg.toString()); + message = makeMessage(PDP_NAME, PDP_GROUP, PDP_SUBGROUP); + newmsg = new PdpMessage(message); + newmsg.setRequestId(message.getRequestId()); + newmsg.setTimestampMs(message.getTimestampMs()); + assertEquals(message.toString(), newmsg.toString()); + } + + @Test + public void testAppliesTo_NameCombos() { + /* + * Test cases where the name matches. + */ + for (String msgGroup : new String[] {null, PDP_GROUP, DIFFERENT}) { + for (String msgSubgroup : new String[] {null, PDP_SUBGROUP, DIFFERENT}) { + message = makeMessage(PDP_NAME, msgGroup, msgSubgroup); + + for (String pdpGroup : new String[] {null, PDP_GROUP, DIFFERENT}) { + for (String pdpSubgroup : new String[] {null, PDP_SUBGROUP, DIFFERENT}) { + assertTrue("name msg " + message + " pdp group " + pdpGroup + "/" + pdpSubgroup, + message.appliesTo(PDP_NAME, pdpGroup, pdpSubgroup)); + } + } + } + } + + /* + * Test cases where the name does not match. + */ + for (String msgGroup : new String[] {null, PDP_GROUP, DIFFERENT}) { + for (String msgSubgroup : new String[] {null, PDP_SUBGROUP, DIFFERENT}) { + message = makeMessage(PDP_NAME, msgGroup, msgSubgroup); + + for (String pdpGroup : new String[] {null, PDP_GROUP, DIFFERENT}) { + for (String pdpSubgroup : new String[] {null, PDP_SUBGROUP, DIFFERENT}) { + assertFalse("name msg " + message + " pdp group " + pdpGroup + "/" + pdpSubgroup, + message.appliesTo(DIFFERENT, pdpGroup, pdpSubgroup)); + } + } + } + } + } + + @Test + public void testAppliesTo_BroadcastGroup() { + /* + * Test cases where the group matches. + */ + for (String msgSubgroup : new String[] {null, PDP_SUBGROUP}) { + message = makeMessage(null, PDP_GROUP, msgSubgroup); + + assertTrue("group msg " + message, message.appliesTo(PDP_NAME, PDP_GROUP, PDP_SUBGROUP)); + } + + /* + * Test cases where the group does not match. + */ + for (String msgGroup : new String[] {null, PDP_GROUP}) { + for (String msgSubgroup : new String[] {null, PDP_SUBGROUP}) { + message = makeMessage(null, msgGroup, msgSubgroup); + + for (String pdpGroup : new String[] {null, DIFFERENT}) { + assertFalse("group msg " + message + " pdp group " + pdpGroup, + message.appliesTo(PDP_NAME, pdpGroup, PDP_SUBGROUP)); + } + } + } + } + + @Test + public void testAppliesTo_BroadcastSubGroup() { + /* + * Test cases where the subgroup matches. + */ + message = makeMessage(null, PDP_GROUP, PDP_SUBGROUP); + assertTrue("subgroup msg " + message, message.appliesTo(PDP_NAME, PDP_GROUP, PDP_SUBGROUP)); + + /* + * Test cases where the subgroup does not match. + */ + message = makeMessage(null, PDP_GROUP, PDP_SUBGROUP); + + for (String pdpSubgroup : new String[] {null, DIFFERENT}) { + assertFalse("subgroup msg " + message + " pdp subgroup " + pdpSubgroup, + message.appliesTo(PDP_NAME, PDP_GROUP, pdpSubgroup)); + } + } + + @Test + public void testAppliesTo_NullPdpName() { + message = makeMessage(PDP_NAME, PDP_GROUP, PDP_SUBGROUP); + + assertThatThrownBy(() -> message.appliesTo(null, PDP_GROUP, PDP_SUBGROUP)) + .isInstanceOf(NullPointerException.class); + + } + + private PdpMessage makeMessage(String pdpName, String pdpGroup, String pdpSubgroup) { + PdpMessage msg = new PdpMessage(PdpMessageType.PDP_STATE_CHANGE); + + msg.setName(pdpName); + msg.setPdpGroup(pdpGroup); + msg.setPdpSubgroup(pdpSubgroup); + + return msg; } } |