2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.models.pdp.concepts;
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;
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;
34 public class DeploymentGroupsTest {
37 public void testValidatePapRest_toMapList() {
38 DeploymentGroup group1 = new DeploymentGroup();
39 group1.setName("group-1");
41 DeploymentSubGroup subgrp = new DeploymentSubGroup();
42 subgrp.setPdpType("pdp-type");
43 subgrp.setAction(Action.DELETE);
44 subgrp.setPolicies(Collections.emptyList());
46 group1.setDeploymentSubgroups(Arrays.asList(subgrp));
48 DeploymentGroup group2 = new DeploymentGroup();
49 group2.setName("group-2");
50 group2.setDeploymentSubgroups(Arrays.asList(subgrp));
52 DeploymentGroups groups = new DeploymentGroups();
53 groups.setGroups(Arrays.asList(group1, group2));
56 ValidationResult result = groups.validatePapRest();
57 assertNotNull(result);
58 assertNull(result.getResult());
59 assertTrue(result.isValid());
62 groups = new DeploymentGroups();
63 groups.setGroups(null);
64 assertInvalid(groups);
67 groups = new DeploymentGroups();
68 groups.setGroups(Arrays.asList(group1, null));
69 assertInvalid(groups);
72 DeploymentGroup groupX = new DeploymentGroup(group1);
74 groups.setGroups(Arrays.asList(group1, groupX));
75 assertInvalid(groups);
78 groups = new DeploymentGroups();
79 groups.setGroups(Arrays.asList(group1, group2, group1));
80 assertInvalid(groups);
83 private void assertInvalid(DeploymentGroups groups) {
84 ValidationResult result = groups.validatePapRest();
85 assertNotNull(result);
86 assertFalse(result.isValid());
87 assertNotNull(result.getResult());