use of org.jboss.resteasy.client.jaxrs.ResteasyWebTarget in project wildfly by wildfly.
the class EjbBeanValidationTestCase method testObjectValidationOnSubclassThatExtendsAbstractClass.
@Test
public void testObjectValidationOnSubclassThatExtendsAbstractClass() throws Exception {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(url.toURI().toString());
ResteasyWebTarget rtarget = (ResteasyWebTarget) target;
EchoResource customerResource = rtarget.proxy(EchoResource.class);
DummyFlag dummyFlag = rtarget.proxy(DummyFlag.class);
// Create subclass of DummyAbstractClass with valid values
DummySubclass validDummySubclass = new DummySubclass();
validDummySubclass.setDirection("north");
validDummySubclass.setSpeed(10);
// Create subclass of DummyAbstractClass with an invalid value (speed should be greater than 0)
DummySubclass invalidDummySubclass = new DummySubclass();
invalidDummySubclass.setDirection("north");
invalidDummySubclass.setSpeed(0);
Response response = customerResource.validateEchoThroughAbstractClass(validDummySubclass);
// Verify that we received a Bad Request Code from HTTP
assertTrue(String.format("Return code should be 200. It was %d", response.getStatus()), 200 == response.getStatus());
// Verify that the service call has not been executed (flag set to false)
assertTrue("Executed flag should be true", dummyFlag.getExecutedServiceCallFlag());
dummyFlag.clearExecution();
Response response2 = customerResource.validateEchoThroughAbstractClass(invalidDummySubclass);
// Verify that we received a Bad Request Code from HTTP
assertTrue(String.format("Return code should either be 400 or 500. It was %d", response2.getStatus()), 400 == response2.getStatus() || 500 == response2.getStatus());
// Verify that the service call has not been executed (flag set to false)
assertFalse("Executed flag should be false", dummyFlag.getExecutedServiceCallFlag());
}
use of org.jboss.resteasy.client.jaxrs.ResteasyWebTarget in project wildfly by wildfly.
the class EjbBeanValidationTestCase method testObjectValidationOnConcreteClass.
@Test
public void testObjectValidationOnConcreteClass() throws Exception {
Client client = ClientBuilder.newBuilder().build();
WebTarget target = client.target(url.toURI().toString());
ResteasyWebTarget rtarget = (ResteasyWebTarget) target;
EchoResource customerResource = rtarget.proxy(EchoResource.class);
DummyFlag dummyFlag = rtarget.proxy(DummyFlag.class);
// Create a concrete class with valid values
DummyClass validDummyClass = new DummyClass();
validDummyClass.setSpeed(5);
validDummyClass.setDirection("north");
// Create a concrete class with invalid values (direction is null and speed is less than 1)
DummyClass invalidDummyClass = new DummyClass();
invalidDummyClass.setSpeed(0);
Response response = customerResource.validateEchoThroughClass(validDummyClass);
// Verify that we received a Bad Request Code from HTTP
assertTrue(String.format("Return code should be 200. It was %d", response.getStatus()), 200 == response.getStatus());
// Verify that the service call has not been executed (flag set to false)
assertTrue("Executed flag should be true", dummyFlag.getExecutedServiceCallFlag());
// Reset flag
dummyFlag.clearExecution();
Response response2 = customerResource.validateEchoThroughClass(invalidDummyClass);
// Verify that we received a Bad Request Code from HTTP
assertTrue(String.format("Return code should either be 400 or 500, it was %d", response2.getStatus()), 400 == response2.getStatus() || 500 == response2.getStatus());
// Verify that the service call has not been executed (flag set to false)
assertFalse("Executed flag should be false", dummyFlag.getExecutedServiceCallFlag());
}
use of org.jboss.resteasy.client.jaxrs.ResteasyWebTarget in project tutorials by eugenp.
the class RestEasyClientLiveTest method testAddMovie.
@Test
public void testAddMovie() {
final ResteasyClient client = new ResteasyClientBuilder().build();
final ResteasyWebTarget target = client.target(FULL_PATH);
final ServicesInterface proxy = target.proxy(ServicesInterface.class);
Response moviesResponse = proxy.addMovie(batmanMovie);
moviesResponse.close();
moviesResponse = proxy.addMovie(transformerMovie);
if (moviesResponse.getStatus() != Response.Status.CREATED.getStatusCode()) {
System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus());
}
moviesResponse.close();
System.out.println("Response Code: " + moviesResponse.getStatus());
}
use of org.jboss.resteasy.client.jaxrs.ResteasyWebTarget in project tutorials by eugenp.
the class RestEasyClientLiveTest method testUpdateMovie.
@Test
public void testUpdateMovie() {
final ResteasyClient client = new ResteasyClientBuilder().build();
final ResteasyWebTarget target = client.target(FULL_PATH);
final ServicesInterface proxy = target.proxy(ServicesInterface.class);
Response moviesResponse = proxy.addMovie(batmanMovie);
moviesResponse.close();
batmanMovie.setTitle("Batman Begins");
moviesResponse = proxy.updateMovie(batmanMovie);
if (moviesResponse.getStatus() != Response.Status.OK.getStatusCode()) {
System.out.println("Failed : HTTP error code : " + moviesResponse.getStatus());
}
moviesResponse.close();
System.out.println("Response Code: " + moviesResponse.getStatus());
}
use of org.jboss.resteasy.client.jaxrs.ResteasyWebTarget in project fabric8 by fabric8io.
the class ResteasyGitRepoClient method createWebClient.
/**
* Creates a JAXRS web client for the given JAXRS client
*/
protected <T> T createWebClient(Class<T> clientType) {
String address = getAddress();
ResteasyProviderFactory providerFactory = ResteasyProviderFactory.getInstance();
providerFactory.register(ResteasyJackson2Provider.class);
providerFactory.register(Jackson2JsonpInterceptor.class);
providerFactory.register(StringTextStar.class);
providerFactory.register(DefaultTextPlain.class);
providerFactory.register(FileProvider.class);
providerFactory.register(InputStreamProvider.class);
providerFactory.register(new Authenticator());
providerFactory.register(clientType);
ResteasyClientBuilder builder = new ResteasyClientBuilder();
builder.providerFactory(providerFactory);
builder.connectionPoolSize(3);
Client client = builder.build();
ResteasyWebTarget target = (ResteasyWebTarget) client.target(address);
return target.proxy(clientType);
}
Aggregations