source: Dev/branches/rest-dojo-ui/client/dojox/rpc/tests/Geonames.js @ 256

Last change on this file since 256 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

File size: 12.5 KB
Line 
1dojo.provide("dojox.rpc.tests.Geonames");
2dojo.require("dojo.io.script");
3dojo.require("dojox.rpc.Service");
4
5dojox.rpc.tests.service = new dojox.rpc.Service(dojo.moduleUrl("dojox.rpc.SMDLibrary", "geonames.smd"));
6
7dojox.rpc.tests.TEST_METHOD_TIMEOUT = 20000;
8dojox.rpc.tests.TEST_METHOD_LONG_TIMEOUT = 30000;
9
10dojox.rpc.tests._testMethod = function(method){
11
12        return function(m){
13                var d = new doh.Deferred();
14
15                if (method.name && method.parameters) {
16                        var def = dojox.rpc.tests.service[method.name](method.parameters);
17                        def.addCallback(this, function(result){
18                                if (method.debugTest) {
19                                        console.log("Results: ", dojo.toJson(result));
20                                }
21                                var testType = method.testType || "compare";
22                                switch(testType){
23                                        case "compare":
24                                                console.log("Comparison Test");
25                                                if (dojo.toJson(result)==method.expectedResult){
26                                                        d.callback(true);
27                                                }else{
28                                                        d.errback(new Error("Unexpected Return Value in comparison: ", result));
29                                                }
30                                                break;
31                                        case "result":
32                                                console.log("Result Test");
33                                                if (result && dojo.toJson(result)){
34                                                        d.callback(true);
35                                                }else{
36                                                        d.errback(new Error("Unexpected Return Value, no result or not valid json: ", result));
37
38                                                }
39                                                break;
40                                        default:
41                                                d.errback(new Error("Unknown test type"));
42                                                break;
43                                }
44                        });
45                }
46
47                return d;
48        }
49};
50
51doh.register("dojox.rpc.tests.geonames",
52        [
53                {
54                        name: "#1, getCities()",
55                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
56                        runTest: dojox.rpc.tests._testMethod({
57                                name: "getCities",
58                                parameters: {north: 44.1, south:-9.9, east: -22.4, west: 55.2},
59                                expectedResult: dojo.toJson({"geonames":[{"fcodeName":"capital of a political entity","countrycode":"MX","fcl":"P","fclName":"city, village,...","name":"Mexico City","wikipedia":"en.wikipedia.org/wiki/Mexico_City","lng":-99.1386111,"fcode":"PPLC","geonameId":3530597,"lat":19.4341667,"population":11285654},{"fcodeName":"capital of a political entity","countrycode":"PH","fcl":"P","fclName":"city, village,...","name":"Manila","wikipedia":"","lng":120.9822222,"fcode":"PPLC","geonameId":1701668,"lat":14.6041667,"population":10444527},{"fcodeName":"capital of a political entity","countrycode":"BD","fcl":"P","fclName":"city, village,...","name":"Dhaka","wikipedia":"en.wikipedia.org/wiki/Dhaka","lng":90.4086111,"fcode":"PPLC","geonameId":1185241,"lat":23.7230556,"population":10356500},{"fcodeName":"capital of a political entity","countrycode":"KR","fcl":"P","fclName":"city, village,...","name":"Seoul","wikipedia":"en.wikipedia.org/wiki/Seoul","lng":126.9997222,"fcode":"PPLC","geonameId":1835848,"lat":37.5663889,"population":10349312},{"fcodeName":"capital of a political entity","countrycode":"ID","fcl":"P","fclName":"city, village,...","name":"Jakarta","wikipedia":"en.wikipedia.org/wiki/Jakarta","lng":106.8294444,"fcode":"PPLC","geonameId":1642911,"lat":-6.1744444,"population":8540121},{"fcodeName":"capital of a political entity","countrycode":"JP","fcl":"P","fclName":"city, village,...","name":"Tokyo","wikipedia":"en.wikipedia.org/wiki/Tokyo","lng":139.7513889,"fcode":"PPLC","geonameId":1850147,"lat":35.685,"population":8336599},{"fcodeName":"capital of a political entity","countrycode":"TW","fcl":"P","fclName":"city, village,...","name":"Taipei","wikipedia":"en.wikipedia.org/wiki/Taipei","lng":121.525,"fcode":"PPLC","geonameId":1668341,"lat":25.0391667,"population":7871900},{"fcodeName":"capital of a political entity","countrycode":"CN","fcl":"P","fclName":"city, village,...","name":"Beijing","wikipedia":"en.wikipedia.org/wiki/Beijing","lng":116.3883333,"fcode":"PPLC","geonameId":1816670,"lat":39.9288889,"population":7480601},{"fcodeName":"capital of a political entity","countrycode":"CO","fcl":"P","fclName":"city, village,...","name":"Bogotá","wikipedia":"en.wikipedia.org/wiki/Bogot%C3%A1","lng":-74.0833333,"fcode":"PPLC","geonameId":3688689,"lat":4.6,"population":7102602},{"fcodeName":"capital of a political entity","countrycode":"HK","fcl":"P","fclName":"city, village,...","name":"Hong Kong","wikipedia":"","lng":114.15007352829,"fcode":"PPLC","geonameId":1819729,"lat":22.2840136009625,"population":7012738}]})
60                        })
61                },
62                {
63                        name: "#2, getQuakes()",
64                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
65                        runTest: dojox.rpc.tests._testMethod({
66                                name: "getQuakes",
67                                parameters: {north: 44.1, south:-9.9, east: -22.4, west: 55.2, "date": "2007-07-31", maxRows: 1},
68                                expectedResult: dojo.toJson({"earthquakes":[{"eqid":"2007flce","magnitude":6.1,"lng":-17.7996,"src":"us","datetime":"2007-07-31 22:55:31","depth":10,"lat":-0.095}]})
69                        })
70                },
71                {
72                        name: "#3, getWeather()",
73                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
74                        runTest: dojox.rpc.tests._testMethod({
75                                name: "getWeather",
76                                testType:'result',
77                                parameters: {north: 44.1, south:-9.9, east: -22.4, west: 55.2, "date": "2007-07-31", maxRows: 1}
78                        })
79                },
80
81                {
82                        name: "#4, getWeatherByICAO()",
83                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
84                        runTest: dojox.rpc.tests._testMethod({
85                                name: "getWeatherByICAO",
86                                testType:'result',
87                                parameters: {ICAO:"LSZH"}
88                        })
89                },
90
91                {
92                        name: "#5, getWeatherByCoords()",
93                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
94                        runTest: dojox.rpc.tests._testMethod({
95                                name: "getWeatherByCoords",
96                                testType:'result',
97                                parameters: {lat:43,lng:-2}
98                        })
99                },
100
101                {
102                        name: "#6, getChildren()",
103                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
104                        runTest: dojox.rpc.tests._testMethod({
105                                name: "getChildren",
106                                parameters: {geonameId:3175395},
107                                testType: 'result'
108                        })
109                },
110
111                {
112                        name: "#7, getHeirarchy()",
113                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
114                        runTest: dojox.rpc.tests._testMethod({
115                                name: "getHierarchy",
116                                parameters: {geonameId:3175395},
117                                testType: 'result'
118                        })
119                },
120                {
121                        name: "#8, getNeighbours()",
122                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
123                        runTest: dojox.rpc.tests._testMethod({
124                                name: "getNeighbours",
125                                parameters: {geonameId:3175395},
126                                testType: 'result'
127                        })
128                },
129
130                {
131                        name: "#9, getNeighbourhood()",
132                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
133                        runTest: dojox.rpc.tests._testMethod({
134                                name: "getNeighbourhood",
135                                parameters: {lat:40.78343, lng:-73.96625},
136                                expectedResult: dojo.toJson({"neighbourhood":{"adminName2":"New York County","adminCode2":"061","adminCode1":"NY","countryName":"United States","name":"Central Park","countryCode":"US","city":"New York City-Manhattan","adminName1":"New York"}})
137                        })
138                },
139
140                {
141                        name: "#10, getSiblings()",
142                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
143                        runTest: dojox.rpc.tests._testMethod({
144                                name: "getSiblings",
145                                parameters: {geonameId:3175395},
146                                testType: 'result'
147                        })
148                },
149
150                {
151                        name: "#11, getCountryCode()",
152                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
153                        runTest: dojox.rpc.tests._testMethod({
154                                name: "getCountryCode",
155                                parameters:{lat:40.78343, lng:-73.96625},
156                                expectedResult: dojo.toJson({"distance":0,"countryName":"United States","countryCode":"US"})
157                        })
158                },
159                {
160                        name: "#12, getCountrySubdivision()",
161                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
162                        runTest: dojox.rpc.tests._testMethod({
163                                name: "getCountrySubdivision",
164                                parameters:{lat:40.78343, lng:-73.96625},
165                                expectedResult: dojo.toJson({"distance":0,"adminCode1":"NY","countryName":"United States","countryCode":"US","codes":[{"code":"36","type":"FIPS10-4"},{"code":"NY","type":"ISO3166-2"}],"adminName1":"New York"})
166                        })
167                },
168                {
169                        name: "#13, getWikipediaBoundingBox()",
170                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
171                        runTest: dojox.rpc.tests._testMethod({
172                                name: "getWikipediaBoundingBox",
173                                parameters:{north: "44.1", "south": "-9.9", "east": "-22.4", "west": "55.2", "maxRows": "1"},
174                                testType: 'result'
175                        })
176                },
177                 {
178                        name: "#14, searchWikipedia()",
179                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
180                        runTest: dojox.rpc.tests._testMethod({
181                                name: "searchWikipedia",
182                                parameters:{q: "dojo", maxRows: 1},
183                                expectedResult: dojo.toJson({"geonames":[{"summary":"which is an umbrella organisation of various national, as well as smaller, aikido organisations. Although the name strictly refers only to the main training hall (''dojo''), it is often used by extension to refer to the Aikikai organisation itself. The dojo was founded by Morihei Ueshiba in 1931 under the name ''Kobukan'' (...)","title":"Aikikai Hombu Dojo","wikipediaUrl":"en.wikipedia.org/wiki/Aikikai_Hombu_Dojo","elevation":0,"countryCode":"JP","lng":139.714305555556,"feature":"landmark","lang":"en","lat":35.6991388888889,"population":0}]})
184                        })
185                },
186                {
187                        name: "#15, getTimezone()",
188                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
189                        runTest: dojox.rpc.tests._testMethod({
190                                name: "getTimezone",
191                                parameters:{lat:40.78343,lng:-73.96625},
192                                expectedResult: dojo.toJson({"countryName":"United States","dstOffset":-4,"countryCode":"US","gmtOffset":-5,"lng":-73.96625,"timezoneId":"America/New_York","lat":40.78343})
193                        })
194                },
195 
196                {
197                        name: "#16, search()",
198                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
199                        runTest: dojox.rpc.tests._testMethod({
200                                name: "search",
201                                parameters:{q: "dojo", maxRows: 1},
202                                testType: 'result'
203                        })
204                },
205
206                 {
207                        name: "#17, postalCodeLookup()",
208                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
209                        runTest: dojox.rpc.tests._testMethod({
210                                name: "postcalCodeLookup",
211                                debugTest: true,
212                                parameters:{postalcode: "24060"},
213                                expectedResult: dojo.toJson({})
214                        })
215                },
216 
217                {
218                        name: "#18, postalCodeSearch()",
219                        timeout: dojox.rpc.tests.TEST_METHOD_TIMEOUT,
220                        runTest: dojox.rpc.tests._testMethod({
221                                name: "postalCodeSearch",
222                                parameters:{placename: "blacksburg"},
223                                expectedResult: dojo.toJson({})
224                        })
225                }
226        ]
227);
Note: See TracBrowser for help on using the repository browser.