| Akron | b329d27 | 2020-11-13 12:45:26 +0100 | [diff] [blame] | 1 | package de.ids_mannheim.korap.plkexport; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | |
| 5 | import static org.junit.Assert.assertEquals; |
| 6 | import static org.junit.Assert.assertNull; |
| 7 | import static org.junit.Assert.assertTrue; |
| Akron | c51327b | 2020-11-13 15:21:26 +0100 | [diff] [blame] | 8 | import static org.junit.Assert.assertFalse; |
| Akron | b329d27 | 2020-11-13 12:45:26 +0100 | [diff] [blame] | 9 | import static org.junit.Assert.fail; |
| 10 | import org.junit.Test; |
| 11 | |
| 12 | import de.ids_mannheim.korap.plkexport.MatchAggregator; |
| 13 | |
| 14 | public class MatchAggregatorTest { |
| 15 | |
| 16 | @Test |
| 17 | public void testEmptyInit () throws IOException { |
| Akron | 1d36eb5 | 2020-11-13 17:52:26 +0100 | [diff] [blame] | 18 | MatchAggregator m = new MatchAggregator(); |
| 19 | m.init(""); |
| Akron | fddd058 | 2020-11-17 09:49:54 +0100 | [diff] [blame] | 20 | assertNull(m.getMeta()); |
| 21 | assertNull(m.getQuery()); |
| 22 | assertNull(m.getCollection()); |
| Akron | c51327b | 2020-11-13 15:21:26 +0100 | [diff] [blame] | 23 | |
| Akron | 1d36eb5 | 2020-11-13 17:52:26 +0100 | [diff] [blame] | 24 | m = new MatchAggregator(); |
| 25 | m.init(null); |
| Akron | fddd058 | 2020-11-17 09:49:54 +0100 | [diff] [blame] | 26 | assertNull(m.getMeta()); |
| 27 | assertNull(m.getQuery()); |
| 28 | assertNull(m.getCollection()); |
| Akron | b329d27 | 2020-11-13 12:45:26 +0100 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | @Test |
| 32 | public void testSampleInit () throws IOException { |
| Akron | 1d36eb5 | 2020-11-13 17:52:26 +0100 | [diff] [blame] | 33 | MatchAggregator m = new MatchAggregator(); |
| 34 | m.init("{\"meta\":{\"totalResults\":6}}"); |
| Akron | fddd058 | 2020-11-17 09:49:54 +0100 | [diff] [blame] | 35 | assertEquals(m.getMeta().toString(),"{\"totalResults\":6}"); |
| 36 | assertNull(m.getQuery()); |
| 37 | assertNull(m.getCollection()); |
| Akron | b329d27 | 2020-11-13 12:45:26 +0100 | [diff] [blame] | 38 | }; |
| Akron | c51327b | 2020-11-13 15:21:26 +0100 | [diff] [blame] | 39 | |
| 40 | @Test |
| 41 | public void testMatchesInit () throws IOException { |
| Akron | 1d36eb5 | 2020-11-13 17:52:26 +0100 | [diff] [blame] | 42 | MatchAggregator m = new MatchAggregator(); |
| 43 | m.init("{\"matches\":[\"first\",\"second\"]}"); |
| Akron | fddd058 | 2020-11-17 09:49:54 +0100 | [diff] [blame] | 44 | assertNull(m.getMeta()); |
| 45 | assertNull(m.getQuery()); |
| 46 | assertNull(m.getCollection()); |
| Akron | c51327b | 2020-11-13 15:21:26 +0100 | [diff] [blame] | 47 | }; |
| Akron | 876017d | 2020-11-17 09:19:24 +0100 | [diff] [blame] | 48 | |
| 49 | @Test |
| 50 | public void testAttributes () throws IOException { |
| 51 | MatchAggregator m = new MatchAggregator(); |
| Akron | 7412271 | 2020-11-17 09:41:21 +0100 | [diff] [blame] | 52 | 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)"); |
| Akron | 876017d | 2020-11-17 09:19:24 +0100 | [diff] [blame] | 56 | assertEquals(m.getMimeType(),"text/plain"); |
| 57 | assertEquals(m.getSuffix(),"txt"); |
| 58 | }; |
| Akron | 7412271 | 2020-11-17 09:41:21 +0100 | [diff] [blame] | 59 | |
| 60 | @Test |
| Akron | d2072ee | 2020-11-17 16:12:41 +0100 | [diff] [blame] | 61 | 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 |
| Akron | c1c1824 | 2020-11-18 18:24:12 +0100 | [diff] [blame] | 71 | 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 |
| Akron | 7412271 | 2020-11-17 09:41:21 +0100 | [diff] [blame] | 89 | 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 | }; |
| Akron | 820dc64 | 2020-11-19 13:11:50 +0100 | [diff] [blame] | 104 | |
| 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 | |
| Akron | b329d27 | 2020-11-13 12:45:26 +0100 | [diff] [blame] | 121 | }; |