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 testSynchronization() 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 testPutAndGetService() throws Exception {
502 putService("name", 0);
505 String url = "/services?name=name";
506 String rsp = restClient().get(url).block();
507 List<ServiceStatus> info = parseList(rsp, ServiceStatus.class);
508 assertThat(info.size()).isEqualTo(1);
509 ServiceStatus status = info.iterator().next();
510 assertThat(status.keepAliveIntervalSeconds).isEqualTo(0);
511 assertThat(status.serviceName).isEqualTo("name");
515 rsp = restClient().get(url).block();
516 assertThat(rsp.contains("name")).isTrue();
520 url = "/services/keepalive?name=name";
521 ResponseEntity<String> entity = restClient().postForEntity(url, null).block();
522 assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
525 assertThat(services.size()).isEqualTo(1);
526 url = "/services?name=name";
527 restClient().delete(url).block();
528 assertThat(services.size()).isEqualTo(0);
530 // Keep alive, no registerred service
531 testErrorCode(restClient().post("/services/keepalive?name=name", ""), HttpStatus.NOT_FOUND);
533 // PUT servive with crap payload
534 testErrorCode(restClient().put("/service", "crap"), HttpStatus.BAD_REQUEST);
535 testErrorCode(restClient().put("/service", "{}"), HttpStatus.BAD_REQUEST);
537 // GET non existing servive
538 testErrorCode(restClient().get("/services?name=XXX"), HttpStatus.NOT_FOUND);
542 public void testServiceSupervision() throws Exception {
543 putService("service1", 1);
544 addPolicyType("type1", "ric1");
546 String url = putPolicyUrl("service1", "ric1", "type1", "instance1");
547 final String policyBody = jsonString();
548 restClient().put(url, policyBody).block();
550 assertThat(policies.size()).isEqualTo(1);
551 assertThat(services.size()).isEqualTo(1);
553 // Timeout after ~1 second
554 await().untilAsserted(() -> assertThat(policies.size()).isEqualTo(0));
555 assertThat(services.size()).isEqualTo(0);
559 public void testGetPolicyStatus() throws Exception {
560 addPolicy("id", "typeName", "service1", "ric1");
561 assertThat(policies.size()).isEqualTo(1);
563 String url = "/policy_status?instance=id";
564 String rsp = restClient().get(url).block();
565 assertThat(rsp.equals("OK")).isTrue();
567 // GET non existing policy status
568 url = "/policy_status?instance=XXX";
569 testErrorCode(restClient().get(url), HttpStatus.NOT_FOUND);
572 private Policy addPolicy(String id, String typeName, String service, String ric) throws ServiceException {
574 Policy p = ImmutablePolicy.builder().id(id) //
575 .json(jsonString()) //
576 .ownerServiceName(service) //
577 .ric(rics.getRic(ric)) //
578 .type(addPolicyType(typeName, ric)) //
579 .lastModified("lastModified").build();
584 private Policy addPolicy(String id, String typeName, String service) throws ServiceException {
585 return addPolicy(id, typeName, service, "ric");
588 private String createServiceJson(String name, long keepAliveIntervalSeconds) {
589 ServiceRegistrationInfo service = new ServiceRegistrationInfo(name, keepAliveIntervalSeconds, "callbackUrl");
591 String json = gson.toJson(service);
595 private void putService(String name) {
599 private void putService(String name, long keepAliveIntervalSeconds) {
600 String url = "/service";
601 String body = createServiceJson(name, keepAliveIntervalSeconds);
602 restClient().put(url, body).block();
605 private String baseUrl() {
606 return "http://localhost:" + port;
609 private String jsonString() {
610 return "{\n \"servingCellNrcgi\": \"1\"\n }";
613 private static class ConcurrencyTestRunnable implements Runnable {
614 private final RestTemplate restTemplate = new RestTemplate();
615 private final String baseUrl;
616 static AtomicInteger nextCount = new AtomicInteger(0);
617 private final int count;
618 private final RicSupervision supervision;
620 ConcurrencyTestRunnable(String baseUrl, RicSupervision supervision) {
621 this.baseUrl = baseUrl;
622 this.count = nextCount.incrementAndGet();
623 this.supervision = supervision;
628 for (int i = 0; i < 100; ++i) {
630 this.supervision.checkAllRics();
632 String name = "policy:" + count + ":" + i;
638 private void putPolicy(String name) {
639 String putUrl = baseUrl + "/policy?type=type1&instance=" + name + "&ric=ric1&service=service1";
640 restTemplate.put(putUrl, createJsonHttpEntity("{}"));
643 private void deletePolicy(String name) {
644 String deleteUrl = baseUrl + "/policy?instance=" + name;
645 restTemplate.delete(deleteUrl);
650 public void testConcurrency() throws Exception {
651 final Instant startTime = Instant.now();
652 List<Thread> threads = new ArrayList<>();
654 addPolicyType("type1", "ric1");
656 for (int i = 0; i < 100; ++i) {
657 Thread t = new Thread(new ConcurrencyTestRunnable(baseUrl(), this.supervision), "TestThread_" + i);
661 for (Thread t : threads) {
664 assertThat(policies.size()).isEqualTo(0);
665 logger.info("Concurrency test took " + Duration.between(startTime, Instant.now()));
668 private AsyncRestClient restClient() {
669 return new AsyncRestClient(baseUrl());
672 private void testErrorCode(Mono<?> request, HttpStatus expStatus) {
673 testErrorCode(request, expStatus, "");
676 private void testErrorCode(Mono<?> request, HttpStatus expStatus, String responseContains) {
677 StepVerifier.create(request) //
678 .expectSubscription() //
679 .expectErrorMatches(t -> checkWebClientError(t, expStatus, responseContains)) //
683 private boolean checkWebClientError(Throwable t, HttpStatus expStatus, String responseContains) {
684 assertTrue(t instanceof WebClientResponseException);
685 WebClientResponseException e = (WebClientResponseException) t;
686 assertThat(e.getStatusCode()).isEqualTo(expStatus);
687 assertThat(e.getResponseBodyAsString()).contains(responseContains);
691 private MockA1Client getA1Client(String ricName) throws ServiceException {
692 return a1ClientFactory.getOrCreateA1Client(ricName);
695 private PolicyType addPolicyType(String policyTypeName, String ricName) {
696 PolicyType type = ImmutablePolicyType.builder() //
697 .name(policyTypeName) //
698 .schema("{\"title\":\"" + policyTypeName + "\"}") //
701 policyTypes.put(type);
702 addRic(ricName).addSupportedPolicyType(type);
706 private Ric addRic(String ricName) {
707 return addRic(ricName, null);
710 private Ric addRic(String ricName, String managedElement) {
711 if (rics.get(ricName) != null) {
712 return rics.get(ricName);
714 List<String> mes = new ArrayList<>();
715 if (managedElement != null) {
716 mes.add(managedElement);
718 RicConfig conf = ImmutableRicConfig.builder() //
721 .managedElementIds(mes) //
723 Ric ric = new Ric(conf);
724 ric.setState(Ric.RicState.IDLE);
729 private static HttpEntity<String> createJsonHttpEntity(String content) {
730 HttpHeaders headers = new HttpHeaders();
731 headers.setContentType(MediaType.APPLICATION_JSON);
732 return new HttpEntity<String>(content, headers);
735 private static <T> List<T> parseList(String jsonString, Class<T> clazz) {
736 List<T> result = new ArrayList<>();
737 JsonArray jsonArr = JsonParser.parseString(jsonString).getAsJsonArray();
738 for (JsonElement jsonElement : jsonArr) {
739 T o = gson.fromJson(jsonElement.toString(), clazz);
745 private static List<String> parseSchemas(String jsonString) {
746 JsonArray arrayOfSchema = JsonParser.parseString(jsonString).getAsJsonArray();
747 List<String> result = new ArrayList<>();
748 for (JsonElement schemaObject : arrayOfSchema) {
749 result.add(schemaObject.toString());