Skip to content

Commit 774278d

Browse files
committed
Added test for auth.
Exposed status code from WebServiceException as 401 errors don't return a body.
1 parent f5b35ab commit 774278d

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/AndroidClient/client/src/androidTest/java/net/servicestack/client/tests/TestServiceTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,17 @@ public void test_Can_POST_valid_ThrowValidation_request() {
178178

179179
public void test_does_handle_auth_failure() {
180180
JsonServiceClient techStacksClient = new JsonServiceClient("http://techstacks.io/");
181-
String errorCode = "";
181+
int errorCode = 0;
182182
try {
183183
dto.LockTechStack request = new dto.LockTechStack();
184184
request.setTechnologyStackId((long)6);
185185
dto.LockStackResponse res = techStacksClient.post(request);
186+
fail("Should throw");
186187
} catch(WebServiceException ex) {
187188
//private StatusCode has correct code, response status is null due to empty response body.
188-
errorCode = ex.getResponseStatus().errorCode;
189+
errorCode = ex.getStatusCode();
189190
}
190-
assertEquals(errorCode,"401");
191+
assertEquals(errorCode,401);
191192
}
192193

193194
/* TEST HELPERS */

src/AndroidClient/client/src/main/java/net/servicestack/client/Utils.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import org.apache.http.util.ByteArrayBuffer;
1212

13-
1413
import java.io.BufferedInputStream;
1514
import java.io.BufferedReader;
1615
import java.io.IOException;
@@ -27,12 +26,12 @@
2726
import java.util.Calendar;
2827
import java.util.Date;
2928
import java.util.HashMap;
30-
import java.util.Iterator;
3129
import java.util.List;
3230
import java.util.Map;
3331
import java.util.UUID;
3432

35-
import static net.servicestack.client.Func.*;
33+
import static net.servicestack.client.Func.Function;
34+
import static net.servicestack.client.Func.last;
3635

3736
// Generic Utils
3837
public class Utils {

src/AndroidClient/client/src/main/java/net/servicestack/client/WebServiceException.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ public String getServerStackTrace(){
3939
return ResponseStatus != null ? ResponseStatus.stackTrace : null;
4040
}
4141

42+
public int getStatusCode() {
43+
return this.StatusCode;
44+
}
45+
46+
public String getStatusDescription() {
47+
return this.StatusDescription;
48+
}
49+
4250
public ArrayList<ResponseError> getFieldErrors(){
4351
ArrayList<ResponseError> fieldErrors = ResponseStatus != null
4452
? ResponseStatus.getErrors()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy