Spring Aspect logging
[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) 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.utils;
22
23 import java.util.List;
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
32 import reactor.core.publisher.Flux;
33 import reactor.core.publisher.Mono;
34
35 public class MockA1Client implements A1Client {
36     Policies policies = new Policies();
37     private final PolicyTypes policyTypes;
38
39     public MockA1Client(PolicyTypes policyTypes) {
40         this.policyTypes = policyTypes;
41     }
42
43     @Override
44     public Mono<List<String>> getPolicyTypeIdentities() {
45         synchronized (this.policyTypes) {
46             List<String> result = new Vector<>();
47             for (PolicyType p : this.policyTypes.getAll()) {
48                 result.add(p.name());
49             }
50             return Mono.just(result);
51         }
52     }
53
54     @Override
55     public Mono<List<String>> getPolicyIdentities() {
56         synchronized (this.policies) {
57             Vector<String> result = new Vector<>();
58             for (Policy policy : policies.getAll()) {
59                 result.add(policy.id());
60             }
61
62             return Mono.just(result);
63         }
64     }
65
66     @Override
67     public Mono<String> getPolicyTypeSchema(String policyTypeId) {
68         try {
69             return Mono.just(this.policyTypes.getType(policyTypeId).schema());
70         } catch (Exception e) {
71             return Mono.error(e);
72         }
73     }
74
75     @Override
76     public Mono<String> putPolicy(Policy p) {
77         this.policies.put(p);
78         return Mono.just("OK");
79     }
80
81     @Override
82     public Mono<String> deletePolicy(Policy policy) {
83         this.policies.remove(policy);
84         return Mono.just("OK");
85     }
86
87     public Policies getPolicies() {
88         return this.policies;
89     }
90
91     @Override
92     public Mono<A1ProtocolType> getProtocolVersion() {
93         return Mono.just(A1ProtocolType.STD_V1);
94     }
95
96     @Override
97     public Flux<String> deleteAllPolicies() {
98         this.policies.clear();
99         return Flux.empty();
100     }
101
102     @Override
103     public Mono<String> getPolicyStatus(Policy policy) {
104         return Mono.just("OK");
105     }
106
107 }