Set all cross references of policy/models
[policy/models.git] / models-pdp / src / test / java / org / onap / policy / models / pdp / concepts / DeploymentGroupsTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Models
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.models.pdp.concepts;
22
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertTrue;
27
28 import java.util.Arrays;
29 import java.util.Collections;
30 import org.junit.Test;
31 import org.onap.policy.common.parameters.ValidationResult;
32 import org.onap.policy.models.pdp.concepts.DeploymentSubGroup.Action;
33
34 public class DeploymentGroupsTest {
35
36     @Test
37     public void testValidatePapRest_toMapList() {
38         DeploymentGroup group1 = new DeploymentGroup();
39         group1.setName("group-1");
40
41         DeploymentSubGroup subgrp = new DeploymentSubGroup();
42         subgrp.setPdpType("pdp-type");
43         subgrp.setAction(Action.DELETE);
44         subgrp.setPolicies(Collections.emptyList());
45
46         group1.setDeploymentSubgroups(Arrays.asList(subgrp));
47
48         DeploymentGroup group2 = new DeploymentGroup();
49         group2.setName("group-2");
50         group2.setDeploymentSubgroups(Arrays.asList(subgrp));
51
52         DeploymentGroups groups = new DeploymentGroups();
53         groups.setGroups(Arrays.asList(group1, group2));
54
55         // valid
56         ValidationResult result = groups.validatePapRest();
57         assertNotNull(result);
58         assertNull(result.getResult());
59         assertTrue(result.isValid());
60
61         // null group list
62         groups = new DeploymentGroups();
63         groups.setGroups(null);
64         assertInvalid(groups);
65
66         // null group
67         groups = new DeploymentGroups();
68         groups.setGroups(Arrays.asList(group1, null));
69         assertInvalid(groups);
70
71         // invalid group
72         DeploymentGroup groupX = new DeploymentGroup(group1);
73         groupX.setName(null);
74         groups.setGroups(Arrays.asList(group1, groupX));
75         assertInvalid(groups);
76
77         // duplicate groups
78         groups = new DeploymentGroups();
79         groups.setGroups(Arrays.asList(group1, group2, group1));
80         assertInvalid(groups);
81     }
82
83     private void assertInvalid(DeploymentGroups groups) {
84         ValidationResult result = groups.validatePapRest();
85         assertNotNull(result);
86         assertFalse(result.isValid());
87         assertNotNull(result.getResult());
88     }
89 }