Set "source" name in PAP PdpMessages 41/122341/1
authorJim Hahn <jrh3@att.com>
Mon, 28 Jun 2021 18:28:01 +0000 (14:28 -0400)
committerJim Hahn <jrh3@att.com>
Tue, 29 Jun 2021 14:06:06 +0000 (10:06 -0400)
Used the unique name generator to initialize the PAP_NAME constant which
is then stuffed into the various outgoing PdpMessages.

Issue-ID: POLICY-3409
Change-Id: I45d26403b4f3de4b040cad779f29c82f35bacf42
Signed-off-by: Jim Hahn <jrh3@att.com>
main/src/main/java/org/onap/policy/pap/main/PapConstants.java
main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java
main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java
main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java
main/src/test/java/org/onap/policy/pap/main/PapConstantsTest.java
main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateProvider.java
main/src/test/java/org/onap/policy/pap/main/rest/TestProviderBase.java

index b51e85c..7d4cb7b 100644 (file)
@@ -20,6 +20,8 @@
 
 package org.onap.policy.pap.main;
 
+import org.onap.policy.common.utils.network.NetworkUtil;
+
 /**
  * Names of various items contained in the Registry.
  */
@@ -43,6 +45,9 @@ public class PapConstants {
     public static final String POLICY_PAP = "pap";
     public static final String POLICY_PDPS = "pdps";
 
+    // unique name used when generating PdpMessages
+    public static final String PAP_NAME = NetworkUtil.genUniqueName("pap");
+
     private PapConstants() {
         super();
     }
index a282957..8dad7ac 100644 (file)
@@ -99,6 +99,7 @@ public class PdpMessageGenerator {
 
         final var update = new PdpUpdate();
 
+        update.setSource(PapConstants.PAP_NAME);
         update.setName(pdpInstanceId);
         update.setPdpGroup(pdpGroupName);
         update.setPdpSubgroup(subGroup.getPdpType());
@@ -134,6 +135,7 @@ public class PdpMessageGenerator {
                     final String pdpInstanceId, final PdpState pdpState) {
 
         final var stateChange = new PdpStateChange();
+        stateChange.setSource(PapConstants.PAP_NAME);
         stateChange.setName(pdpInstanceId);
         stateChange.setPdpGroup(pdpGroupName);
         stateChange.setPdpSubgroup(subGroup.getPdpType());
index 8be787a..696cc8c 100644 (file)
@@ -46,6 +46,7 @@ import org.onap.policy.models.pdp.enums.PdpState;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.pap.main.PapConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -320,11 +321,13 @@ public class PdpGroupCreateOrUpdateProvider extends ProviderBase {
 
             // make it passive
             var change = new PdpStateChange();
+            change.setSource(PapConstants.PAP_NAME);
             change.setName(name);
             change.setState(PdpState.PASSIVE);
 
             // remove it from subgroup and undeploy all policies
             var update = new PdpUpdate();
+            update.setSource(PapConstants.PAP_NAME);
             update.setName(name);
 
             data.addRequests(update, change);
index 6fa0ef3..4cc5a44 100644 (file)
@@ -228,6 +228,7 @@ public abstract class ProviderBase {
 
         var update = new PdpUpdate();
 
+        update.setSource(PapConstants.PAP_NAME);
         update.setName(pdp.getInstanceId());
         update.setDescription(group.getDescription());
         update.setPdpGroup(group.getName());
index 4733f91..6d5d303 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP PAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2020 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
 
 package org.onap.policy.pap.main;
 
-import org.assertj.core.api.Assertions;
+import static org.assertj.core.api.Assertions.assertThat;
+
 import org.junit.Test;
-import org.powermock.reflect.Whitebox;
 
 public class PapConstantsTest {
 
     @Test
     public void test() {
-        // verify that constructor does not throw an exception
-        Assertions.assertThatCode(() -> Whitebox.invokeConstructor(PapConstants.class)).doesNotThrowAnyException();
+        assertThat(PapConstants.PAP_NAME).startsWith("pap").isNotEqualTo("pap");
     }
 }
index 1ea1311..f64a77b 100644 (file)
@@ -25,7 +25,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
@@ -50,6 +49,7 @@ import org.onap.policy.models.pdp.concepts.PdpSubGroup;
 import org.onap.policy.models.pdp.concepts.PdpUpdate;
 import org.onap.policy.models.pdp.enums.PdpState;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
+import org.onap.policy.pap.main.PapConstants;
 
 public class TestPdpGroupCreateOrUpdateProvider extends ProviderSuper {
     private static final String EXPECTED_EXCEPTION = "expected exception";
@@ -292,10 +292,12 @@ public class TestPdpGroupCreateOrUpdateProvider extends ProviderSuper {
         assertEquals(2, pdpUpdates.size());
 
         PdpUpdate pdpUpdate = pdpUpdates.get(0);
+        assertEquals(PapConstants.PAP_NAME, pdpUpdate.getSource());
         assertEquals(PDP2, pdpUpdate.getName());
         assertNull(pdpUpdate.getPdpGroup());
 
         pdpUpdate = pdpUpdates.get(1);
+        assertEquals(PapConstants.PAP_NAME, pdpUpdate.getSource());
         assertEquals(PDP4, pdpUpdate.getName());
         assertNull(pdpUpdate.getPdpGroup());
 
@@ -304,10 +306,12 @@ public class TestPdpGroupCreateOrUpdateProvider extends ProviderSuper {
         assertEquals(2, changes.size());
 
         PdpStateChange change = changes.get(0);
+        assertEquals(PapConstants.PAP_NAME, change.getSource());
         assertEquals(PDP2, change.getName());
         assertEquals(PdpState.PASSIVE, change.getState());
 
         change = changes.get(1);
+        assertEquals(PapConstants.PAP_NAME, change.getSource());
         assertEquals(PDP4, change.getName());
         assertEquals(PdpState.PASSIVE, change.getState());
     }
@@ -541,16 +545,6 @@ public class TestPdpGroupCreateOrUpdateProvider extends ProviderSuper {
         assertNoGroupAction();
     }
 
-    protected void assertUpdate(List<PdpUpdate> updates, String groupName, String pdpType, String pdpName) {
-
-        PdpUpdate update = updates.remove(0);
-
-        assertEquals(groupName, update.getPdpGroup());
-        assertEquals(pdpType, update.getPdpSubgroup());
-        assertEquals(pdpName, update.getName());
-        assertTrue(update.getPoliciesToBeDeployed().contains(policy1));
-    }
-
     private void assertNoGroupAction() throws Exception {
         verify(dao, never()).createPdpGroups(any());
         verify(dao, never()).updatePdpGroups(any());
index ce03264..49eec77 100644 (file)
@@ -49,6 +49,7 @@ import org.onap.policy.models.pdp.concepts.PdpUpdate;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
+import org.onap.policy.pap.main.PapConstants;
 import org.powermock.reflect.Whitebox;
 
 public class TestProviderBase extends ProviderSuper {
@@ -279,6 +280,7 @@ public class TestProviderBase extends ProviderSuper {
 
         PdpUpdate update = updates.remove(0);
 
+        assertEquals(PapConstants.PAP_NAME, update.getSource());
         assertEquals(groupName, update.getPdpGroup());
         assertEquals(pdpType, update.getPdpSubgroup());
         assertEquals(pdpName, update.getName());