Create get Pdp Groups flow
[clamp.git] / src / test / java / org / onap / clamp / policy / pdpgroup / PdpGroupTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights
6  *                             reserved.
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  */
23
24 package org.onap.clamp.policy.pdpgroup;
25
26 import static org.assertj.core.api.Assertions.assertThat;
27
28 import com.google.gson.JsonArray;
29 import com.google.gson.JsonObject;
30
31 import java.io.IOException;
32 import java.util.LinkedList;
33 import java.util.List;
34
35 import org.junit.Test;
36
37 public class PdpGroupTest {
38
39
40     @Test
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();
46
47         PdpGroup pdpGroup2 = new PdpGroup();
48         pdpGroup2.setName("pdpGroup2");
49         pdpGroup2.setPdpGroupState("ACTIVE");
50
51         PolicyModelKey type1 = new PolicyModelKey("type1", "1.0.0");
52         PolicyModelKey type2 = new PolicyModelKey("type2", "2.0.0");
53
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);
60
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);
68
69         List<PdpSubgroup> pdpSubgroupList = new LinkedList<PdpSubgroup>();
70         pdpSubgroupList.add(pdpSubgroup1);
71         pdpSubgroupList.add(pdpSubgroup2);
72         pdpGroup2.setPdpSubgroups(pdpSubgroupList);
73
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();
80
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);
85
86         assertThat(pdpGroup2.getSupportedSubgroups("type3", "1.0.1")).isNull();
87     }
88 }