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.Collection;
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;
31 import reactor.core.publisher.Mono;
33 public class MockA1Client implements A1Client {
34 Policies policies = new Policies();
35 private final PolicyTypes policyTypes;
37 public MockA1Client(PolicyTypes policyTypes) {
38 this.policyTypes = policyTypes;
42 public Mono<Collection<String>> getPolicyTypeIdentities() {
43 synchronized (this.policyTypes) {
44 Vector<String> result = new Vector<>();
45 for (PolicyType p : this.policyTypes.getAll()) {
48 return Mono.just(result);
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());
60 return Mono.just(result);
65 public Mono<String> getPolicyTypeSchema(String policyTypeId) {
67 return Mono.just(this.policyTypes.getType(policyTypeId).schema());
68 } catch (Exception e) {
74 public Mono<String> putPolicy(Policy p) {
76 return Mono.just("OK");
80 public Mono<String> deletePolicy(String policyId) {
81 this.policies.removeId(policyId);
82 return Mono.just("OK");
85 public Policies getPolicies() {
90 public Mono<A1ProtocolType> getProtocolVersion() {
91 return Mono.just(A1ProtocolType.STD_V1);