package com.thinkaurelius.titan.diskstorage.es;

import com.google.common.base.Joiner;
import com.thinkaurelius.titan.StorageSetup;
import com.thinkaurelius.titan.core.TitanGraph;
import com.thinkaurelius.titan.diskstorage.configuration.ModifiableConfiguration;
import com.thinkaurelius.titan.diskstorage.configuration.WriteConfiguration;
import com.thinkaurelius.titan.example.GraphOfTheGodsFactory;
import com.thinkaurelius.titan.graphdb.TitanIndexTest;
import org.junit.Test;

import java.io.File;

import static com.thinkaurelius.titan.diskstorage.es.ElasticSearchIndex.*;
import static com.thinkaurelius.titan.graphdb.configuration.GraphDatabaseConfiguration.*;
import static com.thinkaurelius.titan.BerkeleyStorageSetup.getBerkeleyJEConfiguration;

/**
 * @author Matthias Broecheler (me@matthiasb.com)
 */

public class BerkeleyElasticsearchTest extends TitanIndexTest {

    public BerkeleyElasticsearchTest() {
        super(true, true, true);
    }

    @Override
    public WriteConfiguration getConfiguration() {
        ModifiableConfiguration config = getBerkeleyJEConfiguration();
        //Add index
        config.set(INDEX_BACKEND,"elasticsearch",INDEX);
        config.set(LOCAL_MODE,true,INDEX);
        config.set(CLIENT_ONLY,false,INDEX);
        config.set(INDEX_DIRECTORY,StorageSetup.getHomeDir("es"),INDEX);
        return config.getConfiguration();
    }

    @Override
    public boolean supportsLuceneStyleQueries() {
        return true;
    }

    /**
     * Test {@link com.thinkaurelius.titan.example.GraphOfTheGodsFactory#create(String)}.
     */
    @Test
    public void testGraphOfTheGodsFactoryCreate() {
        String bdbtmp = Joiner.on(File.separator).join("target", "gotgfactory");
        TitanGraph gotg = GraphOfTheGodsFactory.create(bdbtmp);
        TitanIndexTest.assertGraphOfTheGods(gotg);
        gotg.close();
    }
}
@@ -449,16 +449,68 @@
 exTest;%0A
+import com.thinkaurelius.titan.util.system.IOUtils;%0A
 import o
@@ -1341,16 +1341,17 @@
 RECTORY,
+ 
 StorageS
@@ -1372,16 +1372,17 @@
 r(%22es%22),
+ 
 INDEX);%0A
@@ -1419,24 +1419,25 @@
 guration();%0A
+%0A
     %7D%0A%0A    @
@@ -1699,22 +1699,20 @@
         
-String
+File
  bdbtmp 
@@ -1717,46 +1717,24 @@
 p = 
-Joiner.on(File.separator).join
+new File
 (%22target
 %22, %22
@@ -1733,12 +1733,9 @@
 rget
-%22, %22
+/
 gotg
@@ -1745,16 +1745,64 @@
 tory%22);%0A
+        IOUtils.deleteDirectory(bdbtmp, true);%0A%0A
         
@@ -1854,16 +1854,26 @@
 e(bdbtmp
+.getPath()
 );%0A     

Delete graph of gods directory before test run. https://github.com/thinkaurelius/titan/issues/990