19
19
import java .net .URL ;
20
20
import java .util .HashMap ;
21
21
import java .util .Map ;
22
- import java .util .Random ;
23
-
24
- import org .json .JSONArray ;
25
22
import org .json .JSONObject ;
26
23
import org .junit .After ;
27
24
import org .junit .Before ;
28
25
import org .junit .Test ;
29
26
import org .skyscreamer .jsonassert .JSONCompareMode ;
30
27
31
28
public class ParseRESTUserCommandTest {
32
- private static final String ALLOWED_CHARACTERS = "0123456789qwertyuiopasdfghjklzxcvbnm" ;
33
29
34
30
@ Before
35
31
public void setUp () throws MalformedURLException {
@@ -59,7 +55,7 @@ public void testGetCurrentUserCommand() {
59
55
@ Test
60
56
public void testLogInUserCommand () throws Exception {
61
57
ParseRESTUserCommand command =
62
- ParseRESTUserCommand .logInUserCommand ("userName" , "password" , true );
58
+ ParseRESTUserCommand .logInUserCommand ("userName" , "password" , true );
63
59
64
60
assertEquals ("login" , command .httpPath );
65
61
assertEquals (ParseHttpRequest .Method .GET , command .method );
@@ -72,7 +68,7 @@ public void testLogInUserCommand() throws Exception {
72
68
@ Test
73
69
public void testResetPasswordResetCommand () throws Exception {
74
70
ParseRESTUserCommand command =
75
- ParseRESTUserCommand .
resetPasswordResetCommand (
"[email protected] " );
71
+ ParseRESTUserCommand .
resetPasswordResetCommand (
"[email protected] " );
76
72
77
73
assertEquals ("requestPasswordReset" , command .httpPath );
78
74
assertEquals (ParseHttpRequest .Method .POST , command .method );
@@ -86,7 +82,7 @@ public void testSignUpUserCommand() throws Exception {
86
82
JSONObject parameters = new JSONObject ();
87
83
parameters .put ("key" , "value" );
88
84
ParseRESTUserCommand command =
89
- ParseRESTUserCommand .signUpUserCommand (parameters , "sessionToken" , true );
85
+ ParseRESTUserCommand .signUpUserCommand (parameters , "sessionToken" , true );
90
86
91
87
assertEquals ("users" , command .httpPath );
92
88
assertEquals (ParseHttpRequest .Method .POST , command .method );
@@ -100,7 +96,7 @@ public void testServiceLogInUserCommandWithParameters() throws Exception {
100
96
JSONObject parameters = new JSONObject ();
101
97
parameters .put ("key" , "value" );
102
98
ParseRESTUserCommand command =
103
- ParseRESTUserCommand .serviceLogInUserCommand (parameters , "sessionToken" , true );
99
+ ParseRESTUserCommand .serviceLogInUserCommand (parameters , "sessionToken" , true );
104
100
105
101
assertEquals ("users" , command .httpPath );
106
102
assertEquals (ParseHttpRequest .Method .POST , command .method );
@@ -114,7 +110,7 @@ public void testServiceLogInUserCommandWithAuthType() throws Exception {
114
110
Map <String , String > facebookAuthData = new HashMap <>();
115
111
facebookAuthData .put ("token" , "test" );
116
112
ParseRESTUserCommand command =
117
- ParseRESTUserCommand .serviceLogInUserCommand ("facebook" , facebookAuthData , true );
113
+ ParseRESTUserCommand .serviceLogInUserCommand ("facebook" , facebookAuthData , true );
118
114
119
115
assertEquals ("users" , command .httpPath );
120
116
assertEquals (ParseHttpRequest .Method .POST , command .method );
@@ -136,7 +132,7 @@ public void testAddAdditionalHeaders() throws Exception {
136
132
JSONObject parameters = new JSONObject ();
137
133
parameters .put ("key" , "value" );
138
134
ParseRESTUserCommand command =
139
- ParseRESTUserCommand .signUpUserCommand (parameters , "sessionToken" , true );
135
+ ParseRESTUserCommand .signUpUserCommand (parameters , "sessionToken" , true );
140
136
141
137
ParseHttpRequest .Builder requestBuilder = new ParseHttpRequest .Builder ();
142
138
command .addAdditionalHeaders (requestBuilder );
@@ -157,54 +153,15 @@ public void testOnResponseAsync() {
157
153
int statusCode = 200 ;
158
154
159
155
ParseHttpResponse response =
160
- new ParseHttpResponse .Builder ()
161
- .setContent (new ByteArrayInputStream (content .getBytes ()))
162
- .setContentType (contentType )
163
- .setStatusCode (statusCode )
164
- .build ();
156
+ new ParseHttpResponse .Builder ()
157
+ .setContent (new ByteArrayInputStream (content .getBytes ()))
158
+ .setContentType (contentType )
159
+ .setStatusCode (statusCode )
160
+ .build ();
165
161
command .onResponseAsync (response , null );
166
162
167
163
assertEquals (200 , command .getStatusCode ());
168
164
}
169
165
170
- @ Test
171
- public void testRequestIdHeader () throws Exception {
172
- JSONArray nestedJSONArray = new JSONArray ().put (true ).put (1 ).put ("test" );
173
- JSONObject nestedJSON =
174
- new JSONObject ().put ("bool" , false ).put ("int" , 2 ).put ("string" , "test" );
175
- String sessionToken = generateRandomString (32 );
176
- String installationId = generateRandomString (32 );
177
- String masterKey = generateRandomString (32 );
178
- JSONObject json =
179
- new JSONObject ()
180
- .put ("json" , nestedJSON )
181
- .put ("jsonArray" , nestedJSONArray )
182
- .put ("bool" , true )
183
- .put ("int" , 3 )
184
- .put ("string" , "test" );
185
-
186
- String jsonString = ParseRESTCommand .toDeterministicString (json );
187
-
188
- JSONObject jsonAgain = new JSONObject (jsonString );
189
- jsonAgain .put (ParseRESTCommand .HEADER_INSTALLATION_ID , installationId );
190
- jsonAgain .put (ParseRESTCommand .HEADER_SESSION_TOKEN , sessionToken );
191
- jsonAgain .put (ParseRESTCommand .HEADER_MASTER_KEY , masterKey );
192
- ParseRESTCommand restCommand = new ParseRESTCommand .Builder ().jsonParameters (json )
193
- .installationId (installationId ).sessionToken (sessionToken ).masterKey (masterKey )
194
- .build ();
195
-
196
- ParseHttpRequest .Builder builder = new ParseHttpRequest .Builder ();
197
- restCommand .addAdditionalHeaders (builder );
198
- assertEquals (ParseDigestUtils .md5 (ParseRESTCommand .toDeterministicString (jsonAgain )), builder .build ().getHeader (ParseRESTCommand .HEADER_REQUEST_ID ));
199
- }
200
-
201
- private static String generateRandomString (final int sizeOfRandomString ) {
202
- final Random random = new Random ();
203
- final StringBuilder sb = new StringBuilder (sizeOfRandomString );
204
- for (int i = 0 ; i < sizeOfRandomString ; ++i )
205
- sb .append (ALLOWED_CHARACTERS .charAt (random .nextInt (ALLOWED_CHARACTERS .length ())));
206
- return sb .toString ();
207
- }
208
-
209
166
// endregion
210
167
}
0 commit comments