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.assertTrue;
26 import static org.mockito.ArgumentMatchers.any;
27 import static org.mockito.Mockito.doReturn;
29 import com.google.gson.Gson;
30 import com.google.gson.GsonBuilder;
31 import com.google.gson.JsonArray;
32 import com.google.gson.JsonElement;
33 import com.google.gson.JsonParser;
35 import java.nio.charset.StandardCharsets;
36 import java.time.Duration;
37 import java.time.Instant;
38 import java.util.ArrayList;
39 import java.util.List;
40 import java.util.concurrent.atomic.AtomicInteger;
42 import org.junit.jupiter.api.AfterEach;
43 import org.junit.jupiter.api.BeforeEach;
44 import org.junit.jupiter.api.Test;
45 import org.junit.jupiter.api.extension.ExtendWith;
46 import org.oransc.policyagent.clients.AsyncRestClient;
47 import org.oransc.policyagent.configuration.ApplicationConfig;
48 import org.oransc.policyagent.configuration.ImmutableRicConfig;
49 import org.oransc.policyagent.configuration.RicConfig;
50 import org.oransc.policyagent.controllers.PolicyInfo;
51 import org.oransc.policyagent.controllers.ServiceRegistrationInfo;
52 import org.oransc.policyagent.controllers.ServiceStatus;
53 import org.oransc.policyagent.exceptions.ServiceException;
54 import org.oransc.policyagent.repository.ImmutablePolicy;
55 import org.oransc.policyagent.repository.ImmutablePolicyType;
56 import org.oransc.policyagent.repository.Lock.LockType;
57 import org.oransc.policyagent.repository.Policies;
58 import org.oransc.policyagent.repository.Policy;
59 import org.oransc.policyagent.repository.PolicyType;
60 import org.oransc.policyagent.repository.PolicyTypes;
61 import org.oransc.policyagent.repository.Ric;
62 import org.oransc.policyagent.repository.Ric.RicState;
63 import org.oransc.policyagent.repository.Rics;
64 import org.oransc.policyagent.repository.Services;
65 import org.oransc.policyagent.tasks.RicSupervision;
66 import org.oransc.policyagent.tasks.ServiceSupervision;
67 import org.oransc.policyagent.utils.MockA1Client;
68 import org.oransc.policyagent.utils.MockA1ClientFactory;
69 import org.slf4j.Logger;
70 import org.slf4j.LoggerFactory;
71 import org.springframework.beans.factory.annotation.Autowired;
72 import org.springframework.boot.test.context.SpringBootTest;
73 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
74 import org.springframework.boot.test.context.TestConfiguration;
75 import org.springframework.boot.web.server.LocalServerPort;
76 import org.springframework.context.ApplicationContext;
77 import org.springframework.context.annotation.Bean;
78 import org.springframework.http.HttpEntity;
79 import org.springframework.http.HttpHeaders;
80 import org.springframework.http.HttpStatus;
81 import org.springframework.http.MediaType;
82 import org.springframework.http.ResponseEntity;
83 import org.springframework.test.context.junit.jupiter.SpringExtension;
84 import org.springframework.web.client.RestTemplate;
85 import org.springframework.web.reactive.function.client.WebClientResponseException;
87 import reactor.core.publisher.Mono;
88 import reactor.test.StepVerifier;
90 @ExtendWith(SpringExtension.class)
91 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
92 public class ApplicationTest {
93 private static final Logger logger = LoggerFactory.getLogger(ApplicationTest.class);
96 ApplicationContext context;
102 private Policies policies;
105 private PolicyTypes policyTypes;
108 MockA1ClientFactory a1ClientFactory;
111 RicSupervision supervision;
116 private static Gson gson = new GsonBuilder() //
120 public static class MockApplicationConfig extends ApplicationConfig {
122 public String getLocalConfigurationFilePath() {
123 return ""; // No config file loaded for the test
128 * Overrides the BeanFactory.
131 static class TestBeanFactory {
132 private final PolicyTypes policyTypes = new PolicyTypes();
133 private final Services services = new Services();
134 private final Policies policies = new Policies();
135 MockA1ClientFactory a1ClientFactory = null;
138 public ApplicationConfig getApplicationConfig() {
139 return new MockApplicationConfig();
143 MockA1ClientFactory getA1ClientFactory() {
144 if (a1ClientFactory == null) {
145 this.a1ClientFactory = new MockA1ClientFactory(this.policyTypes);
147 return this.a1ClientFactory;
151 public PolicyTypes getPolicyTypes() {
152 return this.policyTypes;
156 Policies getPolicies() {
157 return this.policies;
161 Services getServices() {
162 return this.services;
166 public ServiceSupervision getServiceSupervision() {
167 Duration checkInterval = Duration.ofMillis(1);
168 return new ServiceSupervision(this.services, this.policies, this.getA1ClientFactory(), checkInterval);
176 public void reset() {
184 public void verifyNoRicLocks() {
185 for (Ric ric : this.rics.getRics()) {
186 ric.getLock().lockBlocking(LockType.EXCLUSIVE);
187 ric.getLock().unlockBlocking();
188 assertThat(ric.getLock().getLockCounter()).isEqualTo(0);
189 assertThat(ric.getState()).isEqualTo(Ric.RicState.IDLE);
194 public void testGetRics() throws Exception {
196 this.addPolicyType("type1", "ric1");
197 String url = "/rics?policyType=type1";
198 String rsp = restClient().get(url).block();
199 assertThat(rsp).contains("ric1");
201 // nameless type for ORAN A1 1.1
203 this.addPolicyType("", "ric2");
204 url = "/rics?policyType=";
205 rsp = restClient().get(url).block();
206 assertThat(rsp).contains("ric2");
207 assertThat(rsp).doesNotContain("ric1");
209 // Non existing policy type
210 url = "/rics?policyType=XXXX";
211 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
215 public void testRecovery() throws Exception {
216 addRic("ric").setState(Ric.RicState.UNDEFINED);
217 String ricName = "ric";
218 Policy policy2 = addPolicy("policyId2", "typeName", "service", ricName);
220 getA1Client(ricName).putPolicy(policy2); // put it in the RIC
221 policies.remove(policy2); // Remove it from the repo -> should be deleted in the RIC
223 String policyId = "policyId";
224 Policy policy = addPolicy(policyId, "typeName", "service", ricName); // This should be created in the RIC
225 supervision.checkAllRics(); // The created policy should be put in the RIC
226 await().untilAsserted(() -> RicState.SYNCHRONIZING.equals(rics.getRic(ricName).getState()));
227 await().untilAsserted(() -> RicState.IDLE.equals(rics.getRic(ricName).getState()));
229 Policies ricPolicies = getA1Client(ricName).getPolicies();
230 assertThat(ricPolicies.size()).isEqualTo(1);
231 Policy ricPolicy = ricPolicies.get(policyId);
232 assertThat(ricPolicy.json()).isEqualTo(policy.json());
236 public void testGetRicForManagedElement_thenReturnCorrectRic() throws Exception {
237 String ricName = "ric1";
238 String managedElementId = "kista_1";
239 addRic(ricName, managedElementId);
241 String url = "/ric?managedElementId=" + managedElementId;
242 String rsp = restClient().get(url).block();
243 assertThat(rsp).isEqualTo(ricName);
245 // test GET RIC for ManagedElement that does not exist
246 url = "/ric?managedElementId=" + "junk";
247 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
250 private String putPolicyUrl(String serviceName, String ricName, String policyTypeName, String policyInstanceId) {
251 if (policyTypeName.isEmpty()) {
252 return "/policy?instance=" + policyInstanceId + "&ric=" + ricName + "&service=" + serviceName;
254 return "/policy?instance=" + policyInstanceId + "&ric=" + ricName + "&service=" + serviceName + "&type="
260 public void testPutPolicy() throws Exception {
261 String serviceName = "service1";
262 String ricName = "ric1";
263 String policyTypeName = "type1";
264 String policyInstanceId = "instance1";
266 putService(serviceName);
267 addPolicyType(policyTypeName, ricName);
269 String url = putPolicyUrl(serviceName, ricName, policyTypeName, policyInstanceId);
270 final String policyBody = jsonString();
271 this.rics.getRic(ricName).setState(Ric.RicState.IDLE);
273 restClient().put(url, policyBody).block();
275 Policy policy = policies.getPolicy(policyInstanceId);
276 assertThat(policy).isNotNull();
277 assertThat(policy.id()).isEqualTo(policyInstanceId);
278 assertThat(policy.ownerServiceName()).isEqualTo(serviceName);
279 assertThat(policy.ric().name()).isEqualTo("ric1");
282 String rsp = restClient().get(url).block();
283 assertThat(rsp.contains(policyInstanceId)).isTrue();
285 // Test of error codes
286 url = putPolicyUrl(serviceName, ricName + "XX", policyTypeName, policyInstanceId);
287 testErrorCode(restClient().put(url, policyBody), HttpStatus.NOT_FOUND);
289 url = putPolicyUrl(serviceName, ricName, policyTypeName + "XX", policyInstanceId);
290 testErrorCode(restClient().put(url, policyBody), HttpStatus.NOT_FOUND);
292 url = putPolicyUrl(serviceName, ricName, policyTypeName, policyInstanceId);
293 this.rics.getRic(ricName).setState(Ric.RicState.SYNCHRONIZING);
294 testErrorCode(restClient().put(url, policyBody), HttpStatus.LOCKED);
295 this.rics.getRic(ricName).setState(Ric.RicState.IDLE);
300 * Test that HttpStatus and body from failing REST call to A1 is passed on to
303 * @throws ServiceException
305 public void testErrorFromRIC() throws ServiceException {
306 putService("service1");
307 addPolicyType("type1", "ric1");
309 String url = putPolicyUrl("service1", "ric1", "type1", "id1");
310 MockA1Client a1Client = a1ClientFactory.getOrCreateA1Client("ric1");
311 HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
312 String responseBody = "Refused";
313 byte[] responseBodyBytes = responseBody.getBytes(StandardCharsets.UTF_8);
315 WebClientResponseException a1Exception = new WebClientResponseException(httpStatus.value(), "statusText", null,
316 responseBodyBytes, StandardCharsets.UTF_8, null);
317 doReturn(Mono.error(a1Exception)).when(a1Client).putPolicy(any());
320 testErrorCode(restClient().put(url, "{}"), httpStatus, responseBody);
323 this.addPolicy("instance1", "type1", "service1", "ric1");
324 doReturn(Mono.error(a1Exception)).when(a1Client).deletePolicy(any());
325 testErrorCode(restClient().delete("/policy?instance=instance1"), httpStatus, responseBody);
328 this.addPolicy("instance1", "type1", "service1", "ric1");
329 doReturn(Mono.error(a1Exception)).when(a1Client).getPolicyStatus(any());
330 testErrorCode(restClient().get("/policy_status?instance=instance1"), httpStatus, responseBody);
332 // Check that empty response body is OK
333 a1Exception = new WebClientResponseException(httpStatus.value(), "", null, null, null, null);
334 doReturn(Mono.error(a1Exception)).when(a1Client).getPolicyStatus(any());
335 testErrorCode(restClient().get("/policy_status?instance=instance1"), httpStatus);
339 public void testPutTypelessPolicy() throws Exception {
340 putService("service1");
341 addPolicyType("", "ric1");
342 String url = putPolicyUrl("service1", "ric1", "", "id1");
343 restClient().put(url, jsonString()).block();
345 String rsp = restClient().get("/policies").block();
346 List<PolicyInfo> info = parseList(rsp, PolicyInfo.class);
347 assertThat(info).size().isEqualTo(1);
348 PolicyInfo policyInfo = info.get(0);
349 assertThat(policyInfo.id.equals("id1")).isTrue();
350 assertThat(policyInfo.type.equals("")).isTrue();
354 public void testRefuseToUpdatePolicy() throws Exception {
355 // Test that only the json can be changed for a already created policy
356 // In this case service is attempted to be changed
358 this.addRic("ricXXX");
359 this.addPolicy("instance1", "type1", "service1", "ric1");
361 // Try change ric1 -> ricXXX
362 String urlWrongRic = putPolicyUrl("service1", "ricXXX", "type1", "instance1");
363 testErrorCode(restClient().put(urlWrongRic, jsonString()), HttpStatus.CONFLICT);
367 public void testGetPolicy() throws Exception {
368 String url = "/policy?instance=id";
369 Policy policy = addPolicy("id", "typeName", "service1", "ric1");
371 String rsp = restClient().get(url).block();
372 assertThat(rsp).isEqualTo(policy.json());
375 policies.remove(policy);
376 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
381 public void testDeletePolicy() throws Exception {
382 addPolicy("id", "typeName", "service1", "ric1");
383 assertThat(policies.size()).isEqualTo(1);
385 String url = "/policy?instance=id";
386 ResponseEntity<String> entity = restClient().deleteForEntity(url).block();
388 assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
389 assertThat(policies.size()).isEqualTo(0);
391 // Delete a non existing policy
392 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
396 public void testGetPolicySchemas() throws Exception {
397 addPolicyType("type1", "ric1");
398 addPolicyType("type2", "ric2");
400 String url = "/policy_schemas";
401 String rsp = this.restClient().get(url).block();
402 assertThat(rsp).contains("type1");
403 assertThat(rsp).contains("[{\"title\":\"type2\"}");
405 List<String> info = parseSchemas(rsp);
406 assertThat(info.size()).isEqualTo(2);
408 url = "/policy_schemas?ric=ric1";
409 rsp = restClient().get(url).block();
410 assertThat(rsp).contains("type1");
411 info = parseSchemas(rsp);
412 assertThat(info.size()).isEqualTo(1);
414 // Get schema for non existing RIC
415 url = "/policy_schemas?ric=ric1XXX";
416 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
420 public void testGetPolicySchema() throws Exception {
421 addPolicyType("type1", "ric1");
422 addPolicyType("type2", "ric2");
424 String url = "/policy_schema?id=type1";
425 String rsp = restClient().get(url).block();
427 assertThat(rsp).contains("type1");
428 assertThat(rsp).contains("title");
430 // Get non existing schema
431 url = "/policy_schema?id=type1XX";
432 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
436 public void testGetPolicyTypes() throws Exception {
437 addPolicyType("type1", "ric1");
438 addPolicyType("type2", "ric2");
440 String url = "/policy_types";
441 String rsp = restClient().get(url).block();
442 assertThat(rsp).isEqualTo("[\"type2\",\"type1\"]");
444 url = "/policy_types?ric=ric1";
445 rsp = restClient().get(url).block();
446 assertThat(rsp).isEqualTo("[\"type1\"]");
448 // Get policy types for non existing RIC
449 url = "/policy_types?ric=ric1XXX";
450 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
454 public void testGetPolicies() throws Exception {
456 addPolicy("id1", "type1", "service1");
458 String url = "/policies";
459 String rsp = restClient().get(url).block();
461 List<PolicyInfo> info = parseList(rsp, PolicyInfo.class);
462 assertThat(info).size().isEqualTo(1);
463 PolicyInfo policyInfo = info.get(0);
464 assert (policyInfo.validate());
465 assertThat(policyInfo.id).isEqualTo("id1");
466 assertThat(policyInfo.type).isEqualTo("type1");
467 assertThat(policyInfo.service).isEqualTo("service1");
471 public void testGetPoliciesFilter() throws Exception {
472 addPolicy("id1", "type1", "service1");
473 addPolicy("id2", "type1", "service2");
474 addPolicy("id3", "type2", "service1");
476 String url = "/policies?type=type1";
477 String rsp = restClient().get(url).block();
479 assertThat(rsp).contains("id1");
480 assertThat(rsp).contains("id2");
481 assertThat(rsp.contains("id3")).isFalse();
483 url = "/policies?type=type1&service=service2";
484 rsp = restClient().get(url).block();
486 assertThat(rsp.contains("id1")).isFalse();
487 assertThat(rsp).contains("id2");
488 assertThat(rsp.contains("id3")).isFalse();
490 // Test get policies for non existing type
491 url = "/policies?type=type1XXX";
492 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
494 // Test get policies for non existing RIC
495 url = "/policies?ric=XXX";
496 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
500 public void testGetPolicyIdsFilter() throws Exception {
501 addPolicy("id1", "type1", "service1", "ric1");
502 addPolicy("id2", "type1", "service2", "ric1");
503 addPolicy("id3", "type2", "service1", "ric1");
505 String url = "/policy_ids?type=type1";
506 String rsp = restClient().get(url).block();
508 assertThat(rsp).contains("id1");
509 assertThat(rsp).contains("id2");
510 assertThat(rsp.contains("id3")).isFalse();
512 url = "/policy_ids?type=type1&service=service1&ric=ric1";
513 rsp = restClient().get(url).block();
514 assertThat(rsp).isEqualTo("[\"id1\"]");
516 // Test get policy ids for non existing type
517 url = "/policy_ids?type=type1XXX";
518 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
520 // Test get policy ids for non existing RIC
521 url = "/policy_ids?ric=XXX";
522 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
526 public void testPutAndGetService() throws Exception {
528 putService("name", 0);
531 String url = "/services?name=name";
532 String rsp = restClient().get(url).block();
533 List<ServiceStatus> info = parseList(rsp, ServiceStatus.class);
534 assertThat(info.size()).isEqualTo(1);
535 ServiceStatus status = info.iterator().next();
536 assertThat(status.keepAliveIntervalSeconds).isEqualTo(0);
537 assertThat(status.serviceName).isEqualTo("name");
541 rsp = restClient().get(url).block();
542 assertThat(rsp.contains("name")).isTrue();
546 url = "/services/keepalive?name=name";
547 ResponseEntity<String> entity = restClient().postForEntity(url, null).block();
548 assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
551 assertThat(services.size()).isEqualTo(1);
552 url = "/services?name=name";
553 restClient().delete(url).block();
554 assertThat(services.size()).isEqualTo(0);
556 // Keep alive, no registerred service
557 testErrorCode(restClient().post("/services/keepalive?name=name", ""), HttpStatus.NOT_FOUND);
559 // PUT servive with crap payload
560 testErrorCode(restClient().put("/service", "crap"), HttpStatus.BAD_REQUEST);
561 testErrorCode(restClient().put("/service", "{}"), HttpStatus.BAD_REQUEST);
563 // GET non existing servive
564 testErrorCode(restClient().get("/services?name=XXX"), HttpStatus.NOT_FOUND);
568 public void testServiceSupervision() throws Exception {
569 putService("service1", 1);
570 addPolicyType("type1", "ric1");
572 String url = putPolicyUrl("service1", "ric1", "type1", "instance1");
573 final String policyBody = jsonString();
574 restClient().put(url, policyBody).block();
576 assertThat(policies.size()).isEqualTo(1);
577 assertThat(services.size()).isEqualTo(1);
579 // Timeout after ~1 second
580 await().untilAsserted(() -> assertThat(policies.size()).isEqualTo(0));
581 assertThat(services.size()).isEqualTo(0);
585 public void testGetPolicyStatus() throws Exception {
586 addPolicy("id", "typeName", "service1", "ric1");
587 assertThat(policies.size()).isEqualTo(1);
589 String url = "/policy_status?instance=id";
590 String rsp = restClient().get(url).block();
591 assertThat(rsp.equals("OK")).isTrue();
593 // GET non existing policy status
594 url = "/policy_status?instance=XXX";
595 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
598 private Policy addPolicy(String id, String typeName, String service, String ric) throws ServiceException {
600 Policy p = ImmutablePolicy.builder().id(id) //
601 .json(jsonString()) //
602 .ownerServiceName(service) //
603 .ric(rics.getRic(ric)) //
604 .type(addPolicyType(typeName, ric)) //
605 .lastModified("lastModified").build();
610 private Policy addPolicy(String id, String typeName, String service) throws ServiceException {
611 return addPolicy(id, typeName, service, "ric");
614 private String createServiceJson(String name, long keepAliveIntervalSeconds) {
615 ServiceRegistrationInfo service = new ServiceRegistrationInfo(name, keepAliveIntervalSeconds, "callbackUrl");
617 String json = gson.toJson(service);
621 private void putService(String name) {
625 private void putService(String name, long keepAliveIntervalSeconds) {
626 String url = "/service";
627 String body = createServiceJson(name, keepAliveIntervalSeconds);
628 restClient().put(url, body).block();
631 private String baseUrl() {
632 return "http://localhost:" + port;
635 private String jsonString() {
636 return "{\n \"servingCellNrcgi\": \"1\"\n }";
639 private static class ConcurrencyTestRunnable implements Runnable {
640 private final RestTemplate restTemplate = new RestTemplate();
641 private final String baseUrl;
642 static AtomicInteger nextCount = new AtomicInteger(0);
643 private final int count;
644 private final RicSupervision supervision;
646 ConcurrencyTestRunnable(String baseUrl, RicSupervision supervision) {
647 this.baseUrl = baseUrl;
648 this.count = nextCount.incrementAndGet();
649 this.supervision = supervision;
654 for (int i = 0; i < 100; ++i) {
656 this.supervision.checkAllRics();
658 String name = "policy:" + count + ":" + i;
664 private void putPolicy(String name) {
665 String putUrl = baseUrl + "/policy?type=type1&instance=" + name + "&ric=ric1&service=service1";
666 restTemplate.put(putUrl, createJsonHttpEntity("{}"));
669 private void deletePolicy(String name) {
670 String deleteUrl = baseUrl + "/policy?instance=" + name;
671 restTemplate.delete(deleteUrl);
676 public void testConcurrency() throws Exception {
677 final Instant startTime = Instant.now();
678 List<Thread> threads = new ArrayList<>();
680 addPolicyType("type1", "ric1");
682 for (int i = 0; i < 100; ++i) {
683 Thread t = new Thread(new ConcurrencyTestRunnable(baseUrl(), this.supervision), "TestThread_" + i);
687 for (Thread t : threads) {
690 assertThat(policies.size()).isEqualTo(0);
691 logger.info("Concurrency test took " + Duration.between(startTime, Instant.now()));
694 private AsyncRestClient restClient() {
695 return new AsyncRestClient(baseUrl());
698 private void testErrorCode(Mono<?> request, HttpStatus expStatus) {
699 testErrorCode(request, expStatus, "");
702 private void testErrorCode(Mono<?> request, HttpStatus expStatus, String responseContains) {
703 StepVerifier.create(request) //
704 .expectSubscription() //
705 .expectErrorMatches(t -> checkWebClientError(t, expStatus, responseContains)) //
709 private boolean checkWebClientError(Throwable t, HttpStatus expStatus, String responseContains) {
710 assertTrue(t instanceof WebClientResponseException);
711 WebClientResponseException e = (WebClientResponseException) t;
712 assertThat(e.getStatusCode()).isEqualTo(expStatus);
713 assertThat(e.getResponseBodyAsString()).contains(responseContains);
717 private MockA1Client getA1Client(String ricName) throws ServiceException {
718 return a1ClientFactory.getOrCreateA1Client(ricName);
721 private PolicyType addPolicyType(String policyTypeName, String ricName) {
722 PolicyType type = ImmutablePolicyType.builder() //
723 .name(policyTypeName) //
724 .schema("{\"title\":\"" + policyTypeName + "\"}") //
727 policyTypes.put(type);
728 addRic(ricName).addSupportedPolicyType(type);
732 private Ric addRic(String ricName) {
733 return addRic(ricName, null);
736 private Ric addRic(String ricName, String managedElement) {
737 if (rics.get(ricName) != null) {
738 return rics.get(ricName);
740 List<String> mes = new ArrayList<>();
741 if (managedElement != null) {
742 mes.add(managedElement);
744 RicConfig conf = ImmutableRicConfig.builder() //
747 .managedElementIds(mes) //
749 Ric ric = new Ric(conf);
750 ric.setState(Ric.RicState.IDLE);
755 private static HttpEntity<String> createJsonHttpEntity(String content) {
756 HttpHeaders headers = new HttpHeaders();
757 headers.setContentType(MediaType.APPLICATION_JSON);
758 return new HttpEntity<String>(content, headers);
761 private static <T> List<T> parseList(String jsonString, Class<T> clazz) {
762 List<T> result = new ArrayList<>();
763 JsonArray jsonArr = JsonParser.parseString(jsonString).getAsJsonArray();
764 for (JsonElement jsonElement : jsonArr) {
765 T o = gson.fromJson(jsonElement.toString(), clazz);
771 private static List<String> parseSchemas(String jsonString) {
772 JsonArray arrayOfSchema = JsonParser.parseString(jsonString).getAsJsonArray();
773 List<String> result = new ArrayList<>();
774 for (JsonElement schemaObject : arrayOfSchema) {
775 result.add(schemaObject.toString());