Skip to content

Commit 87b4610

Browse files
author
Lev Zemlyanov
committed
added test for the fix
Signed-off-by: Lev Zemlyanov <lev@confluent.io>
1 parent e044f20 commit 87b4610

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/test/java/io/confluent/connect/elasticsearch/jest/JestElasticsearchClientTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import io.searchbox.indices.IndicesExists;
3737
import io.searchbox.indices.mapping.GetMapping;
3838
import io.searchbox.indices.mapping.PutMapping;
39+
import java.util.Collections;
3940
import org.apache.kafka.connect.data.Schema;
4041
import org.apache.kafka.connect.errors.ConnectException;
4142
import org.junit.Before;
@@ -56,6 +57,7 @@
5657
import static org.mockito.Mockito.inOrder;
5758
import static org.mockito.Mockito.mock;
5859
import static org.mockito.Mockito.verify;
60+
import static org.mockito.Mockito.verifyNoMoreInteractions;
5961
import static org.mockito.Mockito.when;
6062

6163
public class JestElasticsearchClientTest {
@@ -89,6 +91,23 @@ public void getsVersion() {
8991
assertThat(client.getVersion(), is(equalTo(ElasticsearchClient.Version.ES_V1)));
9092
}
9193

94+
@Test
95+
public void attemptToCreateExistingIndex() throws Exception {
96+
JestElasticsearchClient client = new JestElasticsearchClient(jestClient);
97+
JestResult success = new JestResult(new Gson());
98+
success.setSucceeded(true);
99+
IndicesExists indicesExists = new IndicesExists.Builder(INDEX).build();
100+
when(jestClient.execute(indicesExists)).thenReturn(success);
101+
when(jestClient.execute(argThat(isCreateIndexForTestIndex()))).thenReturn(success);
102+
103+
client.createIndices(Collections.singleton(INDEX));
104+
InOrder inOrder = inOrder(jestClient);
105+
inOrder.verify(jestClient).execute(info);
106+
inOrder.verify(jestClient).execute(indicesExists);
107+
108+
verifyNoMoreInteractions(jestClient);
109+
}
110+
92111
@Test
93112
public void createsIndices() throws Exception {
94113
JestElasticsearchClient client = new JestElasticsearchClient(jestClient);

0 commit comments

Comments
 (0)