package io.searchbox.indices.reindex;

import io.searchbox.client.JestResult;
import io.searchbox.common.AbstractIntegrationTest;

import java.io.IOException;
import java.util.Collection;

import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.reindex.ReindexPlugin;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.groovy.GroovyPlugin;
import org.elasticsearch.test.ESIntegTestCase;
import org.junit.Test;

import com.google.common.collect.ImmutableMap;

/**
 * @author fabien baligand
 */
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.SUITE)
public class ReindexIntegrationTest extends AbstractIntegrationTest {

    @Override
    protected Collection<Class<? extends Plugin>> nodePlugins() {
        return pluginList(ReindexPlugin.class);
    }

    @Test
    public void testReindex() throws IOException, InterruptedException {
        String sourceIndex = "my_source_index";
        String destIndex = "my_dest_index";
        String documentType = "my_type";
        String documentId = "my_id";

        createIndex(sourceIndex);
        index(sourceIndex, documentType, documentId, "{}");
        flushAndRefresh(sourceIndex);

        ImmutableMap<String, Object> source = ImmutableMap.<String, Object>of("index", sourceIndex);
        ImmutableMap<String, Object> dest = ImmutableMap.<String, Object>of("index", destIndex);
        Reindex reindex = new Reindex.Builder(source, dest).refresh(true).build();
        JestResult result = client.execute(reindex);

        assertTrue(result.getErrorMessage(), result.isSucceeded());
        assertTrue(indexExists(destIndex));
        assertTrue(get(destIndex, documentType, documentId).isExists());
    }

}

@@ -32,16 +32,63 @@
 index;%0A%0A
+import com.google.common.collect.ImmutableMap;%0A
 import i
@@ -173,118 +173,8 @@
 est;
-%0A%0Aimport java.io.IOException;%0Aimport java.util.Collection;%0A%0Aimport org.elasticsearch.common.settings.Settings;
 %0Aimp
@@ -269,61 +269,8 @@
 in;%0A
-import org.elasticsearch.script.groovy.GroovyPlugin;%0A
 impo
@@ -347,46 +347,56 @@
 ort 
-com.google.common.collect.ImmutableMap
+java.io.IOException;%0Aimport java.util.Collection
 ;%0A%0A/

clean up imports