Coverage Summary for Class: TestTopology (org.umlg.sqlg.test.topology)

Class Method, % Line, %
TestTopology 0% (0/11) 0% (0/141)
TestTopology$1 0% (0/1) 0% (0/2)
TestTopology$10 0% (0/1) 0% (0/3)
TestTopology$2 0% (0/1) 0% (0/2)
TestTopology$3 0% (0/1) 0% (0/2)
TestTopology$4 0% (0/1) 0% (0/2)
TestTopology$5 0% (0/1) 0% (0/2)
TestTopology$6 0% (0/1) 0% (0/2)
TestTopology$7 0% (0/1) 0% (0/2)
TestTopology$8 0% (0/1) 0% (0/3)
TestTopology$9 0% (0/1) 0% (0/3)
Total 0% (0/21) 0% (0/164)


 package org.umlg.sqlg.test.topology;
 
 import org.apache.commons.collections4.set.ListOrderedSet;
 import org.apache.tinkerpop.gremlin.process.traversal.Order;
 import org.apache.tinkerpop.gremlin.process.traversal.P;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.structure.Direction;
 import org.apache.tinkerpop.gremlin.structure.Edge;
 import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 import org.junit.Assert;
 import org.junit.Test;
 import org.umlg.sqlg.structure.Multiplicity;
 import org.umlg.sqlg.structure.PropertyDefinition;
 import org.umlg.sqlg.structure.PropertyType;
 import org.umlg.sqlg.structure.topology.*;
 import org.umlg.sqlg.test.BaseTest;
 
 import java.util.*;
 
 /**
  * Date: 2016/06/27
  * Time: 1:40 PM
  */
 public class TestTopology extends BaseTest {
 
     @Test
     public void testDefaultLiteralAndCheckConstraintOnNewColumn() {
         this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("A", new HashMap<>() {{
             put("col1", PropertyDefinition.of(PropertyType.STRING));
         }});
         this.sqlgGraph.tx().commit();
         this.sqlgGraph.addVertex(T.label, "A", "col1", "value1");
         this.sqlgGraph.tx().commit();
         VertexLabel aVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().getVertexLabel("A").orElseThrow();
         aVertexLabel.ensurePropertiesExist(new HashMap<>() {{
             put("col2", PropertyDefinition.of(PropertyType.STRING, Multiplicity.of(), "'aaa'", "(" + sqlgGraph.getSqlDialect().maybeWrapInQoutes("col2") + " <> 'a')"));
         }});
         this.sqlgGraph.tx().commit();
 
         PropertyColumn col2PropertyColumn = this.sqlgGraph.getTopology().getPublicSchema().getVertexLabel("A").orElseThrow().getProperty("col2").orElseThrow();
         Assert.assertEquals("(" + sqlgGraph.getSqlDialect().maybeWrapInQoutes("col2") + " <> 'a')", col2PropertyColumn.getPropertyDefinition().checkConstraint());
         Assert.assertEquals("'aaa'", col2PropertyColumn.getPropertyDefinition().defaultLiteral());
 
         Vertex a = this.sqlgGraph.traversal().V().hasLabel("A").tryNext().orElseThrow();
         Assert.assertEquals("aaa", a.value("col2"));
 
         boolean failure = false;
         try {
             this.sqlgGraph.addVertex(T.label, "A", "col2", "a");
         } catch (RuntimeException e) {
             this.sqlgGraph.tx().rollback();
             failure = true;
         }
         Assert.assertTrue(failure);
 
         VertexLabel bVertexLabel = this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("B");
         aVertexLabel.ensureEdgeLabelExist("ab", bVertexLabel, new HashMap<>() {{
             put("col1", PropertyDefinition.of(PropertyType.STRING, Multiplicity.of(1, 1)));
         }});
         this.sqlgGraph.tx().commit();
         Vertex b = this.sqlgGraph.addVertex(T.label, "B");
         a.addEdge("ab", b, "col1", "value1");
         this.sqlgGraph.tx().commit();
 
         EdgeLabel edgeLabel = aVertexLabel.getOutEdgeLabel("ab").orElseThrow();
         edgeLabel.ensurePropertiesExist(new HashMap<>() {{
             put("col2", PropertyDefinition.of(PropertyType.STRING, Multiplicity.of(), "'aaa'", "(" + sqlgGraph.getSqlDialect().maybeWrapInQoutes("col2") + " <> 'a')"));
         }});
 
         this.sqlgGraph.tx().commit();
         Edge e = this.sqlgGraph.traversal().E().tryNext().orElseThrow();
         Assert.assertEquals("value1", e.value("col1"));
         Assert.assertEquals("aaa", e.value("col2"));
     }
 
     @Test
     public void testPropertyDefinitionTemp() {
         this.sqlgGraph.getTopology().getPublicSchema().ensureVertexLabelExist("A", new HashMap<>() {{
             put("col1", PropertyDefinition.of(PropertyType.STRING, Multiplicity.of(1, 1)));
         }});
         this.sqlgGraph.addVertex(T.label, "A", "col1", "value1");
         this.sqlgGraph.tx().commit();
         PropertyColumn propertyColumn = this.sqlgGraph.getTopology().getPublicSchema()
                 .getVertexLabel("A").orElseThrow()
                 .getProperty("col1").orElseThrow();
         Assert.assertFalse(propertyColumn.getPropertyDefinition().temp());
         this.sqlgGraph.addVertex(T.label, "A", "col1", "asd");
         propertyColumn = this.sqlgGraph.getTopology().getPublicSchema()
                 .getVertexLabel("A").orElseThrow()
                 .getProperty("col1").orElseThrow();
         Assert.assertFalse(propertyColumn.getPropertyDefinition().temp());
         this.sqlgGraph.tx().commit();
     }
 
     @Test
     public void testEnsureAdditionalPropertyExist() {
         Schema publicSchema = this.sqlgGraph.getTopology().getPublicSchema();
         publicSchema.ensureVertexLabelExist("A", new HashMap<>() {{
             put("a", PropertyDefinition.of(PropertyType.STRING));
         }});
         this.sqlgGraph.tx().commit();
         VertexLabel aVertexLabel = publicSchema.getVertexLabel("A").orElseThrow();
         aVertexLabel.ensurePropertiesExist(new HashMap<>() {{
             put("b", PropertyDefinition.of(PropertyType.STRING));
         }});
         this.sqlgGraph.tx().commit();
 
         publicSchema = this.sqlgGraph.getTopology().getPublicSchema();
         aVertexLabel = publicSchema.getVertexLabel("A").orElseThrow();
         Assert.assertTrue(aVertexLabel.getProperty("a").isPresent());
         Assert.assertTrue(aVertexLabel.getProperty("b").isPresent());
     }
 
     @Test
     public void testDotInLabelName() {
         Vertex hand = this.sqlgGraph.addVertex(T.label, "A.A", "name", "a");
         Vertex finger = this.sqlgGraph.addVertex(T.label, "A.B.interface", "name", "b");
         hand.addEdge("a_b", finger);
         this.sqlgGraph.tx().commit();
 
         List<Vertex> children = sqlgGraph.traversal().V(hand)
                 .out("a_b")
                 .toList();
         Assert.assertEquals(1, children.size());
     }
 
     @Test
     public void testDotInLabelNameUserSuppliedIdentifiers() {
         Schema aSchema = this.sqlgGraph.getTopology().ensureSchemaExist("A");
         VertexLabel testVertexLabel = aSchema.ensureVertexLabelExist(
                 "TestA",
                 new LinkedHashMap<>() {{
                     put("uid", PropertyDefinition.of(PropertyType.varChar(100)));
                     put("name1", PropertyDefinition.of(PropertyType.STRING));
                 }},
                 ListOrderedSet.listOrderedSet(Collections.singletonList("uid"))
         );
         VertexLabel testTestVertexLabel = aSchema.ensureVertexLabelExist(
                 "TestB",
                 new LinkedHashMap<>() {{
                     put("uid", PropertyDefinition.of(PropertyType.varChar(100)));
                     put("name1", PropertyDefinition.of(PropertyType.STRING));
                 }},
                 ListOrderedSet.listOrderedSet(Collections.singletonList("uid"))
         );
         Vertex v1 = this.sqlgGraph.addVertex(T.label, "A.TestA", "uid", UUID.randomUUID().toString(), "name1", "a");
         Vertex v2 = this.sqlgGraph.addVertex(T.label, "A.Test.TestA", "uid", UUID.randomUUID().toString(), "name1", "a");
         this.sqlgGraph.tx().commit();
 
         this.sqlgGraph.getTopology().ensureEdgeLabelExist(
                 "e1",
                 testVertexLabel,
                 testTestVertexLabel,
                 new LinkedHashMap<>() {{
                     put("uid", PropertyDefinition.of(PropertyType.varChar(100)));
                     put("name1", PropertyDefinition.of(PropertyType.STRING));
                 }},
                 ListOrderedSet.listOrderedSet(Collections.singletonList("uid"))
         );
         this.sqlgGraph.tx().commit();
         v1.addEdge("e1", v2, "uid", UUID.randomUUID().toString(), "name1", "a");
         this.sqlgGraph.tx().commit();
 
         List<Vertex> vertices = this.sqlgGraph.traversal().V().hasLabel("A.TestA").out().toList();
         Assert.assertEquals(1, vertices.size());
         Assert.assertEquals(v2, vertices.get(0));
     }
 
     @Test
     public void failTest() {
         Vertex a1 = this.sqlgGraph.addVertex(T.label, "MySchema.A", "name", "A");
         Vertex b1 = this.sqlgGraph.addVertex(T.label, "MySchema.B", "name", "B");
         a1.addEdge("ab", b1);
         this.sqlgGraph.tx().commit();
 
         //works
         Assert.assertEquals(2,
                 this.sqlgGraph.topology()
                         .V().hasLabel("sqlg_schema.schema").has("name", P.within("MySchema")).as("schema").values("name").as("schemaName").select("schema")
                         .out("schema_vertex")
                         .count().next().intValue());
 
         //fails, was bug no longer fails
         Assert.assertTrue(
                 this.sqlgGraph.topology()
                         .V().hasLabel("sqlg_schema.schema").has("name", P.within("MySchema")).as("schema").values("name").as("schemaName").select("schema")
                         .out("schema_vertex")
                         .hasNext());
     }
 
     @Test
     public void testTopologyTraversalWithOrderBy() {
         this.sqlgGraph.addVertex(T.label, "A");
         this.sqlgGraph.addVertex(T.label, "B");
         this.sqlgGraph.addVertex(T.label, "C");
         this.sqlgGraph.tx().commit();
         List<Vertex> vertices = this.sqlgGraph.topology().V().hasLabel("sqlg_schema.schema").out("schema_vertex").order().by("name", Order.desc).toList();
         Assert.assertEquals("A", vertices.get(2).value("name"));
         Assert.assertEquals("B", vertices.get(1).value("name"));
         Assert.assertEquals("C", vertices.get(0).value("name"));
     }
 
     @Test
     public void testTopologyTraversal() {
         Vertex gis = this.sqlgGraph.addVertex(T.label, "Gis", "name", "HaloGis1");
         Vertex something = this.sqlgGraph.addVertex(T.label, "Something", "name", "Something1");
         gis.addEdge("testEdge", something, "edgeProperty", "asdasd");
         this.sqlgGraph.tx().commit();
         Assert.assertEquals(2, this.sqlgGraph.topology().V().hasLabel("sqlg_schema.schema").out("schema_vertex").count().next().intValue());
         Assert.assertEquals(2, this.sqlgGraph.topology().V().hasLabel("sqlg_schema.vertex").in("schema_vertex").count().next().intValue());
         Assert.assertEquals(2, this.sqlgGraph.topology().V().hasLabel("sqlg_schema.vertex").out("vertex_property").count().next().intValue());
         Assert.assertEquals(2, this.sqlgGraph.topology().V().hasLabel("sqlg_schema.property").in("vertex_property").count().next().intValue());
         Assert.assertEquals(1, this.sqlgGraph.topology().V().hasLabel("sqlg_schema.property").in("edge_property").count().next().intValue());
 
         Vertex v = this.sqlgGraph.topology().V().hasLabel("sqlg_schema.schema").has("name", this.sqlgGraph.getSqlDialect().getPublicSchema()).next();
         Assert.assertTrue(v.edges(Direction.OUT, "schema_vertex").hasNext());
 
         Assert.assertEquals(2, this.sqlgGraph.topology().V().hasLabel("sqlg_schema.schema").as("schema").select("schema").out("schema_vertex").count().next().intValue());
         Assert.assertEquals(2, this.sqlgGraph.topology().V().hasLabel("sqlg_schema.schema").as("schema").values("name").as("schemaName").select("schema").out("schema_vertex").count().next().intValue());
         Assert.assertTrue(this.sqlgGraph.topology().V().hasLabel("sqlg_schema.schema").as("schema").values("name").as("schemaName").select("schema").out("schema_vertex").hasNext());
 
         Assert.assertEquals("testEdge", this.sqlgGraph.topology().V().hasLabel("sqlg_schema.property").in("edge_property").values("name").next());
     }
 
 
     //    This test a bug in rollback on edges.
     @Test
     public void testRollback() {
         loadModern();
         final Traversal<Vertex, Edge> traversal = this.sqlgGraph.traversal().V().aggregate("x").as("a").select("x").unfold().addE("existsWith").to("a").property("time", "now");
         IteratorUtils.asList(traversal);
         this.sqlgGraph.tx().rollback();
     }
 
     @Test
     public void testAddColumns(){
     	//Create Schema
         Topology topology = sqlgGraph.getTopology();
         topology.ensureSchemaExist("TEST");
 
         Map<String, Object> columns = new HashMap<>();
         columns.put("Test1", "");
         columns.put("Test2", "");
 
         //Add a vertex and remove to create columns
         Vertex v = sqlgGraph.addVertex("TEST" + "." + "TEST_Table", columns);
         v.remove();
         sqlgGraph.tx().commit();
 
         columns = new HashMap<>();
         columns.put("Test1", "T1");
         columns.put("Test2", "T2");
 
         //Add the data
         sqlgGraph.addVertex("TEST" + "." + "TEST_Table", columns);
         sqlgGraph.tx().commit();
 
         //Simulating second load
         //Remove the whole table label
         Optional<VertexLabel> tableVertexLabel = sqlgGraph.getTopology().getVertexLabel("TEST", "TEST_Table");
         tableVertexLabel.ifPresent(vertexLabel -> vertexLabel.remove(false));
 
         columns = new HashMap<>();
         columns.put("Test1", "");
         columns.put("Test2", "");
         columns.put("Test3", "");
 
         //Add a vertex with more columns than previously had
         v = sqlgGraph.addVertex("TEST" + "." + "TEST_Table", columns);
         v.remove();
         sqlgGraph.tx().commit();
     }
 }