InitResponseHandler implements ResponseHandler { @Override public void onSuccess( Map<String,Value> metadata ) { try { ServerVersion serverVersion = extractNeo4jServerVersion( metadata ); setServerVersion( channel, serverVersion ); connectionInitializedPromise.setSuccess(); } catch ( Throwable error ) { connectionInitializedPromise.setFailure( error ); throw error; } } InitResponseHandler( ChannelPromise connectionInitializedPromise ); @Override void onSuccess( Map<String,Value> metadata ); @Override void onFailure( Throwable error ); @Override void onRecord( Value[] fields );  }
@Test void shouldSetServerVersionOnChannel() { ChannelPromise channelPromise = channel.newPromise(); InitResponseHandler handler = new InitResponseHandler( channelPromise ); Map<String,Value> metadata = singletonMap( "server", value( anyServerVersion().toString() ) ); handler.onSuccess( metadata ); assertTrue( channelPromise.isSuccess() ); assertEquals( anyServerVersion(), serverVersion( channel ) ); }
@Test void shouldFailToConnectWhenNoServerIdentifierIsProvided() { ChannelPromise channelPromise = channel.newPromise(); InitResponseHandler handler = new InitResponseHandler( channelPromise ); Map<String,Value> metadata = singletonMap( "server", Values.NULL ); assertThrows( UntrustedServerException.class, () -> handler.onSuccess( metadata ) ); }
@Test void shouldAllowByteArrays() { InitResponseHandler handler = new InitResponseHandler( channel.newPromise() ); Map<String,Value> metadata = singletonMap( "server", value( anyServerVersion().toString() ) ); handler.onSuccess( metadata ); Map<String,Value> params = singletonMap( "array", value( new byte[]{1, 2, 3} ) ); assertTrue( channel.writeOutbound( new Query( "RETURN 1", Values.value( params ) ) ) ); assertTrue( channel.finish() ); }