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.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertSame;
28 import static org.junit.Assert.assertTrue;
30 import java.util.Arrays;
31 import java.util.Collections;
32 import java.util.Iterator;
33 import java.util.List;
35 import org.junit.Test;
36 import org.onap.policy.common.parameters.ValidationResult;
38 public class PdpGroupsTest {
41 public void testValidatePapRest_toMapList() {
42 PdpGroup group1 = new PdpGroup();
43 group1.setName("group-1");
44 group1.setPdpSubgroups(Collections.emptyList());
46 PdpGroup group2 = new PdpGroup();
47 group2.setName("group-2");
48 group2.setPdpSubgroups(Collections.emptyList());
50 PdpGroups groups = new PdpGroups();
51 groups.setGroups(Arrays.asList(group1, group2));
54 ValidationResult result = groups.validatePapRest();
55 assertNotNull(result);
56 assertTrue(result.isValid());
57 assertNull(result.getResult());
60 List<Map<String, PdpGroup>> lst = groups.toMapList();
61 assertEquals(1, lst.size());
63 Map<String, PdpGroup> map = lst.get(0);
64 assertEquals(2, map.size());
66 Iterator<PdpGroup> iter = map.values().iterator();
67 assertSame(group1, iter.next());
68 assertSame(group2, iter.next());
71 groups = new PdpGroups();
72 groups.setGroups(null);
73 assertInvalid(groups);
76 groups = new PdpGroups();
77 groups.setGroups(Arrays.asList(group1, null));
78 assertInvalid(groups);
81 PdpGroup groupX = new PdpGroup(group1);
83 groups.setGroups(Arrays.asList(group1, groupX));
84 assertInvalid(groups);
87 private void assertInvalid(PdpGroups groups) {
88 ValidationResult result = groups.validatePapRest();
89 assertNotNull(result);
90 assertFalse(result.isValid());
91 assertNotNull(result.getResult());