Search in sources :

Example 71 with BsonBinary

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;
    });
}
Also used : BsonBinary(org.bson.BsonBinary) Test(org.junit.Test)

Example 72 with BsonBinary

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;
    });
}
Also used : BsonBinary(org.bson.BsonBinary) Test(org.junit.Test)

Example 73 with BsonBinary

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;
    });
}
Also used : BsonBinary(org.bson.BsonBinary) Test(org.junit.Test)

Example 74 with BsonBinary

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;
    });
}
Also used : BsonBinary(org.bson.BsonBinary) Test(org.junit.Test)

Example 75 with BsonBinary

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;
    });
}
Also used : BsonBinary(org.bson.BsonBinary) Test(org.junit.Test)

Aggregations

BsonBinary (org.bson.BsonBinary)78 Test (org.junit.Test)51 BsonDocument (org.bson.BsonDocument)32 BsonString (org.bson.BsonString)16 Document (org.bson.Document)16 EncryptOptions (com.mongodb.client.model.vault.EncryptOptions)13 DataKeyOptions (com.mongodb.client.model.vault.DataKeyOptions)11 BSONException (org.bson.BSONException)9 Map (java.util.Map)8 BasicDBObject (com.mongodb.BasicDBObject)6 ClientEncryptionSettings (com.mongodb.ClientEncryptionSettings)6 ConnectionString (com.mongodb.ConnectionString)6 MongoClientSettings (com.mongodb.MongoClientSettings)6 SecureRandom (java.security.SecureRandom)6 HashMap (java.util.HashMap)6 ClientEncryption (com.mongodb.client.vault.ClientEncryption)5 UUID (java.util.UUID)5 Binary (org.bson.types.Binary)5 MongoNamespace (com.mongodb.MongoNamespace)4 IndexOptions (com.mongodb.client.model.IndexOptions)4