Restructure for authorative models
[policy/models.git] / models-pdp / src / test / java / org / onap / policy / models / pdp / concepts / TestPdpGroup.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.Map;
30 import java.util.TreeMap;
31 import org.junit.Test;
32 import org.onap.policy.models.pdp.enums.PdpState;
33
34 /**
35  * Test the copy constructor, as {@link TestModels} tests the other methods.
36  */
37 public class TestPdpGroup {
38
39     @Test
40     public void testCopyConstructor() {
41         assertThatThrownBy(() -> new PdpGroup(null)).isInstanceOf(NullPointerException.class);
42
43         PdpGroup orig = new PdpGroup();
44
45         // verify with null values
46         assertEquals("PdpGroup(name=null, version=null, description=null, pdpGroupState=null, "
47                 + "properties=null, pdpSubgroups=[])", new PdpGroup(orig).toString());
48
49         // verify with all values
50         orig.setDescription("my-descript");
51         orig.setName("my-name");
52         orig.setVersion("my-version");
53         orig.setDescription("my-description");
54         orig.setPdpGroupState(PdpState.SAFE);
55
56         PdpSubGroup sub1 = new PdpSubGroup();
57         sub1.setCurrentInstanceCount(10);
58         PdpSubGroup sub2 = new PdpSubGroup();
59         sub2.setCurrentInstanceCount(11);
60         orig.setPdpSubgroups(Arrays.asList(sub1, sub2));
61
62         Map<String, String> props = new TreeMap<>();
63         props.put("key-A", "value-A");
64         props.put("key-B", "value-B");
65         orig.setProperties(props);
66
67         assertEquals("PdpGroup(name=my-name, version=my-version, description=my-description, "
68                 + "pdpGroupState=SAFE, properties={key-A=value-A, key-B=value-B}, "
69                 + "pdpSubgroups=[PdpSubGroup(pdpType=null, supportedPolicyTypes=[], policies=[], "
70                 + "currentInstanceCount=10, desiredInstanceCount=0, properties=null, pdpInstances=[]), "
71                 + "PdpSubGroup(pdpType=null, supportedPolicyTypes=[], policies=[], currentInstanceCount=11, "
72                 + "desiredInstanceCount=0, properties=null, pdpInstances=[])])", new PdpGroup(orig).toString());
73     }
74
75     @Test
76     public void testHashCode() {
77         PdpGroup group = new PdpGroup();
78         group.setDescription("A");
79         int hash = group.hashCode();
80
81         assertEquals(hash, group.hashCode());
82
83         group.setDescription("B");
84         assertTrue(hash != group.hashCode());
85     }
86 }