use of org.janusgraph.core.attribute.Geoshape in project janusgraph by JanusGraph.
the class GeoToWktConverterTest method testConvertGeoshapeLineToWktString.
@Test
public void testConvertGeoshapeLineToWktString() throws BackendException {
Geoshape l1 = Geoshape.line(Arrays.asList(new double[][] { { 48.9, 35.4 }, { 49.1, 35.6 } }));
String wkt1 = "LINESTRING (48.9 35.4, 49.1 35.6)";
String actualWkt1 = GeoToWktConverter.convertToWktString(l1);
assertEquals(wkt1, actualWkt1);
}
use of org.janusgraph.core.attribute.Geoshape in project janusgraph by JanusGraph.
the class JanusGraphIoTest method assertGeoshape.
private void assertGeoshape(Function<Geoshape, Geoshape> makeGeoshape) {
graph.traversal().E().has("place").toList().forEach(e -> {
assertTrue(e.property("shape").isPresent());
Geoshape place = (Geoshape) e.property("place").value();
Geoshape expected = makeGeoshape.apply(place);
Geoshape actual = (Geoshape) e.property("shape").value();
assertEquals(expected, actual);
});
}
use of org.janusgraph.core.attribute.Geoshape in project janusgraph by JanusGraph.
the class JanusGraphIoTest method addGeoshape.
private void addGeoshape(Function<Geoshape, Geoshape> makeGeoshape) {
JanusGraphTransaction tx = graph.newTransaction();
graph.traversal().E().has("place").toList().forEach(e -> {
Geoshape place = (Geoshape) e.property("place").value();
e.property("shape", makeGeoshape.apply(place));
});
tx.commit();
}
use of org.janusgraph.core.attribute.Geoshape in project janusgraph by JanusGraph.
the class JanusGraphTest method testDataTypes.
/**
* Test the different data types that JanusGraph supports natively and ensure that invalid data types aren't allowed
*/
@Test
public void testDataTypes() {
clopen(option(CUSTOM_ATTRIBUTE_CLASS, "attribute10"), SpecialInt.class.getCanonicalName(), option(CUSTOM_SERIALIZER_CLASS, "attribute10"), SpecialIntSerializer.class.getCanonicalName());
PropertyKey num = makeKey("num", SpecialInt.class);
PropertyKey barr = makeKey("barr", byte[].class);
PropertyKey booleanValue = makeKey("boolval", Boolean.class);
PropertyKey birthday = makeKey("birthday", Instant.class);
PropertyKey location = makeKey("location", Geoshape.class);
PropertyKey boundary = makeKey("boundary", Geoshape.class);
PropertyKey precise = makeKey("precise", Double.class);
PropertyKey any = mgmt.makePropertyKey("any").cardinality(Cardinality.LIST).dataType(Object.class).make();
try {
// Not a valid data type - primitive
makeKey("pint", int.class);
fail();
} catch (IllegalArgumentException ignored) {
}
try {
// Not a valid data type - interface
makeKey("number", Number.class);
fail();
} catch (IllegalArgumentException ignored) {
}
finishSchema();
clopen();
booleanValue = tx.getPropertyKey("boolval");
num = tx.getPropertyKey("num");
barr = tx.getPropertyKey("barr");
birthday = tx.getPropertyKey("birthday");
location = tx.getPropertyKey("location");
boundary = tx.getPropertyKey("boundary");
precise = tx.getPropertyKey("precise");
any = tx.getPropertyKey("any");
assertEquals(Boolean.class, booleanValue.dataType());
assertEquals(byte[].class, barr.dataType());
assertEquals(Object.class, any.dataType());
final Instant c = Instant.ofEpochSecond(1429225756);
final Geoshape point = Geoshape.point(10.0, 10.0);
final Geoshape shape = Geoshape.box(10.0, 10.0, 20.0, 20.0);
JanusGraphVertex v = tx.addVertex();
v.property(n(booleanValue), true);
v.property(VertexProperty.Cardinality.single, n(birthday), c);
v.property(VertexProperty.Cardinality.single, n(num), new SpecialInt(10));
v.property(VertexProperty.Cardinality.single, n(barr), new byte[] { 1, 2, 3, 4 });
v.property(VertexProperty.Cardinality.single, n(location), point);
v.property(VertexProperty.Cardinality.single, n(boundary), shape);
v.property(VertexProperty.Cardinality.single, n(precise), 10.12345);
v.property(n(any), "Hello");
v.property(n(any), 10L);
int[] testArray = { 5, 6, 7 };
v.property(n(any), testArray);
// ######## VERIFICATION ##########
assertTrue(v.<Boolean>value("boolval"));
assertEquals(10, v.<SpecialInt>value("num").getValue());
assertEquals(c, v.value("birthday"));
assertEquals(4, v.<byte[]>value("barr").length);
assertEquals(point, v.<Geoshape>value("location"));
assertEquals(shape, v.<Geoshape>value("boundary"));
assertEquals(10.12345, v.<Double>value("precise"), 0.000001);
assertCount(3, v.properties("any"));
for (Object prop : v.query().labels("any").properties()) {
Object value = ((JanusGraphVertexProperty<?>) prop).value();
if (value instanceof String)
assertEquals("Hello", value);
else if (value instanceof Long)
assertEquals(10L, value);
else if (value.getClass().isArray()) {
assertTrue(Arrays.equals(testArray, (int[]) value));
} else
fail();
}
clopen();
v = getV(tx, v);
// ######## VERIFICATION (copied from above) ##########
assertTrue(v.<Boolean>value("boolval"));
assertEquals(10, v.<SpecialInt>value("num").getValue());
assertEquals(c, v.value("birthday"));
assertEquals(4, v.<byte[]>value("barr").length);
assertEquals(point, v.<Geoshape>value("location"));
assertEquals(shape, v.<Geoshape>value("boundary"));
assertEquals(10.12345, v.<Double>value("precise"), 0.000001);
assertCount(3, v.properties("any"));
for (Object prop : v.query().labels("any").properties()) {
Object value = ((JanusGraphVertexProperty<?>) prop).value();
if (value instanceof String)
assertEquals("Hello", value);
else if (value instanceof Long)
assertEquals(10L, value);
else if (value.getClass().isArray()) {
assertTrue(Arrays.equals(testArray, (int[]) value));
} else
fail();
}
}
Aggregations