org.umlg.sqlg.test.localdate.TestLocalDate Maven / Gradle / Ivy
package org.umlg.sqlg.test.localdate;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Property;
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.structure.SqlgGraph;
import org.umlg.sqlg.test.BaseTest;
import java.time.*;
import java.time.temporal.ChronoUnit;
import java.util.*;
/**
* Created by pieter on 2015/09/05.
*/
public class TestLocalDate extends BaseTest {
@Test
public void testLocalDateTime() {
LocalDateTime now = LocalDateTime.now();
if (isHsqldb() || isMariaDb()) {
now = now.truncatedTo(ChronoUnit.MILLIS);
}
this.sqlgGraph.addVertex(T.label, "A", "dateTime", now);
this.sqlgGraph.tx().commit();
//Create a new sqlgGraph
try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
List extends Property> properties = sqlgGraph1.traversal().V().hasLabel("A").properties("dateTime").toList();
Assert.assertEquals(1, properties.size());
Assert.assertTrue(properties.get(0).isPresent());
Assert.assertEquals(now, properties.get(0).value());
}
}
@Test
public void testLocalDateTimeUpdate() {
LocalDateTime now = LocalDateTime.now();
if (isHsqldb() || isMariaDb()) {
now = now.truncatedTo(ChronoUnit.MILLIS);
}
Vertex v = this.sqlgGraph.addVertex(T.label, "A", "dateTime", now);
this.sqlgGraph.tx().commit();
v.property("dateTime", now.plusHours(1));
this.sqlgGraph.tx().commit();
//Create a new sqlgGraph
try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
List extends Property>> properties = sqlgGraph1.traversal().V().hasLabel("A").properties("dateTime").toList();
Assert.assertEquals(1, properties.size());
Assert.assertTrue(properties.get(0).isPresent());
Assert.assertEquals(now.plusHours(1), properties.get(0).value());
}
}
@Test
public void testLocalDate() {
LocalDate now = LocalDate.now();
this.sqlgGraph.addVertex(T.label, "A", "date", now);
this.sqlgGraph.tx().commit();
//Create a new sqlgGraph
try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
List extends Property> properties = sqlgGraph1.traversal().V().hasLabel("A").properties("date").toList();
Assert.assertEquals(1, properties.size());
Assert.assertTrue(properties.get(0).isPresent());
Assert.assertEquals(now, properties.get(0).value());
}
}
@Test
public void testLocalTime() {
LocalTime now = LocalTime.now();
this.sqlgGraph.addVertex(T.label, "A", "time", now);
this.sqlgGraph.tx().commit();
//Create a new sqlgGraph
try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
List extends Property> properties = sqlgGraph1.traversal().V().hasLabel("A").properties("time").toList();
Assert.assertEquals(1, properties.size());
Assert.assertTrue(properties.get(0).isPresent());
LocalTime value = properties.get(0).value();
Assert.assertEquals(now.toSecondOfDay(), value.toSecondOfDay());
}
}
@Test
public void testZonedDateTime() {
ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai");
ZonedDateTime zonedDateTimeAGT = ZonedDateTime.of(LocalDateTime.now(), zoneIdShanghai);
if (isHsqldb() || isMariaDb()) {
zonedDateTimeAGT = zonedDateTimeAGT.truncatedTo(ChronoUnit.MILLIS);
}
this.sqlgGraph.addVertex(T.label, "A", "zonedDateTime", zonedDateTimeAGT);
this.sqlgGraph.tx().commit();
//Create a new sqlgGraph
try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
List extends Property> properties = sqlgGraph1.traversal().V().hasLabel("A").properties("zonedDateTime").toList();
Assert.assertEquals(1, properties.size());
Assert.assertTrue(properties.get(0).isPresent());
ZonedDateTime value = properties.get(0).value();
Assert.assertEquals(zonedDateTimeAGT, value);
}
}
@Test
public void testDuration() {
Duration duration = Duration.ofHours(5);
this.sqlgGraph.addVertex(T.label, "A", "duration", duration);
this.sqlgGraph.tx().commit();
//Create a new sqlgGraph
try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
List extends Property> properties = sqlgGraph1.traversal().V().hasLabel("A").properties("duration").toList();
Assert.assertEquals(1, properties.size());
Assert.assertTrue(properties.get(0).isPresent());
Assert.assertEquals(duration, properties.get(0).value());
}
}
@Test
public void testPeriod() {
Period period = Period.of(2016, 5, 5);
this.sqlgGraph.addVertex(T.label, "A", "period", period);
this.sqlgGraph.tx().commit();
//Create a new sqlgGraph
try (SqlgGraph sqlgGraph1 = SqlgGraph.open(configuration)) {
List extends Property> properties = sqlgGraph1.traversal().V().hasLabel("A").properties("period").toList();
Assert.assertEquals(1, properties.size());
Assert.assertTrue(properties.get(0).isPresent());
Assert.assertEquals(period, properties.get(0).value());
}
}
@Test
public void testLocalDateVertex() {
ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai");
ZonedDateTime zonedDateTimeAGT = ZonedDateTime.of(LocalDateTime.now(), zoneIdShanghai);
if (isHsqldb() || isMariaDb()) {
zonedDateTimeAGT = zonedDateTimeAGT.truncatedTo(ChronoUnit.MILLIS);
}
Vertex a4 = this.sqlgGraph.addVertex(T.label, "A", "andReBornAgain", zonedDateTimeAGT);
LocalDate now = LocalDate.now();
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "born", now);
LocalDateTime now1 = LocalDateTime.now();
if (isHsqldb() || isMariaDb()) {
now1 = now1.truncatedTo(ChronoUnit.MILLIS);
}
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "bornAgain", now1);
ZoneId zoneIdHarare = ZoneId.of("Africa/Harare");
ZonedDateTime zonedDateTimeAGTHarare = ZonedDateTime.of(LocalDateTime.now(), zoneIdHarare);
if (isHsqldb() || isMariaDb()) {
zonedDateTimeAGTHarare = zonedDateTimeAGTHarare.truncatedTo(ChronoUnit.MILLIS);
}
Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "andBornAgain", zonedDateTimeAGTHarare);
LocalTime now2 = LocalTime.now();
if (isHsqldb() || isMariaDb()) {
now2 = now2.truncatedTo(ChronoUnit.MILLIS);
}
Vertex a5 = this.sqlgGraph.addVertex(T.label, "A", "time", now2);
this.sqlgGraph.tx().commit();
LocalDate ld = this.sqlgGraph.traversal().V(a1.id()).next().value("born");
Assert.assertEquals(now, ld);
LocalDateTime ldt = this.sqlgGraph.traversal().V(a2.id()).next().value("bornAgain");
Assert.assertEquals(now1, ldt);
ZonedDateTime zonedDateTime = this.sqlgGraph.traversal().V(a3.id()).next().value("andBornAgain");
Assert.assertEquals(zonedDateTimeAGTHarare, zonedDateTime);
zonedDateTime = this.sqlgGraph.traversal().V(a4.id()).next().value("andReBornAgain");
Assert.assertEquals(zonedDateTimeAGT, zonedDateTime);
LocalTime localTime = this.sqlgGraph.traversal().V(a5.id()).next().value("time");
Assert.assertEquals(now2.toSecondOfDay(), localTime.toSecondOfDay());
}
@Test
public void testLocalDateManyTimes() {
ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai");
ZonedDateTime zonedDateTimeAGT = ZonedDateTime.of(LocalDateTime.now(), zoneIdShanghai);
if (isHsqldb() || isMariaDb()) {
zonedDateTimeAGT = zonedDateTimeAGT.truncatedTo(ChronoUnit.MILLIS);
}
ZoneId zoneIdHarare = ZoneId.of("Africa/Harare");
ZonedDateTime zonedDateTimeAGTHarare = ZonedDateTime.of(LocalDateTime.now(), zoneIdHarare);
if (isHsqldb() || isMariaDb()) {
zonedDateTimeAGTHarare = zonedDateTimeAGTHarare.truncatedTo(ChronoUnit.MILLIS);
}
LocalDate now = LocalDate.now();
LocalDateTime now1 = LocalDateTime.now();
if (isHsqldb() || isMariaDb()) {
now1 = now1.truncatedTo(ChronoUnit.MILLIS);
}
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A",
"created1", now,
"created2", now1,
"created3", zonedDateTimeAGT,
"created4", zonedDateTimeAGTHarare
);
this.sqlgGraph.tx().commit();
Assert.assertEquals(now, this.sqlgGraph.traversal().V(a1.id()).next().value("created1"));
Assert.assertEquals(now1, this.sqlgGraph.traversal().V(a1.id()).next().value("created2"));
Assert.assertEquals(zonedDateTimeAGT, this.sqlgGraph.traversal().V(a1.id()).next().value("created3"));
Assert.assertEquals(zonedDateTimeAGTHarare, this.sqlgGraph.traversal().V(a1.id()).next().value("created4"));
}
@Test
public void testLocalDateEdge() {
ZoneId zoneIdShanghai = ZoneId.of("Asia/Shanghai");
ZonedDateTime zonedDateTimeAGT = ZonedDateTime.of(LocalDateTime.now(), zoneIdShanghai);
if (isHsqldb() || isMariaDb()) {
zonedDateTimeAGT = zonedDateTimeAGT.truncatedTo(ChronoUnit.MILLIS);
}
ZoneId zoneIdHarare = ZoneId.of("Africa/Harare");
ZonedDateTime zonedDateTimeAGTHarare = ZonedDateTime.of(LocalDateTime.now(), zoneIdHarare);
if (isHsqldb() || isMariaDb()) {
zonedDateTimeAGTHarare = zonedDateTimeAGTHarare.truncatedTo(ChronoUnit.MILLIS);
}
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1", "born", LocalDate.now());
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2", "born", LocalDate.now());
LocalDate now = LocalDate.now();
LocalDateTime now1 = LocalDateTime.now();
if (isHsqldb() || isMariaDb()) {
now1 = now1.truncatedTo(ChronoUnit.MILLIS);
}
LocalTime time = LocalTime.now();
Edge e1 = a1.addEdge("halo", a2,
"created1", now,
"created2", now1,
"created3", zonedDateTimeAGT,
"created4", zonedDateTimeAGTHarare,
"created5", time
);
this.sqlgGraph.tx().commit();
Assert.assertEquals(now, this.sqlgGraph.traversal().E(e1.id()).next().value("created1"));
Assert.assertEquals(now1, this.sqlgGraph.traversal().E(e1.id()).next().value("created2"));
Assert.assertEquals(zonedDateTimeAGT, this.sqlgGraph.traversal().E(e1.id()).next().value("created3"));
Assert.assertEquals(zonedDateTimeAGTHarare, this.sqlgGraph.traversal().E(e1.id()).next().value("created4"));
Assert.assertEquals(time.toSecondOfDay(), this.sqlgGraph.traversal().E(e1.id()).next().value("created5").toSecondOfDay());
}
@Test
public void testPeriod2() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "period", Period.of(1, 1, 1));
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "period", Period.of(11, 11, 11));
a1.addEdge("test", a2, "period", Period.of(22, 10, 22));
this.sqlgGraph.tx().commit();
Assert.assertEquals(Period.of(1,1,1), this.sqlgGraph.traversal().V(a1.id()).next().value("period"));
Assert.assertEquals(Period.of(11,11,11), this.sqlgGraph.traversal().V(a2.id()).next().value("period"));
Assert.assertEquals(Period.of(22,10,22), this.sqlgGraph.traversal().V(a1.id()).outE().next().value("period"));
Assert.assertEquals(Period.of(11, 11, 11), this.sqlgGraph.traversal().V(a1.id()).out().next().value("period"));
}
@Test
public void testDuration2() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "duration", Duration.ofSeconds(1, 1));
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "duration", Duration.ofSeconds(1, 1));
a1.addEdge("test", a2, "duration", Duration.ofSeconds(2, 2));
this.sqlgGraph.tx().commit();
Assert.assertEquals(Duration.ofSeconds(1, 1), this.sqlgGraph.traversal().V(a1.id()).next().value("duration"));
Assert.assertEquals(Duration.ofSeconds(1, 1), this.sqlgGraph.traversal().V(a2.id()).next().value("duration"));
Assert.assertEquals(Duration.ofSeconds(2, 2), this.sqlgGraph.traversal().V(a1.id()).outE().next().value("duration"));
Assert.assertEquals(Duration.ofSeconds(1, 1), this.sqlgGraph.traversal().V(a1.id()).out().next().value("duration"));
}
@Test
public void testLabelledZonedDate() throws InterruptedException {
ZonedDateTime now = ZonedDateTime.now();
if (isHsqldb() || isMariaDb()) {
now = now.truncatedTo(ChronoUnit.MILLIS);
}
Thread.sleep(1000);
ZonedDateTime now1 = ZonedDateTime.now();
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "now", now);
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "now", now);
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "now", now);
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "now", now);
Vertex c2 = this.sqlgGraph.addVertex(T.label, "C", "now", now);
Vertex c3 = this.sqlgGraph.addVertex(T.label, "C", "now", now);
Vertex c4 = this.sqlgGraph.addVertex(T.label, "C", "now", now);
a1.addEdge("ab", b1, "now1", now1);
a1.addEdge("ab", b2, "now1", now1);
b1.addEdge("bc", c1, "now1", now1);
b1.addEdge("bc", c2, "now1", now1);
b2.addEdge("bc", c3, "now1", now1);
b2.addEdge("bc", c4, "now1", now1);
this.sqlgGraph.tx().commit();
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy