use of org.bson.BsonObjectId in project core-ng-project by neowu.
the class EntityCodecTest method getDocumentId.
@Test
void getDocumentId() {
TestEntity entity = new TestEntity();
entity.id = new ObjectId();
assertEquals(new BsonObjectId(entity.id), entityCodec.getDocumentId(entity));
}
use of org.bson.BsonObjectId in project drill by axbaretto.
the class TestBsonRecordReader method testObjectIdType.
@Test
public void testObjectIdType() throws IOException {
BsonDocument bsonDoc = new BsonDocument();
BsonObjectId value = new BsonObjectId(new ObjectId());
bsonDoc.append("_idKey", value);
writer.reset();
bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
byte[] readByteArray = mapReader.reader("_idKey").readByteArray();
assertTrue(Arrays.equals(value.getValue().toByteArray(), readByteArray));
}
use of org.bson.BsonObjectId in project drill by apache.
the class TestBsonRecordReader method testObjectIdType.
@Test
public void testObjectIdType() throws IOException {
BsonDocument bsonDoc = new BsonDocument();
BsonObjectId value = new BsonObjectId(new ObjectId());
bsonDoc.append("_idKey", value);
writer.reset();
bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
byte[] readByteArray = mapReader.reader("_idKey").readByteArray();
assertArrayEquals(value.getValue().toByteArray(), readByteArray);
}
use of org.bson.BsonObjectId in project pinpoint by naver.
the class WritecontextTest method parseBsonArrayWithValues.
@Test
public void parseBsonArrayWithValues() throws IOException {
BsonValue a = new BsonString("stest");
BsonValue b = new BsonDouble(111);
BsonValue c = new BsonBoolean(true);
BsonDocument document = new BsonDocument().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()).append("decimal128", new BsonDecimal128(new Decimal128(55)));
BasicDBObject query = new BasicDBObject();
query.put("ComplexBson", document);
logger.debug("document:{}", document);
NormalizedBson stringStringValue = MongoUtil.parseBson(new Object[] { query }, true);
logger.debug("val:{}", stringStringValue);
List list = objectMapper.readValue("[" + stringStringValue.getNormalizedBson() + "]", List.class);
Assert.assertEquals(list.size(), 1);
Map<String, ?> query1Map = (Map<String, ?>) list.get(0);
checkValue(query1Map);
}
use of org.bson.BsonObjectId in project mongo-java-driver by mongodb.
the class GridFSTest method doUpload.
private void doUpload(final BsonDocument rawArguments, final BsonDocument assertion) {
Throwable error = null;
ObjectId objectId = null;
BsonDocument arguments = parseHexDocument(rawArguments, "source");
try {
String filename = arguments.getString("filename").getValue();
InputStream input = new ByteArrayInputStream(arguments.getBinary("source").getData());
GridFSUploadOptions options = new GridFSUploadOptions();
BsonDocument rawOptions = arguments.getDocument("options", new BsonDocument());
if (rawOptions.containsKey("chunkSizeBytes")) {
options = options.chunkSizeBytes(rawOptions.getInt32("chunkSizeBytes").getValue());
}
if (rawOptions.containsKey("metadata")) {
options = options.metadata(Document.parse(rawOptions.getDocument("metadata").toJson()));
}
objectId = gridFSBucket.uploadFromStream(filename, input, options);
} catch (Throwable e) {
error = e;
}
if (assertion.containsKey("error")) {
// We don't need to read anything more so don't see the extra chunk
if (!assertion.getString("error").getValue().equals("ExtraChunk")) {
assertNotNull("Should have thrown an exception", error);
}
} else {
assertNull("Should not have thrown an exception", error);
for (BsonValue rawDataItem : assertion.getArray("data", new BsonArray())) {
BsonDocument dataItem = rawDataItem.asDocument();
String insert = dataItem.getString("insert", new BsonString("none")).getValue();
if (insert.equals("expected.files")) {
List<BsonDocument> documents = processFiles(dataItem.getArray("documents", new BsonArray()), new ArrayList<BsonDocument>());
assertEquals(filesCollection.count(), documents.size());
BsonDocument actual = filesCollection.find().first();
for (BsonDocument expected : documents) {
assertEquals(expected.get("length"), actual.get("length"));
assertEquals(expected.get("chunkSize"), actual.get("chunkSize"));
assertEquals(expected.get("md5"), actual.get("md5"));
assertEquals(expected.get("filename"), actual.get("filename"));
if (expected.containsKey("metadata")) {
assertEquals(expected.get("metadata"), actual.get("metadata"));
}
}
} else if (insert.equals("expected.chunks")) {
List<BsonDocument> documents = processChunks(dataItem.getArray("documents", new BsonArray()), new ArrayList<BsonDocument>());
assertEquals(chunksCollection.count(), documents.size());
List<BsonDocument> actualDocuments = chunksCollection.find().into(new ArrayList<BsonDocument>());
for (int i = 0; i < documents.size(); i++) {
BsonDocument expected = documents.get(i);
BsonDocument actual = actualDocuments.get(i);
assertEquals(new BsonObjectId(objectId), actual.getObjectId("files_id"));
assertEquals(expected.get("n"), actual.get("n"));
assertEquals(expected.get("data"), actual.get("data"));
}
}
}
}
}
Aggregations