use of org.neo4j.bolt.v1.packstream.PackedOutputArray in project neo4j by neo4j.
the class Neo4jPackTest method shouldTreatCharArrayAsListOfStrings.
@Test
public void shouldTreatCharArrayAsListOfStrings() throws IOException {
// Given
PackedOutputArray output = new PackedOutputArray();
Neo4jPack.Packer packer = new Neo4jPack.Packer(output);
packer.pack(new char[] { 'W', 'H', 'Y' });
Object unpacked = unpacked(output.bytes());
// Then
assertThat(unpacked, instanceOf(List.class));
assertThat(unpacked, equalTo(asList("W", "H", "Y")));
}
use of org.neo4j.bolt.v1.packstream.PackedOutputArray in project neo4j by neo4j.
the class Neo4jPackTest method packed.
private byte[] packed(Object object) throws IOException {
PackedOutputArray output = new PackedOutputArray();
Neo4jPack.Packer packer = new Neo4jPack.Packer(output);
packer.pack(object);
return output.bytes();
}
use of org.neo4j.bolt.v1.packstream.PackedOutputArray in project neo4j by neo4j.
the class Neo4jPackTest method shouldFailNicelyWhenPackingAMapWithUnpackableValues.
@SuppressWarnings("unchecked")
@Test
public void shouldFailNicelyWhenPackingAMapWithUnpackableValues() throws IOException {
// Given
PackedOutputArray output = new PackedOutputArray();
Neo4jPack.Packer packer = new Neo4jPack.Packer(output);
packer.packRawMap(map("unpackable", new Unpackable()));
Object unpacked = unpacked(output.bytes());
// Then
assertThat(unpacked, instanceOf(Map.class));
Map<String, Object> unpackedMap = (Map<String, Object>) unpacked;
assertThat(unpackedMap, equalTo(map("unpackable", null)));
assertTrue(packer.hasErrors());
}
use of org.neo4j.bolt.v1.packstream.PackedOutputArray in project neo4j by neo4j.
the class Neo4jPackTest method shouldBeAbleToPackAndUnpackMapStream.
@SuppressWarnings("unchecked")
@Test
public void shouldBeAbleToPackAndUnpackMapStream() throws IOException {
// Given
PackedOutputArray output = new PackedOutputArray();
Neo4jPack.Packer packer = new Neo4jPack.Packer(output);
packer.packMapStreamHeader();
for (Map.Entry<String, Object> entry : ALICE.getAllProperties().entrySet()) {
packer.pack(entry.getKey());
packer.pack(entry.getValue());
}
packer.packEndOfStream();
Object unpacked = unpacked(output.bytes());
// Then
assertThat(unpacked, instanceOf(Map.class));
Map<String, Object> unpackedMap = (Map<String, Object>) unpacked;
assertThat(unpackedMap, equalTo(ALICE.getAllProperties()));
}
use of org.neo4j.bolt.v1.packstream.PackedOutputArray 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.")));
}
Aggregations