补全代码private MongoClient mongoClient; @Before public void initMongoClient() throws IOException { mongoClient = MongoDBUtil.(1); @Test(timeout = 1000) public void saveCommentTest() throws llgalArgumentException, llegalAccessException { Document document = ConvetUtil.convertDac(this.(2)); mongoClient.getDatabase("CommentTest").getCollection("comment") .insertOnel(3)); @Test public void queryCommentTest() { Findlterable<Document> iter = (4).getDatabase((5)) .getCollection("comment").(6); iter.forEach(new Block<Document>() { public void apply(Document doc) { System.out.printin(doc.toJson(); } }); @After public void closeMongoClient() { mongoClient.(7); } private Comment initComment() { List<CommentL .abel> commentL abels = new ArrayL ist<CommentL .abel>(); CommentL .abel commentL abel1 = new CommentL abel(); commentL abel1.setContent("商品不错"); CommentL abel commentl abel2 = new CommentL abel(); commentL abel2.setContent("非常耐用"); commentL abels. add(commentL abel1); commentL abels. add(commentL _abel2); Comment comment = new Comment(); comment.setCommentL .abels(JsonUtil.toJson(commentl .abels)); comment.setConten("快递非常快,下次还会买。"); comment.setCreatedTime(new Date(); comment.setPid(9000198); comment.setStar("4"); comment.setUserName("admin"); return (8); } }
时间: 2024-04-01 21:32:30 浏览: 71
BeanPostProcessor实现注入的@Autowired注入的对象是增强的代理对象.rar
private MongoClient mongoClient;
@Before
public void initMongoClient() throws IOException {
mongoClient = MongoDBUtil.getMongoClient();
}
@Test(timeout = 1000)
public void saveCommentTest() throws llgalArgumentException, llegalAccessException {
Document document = ConvetUtil.convertDac(this.initComment());
mongoClient.getDatabase("CommentTest").getCollection("comment")
.insertOne(document));
}
@Test
public void queryCommentTest() {
FindIterable<Document> iter = mongoClient.getDatabase("CommentTest")
.getCollection("comment").find();
iter.forEach(new Block<Document>() {
public void apply(Document doc) {
System.out.printin(doc.toJson();
}
});
}
@After
public void closeMongoClient() {
mongoClient.close();
}
private Comment initComment() {
List<Comment.Label> commentLabels = new ArrayList<Comment.Label>();
Comment.Label commentLabel1 = new Comment.Label();
commentLabel1.setContent("商品不错");
Comment.Label commentLabel2 = new Comment.Label();
commentLabel2.setContent("非常耐用");
commentLabels.add(commentLabel1);
commentLabels.add(commentLabel2);
Comment comment = new Comment();
comment.setCommentLabels(JsonUtil.toJson(commentLabels));
comment.setContent("快递非常快,下次还会买。");
comment.setCreatedTime(new Date());
comment.setPid(9000198);
comment.setStar("4");
comment.setUserName("admin");
return comment;
}
阅读全文