Search in sources :

Example 1 with ResponseMessage

use of org.neo4j.bolt.v1.messaging.message.ResponseMessage in project neo4j by neo4j.

the class MessageMatchers method msgFailure.

public static Matcher<ResponseMessage> msgFailure(final Status status, final String message) {
    return new TypeSafeMatcher<ResponseMessage>() {

        @Override
        protected boolean matchesSafely(ResponseMessage t) {
            assertThat(t, instanceOf(FailureMessage.class));
            FailureMessage msg = (FailureMessage) t;
            assertThat(msg.status(), equalTo(status));
            assertThat(msg.message(), containsString(message));
            return true;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("FAILURE");
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) FailureMessage(org.neo4j.bolt.v1.messaging.message.FailureMessage) ResponseMessage(org.neo4j.bolt.v1.messaging.message.ResponseMessage)

Example 2 with ResponseMessage

use of org.neo4j.bolt.v1.messaging.message.ResponseMessage in project neo4j by neo4j.

the class MessageMatchers method msgRecord.

public static Matcher<ResponseMessage> msgRecord(final Matcher<Record> matcher) {
    return new TypeSafeMatcher<ResponseMessage>() {

        @Override
        protected boolean matchesSafely(ResponseMessage t) {
            assertThat(t, instanceOf(RecordMessage.class));
            RecordMessage msg = (RecordMessage) t;
            assertThat(msg.record(), matcher);
            return true;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("RECORD ");
            description.appendDescriptionOf(matcher);
        }
    };
}
Also used : TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) ResponseMessage(org.neo4j.bolt.v1.messaging.message.ResponseMessage) RecordMessage(org.neo4j.bolt.v1.messaging.message.RecordMessage)

Example 3 with ResponseMessage

use of org.neo4j.bolt.v1.messaging.message.ResponseMessage in project neo4j by neo4j.

the class MessageMatchers method responseMessage.

public static ResponseMessage responseMessage(byte[] bytes) throws IOException {
    BoltResponseMessageReader unpacker = responseReader(bytes);
    BoltResponseMessageRecorder consumer = new BoltResponseMessageRecorder();
    try {
        if (unpacker.hasNext()) {
            unpacker.read(consumer);
            return consumer.asList().get(0);
        }
        throw new IllegalArgumentException("Expected a message in `" + HexPrinter.hex(bytes) + "`");
    } catch (Throwable e) {
        throw new IOException("Failed to deserialize response, '" + e.getMessage() + "'.\n" + "Raw data: \n" + HexPrinter.hex(bytes), e);
    }
}
Also used : BoltResponseMessageRecorder(org.neo4j.bolt.v1.messaging.BoltResponseMessageRecorder) BoltResponseMessageReader(org.neo4j.bolt.v1.messaging.BoltResponseMessageReader) IOException(java.io.IOException)

Example 4 with ResponseMessage

use of org.neo4j.bolt.v1.messaging.message.ResponseMessage in project neo4j by neo4j.

the class MessageMatchers method serialize.

public static byte[] serialize(ResponseMessage... messages) throws IOException {
    final RecordingByteChannel rawData = new RecordingByteChannel();
    final BoltResponseMessageWriter packer = new BoltResponseMessageWriter(new Neo4jPack.Packer(new BufferedChannelOutput(rawData)), NO_BOUNDARY_HOOK);
    for (ResponseMessage message : messages) {
        message.dispatch(packer);
    }
    packer.flush();
    return rawData.getBytes();
}
Also used : BoltResponseMessageWriter(org.neo4j.bolt.v1.messaging.BoltResponseMessageWriter) RecordingByteChannel(org.neo4j.bolt.v1.messaging.RecordingByteChannel) ResponseMessage(org.neo4j.bolt.v1.messaging.message.ResponseMessage) Neo4jPack(org.neo4j.bolt.v1.messaging.Neo4jPack) BufferedChannelOutput(org.neo4j.bolt.v1.packstream.BufferedChannelOutput)

Example 5 with ResponseMessage

use of org.neo4j.bolt.v1.messaging.message.ResponseMessage in project neo4j by neo4j.

the class BoltResponseMessageTest method serializeAndDeserialize.

private <T extends ResponseMessage> T serializeAndDeserialize(T msg) throws IOException {
    RecordingByteChannel channel = new RecordingByteChannel();
    BoltResponseMessageReader reader = new BoltResponseMessageReader(new Neo4jPack.Unpacker(new BufferedChannelInput(16).reset(channel)));
    BoltResponseMessageWriter writer = new BoltResponseMessageWriter(new Neo4jPack.Packer(new BufferedChannelOutput(channel)), NO_BOUNDARY_HOOK);
    msg.dispatch(writer);
    writer.flush();
    channel.eof();
    return unpack(reader, channel);
}
Also used : BufferedChannelInput(org.neo4j.bolt.v1.packstream.BufferedChannelInput) BufferedChannelOutput(org.neo4j.bolt.v1.packstream.BufferedChannelOutput)

Aggregations

ResponseMessage (org.neo4j.bolt.v1.messaging.message.ResponseMessage)5 Description (org.hamcrest.Description)3 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)3 IOException (java.io.IOException)2 FailureMessage (org.neo4j.bolt.v1.messaging.message.FailureMessage)2 RecordMessage (org.neo4j.bolt.v1.messaging.message.RecordMessage)2 BufferedChannelOutput (org.neo4j.bolt.v1.packstream.BufferedChannelOutput)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AuthenticationException (org.neo4j.bolt.security.auth.AuthenticationException)1 BoltResponseMessageReader (org.neo4j.bolt.v1.messaging.BoltResponseMessageReader)1 BoltResponseMessageRecorder (org.neo4j.bolt.v1.messaging.BoltResponseMessageRecorder)1 BoltResponseMessageWriter (org.neo4j.bolt.v1.messaging.BoltResponseMessageWriter)1 Neo4jPack (org.neo4j.bolt.v1.messaging.Neo4jPack)1 RecordingByteChannel (org.neo4j.bolt.v1.messaging.RecordingByteChannel)1 SuccessMessage (org.neo4j.bolt.v1.messaging.message.SuccessMessage)1 BufferedChannelInput (org.neo4j.bolt.v1.packstream.BufferedChannelInput)1 TransportConnection (org.neo4j.bolt.v1.transport.socket.client.TransportConnection)1