2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019-2021 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.pdp.concepts;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotSame;
27 import static org.onap.policy.models.pdp.concepts.PdpMessageUtils.removeVariableFields;
29 import java.util.Arrays;
30 import java.util.List;
31 import java.util.stream.Collectors;
32 import org.junit.Test;
33 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
36 * Test the copy constructor, as {@link ModelsTest} tests the other methods.
38 public class PdpUpdateTest {
41 public void testCopyConstructor() {
42 assertThatThrownBy(() -> new PdpUpdate(null)).isInstanceOf(NullPointerException.class);
44 PdpUpdate orig = new PdpUpdate();
45 orig.setPoliciesToBeDeployed(null);
46 orig.setPoliciesToBeUndeployed(null);
48 // verify with null values
49 assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpUpdate(orig).toString()));
51 // verify with all values
52 orig.setDescription("my-description");
53 orig.setName("my-name");
54 orig.setPdpGroup("my-group");
55 orig.setPdpSubgroup("my-subgroup");
56 orig.setPdpHeartbeatIntervalMs(30000L);
58 ToscaPolicy policy1 = new ToscaPolicy();
59 policy1.setName("policy-a");
60 policy1.setVersion("1.2.3");
62 ToscaPolicy policy2 = new ToscaPolicy();
63 policy2.setName("policy-b");
64 policy2.setVersion("4.5.6");
66 List<ToscaPolicy> policies = Arrays.asList(policy1, policy2);
67 orig.setPoliciesToBeDeployed(policies);
68 orig.setPoliciesToBeUndeployed(policies.stream().map(ToscaPolicy::getIdentifier).collect(Collectors.toList()));
70 PdpUpdate other = new PdpUpdate(orig);
72 assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
74 // ensure list and items are not the same object
75 assertNotSame(other.getPoliciesToBeDeployed(), policies);
76 assertNotSame(other.getPoliciesToBeDeployed().get(0), policies.get(0));
77 assertNotSame(other.getPoliciesToBeUndeployed(), policies);
78 assertNotSame(other.getPoliciesToBeUndeployed().get(0), policies.get(0));