Search in sources :

Example 1 with PackedInputArray

use of org.neo4j.bolt.v1.packstream.PackedInputArray in project neo4j by neo4j.

the class Neo4jPackTest method shouldFailWhenTryingToPackAndUnpackMapStreamContainingNullKeys.

@SuppressWarnings("unchecked")
@Test
public void shouldFailWhenTryingToPackAndUnpackMapStreamContainingNullKeys() throws IOException {
    // Given
    PackedOutputArray output = new PackedOutputArray();
    Neo4jPack.Packer packer = new Neo4jPack.Packer(output);
    packer.packMapStreamHeader();
    HashMap<String, Object> map = new HashMap<>();
    map.put(null, 42L);
    map.put("foo", 1337L);
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        packer.pack(entry.getKey());
        packer.pack(entry.getValue());
    }
    packer.packEndOfStream();
    // When
    PackedInputArray input = new PackedInputArray(output.bytes());
    Neo4jPack.Unpacker unpacker = new Neo4jPack.Unpacker(input);
    unpacker.unpack();
    // Then
    assertThat(unpacker.consumeError().get(), equalTo(Neo4jError.from(Status.Request.Invalid, "Value `null` is not supported as key in maps, must be a non-nullable string.")));
}
Also used : HashMap(java.util.HashMap) PackedInputArray(org.neo4j.bolt.v1.packstream.PackedInputArray) PackedOutputArray(org.neo4j.bolt.v1.packstream.PackedOutputArray) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with PackedInputArray

use of org.neo4j.bolt.v1.packstream.PackedInputArray in project neo4j by neo4j.

the class Neo4jPackTest method shouldErrorOnUnpackingMapWithDuplicateKeys.

@Test
public void shouldErrorOnUnpackingMapWithDuplicateKeys() throws IOException {
    // Given
    PackedOutputArray output = new PackedOutputArray();
    Neo4jPack.Packer packer = new Neo4jPack.Packer(output);
    packer.packMapHeader(2);
    packer.pack("key");
    packer.pack(1);
    packer.pack("key");
    packer.pack(2);
    // When
    PackedInputArray input = new PackedInputArray(output.bytes());
    Neo4jPack.Unpacker unpacker = new Neo4jPack.Unpacker(input);
    unpacker.unpack();
    // Then
    assertThat(unpacker.consumeError().get(), equalTo(Neo4jError.from(Status.Request.Invalid, "Duplicate map key `key`.")));
}
Also used : PackedInputArray(org.neo4j.bolt.v1.packstream.PackedInputArray) PackedOutputArray(org.neo4j.bolt.v1.packstream.PackedOutputArray) Test(org.junit.Test)

Example 3 with PackedInputArray

use of org.neo4j.bolt.v1.packstream.PackedInputArray in project neo4j by neo4j.

the class Neo4jPackTest method unpacked.

private Object unpacked(byte[] bytes) throws IOException {
    PackedInputArray input = new PackedInputArray(bytes);
    Neo4jPack.Unpacker unpacker = new Neo4jPack.Unpacker(input);
    return unpacker.unpack();
}
Also used : PackedInputArray(org.neo4j.bolt.v1.packstream.PackedInputArray)

Aggregations

PackedInputArray (org.neo4j.bolt.v1.packstream.PackedInputArray)3 Test (org.junit.Test)2 PackedOutputArray (org.neo4j.bolt.v1.packstream.PackedOutputArray)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1