source: Dev/trunk/src/client/dojo/tests/rpc.js @ 532

Last change on this file since 532 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 3.2 KB
Line 
1define(["doh/main", "require", "../rpc/RpcService", "../rpc/JsonService", "../rpc/JsonpService"],
2        function(doh, require, RpcService, JsonService, JsonpService){
3
4        doh.register("tests.rpc", [
5                {
6                        name: "JsonRPC-EchoTest",
7                        timeout: 2000,
8                        setUp: function(){
9
10                                var testSmd = {
11                                        serviceURL:"../../dojo/tests/resources/test_JsonRPCMediator.php",
12                                        methods:[
13                                                {
14                                                        name:"myecho",
15                                                        parameters:[
16                                                                {
17                                                                        name:"somestring",
18                                                                        type:"STRING"
19                                                                }
20                                                        ]
21                                                }
22                                        ]
23                                };
24
25                                this.svc = new JsonService(testSmd);
26                        },
27                        runTest: function(){
28                                var d = new doh.Deferred();
29                                var td = this.svc.myecho("RPC TEST");
30
31                                if (window.location.protocol=="file:"){
32                                        var err= new Error("This Test requires a webserver and PHP and will fail intentionally if loaded from file://");
33                                        d.errback(err);
34                                        return d;
35                                }
36
37                                td.addCallbacks(function(result){
38                                        if(result=="<P>RPC TEST</P>"){
39                                                return true;
40                                        }else{
41                                                return new Error("JsonRpc-EchoTest test failed, resultant content didn't match");
42                                        }
43                                }, function(result){
44                                        return new Error(result);
45                                });
46
47                                td.addBoth(d, "callback");
48
49                                return d;
50                        }
51
52                },
53
54                {
55                        name: "JsonRPC-EmptyParamTest",
56                        timeout: 2000,
57                        setUp: function(){
58                                var testSmd={
59                                        serviceURL:"../../dojo/tests/resources/test_JsonRPCMediator.php",
60                                        methods:[ { name:"contentB" } ]
61                                };
62
63                                this.svc = new JsonService(testSmd);
64                        },
65                        runTest: function(){
66                                var d = new doh.Deferred();
67                                var td = this.svc.contentB();
68
69                                if (window.location.protocol=="file:"){
70                                        var err= new Error("This Test requires a webserver and PHP and will fail intentionally if loaded from file://");
71                                        d.errback(err);
72                                        return d;
73                                }
74
75                                td.addCallbacks(function(result){
76                                        if(result=="<P>Content B</P>"){
77                                                return true;
78                                        }else{
79                                                return new Error("JsonRpc-EmpytParamTest test failed, resultant content didn't match");
80                                        }
81                                }, function(result){
82                                        return new Error(result);
83                                });
84
85                                td.addBoth(d, "callback");
86
87                                return d;
88                        }
89                },
90
91                {
92                        name: "JsonRPC_SMD_Loading_test",
93                        setUp: function(){
94                                this.svc = new JsonService("../../dojo/tests/resources/testClass.smd");
95                        },
96                        runTest: function(){
97
98                                if (this.svc.objectName=="testClass"){
99                                        return true;
100                                }else{
101                                        return new Error("Error loading and/or parsing an smd file");
102                                }
103                        }
104                },
105
106                {
107                        name: "JsonP_test",
108                        timeout: 10000,
109                        setUp: function(){
110                                this.svc = new JsonpService(require.toUrl("dojo/tests/resources/yahoo_smd_v1.smd"), {appid: "foo"});
111                        },
112                        runTest: function(){
113                                var d = new doh.Deferred();
114
115                                if (window.location.protocol=="file:"){
116                                        var err= new Error("This Test requires a webserver and will fail intentionally if loaded from file://");
117                                        d.errback(err);
118                                        return d;
119                                }
120
121                                var td = this.svc.webSearch({query:"dojotoolkit"});
122
123                                td.addCallbacks(function(result){
124                                        return true;
125                                        if (result["ResultSet"]["Result"][0]["DisplayUrl"]=="dojotoolkit.org/"){
126                                                return true;
127                                        }else{
128                                                return new Error("JsonRpc_SMD_Loading_Test failed, resultant content didn't match");
129                                        }
130                                }, function(result){
131                                        return new Error(result);
132                                });
133
134                                td.addBoth(d, "callback");
135
136                                return d;
137                        }
138                }
139        ]);
140
141});
Note: See TracBrowser for help on using the repository browser.