本文整理汇总了Java中org.bson.BsonDocument.containsKey方法的典型用法代码示例。如果您正苦于以下问题:Java BsonDocument.containsKey方法的具体用法?Java BsonDocument.containsKey怎么用?Java BsonDocument.containsKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bson.BsonDocument
的用法示例。
在下文中一共展示了BsonDocument.containsKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPatchAppliedCleanly
import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test
public void testPatchAppliedCleanly() throws Exception {
for (int i = 0; i < jsonNode.size(); i++) {
BsonDocument node = jsonNode.get(i).asDocument();
BsonValue first = node.get("first");
BsonValue second = node.get("second");
BsonArray patch = node.getArray("patch");
String message = node.containsKey("message") ? node.getString("message").getValue() : "";
// System.out.println("Test # " + i);
// System.out.println(first);
// System.out.println(second);
// System.out.println(patch);
BsonValue secondPrime = BsonPatch.apply(patch, first);
// System.out.println(secondPrime);
Assert.assertThat(message, secondPrime, equalTo(second));
}
}
示例2: commandStarted
import org.bson.BsonDocument; //导入方法依赖的package包/类
public void commandStarted(CommandStartedEvent event) {
BsonDocument document = event.getCommand();
Labels.Builder labels = Labels.builder();
String commandName = event.getCommandName();
labels.add(MongoLabels.COMMAND_NAME, commandName);
String databaseName = event.getDatabaseName();
labels.add(MongoLabels.DATABASE_NAME, databaseName);
labels.add(MongoLabels.REQUEST_ID, Integer.toString(event.getRequestId()));
if (document.containsKey("batchSize")) {
int batchSize = document.getInt32("batchSize").getValue();
labels.add(MongoLabels.BATCH_SIZE, Integer.toString(batchSize));
}
String collectionKey = collectionKeyByCommand.get(commandName);
if (collectionKey != null && document.containsKey(collectionKey)) {
String collectionName = document.getString(collectionKey).getValue();
labels.add(MongoLabels.COLLECTION_NAME, collectionName);
}
TraceContext context = tracer.startSpan(commandName);
tracer.annotateSpan(context, labels.build());
contexts.set(new MongoDBCommandTraceContext(context, event.getRequestId()));
}
开发者ID:GoogleCloudPlatform,项目名称:cloud-trace-java-instrumentation,代码行数:23,代码来源:TracingCommandListener.java
示例3: testOperation
import org.bson.BsonDocument; //导入方法依赖的package包/类
private void testOperation() throws Exception {
BsonDocument node = p.getNode();
BsonValue doc = node.get("node");
BsonValue expected = node.get("expected");
BsonArray patch = node.getArray("op");
String message = node.containsKey("message") ? node.getString("message").getValue() : "";
BsonValue result = BsonPatch.apply(patch, doc);
String failMessage = "The following test failed: \n" +
"message: " + message + '\n' +
"at: " + p.getSourceFile();
assertEquals(failMessage, expected, result);
}
示例4: testError
import org.bson.BsonDocument; //导入方法依赖的package包/类
private void testError() throws ClassNotFoundException {
BsonDocument node = p.getNode();
BsonValue first = node.get("node");
BsonArray patch = node.getArray("op");
String message = node.containsKey("message") ? node.getString("message").getValue() : "";
Class<?> type =
node.containsKey("type") ? exceptionType(node.getString("type").getValue()) : BsonPatchApplicationException.class;
try {
BsonPatch.apply(patch, first);
fail(errorMessage("Failure expected: " + message));
} catch (Exception e) {
if (matchOnErrors()) {
StringWriter fullError = new StringWriter();
e.printStackTrace(new PrintWriter(fullError));
assertThat(
errorMessage("Operation failed but with wrong exception type", e),
e,
instanceOf(type));
if (message != null) {
assertThat(
errorMessage("Operation failed but with wrong message", e),
e.getMessage(),
containsString(message)); // equalTo would be better, but fail existing tests
}
}
}
}
示例5: isUnique
import org.bson.BsonDocument; //导入方法依赖的package包/类
private static boolean isUnique(BsonDocument doc) {
return doc.containsKey(UNIQUE) && doc.getBoolean(UNIQUE).getValue();
}