r108948 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r108947‎ | r108948 | r108949 >
Date:02:23, 15 January 2012
Author:oren
Status:deferred
Tags:
Comment:
fixed portability issue for running tests. Increased test granularity
Modified paths:
  • /trunk/lucene-search-2/test/org/wikimedia/lsearch/config/GlobalConfigurationTest.java (modified) (history)

Diff [purge]

Index: trunk/lucene-search-2/test/org/wikimedia/lsearch/config/GlobalConfigurationTest.java
@@ -4,6 +4,7 @@
55 */
66 package org.wikimedia.lsearch.config;
77
 8+import java.io.File;
89 import java.io.IOException;
910 import java.net.InetAddress;
1011 import java.net.MalformedURLException;
@@ -26,48 +27,87 @@
2728 *
2829 */
2930 public class GlobalConfigurationTest extends WikiTestCase {
 31+
3032 GlobalConfiguration global = null;
 33+
 34+ @Override
3135 public void setUp() throws Exception {
 36+
3237 super.setUp();
3338 if(global == null)
3439 global = GlobalConfiguration.getInstance();
 40+
 41+ database = global.database;
 42+
3543 }
 44+ @Override
 45+ public void tearDown() throws Exception{
 46+
 47+ database=null;
 48+ super.tearDown();
 49+ }
3650
3751 public void testPreprocessLine(){
 52+
 53+ String winPathFixer;
 54+ if(System.getProperty("os.name").startsWith("Windows")){
 55+ winPathFixer = File.separator;
 56+ }else{
 57+ winPathFixer="";
 58+ }
 59+
3860 String text = "entest: (mainsplit)";
3961 assertEquals(text,global.preprocessLine(text));
4062
41 - String dburl = "file://"+System.getProperty("user.dir")+"/test-data/dbs.test";
 63+ StringBuilder dburl = new StringBuilder("file://")
 64+ .append(winPathFixer)
 65+ .append(System.getProperty("user.dir"))
 66+ .append(File.separator)
 67+ .append("test-data")
 68+ .append(File.separator)
 69+ .append("dbs.test");
4270 text = "{"+dburl+"}: (mainsplit)";
4371 assertEquals("entest,rutest,srtest,kktest: (mainsplit)",global.preprocessLine(text));
4472 }
4573
46 - public void testReadURL(){
 74+ Hashtable<String, Hashtable<String, Hashtable<String, String>>> database;
 75+
 76+ public void testRoles(){
4777 // database
48 - Hashtable database = global.database;
49 - Hashtable roles = (Hashtable) database.get("entest");
 78+
 79+ Hashtable<String, Hashtable<String, String>> roles = database.get("entest");
 80+
5081 assertNotNull(roles.get("mainsplit"));
5182 assertNotNull(roles.get("mainpart"));
5283 assertNotNull(roles.get("restpart"));
5384
54 - Hashtable mainpart = (Hashtable) roles.get("mainpart");
 85+ Hashtable<String, String> mainpart = roles.get("mainpart");
5586 assertEquals("false",mainpart.get("optimize"));
5687 assertEquals("2",mainpart.get("mergeFactor"));
5788 assertEquals("10",mainpart.get("maxBufDocs"));
58 -
59 - Hashtable splitroles = (Hashtable) database.get("frtest");
 89+ }
 90+
 91+
 92+ public void testReadURLSplitRoles(){
 93+
 94+ Hashtable<String, Hashtable<String, String>> splitroles = database.get("frtest");
6095 assertNotNull(splitroles.get("split"));
6196 assertNotNull(splitroles.get("part1"));
6297 assertNotNull(splitroles.get("part2"));
6398 assertNotNull(splitroles.get("part3"));
64 -
65 - Hashtable nspart1 = (Hashtable) ((Hashtable) database.get("njawiki")).get("nspart1");
 99+ }
 100+
 101+ public void testParts(){
 102+ Hashtable<String, String> nspart1 = database.get("njawiki").get("nspart1");
66103 assertEquals("false",nspart1.get("optimize"));
67104 assertEquals("5",nspart1.get("mergeFactor"));
68105
 106+ }
 107+
 108+ public void testReadURLAdress(){
69109 // search
70 - Hashtable search = global.search;
71 - ArrayList sr = (ArrayList) search.get("192.168.0.2");
 110+ Hashtable<String,ArrayList<String>> search = global.search;
 111+ ArrayList<String> sr = search.get("192.168.0.2");
72112
73113 String[] ssr = (String[]) sr.toArray(new String [] {} );
74114
@@ -75,7 +115,9 @@
76116 assertEquals("entest.restpart",ssr[1]);
77117 assertEquals("rutest",ssr[2]);
78118 assertEquals(6,ssr.length);
79 -
 119+ }
 120+
 121+ public void testSearchGroups(){
80122 // search groups
81123 Hashtable<Integer,Hashtable<String,ArrayList<String>>> sg = global.searchGroup;
82124
@@ -83,11 +125,12 @@
84126 assertEquals("{192.168.0.5=[entest.mainpart, entest.restpart], 192.168.0.2=[entest.mainpart]}",g0.toString());
85127 Hashtable<String,ArrayList<String>> g1 = sg.get(new Integer(1));
86128 assertEquals("{192.168.0.6=[frtest.part3, detest], 192.168.0.4=[frtest.part1, frtest.part2]}",g1.toString());
87 -
88 -
 129+ }
 130+
 131+ public void testIndex(){
89132 // index
90 - Hashtable index = global.index;
91 - ArrayList ir = (ArrayList) index.get("192.168.0.5");
 133+ Hashtable<String,ArrayList<String>> index = global.index;
 134+ ArrayList<String> ir = index.get("192.168.0.5");
92135
93136 String[] sir = (String[]) ir.toArray(new String [] {} );
94137
@@ -101,29 +144,44 @@
102145 assertTrue(ir.contains("entest.mainpart.sub2"));
103146 assertTrue(ir.contains("entest.mainpart.sub3"));
104147 assertEquals(17,sir.length);
105 -
 148+ }
 149+
 150+ public void testIndexLocation(){
106151 // indexLocation
107 - Hashtable indexLocation = global.indexLocation;
 152+ Hashtable<String,String> indexLocation = global.indexLocation;
108153
109154 assertEquals("192.168.0.5",indexLocation.get("entest.mainpart"));
110155 assertEquals("192.168.0.2",indexLocation.get("entest.ngram"));
111156
112 -
 157+ }
 158+
 159+ public void testMyHost(){
113160 // this should be the nonloopback address
114 - InetAddress host = global.myHost;
 161+ InetAddress host = GlobalConfiguration.myHost;
115162 String hostAddr = host.getHostAddress();
116163 String hostName = host.getHostName();
117164 System.out.println("Verify internet IP: "+hostAddr+", and hostname: "+hostName);
118165
 166+ }
 167+
 168+ public void testPrefixes(){
 169+
119170 // test prefixes
120171 Hashtable<String,NamespaceFilter> p = global.namespacePrefix;
121172 assertEquals(17,p.size());
 173+
 174+}
 175+
 176+ public void testGlobalProperties(){
122177
123178 // check global properties
124179 Properties prop = global.globalProperties;
125180 assertEquals("wiki wiktionary test",prop.get("Database.suffix"));
126181 assertEquals("wiki rutest",prop.get("KeywordScoring.suffix"));
127 -
 182+ }
 183+
 184+ public void testLanguages(){
 185+
128186 // check languages and keyword stuff
129187 assertEquals("en",global.getLanguage("entest"));
130188 assertEquals("sr",global.getLanguage("srwiki"));
@@ -131,6 +189,10 @@
132190 assertTrue(global.useKeywordScoring("srwiki"));
133191 assertTrue(global.useKeywordScoring("rutest"));
134192
 193+}
 194+
 195+ public void testOaiRepository(){
 196+
135197 // test oai repo stuff
136198 Hashtable<String,String> oairepo = global.oaiRepo;
137199 assertEquals("http://$lang.wiktionary.org/w/index.php",oairepo.get("wiktionary"));
@@ -139,12 +201,17 @@
140202
141203 assertEquals("http://sr.wikipedia.org/w/index.php?title=Special:OAIRepository",global.getOAIRepo("srwiki"));
142204 assertEquals("http://localhost/wiki-lucene/phase3/index.php?title=Special:OAIRepository",global.getOAIRepo("frtest"));
143 -
 205+}
 206+
 207+ public void testInitiazeSettings(){
 208+
144209 // InitialiseSettings test
145210 assertEquals("sr",global.getLanguage("rswikimedia"));
146211 assertEquals("http://rs.wikimedia.org/w/index.php?title=Special:OAIRepository",global.getOAIRepo("rswikimedia"));
147212 assertEquals("http://commons.wikimedia.org/w/index.php?title=Special:OAIRepository",global.getOAIRepo("commonswiki"));
148 -
 213+}
 214+
 215+ public void testSuggestTags(){
149216 // test suggest tag
150217 Hashtable<String,String> sug = global.getDBParams("entest","spell");
151218 assertEquals("1",sug.get("wordsMinFreq"));

Status & tagging log