Fixed the query parameter 'owner'
[nonrtric.git] / enrichment-coordinator-service / src / test / java / org / oransc / enrichment / ApplicationTest.java
index 9cfe222..8b8cb67 100644 (file)
@@ -30,9 +30,13 @@ 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;
@@ -139,6 +143,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");
@@ -147,6 +163,13 @@ class ApplicationTest {
         assertThat(rsp).isEqualTo("[\"test\"]");
     }
 
+    @Test
+    void testGetEiTypesEmpty() throws Exception {
+        String url = ConsumerConsts.API_ROOT + "/eitypes";
+        String rsp = restClient().get(url).block();
+        assertThat(rsp).isEqualTo("[]");
+    }
+
     @Test
     void testGetEiType() throws Exception {
         putEiProducerWithOneType(EI_PRODUCER_ID, "test");
@@ -169,6 +192,14 @@ class ApplicationTest {
         String url = ConsumerConsts.API_ROOT + "/eitypes/typeId/eijobs";
         String rsp = restClient().get(url).block();
         assertThat(rsp).isEqualTo("[\"jobId\"]");
+
+        url = ConsumerConsts.API_ROOT + "/eitypes/typeId/eijobs?owner=owner";
+        rsp = restClient().get(url).block();
+        assertThat(rsp).isEqualTo("[\"jobId\"]");
+
+        url = ConsumerConsts.API_ROOT + "/eitypes/typeId/eijobs?owner=JUNK";
+        rsp = restClient().get(url).block();
+        assertThat(rsp).isEqualTo("[]");
     }
 
     @Test
@@ -458,6 +489,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);