Add PDP-TOPIC-CHECK message 64/123364/1
authorJim Hahn <jrh3@att.com>
Tue, 17 Aug 2021 19:25:39 +0000 (15:25 -0400)
committerJim Hahn <jrh3@att.com>
Wed, 18 Aug 2021 19:51:02 +0000 (15:51 -0400)
Added a new PdpMessage subclass that a PDP can use to verify its ability
to send/receive to/from the PDP-PAP topic before it sends its first
registration message.

Issue-ID: POLICY-3531
Change-Id: Ied61caa805e93e25732385bf91272b4fc248fd69
Signed-off-by: Jim Hahn <jrh3@att.com>
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpMessage.java
models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpTopicCheck.java [new file with mode: 0644]
models-pdp/src/main/java/org/onap/policy/models/pdp/enums/PdpMessageType.java
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpMessageTest.java
models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpTopicCheckTest.java [new file with mode: 0644]

index 5d0359c..2191932 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@ package org.onap.policy.models.pdp.concepts;
 
 import java.util.UUID;
 import lombok.AccessLevel;
+import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.NonNull;
 import lombok.Setter;
@@ -38,6 +39,7 @@ import org.onap.policy.models.pdp.enums.PdpMessageType;
 @Getter
 @Setter
 @ToString
+@EqualsAndHashCode
 public class PdpMessage {
 
     @Setter(AccessLevel.NONE)
@@ -58,13 +60,13 @@ public class PdpMessage {
 
     /**
      * Group associated with the PDP. For state-change messages, this may be {@code null},
-     * if the {@link #name} is provided.
+     * if the {@link #name} is provided.  Also {@code null} for topic-check messages.
      */
     private String pdpGroup;
 
     /**
      * Group associated with the PDP. For state-change messages, this may be {@code null},
-     * if the {@link #name} is provided.
+     * if the {@link #name} is provided.  Also {@code null} for topic-check messages.
      */
     private String pdpSubgroup;
 
diff --git a/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpTopicCheck.java b/models-pdp/src/main/java/org/onap/policy/models/pdp/concepts/PdpTopicCheck.java
new file mode 100644 (file)
index 0000000..2cd3a9d
--- /dev/null
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2021 AT&T Intellectual Property.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.onap.policy.models.pdp.enums.PdpMessageType;
+
+/**
+ * Class to represent the PDP_TOPIC_CHECK message that a PDP will send to itself.
+ */
+@Getter
+@Setter
+@ToString(callSuper = true)
+public class PdpTopicCheck extends PdpMessage {
+
+    /**
+     * Constructs the object.
+     *
+     */
+    public PdpTopicCheck() {
+        super(PdpMessageType.PDP_TOPIC_CHECK);
+    }
+
+    /**
+     * Constructs the object, making a deep copy.
+     *
+     * @param source source from which to copy
+     */
+    public PdpTopicCheck(PdpTopicCheck source) {
+        super(source);
+    }
+}
index 7ba4ad7..a8aad96 100644 (file)
@@ -1,7 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 Nordix Foundation.
- *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -50,4 +50,9 @@ public enum PdpMessageType {
      * PDP_HEALTH_CHECK operation.
      */
     PDP_HEALTH_CHECK,
+
+    /**
+     * Used by PDPs to check their ability to send and receive messages on the PDP-PAP topic.
+     */
+    PDP_TOPIC_CHECK,
 }
index dc67268..763b29a 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Models
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2019 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,6 +24,7 @@ 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.assertNotEquals;
 import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
@@ -39,7 +40,7 @@ public class PdpMessageTest {
     private PdpMessage message;
 
     @Test
-    public void testCopyConstructor() {
+    public void testCopyConstructorAndEquals() {
         assertThatThrownBy(() -> new PdpMessage((PdpMessage) null)).isInstanceOf(NullPointerException.class);
 
         // verify with null values
@@ -48,6 +49,7 @@ public class PdpMessageTest {
         newmsg.setRequestId(message.getRequestId());
         newmsg.setTimestampMs(message.getTimestampMs());
         assertEquals(message.toString(), newmsg.toString());
+        assertEquals(message, newmsg);
 
         // verify with all values
         message = makeMessage(PDP_NAME, PDP_GROUP, PDP_SUBGROUP);
@@ -55,6 +57,10 @@ public class PdpMessageTest {
         newmsg.setRequestId(message.getRequestId());
         newmsg.setTimestampMs(message.getTimestampMs());
         assertEquals(message.toString(), newmsg.toString());
+        assertEquals(message, newmsg);
+
+        newmsg.setTimestampMs(1);
+        assertNotEquals(message, newmsg);
     }
 
     @Test
diff --git a/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpTopicCheckTest.java b/models-pdp/src/test/java/org/onap/policy/models/pdp/concepts/PdpTopicCheckTest.java
new file mode 100644 (file)
index 0000000..270278a
--- /dev/null
@@ -0,0 +1,48 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Models
+ * ================================================================================
+ * Copyright (C) 2021 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.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.pdp.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.onap.policy.models.pdp.concepts.PdpMessageUtils.removeVariableFields;
+
+import org.junit.Test;
+
+/**
+ * Test the copy constructor, as {@link ModelsTest} tests the other methods.
+ */
+public class PdpTopicCheckTest {
+
+    @Test
+    public void testCopyConstructor() {
+        assertThatThrownBy(() -> new PdpTopicCheck(null)).isInstanceOf(NullPointerException.class);
+
+        PdpTopicCheck orig = new PdpTopicCheck();
+
+        // verify with null values
+        assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpTopicCheck(orig).toString()));
+
+        // verify with all values
+        orig.setName("my-name");
+
+        assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpTopicCheck(orig).toString()));
+    }
+}