2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 Nordix Foundation
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
21 package org.oransc.policyagent.utils;
23 import java.util.List;
24 import java.util.Vector;
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;
32 import reactor.core.publisher.Flux;
33 import reactor.core.publisher.Mono;
35 public class MockA1Client implements A1Client {
36 Policies policies = new Policies();
37 private final PolicyTypes policyTypes;
39 public MockA1Client(PolicyTypes policyTypes) {
40 this.policyTypes = policyTypes;
44 public Mono<List<String>> getPolicyTypeIdentities() {
45 synchronized (this.policyTypes) {
46 List<String> result = new Vector<>();
47 for (PolicyType p : this.policyTypes.getAll()) {
50 return Mono.just(result);
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());
62 return Mono.just(result);
67 public Mono<String> getPolicyTypeSchema(String policyTypeId) {
69 return Mono.just(this.policyTypes.getType(policyTypeId).schema());
70 } catch (Exception e) {
76 public Mono<String> putPolicy(Policy p) {
78 return Mono.just("OK");
82 public Mono<String> deletePolicy(Policy policy) {
83 this.policies.remove(policy);
84 return Mono.just("OK");
87 public Policies getPolicies() {
92 public Mono<A1ProtocolType> getProtocolVersion() {
93 return Mono.just(A1ProtocolType.STD_V1);
97 public Flux<String> deleteAllPolicies() {
98 this.policies.clear();
103 public Mono<String> getPolicyStatus(Policy policy) {
104 return Mono.just("OK");