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;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.awaitility.Awaitility.await;
25 import static org.junit.jupiter.api.Assertions.assertEquals;
26 import static org.junit.jupiter.api.Assertions.assertTrue;
27 import static org.mockito.ArgumentMatchers.any;
28 import static org.mockito.Mockito.doReturn;
30 import com.google.gson.Gson;
31 import com.google.gson.GsonBuilder;
32 import com.google.gson.JsonArray;
33 import com.google.gson.JsonElement;
34 import com.google.gson.JsonParser;
36 import java.nio.charset.StandardCharsets;
37 import java.time.Duration;
38 import java.time.Instant;
39 import java.util.ArrayList;
40 import java.util.List;
41 import java.util.concurrent.atomic.AtomicInteger;
43 import org.junit.jupiter.api.AfterEach;
44 import org.junit.jupiter.api.BeforeEach;
45 import org.junit.jupiter.api.Test;
46 import org.junit.jupiter.api.extension.ExtendWith;
47 import org.oransc.policyagent.clients.AsyncRestClient;
48 import org.oransc.policyagent.configuration.ApplicationConfig;
49 import org.oransc.policyagent.configuration.ImmutableRicConfig;
50 import org.oransc.policyagent.configuration.RicConfig;
51 import org.oransc.policyagent.controllers.PolicyInfo;
52 import org.oransc.policyagent.controllers.ServiceRegistrationInfo;
53 import org.oransc.policyagent.controllers.ServiceStatus;
54 import org.oransc.policyagent.exceptions.ServiceException;
55 import org.oransc.policyagent.repository.ImmutablePolicy;
56 import org.oransc.policyagent.repository.ImmutablePolicyType;
57 import org.oransc.policyagent.repository.Lock.LockType;
58 import org.oransc.policyagent.repository.Policies;
59 import org.oransc.policyagent.repository.Policy;
60 import org.oransc.policyagent.repository.PolicyType;
61 import org.oransc.policyagent.repository.PolicyTypes;
62 import org.oransc.policyagent.repository.Ric;
63 import org.oransc.policyagent.repository.Ric.RicState;
64 import org.oransc.policyagent.repository.Rics;
65 import org.oransc.policyagent.repository.Services;
66 import org.oransc.policyagent.tasks.RicSupervision;
67 import org.oransc.policyagent.tasks.ServiceSupervision;
68 import org.oransc.policyagent.utils.MockA1Client;
69 import org.oransc.policyagent.utils.MockA1ClientFactory;
70 import org.slf4j.Logger;
71 import org.slf4j.LoggerFactory;
72 import org.springframework.beans.factory.annotation.Autowired;
73 import org.springframework.boot.test.context.SpringBootTest;
74 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
75 import org.springframework.boot.test.context.TestConfiguration;
76 import org.springframework.boot.web.server.LocalServerPort;
77 import org.springframework.context.ApplicationContext;
78 import org.springframework.context.annotation.Bean;
79 import org.springframework.http.HttpEntity;
80 import org.springframework.http.HttpHeaders;
81 import org.springframework.http.HttpStatus;
82 import org.springframework.http.MediaType;
83 import org.springframework.http.ResponseEntity;
84 import org.springframework.test.context.junit.jupiter.SpringExtension;
85 import org.springframework.web.client.RestTemplate;
86 import org.springframework.web.reactive.function.client.WebClientResponseException;
88 import reactor.core.publisher.Mono;
89 import reactor.test.StepVerifier;
90 import reactor.util.annotation.Nullable;
92 @ExtendWith(SpringExtension.class)
93 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
94 public class ApplicationTest {
95 private static final Logger logger = LoggerFactory.getLogger(ApplicationTest.class);
98 ApplicationContext context;
104 private Policies policies;
107 private PolicyTypes policyTypes;
110 MockA1ClientFactory a1ClientFactory;
113 RicSupervision supervision;
118 private static Gson gson = new GsonBuilder() //
122 public static class MockApplicationConfig extends ApplicationConfig {
124 public String getLocalConfigurationFilePath() {
125 return ""; // No config file loaded for the test
130 * Overrides the BeanFactory.
133 static class TestBeanFactory {
134 private final PolicyTypes policyTypes = new PolicyTypes();
135 private final Services services = new Services();
136 private final Policies policies = new Policies();
137 MockA1ClientFactory a1ClientFactory = null;
140 public ApplicationConfig getApplicationConfig() {
141 return new MockApplicationConfig();
145 MockA1ClientFactory getA1ClientFactory() {
146 if (a1ClientFactory == null) {
147 this.a1ClientFactory = new MockA1ClientFactory(this.policyTypes);
149 return this.a1ClientFactory;
153 public PolicyTypes getPolicyTypes() {
154 return this.policyTypes;
158 Policies getPolicies() {
159 return this.policies;
163 Services getServices() {
164 return this.services;
168 public ServiceSupervision getServiceSupervision() {
169 Duration checkInterval = Duration.ofMillis(1);
170 return new ServiceSupervision(this.services, this.policies, this.getA1ClientFactory(), checkInterval);
178 public void reset() {
186 public void verifyNoRicLocks() {
187 for (Ric ric : this.rics.getRics()) {
188 ric.getLock().lockBlocking(LockType.EXCLUSIVE);
189 ric.getLock().unlockBlocking();
190 assertThat(ric.getLock().getLockCounter()).isEqualTo(0);
191 assertThat(ric.getState()).isEqualTo(Ric.RicState.IDLE);
196 public void testGetRics() throws Exception {
198 this.addPolicyType("type1", "ric1");
199 String url = "/rics?policyType=type1";
200 String rsp = restClient().get(url).block();
201 assertThat(rsp).contains("ric1");
203 // nameless type for ORAN A1 1.1
205 this.addPolicyType("", "ric2");
206 url = "/rics?policyType=";
207 rsp = restClient().get(url).block();
208 assertThat(rsp).contains("ric2");
209 assertThat(rsp).doesNotContain("ric1");
211 // Non existing policy type
212 url = "/rics?policyType=XXXX";
213 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
217 public void testSynchronization() throws Exception {
218 addRic("ric").setState(Ric.RicState.UNDEFINED);
219 String ricName = "ric";
220 Policy policy2 = addPolicy("policyId2", "typeName", "service", ricName);
222 getA1Client(ricName).putPolicy(policy2); // put it in the RIC
223 policies.remove(policy2); // Remove it from the repo -> should be deleted in the RIC
225 String policyId = "policyId";
226 Policy policy = addPolicy(policyId, "typeName", "service", ricName); // This should be created in the RIC
227 supervision.checkAllRics(); // The created policy should be put in the RIC
228 await().untilAsserted(() -> RicState.SYNCHRONIZING.equals(rics.getRic(ricName).getState()));
229 await().untilAsserted(() -> RicState.IDLE.equals(rics.getRic(ricName).getState()));
231 Policies ricPolicies = getA1Client(ricName).getPolicies();
232 assertThat(ricPolicies.size()).isEqualTo(1);
233 Policy ricPolicy = ricPolicies.get(policyId);
234 assertThat(ricPolicy.json()).isEqualTo(policy.json());
238 public void testGetRicForManagedElement_thenReturnCorrectRic() throws Exception {
239 String ricName = "ric1";
240 String managedElementId = "kista_1";
241 addRic(ricName, managedElementId);
243 String url = "/ric?managedElementId=" + managedElementId;
244 String rsp = restClient().get(url).block();
245 assertThat(rsp).isEqualTo(ricName);
247 // test GET RIC for ManagedElement that does not exist
248 url = "/ric?managedElementId=" + "junk";
249 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
252 private String putPolicyUrl(String serviceName, String ricName, String policyTypeName, String policyInstanceId) {
253 if (policyTypeName.isEmpty()) {
254 return "/policy?instance=" + policyInstanceId + "&ric=" + ricName + "&service=" + serviceName;
256 return "/policy?instance=" + policyInstanceId + "&ric=" + ricName + "&service=" + serviceName + "&type="
262 public void testPutPolicy() throws Exception {
263 String serviceName = "service1";
264 String ricName = "ric1";
265 String policyTypeName = "type1";
266 String policyInstanceId = "instance1";
268 putService(serviceName);
269 addPolicyType(policyTypeName, ricName);
271 String url = putPolicyUrl(serviceName, ricName, policyTypeName, policyInstanceId);
272 final String policyBody = jsonString();
273 this.rics.getRic(ricName).setState(Ric.RicState.IDLE);
275 restClient().put(url, policyBody).block();
277 Policy policy = policies.getPolicy(policyInstanceId);
278 assertThat(policy).isNotNull();
279 assertThat(policy.id()).isEqualTo(policyInstanceId);
280 assertThat(policy.ownerServiceName()).isEqualTo(serviceName);
281 assertThat(policy.ric().name()).isEqualTo("ric1");
284 String rsp = restClient().get(url).block();
285 assertThat(rsp.contains(policyInstanceId)).isTrue();
287 // Test of error codes
288 url = putPolicyUrl(serviceName, ricName + "XX", policyTypeName, policyInstanceId);
289 testErrorCode(restClient().put(url, policyBody), HttpStatus.NOT_FOUND);
291 url = putPolicyUrl(serviceName, ricName, policyTypeName + "XX", policyInstanceId);
292 testErrorCode(restClient().put(url, policyBody), HttpStatus.NOT_FOUND);
294 url = putPolicyUrl(serviceName, ricName, policyTypeName, policyInstanceId);
295 this.rics.getRic(ricName).setState(Ric.RicState.SYNCHRONIZING);
296 testErrorCode(restClient().put(url, policyBody), HttpStatus.LOCKED);
297 this.rics.getRic(ricName).setState(Ric.RicState.IDLE);
302 * Test that HttpStatus and body from failing REST call to A1 is passed on to
305 * @throws ServiceException
307 public void testErrorFromRIC() throws ServiceException {
308 putService("service1");
309 addPolicyType("type1", "ric1");
311 String url = putPolicyUrl("service1", "ric1", "type1", "id1");
312 MockA1Client a1Client = a1ClientFactory.getOrCreateA1Client("ric1");
313 HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
314 String responseBody = "Refused";
315 byte[] responseBodyBytes = responseBody.getBytes(StandardCharsets.UTF_8);
317 WebClientResponseException a1Exception = new WebClientResponseException(httpStatus.value(), "statusText", null,
318 responseBodyBytes, StandardCharsets.UTF_8, null);
319 doReturn(Mono.error(a1Exception)).when(a1Client).putPolicy(any());
322 testErrorCode(restClient().put(url, "{}"), httpStatus, responseBody);
325 this.addPolicy("instance1", "type1", "service1", "ric1");
326 doReturn(Mono.error(a1Exception)).when(a1Client).deletePolicy(any());
327 testErrorCode(restClient().delete("/policy?instance=instance1"), httpStatus, responseBody);
330 this.addPolicy("instance1", "type1", "service1", "ric1");
331 doReturn(Mono.error(a1Exception)).when(a1Client).getPolicyStatus(any());
332 testErrorCode(restClient().get("/policy_status?instance=instance1"), httpStatus, responseBody);
334 // Check that empty response body is OK
335 a1Exception = new WebClientResponseException(httpStatus.value(), "", null, null, null, null);
336 doReturn(Mono.error(a1Exception)).when(a1Client).getPolicyStatus(any());
337 testErrorCode(restClient().get("/policy_status?instance=instance1"), httpStatus);
341 public void testPutTypelessPolicy() throws Exception {
342 putService("service1");
343 addPolicyType("", "ric1");
344 String url = putPolicyUrl("service1", "ric1", "", "id1");
345 restClient().put(url, jsonString()).block();
347 String rsp = restClient().get("/policies").block();
348 List<PolicyInfo> info = parseList(rsp, PolicyInfo.class);
349 assertThat(info).size().isEqualTo(1);
350 PolicyInfo policyInfo = info.get(0);
351 assertThat(policyInfo.id.equals("id1")).isTrue();
352 assertThat(policyInfo.type.equals("")).isTrue();
356 public void testRefuseToUpdatePolicy() throws Exception {
357 // Test that only the json can be changed for a already created policy
358 // In this case service is attempted to be changed
360 this.addRic("ricXXX");
361 this.addPolicy("instance1", "type1", "service1", "ric1");
363 // Try change ric1 -> ricXXX
364 String urlWrongRic = putPolicyUrl("service1", "ricXXX", "type1", "instance1");
365 testErrorCode(restClient().put(urlWrongRic, jsonString()), HttpStatus.CONFLICT);
369 public void testGetPolicy() throws Exception {
370 String url = "/policy?instance=id";
371 Policy policy = addPolicy("id", "typeName", "service1", "ric1");
373 String rsp = restClient().get(url).block();
374 assertThat(rsp).isEqualTo(policy.json());
377 policies.remove(policy);
378 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
383 public void testDeletePolicy() throws Exception {
384 addPolicy("id", "typeName", "service1", "ric1");
385 assertThat(policies.size()).isEqualTo(1);
387 String url = "/policy?instance=id";
388 ResponseEntity<String> entity = restClient().deleteForEntity(url).block();
390 assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
391 assertThat(policies.size()).isEqualTo(0);
393 // Delete a non existing policy
394 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
398 public void testGetPolicySchemas() throws Exception {
399 addPolicyType("type1", "ric1");
400 addPolicyType("type2", "ric2");
402 String url = "/policy_schemas";
403 String rsp = this.restClient().get(url).block();
404 assertThat(rsp).contains("type1");
405 assertThat(rsp).contains("[{\"title\":\"type2\"}");
407 List<String> info = parseSchemas(rsp);
408 assertThat(info.size()).isEqualTo(2);
410 url = "/policy_schemas?ric=ric1";
411 rsp = restClient().get(url).block();
412 assertThat(rsp).contains("type1");
413 info = parseSchemas(rsp);
414 assertThat(info.size()).isEqualTo(1);
416 // Get schema for non existing RIC
417 url = "/policy_schemas?ric=ric1XXX";
418 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
422 public void testGetPolicySchema() throws Exception {
423 addPolicyType("type1", "ric1");
424 addPolicyType("type2", "ric2");
426 String url = "/policy_schema?id=type1";
427 String rsp = restClient().get(url).block();
429 assertThat(rsp).contains("type1");
430 assertThat(rsp).contains("title");
432 // Get non existing schema
433 url = "/policy_schema?id=type1XX";
434 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
438 public void testGetPolicyTypes() throws Exception {
439 addPolicyType("type1", "ric1");
440 addPolicyType("type2", "ric2");
442 String url = "/policy_types";
443 String rsp = restClient().get(url).block();
444 assertThat(rsp).isEqualTo("[\"type2\",\"type1\"]");
446 url = "/policy_types?ric=ric1";
447 rsp = restClient().get(url).block();
448 assertThat(rsp).isEqualTo("[\"type1\"]");
450 // Get policy types for non existing RIC
451 url = "/policy_types?ric=ric1XXX";
452 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
456 public void testGetPolicies() throws Exception {
458 addPolicy("id1", "type1", "service1");
460 String url = "/policies";
461 String rsp = restClient().get(url).block();
463 List<PolicyInfo> info = parseList(rsp, PolicyInfo.class);
464 assertThat(info).size().isEqualTo(1);
465 PolicyInfo policyInfo = info.get(0);
466 assert (policyInfo.validate());
467 assertThat(policyInfo.id).isEqualTo("id1");
468 assertThat(policyInfo.type).isEqualTo("type1");
469 assertThat(policyInfo.service).isEqualTo("service1");
473 public void testGetPoliciesFilter() throws Exception {
474 addPolicy("id1", "type1", "service1");
475 addPolicy("id2", "type1", "service2");
476 addPolicy("id3", "type2", "service1");
478 String url = "/policies?type=type1";
479 String rsp = restClient().get(url).block();
481 assertThat(rsp).contains("id1");
482 assertThat(rsp).contains("id2");
483 assertThat(rsp.contains("id3")).isFalse();
485 url = "/policies?type=type1&service=service2";
486 rsp = restClient().get(url).block();
488 assertThat(rsp.contains("id1")).isFalse();
489 assertThat(rsp).contains("id2");
490 assertThat(rsp.contains("id3")).isFalse();
492 // Test get policies for non existing type
493 url = "/policies?type=type1XXX";
494 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
496 // Test get policies for non existing RIC
497 url = "/policies?ric=XXX";
498 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
502 public void testGetPolicyIdsFilter() throws Exception {
503 addPolicy("id1", "type1", "service1", "ric1");
504 addPolicy("id2", "type1", "service2", "ric1");
505 addPolicy("id3", "type2", "service1", "ric1");
507 String url = "/policy_ids?type=type1";
508 String rsp = restClient().get(url).block();
510 assertThat(rsp).contains("id1");
511 assertThat(rsp).contains("id2");
512 assertThat(rsp.contains("id3")).isFalse();
514 url = "/policy_ids?type=type1&service=service1&ric=ric1";
515 rsp = restClient().get(url).block();
516 assertThat(rsp).isEqualTo("[\"id1\"]");
518 // Test get policy ids for non existing type
519 url = "/policy_ids?type=type1XXX";
520 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
522 // Test get policy ids for non existing RIC
523 url = "/policy_ids?ric=XXX";
524 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
528 public void testPutAndGetService() throws Exception {
530 putService("name", 0, HttpStatus.CREATED);
531 putService("name", 0, HttpStatus.OK);
534 String url = "/services?name=name";
535 String rsp = restClient().get(url).block();
536 List<ServiceStatus> info = parseList(rsp, ServiceStatus.class);
537 assertThat(info.size()).isEqualTo(1);
538 ServiceStatus status = info.iterator().next();
539 assertThat(status.keepAliveIntervalSeconds).isEqualTo(0);
540 assertThat(status.serviceName).isEqualTo("name");
544 rsp = restClient().get(url).block();
545 assertThat(rsp.contains("name")).isTrue();
549 url = "/services/keepalive?name=name";
550 ResponseEntity<String> entity = restClient().postForEntity(url, null).block();
551 assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
554 assertThat(services.size()).isEqualTo(1);
555 url = "/services?name=name";
556 restClient().delete(url).block();
557 assertThat(services.size()).isEqualTo(0);
559 // Keep alive, no registerred service
560 testErrorCode(restClient().post("/services/keepalive?name=name", ""), HttpStatus.NOT_FOUND);
562 // PUT servive with crap payload
563 testErrorCode(restClient().put("/service", "crap"), HttpStatus.BAD_REQUEST);
564 testErrorCode(restClient().put("/service", "{}"), HttpStatus.BAD_REQUEST);
566 // GET non existing servive
567 testErrorCode(restClient().get("/services?name=XXX"), HttpStatus.NOT_FOUND);
571 public void testServiceSupervision() throws Exception {
572 putService("service1", 1, HttpStatus.CREATED);
573 addPolicyType("type1", "ric1");
575 String url = putPolicyUrl("service1", "ric1", "type1", "instance1");
576 final String policyBody = jsonString();
577 restClient().put(url, policyBody).block();
579 assertThat(policies.size()).isEqualTo(1);
580 assertThat(services.size()).isEqualTo(1);
582 // Timeout after ~1 second
583 await().untilAsserted(() -> assertThat(policies.size()).isEqualTo(0));
584 assertThat(services.size()).isEqualTo(0);
588 public void testGetPolicyStatus() throws Exception {
589 addPolicy("id", "typeName", "service1", "ric1");
590 assertThat(policies.size()).isEqualTo(1);
592 String url = "/policy_status?instance=id";
593 String rsp = restClient().get(url).block();
594 assertThat(rsp.equals("OK")).isTrue();
596 // GET non existing policy status
597 url = "/policy_status?instance=XXX";
598 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
601 private Policy addPolicy(String id, String typeName, String service, String ric) throws ServiceException {
603 Policy p = ImmutablePolicy.builder().id(id) //
604 .json(jsonString()) //
605 .ownerServiceName(service) //
606 .ric(rics.getRic(ric)) //
607 .type(addPolicyType(typeName, ric)) //
608 .lastModified("lastModified").build();
613 private Policy addPolicy(String id, String typeName, String service) throws ServiceException {
614 return addPolicy(id, typeName, service, "ric");
617 private String createServiceJson(String name, long keepAliveIntervalSeconds) {
618 ServiceRegistrationInfo service = new ServiceRegistrationInfo(name, keepAliveIntervalSeconds, "callbackUrl");
620 String json = gson.toJson(service);
624 private void putService(String name) {
625 putService(name, 0, null);
628 private void putService(String name, long keepAliveIntervalSeconds, @Nullable HttpStatus expectedStatus) {
629 String url = "/service";
630 String body = createServiceJson(name, keepAliveIntervalSeconds);
631 ResponseEntity<String> resp = restClient().putForEntity(url, body).block();
632 if (expectedStatus != null) {
633 assertEquals(expectedStatus, resp.getStatusCode(), "");
637 private String baseUrl() {
638 return "http://localhost:" + port;
641 private String jsonString() {
642 return "{\n \"servingCellNrcgi\": \"1\"\n }";
645 private static class ConcurrencyTestRunnable implements Runnable {
646 private final RestTemplate restTemplate = new RestTemplate();
647 private final String baseUrl;
648 static AtomicInteger nextCount = new AtomicInteger(0);
649 private final int count;
650 private final RicSupervision supervision;
652 ConcurrencyTestRunnable(String baseUrl, RicSupervision supervision) {
653 this.baseUrl = baseUrl;
654 this.count = nextCount.incrementAndGet();
655 this.supervision = supervision;
660 for (int i = 0; i < 100; ++i) {
662 this.supervision.checkAllRics();
664 String name = "policy:" + count + ":" + i;
670 private void putPolicy(String name) {
671 String putUrl = baseUrl + "/policy?type=type1&instance=" + name + "&ric=ric1&service=service1";
672 restTemplate.put(putUrl, createJsonHttpEntity("{}"));
675 private void deletePolicy(String name) {
676 String deleteUrl = baseUrl + "/policy?instance=" + name;
677 restTemplate.delete(deleteUrl);
682 public void testConcurrency() throws Exception {
683 final Instant startTime = Instant.now();
684 List<Thread> threads = new ArrayList<>();
686 addPolicyType("type1", "ric1");
688 for (int i = 0; i < 100; ++i) {
689 Thread t = new Thread(new ConcurrencyTestRunnable(baseUrl(), this.supervision), "TestThread_" + i);
693 for (Thread t : threads) {
696 assertThat(policies.size()).isEqualTo(0);
697 logger.info("Concurrency test took " + Duration.between(startTime, Instant.now()));
700 private AsyncRestClient restClient() {
701 return new AsyncRestClient(baseUrl());
704 private void testErrorCode(Mono<?> request, HttpStatus expStatus) {
705 testErrorCode(request, expStatus, "");
708 private void testErrorCode(Mono<?> request, HttpStatus expStatus, String responseContains) {
709 StepVerifier.create(request) //
710 .expectSubscription() //
711 .expectErrorMatches(t -> checkWebClientError(t, expStatus, responseContains)) //
715 private boolean checkWebClientError(Throwable t, HttpStatus expStatus, String responseContains) {
716 assertTrue(t instanceof WebClientResponseException);
717 WebClientResponseException e = (WebClientResponseException) t;
718 assertThat(e.getStatusCode()).isEqualTo(expStatus);
719 assertThat(e.getResponseBodyAsString()).contains(responseContains);
723 private MockA1Client getA1Client(String ricName) throws ServiceException {
724 return a1ClientFactory.getOrCreateA1Client(ricName);
727 private PolicyType addPolicyType(String policyTypeName, String ricName) {
728 PolicyType type = ImmutablePolicyType.builder() //
729 .name(policyTypeName) //
730 .schema("{\"title\":\"" + policyTypeName + "\"}") //
733 policyTypes.put(type);
734 addRic(ricName).addSupportedPolicyType(type);
738 private Ric addRic(String ricName) {
739 return addRic(ricName, null);
742 private Ric addRic(String ricName, String managedElement) {
743 if (rics.get(ricName) != null) {
744 return rics.get(ricName);
746 List<String> mes = new ArrayList<>();
747 if (managedElement != null) {
748 mes.add(managedElement);
750 RicConfig conf = ImmutableRicConfig.builder() //
753 .managedElementIds(mes) //
755 Ric ric = new Ric(conf);
756 ric.setState(Ric.RicState.IDLE);
761 private static HttpEntity<String> createJsonHttpEntity(String content) {
762 HttpHeaders headers = new HttpHeaders();
763 headers.setContentType(MediaType.APPLICATION_JSON);
764 return new HttpEntity<String>(content, headers);
767 private static <T> List<T> parseList(String jsonString, Class<T> clazz) {
768 List<T> result = new ArrayList<>();
769 JsonArray jsonArr = JsonParser.parseString(jsonString).getAsJsonArray();
770 for (JsonElement jsonElement : jsonArr) {
771 T o = gson.fromJson(jsonElement.toString(), clazz);
777 private static List<String> parseSchemas(String jsonString) {
778 JsonArray arrayOfSchema = JsonParser.parseString(jsonString).getAsJsonArray();
779 List<String> result = new ArrayList<>();
780 for (JsonElement schemaObject : arrayOfSchema) {
781 result.add(schemaObject.toString());