diff options
author | waynedunican <wayne.dunican@est.tech> | 2021-05-10 12:12:56 +0100 |
---|---|---|
committer | WayneDunican <wayne.dunican@est.tech> | 2021-05-27 19:26:28 +0100 |
commit | 42375e6c04f82821c7daff5a059c8974a7c89a10 (patch) | |
tree | 8dc0905f6d98c5a1f5745ff0c773e71e45680c60 /main | |
parent | 47c4b4bf0940aa56bbf43b1ff7edc018b538019e (diff) |
Update PAP to check for deployed policies only
Have PAP compare the returned list against the delta deployment list instead of comparing against the full list of policies as is the current behaviour. Any references to "get" or "set" policies methods have also been removed
Issue-ID: POLICY-3263
Change-Id: I0efe03e835db3c4b2136f7e742bba0e78dc2ac44
Signed-off-by: waynedunican <wayne.dunican@est.tech>
Signed-off-by: WayneDunican <wayne.dunican@est.tech>
Diffstat (limited to 'main')
14 files changed, 85 insertions, 83 deletions
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 76c47544..a2829572 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 @@ -93,7 +93,7 @@ public class PdpMessageGenerator { } protected PdpUpdate createPdpUpdateMessage(final String pdpGroupName, final PdpSubGroup subGroup, - final String pdpInstanceId, final List<ToscaPolicy> policies, + final String pdpInstanceId, final List<ToscaPolicy> policiesToBeDeployed, final List<ToscaConceptIdentifier> policiesToBeUndeployed) { @@ -102,7 +102,6 @@ public class PdpMessageGenerator { update.setName(pdpInstanceId); update.setPdpGroup(pdpGroupName); update.setPdpSubgroup(subGroup.getPdpType()); - update.setPolicies(policies); update.setPoliciesToBeDeployed(policiesToBeDeployed); update.setPoliciesToBeUndeployed(policiesToBeUndeployed); update.setPdpHeartbeatIntervalMs(heartBeatMs); diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java b/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java index 79889a79..1099a4dc 100644 --- a/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java +++ b/main/src/main/java/org/onap/policy/pap/main/comm/PdpStatusMessageHandler.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019-2020 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ @@ -325,12 +325,12 @@ public class PdpStatusMessageHandler extends PdpMessageGenerator { throws PfModelException { final List<ToscaPolicy> polsToBeDeployed = new LinkedList<>(policiesToBeDeployed.values()); final var pdpUpdatemessage = - createPdpUpdateMessage(pdpGroupName, subGroup, pdpInstanceId, policies, + createPdpUpdateMessage(pdpGroupName, subGroup, pdpInstanceId, polsToBeDeployed, policiesToBeUndeployed); final var pdpStateChangeMessage = createPdpStateChangeMessage(pdpGroupName, subGroup, pdpInstanceId, pdpState); updateDeploymentStatus(pdpGroupName, subGroup.getPdpType(), pdpInstanceId, pdpStateChangeMessage.getState(), - databaseProvider, pdpUpdatemessage.getPolicies()); + databaseProvider, pdpUpdatemessage.getPoliciesToBeDeployed()); requestMap.addRequest(pdpUpdatemessage, pdpStateChangeMessage); LOGGER.debug("Sent PdpUpdate message - {}", pdpUpdatemessage); diff --git a/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateReq.java b/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateReq.java index 18ae5af6..d0d1f5f0 100644 --- a/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateReq.java +++ b/main/src/main/java/org/onap/policy/pap/main/comm/msgdata/UpdateReq.java @@ -23,6 +23,7 @@ package org.onap.policy.pap.main.comm.msgdata; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -37,6 +38,8 @@ 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.ToscaPolicy; import org.onap.policy.pap.main.parameters.RequestParams; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** @@ -44,6 +47,8 @@ import org.onap.policy.pap.main.parameters.RequestParams; */ public class UpdateReq extends RequestImpl { + private static final Logger logger = LoggerFactory.getLogger(RequestImpl.class); + /** * Policies to be undeployed if the request fails. */ @@ -94,14 +99,19 @@ public class UpdateReq extends RequestImpl { } Set<ToscaConceptIdentifier> actualSet = new HashSet<>(alwaysList(response.getPolicies())); - Set<ToscaConceptIdentifier> expectedSet = new HashSet<>(alwaysList(message.getPolicies()).stream() + Set<ToscaConceptIdentifier> expectedSet = new HashSet<>(alwaysList(message.getPoliciesToBeDeployed()).stream() .map(ToscaPolicy::getIdentifier).collect(Collectors.toSet())); getNotifier().processResponse(response.getName(), message.getPdpGroup(), expectedSet, actualSet); - // see if the policies match + Set<ToscaConceptIdentifier> expectedUndeploySet = + new HashSet<>(alwaysList(message.getPoliciesToBeUndeployed())); + + if (actualSet.stream().anyMatch(expectedUndeploySet::contains)) { + logger.info("some policies have failed to undeploy"); + } - if (!actualSet.equals(expectedSet)) { + if (!actualSet.containsAll(expectedSet)) { // need to undeploy the policies that are expected, but missing from the // response undeployPolicies = expectedSet; @@ -130,9 +140,6 @@ public class UpdateReq extends RequestImpl { Map<ToscaConceptIdentifier, ToscaPolicy> newDeployMap = update.getPoliciesToBeDeployed().stream() .collect(Collectors.toMap(ToscaPolicy::getIdentifier, policy -> policy)); - // Merge full lists - final List<ToscaPolicy> fullPolicies = update.getPolicies(); - // Merge undpeloy lists Set<ToscaConceptIdentifier> policiesToBeUndeployedSet = new HashSet<>(getMessage().getPoliciesToBeUndeployed()); policiesToBeUndeployedSet.removeAll(newDeployMap.keySet()); @@ -140,19 +147,13 @@ public class UpdateReq extends RequestImpl { final List<ToscaConceptIdentifier> policiestoBeUndeployed = new LinkedList<>(policiesToBeUndeployedSet); // Merge deploy lists - final List<ToscaPolicy> policiesToBeDeployed; - if (update.getPoliciesToBeDeployed() == update.getPolicies()) { - policiesToBeDeployed = update.getPoliciesToBeDeployed(); - } else { - Map<ToscaConceptIdentifier, ToscaPolicy> policiesToBeDeployedMap = getMessage().getPoliciesToBeDeployed() - .stream().collect(Collectors.toMap(ToscaPolicy::getIdentifier, policy -> policy)); - policiesToBeDeployedMap.keySet().removeAll(update.getPoliciesToBeUndeployed()); - policiesToBeDeployedMap.putAll(newDeployMap); - policiesToBeDeployed = new LinkedList<>(policiesToBeDeployedMap.values()); - } + Map<ToscaConceptIdentifier, ToscaPolicy> policiesToBeDeployedMap = getMessage().getPoliciesToBeDeployed() + .stream().collect(Collectors.toMap(ToscaPolicy::getIdentifier, policy -> policy)); + policiesToBeDeployedMap.keySet().removeAll(update.getPoliciesToBeUndeployed()); + policiesToBeDeployedMap.putAll(newDeployMap); + final List<ToscaPolicy> policiesToBeDeployed = new LinkedList<>(policiesToBeDeployedMap.values()); // Set lists in update - update.setPolicies(fullPolicies); update.setPoliciesToBeDeployed(policiesToBeDeployed); update.setPoliciesToBeUndeployed(policiestoBeUndeployed); @@ -172,24 +173,15 @@ public class UpdateReq extends RequestImpl { } // see if the policies are the same - Set<ToscaPolicy> set1 = new HashSet<>(alwaysList(first.getPolicies())); - Set<ToscaPolicy> set2 = new HashSet<>(alwaysList(second.getPolicies())); + Set<ToscaPolicy> set1 = new HashSet<>(alwaysList(first.getPoliciesToBeDeployed())); + Set<ToscaPolicy> set2 = new HashSet<>(alwaysList(second.getPoliciesToBeDeployed())); if (!(set1.equals(set2))) { return false; } - Map<ToscaConceptIdentifier, ToscaPolicy> dep1 = first.getPolicies().stream() - .collect(Collectors.toMap(ToscaPolicy::getIdentifier, p -> p)); - Map<ToscaConceptIdentifier, ToscaPolicy> dep2 = second.getPoliciesToBeDeployed() - .stream().collect(Collectors.toMap(ToscaPolicy::getIdentifier, p -> p)); - - if (!(dep1.equals(dep2))) { - return false; - } - - HashSet<ToscaConceptIdentifier> undep1 = new HashSet<>(alwaysList(first.getPoliciesToBeUndeployed())); - HashSet<ToscaConceptIdentifier> undep2 = new HashSet<>(alwaysList(second.getPoliciesToBeUndeployed())); + Set<ToscaConceptIdentifier> undep1 = new HashSet<>(alwaysList(first.getPoliciesToBeUndeployed())); + Set<ToscaConceptIdentifier> undep2 = new HashSet<>(alwaysList(second.getPoliciesToBeUndeployed())); return undep1.equals(undep2); } diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java index f0de7f9a..c8f67d75 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupStateChangeProvider.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2021 Nordix Foundation. * Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ @@ -121,11 +121,11 @@ public class PdpGroupStateChangeProvider extends PdpMessageGenerator { String pdpInstanceId = pdp.getInstanceId(); final var pdpUpdatemessage = createPdpUpdateMessage(pdpGroup.getName(), subGroup, pdp.getInstanceId(), - policies, policies, null); + policies, null); final var pdpStateChangeMessage = createPdpStateChangeMessage(pdpGroupName, subGroup, pdpInstanceId, pdpState); updateDeploymentStatus(pdpGroupName, subGroup.getPdpType(), pdpInstanceId, - pdpStateChangeMessage.getState(), databaseProvider, pdpUpdatemessage.getPolicies()); + pdpStateChangeMessage.getState(), databaseProvider, pdpUpdatemessage.getPoliciesToBeDeployed()); requestMap.addRequest(pdpUpdatemessage, pdpStateChangeMessage); LOGGER.debug("Sent PdpUpdate message - {}", pdpUpdatemessage); LOGGER.debug("Sent PdpStateChange message - {}", pdpStateChangeMessage); 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 6aefce01..a21c2a15 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 @@ -233,8 +233,6 @@ public abstract class ProviderBase { update.setDescription(group.getDescription()); update.setPdpGroup(group.getName()); update.setPdpSubgroup(subgroup.getPdpType()); - update.setPolicies(subgroup.getPolicies().stream().map(ToscaConceptIdentifierOptVersion::new) - .map(ident -> getPolicy(data, ident)).collect(Collectors.toList())); update.setPoliciesToBeDeployed(data.getPoliciesToBeDeployed()); update.setPoliciesToBeUndeployed(data.getPoliciesToBeUndeployed()); diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java b/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java index 923871eb..235c852e 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java @@ -220,7 +220,7 @@ public class SessionData { } logger.info("add update and state-change {} {} {} policies={}", update.getName(), update.getPdpGroup(), - update.getPdpSubgroup(), update.getPolicies().size()); + update.getPdpSubgroup(), update.getPoliciesToBeDeployed().size()); pdpRequests.put(update.getName(), Pair.of(update, change)); } @@ -231,7 +231,7 @@ public class SessionData { */ public void addUpdate(PdpUpdate update) { logger.info("add update {} {} {} policies={}", update.getName(), update.getPdpGroup(), update.getPdpSubgroup(), - update.getPolicies().size()); + update.getPoliciesToBeDeployed().size()); pdpRequests.compute(update.getName(), (name, data) -> Pair.of(update, (data == null ? null : data.getRight()))); } diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/CommonRequestBase.java b/main/src/test/java/org/onap/policy/pap/main/comm/CommonRequestBase.java index 47d1de5f..45c278c5 100644 --- a/main/src/test/java/org/onap/policy/pap/main/comm/CommonRequestBase.java +++ b/main/src/test/java/org/onap/policy/pap/main/comm/CommonRequestBase.java @@ -3,6 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -205,7 +206,8 @@ public class CommonRequestBase { PdpUpdate message = new PdpUpdate(); message.setName(pdpName); - message.setPolicies(Collections.emptyList()); + message.setPoliciesToBeDeployed(Collections.emptyList()); + message.setPoliciesToBeUndeployed(Collections.emptyList()); message.setPdpGroup(group); message.setPdpSubgroup(subgroup); diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java index 0ceef772..31d4af46 100644 --- a/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/comm/PdpHeartbeatListenerTest.java @@ -225,8 +225,7 @@ public class PdpHeartbeatListenerTest extends End2EndBase { PdpStatusMessageHandler handler = new PdpStatusMessageHandler(params); PdpUpdate update10 = handler.createPdpUpdateMessage( status3.getPdpGroup(), new PdpSubGroup(), "pdp_2", - policies, policies, polsUndep); - assertSame(update10.getPolicies(), policies); + policies, polsUndep); assertSame(update10.getPoliciesToBeDeployed(), policies); assertSame(update10.getPoliciesToBeUndeployed(), polsUndep); assertThat(update10.getPoliciesToBeDeployed()).isInstanceOf(List.class); diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java index 6a0800f1..df036d25 100644 --- a/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/comm/PdpModifyRequestMapTest.java @@ -585,7 +585,7 @@ public class PdpModifyRequestMapTest extends CommonRequestBase { when(policy.getIdentifier()).thenReturn(ident); // add some policies to the update - update.setPolicies(Arrays.asList(policy)); + update.setPoliciesToBeDeployed(Arrays.asList(policy)); map.addRequest(update); @@ -597,7 +597,8 @@ public class PdpModifyRequestMapTest extends CommonRequestBase { doAnswer(ans -> { PdpUpdate update2 = new PdpUpdate(update); - update2.setPolicies(Collections.emptyList()); + update2.setPoliciesToBeDeployed(Collections.emptyList()); + update2.setPoliciesToBeUndeployed(Arrays.asList(policy.getIdentifier())); assertTrue(req.reconfigure(update2)); throw makeException(); }).when(undeployer).undeploy(any(), any(), any()); @@ -630,7 +631,7 @@ public class PdpModifyRequestMapTest extends CommonRequestBase { when(policy.getIdentifier()).thenReturn(ident); // add some policies to the update - update.setPolicies(Arrays.asList(policy)); + update.setPoliciesToBeDeployed(Arrays.asList(policy)); map.addRequest(update); diff --git a/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/UpdateReqTest.java b/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/UpdateReqTest.java index 02f47287..306418c4 100644 --- a/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/UpdateReqTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/comm/msgdata/UpdateReqTest.java @@ -3,6 +3,7 @@ * ONAP PAP * ================================================================================ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2021 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,7 +72,8 @@ public class UpdateReqTest extends CommonRequestBase { response.setPdpGroup(update.getPdpGroup()); response.setPdpSubgroup(update.getPdpSubgroup()); response.setPolicies( - update.getPolicies().stream().map(ToscaPolicy::getIdentifier).collect(Collectors.toList())); + update.getPoliciesToBeDeployed().stream().map(ToscaPolicy::getIdentifier) + .collect(Collectors.toList())); data = new UpdateReq(reqParams, MY_REQ_NAME, update); data.setNotifier(notifier); @@ -90,7 +92,7 @@ public class UpdateReqTest extends CommonRequestBase { verifyResponse(); // both policy lists null - update.setPolicies(null); + update.setPoliciesToBeDeployed(null); response.setPolicies(null); assertNull(data.checkResponse(response)); assertTrue(data.getUndeployPolicies().isEmpty()); @@ -147,7 +149,7 @@ public class UpdateReqTest extends CommonRequestBase { @Test public void testUpdateReqCheckResponse_MismatchedPolicies() { - ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPolicies()); + ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPoliciesToBeDeployed()); policies.set(0, makePolicy(DIFFERENT, "10.0.0")); response.setPolicies(policies.stream().map(ToscaPolicy::getIdentifier).collect(Collectors.toList())); @@ -156,15 +158,15 @@ public class UpdateReqTest extends CommonRequestBase { verifyResponse(); // the first policy from the original update is all that should be undeployed - assertEquals(Collections.singleton(update.getPolicies().get(0).getIdentifier()).toString(), + assertEquals(Collections.singleton(update.getPoliciesToBeDeployed().get(0).getIdentifier()).toString(), data.getUndeployPolicies().toString()); } @Test public void testUpdateReqCheckResponse_MismatchedPolicies_Null_NotNull() { - update.setPolicies(null); + update.setPoliciesToBeDeployed(null); - assertEquals("policies do not match", data.checkResponse(response)); + assertEquals(null, data.checkResponse(response)); assertTrue(data.getUndeployPolicies().isEmpty()); verifyResponse(); } @@ -177,7 +179,8 @@ public class UpdateReqTest extends CommonRequestBase { verifyResponse(); // all policies in the update should be undeployed - assertEquals(update.getPolicies().stream().map(ToscaPolicy::getIdentifier).collect(Collectors.toList()) + assertEquals(update.getPoliciesToBeDeployed().stream().map(ToscaPolicy::getIdentifier) + .collect(Collectors.toList()) .toString(), new TreeSet<>(data.getUndeployPolicies()).toString()); } @@ -201,23 +204,22 @@ public class UpdateReqTest extends CommonRequestBase { @Test public void testReconfigureIsFullSameAsDeployList() { PdpUpdate msg2 = new PdpUpdate(update); - ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPolicies()); + ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPoliciesToBeDeployed()); - msg2.setPolicies(policies); msg2.setPoliciesToBeDeployed(policies); assertTrue(data.reconfigure(msg2)); - assertThat(data.getMessage().getPolicies()).containsAll(msg2.getPolicies()); + assertThat(data.getMessage().getPoliciesToBeDeployed()).containsAll(msg2.getPoliciesToBeDeployed()); } @Test public void testListsNewVsResult() { PdpUpdate msg2 = new PdpUpdate(update); - ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPolicies()); + ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPoliciesToBeDeployed()); // some items in both deploy and newMessage.deploy msg2.setPoliciesToBeDeployed(policies); policies.remove(0); - data.getMessage().setPolicies(policies); + data.getMessage().setPoliciesToBeDeployed(policies); assertTrue(data.reconfigure(msg2)); assertThat(data.getMessage().getPoliciesToBeDeployed()).containsAll(msg2.getPoliciesToBeDeployed()); @@ -228,7 +230,7 @@ public class UpdateReqTest extends CommonRequestBase { data.getMessage().setPoliciesToBeDeployed(policies); policies.clear(); - policies = new ArrayList<>(update.getPolicies()); + policies = new ArrayList<>(update.getPoliciesToBeDeployed()); List<ToscaConceptIdentifier> polsToUndep = policies.parallelStream() .map(ToscaPolicy::getIdentifier) .collect(Collectors.toList()); @@ -236,10 +238,8 @@ public class UpdateReqTest extends CommonRequestBase { assertTrue(data.reconfigure(msg2)); - assertThat(data.getMessage().getPoliciesToBeDeployed()).isEmpty(); - // some items only in deploy - policies = new ArrayList<>(update.getPolicies()); + policies = new ArrayList<>(update.getPoliciesToBeDeployed()); msg2.setPoliciesToBeDeployed(policies); data.getMessage().setPoliciesToBeDeployed(new LinkedList<>()); assertTrue(data.reconfigure(msg2)); @@ -249,13 +249,13 @@ public class UpdateReqTest extends CommonRequestBase { List<ToscaConceptIdentifier> pols = policies.stream().map(ToscaPolicy::getIdentifier) .collect(Collectors.toList()); msg2.setPoliciesToBeUndeployed(pols); - pols.remove(0); + pols.add(makePolicy("policy-zz-1", "1.1.0").getIdentifier()); data.getMessage().setPoliciesToBeUndeployed(pols); assertTrue(data.reconfigure(msg2)); assertThat(data.getMessage().getPoliciesToBeUndeployed()).containsAll(msg2.getPoliciesToBeUndeployed()); // some items in both undeploy and newMessage.deploy - policies = new ArrayList<>(update.getPolicies()); + policies = new ArrayList<>(update.getPoliciesToBeDeployed()); List<ToscaConceptIdentifier> polsToUndep2 = policies.parallelStream() .map(ToscaPolicy::getIdentifier) .collect(Collectors.toList()); @@ -290,12 +290,16 @@ public class UpdateReqTest extends CommonRequestBase { PdpUpdate msg2 = new PdpUpdate(update); msg2.setName("world"); - assertFalse(data.isSameContent(msg2)); + update.setPoliciesToBeDeployed(null); + List<ToscaPolicy> polsToDep2 = new LinkedList<>(); + polsToDep2.add(makePolicy("policy-m-1", "1.0.0")); + polsToDep2.add(makePolicy("policy-n-1", "1.0.0")); + msg2.setPoliciesToBeDeployed(polsToDep2); + assertThat(data.isSameContent(msg2)).isFalse(); // both policy lists null - update.setPolicies(null); - msg2.setPolicies(null); - assertEquals(data.getMessage().getPolicies(), msg2.getPolicies()); + msg2.setPoliciesToBeDeployed(null); + assertEquals(data.getMessage().getPoliciesToBeDeployed(), msg2.getPoliciesToBeDeployed()); } @Test @@ -344,9 +348,9 @@ public class UpdateReqTest extends CommonRequestBase { public void testIsSameContent_DiffPolicies() { PdpUpdate msg2 = new PdpUpdate(update); - ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPolicies()); + ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPoliciesToBeDeployed()); policies.set(0, makePolicy(DIFFERENT, "10.0.0")); - msg2.setPolicies(policies); + msg2.setPoliciesToBeDeployed(policies); assertFalse(data.isSameContent(msg2)); } @@ -354,18 +358,22 @@ public class UpdateReqTest extends CommonRequestBase { @Test public void testIsSameContent_DiffPolicies_NotNull_Null() { PdpUpdate msg2 = new PdpUpdate(update); - msg2.setPolicies(null); + msg2.setPoliciesToBeDeployed(null); assertFalse(data.isSameContent(msg2)); } @Test public void testIsSameContent_DiffPolicies_Null_NotNull() { - PdpUpdate msg2 = new PdpUpdate(update); + final PdpUpdate msg2 = new PdpUpdate(update); - update.setPolicies(null); + update.setPoliciesToBeDeployed(null); + List<ToscaPolicy> polsToDep2 = new LinkedList<>(); + polsToDep2.add(makePolicy("policy-m-1", "1.0.0")); + polsToDep2.add(makePolicy("policy-n-1", "1.0.0")); + msg2.setPoliciesToBeDeployed(polsToDep2); - assertFalse(data.isSameContent(msg2)); + assertThat(data.isSameContent(msg2)).isFalse(); } @SuppressWarnings("unchecked") @@ -394,7 +402,8 @@ public class UpdateReqTest extends CommonRequestBase { ToscaPolicy policy1 = makePolicy("policy-1-a", "1.0.0"); ToscaPolicy policy2 = makePolicy("policy-2-a", "1.1.0"); - upd.setPolicies(Arrays.asList(policy1, policy2)); + upd.setPoliciesToBeDeployed(Arrays.asList(policy1, policy2)); + upd.setPoliciesToBeUndeployed(Collections.emptyList()); return upd; } 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 64534530..1ea13119 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 @@ -548,7 +548,7 @@ public class TestPdpGroupCreateOrUpdateProvider extends ProviderSuper { assertEquals(groupName, update.getPdpGroup()); assertEquals(pdpType, update.getPdpSubgroup()); assertEquals(pdpName, update.getName()); - assertTrue(update.getPolicies().contains(policy1)); + assertTrue(update.getPoliciesToBeDeployed().contains(policy1)); } private void assertNoGroupAction() throws Exception { diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteProvider.java index fc71c62c..30b5b16f 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteProvider.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteProvider.java @@ -194,7 +194,7 @@ public class TestPdpGroupDeleteProvider extends ProviderSuper { assertEquals("pdpA", req.getName()); assertEquals(GROUP1_NAME, req.getPdpGroup()); assertEquals("pdpTypeA", req.getPdpSubgroup()); - assertEquals(Arrays.asList(policy1, policy1), req.getPolicies()); + assertEquals(Arrays.asList(policy1.getIdentifier()), req.getPoliciesToBeUndeployed()); } @Test diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployProvider.java index 575dfefc..8d7ec96c 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployProvider.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployProvider.java @@ -21,6 +21,7 @@ package org.onap.policy.pap.main.rest; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.Assert.assertEquals; @@ -646,7 +647,7 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { assertEquals(groupName, update.getPdpGroup()); assertEquals(pdpType, update.getPdpSubgroup()); assertEquals(pdpName, update.getName()); - assertTrue(update.getPolicies().contains(policy1)); + assertThat(update.getPoliciesToBeDeployed()).contains(policy1); } private void assertNoGroupAction() throws Exception { @@ -670,10 +671,11 @@ public class TestPdpGroupDeployProvider extends ProviderSuper { assertEquals(subgrp.getPdpType(), pdpUpdate.getPdpSubgroup()); List<ToscaConceptIdentifier> pdpPolicies = - pdpUpdate.getPolicies().stream().map(ToscaPolicy::getIdentifier).collect(Collectors.toList()); + pdpUpdate.getPoliciesToBeDeployed().stream().map(ToscaPolicy::getIdentifier) + .collect(Collectors.toList()); Collections.sort(pdpPolicies); - assertEquals(subgrp.getPolicies().toString(), pdpPolicies.toString()); + assertThat(subgrp.getPolicies()).containsAll(pdpPolicies); List<PdpGroup> updates = getGroupUpdates(); assertEquals(Arrays.asList(group), updates); 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 2bf4f3df..ce032647 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 @@ -282,7 +282,7 @@ public class TestProviderBase extends ProviderSuper { assertEquals(groupName, update.getPdpGroup()); assertEquals(pdpType, update.getPdpSubgroup()); assertEquals(pdpName, update.getName()); - assertTrue(update.getPolicies().contains(policy1)); + assertTrue(update.getPoliciesToBeDeployed().contains(policy1)); } /** |