Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

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