Index: trunk/lucene-search-2/test/org/wikimedia/lsearch/config/GlobalConfigurationTest.java |
— | — | @@ -4,6 +4,7 @@ |
5 | 5 | */ |
6 | 6 | package org.wikimedia.lsearch.config; |
7 | 7 | |
| 8 | +import java.io.File; |
8 | 9 | import java.io.IOException; |
9 | 10 | import java.net.InetAddress; |
10 | 11 | import java.net.MalformedURLException; |
— | — | @@ -26,48 +27,87 @@ |
27 | 28 | * |
28 | 29 | */ |
29 | 30 | public class GlobalConfigurationTest extends WikiTestCase { |
| 31 | + |
30 | 32 | GlobalConfiguration global = null; |
| 33 | + |
| 34 | + @Override |
31 | 35 | public void setUp() throws Exception { |
| 36 | + |
32 | 37 | super.setUp(); |
33 | 38 | if(global == null) |
34 | 39 | global = GlobalConfiguration.getInstance(); |
| 40 | + |
| 41 | + database = global.database; |
| 42 | + |
35 | 43 | } |
| 44 | + @Override |
| 45 | + public void tearDown() throws Exception{ |
| 46 | + |
| 47 | + database=null; |
| 48 | + super.tearDown(); |
| 49 | + } |
36 | 50 | |
37 | 51 | 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 | + |
38 | 60 | String text = "entest: (mainsplit)"; |
39 | 61 | assertEquals(text,global.preprocessLine(text)); |
40 | 62 | |
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"); |
42 | 70 | text = "{"+dburl+"}: (mainsplit)"; |
43 | 71 | assertEquals("entest,rutest,srtest,kktest: (mainsplit)",global.preprocessLine(text)); |
44 | 72 | } |
45 | 73 | |
46 | | - public void testReadURL(){ |
| 74 | + Hashtable<String, Hashtable<String, Hashtable<String, String>>> database; |
| 75 | + |
| 76 | + public void testRoles(){ |
47 | 77 | // 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 | + |
50 | 81 | assertNotNull(roles.get("mainsplit")); |
51 | 82 | assertNotNull(roles.get("mainpart")); |
52 | 83 | assertNotNull(roles.get("restpart")); |
53 | 84 | |
54 | | - Hashtable mainpart = (Hashtable) roles.get("mainpart"); |
| 85 | + Hashtable<String, String> mainpart = roles.get("mainpart"); |
55 | 86 | assertEquals("false",mainpart.get("optimize")); |
56 | 87 | assertEquals("2",mainpart.get("mergeFactor")); |
57 | 88 | 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"); |
60 | 95 | assertNotNull(splitroles.get("split")); |
61 | 96 | assertNotNull(splitroles.get("part1")); |
62 | 97 | assertNotNull(splitroles.get("part2")); |
63 | 98 | 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"); |
66 | 103 | assertEquals("false",nspart1.get("optimize")); |
67 | 104 | assertEquals("5",nspart1.get("mergeFactor")); |
68 | 105 | |
| 106 | + } |
| 107 | + |
| 108 | + public void testReadURLAdress(){ |
69 | 109 | // 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"); |
72 | 112 | |
73 | 113 | String[] ssr = (String[]) sr.toArray(new String [] {} ); |
74 | 114 | |
— | — | @@ -75,7 +115,9 @@ |
76 | 116 | assertEquals("entest.restpart",ssr[1]); |
77 | 117 | assertEquals("rutest",ssr[2]); |
78 | 118 | assertEquals(6,ssr.length); |
79 | | - |
| 119 | + } |
| 120 | + |
| 121 | + public void testSearchGroups(){ |
80 | 122 | // search groups |
81 | 123 | Hashtable<Integer,Hashtable<String,ArrayList<String>>> sg = global.searchGroup; |
82 | 124 | |
— | — | @@ -83,11 +125,12 @@ |
84 | 126 | assertEquals("{192.168.0.5=[entest.mainpart, entest.restpart], 192.168.0.2=[entest.mainpart]}",g0.toString()); |
85 | 127 | Hashtable<String,ArrayList<String>> g1 = sg.get(new Integer(1)); |
86 | 128 | 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(){ |
89 | 132 | // 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"); |
92 | 135 | |
93 | 136 | String[] sir = (String[]) ir.toArray(new String [] {} ); |
94 | 137 | |
— | — | @@ -101,29 +144,44 @@ |
102 | 145 | assertTrue(ir.contains("entest.mainpart.sub2")); |
103 | 146 | assertTrue(ir.contains("entest.mainpart.sub3")); |
104 | 147 | assertEquals(17,sir.length); |
105 | | - |
| 148 | + } |
| 149 | + |
| 150 | + public void testIndexLocation(){ |
106 | 151 | // indexLocation |
107 | | - Hashtable indexLocation = global.indexLocation; |
| 152 | + Hashtable<String,String> indexLocation = global.indexLocation; |
108 | 153 | |
109 | 154 | assertEquals("192.168.0.5",indexLocation.get("entest.mainpart")); |
110 | 155 | assertEquals("192.168.0.2",indexLocation.get("entest.ngram")); |
111 | 156 | |
112 | | - |
| 157 | + } |
| 158 | + |
| 159 | + public void testMyHost(){ |
113 | 160 | // this should be the nonloopback address |
114 | | - InetAddress host = global.myHost; |
| 161 | + InetAddress host = GlobalConfiguration.myHost; |
115 | 162 | String hostAddr = host.getHostAddress(); |
116 | 163 | String hostName = host.getHostName(); |
117 | 164 | System.out.println("Verify internet IP: "+hostAddr+", and hostname: "+hostName); |
118 | 165 | |
| 166 | + } |
| 167 | + |
| 168 | + public void testPrefixes(){ |
| 169 | + |
119 | 170 | // test prefixes |
120 | 171 | Hashtable<String,NamespaceFilter> p = global.namespacePrefix; |
121 | 172 | assertEquals(17,p.size()); |
| 173 | + |
| 174 | +} |
| 175 | + |
| 176 | + public void testGlobalProperties(){ |
122 | 177 | |
123 | 178 | // check global properties |
124 | 179 | Properties prop = global.globalProperties; |
125 | 180 | assertEquals("wiki wiktionary test",prop.get("Database.suffix")); |
126 | 181 | assertEquals("wiki rutest",prop.get("KeywordScoring.suffix")); |
127 | | - |
| 182 | + } |
| 183 | + |
| 184 | + public void testLanguages(){ |
| 185 | + |
128 | 186 | // check languages and keyword stuff |
129 | 187 | assertEquals("en",global.getLanguage("entest")); |
130 | 188 | assertEquals("sr",global.getLanguage("srwiki")); |
— | — | @@ -131,6 +189,10 @@ |
132 | 190 | assertTrue(global.useKeywordScoring("srwiki")); |
133 | 191 | assertTrue(global.useKeywordScoring("rutest")); |
134 | 192 | |
| 193 | +} |
| 194 | + |
| 195 | + public void testOaiRepository(){ |
| 196 | + |
135 | 197 | // test oai repo stuff |
136 | 198 | Hashtable<String,String> oairepo = global.oaiRepo; |
137 | 199 | assertEquals("http://$lang.wiktionary.org/w/index.php",oairepo.get("wiktionary")); |
— | — | @@ -139,12 +201,17 @@ |
140 | 202 | |
141 | 203 | assertEquals("http://sr.wikipedia.org/w/index.php?title=Special:OAIRepository",global.getOAIRepo("srwiki")); |
142 | 204 | assertEquals("http://localhost/wiki-lucene/phase3/index.php?title=Special:OAIRepository",global.getOAIRepo("frtest")); |
143 | | - |
| 205 | +} |
| 206 | + |
| 207 | + public void testInitiazeSettings(){ |
| 208 | + |
144 | 209 | // InitialiseSettings test |
145 | 210 | assertEquals("sr",global.getLanguage("rswikimedia")); |
146 | 211 | assertEquals("http://rs.wikimedia.org/w/index.php?title=Special:OAIRepository",global.getOAIRepo("rswikimedia")); |
147 | 212 | assertEquals("http://commons.wikimedia.org/w/index.php?title=Special:OAIRepository",global.getOAIRepo("commonswiki")); |
148 | | - |
| 213 | +} |
| 214 | + |
| 215 | + public void testSuggestTags(){ |
149 | 216 | // test suggest tag |
150 | 217 | Hashtable<String,String> sug = global.getDBParams("entest","spell"); |
151 | 218 | assertEquals("1",sug.get("wordsMinFreq")); |