use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class JsonReaderTest method testLegacyUserDefinedBinaryWithKeyOrderReversed.
@Test
public void testLegacyUserDefinedBinaryWithKeyOrderReversed() {
String json = "{ \"$type\" : \"80\", \"$binary\" : \"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 testUuidConstructor.
@Test
public void testUuidConstructor() {
String json = "UUID(\"b5f21e0c-2a0d-42d6-ad03-d827008d8ab6\")";
testStringAndStream(json, bsonReader -> {
assertEquals(BsonType.BINARY, bsonReader.readBsonType());
BsonBinary binary = bsonReader.readBinaryData();
assertEquals(BsonBinarySubType.UUID_STANDARD.getValue(), binary.getType());
assertArrayEquals(new byte[] { -75, -14, 30, 12, 42, 13, 66, -42, -83, 3, -40, 39, 0, -115, -118, -74 }, binary.getData());
assertEquals(AbstractBsonReader.State.DONE, bsonReader.getState());
return null;
});
}
use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class AbstractExplicitUuidCodecUuidRepresentationTest method shouldDecodeDocumentWithUuidRepresentation.
@Test
public void shouldDecodeDocumentWithUuidRepresentation() {
bsonDocumentCollection.insertOne(new BsonDocument("standard", new BsonBinary(uuid, UuidRepresentation.STANDARD)).append("legacy", new BsonBinary(uuid, uuidRepresentationForExplicitEncoding)));
Document document;
try {
document = documentCollection.find().first();
assertNotNull(document);
} catch (BSONException e) {
if (uuidCodec.getUuidRepresentation() != STANDARD) {
throw e;
}
return;
}
if (uuidRepresentationForClient == UuidRepresentation.STANDARD) {
assertEquals(UUID.class, document.get("standard").getClass());
assertEquals(uuid, document.get("standard"));
assertEquals(Binary.class, document.get("legacy").getClass());
assertEquals(new Binary(BsonBinarySubType.UUID_LEGACY, encodedValue), document.get("legacy"));
} else {
if (uuidRepresentationForClient == UuidRepresentation.JAVA_LEGACY) {
assertEquals(UUID.class, document.get("standard").getClass());
assertEquals(uuid, document.get("standard"));
} else {
assertEquals(Binary.class, document.get("standard").getClass());
assertEquals(new Binary(BsonBinarySubType.UUID_STANDARD, standardEncodedValue), document.get("standard"));
}
assertEquals(UUID.class, document.get("legacy").getClass());
assertEquals(uuid, document.get("legacy"));
}
}
use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class AbstractExplicitUuidCodecUuidRepresentationTest method shouldDecodePojoWithStandardUuidRepresentation.
@Test
public void shouldDecodePojoWithStandardUuidRepresentation() {
bsonDocumentCollection.insertOne(new BsonDocument("_id", new BsonBinary(uuid, STANDARD)));
try {
UuidIdPojo document = uuidIdPojoCollection.find().first();
assertNotNull(document);
assertEquals(uuid, document.getId());
} catch (BSONException e) {
if (uuidCodec.getUuidRepresentation() == uuidRepresentationForClient) {
throw e;
}
}
}
use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class AbstractExplicitUuidCodecUuidRepresentationTest method shouldEncodePojoWithUuidRepresentation.
@Test
public void shouldEncodePojoWithUuidRepresentation() {
uuidIdPojoCollection.insertOne(new UuidIdPojo(uuid));
BsonDocument document = bsonDocumentCollection.find().first();
assertNotNull(document);
BsonBinary uuidAsBinary = document.getBinary("_id");
assertEquals(subType.getValue(), uuidAsBinary.getType());
assertArrayEquals(encodedValue, uuidAsBinary.getData());
}
Aggregations