+ @Test
+ public void removeTopic_shouldFailIfTopicDoesNotExist() {
+ ApiError apiError = new ApiError();
+
+ Topic removedTopic = topicService.removeTopic("not_existing_fqtn", apiError);
+
+ assertNull(removedTopic);
+ assertEquals(NOT_FOUND.getStatusCode(), apiError.getCode());
+ assertTrue(topicService.getTopics().containsKey(TOPIC_FQTN));
+ }
+
+ @Test
+ public void removeTopic_shouldExecuteAafCleanup() {
+ ApiError apiError = new ApiError();
+
+ Topic removedTopic = topicService.removeTopic(TOPIC_FQTN, apiError);
+
+ then(aafTopicSetupService).should().aafTopicCleanup(removedTopic);
+ assertEquals(OK.getStatusCode(), apiError.getCode());
+ }
+
+ @Test
+ public void removeTopic_shouldRemoveEachMrClientAssignedToTopic() {
+ ApiError apiError = new ApiError();
+ MR_Client mrClient = new MR_Client();
+ mrClient.setMrClientId("mrClientId");
+
+ given(clientService.getAllMrClients(TOPIC_FQTN)).willReturn(newArrayList(mrClient));
+
+ topicService.removeTopic(TOPIC_FQTN, apiError);
+
+ then(clientService).should().removeMr_Client(mrClient.getMrClientId(), false, apiError);
+ assertEquals(OK.getStatusCode(), apiError.getCode());
+ }
+
+ @Test
+ public void removeTopic_shouldRemoveTopicFromCache() {
+ ApiError apiError = new ApiError();
+
+ topicService.removeTopic(TOPIC_FQTN, apiError);
+
+ assertTrue(topicService.getTopics().isEmpty());
+ assertEquals(OK.getStatusCode(), apiError.getCode());
+ }
+
+ @Test
+ public void removeTopic_shouldFailIfAafCleanupWasFailed() {
+ ApiError apiError = new ApiError();
+ given(aafTopicSetupService.aafTopicCleanup(any(Topic.class))).willReturn(new ApiError(404, "sth went wrong"));
+
+ Topic removedTopic = topicService.removeTopic(TOPIC_FQTN, apiError);
+
+ assertNull(removedTopic);
+ assertEquals(404, apiError.getCode());
+ assertTrue(topicService.getTopics().containsKey(TOPIC_FQTN));
+ }
+