use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class AbstractExplicitUuidCodecUuidRepresentationTest method shouldDecodeDBObjectWithUuidRepresentation.
@Test
public void shouldDecodeDBObjectWithUuidRepresentation() {
bsonDocumentCollection.insertOne(new BsonDocument("standard", new BsonBinary(uuid, UuidRepresentation.STANDARD)).append("legacy", new BsonBinary(uuid, uuidRepresentationForExplicitEncoding)));
DBObject document;
try {
document = dbObjectCollection.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 shouldEncodeDbObjectWithUuidRepresentation.
@Test
public void shouldEncodeDbObjectWithUuidRepresentation() {
dbObjectCollection.insertOne(new BasicDBObject("_id", uuid));
BsonDocument document = bsonDocumentCollection.find().first();
assertNotNull(document);
BsonBinary uuidAsBinary = document.getBinary("_id");
assertEquals(subType.getValue(), uuidAsBinary.getType());
assertEquals(subType.getValue(), uuidAsBinary.getType());
assertArrayEquals(encodedValue, uuidAsBinary.getData());
}
use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class AbstractExplicitUuidCodecUuidRepresentationTest method shouldDecodePojoWithLegacyUuidRepresentation.
@Test
public void shouldDecodePojoWithLegacyUuidRepresentation() {
bsonDocumentCollection.insertOne(new BsonDocument("_id", new BsonBinary(uuid, uuidRepresentationForExplicitEncoding)));
try {
UuidIdPojo document = uuidIdPojoCollection.find().first();
assertNotNull(document);
assertEquals(uuid, document.getId());
} catch (BSONException e) {
if (uuidCodec.getUuidRepresentation() == uuidRepresentationForExplicitEncoding) {
throw e;
}
}
}
use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class AbstractRetryableReadsTest method parseHexDocument.
private BsonDocument parseHexDocument(final BsonDocument document, final String hexDocument) {
if (document.containsKey(hexDocument) && document.get(hexDocument).isDocument()) {
byte[] bytes = Hex.decode(document.getDocument(hexDocument).getString("$hex").getValue());
document.put(hexDocument, new BsonBinary(bytes));
}
return document;
}
use of org.bson.BsonBinary in project mongo-java-driver by mongodb.
the class ClientSideEncryptionBypassAutoEncryptionTest method shouldAutoDecryptManuallyEncryptedData.
@Test
public void shouldAutoDecryptManuallyEncryptedData() {
String fieldValue = "123456789";
BsonBinary dataKeyId = clientEncryption.createDataKey("local", new DataKeyOptions());
BsonBinary encryptedFieldValue = clientEncryption.encrypt(new BsonString(fieldValue), new EncryptOptions("AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic").keyId(dataKeyId));
MongoCollection<Document> collection = clientEncrypted.getDatabase(Fixture.getDefaultDatabaseName()).getCollection("test");
collection.insertOne(new Document("encryptedField", encryptedFieldValue));
assertEquals(fieldValue, collection.find().first().getString("encryptedField"));
}
Aggregations