]> git.somenet.org - pub/jan/dst18.git/blob - ass1-doc/src/test/java/dst/ass1/doc/tests/Ass1_4_3_01Test.java
Make Ass1_4_3_01Test tolerant towards existing collections
[pub/jan/dst18.git] / ass1-doc / src / test / java / dst / ass1 / doc / tests / Ass1_4_3_01Test.java
1 package dst.ass1.doc.tests;
2
3 import static org.junit.Assert.assertNotNull;
4 import static org.junit.Assert.assertTrue;
5
6 import java.util.List;
7 import java.util.stream.StreamSupport;
8
9 import org.bson.Document;
10 import org.junit.ClassRule;
11 import org.junit.Rule;
12 import org.junit.Test;
13
14 import dst.ass1.doc.EmbeddedMongo;
15 import dst.ass1.doc.MongoService;
16 import dst.ass1.jpa.util.Constants;
17
18 public class Ass1_4_3_01Test {
19
20     @ClassRule
21     public static EmbeddedMongo embeddedMongo = new EmbeddedMongo();
22
23     @Rule
24     public MongoService mongo = new MongoService(db -> {
25         boolean exists = StreamSupport.stream(db.listCollectionNames().spliterator(), false)
26                 .anyMatch(Constants.COLL_MATERIAL_DATA::equalsIgnoreCase);
27
28         if (!exists) {
29             db.createCollection(Constants.COLL_MATERIAL_DATA); // make sure the empty collection exists
30         }
31     });
32
33     @Test
34     public void getDocumentStatistics_withEmptyData_returnsEmptyStatistics() throws Exception {
35         List<Document> documentStatistics = mongo.getDocumentQuery().getDocumentStatistics();
36         assertNotNull(documentStatistics);
37         assertTrue(documentStatistics.isEmpty());
38     }
39
40 }