package org.elasticgremlin.elastic;

import org.apache.commons.configuration.BaseConfiguration;
import org.apache.tinkerpop.gremlin.LoadGraphWith;
import org.elasticgremlin.ElasticGraphGraphProvider;
import org.elasticgremlin.elasticservice.ElasticService;
import org.elasticgremlin.structure.ElasticGraph;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.*;
import org.apache.tinkerpop.gremlin.structure.*;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.junit.Test;

import java.io.IOException;
import java.lang.reflect.Method;

public class TemporaryTests {
    /*@Test
    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
    public void shouldPersistDataOnClose() throws Exception {
        final GraphProvider graphProvider = new ElasticGraphGraphProvider();
        Graph graph = graphProvider.standardTestGraph(this.getClass(), "shouldPersistDataOnClose");;

        final Vertex v = graph.addVertex();
        final Vertex u = graph.addVertex();
        if (graph.features().edge().properties().supportsStringValues()) {
            v.property("name", "marko");
            u.property("name", "pavel");
        }

        final Edge e = v.addEdge(graphProvider.convertLabel("collaborator"), u);
        if (graph.features().edge().properties().supportsStringValues())
            e.property("location", "internet");

        graph.close();

        final Graph reopenedGraph = graphProvider.standardTestGraph(this.getClass(), "shouldPersistDataOnClose");

        if (graph.features().vertex().properties().supportsStringValues()) {
            reopenedGraph.vertices().forEachRemaining(vertex -> {
                assertTrue(vertex.property("name").value().equals("marko") || vertex.property("name").value().equals("pavel"));
            });
        }

        reopenedGraph.edges().forEachRemaining(edge -> {
            assertEquals(graphProvider.convertId("collaborator"), edge.label());
            if (graph.features().edge().properties().supportsStringValues())
                assertEquals("internet", edge.property("location").value());
        });

        graphProvider.clear(reopenedGraph, graphProvider.standardGraphConfiguration(this.getClass(), "shouldPersistDataOnClose"));
    }*/

    @Test
    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
    public void testToPassTests() throws IOException, NoSuchMethodException {
        BaseConfiguration config = new BaseConfiguration();
        config.addProperty("elasticsearch.cluster.name", "testgraph");
        String indexName = "graphtest14";
        config.addProperty("elasticsearch.index.name", indexName.toLowerCase());
        config.addProperty("elasticsearch.refresh", true);
        config.addProperty("elasticsearch.client", ElasticService.ClientType.NODE);
        ElasticGraph graph = new ElasticGraph(config);
        graph.elasticService.clearAllData();
        ElasticGraphGraphProvider elasticGraphProvider = new ElasticGraphGraphProvider();
        Method m = this.getClass().getMethod("testToPassTests");
        LoadGraphWith[] loadGraphWiths = m.getAnnotationsByType(LoadGraphWith.class);
        elasticGraphProvider.loadGraphData(graph, loadGraphWiths[0], this.getClass(), m.getName());
        GraphTraversalSource g = graph.traversal();


        /*GraphTraversal<Vertex, Path> iter = g.V().out().outE().inV().inE().inV().both().values("name").path();
        printTraversalForm(iter);
        //iter.profile().cap(TraversalMetrics.METRICS_KEY);

        System.out.println("iter = " + iter);
        while(iter.hasNext()){
            Object next = iter.next();
            String s = next.toString();
            System.out.println("s = " + s);
        }*/

        GraphTraversal<Vertex, Edge> iter2 = graph.traversal().V().has("name", "marko").outE("knows").as("e").inV().has("name", "vadas").<Edge>select("e");
        System.out.println(iter2.id());
        printTraversalForm(iter2);
        //iter.profile().cap(TraversalMetrics.METRICS_KEY);

        System.out.println("iter2 = " + iter2);
        while(iter2.hasNext()){
            Object next = iter2.next();
            String s = next.toString();
            System.out.println("s = " + s);
        }


        graph.elasticService.client.admin().indices().delete(new DeleteIndexRequest(indexName)).actionGet();
        graph.close();
    }

    public void printTraversalForm(final Traversal traversal) {
        System.out.println("   pre-strategy:" + traversal);
        traversal.hasNext();
        System.out.println("  post-strategy:" + traversal);
    }
}

@@ -155,125 +155,149 @@
 org.
-elasticgremlin.ElasticGraphGraphProvider;%0Aimport org.elasticgremlin.elasticservice.ElasticService;%0Aimport org.elastic
+apache.tinkerpop.gremlin.process.traversal.*;%0Aimport org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.*;%0Aimport org.apache.tinkerpop.
 grem
@@ -310,28 +310,22 @@
 ructure.
-ElasticGraph
+Vertex
 ;%0Aimport
@@ -333,157 +333,125 @@
 org.
-apache.tinkerpop.gremlin.process.traversal.Traversal;%0Aimport org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.*;%0Aimport org.apache.tinkerpop.
+elasticgremlin.ElasticGraphGraphProvider;%0Aimport org.elasticgremlin.elasticservice.ElasticService;%0Aimport org.elastic
 grem
@@ -464,17 +464,28 @@
 ructure.
-*
+ElasticGraph
 ;%0Aimport
@@ -3211,16 +3211,18 @@
         
+//
 elasticG
@@ -3358,25 +3358,24 @@
 sal();%0A%0A
-%0A
         
 /*GraphT
@@ -3370,419 +3370,170 @@
     
-/*GraphTraversal%3CVertex, Path%3E iter = g.V().out().outE().inV().inE().inV().both().values(%22name%22).path();%0A        printTraversalForm(iter);%0A        //iter.profile().cap(TraversalMetrics.METRICS_KEY);%0A%0A        System.out.println(%22iter = %22 + iter);%0A        while(iter.hasNext())%7B%0A            Object next = iter.next();%0A            String s = next.toString();%0A            System.out.println(%22s = %22 + s);%0A        %7D*/
+Vertex vertex1 = graph.addVertex();%0A        Vertex vertex2 = graph.addVertex();%0A        vertex1.addEdge(%22bla%22, vertex2);%0A        vertex2.addEdge(%22bla%22, vertex1);%0A
 %0A%0A  
@@ -3565,170 +3565,53 @@
 ex, 
-Edge
+Vertex
 %3E iter
-2
  = g
-raph.traversal().V().has(%22name%22, %22marko%22).outE(%22knows%22).as(%22e%22).inV().has(%22name%22, %22vadas%22).%3CEdge%3Eselect(%22e%22);%0A        System.out.println(iter2.id()
+.V().repeat(__.out()).times(8
 );%0A 
@@ -3636,25 +3636,24 @@
 salForm(iter
-2
 );%0A        /
@@ -3736,17 +3736,16 @@
 ln(%22iter
-2
  = %22 + i
@@ -3747,17 +3747,16 @@
 %22 + iter
-2
 );%0A     
@@ -3768,17 +3768,16 @@
 ile(iter
-2
 .hasNext
@@ -3811,17 +3811,16 @@
 t = iter
-2
 .next();
@@ -3916,16 +3916,17 @@
     %7D%0A%0A%0A
+%0A
         

test inner traversals