2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ===================================================================
24 package org.onap.clamp.policy.pdpgroup;
26 import static org.assertj.core.api.Assertions.assertThat;
28 import com.google.gson.JsonArray;
29 import com.google.gson.JsonObject;
31 import java.io.IOException;
32 import java.util.LinkedList;
33 import java.util.List;
35 import org.junit.Test;
37 public class PdpGroupTest {
41 public void testGetSupportedSubgroups() throws IOException {
42 PdpGroup pdpGroup1 = new PdpGroup();
43 pdpGroup1.setName("pdpGroup1");
44 pdpGroup1.setPdpGroupState("INACTIVE");
45 assertThat(pdpGroup1.getSupportedSubgroups("test", "1.0.0")).isNull();
47 PdpGroup pdpGroup2 = new PdpGroup();
48 pdpGroup2.setName("pdpGroup2");
49 pdpGroup2.setPdpGroupState("ACTIVE");
51 PolicyModelKey type1 = new PolicyModelKey("type1", "1.0.0");
52 PolicyModelKey type2 = new PolicyModelKey("type2", "2.0.0");
54 PdpSubgroup pdpSubgroup1 = new PdpSubgroup();
55 pdpSubgroup1.setPdpType("subGroup1");
56 List<PolicyModelKey> pdpTypeList = new LinkedList<PolicyModelKey>();
57 pdpTypeList.add(type1);
58 pdpTypeList.add(type2);
59 pdpSubgroup1.setSupportedPolicyTypes(pdpTypeList);
61 PolicyModelKey type3 = new PolicyModelKey("type3", "1.0.0");
62 PdpSubgroup pdpSubgroup2 = new PdpSubgroup();
63 pdpSubgroup2.setPdpType("subGroup2");
64 List<PolicyModelKey> pdpTypeList2 = new LinkedList<PolicyModelKey>();
65 pdpTypeList2.add(type2);
66 pdpTypeList2.add(type3);
67 pdpSubgroup2.setSupportedPolicyTypes(pdpTypeList2);
69 List<PdpSubgroup> pdpSubgroupList = new LinkedList<PdpSubgroup>();
70 pdpSubgroupList.add(pdpSubgroup1);
71 pdpSubgroupList.add(pdpSubgroup2);
72 pdpGroup2.setPdpSubgroups(pdpSubgroupList);
74 JsonObject res1 = pdpGroup2.getSupportedSubgroups("type2", "2.0.0");
75 assertThat(res1.get("pdpGroup2")).isNotNull();
76 JsonArray resSubList = res1.getAsJsonArray("pdpGroup2");
77 assertThat(resSubList.size()).isEqualTo(2);
78 assertThat(resSubList.toString().contains("subGroup1")).isTrue();
79 assertThat(resSubList.toString().contains("subGroup2")).isTrue();
81 JsonObject res2 = pdpGroup2.getSupportedSubgroups("type1", "1.0.0");
82 assertThat(res2.get("pdpGroup2")).isNotNull();
83 JsonArray resSubList2 = res2.getAsJsonArray("pdpGroup2");
84 assertThat(resSubList2.size()).isEqualTo(1);
86 assertThat(pdpGroup2.getSupportedSubgroups("type3", "1.0.1")).isNull();