1 package dst.ass1.doc.tests;
3 import static org.hamcrest.CoreMatchers.hasItems;
4 import static org.junit.Assert.assertEquals;
5 import static org.junit.Assert.assertNotNull;
6 import static org.junit.Assert.assertThat;
10 import java.util.stream.Collectors;
12 import org.bson.Document;
13 import org.junit.ClassRule;
14 import org.junit.Rule;
15 import org.junit.Test;
17 import dst.ass1.doc.DocumentTestData;
18 import dst.ass1.doc.EmbeddedMongo;
19 import dst.ass1.doc.MongoService;
21 public class Ass1_4_3_02Test {
24 public static EmbeddedMongo embeddedMongo = new EmbeddedMongo();
27 public MongoService mongo = new MongoService(new DocumentTestData());
30 public void getDocumentStatistics_returnsCorrectStatistics() throws Exception {
31 List<Document> documentStatistics = mongo.getDocumentQuery().getDocumentStatistics();
32 assertNotNull(documentStatistics);
33 assertEquals(3, documentStatistics.size());
35 List<String> types = documentStatistics.stream().map(d -> d.getString("_id")).collect(Collectors.toList());
36 assertThat("expected three aggregation keys", types, hasItems("single-choice", "multiple-choice", "text"));
38 Map<String, Double> dsMap = documentStatistics.stream().collect(Collectors.toMap(
39 d -> d.getString("_id"),
40 d -> d.getDouble("value"))
43 assertEquals(4.0d, dsMap.get("single-choice"), 0);
44 assertEquals(1.0d, dsMap.get("multiple-choice"), 0);
45 assertEquals(7.0d, dsMap.get("text"), 0);