AsyncRestClient reuse of SSL context
[nonrtric.git] / enrichment-coordinator-service / src / test / java / org / oransc / enrichment / ApplicationTest.java
index 9cfe222..236ed3e 100644 (file)
@@ -1,9 +1,9 @@
 /*-
  * ========================LICENSE_START=================================
- * ONAP : ccsdk oran
- * ======================================================================
- * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
- * ======================================================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2020 Nordix Foundation
+ * %%
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -30,14 +30,19 @@ import com.google.gson.Gson;
 import com.google.gson.GsonBuilder;
 import com.google.gson.JsonParser;
 
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.PrintStream;
 import java.util.ArrayList;
 import java.util.Collection;
 
+import org.json.JSONObject;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.oransc.enrichment.clients.AsyncRestClient;
+import org.oransc.enrichment.clients.AsyncRestClientFactory;
 import org.oransc.enrichment.clients.ProducerJobInfo;
 import org.oransc.enrichment.configuration.ApplicationConfig;
 import org.oransc.enrichment.configuration.ImmutableWebClientConfig;
@@ -139,6 +144,18 @@ class ApplicationTest {
         assertThat(this.producerSimulator.getTestResults().errorFound).isFalse();
     }
 
+    @Test
+    void createApiDoc() throws FileNotFoundException {
+        String url = "/v2/api-docs";
+        ResponseEntity<String> resp = restClient().getForEntity(url).block();
+        assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
+
+        String indented = (new JSONObject(resp.getBody())).toString(4);
+        try (PrintStream out = new PrintStream(new FileOutputStream("docs/api.json"))) {
+            out.print(indented);
+        }
+    }
+
     @Test
     void testGetEiTypes() throws Exception {
         putEiProducerWithOneType(EI_PRODUCER_ID, "test");
@@ -458,6 +475,16 @@ class ApplicationTest {
         assertThat(this.eiTypes.size()).isEqualTo(0);
     }
 
+    @Test
+    void testGetStatus() throws JsonMappingException, JsonProcessingException, ServiceException {
+        putEiProducerWithOneTypeRejecting("simulateProducerError", EI_TYPE_ID);
+        putEiProducerWithOneTypeRejecting("simulateProducerError2", EI_TYPE_ID);
+
+        String url = "/status";
+        ResponseEntity<String> resp = restClient().getForEntity(url).block();
+        assertThat(resp.getBody()).contains("hunky dory");
+    }
+
     ProducerEiTypeRegistrationInfo producerEiTypeRegistrationInfo(String typeId)
         throws JsonMappingException, JsonProcessingException {
         return new ProducerEiTypeRegistrationInfo(jsonSchemaObject(), typeId);
@@ -560,7 +587,8 @@ class ApplicationTest {
             .trustStorePassword(config.trustStorePassword()) //
             .build();
 
-        return new AsyncRestClient(baseUrl(), config);
+        AsyncRestClientFactory restClientFactory = new AsyncRestClientFactory(config);
+        return restClientFactory.createRestClient(baseUrl());
     }
 
     private AsyncRestClient restClient() {