Search in sources :

Example 36 with BsonObjectId

use of org.bson.BsonObjectId in project spring-data-mongodb by spring-projects.

the class GridFsTemplateIntegrationTests method convertFileToResource.

// DATAMONGO-1813
@Test
public void convertFileToResource() throws IOException {
    Document metadata = new Document("key", "value");
    ObjectId reference = operations.store(resource.getInputStream(), "foobar", metadata);
    GridFSFile file = operations.findOne(query(whereMetaData("key").is("value")));
    GridFsResource result = operations.getResource(file);
    assertThat(result.contentLength()).isEqualTo(resource.contentLength());
    assertThat(((BsonObjectId) result.getId()).getValue()).isEqualTo(reference);
}
Also used : BsonObjectId(org.bson.BsonObjectId) ObjectId(org.bson.types.ObjectId) GridFSFile(com.mongodb.client.gridfs.model.GridFSFile) Document(org.bson.Document) BsonObjectId(org.bson.BsonObjectId) Test(org.junit.Test)

Example 37 with BsonObjectId

use of org.bson.BsonObjectId in project spring-data-mongodb by spring-projects.

the class GridFsResourceUnitTests method shouldThrowExceptionOnEmptyContentTypeInMetadata.

// DATAMONGO-1850
@Test
public void shouldThrowExceptionOnEmptyContentTypeInMetadata() {
    GridFSFile file = new GridFSFile(new BsonObjectId(), "foo", 0, 0, new Date(), new Document());
    GridFsResource resource = new GridFsResource(file);
    assertThatThrownBy(resource::getContentType).isInstanceOf(MongoGridFSException.class);
}
Also used : GridFSFile(com.mongodb.client.gridfs.model.GridFSFile) Document(org.bson.Document) BsonObjectId(org.bson.BsonObjectId) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 38 with BsonObjectId

use of org.bson.BsonObjectId in project spring-data-mongodb by spring-projects.

the class BsonUtilsTest method objectIdToBsonValue.

// DATAMONGO-625
@Test
void objectIdToBsonValue() {
    ObjectId source = new ObjectId();
    assertThat(BsonUtils.simpleToBsonValue(source)).isEqualTo(new BsonObjectId(source));
}
Also used : BsonObjectId(org.bson.BsonObjectId) ObjectId(org.bson.types.ObjectId) BsonObjectId(org.bson.BsonObjectId) Test(org.junit.jupiter.api.Test)

Example 39 with BsonObjectId

use of org.bson.BsonObjectId in project pinpoint by naver.

the class MongoDBITBase method createComplexDocument.

private Document createComplexDocument() {
    // insert Data
    BsonValue a = new BsonString("stest");
    BsonValue b = new BsonDouble(111);
    BsonValue c = new BsonBoolean(true);
    Document document = new Document().append("int32", new BsonInt32(12)).append("int64", new BsonInt64(77L)).append("bo\"olean", new BsonBoolean(true)).append("date", new BsonDateTime(new Date().getTime())).append("double", new BsonDouble(12.3)).append("string", new BsonString("pinpoint")).append("objectId", new BsonObjectId(new ObjectId())).append("code", new BsonJavaScript("int i = 10;")).append("codeWithScope", new BsonJavaScriptWithScope("int x = y", new BsonDocument("y", new BsonInt32(1)))).append("regex", new BsonRegularExpression("^test.*regex.*xyz$", "big")).append("symbol", new BsonSymbol("wow")).append("timestamp", new BsonTimestamp(0x12345678, 5)).append("undefined", new BsonUndefined()).append("binary1", new BsonBinary(new byte[] { (byte) 0xe0, 0x4f, (byte) 0xd0, 0x20 })).append("oldBinary", new BsonBinary(BsonBinarySubType.OLD_BINARY, new byte[] { 1, 1, 1, 1, 1 })).append("arrayInt", new BsonArray(Arrays.asList(a, b, c, new BsonInt32(7)))).append("document", new BsonDocument("a", new BsonInt32(77))).append("dbPointer", new BsonDbPointer("db.coll", new ObjectId())).append("null", new BsonNull());
    return document;
}
Also used : BsonNull(org.bson.BsonNull) BsonObjectId(org.bson.BsonObjectId) ObjectId(org.bson.types.ObjectId) BsonBinary(org.bson.BsonBinary) BsonDbPointer(org.bson.BsonDbPointer) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) BsonRegularExpression(org.bson.BsonRegularExpression) BsonBoolean(org.bson.BsonBoolean) BsonObjectId(org.bson.BsonObjectId) BsonJavaScript(org.bson.BsonJavaScript) Date(java.util.Date) BsonTimestamp(org.bson.BsonTimestamp) BsonInt64(org.bson.BsonInt64) BsonInt32(org.bson.BsonInt32) BsonSymbol(org.bson.BsonSymbol) BsonDocument(org.bson.BsonDocument) BsonDateTime(org.bson.BsonDateTime) BsonString(org.bson.BsonString) BsonArray(org.bson.BsonArray) BsonDouble(org.bson.BsonDouble) BsonJavaScriptWithScope(org.bson.BsonJavaScriptWithScope) BsonUndefined(org.bson.BsonUndefined) BsonValue(org.bson.BsonValue)

Aggregations

BsonObjectId (org.bson.BsonObjectId)39 ObjectId (org.bson.types.ObjectId)30 Test (org.junit.Test)18 GridFSFile (com.mongodb.client.gridfs.model.GridFSFile)14 BsonString (org.bson.BsonString)13 ArrayList (java.util.ArrayList)11 Document (org.bson.Document)11 BsonDocument (org.bson.BsonDocument)10 GridFSFindIterable (com.mongodb.client.gridfs.GridFSFindIterable)8 ByteArrayInputStream (java.io.ByteArrayInputStream)8 Test (org.junit.jupiter.api.Test)8 List (java.util.List)7 BsonValue (org.bson.BsonValue)7 MongoGridFSException (com.mongodb.MongoGridFSException)6 Date (java.util.Date)6 Map (java.util.Map)6 BsonArray (org.bson.BsonArray)6 IOException (java.io.IOException)5 Assertions (org.assertj.core.api.Assertions)5 Before (org.junit.Before)5