org.umlg.sqlg.test.schema.TestSqlgSchema Maven / Gradle / Ivy
package org.umlg.sqlg.test.schema;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Assert;
import org.junit.Test;
import org.umlg.sqlg.strategy.TopologyStrategy;
import org.umlg.sqlg.structure.SchemaManager;
import org.umlg.sqlg.structure.SqlgGraph;
import org.umlg.sqlg.test.BaseTest;
import java.time.LocalDateTime;
import java.util.List;
/**
* Created by pieter on 2015/12/09.
*/
public class TestSqlgSchema extends BaseTest {
@Test
public void testSqlgSchemaExist() throws Exception {
Vertex person = this.sqlgGraph.addVertex(T.label, "Person", "name", "John");
Vertex dog = this.sqlgGraph.addVertex(T.label, "Dog", "name", "Snowy");
person.addEdge("pet", dog, "createdOn", LocalDateTime.now());
this.sqlgGraph.tx().commit();
Assert.assertEquals(2, this.sqlgGraph.traversal().V().count().next(), 0);
this.sqlgGraph.close();
try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
GraphTraversalSource traversalSource = sqlgGraph1.traversal().withStrategies(
TopologyStrategy.build().selectFrom(
SchemaManager.SQLG_SCHEMA_SCHEMA_TABLES
).create()
);
//Assert the schema
List schemas = traversalSource.V()
.hasLabel(SchemaManager.SQLG_SCHEMA + "." + SchemaManager.SQLG_SCHEMA_SCHEMA)
.toList();
Assert.assertEquals(1, schemas.size());
Assert.assertEquals(sqlgGraph1.getSqlDialect().getPublicSchema(), schemas.get(0).value("name"));
//Assert the vertex labels
List vertexLabels = traversalSource.V()
.hasLabel(SchemaManager.SQLG_SCHEMA + "." + SchemaManager.SQLG_SCHEMA_VERTEX_LABEL)
.toList();
Assert.assertEquals(2, vertexLabels.size());
Assert.assertEquals(1, vertexLabels.stream().filter(v->v.value("name").equals("Person")).count());
Assert.assertEquals(1, vertexLabels.stream().filter(v->v.value("name").equals("Dog")).count());
//Assert the edge labels
List edgeLabels = traversalSource.V()
.hasLabel(SchemaManager.SQLG_SCHEMA + "." + SchemaManager.SQLG_SCHEMA_EDGE_LABEL)
.toList();
Assert.assertEquals(1, edgeLabels.size());
Assert.assertEquals(1, edgeLabels.stream().filter(v->v.value("name").equals("pet")).count());
//Assert the Person's properties
List vertexLabelPersons = traversalSource.V()
.hasLabel(SchemaManager.SQLG_SCHEMA + "." + SchemaManager.SQLG_SCHEMA_VERTEX_LABEL)
.has("name", "Person")
.toList();
Assert.assertEquals(1, vertexLabelPersons.size());
Vertex vertexLabelPerson = vertexLabelPersons.get(0);
List personProperties = traversalSource.V(vertexLabelPerson).out(SchemaManager.SQLG_SCHEMA_VERTEX_PROPERTIES_EDGE).toList();
Assert.assertEquals(1, personProperties.size());
Assert.assertEquals("name", personProperties.get(0).value("name"));
Assert.assertEquals("STRING", personProperties.get(0).value("type"));
//Assert the Dog's properties
List vertexLabelDogs = traversalSource.V()
.hasLabel(SchemaManager.SQLG_SCHEMA + "." + SchemaManager.SQLG_SCHEMA_VERTEX_LABEL)
.has("name", "Dog")
.toList();
Assert.assertEquals(1, vertexLabelDogs.size());
Vertex vertexLabelDog = vertexLabelDogs.get(0);
List dogProperties = traversalSource.V(vertexLabelDog).out(SchemaManager.SQLG_SCHEMA_VERTEX_PROPERTIES_EDGE).toList();
Assert.assertEquals(1, dogProperties.size());
Assert.assertEquals("name", dogProperties.get(0).value("name"));
Assert.assertEquals("STRING", personProperties.get(0).value("type"));
//Assert the pet edge's properties
List edgeLabelPets = traversalSource.V()
.hasLabel(SchemaManager.SQLG_SCHEMA + "." + SchemaManager.SQLG_SCHEMA_EDGE_LABEL)
.has("name", "pet")
.toList();
Assert.assertEquals(1, edgeLabelPets.size());
Vertex edgeLabelPet = edgeLabelPets.get(0);
List petProperties = traversalSource.V(edgeLabelPet).out(SchemaManager.SQLG_SCHEMA_EDGE_PROPERTIES_EDGE).toList();
Assert.assertEquals(1, petProperties.size());
Assert.assertEquals("createdOn", petProperties.get(0).value("name"));
Assert.assertEquals("LOCALDATETIME", petProperties.get(0).value("type"));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy