本文整理匯總了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();
}