|
@@ -1,42 +0,0 @@
|
|
|
-package ieven.server.webapp.service.impl;
|
|
|
-
|
|
|
-import com.mongodb.MongoException;
|
|
|
-import com.mongodb.client.FindIterable;
|
|
|
-import com.mongodb.client.MongoCollection;
|
|
|
-import com.mongodb.client.model.Filters;
|
|
|
-import ieven.server.webapp.util.Properties;
|
|
|
-import org.bson.Document;
|
|
|
-import org.bson.conversions.Bson;
|
|
|
-import org.bson.types.ObjectId;
|
|
|
-import org.junit.jupiter.api.Test;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.boot.test.context.SpringBootTest;
|
|
|
-import org.springframework.dao.DataAccessException;
|
|
|
-import org.springframework.data.mongodb.core.CollectionCallback;
|
|
|
-import org.springframework.data.mongodb.core.MongoTemplate;
|
|
|
-
|
|
|
-import java.util.logging.Logger;
|
|
|
-
|
|
|
-@SpringBootTest
|
|
|
-class TestServiceImplTest {
|
|
|
- private final Logger logger = Logger.getLogger("TestServiceImplTest");
|
|
|
- @Autowired
|
|
|
- private MongoTemplate mongoTemplate;
|
|
|
-
|
|
|
- @Test
|
|
|
- void testFind() {
|
|
|
- String json = mongoTemplate.execute(Properties.COLLECTION_UPLOADED, new CollectionCallback<String>() {
|
|
|
- @Override
|
|
|
- public String doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException {
|
|
|
- String json = null;
|
|
|
- Bson queryBson = Filters.eq("_id",new ObjectId("61765d10eda4a31a6582df6a"));
|
|
|
- FindIterable<Document> finds = collection.find(queryBson);
|
|
|
- for (Document document : finds) {
|
|
|
- json = document.toJson();
|
|
|
- }
|
|
|
- logger.info(json);
|
|
|
- return json;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-}
|