use of org.neo4j.bolt.v1.packstream.PackedOutputArray 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.PackedOutputArray in project neo4j by neo4j.
the class Neo4jPackTest method shouldTreatSingleCharAsSingleCharacterString.
@Test
public void shouldTreatSingleCharAsSingleCharacterString() throws IOException {
// Given
PackedOutputArray output = new PackedOutputArray();
Neo4jPack.Packer packer = new Neo4jPack.Packer(output);
packer.pack('C');
Object unpacked = unpacked(output.bytes());
// Then
assertThat(unpacked, instanceOf(String.class));
assertThat(unpacked, equalTo("C"));
}
use of org.neo4j.bolt.v1.packstream.PackedOutputArray in project neo4j by neo4j.
the class Neo4jPackTest method shouldFailWhenNullKeysInMaps.
@SuppressWarnings("unchecked")
@Test
public void shouldFailWhenNullKeysInMaps() throws IOException {
// Given
PackedOutputArray output = new PackedOutputArray();
Neo4jPack.Packer packer = new Neo4jPack.Packer(output);
HashMap<String, Object> map = new HashMap<>();
map.put(null, 42L);
map.put("foo", 1337L);
packer.pack(map);
assertTrue(packer.hasErrors());
}
use of org.neo4j.bolt.v1.packstream.PackedOutputArray in project neo4j by neo4j.
the class Neo4jPackTest method shouldBeAbleToPackAndUnpackListStream.
@SuppressWarnings("unchecked")
@Test
public void shouldBeAbleToPackAndUnpackListStream() throws IOException {
// Given
PackedOutputArray output = new PackedOutputArray();
Neo4jPack.Packer packer = new Neo4jPack.Packer(output);
packer.packListStreamHeader();
List<String> expected = new ArrayList<>();
for (Label label : ALICE.getLabels()) {
String labelName = label.name();
packer.pack(labelName);
expected.add(labelName);
}
packer.packEndOfStream();
Object unpacked = unpacked(output.bytes());
// Then
assertThat(unpacked, instanceOf(List.class));
List<String> unpackedList = (List<String>) unpacked;
assertThat(unpackedList, equalTo(expected));
}
Aggregations