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

Last change on this file since 274 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: 18.8 KB
Line 
1dojo.provide("dojox.rpc.tests.Service");
2dojo.require("dojo.io.script");
3dojo.require("dojox.rpc.Service");
4dojo.require("dojox.rpc.JsonRPC");
5dojo.require("dojox.rpc.Rest");
6dojo.require("dojox.rpc.Client");
7//this is a copy of our smd in js form, so we can just share it easily
8//dojo.require("dojox.rpc.tests.resources.testSmd");
9
10dojox.rpc.tests.service = new dojox.rpc.Service(dojo.moduleUrl("dojox.rpc.tests.resources", "test.smd"));
11
12doh.register("dojox.rpc.tests.echo",
13        [
14                {
15                        name: "#1 POST,URL,Named Parameters",
16                        timeout: 4000,
17                        setUp: function(){
18                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
19                                this.svc = dojox.rpc.tests.service;
20                        },
21                        runTest: function(){
22                                var d = new doh.Deferred();
23
24                                if (window.location.protocol=="file:") {
25                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
26                                        d.errback(err);
27                                        return d;
28                                }
29                                //test when given named params
30                                var td = this.svc.postEcho({message: this.name,foo:2});
31                                td.addCallback(this, function(result){
32                                        if (result==this.name){
33                                                d.callback(true);
34                                        }else{
35                                                d.errback(new Error("Unexpected Return Value: ", result));
36                                        }
37                                });
38
39                                return d;
40                        }
41                },
42                {
43                        name: "#2 POST,URL,Ordered Parameters",
44                        timeout: 4000,
45                        setUp: function(){
46                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
47                                this.svc = dojox.rpc.tests.service;
48
49                        },
50                        runTest: function(){
51                                var d = new doh.Deferred();
52
53                                if (window.location.protocol=="file:") {
54                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
55                                        d.errback(err);
56                                        return d;
57                                }
58
59                                //test when given named params
60                                var td = this.svc.postEcho(this.name,2);
61                                td.addCallback(this, function(result){
62                                        if (result==this.name){
63                                                d.callback(true);
64                                        }else{
65                                                d.errback(new Error("Unexpected Return Value: ", result));
66                                        }
67                                });
68
69                                return d;
70                        }
71                },
72                {
73                        name: "#3 GET,URL,Named Parameters",
74                        timeout: 4000,
75                        setUp: function(){
76                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
77                                this.svc = dojox.rpc.tests.service;
78                        },
79                        runTest: function(){
80                                var d = new doh.Deferred();
81
82                                if (window.location.protocol=="file:") {
83                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
84                                        d.errback(err);
85                                        return d;
86                                }
87
88                                //test when given named params
89                                var td = this.svc.getEcho({message: this.name});
90                                td.addCallback(this, function(result){
91                                        if (result==this.name){
92                                                d.callback(true);
93                                        }else{
94                                                d.errback(new Error("Unexpected Return Value: ", result));
95                                        }
96                                });
97
98                                return d;
99                        }
100                },
101               
102                {
103                        name: "#3.1 REST PUT,Named Parameters",
104                        timeout: 4000,
105                        setUp: function(){
106                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
107                                this.svc = dojox.rpc.tests.service;
108                        },
109                        runTest: function(){
110                                var d = new doh.Deferred();
111
112                                if (window.location.protocol=="file:") {
113                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
114                                        d.errback(err);
115                                        return d;
116                                }
117
118                                res = this.name + Math.random();
119                                //test when given named params
120                                var td = this.svc.restStore.put({location: "res"},res);
121                                td.addCallback(this, function(result){
122                                        var td = this.svc.restStore({location: "res"});
123                                        td.addCallback(this, function(result){
124                                                if (result==res){
125                                                        d.callback(true);
126                                                }else{
127                                                        d.errback(new Error("Unexpected Return Value: ", result));
128                                                }
129                                        });
130                                               
131                                });
132
133                                return d;
134                        }
135                },
136                {
137                        name: "#3.2 REST POST,Named Parameters",
138                        timeout: 4000,
139                        setUp: function(){
140                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
141                                this.svc = dojox.rpc.tests.service;
142                        },
143                        runTest: function(){
144                                var d = new doh.Deferred();
145
146                                if (window.location.protocol=="file:") {
147                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
148                                        d.errback(err);
149                                        return d;
150                                }
151                                var newRes = this.name + Math.random();
152                                res += newRes;
153                                //test when given named params
154                                var td = this.svc.restStore.post({location: "res"},newRes);
155                                td.addCallback(this, function(result){
156                                        var td = this.svc.restStore({location: "res"});
157                                        td.addCallback(this, function(result){
158                                                if (result==res){
159                                                        d.callback(true);
160                                                }else{
161                                                        d.errback(new Error("Unexpected Return Value: ", result));
162                                                }
163                                        });
164                                               
165                                });
166
167                                return d;
168                        }
169                },
170                {
171                        name: "#3.3 REST DELETE,Named Parameters",
172                        timeout: 4000,
173                        setUp: function(){
174                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
175                                this.svc = dojox.rpc.tests.service;
176                        },
177                        runTest: function(){
178                                var d = new doh.Deferred();
179
180                                if (window.location.protocol=="file:") {
181                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
182                                        d.errback(err);
183                                        return d;
184                                }
185
186                                //test when given named params
187                                var td = this.svc.restStore['delete']({location: "res"});
188                                td.addCallback(this, function(result){
189                                        var td = this.svc.restStore({location: "res"});
190                                        td.addCallback(this, function(result){
191                                                if (result=="deleted"){
192                                                        d.callback(true);
193                                                }else{
194                                                        d.errback(new Error("Unexpected Return Value: ", result));
195                                                }
196                                        });
197                                               
198                                });
199
200                                return d;
201                        }
202                },
203                {
204                        name: "#3.4 GET,URL,Named Parameters, Returning Json",
205                        timeout: 4000,
206                        setUp: function(){
207                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
208                                this.svc = dojox.rpc.tests.service;
209                        },
210                        runTest: function(){
211                                var d = new doh.Deferred();
212
213                                if (window.location.protocol=="file:") {
214                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
215                                        d.errback(err);
216                                        return d;
217                                }
218
219                                //test when given named params
220                                var td = this.svc.getEchoJson({message:'{"foo":"bar"}'});
221                                td.addCallback(this, function(result){
222                                        if (result.foo=='bar'){
223                                                d.callback(true);
224                                        }else{
225                                                d.errback(new Error("Unexpected Return Value: ", result));
226                                        }
227                                });
228
229                                return d;
230                        }
231                },
232                {
233                        name: "#3.5 GET,PATH,Named Parameters",
234                        timeout: 4000,
235                        setUp: function(){
236                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
237                                this.svc = dojox.rpc.tests.service;
238                        },
239                        runTest: function(){
240                                var d = new doh.Deferred();
241
242                                if (window.location.protocol=="file:") {
243                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
244                                        d.errback(err);
245                                        return d;
246                                }
247
248                                //test when given named params
249                                var td = this.svc.getPathEcho({path: "pathname"});
250                                td.addCallback(this, function(result){
251                                        if (result=="/path/pathname"){
252                                                d.callback(true);
253                                        }else{
254                                                d.errback(new Error("Unexpected Return Value: ", result));
255                                        }
256                                });
257
258                                return d;
259                        }
260                },
261
262                {
263                        name: "#4.1 GET,URL,Ordered Parameters",
264                        timeout: 4000,
265                        setUp: function(){
266                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
267                                this.svc = dojox.rpc.tests.service;
268                        },
269                        runTest: function(){
270                                var d = new doh.Deferred();
271
272                                if (window.location.protocol=="file:") {
273                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
274                                        d.errback(err);
275                                        return d;
276                                }
277
278                                //test when given named params
279                                var td = this.svc.getEcho(this.name);
280                                td.addCallback(this, function(result){
281                                        if (result==this.name){
282                                                d.callback(true);
283                                        }else{
284                                                d.errback(new Error("Unexpected Return Value: ", result));
285                                        }
286                                });
287
288                                return d;
289                        }
290                },
291                {
292                        name: "#4.2 Namespaced GET,URL,Ordered Parameters",
293                        timeout: 4000,
294                        setUp: function(){
295                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
296                                this.svc = dojox.rpc.tests.service;
297                        },
298                        runTest: function(){
299                                var d = new doh.Deferred();
300
301                                if (window.location.protocol=="file:") {
302                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
303                                        d.errback(err);
304                                        return d;
305                                }
306
307                                //test when given named params
308                                var td = this.svc.namespace.getEcho(this.name);
309                                td.addCallback(this, function(result){
310                                        if (result==this.name){
311                                                d.callback(true);
312                                        }else{
313                                                d.errback(new Error("Unexpected Return Value: ", result));
314                                        }
315                                });
316
317                                return d;
318                        }
319                },
320
321                {
322                        name: "#5 POST,URL,Named Parameters",
323                        timeout: 4000,
324                        setUp: function(){
325                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
326                                this.svc = dojox.rpc.tests.service;
327                        },
328                        runTest: function(){
329                                var d = new doh.Deferred();
330
331                                if (window.location.protocol=="file:") {
332                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
333                                        d.errback(err);
334                                        return d;
335                                }
336
337                                //test when given named params
338                                var td = this.svc.postJsonEcho({message: this.name});
339                                td.addCallback(this, function(result){
340                                        if (result && result.message && result.message==this.name){
341                                                d.callback(true);
342                                        }else{
343                                                d.errback(new Error("Unexpected Return Value: ", result));
344                                        }
345                                });
346
347                                return d;
348                        }
349                },
350
351                {
352                        name: "#6 POST,JSON,Ordered Parameters",
353                        timeout: 4000,
354                        setUp: function(){
355                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
356                                this.svc = dojox.rpc.tests.service;
357                        },
358                        runTest: function(){
359                                var d = new doh.Deferred();
360
361                                if (window.location.protocol=="file:") {
362                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
363                                        d.errback(err);
364                                        return d;
365                                }
366
367                                //test when given named params
368                                var td = this.svc.postJsonEcho(this.name);
369                                td.addCallback(this, function(result){
370                                        if (result && result[0] && result[0]==this.name){
371                                                d.callback(true);
372                                        }else{
373                                                d.errback(new Error("Unexpected Return Value: ", result));
374                                        }
375                                });
376
377                                return d;
378                        }
379                },
380                {
381                        name: "#7 JSONP,URL,Named Parameters",
382                        timeout: 4000,
383                        setUp: function(){
384                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
385                                this.svc = dojox.rpc.tests.service;
386                        },
387                        runTest: function(){
388                                var d = new doh.Deferred();
389
390                                if (window.location.protocol=="file:") {
391                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
392                                        d.errback(err);
393                                        return d;
394                                }
395
396                                //test when given named params
397                                var td = this.svc.jsonpEcho({message: this.name});
398                                td.addCallback(this, function(result){
399                                        if (result==this.name){
400                                                d.callback(true);
401                                        }else{
402                                                d.errback(new Error("Unexpected Return Value: ", result));
403                                        }
404                                });
405
406                                return d;
407                        }
408                },
409                {
410                        name: "#8 JSONP,URL, Ordered Parameters",
411                        timeout: 4000,
412                        setUp: function(){
413                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
414                                this.svc = dojox.rpc.tests.service;
415                        },
416                        runTest: function(){
417                                var d = new doh.Deferred();
418
419                                if (window.location.protocol=="file:") {
420                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
421                                        d.errback(err);
422                                        return d;
423                                }
424
425                                //test when given named params
426                                var td = this.svc.jsonpEcho(this.name);
427                                td.addCallback(this, function(result){
428                                        if (result==this.name){
429                                                d.callback(true);
430                                        }else{
431                                                d.errback(new Error("Unexpected Return Value: ", result));
432                                        }
433                                });
434
435                                return d;
436                        }
437                },
438                {
439                        name: "#9 POST,JSON-RPC-1.0,Ordered Parameters",
440                        timeout: 4000,
441                        setUp: function(){
442                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
443                                this.svc = dojox.rpc.tests.service;
444                        },
445                        runTest: function(){
446                                var d = new doh.Deferred();
447
448                                if (window.location.protocol=="file:") {
449                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
450                                        d.errback(err);
451                                        return d;
452                                }
453
454                                //test when given named params
455                                var td = this.svc.postJsonRpc10Echo(this.name);
456                                td.addCallback(this, function(result){
457                                        if (result==this.name){
458                                                d.callback(true);
459                                        }else{
460                                                d.errback(new Error("Unexpected Return Value: ", result));
461                                        }
462                                });
463
464                                return d;
465                        }
466                },
467                {
468                        name: "#10 POST,JSON-RPC-1.0,Named Parameters",
469                        timeout: 4000,
470                        setUp: function(){
471                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
472                                this.svc = dojox.rpc.tests.service;
473                        },
474                        runTest: function(){
475                                var d = new doh.Deferred();
476
477                                if (window.location.protocol=="file:") {
478                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
479                                        d.errback(err);
480                                        return d;
481                                }
482
483                                //test when given named params
484                                var td = this.svc.postJsonRpc10EchoNamed(this.name);
485                                td.addCallback(this, function(result){
486                                        if (result==this.name){
487                                                d.callback(true);
488                                        }else{
489                                                d.errback(new Error("Unexpected Return Value: ", result));
490                                        }
491                                });
492
493                                return d;
494                        }
495                },
496                {
497                        name: "#11 POST,JSON-RPC 2.0, Ordered Parameters",
498                        timeout: 4000,
499                        setUp: function(){
500                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
501                                this.svc = dojox.rpc.tests.service;
502                        },
503                        runTest: function(){
504                                var d = new doh.Deferred();
505
506                                if (window.location.protocol=="file:") {
507                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
508                                        d.errback(err);
509                                        return d;
510                                }
511
512                                //test when given named params
513                                var td = this.svc.postJsonRpc12Echo(this.name);
514                                td.addCallback(this, function(result){
515                                        if (result==this.name){
516                                                d.callback(true);
517                                        }else{
518                                                d.errback(new Error("Unexpected Return Value: ", result));
519                                        }
520                                });
521
522                                return d;
523                        }
524                },
525                {
526                        name: "#12 POST,JSON-RPC 2.0, Named Parameters",
527                        timeout: 4000,
528                        setUp: function(){
529                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
530                                this.svc = dojox.rpc.tests.service;
531                        },
532                        runTest: function(){
533                                var d = new doh.Deferred();
534
535                                if (window.location.protocol=="file:") {
536                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
537                                        d.errback(err);
538                                        return d;
539                                }
540
541                                //test when given named params
542                                var td = this.svc.postJsonRpc12Echo({message: this.name});
543                                td.addCallback(this, function(result){
544                                        if (result==this.name){
545                                                d.callback(true);
546                                        }else{
547                                                d.errback(new Error("Unexpected Return Value: ", result));
548                                        }
549                                });
550
551                                return d;
552                        }
553                }
554        /*
555                ,{
556                        name: "#13 GET,JSON-RPC 2.0, Ordered Parameters",
557                        timeout: 4000,
558                        setUp: function(){
559                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
560                                this.svc = dojox.rpc.tests.service;
561                        },
562                        runTest: function(){
563                                var d = new doh.Deferred();
564
565                                if (window.location.protocol=="file:") {
566                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
567                                        d.errback(err);
568                                        return d;
569                                }
570
571                                //test when given named params
572                                var td = this.svc.getJsonRpc12Echo(this.name);
573                                td.addCallback(this, function(result){
574                                        if (result==this.name){
575                                                d.callback(true);
576                                        }else{
577                                                d.errback(new Error("Unexpected Return Value: ", result));
578                                        }
579                                });
580
581                                return d;
582                        }
583                },
584                {
585                        name: "#14 GET,JSON-RPC 2.0, Named Parameters",
586                        timeout: 4000,
587                        setUp: function(){
588                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
589                                this.svc = dojox.rpc.tests.service;
590                        },
591                        runTest: function(){
592                                var d = new doh.Deferred();
593
594                                if (window.location.protocol=="file:") {
595                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
596                                        d.errback(err);
597                                        return d;
598                                }
599
600                                //test when given named params
601                                var td = this.svc.getJsonRpc12EchoNamed({message: this.name});
602                                td.addCallback(this, function(result){
603                                        if (result==this.name){
604                                                d.callback(true);
605                                        }else{
606                                                d.errback(new Error("Unexpected Return Value: ", result));
607                                        }
608                                });
609
610                                return d;
611                        }
612                },
613                ,{
614                        name: "#15 JSONP,JSON-RPC 2.0, Ordered Parameters",
615                        timeout: 4000,
616                        setUp: function(){
617                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
618                                this.svc = dojox.rpc.tests.service;
619                        },
620                        runTest: function(){
621                                var d = new doh.Deferred();
622
623                                if (window.location.protocol=="file:") {
624                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
625                                        d.errback(err);
626                                        return d;
627                                }
628
629                                //test when given named params
630                                var td = this.svc.jsonpJsonRpc12Echo(this.name);
631                                td.addCallback(this, function(result){
632                                        if (result==this.name){
633                                                d.callback(true);
634                                        }else{
635                                                d.errback(new Error("Unexpected Return Value: ", result));
636                                        }
637                                });
638
639                                return d;
640                        }
641                }
642                */
643        ]
644);
645
646doh.register("dojox.rpc.tests.jsonRpcForcedError", [
647                {
648                        name: "POST,JSON-RPC 1.0, Ordered Parameters",
649                        timeout: 4000,
650                        setUp: function(){
651                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
652                                this.svc = dojox.rpc.tests.service;
653                        },
654                        runTest: function(){
655                                var d = new doh.Deferred();
656
657                                if (window.location.protocol=="file:") {
658                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
659                                        d.errback(err);
660                                        return d;
661                                }
662
663                                //test when given named params
664                                var td = this.svc.postJsonRpc10ForcedError(this.name);
665
666                                td.addErrback(this, function(error){
667                                        d.callback(true);
668                                });
669
670                                return d;
671                        }
672                },
673                {
674                        name: "POST,JSON-RPC 2.0, Ordered Parameters",
675                        timeout: 4000,
676                        setUp: function(){
677                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
678                                this.svc = dojox.rpc.tests.service;
679                        },
680                        runTest: function(){
681                                var d = new doh.Deferred();
682
683                                if (window.location.protocol=="file:") {
684                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
685                                        d.errback(err);
686                                        return d;
687                                }
688
689                                //test when given named params
690                                var td = this.svc.postJsonRpc12ForcedError(this.name);
691
692                                td.addErrback(this, function(error){
693                                        d.callback(true);
694                                });
695
696                                return d;
697                        }
698                },
699                {
700                        name: "POST,JSON-RPC 2.0, Named Parameters",
701                        timeout: 4000,
702                        setUp: function(){
703                                //this.svc = new dojox.rpc.Service(dojox.rpc.tests.resources.testSmd);
704                                this.svc = dojox.rpc.tests.service;
705                        },
706                        runTest: function(){
707                                var d = new doh.Deferred();
708
709                                if (window.location.protocol=="file:") {
710                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
711                                        d.errback(err);
712                                        return d;
713                                }
714
715                                //test when given named params
716                                var td = this.svc.postJsonRpc12ForcedError({message: this.name});
717
718                                td.addErrback(this, function(error){
719                                        d.callback(true);
720                                });
721
722                                return d;
723                        }
724                }
725]);
Note: See TracBrowser for help on using the repository browser.