Add unit tests for SdncOscA1Client
[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 import com.google.gson.FieldNamingPolicy;
24 import com.google.gson.Gson;
25 import com.google.gson.GsonBuilder;
26
27 import java.util.Arrays;
28 import java.util.Vector;
29
30 import org.json.JSONObject;
31 import org.oransc.policyagent.configuration.ImmutableRicConfig;
32 import org.oransc.policyagent.configuration.RicConfig;
33 import org.oransc.policyagent.repository.ImmutablePolicy;
34 import org.oransc.policyagent.repository.ImmutablePolicyType;
35 import org.oransc.policyagent.repository.Policy;
36 import org.oransc.policyagent.repository.PolicyType;
37 import org.oransc.policyagent.repository.Ric;
38 import reactor.core.publisher.Mono;
39
40 public class A1ClientHelper {
41     private static Gson gson = new GsonBuilder() //
42         .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES) //
43         .create(); //
44
45     private A1ClientHelper() {
46     }
47
48     protected static String createInputJsonString(SdncOscAdapterInput inputParams) {
49         JSONObject inputJson = new JSONObject();
50         inputJson.put("input", new JSONObject(gson.toJson(inputParams)));
51         return inputJson.toString();
52     }
53
54     protected static Mono<String> createOutputJsonResponse(String key, String value) {
55         JSONObject paramsJson = new JSONObject();
56         paramsJson.put(key, value);
57         JSONObject responseJson = new JSONObject();
58         responseJson.put("output", paramsJson);
59         return Mono.just(responseJson.toString());
60     }
61
62     protected static Ric createRic(String url) {
63         RicConfig cfg = ImmutableRicConfig.builder().name("ric") //
64             .baseUrl(url) //
65             .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) //
66             .build();
67         return new Ric(cfg);
68     }
69
70     protected static Policy createPolicy(String nearRtRicUrl, String policyId, String json, String type) {
71         return ImmutablePolicy.builder() //
72             .id(policyId) //
73             .json(json) //
74             .ownerServiceName("service") //
75             .ric(createRic(nearRtRicUrl)) //
76             .type(createPolicyType(type)) //
77             .lastModified("now") //
78             .build();
79     }
80
81     protected static PolicyType createPolicyType(String name) {
82         return ImmutablePolicyType.builder().name(name).schema("schema").build();
83     }
84
85 }