use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class JsonReaderTest method testCanonicalExtendedJsonBinaryWithKeysReversed.
@Test
public void testCanonicalExtendedJsonBinaryWithKeysReversed() {
String json = "{ \"$binary\" : { \"subType\" : \"80\", \"base64\" : \"AQID\" } }";
testStringAndStream(json, bsonReader -> {
assertEquals(BsonType.BINARY, bsonReader.readBsonType());
BsonBinary binary = bsonReader.readBinaryData();
assertEquals(BsonBinarySubType.USER_DEFINED.getValue(), binary.getType());
assertArrayEquals(new byte[] { 1, 2, 3 }, binary.getData());
assertEquals(AbstractBsonReader.State.DONE, bsonReader.getState());
return null;
});
}
use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class JsonReaderTest method testBinData.
@Test
public void testBinData() {
String json = "{ \"a\" : BinData(3, AQID) }";
testStringAndStream(json, bsonReader -> {
bsonReader.readStartDocument();
assertEquals(BsonType.BINARY, bsonReader.readBsonType());
BsonBinary binary = bsonReader.readBinaryData();
assertEquals(3, binary.getType());
assertArrayEquals(new byte[] { 1, 2, 3 }, binary.getData());
bsonReader.readEndDocument();
assertEquals(AbstractBsonReader.State.DONE, bsonReader.getState());
return null;
});
}
use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class JsonReaderTest method testBinDataUserDefined.
@Test
public void testBinDataUserDefined() {
String json = "{ \"a\" : BinData(128, AQID) }";
testStringAndStream(json, bsonReader -> {
bsonReader.readStartDocument();
assertEquals(BsonType.BINARY, bsonReader.readBsonType());
BsonBinary binary = bsonReader.readBinaryData();
assertEquals(BsonBinarySubType.USER_DEFINED.getValue(), binary.getType());
assertArrayEquals(new byte[] { 1, 2, 3 }, binary.getData());
bsonReader.readEndDocument();
assertEquals(AbstractBsonReader.State.DONE, bsonReader.getState());
return null;
});
}
use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class JsonReaderTest method testBinDataQuoted.
@Test
public void testBinDataQuoted() {
String json = "{ \"a\" : BinData(3, \"AQIDBA==\") }";
testStringAndStream(json, bsonReader -> {
bsonReader.readStartDocument();
assertEquals(BsonType.BINARY, bsonReader.readBsonType());
BsonBinary binary = bsonReader.readBinaryData();
assertEquals(3, binary.getType());
assertArrayEquals(new byte[] { 1, 2, 3, 4 }, binary.getData());
bsonReader.readEndDocument();
assertEquals(AbstractBsonReader.State.DONE, bsonReader.getState());
return null;
});
}
use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class JsonReaderTest method testLegacyBinary.
@Test
public void testLegacyBinary() {
String json = "{ \"$binary\" : \"AQID\", \"$type\" : \"0\" }";
testStringAndStream(json, bsonReader -> {
assertEquals(BsonType.BINARY, bsonReader.readBsonType());
BsonBinary binary = bsonReader.readBinaryData();
assertEquals(BsonBinarySubType.BINARY.getValue(), binary.getType());
assertArrayEquals(new byte[] { 1, 2, 3 }, binary.getData());
assertEquals(AbstractBsonReader.State.DONE, bsonReader.getState());
return null;
});
}
Aggregations