Changed service keepAlive from POST to PUT
[nonrtric.git] / policy-agent / src / test / java / org / oransc / policyagent / utils / MockA1Client.java
index 3265d76..fc0eba3 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.oransc.policyagent.utils;
 
+import java.nio.charset.StandardCharsets;
 import java.time.Duration;
 import java.util.List;
 import java.util.Vector;
@@ -29,6 +30,8 @@ import org.oransc.policyagent.repository.Policies;
 import org.oransc.policyagent.repository.Policy;
 import org.oransc.policyagent.repository.PolicyType;
 import org.oransc.policyagent.repository.PolicyTypes;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.reactive.function.client.WebClientResponseException;
 
 import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
@@ -46,25 +49,21 @@ public class MockA1Client implements A1Client {
 
     @Override
     public Mono<List<String>> getPolicyTypeIdentities() {
-        synchronized (this.policyTypes) {
-            List<String> result = new Vector<>();
-            for (PolicyType p : this.policyTypes.getAll()) {
-                result.add(p.name());
-            }
-            return mono(result);
+        List<String> result = new Vector<>();
+        for (PolicyType p : this.policyTypes.getAll()) {
+            result.add(p.name());
         }
+        return mono(result);
     }
 
     @Override
     public Mono<List<String>> getPolicyIdentities() {
-        synchronized (this.policies) {
-            Vector<String> result = new Vector<>();
-            for (Policy policy : policies.getAll()) {
-                result.add(policy.id());
-            }
-
-            return mono(result);
+        Vector<String> result = new Vector<>();
+        for (Policy policy : policies.getAll()) {
+            result.add(policy.id());
         }
+
+        return mono(result);
     }
 
     @Override
@@ -118,6 +117,13 @@ public class MockA1Client implements A1Client {
         }
     }
 
+    Mono<String> monoError(String responseBody, HttpStatus status) {
+        byte[] responseBodyBytes = responseBody.getBytes(StandardCharsets.UTF_8);
+        WebClientResponseException a1Exception = new WebClientResponseException(status.value(),
+            status.getReasonPhrase(), null, responseBodyBytes, StandardCharsets.UTF_8, null);
+        return Mono.error(a1Exception);
+    }
+
     @SuppressWarnings("squid:S2925") // "Thread.sleep" should not be used in tests.
     private void sleep() {
         try {