Refine search
@Test public void shouldMakeCustomAuthTokenAndCustomcSchemeWithParameters() { Map<String, Object> token = AuthToken.newCustomAuthToken( "me", "my secret", "my realm", "my scheme", map("a", "A", "b", "B") ); assertThat("Should have correct username", token.get(AuthToken.PRINCIPAL), equalTo("me")); assertThat( "Should have correct password", token.get( AuthToken.CREDENTIALS ), equalTo( UTF8.encode( "my secret" ) ) ); assertThat("Should have correct scheme", token.get(AuthToken.SCHEME_KEY), equalTo("my scheme")); assertThat("Should have correct realm", token.get(AuthToken.REALM_KEY), equalTo( "my realm" )); assertThat("Should have correct parameters", token.get(AuthToken.PARAMETERS), equalTo( map("a", "A", "b", "B") )); } }
@Test( expected = NotFoundException.class ) public void shouldHandleNoFoundPathsCorrectly() { long[] nodes = createMoreComplexGraph(); actions.findSinglePath( nodes[0], nodes[1], map( "max_depth", 2, "algorithm", "shortestPath", "relationships", map( "type", "to", "direction", "in" ), "single", false ) ); }
@Test void shouldParseTransactionMetadataCorrectly() throws Throwable { // Given Map<String,Object> txMetadata = map( "creation-time", Duration.ofMillis( 4321L ) ); Map<String,Object> msgMetadata = map( "tx_metadata", txMetadata ); MapValue meta = ValueUtils.asMapValue( msgMetadata ); // When BeginMessage beginMessage = new BeginMessage( meta ); // Then assertThat( beginMessage.transactionMetadata().toString(), equalTo( txMetadata.toString() ) ); }
@Test @SuppressWarnings( "unchecked" ) public void shouldDeserializeSingleStatement() { // Given String json = createJsonFrom( map( "statements", asList( map( "statement", "Blah blah", "parameters", map( "one", 12 ) ) ) ) ); // When StatementDeserializer de = new StatementDeserializer( new ByteArrayInputStream( UTF8.encode( json ) ) ); // Then assertThat( de.hasNext(), equalTo( true ) ); Statement stmt = de.next(); assertThat( stmt.statement(), equalTo( "Blah blah" ) ); assertThat( stmt.parameters(), equalTo( map( "one", 12 ) ) ); assertThat( de.hasNext(), equalTo( false ) ); }
@Test void shouldParseTransactionMetadataCorrectly() throws Throwable { // Given Map<String,Object> txMetadata = map( "creation-time", Duration.ofMillis( 4321L ) ); Map<String,Object> msgMetadata = map( "tx_metadata", txMetadata ); MapValue meta = ValueUtils.asMapValue( msgMetadata ); // When RunMessage runMessage = new RunMessage( "RETURN 1", EMPTY_MAP, meta ); // Then assertThat( runMessage.transactionMetadata().toString(), equalTo( txMetadata.toString() ) ); }
@Test public void shouldHandleMapWithPointsAsInput() { // Given Point point1 = (Point) db.execute( "RETURN point({latitude: 12.78, longitude: 56.7}) as point" ).next().get( "point" ); Point point2 = (Point) db.execute( "RETURN point({latitude: 12.18, longitude: 56.2}) as point" ).next().get( "point" ); // When double distance = (double) db.execute( "RETURN distance({points}['p1'], {points}['p2']) as dist", map( "points", map("p1", point1, "p2", point2) ) ).next().get( "dist" ); // Then assertThat(Math.round( distance ), equalTo(86107L)); }
@Test void shouldParseTransactionTimeoutCorrectly() throws Throwable { // Given Map<String,Object> msgMetadata = map( "tx_timeout", 123456L ); MapValue meta = ValueUtils.asMapValue( msgMetadata ); // When RunMessage runMessage = new RunMessage( "RETURN 1", EMPTY_MAP, meta ); // Then assertThat( runMessage.transactionTimeout().toMillis(), equalTo( 123456L ) ); } }
@Test public void shouldBeAbleToUseResultingPointFromOneQueryAsParameterToNext() { // given a point create by one cypher query Result execute = graphDb.execute( "RETURN point({longitude: 144.317718, latitude: -37.031738}) AS p" ); Point point = (Point) execute.next().get( "p" ); // when passing as params to a distance function Result result = graphDb.execute( "RETURN distance(point({longitude: 144.317718, latitude: -37.031738}),{previous}) AS dist", map( "previous", point ) ); // then Double dist = (Double) result.next().get( "dist" ); assertThat( dist, equalTo( 0.0 ) ); }
@Test void shouldParseTransactionTimeoutCorrectly() throws Throwable { // Given Map<String,Object> msgMetadata = map( "tx_timeout", 123456L ); MapValue meta = ValueUtils.asMapValue( msgMetadata ); // When BeginMessage beginMessage = new BeginMessage( meta ); // Then assertThat( beginMessage.transactionTimeout().toMillis(), equalTo( 123456L ) ); } }
@Test public void shouldHandleJsonLists() throws Exception { String methodUri = getPluginMethodUri( functionalTestHelper.dataUri(), "methodWithList" ); List<String> strings = Arrays.asList( "aaa", "bbb", "aaa" ); Map<String, Object> params = MapUtil.map( "strings", strings ); PluginFunctionalTestHelper.makePostMap( methodUri, params ); List<String> stringsList = new ArrayList<>( strings ); assertThat( FunctionalTestPlugin.stringList, is( stringsList ) ); }
@Test public void shouldBeAbleToUseExternalPointAsParameterToQuery() { // given a point created from public interface Point point = makeFakePoint( 144.317718, -37.031738, makeWGS84() ); // when passing as params to a distance function Result result = graphDb.execute( "RETURN distance(point({longitude: 144.317718, latitude: -37.031738}),{previous}) AS dist", map( "previous", point ) ); // then Double dist = (Double) result.next().get( "dist" ); assertThat( dist, equalTo( 0.0 ) ); }
@Test void shouldHandleMaps() { // Given Map<String,Object> map = MapUtil.map( "a", Arrays.asList( "foo", 42 ) ); // When AnyValue anyValue = ValueUtils.of( map ); // Then assertThat( anyValue, instanceOf( MapValue.class ) ); MapValue mapValue = (MapValue) anyValue; assertThat( mapValue.get( "a" ), equalTo( VirtualValues.list( stringValue( "foo" ), intValue( 42 ) ) ) ); assertThat( mapValue.size(), equalTo( 1 ) ); }
@Test public void shouldBeAbleToUseExternalGeometryAsParameterToQuery() { // given a point created from public interface Geometry geometry = makeFakePointAsGeometry( 144.317718, -37.031738, makeWGS84() ); // when passing as params to a distance function Result result = graphDb.execute( "RETURN distance(point({longitude: 144.317718, latitude: -37.031738}),{previous}) AS dist", map( "previous", geometry ) ); // then Double dist = (Double) result.next().get( "dist" ); assertThat( dist, equalTo( 0.0 ) ); }
@Test void shouldThrowExceptionIfFailedToParseTransactionMetadataCorrectly() throws Throwable { // Given Map<String,Object> msgMetadata = map( "tx_metadata", "invalid value type" ); MapValue meta = ValueUtils.asMapValue( msgMetadata ); // When & Then BoltIOException exception = assertThrows( BoltIOException.class, () -> new BeginMessage( meta ) ); assertThat( exception.getMessage(), startsWith( "Expecting transaction metadata value to be a Map value" ) ); }
@Test public void shouldBeAbleToUpdateExpiredCredentials() throws Exception { // When AuthenticationResult result = authentication.authenticate( map( "scheme", "basic", "principal", "bob", "credentials", UTF8.encode( "secret" ), "new_credentials", UTF8.encode( "secret2" ) ) ); // Then assertThat(result.credentialsExpired(), equalTo( false )); }