1
|
package eu.dnetlib.data.mdstore.modular.mongodb;
|
2
|
|
3
|
import com.mongodb.BasicDBObject;
|
4
|
import com.mongodb.DBObject;
|
5
|
import com.mongodb.client.MongoCollection;
|
6
|
import com.mongodb.client.MongoDatabase;
|
7
|
import eu.dnetlib.data.mdstore.MDStoreServiceException;
|
8
|
import eu.dnetlib.data.mdstore.modular.connector.MDStoreDao;
|
9
|
import eu.dnetlib.data.mdstore.modular.connector.MDStoreTransactionManager;
|
10
|
import org.junit.After;
|
11
|
import org.junit.Before;
|
12
|
import org.junit.Ignore;
|
13
|
import org.junit.Test;
|
14
|
import org.junit.runner.RunWith;
|
15
|
import org.springframework.beans.factory.annotation.Autowired;
|
16
|
import org.springframework.test.context.ContextConfiguration;
|
17
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
18
|
|
19
|
import static org.junit.Assert.assertEquals;
|
20
|
|
21
|
@Ignore
|
22
|
@RunWith(SpringJUnit4ClassRunner.class)
|
23
|
@ContextConfiguration(classes = ConfigurationTestConfig.class)
|
24
|
public class MDStoreDaoImplTest {
|
25
|
|
26
|
@Autowired
|
27
|
private MDStoreDao dao;
|
28
|
@Autowired
|
29
|
private MongoDatabase db;
|
30
|
@Autowired
|
31
|
private MDStoreTransactionManager manager;
|
32
|
|
33
|
@After
|
34
|
public void tearDown() throws MDStoreServiceException {
|
35
|
dao.deleteMDStore("1");
|
36
|
dao.deleteMDStore("2");
|
37
|
dao.deleteMDStore("3");
|
38
|
dao.deleteMDStore("4");
|
39
|
dao.deleteMDStore("5");
|
40
|
dao.deleteMDStore("6");
|
41
|
}
|
42
|
|
43
|
@Before
|
44
|
public void setUp() throws Exception {
|
45
|
dao.createMDStore("1", "F", "I", "L");
|
46
|
dao.createMDStore("2", "F", "I", "L");
|
47
|
dao.createMDStore("3", "F", "I", "L");
|
48
|
dao.createMDStore("4", "F", "I", "L");
|
49
|
dao.createMDStore("5", "F1", "I", "L");
|
50
|
dao.createMDStore("6", "F1", "I", "L");
|
51
|
|
52
|
final MongoCollection<DBObject> metadata = db.getCollection(MDStoreDaoImpl.METADATA_NAME, DBObject.class);
|
53
|
|
54
|
metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "1"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10)));
|
55
|
metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "2"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10)));
|
56
|
metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "3"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10)));
|
57
|
metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "4"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10)));
|
58
|
metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "5"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10)));
|
59
|
metadata.findOneAndUpdate(new BasicDBObject(MDStoreDaoImpl.MD_ID, "6"), new BasicDBObject("$set", new BasicDBObject(MDStoreDaoImpl.SIZE, 10)));
|
60
|
|
61
|
}
|
62
|
|
63
|
@Test
|
64
|
public void test() throws MDStoreServiceException {
|
65
|
assertEquals(40, dao.getSumOfSizes("F", "L", "I"));
|
66
|
assertEquals(20, dao.getSumOfSizes("F1", "L", "I"));
|
67
|
assertEquals(0, dao.getSumOfSizes("F_0", "L", "I"));
|
68
|
}
|
69
|
|
70
|
}
|