package com.viadeo.axonframework.eventhandling.terminal.kafka;

import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class TopicStatementITest {

    private TopicStatement topicStatement;

    @Before
    public void setup() {
        topicStatement = new TopicStatement(KafkaTerminalITest.KAFKA_PROPERTIES_MAP.get("zookeeper.connect"));
    }

    @Test
    public void prepare_withTopic_isOk() {
        // Given

        // When
        topicStatement.create("TOTO");

        // Then
        assertTrue(topicStatement.getTopics().contains("TOTO"));
    }

    @Test
    public void prepare_withExistingTopic_isOk() {
        // Given
        topicStatement.create("TOTO");

        // When
        topicStatement.create("TOTO");

        // Then
        assertTrue(topicStatement.getTopics().contains("TOTO"));
    }

    @Test
    public void remove_withExistingTopic_isOk() {
        // Given
        topicStatement.create("TOTO");

        // When
        topicStatement.remove("TOTO");

        // Then
        assertFalse(topicStatement.getTopics().contains("TOTO"));
    }

    @Test
    public void remove_withNonexistentTopic_isOk() {
        // Given

        // When
        topicStatement.remove("FB");

        // Then
        assertFalse(topicStatement.getTopics().contains("FB"));
    }

}

@@ -106,16 +106,40 @@
 .Test;%0A%0A
+import java.util.UUID;%0A%0A
 import s
@@ -564,36 +564,33 @@
 atement.create(%22
-TOTO
+A
 %22);%0A%0A        // 
@@ -642,36 +642,33 @@
 ics().contains(%22
-TOTO
+A
 %22));%0A    %7D%0A%0A    
@@ -764,36 +764,33 @@
 atement.create(%22
-TOTO
+B
 %22);%0A%0A        // 
@@ -817,36 +817,33 @@
 atement.create(%22
-TOTO
+B
 %22);%0A%0A        // 
@@ -895,36 +895,33 @@
 ics().contains(%22
-TOTO
+B
 %22));%0A    %7D%0A%0A    
@@ -978,63 +978,111 @@
 k() 
-%7B%0A        // Given%0A        topicStatement.create(%22TOTO%22
+throws InterruptedException %7B%0A        // Given%0A        final String topic = UUID.randomUUID().toString(
 );%0A%0A
@@ -1127,22 +1127,21 @@
 .remove(
-%22TOTO%22
+topic
 );%0A%0A    
@@ -1353,18 +1353,17 @@
 remove(%22
-FB
+D
 %22);%0A%0A   
@@ -1436,10 +1436,9 @@
 ns(%22
-FB
+D
 %22));

generate new topic each time in order to be more robust