package org.dainst.chronontology.store;

import org.dainst.chronontology.TestConstants;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.node.Node;

import static org.elasticsearch.node.NodeBuilder.nodeBuilder;

/**
 * TODO clean up test dir after tests
 *
 * @author Daniel M. de Oliveira
 */
public class ESServerTestUtil {

    private static Node esNode = null;
    private static final String HTTP_PORT = "9201";
    private static final String ES_URL= "http://localhost:"+HTTP_PORT;
    private static final String TEST_ES_DATA = TestConstants.TEST_FOLDER+"/test_es_data";

    public static String getUrl() {
        return ES_URL;
    }

    public static void startElasticSearchServer() {

        ImmutableSettings.Builder elasticsearchSettings = ImmutableSettings.settingsBuilder()
                .put("cluster.name", "chronontology_connected_unit_testing_cluster")
                .put("http.port",HTTP_PORT)
                .put("path.data", TEST_ES_DATA);

        esNode = nodeBuilder()
                .local(true)
                .settings(elasticsearchSettings.build())
                .node();
    }

    public static void stopElasticSearchServer() {
        if (esNode==null) return;
        esNode.close();
        esNode=null;
    }
}

@@ -30,24 +30,64 @@
 ogy.store;%0A%0A
+import org.apache.commons.io.FileUtils;%0A
 import org.d
@@ -121,16 +121,16 @@
 stants;%0A
-
 import o
@@ -214,24 +214,74 @@
 node.Node;%0A%0A
+import java.io.File;%0Aimport java.io.IOException;%0A%0A
 import stati
@@ -335,53 +335,12 @@
 r;%0A%0A
+
 /**%0A
- * TODO clean up test dir after tests%0A *%0A
  * @
@@ -1325,20 +1325,154 @@
 sNode=null;%0A
+        try %7B%0A            FileUtils.deleteDirectory(new File(%22src/test/resources/test_es_data%22));%0A        %7D catch (IOException e) %7B %7D%0A
     %7D%0A%7D%0A

Delete elasticsearch test data folder after stopping it in tests.