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);
}
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);
}
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));
}
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;
}
Aggregations