summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/PapConstants.java5
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java2
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java3
-rw-r--r--main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java1
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/PapConstantsTest.java9
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateProvider.java16
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestProviderBase.java2
7 files changed, 22 insertions, 16 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/PapConstants.java b/main/src/main/java/org/onap/policy/pap/main/PapConstants.java
index b51e85cc..7d4cb7b4 100644
--- a/main/src/main/java/org/onap/policy/pap/main/PapConstants.java
+++ b/main/src/main/java/org/onap/policy/pap/main/PapConstants.java
@@ -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();
}
diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java
index a2829572..8dad7ac4 100644
--- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java
+++ b/main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java
@@ -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());
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java
index 8be787a0..696cc8c0 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupCreateOrUpdateProvider.java
@@ -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);
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java b/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java
index 6fa0ef3d..4cc5a44e 100644
--- a/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java
+++ b/main/src/main/java/org/onap/policy/pap/main/rest/ProviderBase.java
@@ -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());
diff --git a/main/src/test/java/org/onap/policy/pap/main/PapConstantsTest.java b/main/src/test/java/org/onap/policy/pap/main/PapConstantsTest.java
index 4733f91e..6d5d303a 100644
--- a/main/src/test/java/org/onap/policy/pap/main/PapConstantsTest.java
+++ b/main/src/test/java/org/onap/policy/pap/main/PapConstantsTest.java
@@ -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");
@@ -21,15 +21,14 @@
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");
}
}
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateProvider.java
index 1ea13119..f64a77b3 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateProvider.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateProvider.java
@@ -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());
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestProviderBase.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestProviderBase.java
index ce032647..49eec772 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestProviderBase.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestProviderBase.java
@@ -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());