21808567ad1362147f40c5f882c61f083e4813cb
[nonrtric.git] / policy-agent / src / test / java / org / oransc / policyagent / clients / A1ClientHelper.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2020 Nordix Foundation
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.oransc.policyagent.clients;
22
23
24 import java.util.Arrays;
25 import java.util.Vector;
26
27 import org.json.JSONObject;
28 import org.oransc.policyagent.configuration.ImmutableRicConfig;
29 import org.oransc.policyagent.configuration.RicConfig;
30 import org.oransc.policyagent.repository.ImmutablePolicy;
31 import org.oransc.policyagent.repository.ImmutablePolicyType;
32 import org.oransc.policyagent.repository.Policy;
33 import org.oransc.policyagent.repository.PolicyType;
34 import org.oransc.policyagent.repository.Ric;
35 import reactor.core.publisher.Mono;
36
37 public class A1ClientHelper {
38
39     private A1ClientHelper() {
40     }
41
42     protected static Mono<String> createOutputJsonResponse(String key, String value) {
43         JSONObject paramsJson = new JSONObject();
44         paramsJson.put(key, value);
45         JSONObject responseJson = new JSONObject();
46         responseJson.put("output", paramsJson);
47         return Mono.just(responseJson.toString());
48     }
49
50     protected static Ric createRic(String url) {
51         RicConfig cfg = ImmutableRicConfig.builder().name("ric") //
52             .baseUrl(url) //
53             .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) //
54             .controllerName("") //
55             .build();
56         return new Ric(cfg);
57     }
58
59     protected static Policy createPolicy(String nearRtRicUrl, String policyId, String json, String type) {
60         return ImmutablePolicy.builder() //
61             .id(policyId) //
62             .json(json) //
63             .ownerServiceName("service") //
64             .ric(createRic(nearRtRicUrl)) //
65             .type(createPolicyType(type)) //
66             .lastModified("now") //
67             .build();
68     }
69
70     protected static PolicyType createPolicyType(String name) {
71         return ImmutablePolicyType.builder().name(name).schema("schema").build();
72     }
73
74     protected static String getCreateSchema(String policyType, String policyTypeId) {
75         JSONObject obj = new JSONObject(policyType);
76         JSONObject schemaObj = obj.getJSONObject("create_schema");
77         schemaObj.put("title", policyTypeId);
78         return schemaObj.toString();
79     }
80 }