本文整理汇总了Java中com.mongodb.BasicDBObject.getObjectId方法的典型用法代码示例。如果您正苦于以下问题:Java BasicDBObject.getObjectId方法的具体用法?Java BasicDBObject.getObjectId怎么用?Java BasicDBObject.getObjectId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.BasicDBObject
的用法示例。
在下文中一共展示了BasicDBObject.getObjectId方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDeleteGroup
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
/**
* Add a new group object to the database. Call DELETE using the id of the new mongo object.
* Verify that the group no longer exists in the database
*
* @throws GeneralSecurityException
*/
@Test
public void testDeleteGroup() throws IOException, GeneralSecurityException {
System.out.println("\nStarting testDeleteGroup");
// Create group in database
Group group = new Group(null, "testGroup", new String[] {"12345"});
BasicDBObject dbGroup = group.getDBObject(false);
db.getCollection(Group.DB_COLLECTION_NAME).insert(dbGroup);
group.setId(dbGroup.getObjectId(Group.DB_ID).toString());
ObjectId groupId = dbGroup.getObjectId(Group.DB_ID);
// Make DELETE call with group id
String url = groupServiceURL + "/" + groupId;
makeConnection("DELETE", url, null, 200);
// Verify that the group no longer exists in mongo
BasicDBObject groupAfterDelete = (BasicDBObject) db.getCollection("groups").findOne(groupId);
assertNull("The group still exists after DELETE was called", groupAfterDelete);
}
示例2: testGetGroupInfo
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
/**
* Add a new group object to the database. Call GET using the id of the new mongo object. Verify
* group info returned matches the group info in the database
*/
@Test
public void testGetGroupInfo() throws Exception {
System.out.println("\nStarting testGetGroupInfo");
// Create group in database
Group group = new Group(null, "testGroup", new String[] {"12345"});
BasicDBObject dbGroup = group.getDBObject(false);
db.getCollection(Group.DB_COLLECTION_NAME).insert(dbGroup);
group.setId(dbGroup.getObjectId(Group.DB_ID).toString());
// Make GET call with group id
String url = groupServiceURL + "/" + dbGroup.getObjectId(Group.DB_ID);
JsonObject response = makeConnection("GET", url, null, 200);
Group returnedGroup = new Group(response.toString());
// Verify the returned group info is correct
assertTrue(
"Group info returned does not match the group info in the database ",
group.isEqual(returnedGroup));
}
示例3: testUpdateGroup
import com.mongodb.BasicDBObject; //导入方法依赖的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));
}
示例4: createOccasion
import com.mongodb.BasicDBObject; //导入方法依赖的package包/类
@POST
@Path("/")
@Consumes(MediaType.APPLICATION_JSON)
public Response createOccasion(JsonObject json) {
String method = "createOccasion";
logger.entering(clazz, method, json);
// Validate the JWT. At this point, anyone create an occasion if they
// have a valid JWT.
try {
validateJWT();
} catch (JWTException jwte) {
logger.exiting(clazz, method, Status.UNAUTHORIZED);
return Response.status(Status.UNAUTHORIZED)
.type(MediaType.TEXT_PLAIN)
.entity(jwte.getMessage())
.build();
}
Response response;
// make sure we received some json
if (null == json || json.toString().isEmpty()) {
response = Response.status(400).entity("Create failed. Empty payload.").build();
} else {
logger.fine("json = " + json);
Occasion occasion = new Occasion(json);
BasicDBObject dbo = occasion.toDbo();
logger.fine("dbo = " + dbo);
// new json payload should not contain an id
ObjectId id = (ObjectId) dbo.get(Occasion.OCCASION_ID_KEY);
logger.fine("id = " + id);
if (null != id && !id.toString().isEmpty()) {
logger.fine("non null id, responding 400");
response =
Response.status(400)
.entity(
"Create failed. Payload must not contain an ID. Recieved ID: \"" + id + "\"")
.build();
} else {
// store the occasion and return the ID
getCollection().insert(dbo);
ObjectId occasionId = dbo.getObjectId(Occasion.OCCASION_ID_KEY);
logger.fine("id: " + occasionId.toString());
String jsonResp =
new Occasion(occasionId, null, null, null, null, null, null, null).toString();
logger.fine(jsonResp);
response = Response.ok(jsonResp, MediaType.APPLICATION_JSON).build();
occasion.setId(occasionId);
// Schedule occasion with the orchestrator
try {
orchestrator.scheduleOccasion(occasion);
} catch (ParseException e) {
e.printStackTrace();
}
}
}
logger.exiting(clazz, method, response.readEntity(String.class));
return response;
}