use of net.servicestack.client.JsonServiceClient in project ServiceStack.Java by ServiceStack.
the class JsonServiceClientTests method test_can_serialize_dates_correctly_via_get_request.
public void test_can_serialize_dates_correctly_via_get_request() {
JsonServiceClient client = new JsonServiceClient("http://test.servicestack.net/");
EchoTypes request = new EchoTypes();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2015);
cal.set(Calendar.MONTH, Calendar.JANUARY);
cal.set(Calendar.DAY_OF_MONTH, 1);
Date dateRepresentation = cal.getTime();
Date date = dateRepresentation;
request.setDateTime(date);
EchoTypes response = client.get(request);
assertTrue(response != null);
assertEquals(request.getDateTime(), response.getDateTime());
}
use of net.servicestack.client.JsonServiceClient in project ServiceStack.Java by ServiceStack.
the class JsonServiceClientTests method test_does_process_missing_service_correctly.
public void test_does_process_missing_service_correctly() {
JsonServiceClient localTestClient = new JsonServiceClient("http://techstacks.io/");
try {
localTestClient.get(new EchoTypes());
fail("Should throw");
} catch (WebServiceException ex) {
assertEquals(ex.getStatusCode(), 405);
}
}
use of net.servicestack.client.JsonServiceClient in project ServiceStack.Java by ServiceStack.
the class JsonServiceClientTests method test_can_use_request_filter.
public void test_can_use_request_filter() {
final Boolean[] passTest = { false };
JsonServiceClient localTestClient = new JsonServiceClient("http://test.servicestack.net/");
localTestClient.RequestFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
passTest[0] = true;
}
};
Hello request = new Hello().setName("World");
HelloResponse response = localTestClient.get(request);
assertEquals("Hello, World!", response.getResult());
assertTrue(passTest[0]);
}
use of net.servicestack.client.JsonServiceClient in project ServiceStack.Java by ServiceStack.
the class TestServiceTests method test_Does_handle_401_Error_with_empty_ResponseBody.
public void test_Does_handle_401_Error_with_empty_ResponseBody() {
JsonServiceClient testClient = new JsonServiceClient("http://test.servicestack.net");
// Wow Java, you suck.
final Exception[] globalError = new Exception[1];
final Exception[] localError = new Exception[1];
WebServiceException thrownError = null;
JsonServiceClient.GlobalExceptionFilter = new ExceptionFilter() {
@Override
public void exec(HttpURLConnection res, Exception ex) {
globalError[0] = ex;
}
};
testClient.ExceptionFilter = new ExceptionFilter() {
@Override
public void exec(HttpURLConnection res, Exception ex) {
localError[0] = ex;
}
};
TestAuth request = new TestAuth();
try {
TestAuthResponse response = testClient.send(request);
} catch (WebServiceException webEx) {
thrownError = webEx;
}
assertNotNull(globalError[0]);
assertNotNull(localError[0]);
assertNotNull(thrownError);
ResponseStatus status = thrownError.getResponseStatus();
assertNull(status);
}
use of net.servicestack.client.JsonServiceClient in project ServiceStack.Java by ServiceStack.
the class TestServiceTests method test_Does_handle_404_Error.
public void test_Does_handle_404_Error() {
JsonServiceClient testClient = new JsonServiceClient("http://test.servicestack.net");
// Wow Java, you suck.
final Exception[] globalError = new Exception[1];
final Exception[] localError = new Exception[1];
WebServiceException thrownError = null;
JsonServiceClient.GlobalExceptionFilter = new ExceptionFilter() {
@Override
public void exec(HttpURLConnection res, Exception ex) {
globalError[0] = ex;
}
};
testClient.ExceptionFilter = new ExceptionFilter() {
@Override
public void exec(HttpURLConnection res, Exception ex) {
localError[0] = ex;
}
};
ThrowType request = new ThrowType().setType("NotFound").setMessage("not here");
try {
ThrowTypeResponse response = testClient.put(request);
} catch (WebServiceException webEx) {
thrownError = webEx;
}
assertNotNull(globalError[0]);
assertNotNull(localError[0]);
assertNotNull(thrownError);
ResponseStatus status = thrownError.getResponseStatus();
assertEquals("NotFound", status.getErrorCode());
assertEquals("not here", status.getMessage());
assertNotNull(status.getStackTrace());
}
Aggregations