Merge "Dockerize the test enviroment"
[nonrtric.git] / policy-agent / src / test / java / org / oransc / policyagent / utils / MockA1Client.java
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2019 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.utils;
22
23 import java.util.Collection;
24 import java.util.Vector;
25
26 import org.oransc.policyagent.clients.A1Client;
27 import org.oransc.policyagent.repository.Policies;
28 import org.oransc.policyagent.repository.Policy;
29 import org.oransc.policyagent.repository.PolicyType;
30 import org.oransc.policyagent.repository.PolicyTypes;
31 import reactor.core.publisher.Mono;
32
33 public class MockA1Client implements A1Client {
34     Policies policies = new Policies();
35     private final PolicyTypes policyTypes;
36
37     public MockA1Client(PolicyTypes policyTypes) {
38         this.policyTypes = policyTypes;
39     }
40
41     @Override
42     public Mono<Collection<String>> getPolicyTypeIdentities() {
43         synchronized (this.policyTypes) {
44             Vector<String> result = new Vector<>();
45             for (PolicyType p : this.policyTypes.getAll()) {
46                 result.add(p.name());
47             }
48             return Mono.just(result);
49         }
50     }
51
52     @Override
53     public Mono<Collection<String>> getPolicyIdentities() {
54         synchronized (this.policies) {
55             Vector<String> result = new Vector<>();
56             for (Policy policy : policies.getAll()) {
57                 result.add(policy.id());
58             }
59
60             return Mono.just(result);
61         }
62     }
63
64     @Override
65     public Mono<String> getPolicyTypeSchema(String policyTypeId) {
66         try {
67             return Mono.just(this.policyTypes.getType(policyTypeId).schema());
68         } catch (Exception e) {
69             return Mono.error(e);
70         }
71     }
72
73     @Override
74     public Mono<String> putPolicy(Policy p) {
75         this.policies.put(p);
76         return Mono.just("OK");
77     }
78
79     @Override
80     public Mono<String> deletePolicy(String policyId) {
81         this.policies.removeId(policyId);
82         return Mono.just("OK");
83     }
84
85     public Policies getPolicies() {
86         return this.policies;
87     }
88
89     @Override
90     public Mono<A1ProtocolType> getProtocolVersion() {
91         return Mono.just(A1ProtocolType.STD_V1);
92     }
93
94 }