2dfcb30feca88f02bf7cb5335007e4b1a13b9de0
[policy/models.git] / models-pdp / src / test / java / org / onap / policy / models / pdp / concepts / PdpUpdateTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Models
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21
22 package org.onap.policy.models.pdp.concepts;
23
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertTrue;
27 import static org.onap.policy.models.pdp.concepts.PdpMessageUtils.removeVariableFields;
28
29 import java.util.Arrays;
30 import java.util.List;
31 import org.junit.Test;
32 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
33
34 /**
35  * Test the copy constructor, as {@link ModelsTest} tests the other methods.
36  */
37 public class PdpUpdateTest {
38
39     @Test
40     public void testCopyConstructor() {
41         assertThatThrownBy(() -> new PdpUpdate(null)).isInstanceOf(NullPointerException.class);
42
43         PdpUpdate orig = new PdpUpdate();
44         orig.setPolicies(null);
45
46         // verify with null values
47         assertEquals(removeVariableFields(orig.toString()), removeVariableFields(new PdpUpdate(orig).toString()));
48
49         // verify with all values
50         orig.setDescription("my-description");
51         orig.setName("my-name");
52         orig.setPdpGroup("my-group");
53         orig.setPdpSubgroup("my-subgroup");
54         orig.setPdpHeartbeatIntervalMs(30000L);
55
56         ToscaPolicy policy1 = new ToscaPolicy();
57         policy1.setName("policy-a");
58         policy1.setVersion("1.2.3");
59
60         ToscaPolicy policy2 = new ToscaPolicy();
61         policy2.setName("policy-b");
62         policy2.setVersion("4.5.6");
63
64         List<ToscaPolicy> policies = Arrays.asList(policy1, policy2);
65         orig.setPolicies(policies);
66
67         PdpUpdate other = new PdpUpdate(orig);
68
69         assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
70
71         // ensure list and items are not the same object
72         assertTrue(other.getPolicies() != policies);
73         assertTrue(other.getPolicies().get(0) != policies.get(0));
74     }
75 }