/** * Create a new statement. * @param text the statement text * @param parameters the statement parameters */ public Statement( String text, Map<String, Object> parameters ) { this( text, Values.value( parameters ) ); }
assertEquals("Tom", start.getProperty("name")); assertEquals("Loagan", start.getProperty("surname")); assertEquals(isoDuration(5, 1, 43200, 0).asIsoDuration(), start.getProperty("duration")); Relationship rel = (Relationship) path.get(1); assertEquals("KNOWS", rel.getType().name()); assertEquals(LocalTime.parse("12:50:35.556"), rel.getProperty("since")); assertEquals(point(4326, 56.7, 12.78).asPoint(), rel.getProperty("born")); Node end = (Node) path.get(2); assertEquals(true, end.hasLabel(Label.label("Person"))); assertEquals("John", end.getProperty("name")); assertEquals("Green", end.getProperty("surname")); assertEquals(point(7203, 2.3, 4.5).asPoint(), end.getProperty("born")); start = (Node) path.get(3); assertEquals(true, start.hasLabel(Label.label("Person"))); assertEquals("John", start.getProperty("name")); assertEquals("Green", start.getProperty("surname")); assertEquals(point(7203, 2.3, 4.5).asPoint(), end.getProperty("born")); rel = (Relationship) path.get(4); assertEquals("KNOWS", rel.getType().name()); assertEquals(OffsetTime.parse("12:50:35.556+01:00"), rel.getProperty("since")); assertEquals(point(4979, 56.7, 12.78, 100.0).asPoint(), rel.getProperty("born")); end = (Node) path.get(5); assertEquals(true, end.hasLabel(Label.label("Person"))); assertEquals("Anne", end.getProperty("name")); assertEquals("Olsson", end.getProperty("surname")); assertEquals(point(9157,2.3, 4.5, 1.2).asPoint(), end.getProperty("born")); });
@Override public Map<String, Object> asMap() { return Extract.map( this, ofObject() ); }
private Statement procedureStatement( ServerVersion serverVersion ) { if ( serverVersion.greaterThanOrEqual( v3_2_0 ) ) { return new Statement( "CALL " + GET_ROUTING_TABLE, parameters( GET_ROUTING_TABLE_PARAM, context.asMap() ) ); } else { return new Statement( "CALL " + GET_SERVERS ); } }
@Test public void testMetaList() throws Exception { Map<String, Object> param = map( "LIST FLOAT", asList(1.2F, 2.1F), "LIST STRING", asList("a", "b"), "LIST CHAR", asList('a', 'a'), "LIST DATE", asList(LocalDate.of(2018,1,1), LocalDate.of(2018,2,2)), "LIST ANY", asList("test",1,"asd",isoDuration(5, 1, 43200, 0).asIsoDuration()), "LIST NULL", asList("test",null), "LIST POINT", asList(Values.pointValue(CoordinateReferenceSystem.WGS84, 56.d, 12.78), Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, 2.3, 4.5, 1.2)), "LIST DURATION", asList(isoDuration(5, 1, 43200, 0).asIsoDuration(), isoDuration(2, 1, 125454, 0).asIsoDuration()), "LIST OBJECT", new Object[]{LocalDate.of(2018,1,1), "test"}, "LIST OF LIST", asList(asList("a", "b", "c"),asList("aa", "bb", "cc"),asList("aaa", "bbb", "ccc")), "LIST DOUBLE", asList(1.2D, 2.1D)); TestUtil.testCall(db, "RETURN apoc.meta.cypher.types({param}) AS value", singletonMap("param",param), row -> { Map<String, Object> r = (Map<String, Object>) row.get("value"); assertEquals("LIST OF FLOAT", r.get("LIST FLOAT")); assertEquals("LIST OF STRING", r.get("LIST STRING")); assertEquals("LIST OF ANY", r.get("LIST CHAR")); assertEquals("LIST OF DATE", r.get("LIST DATE")); assertEquals("LIST OF FLOAT", r.get("LIST DOUBLE")); assertEquals("LIST OF POINT", r.get("LIST POINT")); assertEquals("LIST OF DURATION", r.get("LIST DURATION")); assertEquals("LIST OF ANY", r.get("LIST ANY")); assertEquals("LIST OF ANY", r.get("LIST OBJECT")); assertEquals("LIST OF LIST", r.get("LIST OF LIST")); assertEquals("LIST OF ANY", r.get("LIST NULL")); }); }
private Value unpackPoint2D() throws IOException { int srid = Math.toIntExact( unpacker.unpackLong() ); double x = unpacker.unpackDouble(); double y = unpacker.unpackDouble(); return point( srid, x, y ); }
@Test public void prettyPrintPlanInformation() throws Exception { // given ResultSummary resultSummary = mock(ResultSummary.class); ProfiledPlan plan = mock(ProfiledPlan.class); when(plan.dbHits()).thenReturn(1000L); when(plan.records()).thenReturn(20L); when(resultSummary.hasPlan()).thenReturn(true); when(resultSummary.hasProfile()).thenReturn(true); when(resultSummary.plan()).thenReturn(plan); when(resultSummary.profile()).thenReturn(plan); when(resultSummary.resultAvailableAfter(anyObject())).thenReturn(5L); when(resultSummary.resultConsumedAfter(anyObject())).thenReturn(7L); when(resultSummary.statementType()).thenReturn(StatementType.READ_ONLY); Map<String, Value> argumentMap = Values.parameters("Version", "3.1", "Planner", "COST", "Runtime", "INTERPRETED").asMap(v -> v); when(plan.arguments()).thenReturn(argumentMap); BoltResult result = mock(BoltResult.class); when(result.getRecords()).thenReturn(Collections.emptyList()); when(result.getSummary()).thenReturn(resultSummary); // when String actual = verbosePrinter.format(result); // then argumentMap.forEach((k, v) -> { assertThat(actual, CoreMatchers.containsString("| " + k)); assertThat(actual, CoreMatchers.containsString("| " + v.toString())); }); }
@Test public void testMetaArray() throws Exception { Map<String, Object> param = map( "ARRAY", new String[]{"a","b","c"}, "ARRAY_FLOAT", new Float[]{1.2f, 2.2f}, "ARRAY_DOUBLE", new Double[]{1.2, 2.2}, "ARRAY_INT", new Integer[]{1, 2}, "ARRAY_OBJECT", new Object[]{1, "a"}, "ARRAY_POINT", new Object[]{Values.pointValue(CoordinateReferenceSystem.WGS84, 56.d, 12.78), Values.pointValue(CoordinateReferenceSystem.WGS84_3D, 56.d, 12.78, 100)}, "ARRAY_DURATION", new Object[]{isoDuration(5, 1, 43200, 0).asIsoDuration(), isoDuration(2, 1, 125454, 0).asIsoDuration()}, "ARRAY_ARRAY", new Object[]{1, "a", new Object[]{"a", 1}, isoDuration(5, 1, 43200, 0).asIsoDuration()}, "NULL", null); TestUtil.testCall(db, "RETURN apoc.meta.cypher.types({param}) AS value", singletonMap("param",param), row -> { Map<String, Object> r = (Map<String, Object>) row.get("value"); assertEquals("LIST OF STRING", r.get("ARRAY")); assertEquals("LIST OF FLOAT", r.get("ARRAY_FLOAT")); assertEquals("LIST OF FLOAT", r.get("ARRAY_DOUBLE")); assertEquals("LIST OF INTEGER", r.get("ARRAY_INT")); assertEquals("LIST OF ANY", r.get("ARRAY_OBJECT")); assertEquals("LIST OF POINT", r.get("ARRAY_POINT")); assertEquals("LIST OF DURATION", r.get("ARRAY_DURATION")); assertEquals("LIST OF ANY", r.get("ARRAY_ARRAY")); assertEquals("NULL", r.get("NULL")); }); }
private Value unpackPoint3D() throws IOException { int srid = Math.toIntExact( unpacker.unpackLong() ); double x = unpacker.unpackDouble(); double y = unpacker.unpackDouble(); double z = unpacker.unpackDouble(); return point( srid, x, y, z ); }
public static Value[] values( final Object... input ) { Value[] values = new Value[input.length]; for ( int i = 0; i < input.length; i++ ) { values[i] = value( input[i] ); } return values; }
@Test public void prettyPrintExplainInformation() throws Exception { // given ResultSummary resultSummary = mock(ResultSummary.class); ProfiledPlan plan = mock(ProfiledPlan.class); when(plan.dbHits()).thenReturn(1000L); when(plan.records()).thenReturn(20L); when(resultSummary.hasPlan()).thenReturn(true); when(resultSummary.hasProfile()).thenReturn(false); when(resultSummary.plan()).thenReturn(plan); when(resultSummary.resultAvailableAfter(anyObject())).thenReturn(5L); when(resultSummary.resultConsumedAfter(anyObject())).thenReturn(7L); when(resultSummary.statementType()).thenReturn(StatementType.READ_ONLY); Map<String, Value> argumentMap = Values.parameters("Version", "3.1", "Planner", "COST", "Runtime", "INTERPRETED").asMap(v -> v); when(plan.arguments()).thenReturn(argumentMap); BoltResult result = mock(BoltResult.class); when(result.getRecords()).thenReturn(Collections.emptyList()); when(result.getSummary()).thenReturn(resultSummary); // when String actual = plainPrinter.format(result); // then String expected = "Plan: \"EXPLAIN\"\n" + "Statement: \"READ_ONLY\"\n" + "Version: \"3.1\"\n" + "Planner: \"COST\"\n" + "Runtime: \"INTERPRETED\"\n" + "Time: 12"; Stream.of(expected.split("\n")).forEach(e -> assertThat(actual, containsString(e))); }
@Test public void testMeta() throws Exception { Map<String, Object> param = map( "LIST", asList(1.2, 2.1), "STRING", "a", "BOOLEAN", true, "CHAR", 'a', "DURATION", 'a', "POINT_2D",Values.pointValue(CoordinateReferenceSystem.WGS84, 56.d, 12.78), "POINT_3D", Values.pointValue(CoordinateReferenceSystem.WGS84_3D, 56.7, 12.78, 100.0), "POINT_XYZ_2D", Values.pointValue(CoordinateReferenceSystem.Cartesian, 2.3, 4.5), "POINT_XYZ_3D", Values.pointValue(CoordinateReferenceSystem.Cartesian_3D, 2.3, 4.5, 1.2), "DURATION", isoDuration(5, 1, 43200, 0).asIsoDuration(), "MAP", Util.map("a", "b"), "NULL", null); TestUtil.testCall(db, "RETURN apoc.meta.cypher.types({param}) AS value", singletonMap("param",param), row -> { Map<String, Object> r = (Map<String, Object>) row.get("value"); assertEquals("LIST OF FLOAT", r.get("LIST")); assertEquals("STRING", r.get("STRING")); assertEquals("BOOLEAN", r.get("BOOLEAN")); assertEquals("Character", r.get("CHAR")); assertEquals("POINT", r.get("POINT_2D")); assertEquals("POINT", r.get("POINT_3D")); assertEquals("POINT", r.get("POINT_XYZ_2D")); assertEquals("POINT", r.get("POINT_XYZ_3D")); assertEquals("DURATION", r.get("DURATION")); assertEquals("MAP", r.get("MAP")); assertEquals("NULL", r.get("NULL")); }); }
@Override public Map<String, Object> asObject() { return asMap( ofObject() ); }
public static Value value( Iterable<Object> val ) { return value( val.iterator() ); }
when(resultSummary.resultConsumedAfter(anyObject())).thenReturn(7L); when(resultSummary.statementType()).thenReturn(StatementType.READ_ONLY); Map<String, Value> argumentMap = Values.parameters("Version", "3.1", "Planner", "COST", "Runtime", "INTERPRETED").asMap(v -> v); when(plan.arguments()).thenReturn(argumentMap);
private Value unpackDuration() throws IOException { long months = unpacker.unpackLong(); long days = unpacker.unpackLong(); long seconds = unpacker.unpackLong(); int nanoseconds = Math.toIntExact( unpacker.unpackLong() ); return isoDuration( months, days, seconds, nanoseconds ); }
@Override public List<Object> asObject() { return asList( ofObject() ); }
private static Map<String,Value> buildMetadata( String userAgent, Map<String,Value> authToken ) { Map<String,Value> result = new HashMap<>( authToken ); result.put( USER_AGENT_METADATA_KEY, value( userAgent ) ); return result; } }
@Test public void withParameter() { Driver driver = GremlinDatabase.driver("//localhost:" + server.getPort()); try (Session session = driver.session()) { StatementResult result = session.run("CREATE (a:Greeting) " + "SET a.message = $message " + "RETURN a.message", parameters("message", "Hello")); String message = result.single().get(0).asString(); assertThat(message).isEqualTo("Hello"); } }