NONRTRIC - Enrichment Coordinator Service, making type availability subscriptions...
[nonrtric.git] / enrichment-coordinator-service / src / test / java / org / oransc / enrichment / ApplicationTest.java
index df938ad..5292d90 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
@@ -555,9 +555,12 @@ class ApplicationTest {
     @Test
     void producerDeleteEiType() throws Exception {
         putInfoType(TYPE_ID);
+        this.putEiJob(TYPE_ID, "job1");
+        this.putEiJob(TYPE_ID, "job2");
         deleteInfoType(TYPE_ID);
 
         assertThat(this.infoTypes.size()).isZero();
+        assertThat(this.infoJobs.size()).isZero(); // Test that also the job is deleted
 
         testErrorCode(restClient().delete(deleteInfoTypeUrl(TYPE_ID)), HttpStatus.NOT_FOUND,
             "Information type not found");
@@ -762,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
@@ -905,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
@@ -919,6 +922,25 @@ 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);
+        assertThat(restoredSubscriptions.getSubscriptionsForOwner("owner")).hasSize(1);
+
+        // Delete the subscription
+        restClient().deleteForEntity(typeSubscriptionUrl() + "/subscriptionId").block();
+        restoredSubscriptions = new InfoTypeSubscriptions(this.applicationConfig);
+        assertThat(restoredSubscriptions.size()).isZero();
+    }
+
     @Test
     void testConsumerTypeSubscription() throws Exception {
 
@@ -980,6 +1002,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 {
 
@@ -1015,7 +1052,7 @@ class ApplicationTest {
 
     ProducerInfoTypeInfo producerEiTypeRegistrationInfo(String typeId)
         throws JsonMappingException, JsonProcessingException {
-        return new ProducerInfoTypeInfo(jsonSchemaObject());
+        return new ProducerInfoTypeInfo(jsonSchemaObject(), typeSpecifcInfoObject());
     }
 
     ProducerRegistrationInfo producerEiRegistratioInfoRejecting(String typeId)
@@ -1058,6 +1095,10 @@ class ApplicationTest {
         }
     }
 
+    private Object typeSpecifcInfoObject() {
+        return jsonObject("{ \"propertyName\" : \"value\" }");
+    }
+
     private Object jsonSchemaObject() {
         // a json schema with one mandatory property named "string"
         String schemaStr = "{" //