gt:         final CloudView t0 = dimension0.time(0l);
context: package org.kevoree.modeling.traversal;
  
  import org.junit.Assert;
  import org.junit.Test;
  import org.kevoree.modeling.KCallback;
  import org.kevoree.modeling.KObject;
  import org.kevoree.modeling.meta.KMetaReference;
  import org.kevoree.modeling.cloudmodel.CloudModel;
  import org.kevoree.modeling.cloudmodel.CloudUniverse;
  import org.kevoree.modeling.cloudmodel.CloudView;
  import org.kevoree.modeling.cloudmodel.Element;
  import org.kevoree.modeling.cloudmodel.Node;
  import org.kevoree.modeling.cloudmodel.meta.MetaNode;
  
  /**
   * Created by thomas on 19/12/14.
   */
  public class TraversalTest {
  
      @Test
      public void simpleTraversalTest() {
          final CloudModel universe = new CloudModel();
          universe.connect(null);
          final CloudUniverse dimension0 = universe.newUniverse();
          final CloudView t0 = dimension0.time(0l);
  
          final Node node0 = t0.createNode();
          final Element elem0_0 = t0.createElement();
          node0.setElement(elem0_0);
  
          t0.setRoot(node0, new KCallback<Throwable>() {
              @Override
              public void on(Throwable throwable) {
  
                  final Node node1 = t0.createNode();
                  node1.setName("child1");
                  final Element elem1_0 = t0.createElement();
                  node1.setElement(elem1_0);
  
                  final Node node2 = t0.createNode();
                  node2.setName("child2");
                  final Element elem2_0 = t0.createElement();
                  node2.setElement(elem2_0);
  
                  node0.addChildren(node1);
                  node0.addChildren(node2);
  
                  // traversal promise
                  node0.traversal().traverse((KMetaReference) node0.metaClass().metaByName("children")).then(new KCallback<KObject[]>() {
                      @Override
                      public void on(KObject[] kObjects) {
                          Assert.assertEquals(kObjects.length, 2);
                      }
                  });
  
                  node0.traversal().traverse((KMetaReference) node0.metaClass().metaByName("children")).withAttribute(MetaNode.ATT_NAME, "child*").map(MetaNode.ATT_NAME, new KCallback<Object[]>() {
                      @Override
                      public void on(Object[] objects) {
                          Assert.assertEquals(objects.length, 2);
                      }
                  });
  
                  node0.traversal().traverse((KMetaReference) node0.metaClass().metaByName("children")).withAttribute(MetaNode.ATT_NAME, "child1").map(MetaNode.ATT_NAME, new KCallback<Object[]>() {
                      @Override
                      public void on(Object[] objects) {
                          Assert.assertEquals(objects.length, 1);
                          Assert.assertEquals(objects[0], "child1");
                      }
                  });
  
                  node0.traversal().traverse((KMetaReference) node0.metaClass().metaByName("children")).withoutAttribute(MetaNode.ATT_NAME, "child1").map(MetaNode.ATT_NAME, new KCallback<Object[]>() {
                      @Override
                      public void on(Object[] objects) {
                          Assert.assertEquals(objects.length, 1);
                          Assert.assertEquals(objects[0], "child2");
                      }
                  });
  
                  node0.traversal().traverse((KMetaReference) node0.metaClass().metaByName("children")).withAttribute(MetaNode.ATT_NAME, null).map(MetaNode.ATT_NAME, new KCallback<Object[]>() {
                      @Override
                      public void on(Object[] objects) {
                          Assert.assertEquals(objects.length, 0);
                      }
                  });
  
                  node0.traversal().traverse((KMetaReference) node0.metaClass().metaByName("children")).withAttribute(MetaNode.ATT_NAME, "*").map(MetaNode.ATT_NAME, new KCallback<Object[]>() {
                      @Override
                      public void on(Object[] objects) {
                          Assert.assertEquals(objects.length, 2);
                      }
                  });
  
                  node0.traversal().traverse((KMetaReference) node0.metaClass().metaByName("children")).withoutAttribute(MetaNode.ATT_NAME, null).map(MetaNode.ATT_NAME, new KCallback<Object[]>() {
                      @Override
                      public void on(Object[] objects) {
                          Assert.assertEquals(objects.length, 2);
                      }
                  });
  
                  node0.traversal().traverse((KMetaReference) node0.metaClass().metaByName("children")).withoutAttribute(MetaNode.ATT_NAME, "*").map(MetaNode.ATT_NAME, new KCallback<Object[]>() {
                      @Override
                      public void on(Object[] objects) {
                          Assert.assertEquals(objects.length, 0);
                      }
                  });
  
              }
          });
      }
  
      @Test
      public void chainedTraversalTest() {
          final CloudModel universe = new CloudModel();
          universe.connect(null);
          final CloudUniverse dimension0 = universe.newUniverse();
          final CloudView t0 = dimension0.time(0l);
  
          final Node node0 = t0.createNode();
          final Element elem0_0 = t0.createElement();
          node0.setElement(elem0_0);
  
          t0.setRoot(node0, new KCallback<Throwable>() {
              @Override
              public void on(Throwable throwable) {
  
                  final Node node1 = t0.createNode();
                  node1.setName("child1");
                  final Element elem1_0 = t0.createElement();
                  elem1_0.setName("child1_elem1");
                  node1.setElement(elem1_0);
  
                  final Node node2 = t0.createNode();
                  node2.setName("child2");
                  final Element elem2_0 = t0.createElement();
                  elem2_0.setName("child2_elem1");
                  node2.setElement(elem2_0);
  
                  node0.addChildren(node1);
                  node0.addChildren(node2);
  
                  // chained traversal promise
                  node0.traversal().traverse((KMetaReference) node0.metaClass().metaByName("children")).traverse((KMetaReference) node0.metaClass().metaByName("element")).then(new KCallback<KObject[]>() {
                      @Override
                      public void on(KObject[] kObjects) {
                          Assert.assertEquals(kObjects.length, 2);
                      }
                  });
  
              }
          });
      }
  
      @Test
      public void filterTest() {
          final CloudModel universe = new CloudModel();
          universe.connect(null);
          final CloudUniverse dimension0 = universe.newUniverse();
          final CloudView t0 = dimension0.time(0l);
  
          final Node node0 = t0.createNode();
          final Element elem0_0 = t0.createElement();
          node0.setElement(elem0_0);
  
          t0.setRoot(node0, new KCallback<Throwable>() {
              @Override
              public void on(Throwable throwable) {
  
                  final Node node1 = t0.createNode();
                  node1.setName("child1");
                  final Element elem1_0 = t0.createElement();
                  elem1_0.setName("child1_elem1");
                  node1.setElement(elem1_0);
  
                  final Node node2 = t0.createNode();
                  node2.setName("child2");
                  final Element elem2_0 = t0.createElement();
                  elem2_0.setName("child2_elem1");
                  node2.setElement(elem2_0);
  
                  node0.addChildren(node1);
                  node0.addChildren(node2);
  
                  // chained traversal promise
                  node0.traversal().traverse((KMetaReference) node0.metaClass().metaByName("children")).filter(new KTraversalFilter() {
                      @Override
                      public boolean filter(KObject obj) {
                          return ((Node) obj).getName().equals("child1");
                      }
                  }).then(new KCallback<KObject[]>() {
                      @Override
                      public void on(KObject[] kObjects) {
                          Assert.assertEquals(kObjects.length, 1);
                          Assert.assertEquals(((Node) kObjects[0]).getName(), "child1");
  
                      }
                  });
  
              }
          });
      }
  
      @Test
      public void parentTest() {
          final CloudModel model = new CloudModel();
          model.connect(new KCallback<Throwable>() {
              @Override
              public void on(Throwable throwable) {
                  final CloudUniverse universe = model.newUniverse();
                  final CloudView t0 = universe.time(0l);
                  final Node node0 = t0.createNode();
                  final Element elem0_0 = t0.createElement();
                  node0.setElement(elem0_0);
                  t0.setRoot(node0, new KCallback<Throwable>() {
                      @Override
                      public void on(Throwable throwable) {
                          final Node node1 = t0.createNode();
                          node1.setName("child1");
                          final Element elem1_0 = t0.createElement();
                          elem1_0.setName("child1_elem1");
                          node1.setElement(elem1_0);
                          final Node node2 = t0.createNode();
                          node2.setName("child2");
                          final Element elem2_0 = t0.createElement();
                          elem2_0.setName("child2_elem1");
                          node2.setElement(elem2_0);
                          node0.addChildren(node1);
                          node0.addChildren(node2);
                      }
                  });
              }
          });
      }
  
      @Test
      public void traverseQueryTest() {
          final CloudModel universe = new CloudModel();
          universe.connect(new KCallback<Throwable>() {
              @Override
              public void on(Throwable throwable) {
                  final CloudUniverse dimension0 = universe.newUniverse();
                  final CloudView t0 = dimension0.time(0l);
  
                  final Node node0 = t0.createNode();
                  final Element elem0_0 = t0.createElement();
                  node0.setElement(elem0_0);
  
                  t0.setRoot(node0, new KCallback<Throwable>() {
                      @Override
                      public void on(Throwable throwable) {
  
                          final Node node1 = t0.createNode();
                          node1.setName("child1");
                          final Element elem1_0 = t0.createElement();
                          elem1_0.setName("child1_elem1");
                          node1.setElement(elem1_0);
  
                          final Node node2 = t0.createNode();
                          node2.setName("child2");
                          final Element elem2_0 = t0.createElement();
                          elem2_0.setName("child2_elem1");
                          node2.setElement(elem2_0);
  
                          node0.addChildren(node1);
                          node0.addChildren(node2);
  
  
                          // chained traversal promise
                          node0.traversal().traverseQuery("children").filter(new KTraversalFilter() {
                              @Override
                              public boolean filter(KObject obj) {
                                  return ((Node) obj).getName().equals("child1");
                              }
                          }).then(new KCallback<KObject[]>() {
                              @Override
                              public void on(KObject[] kObjects) {
                                  Assert.assertEquals(kObjects.length, 1);
                                  Assert.assertEquals(((Node) kObjects[0]).getName(), "child1");
                              }
                          });
  
                          // chained traversal promise
                          node0.traversal().traverseQuery("child*").filter(new KTraversalFilter() {
                              @Override
                              public boolean filter(KObject obj) {
                                  return ((Node) obj).getName().equals("child1");
                              }
                          }).then(new KCallback<KObject[]>() {
                              @Override
                              public void on(KObject[] kObjects) {
                                  Assert.assertEquals(kObjects.length, 1);
                                  Assert.assertEquals(((Node) kObjects[0]).getName(), "child1");
                              }
                          });
  
                          // chained traversal promise
                          node0.traversal().traverseQuery("*children").filter(new KTraversalFilter() {
                              @Override
                              public boolean filter(KObject obj) {
                                  return ((Node) obj).getName().equals("child1");
                              }
                          }).then(new KCallback<KObject[]>() {
                              @Override
                              public void on(KObject[] kObjects) {
                                  Assert.assertEquals(kObjects.length, 1);
                                  Assert.assertEquals(((Node) kObjects[0]).getName(), "child1");
                              }
                          });
  
                          // chained traversal promise
                          node0.traversal().traverseQuery("cc,children").filter(new KTraversalFilter() {
                              @Override
                              public boolean filter(KObject obj) {
                                  return ((Node) obj).getName().equals("child1");
                              }
                          }).then(new KCallback<KObject[]>() {
                              @Override
                              public void on(KObject[] kObjects) {
                                  Assert.assertEquals(kObjects.length, 1);
                                  Assert.assertEquals(((Node) kObjects[0]).getName(), "child1");
                              }
                          });
  
                      }
                  });
              }
          });
      }
  
      @Test
      public void attributeQueryTest() {
          final CloudModel universe = new CloudModel();
          universe.connect(null);
          final CloudUniverse dimension0 = universe.newUniverse();
  