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