Index: trunk/lucene-search-3/src/test/java/org/wikimedia/lsearch/config/GlobalConfigurationTest.java |
— | — | @@ -10,7 +10,9 @@ |
11 | 11 | import java.util.Properties; |
12 | 12 | import java.util.regex.Pattern; |
13 | 13 | |
14 | | -import org.apache.log4j.Logger; |
| 14 | +import org.junit.After; |
| 15 | +import org.junit.Before; |
| 16 | +import org.junit.Test; |
15 | 17 | import org.wikimedia.lsearch.search.NamespaceFilter; |
16 | 18 | import org.wikimedia.lsearch.test.AbstractWikiTestCase; |
17 | 19 | import org.wikimedia.lsearch.util.StringUtils; |
— | — | @@ -21,13 +23,15 @@ |
22 | 24 | */ |
23 | 25 | public class GlobalConfigurationTest extends AbstractWikiTestCase { // NOPMD by OrenBochman on 1/15/12 3:38 AM |
24 | 26 | |
25 | | - private static final Logger LOG = Logger.getLogger(GlobalConfigurationTest.class.getName()); |
| 27 | + // private static final Logger LOGGER = |
| 28 | + // Logger.getLogger(GlobalConfigurationTest.class.getName()); |
26 | 29 | private transient GlobalConfiguration global = null; |
27 | 30 | private transient IndexId frTest=null; |
28 | 31 | |
29 | 32 | private transient Hashtable<String, Hashtable<String, Hashtable<String, String>>> database; |
30 | 33 | |
31 | 34 | @Override |
| 35 | + @Before |
32 | 36 | public void setUp() { |
33 | 37 | |
34 | 38 | super.setUp(); |
— | — | @@ -37,18 +41,22 @@ |
38 | 42 | database = global.database; |
39 | 43 | frTest = IndexId.get("frtest"); |
40 | 44 | } |
| 45 | + |
41 | 46 | @Override |
| 47 | + @After |
42 | 48 | public void tearDown() { |
| 49 | + // XXX: is this method really needed? |
43 | 50 | |
44 | 51 | database=null; |
45 | 52 | frTest=null; |
46 | 53 | } |
47 | 54 | |
| 55 | + @Test |
48 | 56 | public void testPreprocessLine(){ |
49 | 57 | |
50 | 58 | String winPathFixer; |
51 | 59 | if(System.getProperty("os.name").startsWith("Windows")){ |
52 | | - winPathFixer = File.separator; |
| 60 | + winPathFixer = "/"; |
53 | 61 | }else{ |
54 | 62 | winPathFixer=""; |
55 | 63 | } |
— | — | @@ -57,19 +65,17 @@ |
58 | 66 | assertEquals("preprocessLine() failed - ",text,global.preprocessLine(text)); |
59 | 67 | |
60 | 68 | final StringBuilder dburl = new StringBuilder("file://") |
61 | | - .append(winPathFixer) |
62 | | - .append(System.getProperty("user.dir")) |
63 | | - .append(File.separator) |
64 | | - .append("test-data") |
65 | | - .append(File.separator) |
66 | | - .append("dbs.test"); |
| 69 | + .append(winPathFixer).append(System.getProperty("user.dir")) |
| 70 | + .append(File.separator).append("src").append(File.separator) |
| 71 | + .append("test").append(File.separator) |
| 72 | + .append("resources").append(File.separator).append("dbs.test"); |
67 | 73 | text = "{"+dburl+"}: (mainsplit)"; |
68 | 74 | |
69 | 75 | assertEquals("preprocessLine() failed - ","entest,rutest,srtest,kktest: (mainsplit)",global.preprocessLine(text)); |
70 | 76 | } |
71 | 77 | |
72 | 78 | |
73 | | - |
| 79 | + @Test |
74 | 80 | public void testRoles(){ |
75 | 81 | // database |
76 | 82 | |
— | — | @@ -85,7 +91,7 @@ |
86 | 92 | assertEquals("10",mainpart.get("maxBufDocs")); |
87 | 93 | } |
88 | 94 | |
89 | | - |
| 95 | + @Test |
90 | 96 | public void testReadURLSplitRoles(){ |
91 | 97 | |
92 | 98 | Hashtable<String, Hashtable<String, String>> splitroles = database.get("frtest"); |
— | — | @@ -95,6 +101,7 @@ |
96 | 102 | assertNotNull(splitroles.get("part3")); |
97 | 103 | } |
98 | 104 | |
| 105 | + @Test |
99 | 106 | public void testParts(){ |
100 | 107 | Hashtable<String, String> nspart1 = database.get("njawiki").get("nspart1"); |
101 | 108 | assertEquals("false",nspart1.get("optimize")); |
— | — | @@ -102,6 +109,7 @@ |
103 | 110 | |
104 | 111 | } |
105 | 112 | |
| 113 | + @Test |
106 | 114 | public void testReadURLAdress(){ |
107 | 115 | // search |
108 | 116 | Hashtable<String,ArrayList<String>> search = global.search; |
— | — | @@ -115,6 +123,7 @@ |
116 | 124 | assertEquals(6,ssr.length); |
117 | 125 | } |
118 | 126 | |
| 127 | + @Test |
119 | 128 | public void testSearchGroups(){ |
120 | 129 | // search groups |
121 | 130 | Hashtable<Integer,Hashtable<String,ArrayList<String>>> searchGroups = global.searchGroup; |
— | — | @@ -124,7 +133,8 @@ |
125 | 134 | Hashtable<String,ArrayList<String>> group1 = searchGroups.get(Integer.valueOf(1)); |
126 | 135 | assertEquals("{192.168.0.6=[frtest.part3, detest], 192.168.0.4=[frtest.part1, frtest.part2]}",group1.toString()); |
127 | 136 | } |
128 | | - |
| 137 | + |
| 138 | + @Test |
129 | 139 | public void testIndex(){ |
130 | 140 | // index |
131 | 141 | Hashtable<String,ArrayList<String>> index = global.index; |
— | — | @@ -150,10 +160,8 @@ |
151 | 161 | |
152 | 162 | assertEquals("192.168.0.5",indexLocation.get("entest.mainpart")); |
153 | 163 | assertEquals("192.168.0.2",indexLocation.get("entest.ngram")); |
154 | | - |
155 | 164 | } |
156 | 165 | |
157 | | - |
158 | 166 | |
159 | 167 | public void testPrefixes(){ |
160 | 168 | |
— | — | @@ -161,8 +169,9 @@ |
162 | 170 | Hashtable<String,NamespaceFilter> prefixes = global.namespacePrefix; |
163 | 171 | assertEquals(17,prefixes.size()); |
164 | 172 | |
165 | | -} |
| 173 | + } |
166 | 174 | |
| 175 | + @Test |
167 | 176 | public void testGlobalProperties(){ |
168 | 177 | |
169 | 178 | // check global properties |
— | — | @@ -171,6 +180,7 @@ |
172 | 181 | assertEquals("wiki rutest",prop.get("KeywordScoring.suffix")); |
173 | 182 | } |
174 | 183 | |
| 184 | + @Test |
175 | 185 | public void testLanguages(){ |
176 | 186 | |
177 | 187 | // check languages and keyword stuff |
— | — | @@ -179,9 +189,9 @@ |
180 | 190 | assertFalse(global.useKeywordScoring("frtest")); |
181 | 191 | assertTrue(global.useKeywordScoring("srwiki")); |
182 | 192 | assertTrue(global.useKeywordScoring("rutest")); |
| 193 | + } |
183 | 194 | |
184 | | -} |
185 | | - |
| 195 | + @Test |
186 | 196 | public void testOaiRepository(){ |
187 | 197 | |
188 | 198 | // test oai repo stuff |
— | — | @@ -192,16 +202,18 @@ |
193 | 203 | |
194 | 204 | assertEquals("http://sr.wikipedia.org/w/index.php?title=Special:OAIRepository",global.getOAIRepo("srwiki")); |
195 | 205 | assertEquals("http://localhost/wiki-lucene/phase3/index.php?title=Special:OAIRepository",global.getOAIRepo("frtest")); |
196 | | -} |
| 206 | + } |
197 | 207 | |
| 208 | + @Test |
198 | 209 | public void testInitiazeSettings(){ |
199 | 210 | //FIXME: try to add InitialiseSettings.php to testdata/ |
200 | 211 | // InitialiseSettings test |
201 | 212 | assertEquals("sr",global.getLanguage("rswikimedia")); |
202 | 213 | assertEquals("http://rs.wikimedia.org/w/index.php?title=Special:OAIRepository",global.getOAIRepo("rswikimedia")); |
203 | 214 | assertEquals("http://commons.wikimedia.org/w/index.php?title=Special:OAIRepository",global.getOAIRepo("commonswiki")); |
204 | | -} |
205 | | - |
| 215 | + } |
| 216 | + |
| 217 | + @Test |
206 | 218 | public void testSuggestTags(){ |
207 | 219 | // test suggest tag |
208 | 220 | Hashtable<String,String> sug = global.getDBParams("entest","spell"); |
— | — | @@ -210,6 +222,7 @@ |
211 | 223 | |
212 | 224 | } |
213 | 225 | |
| 226 | + @Test |
214 | 227 | public void testOrphans() { |
215 | 228 | |
216 | 229 | IndexId enw = IndexId.get("enwiktionary"); |
— | — | @@ -221,7 +234,9 @@ |
222 | 235 | assertFalse(enIndexId.getSearchHosts().contains("oblak2")); |
223 | 236 | } |
224 | 237 | |
| 238 | + @Test |
225 | 239 | public void testIndexIds(){ |
| 240 | + |
226 | 241 | IndexId entest = IndexId.get("entest"); |
227 | 242 | |
228 | 243 | assertTrue(entest.isMainsplit()); |
— | — | @@ -235,14 +250,18 @@ |
236 | 251 | |
237 | 252 | } |
238 | 253 | |
| 254 | + @Test |
239 | 255 | public void testgetType(){ |
| 256 | + |
240 | 257 | IndexId entest = IndexId.get("entest"); |
241 | 258 | |
242 | 259 | //assertEquals(null,entest.getSnapshotPath()); |
243 | 260 | assertEquals("mainsplit",entest.getType()); |
244 | 261 | } |
245 | | - |
| 262 | + |
| 263 | + @Test |
246 | 264 | public void testgetRsyncSnapshotPath(){ |
| 265 | + |
247 | 266 | IndexId entest = IndexId.get("entest"); |
248 | 267 | |
249 | 268 | assertEquals("/mwsearch2/snapshot/entest",entest.getRsyncSnapshotPath()); |
— | — | @@ -260,7 +279,8 @@ |
261 | 280 | //assertEquals(null,enrest.getIndexPath()); |
262 | 281 | |
263 | 282 | } |
264 | | - |
| 283 | + |
| 284 | + @Test |
265 | 285 | public void testGetFrench(){ |
266 | 286 | |
267 | 287 | |
— | — | @@ -272,7 +292,8 @@ |
273 | 293 | assertEquals(3,frTest.getSplitFactor()); |
274 | 294 | |
275 | 295 | } |
276 | | - |
| 296 | + |
| 297 | + @Test |
277 | 298 | public void testGetFrenchPart(){ |
278 | 299 | |
279 | 300 | |
— | — | @@ -287,11 +308,14 @@ |
288 | 309 | assertFalse(detest.isLogical()); |
289 | 310 | |
290 | 311 | } |
291 | | - |
| 312 | + |
| 313 | + /** |
| 314 | + * check nssplit configuration option. |
| 315 | + * this configuration option should split the index into servral parts |
| 316 | + */ |
| 317 | + @Test |
292 | 318 | public void testGetNjPart(){ |
293 | 319 | |
294 | | - |
295 | | - // check nssplit |
296 | 320 | IndexId njawiki = IndexId.get("njawiki"); |
297 | 321 | assertTrue(njawiki.isLogical()); |
298 | 322 | assertFalse(njawiki.isSplit()); |
— | — | @@ -310,7 +334,8 @@ |
311 | 335 | assertEquals(2,njawiki2.getPartNum()); |
312 | 336 | assertEquals("[192.168.0.1]",njawiki2.getSearchHosts().toString()); |
313 | 337 | } |
314 | | - |
| 338 | + |
| 339 | + @Test |
315 | 340 | public void testEnSpell(){ |
316 | 341 | |
317 | 342 | IndexId sug = IndexId.get("entest.spell"); |
— | — | @@ -318,7 +343,8 @@ |
319 | 344 | assertFalse(sug.isLogical()); |
320 | 345 | assertEquals(sug,sug.getSpell()); |
321 | 346 | } |
322 | | - |
| 347 | + |
| 348 | + @Test |
323 | 349 | public void testEnSubdivided(){ |
324 | 350 | |
325 | 351 | IndexId sub1 = IndexId.get("entest.mainpart.sub1"); |
— | — | @@ -337,7 +363,8 @@ |
338 | 364 | //assertNull(enmain.getImportPath()); |
339 | 365 | |
340 | 366 | } |
341 | | - |
| 367 | + |
| 368 | + @Test |
342 | 369 | public void testHmSubdivided(){ |
343 | 370 | |
344 | 371 | |
— | — | @@ -361,7 +388,8 @@ |
362 | 389 | assertEquals("[192.168.0.1]",hhl1.getSearchHosts().toString()); |
363 | 390 | |
364 | 391 | } |
365 | | - |
| 392 | + |
| 393 | + @Test |
366 | 394 | public void testEnTitles(){ |
367 | 395 | |
368 | 396 | |
— | — | @@ -370,7 +398,8 @@ |
371 | 399 | assertEquals(2,ent.getSplitFactor()); |
372 | 400 | //assertEquals("[en-titles.tspart2, en-titles.tspart1]",ent.getPhysicalIndexes().toString()); |
373 | 401 | } |
374 | | - |
| 402 | + |
| 403 | + @Test |
375 | 404 | public void testEnTitlesParts(){ |
376 | 405 | |
377 | 406 | IndexId ents1 = IndexId.get("en-titles.tspart1"); |
— | — | @@ -391,7 +420,8 @@ |
392 | 421 | assertEquals("mw",mwt.getInterwikiBySuffix("mediawikiwiki")); |
393 | 422 | assertEquals("{mediawikiwiki=mediawikiwiki, metawiki=metawiki}",mwt.getSuffixToDbname().toString()); |
394 | 423 | } |
395 | | - |
| 424 | + |
| 425 | + @Test |
396 | 426 | public void testEnSpellPrecursor(){ |
397 | 427 | |
398 | 428 | IndexId ep = IndexId.get("entest.spell.pre"); |
— | — | @@ -406,6 +436,7 @@ |
407 | 437 | |
408 | 438 | } |
409 | 439 | |
| 440 | + @Test |
410 | 441 | public void testComplexWildcard(){ |
411 | 442 | Pattern p = Pattern.compile(StringUtils.wildcardToRegexp("(?!(enwiki.|dewiki.|frwiki.|itwiki.|nlwiki|.))*.spell")); |
412 | 443 | assertFalse(p.matcher("enwiki.spell").matches()); |