NONRTRIC - Enrichment Coordinator Service, extend information in information type
[nonrtric.git] / enrichment-coordinator-service / src / test / java / org / oransc / enrichment / ApplicationTest.java
index 12d4e47..fa5b7e3 100644 (file)
@@ -162,6 +162,7 @@ class ApplicationTest {
         this.infoJobs.clear();
         this.infoTypes.clear();
         this.infoProducers.clear();
+        this.infoTypeSubscriptions.clear();
         this.producerSimulator.getTestResults().reset();
         this.consumerSimulator.getTestResults().reset();
     }
@@ -475,7 +476,6 @@ class ApplicationTest {
         putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
 
         verifyJobStatus(EI_JOB_ID, "ENABLED");
-
     }
 
     @Test
@@ -765,6 +765,7 @@ class ApplicationTest {
         ResponseEntity<String> resp = restClient().getForEntity(url).block();
         ProducerInfoTypeInfo info = gson.fromJson(resp.getBody(), ProducerInfoTypeInfo.class);
         assertThat(info.jobDataSchema).isNotNull();
+        assertThat(info.typeSpecificInformation).isNotNull();
     }
 
     @Test
@@ -908,7 +909,6 @@ class ApplicationTest {
             InfoTypes types = new InfoTypes(this.applicationConfig);
             types.restoreTypesFromDatabase();
             assertThat(types.size()).isEqualTo(1);
-
         }
         {
             // Restore the jobs, no jobs in database
@@ -922,6 +922,24 @@ class ApplicationTest {
         assertThat(this.infoJobs.size()).isZero();
     }
 
+    @Test
+    void testConsumerTypeSubscriptionDatabase() {
+        final String callbackUrl = baseUrl() + ConsumerSimulatorController.getTypeStatusCallbackUrl();
+        final ConsumerTypeSubscriptionInfo info = new ConsumerTypeSubscriptionInfo(callbackUrl, "owner");
+        // PUT a subscription
+        String body = gson.toJson(info);
+        restClient().putForEntity(typeSubscriptionUrl() + "/subscriptionId", body).block();
+        assertThat(this.infoTypeSubscriptions.size()).isEqualTo(1);
+
+        InfoTypeSubscriptions restoredSubscriptions = new InfoTypeSubscriptions(this.applicationConfig);
+        assertThat(restoredSubscriptions.size()).isEqualTo(1);
+
+        // Delete the subscription
+        restClient().deleteForEntity(typeSubscriptionUrl() + "/subscriptionId").block();
+        restoredSubscriptions = new InfoTypeSubscriptions(this.applicationConfig);
+        assertThat(restoredSubscriptions.size()).isZero();
+    }
+
     @Test
     void testConsumerTypeSubscription() throws Exception {
 
@@ -983,6 +1001,21 @@ class ApplicationTest {
         }
     }
 
+    @Test
+    void testRemovingNonWorkingSubscription() throws Exception {
+        // Test that subscriptions are removed for a unresponsive consumer
+
+        // PUT a subscription with a junk callback
+        final ConsumerTypeSubscriptionInfo info = new ConsumerTypeSubscriptionInfo(baseUrl() + "JUNK", "owner");
+        String body = gson.toJson(info);
+        restClient().putForEntity(typeSubscriptionUrl() + "/subscriptionId", body).block();
+        assertThat(this.infoTypeSubscriptions.size()).isEqualTo(1);
+
+        this.putInfoType(TYPE_ID);
+        // The callback will fail and the subscription will be removed
+        await().untilAsserted(() -> assertThat(this.infoTypeSubscriptions.size()).isZero());
+    }
+
     @Test
     void testTypeSubscriptionErrorCodes() throws Exception {
 
@@ -1018,7 +1051,7 @@ class ApplicationTest {
 
     ProducerInfoTypeInfo producerEiTypeRegistrationInfo(String typeId)
         throws JsonMappingException, JsonProcessingException {
-        return new ProducerInfoTypeInfo(jsonSchemaObject());
+        return new ProducerInfoTypeInfo(jsonSchemaObject(), typeSpecifcInfoObject());
     }
 
     ProducerRegistrationInfo producerEiRegistratioInfoRejecting(String typeId)
@@ -1061,6 +1094,10 @@ class ApplicationTest {
         }
     }
 
+    private Object typeSpecifcInfoObject() {
+        return jsonObject("{ \"propertyName\" : \"value\" }");
+    }
+
     private Object jsonSchemaObject() {
         // a json schema with one mandatory property named "string"
         String schemaStr = "{" //