blob: 52a8f717522ea657771229378e546e963d2f3f35 [file] [log] [blame]
Akronb329d272020-11-13 12:45:26 +01001package de.ids_mannheim.korap.plkexport;
2
3import java.io.IOException;
4
5import static org.junit.Assert.assertEquals;
6import static org.junit.Assert.assertNull;
7import static org.junit.Assert.assertTrue;
Akronc51327b2020-11-13 15:21:26 +01008import static org.junit.Assert.assertFalse;
Akronb329d272020-11-13 12:45:26 +01009import static org.junit.Assert.fail;
10import org.junit.Test;
11
12import de.ids_mannheim.korap.plkexport.MatchAggregator;
13
14public class MatchAggregatorTest {
15
16 @Test
17 public void testEmptyInit () throws IOException {
Akron1d36eb52020-11-13 17:52:26 +010018 MatchAggregator m = new MatchAggregator();
19 m.init("");
Akronfddd0582020-11-17 09:49:54 +010020 assertNull(m.getMeta());
21 assertNull(m.getQuery());
22 assertNull(m.getCollection());
Akronc51327b2020-11-13 15:21:26 +010023
Akron1d36eb52020-11-13 17:52:26 +010024 m = new MatchAggregator();
25 m.init(null);
Akronfddd0582020-11-17 09:49:54 +010026 assertNull(m.getMeta());
27 assertNull(m.getQuery());
28 assertNull(m.getCollection());
Akronb329d272020-11-13 12:45:26 +010029 };
30
31 @Test
32 public void testSampleInit () throws IOException {
Akron1d36eb52020-11-13 17:52:26 +010033 MatchAggregator m = new MatchAggregator();
34 m.init("{\"meta\":{\"totalResults\":6}}");
Akronfddd0582020-11-17 09:49:54 +010035 assertEquals(m.getMeta().toString(),"{\"totalResults\":6}");
36 assertNull(m.getQuery());
37 assertNull(m.getCollection());
Akronb329d272020-11-13 12:45:26 +010038 };
Akronc51327b2020-11-13 15:21:26 +010039
40 @Test
41 public void testMatchesInit () throws IOException {
Akron1d36eb52020-11-13 17:52:26 +010042 MatchAggregator m = new MatchAggregator();
43 m.init("{\"matches\":[\"first\",\"second\"]}");
Akronfddd0582020-11-17 09:49:54 +010044 assertNull(m.getMeta());
45 assertNull(m.getQuery());
46 assertNull(m.getCollection());
Akronc51327b2020-11-13 15:21:26 +010047 };
Akron876017d2020-11-17 09:19:24 +010048
49 @Test
50 public void testAttributes () throws IOException {
51 MatchAggregator m = new MatchAggregator();
Akron74122712020-11-17 09:41:21 +010052 m.setFileName("Beispiel");
53 assertEquals(m.getFileName(),"Beispiel");
54 m.setFileName("contains(<s name=\"okay\">,[orth='Test'])");
55 assertEquals(m.getFileName(),"contains(s-name-okay-orth-Test)");
Akron876017d2020-11-17 09:19:24 +010056 assertEquals(m.getMimeType(),"text/plain");
57 assertEquals(m.getSuffix(),"txt");
58 };
Akron74122712020-11-17 09:41:21 +010059
60 @Test
Akrond2072ee2020-11-17 16:12:41 +010061 public void testStrings () throws IOException {
62 MatchAggregator m = new MatchAggregator();
63 m.setQueryString("Beispiel-Query");
64 assertEquals(m.getQueryString(),"Beispiel-Query");
65
66 m.setCorpusQueryString("Beispiel-Corpus");
67 assertEquals(m.getCorpusQueryString(),"Beispiel-Corpus");
68 };
69
70 @Test
Akronc1c18242020-11-18 18:24:12 +010071 public void testTimeout () throws IOException {
72 MatchAggregator m = new MatchAggregator();
73 m.init("{\"meta\":{\"totalResults\":6}}");
74 assertEquals(m.getTotalResults(),6);
75 assertFalse(m.hasTimeExceeded());
76
77 m = new MatchAggregator();
78 m.init("{\"meta\":{\"totalResults\":7,\"timeExceeded\":true}}");
79 assertEquals(m.getTotalResults(),7);
80 assertTrue(m.hasTimeExceeded());
81
82 m = new MatchAggregator();
83 m.init("{\"meta\":{\"totalResults\":8,\"timeExceeded\":false}}");
84 assertEquals(m.getTotalResults(),8);
85 assertFalse(m.hasTimeExceeded());
86 };
87
88 @Test
Akron74122712020-11-17 09:41:21 +010089 public void testFileName () throws IOException {
90 MatchAggregator m = new MatchAggregator();
91 assertEquals(m.getFileName(),"export");
92
93 m = new MatchAggregator();
94 m.setFileName("Beispiel");
95 assertEquals(m.getFileName(),"Beispiel");
96
97 m = new MatchAggregator();
98 m.setQueryString("contains(<s name=\"okay\">,[orth='Test'])");
99 assertEquals(m.getQueryString(),"contains(<s name=\"okay\">,[orth='Test'])");
100 assertEquals(m.getFileName(),"contains(s-name-okay-orth-Test)");
101 m.setFileName("Beispiel");
102 assertEquals(m.getFileName(),"Beispiel");
103 };
Akron820dc642020-11-19 13:11:50 +0100104
105 @Test
106 public void testSource () throws IOException {
107 MatchAggregator m = new MatchAggregator();
108 assertNull(m.getSource());
109 m.setSource("localhost","");
110 assertEquals(m.getSource(),"localhost");
111 m.setSource("localhost",null);
112 assertEquals(m.getSource(),"localhost");
113 m.setSource("localhost","path");
114 assertEquals(m.getSource(),"localhost/path");
115 m.setSource("","path");
116 assertEquals(m.getSource(),"/path");
117 m.setSource(null,"path");
118 assertEquals(m.getSource(),"/path");
119 };
120
Akronb329d272020-11-13 12:45:26 +0100121};