Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js') (more/less context) (show whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js new file mode 100644 index 0000000..be1c337 --- a/dev/null +++ b/frontend/gamma/js/Clipperz/PM/Proxy/Proxy.Test.js | |||
@@ -0,0 +1,167 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer to http://www.clipperz.com | ||
12 | |||
13 | * Javascript Crypto Library is free software: you can redistribute | ||
14 | it and/or modify it under the terms of the GNU Affero General Public | ||
15 | License as published by the Free Software Foundation, either version | ||
16 | 3 of the License, or (at your option) any later version. | ||
17 | |||
18 | * Javascript Crypto Library is distributed in the hope that it will | ||
19 | be useful, but WITHOUT ANY WARRANTY; without even the implied | ||
20 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
21 | See the GNU Affero General Public License for more details. | ||
22 | |||
23 | * You should have received a copy of the GNU Affero General Public | ||
24 | License along with Javascript Crypto Library. If not, see | ||
25 | <http://www.gnu.org/licenses/>. | ||
26 | |||
27 | */ | ||
28 | |||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | ||
30 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | ||
31 | if (typeof(Clipperz.PM.Proxy) == 'undefined') { Clipperz.PM.Proxy = {}; } | ||
32 | |||
33 | //============================================================================= | ||
34 | |||
35 | Clipperz.PM.Proxy.Test = function(args) { | ||
36 | Clipperz.PM.Proxy.Test.superclass.constructor.call(this, args); | ||
37 | |||
38 | args = args || {}; | ||
39 | |||
40 | this._expectedRequests = (args.shouldCheckExpectedRequests === true) ? [] : null; | ||
41 | this._isExpectingRequests = true; | ||
42 | this._unexpectedRequests = []; | ||
43 | |||
44 | this.dataStore().resetData(); | ||
45 | |||
46 | return this; | ||
47 | } | ||
48 | |||
49 | Clipperz.Base.extend(Clipperz.PM.Proxy.Test, Clipperz.PM.Proxy.Offline, { | ||
50 | |||
51 | 'toString': function() { | ||
52 | return "Clipperz.PM.Proxy.Test"; | ||
53 | }, | ||
54 | |||
55 | //========================================================================= | ||
56 | |||
57 | 'expectedRequests': function () { | ||
58 | return this._expectedRequests; | ||
59 | }, | ||
60 | |||
61 | //------------------------------------------------------------------------- | ||
62 | |||
63 | 'shouldCheckExpectedRequests': function () { | ||
64 | return (this._expectedRequests != null); | ||
65 | }, | ||
66 | |||
67 | 'setShouldCheckExpectedRequests': function(aValue) { | ||
68 | if (aValue) { | ||
69 | this._expectedRequests = aValue; | ||
70 | } else { | ||
71 | this._expectedRequests = null; | ||
72 | } | ||
73 | }, | ||
74 | |||
75 | //------------------------------------------------------------------------- | ||
76 | |||
77 | 'shouldNotReceiveAnyFurtherRequest': function () { | ||
78 | this._isExpectingRequests = false; | ||
79 | }, | ||
80 | |||
81 | 'mayReceiveMoreRequests': function () { | ||
82 | this._isExpectingRequests = true; | ||
83 | this.resetUnexpectedRequests(); | ||
84 | }, | ||
85 | |||
86 | 'isExpectingRequests': function () { | ||
87 | return this._isExpectingRequests; | ||
88 | }, | ||
89 | |||
90 | //------------------------------------------------------------------------- | ||
91 | |||
92 | 'unexpectedRequests': function () { | ||
93 | return this._unexpectedRequests; | ||
94 | }, | ||
95 | |||
96 | 'resetUnexpectedRequests': function () { | ||
97 | this._unexpectedRequests = []; | ||
98 | }, | ||
99 | |||
100 | //------------------------------------------------------------------------- | ||
101 | |||
102 | 'testExpectedRequestParameters': function (aPath, anActualRequest, anExpectedRequest) { | ||
103 | var aKey; | ||
104 | //console.log(">>> Proxy.testExpectedRequestParameters [" + aPath + "]", anActualRequest, anExpectedRequest); | ||
105 | for (aKey in anExpectedRequest) { | ||
106 | if (typeof(anActualRequest[aKey]) == 'undefined') { | ||
107 | throw "the expected paramter [" + aKey + "] is missing from the actual request"; | ||
108 | } | ||
109 | if (typeof(anExpectedRequest[aKey]) == 'object') { | ||
110 | this.testExpectedRequestParameters(aPath + "." + aKey, anActualRequest[aKey], anExpectedRequest[aKey]) | ||
111 | } else { | ||
112 | if (! anExpectedRequest[aKey](anActualRequest[aKey])) { | ||
113 | throw "wrong value for paramter [" + aKey + "]; got '" + anActualRequest[aKey] + "'"; | ||
114 | } | ||
115 | } | ||
116 | } | ||
117 | //console.log("<<< Proxy.testExpectedRequestParameters"); | ||
118 | }, | ||
119 | |||
120 | //------------------------------------------------------------------------- | ||
121 | |||
122 | 'checkRequest': function(aFunctionName, someParameters) { | ||
123 | if (this.shouldCheckExpectedRequests()) { | ||
124 | var expectedRequest; | ||
125 | |||
126 | //console.log(">>> Proxy.Test.checkRequest - " + aFunctionName, someParameters); | ||
127 | expectedRequest = this.expectedRequests().pop(); | ||
128 | //console.log("--- Proxy.Test.checkRequest - expectedRequest", expectedRequest); | ||
129 | if (expectedRequest == null) { | ||
130 | throw "Proxy.Test.sentMessage: no expected result specified. Got request '" + aFunctionName + "': " + someParameters; | ||
131 | } | ||
132 | |||
133 | try { | ||
134 | if (aFunctionName != expectedRequest.functionName) { | ||
135 | throw "wrong function name. Got '" + aFunctionName + "', expected '" + expectedRequest.request.functionName + "'"; | ||
136 | } | ||
137 | |||
138 | this.testExpectedRequestParameters("parameters", someParameters, expectedRequest.parameters); | ||
139 | } catch(exception) { | ||
140 | //console.log("EXCEPTION: Proxy.Test.sentMessage[" + expectedRequest.name + "]", exception) | ||
141 | throw "Proxy.Test.sentMessage[" + expectedRequest.name + "]: " + exception; | ||
142 | } | ||
143 | } | ||
144 | //console.log("<<< Proxy.Test.checkRequest"); | ||
145 | }, | ||
146 | |||
147 | //========================================================================= | ||
148 | |||
149 | 'sendMessage': function(aFunctionName, someParameters) { | ||
150 | var result; | ||
151 | |||
152 | if (this.isExpectingRequests() == false) { | ||
153 | // throw Clipperz.PM.Connection.exception.UnexpectedRequest; | ||
154 | Clipperz.log("UNEXPECTED REQUEST " + aFunctionName /* + ": " + Clipperz.Base.serializeJSON(someParameters) */); | ||
155 | this.unexpectedRequests().push({'functionName':aFunctionName, 'someParameters': someParameters}); | ||
156 | }; | ||
157 | this.checkRequest(aFunctionName, someParameters); | ||
158 | result = Clipperz.PM.Proxy.Test.superclass.sendMessage.call(this, aFunctionName, someParameters); | ||
159 | |||
160 | return result; | ||
161 | }, | ||
162 | |||
163 | //========================================================================= | ||
164 | __syntaxFix__: "syntax fix" | ||
165 | |||
166 | }); | ||
167 | |||