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.")));
}
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`.")));
}
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();
}
Aggregations