use of org.bson.BsonString in project spring-data-mongodb by spring-projects.
the class GridFsTemplateIntegrationTests method storeSavesGridFsUploadWithGivenIdCorrectly.
// DATAMONGO-625
@Test
public void storeSavesGridFsUploadWithGivenIdCorrectly() throws IOException {
String id = "id-1";
GridFsUpload<String> upload = //
GridFsUpload.fromStream(resource.getInputStream()).id(//
id).filename(//
"gridFsUpload.xml").contentType(//
"xml").build();
assertThat(operations.store(upload)).isEqualTo(id);
GridFsResource fsFile = operations.getResource(operations.findOne(query(where("_id").is(id))));
byte[] content = StreamUtils.copyToByteArray(fsFile.getInputStream());
assertThat(content).isEqualTo(StreamUtils.copyToByteArray(resource.getInputStream()));
assertThat(fsFile.getFilename()).isEqualTo("gridFsUpload.xml");
assertThat(fsFile.getId()).isEqualTo(new BsonString(id));
assertThat(fsFile.getFileId()).isEqualTo(id);
assertThat(fsFile.getContentType()).isEqualTo("xml");
}
use of org.bson.BsonString in project spring-data-mongodb by spring-projects.
the class ReactiveGridFsTemplateTests method storeSavesGridFsUploadWithGivenIdCorrectly.
// DATAMONGO-625
@Test
public void storeSavesGridFsUploadWithGivenIdCorrectly() throws IOException {
String id = "id-1";
byte[] content = StreamUtils.copyToByteArray(resource.getInputStream());
Flux<DataBuffer> data = DataBufferUtils.read(resource, new DefaultDataBufferFactory(), 256);
ReactiveGridFsUpload<String> upload = //
ReactiveGridFsUpload.fromPublisher(data).id(//
id).filename(//
"gridFsUpload.xml").contentType(//
"xml").build();
operations.store(upload).as(StepVerifier::create).expectNext(id).verifyComplete();
operations.findOne(query(where("_id").is(id))).flatMap(operations::getResource).flatMapMany(//
ReactiveGridFsResource::getDownloadStream).transform(//
DataBufferUtils::join).as(//
StepVerifier::create).consumeNextWith(dataBuffer -> {
byte[] actual = new byte[dataBuffer.readableByteCount()];
dataBuffer.read(actual);
assertThat(actual).isEqualTo(content);
}).verifyComplete();
operations.findOne(query(where("_id").is(id))).as(StepVerifier::create).consumeNextWith(it -> {
assertThat(it.getFilename()).isEqualTo("gridFsUpload.xml");
assertThat(it.getId()).isEqualTo(new BsonString(id));
assertThat(it.getMetadata()).containsValue("xml");
}).verifyComplete();
}
use of org.bson.BsonString in project brave by openzipkin.
the class TraceMongoCommandListenerTest method getCollectionName_allowListedCommandAndCollectionField.
@Test
public void getCollectionName_allowListedCommandAndCollectionField() {
BsonDocument command = new BsonDocument(Arrays.asList(new BsonElement("collection", new BsonString("coll")), new BsonElement("find", new BsonString("bar"))));
// command wins
assertThat(listener.getCollectionName(command, "find")).isEqualTo("bar");
}
use of org.bson.BsonString in project mongo-java-driver by mongodb.
the class UserOperationHelper method asCommandDocument.
static BsonDocument asCommandDocument(final MongoCredential credential, final boolean readOnly, final String commandName) {
BsonDocument document = new BsonDocument();
document.put(commandName, new BsonString(credential.getUserName()));
document.put("pwd", new BsonString(createAuthenticationHash(credential.getUserName(), credential.getPassword())));
document.put("digestPassword", BsonBoolean.FALSE);
document.put("roles", new BsonArray(Arrays.<BsonValue>asList(new BsonString(getRoleName(credential, readOnly)))));
return document;
}
use of org.bson.BsonString in project morphia by mongodb.
the class IndexHelperTest method calculateKeys.
@Test
public void calculateKeys() {
MappedClass mappedClass = getMorphia().getMapper().getMappedClass(IndexedClass.class);
BsonDocument keys = indexHelper.calculateKeys(mappedClass, new IndexBuilder().fields(new FieldBuilder().value("text").type(IndexType.TEXT).weight(1), new FieldBuilder().value("nest").type(IndexType.DESC)));
assertEquals(new BsonDocument().append("text", new BsonString("text")).append("nest", new BsonInt32(-1)), keys);
}
Aggregations