use of org.neo4j.bolt.packstream.PackedInputArray in project neo4j by neo4j.
the class HelloMessageDecoderTest method testShouldDecodeAuthToken.
@Override
protected void testShouldDecodeAuthToken(Map<String, Object> authToken) throws Exception {
Neo4jPack neo4jPack = newNeo4jPack();
authToken.put("user_agent", "My Driver");
HelloMessage originalMessage = new HelloMessage(authToken, new RoutingContext(true, Collections.emptyMap()), authToken);
PackedInputArray input = new PackedInputArray(encode(neo4jPack, originalMessage));
Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
// these two steps are executed before decoding in order to select a correct decoder
unpacker.unpackStructHeader();
unpacker.unpackStructSignature();
RequestMessage deserializedMessage = decoder.decode(unpacker);
assertHelloMessageMatches(originalMessage, deserializedMessage);
}
use of org.neo4j.bolt.packstream.PackedInputArray in project neo4j by neo4j.
the class HelloMessageDecoderTest method shouldThrowExceptionOnIncorrectRoutingContextFormat.
@Test
public void shouldThrowExceptionOnIncorrectRoutingContextFormat() throws Exception {
Map<String, Object> meta = new HashMap<>();
// incorrect Map type params
Map<String, Integer> routingContext = new HashMap<>();
routingContext.put("policy", 4);
Neo4jPack neo4jPack = newNeo4jPack();
meta.put("user_agent", "My Driver");
meta.put("routing", routingContext);
HelloMessage originalMessage = new HelloMessage(meta, null, meta);
PackedInputArray input = new PackedInputArray(encode(neo4jPack, originalMessage));
Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
// these two steps are executed before decoding in order to select a correct decoder
unpacker.unpackStructHeader();
unpacker.unpackStructSignature();
BoltIOException ex = assertThrows(BoltIOException.class, () -> decoder.decode(unpacker));
assertEquals("Routing information in the HELLO message must be a map with string keys and string values.", ex.getMessage());
}
use of org.neo4j.bolt.packstream.PackedInputArray in project neo4j by neo4j.
the class HelloMessageDecoderTest method assertOriginalMessageEqualsToDecoded.
static void assertOriginalMessageEqualsToDecoded(RequestMessage originalMessage, RequestMessageDecoder decoder) throws Exception {
Neo4jPack neo4jPack = newNeo4jPack();
PackedInputArray input = new PackedInputArray(encode(neo4jPack, originalMessage));
Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
// these two steps are executed before decoding in order to select a correct decoder
unpacker.unpackStructHeader();
unpacker.unpackStructSignature();
RequestMessage deserializedMessage = decoder.decode(unpacker);
assertEquals(originalMessage, deserializedMessage);
assertAuthTokenDoesNotContainRoutingContext(deserializedMessage);
}
use of org.neo4j.bolt.packstream.PackedInputArray in project neo4j by neo4j.
the class HelloMessageDecoderTest method testShouldDecodeWhenNoRoutingContextProvided.
@Test
void testShouldDecodeWhenNoRoutingContextProvided() throws Exception {
Map<String, Object> meta = new HashMap<>();
Neo4jPack neo4jPack = newNeo4jPack();
meta.put("user_agent", "My Driver");
HelloMessage originalMessage = new HelloMessage(meta, new RoutingContext(false, Collections.emptyMap()), meta);
PackedInputArray input = new PackedInputArray(encode(neo4jPack, originalMessage));
Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
// these two steps are executed before decoding in order to select a correct decoder
unpacker.unpackStructHeader();
unpacker.unpackStructSignature();
RequestMessage deserializedMessage = decoder.decode(unpacker);
assertHelloMessageMatches(originalMessage, deserializedMessage);
assertRoutingContextMatches(originalMessage, deserializedMessage);
}
use of org.neo4j.bolt.packstream.PackedInputArray in project neo4j by neo4j.
the class BoltRequestMessageReaderV41Test method verifyBoltV3MessageIsReadAsBoltV4Message.
private static void verifyBoltV3MessageIsReadAsBoltV4Message(TransactionInitiatingMessage messageV3, TransactionInitiatingMessage messageV4) throws Exception {
Neo4jPack neo4jPack = newNeo4jPack();
BoltStateMachine stateMachine = mock(BoltStateMachine.class);
BoltRequestMessageReader reader = requestMessageReader(stateMachine);
PackedInputArray input = new PackedInputArray(encode(neo4jPack, messageV3));
Neo4jPack.Unpacker unpacker = neo4jPack.newUnpacker(input);
reader.read(unpacker);
verify(stateMachine).process(eq(messageV4), any());
assertThat(messageV3.meta()).isEqualTo(messageV4.meta());
}
Aggregations