Search in sources :

Example 21 with BsonBinary

use of org.bson.BsonBinary in project mongo-java-driver by mongodb.

the class JsonReaderTest method testLegacyBinaryWithNumericType.

@Test
public void testLegacyBinaryWithNumericType() {
    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)

Example 22 with BsonBinary

use of org.bson.BsonBinary in project mongo-java-driver by mongodb.

the class JsonReaderTest method testCanonicalExtendedJsonBinary.

@Test
public void testCanonicalExtendedJsonBinary() {
    String json = "{ \"$binary\" : { \"base64\" : \"AQID\", \"subType\" : \"80\" } }";
    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 23 with BsonBinary

use of org.bson.BsonBinary in project mongo-java-driver by mongodb.

the class JsonReaderTest method testLegacyUserDefinedBinary.

@Test
public void testLegacyUserDefinedBinary() {
    String json = "{ \"$binary\" : \"AQID\", \"$type\" : \"80\" }";
    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 24 with BsonBinary

use of org.bson.BsonBinary in project mongo-java-driver by mongodb.

the class JsonReaderTest method testHexData.

@Test
public void testHexData() {
    final byte[] expectedBytes = new byte[] { 0x01, 0x23 };
    String json = "HexData(0, \"0123\")";
    testStringAndStream(json, bsonReader -> {
        assertEquals(BsonType.BINARY, bsonReader.readBsonType());
        BsonBinary binary = bsonReader.readBinaryData();
        assertArrayEquals(expectedBytes, binary.getData());
        assertEquals(AbstractBsonReader.State.DONE, bsonReader.getState());
        return null;
    });
}
Also used : BsonBinary(org.bson.BsonBinary) Test(org.junit.Test)

Example 25 with BsonBinary

use of org.bson.BsonBinary in project mongo-java-driver by mongodb.

the class JsonReaderTest method testHexDataWithNew.

@Test
public void testHexDataWithNew() {
    final byte[] expectedBytes = new byte[] { 0x01, 0x23 };
    String json = "new HexData(0, \"0123\")";
    testStringAndStream(json, bsonReader -> {
        assertEquals(BsonType.BINARY, bsonReader.readBsonType());
        BsonBinary binary = bsonReader.readBinaryData();
        assertArrayEquals(expectedBytes, 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