5f8819b48618bd7faedbe084e45378012bce0a40
[policy/models.git] / models-pdp / src / test / java / org / onap / policy / models / pdp / concepts / TestPdpUpdate.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
28 import java.util.Arrays;
29 import java.util.List;
30 import org.junit.Test;
31 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
32
33 /**
34  * Test the copy constructor, as {@link TestModels} tests the other methods.
35  */
36 public class TestPdpUpdate {
37
38     @Test
39     public void testCopyConstructor() {
40         assertThatThrownBy(() -> new PdpUpdate(null)).isInstanceOf(NullPointerException.class);
41
42         PdpUpdate orig = new PdpUpdate();
43
44         // verify with null values
45         assertEquals("PdpUpdate(name=null, pdpType=null, description=null, pdpGroup=null, "
46                         + "pdpSubgroup=null, policies=null)", new PdpUpdate(orig).toString());
47
48         // verify with all values
49         orig.setDescription("my-description");
50         orig.setName("my-name");
51         orig.setPdpGroup("my-group");
52         orig.setPdpSubgroup("my-subgroup");
53         orig.setPdpType("my-type");
54
55         ToscaPolicy policy1 = new ToscaPolicy();
56         policy1.setName("policy-a");
57         policy1.setVersion("1.2.3");
58
59         ToscaPolicy policy2 = new ToscaPolicy();
60         policy2.setName("policy-b");
61         policy2.setVersion("4.5.6");
62
63         List<ToscaPolicy> policies = Arrays.asList(policy1, policy2);
64         orig.setPolicies(policies);
65
66         PdpUpdate other = new PdpUpdate(orig);
67
68         assertEquals("PdpUpdate(name=my-name, pdpType=my-type, description=my-description, "
69                         + "pdpGroup=my-group, pdpSubgroup=my-subgroup, policies=["
70                         + "ToscaPolicy(super=ToscaEntity(name=policy-a, version=1.2.3, derivedFrom=null, "
71                         + "metadata=null, description=null), type=null, typeVersion=null, properties=null), "
72                         + "ToscaPolicy(super=ToscaEntity(name=policy-b, version=4.5.6, derivedFrom=null, "
73                         + "metadata=null, description=null), type=null, typeVersion=null, properties=null)])",
74                         other.toString());
75
76         // ensure list and items are not the same object
77         assertTrue(other.getPolicies() != policies);
78         assertTrue(other.getPolicies().get(0) != policies.get(0));
79     }
80 }