本文整理汇总了Java中org.bson.types.ObjectId.toString方法的典型用法代码示例。如果您正苦于以下问题:Java ObjectId.toString方法的具体用法?Java ObjectId.toString怎么用?Java ObjectId.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bson.types.ObjectId
的用法示例。
在下文中一共展示了ObjectId.toString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUpdateGroup
import org.bson.types.ObjectId; //导入方法依赖的package包/类
/**
* Add a new group object to the database. Call PUT using the id of the new mongo object to update
* the group information (name, members list, occasions list). Verify that the group information
* has been updated
*
* @throws GeneralSecurityException
*/
@Test
public void testUpdateGroup() throws IOException, GeneralSecurityException {
System.out.println("\nStarting testUpdateGroup");
// Create group in database
Group group = new Group(null, "testGroup", new String[] {"12345", "23456"});
BasicDBObject dbGroup = group.getDBObject(false);
db.getCollection(Group.DB_COLLECTION_NAME).insert(dbGroup);
group.setId(dbGroup.getObjectId(Group.DB_ID).toString());
// Create updated group
ObjectId groupId = dbGroup.getObjectId(Group.DB_ID);
Group newGroup = new Group(groupId.toString(), "newTestGroup", new String[] {"12345"});
String url = groupServiceURL + "/" + groupId;
makeConnection("PUT", url, newGroup.getJson(), 200);
// Verify that the new group information is in mongo
BasicDBObject newDBGroup = (BasicDBObject) db.getCollection("groups").findOne(groupId);
assertNotNull("Group testGroup was not found in the database.", newDBGroup);
assertTrue(
"Group in database does not contain the expected data", newGroup.isEqual(newDBGroup));
}
示例2: insertCityItem
import org.bson.types.ObjectId; //导入方法依赖的package包/类
/**
*
* @param cityItem Wrapper object for JSON values
* @return id of inserted document
*/
public static String insertCityItem(CityItem cityItem)
{
ObjectId id = new ObjectId();
Document post = new Document();
post.put("_id",id);
post.put("type", Integer.toString(cityItem.getType()));
post.put("location",new Document("x",String.valueOf(cityItem.getLongitude()))
.append("y",String.valueOf(cityItem.getLatitude())));
post.put("description", cityItem.getDescription());
MongoCollection<Document> collection = Configurator.INSTANCE.getDatabase().getCollection(COLLECTION);
try {
collection.insertOne(post);
return id.toString();
} catch (DuplicateKeyException e) {
e.printStackTrace();
return "-1";
}
}
示例3: testDuplicateKeyFailureOrderedFalse
import org.bson.types.ObjectId; //导入方法依赖的package包/类
@Test
public void testDuplicateKeyFailureOrderedFalse() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new StoreInMongo());
addMongoService(runner);
runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
runner.setProperty(MongoProps.COLLECTION, "insert_test");
runner.setProperty(MongoProps.BATCH_SIZE, "10");
runner.setProperty(MongoProps.ORDERED, "false");
ObjectId objectId = ObjectId.get();
String success = FileUtils.readFileToString(Paths.get("src/test/resources/payload.json").toFile());
String successTwo = "{\"a\":\"a\"}";
String payloadOne = "{\"_id\":\"" + objectId.toString() + "\", \"text\": \"first value\"}";
String payloadTwo = "{\"_id\":\"" + objectId.toString() + "\", \"text\": \"second value\"}";
runner.enqueue(payloadOne.getBytes());
runner.enqueue(success.getBytes());
runner.enqueue(payloadTwo.getBytes());
runner.enqueue(successTwo.getBytes()); // add another successful message
runner.run();
runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 1);
runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 3);
FlowFile failure = runner.getFlowFilesForRelationship(AbstractMongoProcessor.REL_FAILURE).get(0);
String errorCode = failure.getAttribute("mongo.errorcode");
assertEquals("11000", errorCode); // duplicate key error code
String errorMessage = failure.getAttribute("mongo.errormessage");
assertTrue(StringUtils.isNotBlank(errorMessage));
// Test contents of mongo
MongoCollection<Document> collection = mongo.getMongoClient().getDatabase(MONGO_DATABASE_NAME).getCollection("insert_test");
assertEquals(3L, collection.count());
}
示例4: testDuplicateKeyFailureWithoutBatching
import org.bson.types.ObjectId; //导入方法依赖的package包/类
@Test
public void testDuplicateKeyFailureWithoutBatching() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new StoreInMongo());
addMongoService(runner);
runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
runner.setProperty(MongoProps.COLLECTION, "insert_test");
runner.setProperty(MongoProps.BATCH_SIZE, "1");
runner.setProperty(MongoProps.ORDERED, "true");
ObjectId objectId = ObjectId.get();
String success = FileUtils.readFileToString(Paths.get("src/test/resources/payload.json").toFile());
String successTwo = "{\"a\":\"a\"}";
String payloadOne = "{\"_id\":\"" + objectId.toString() + "\", \"text\": \"first value\"}";
String payloadTwo = "{\"_id\":\"" + objectId.toString() + "\", \"text\": \"second value\"}";
runner.enqueue(payloadOne.getBytes());
runner.enqueue(success.getBytes());
runner.enqueue(payloadTwo.getBytes());
runner.enqueue(successTwo.getBytes()); // add another successful message
runner.run(runner.getQueueSize().getObjectCount()); // run through the entire queue
runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 1);
runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 3);
FlowFile failure = runner.getFlowFilesForRelationship(AbstractMongoProcessor.REL_FAILURE).get(0);
String errorCode = failure.getAttribute("mongo.errorcode");
assertEquals("11000", errorCode); // duplicate key error code
String errorMessage = failure.getAttribute("mongo.errormessage");
assertTrue(StringUtils.isNotBlank(errorMessage));
}
示例5: testDuplicateKeyFailureOrderedTrue
import org.bson.types.ObjectId; //导入方法依赖的package包/类
@Test
public void testDuplicateKeyFailureOrderedTrue() throws Exception {
final TestRunner runner = TestRunners.newTestRunner(new StoreInMongo());
addMongoService(runner);
runner.setProperty(MongoProps.DATABASE, MONGO_DATABASE_NAME);
runner.setProperty(MongoProps.COLLECTION, "insert_test");
runner.setProperty(MongoProps.BATCH_SIZE, "10");
runner.setProperty(MongoProps.ORDERED, "true");
ObjectId objectId = ObjectId.get();
String success = FileUtils.readFileToString(Paths.get("src/test/resources/payload.json").toFile());
String successTwo = "{\"a\":\"a\"}";
String payloadOne = "{\"_id\":\"" + objectId.toString() + "\", \"text\": \"first value\"}";
String payloadTwo = "{\"_id\":\"" + objectId.toString() + "\", \"text\": \"second value\"}";
runner.enqueue(payloadOne.getBytes());
runner.enqueue(success.getBytes());
runner.enqueue(payloadTwo.getBytes());
runner.enqueue(successTwo.getBytes()); // add another successful message
runner.run();
runner.assertTransferCount(AbstractMongoProcessor.REL_FAILURE, 2);
runner.assertTransferCount(AbstractMongoProcessor.REL_SUCCESS, 2);
List<MockFlowFile> failures = runner.getFlowFilesForRelationship(AbstractMongoProcessor.REL_FAILURE);
FlowFile failure1 = failures.get(0);
String errorCode1 = failure1.getAttribute("mongo.errorcode");
assertEquals("11000", errorCode1); // duplicate key error code
String errorMessage1 = failure1.getAttribute("mongo.errormessage");
assertTrue(StringUtils.isNotBlank(errorMessage1));
FlowFile failure2 = failures.get(1);
String errorMessage2 = failure2.getAttribute("storeinmongo.error");
assertTrue(StringUtils.isNotBlank(errorMessage2));
String mongoErrorCode2 = failure2.getAttribute("mongo.errorcode");
assertTrue(StringUtils.isBlank(mongoErrorCode2));
// Test contents of mongo
MongoCollection<Document> collection = mongo.getMongoClient().getDatabase(MONGO_DATABASE_NAME).getCollection("insert_test");
assertEquals(2L, collection.count());
}