use of net.servicestack.client.JsonServiceClient in project ServiceStack.Java by ServiceStack.
the class TechStacksServiceTests method test_does_handle_auth_failure.
public void test_does_handle_auth_failure() {
JsonServiceClient techStacksClient = new JsonServiceClient("http://techstacks.io/");
int errorCode = 0;
try {
LockTechStack request = new LockTechStack();
request.setTechnologyStackId((long) 6);
LockStackResponse res = techStacksClient.post(request);
fail("Should throw");
} catch (WebServiceException ex) {
// private StatusCode has correct code, response status is null due to empty response body.
errorCode = ex.getStatusCode();
}
assertEquals(errorCode, 401);
}
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("https://servicestack.net/");
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_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 TestServiceTests method test_does_fire_Request_and_Response_Filters.
public void test_does_fire_Request_and_Response_Filters() {
JsonServiceClient client = new JsonServiceClient("http://test.servicestack.net");
final ArrayList<String> events = new ArrayList<>();
JsonServiceClient.GlobalRequestFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
events.add("GlobalRequestFilter");
}
};
JsonServiceClient.GlobalResponseFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
events.add("GlobalResponseFilter");
}
};
client.RequestFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
events.add("RequestFilter");
}
};
client.ResponseFilter = new ConnectionFilter() {
@Override
public void exec(HttpURLConnection conn) {
events.add("ResponseFilter");
}
};
Hello request = new Hello().setName("World");
HelloResponse response = client.get(request);
assertEquals("Hello, World!", response.getResult());
String results = strJoin(", ", events);
assertEquals("RequestFilter, GlobalRequestFilter, ResponseFilter, GlobalResponseFilter", results);
}
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]);
}
Aggregations