Search in sources :

Example 56 with GenericType

use of javax.ws.rs.core.GenericType in project cxf by apache.

the class FluxReactorTest method testFluxErrorWithExceptionMapperReturnsContentPayload.

@Test
public void testFluxErrorWithExceptionMapperReturnsContentPayload() throws Exception {
    GenericType<List<HelloWorldBean>> helloWorldBeanListType = new GenericType<List<HelloWorldBean>>() {
    };
    String address = "http://localhost:" + PORT + "/reactor2/flux/mixed/error";
    StepVerifier.create(ClientBuilder.newClient().register(new JacksonJsonProvider()).register(new ReactorInvokerProvider()).target(address).request(MediaType.APPLICATION_JSON).rx(ReactorInvoker.class).get()).expectNextMatches(r -> r.getStatus() == 409 && r.readEntity(helloWorldBeanListType).size() == 4).expectComplete().verify();
}
Also used : GenericType(javax.ws.rs.core.GenericType) ReactorInvokerProvider(org.apache.cxf.jaxrs.reactor.client.ReactorInvokerProvider) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) List(java.util.List) ReactorInvoker(org.apache.cxf.jaxrs.reactor.client.ReactorInvoker) Test(org.junit.Test)

Example 57 with GenericType

use of javax.ws.rs.core.GenericType in project quickstart by wildfly.

the class ContactsRestClientIT method delayedInvocationTest.

// Shows how to use a delayed REST invocation
@Test
public void delayedInvocationTest() throws Exception {
    log.info("### Testing Delayed invocaton ###");
    // 1 - Drop all contacts
    log.info("dropping all contacts");
    Response response = ClientBuilder.newClient().target(getRequestUrl()).request().delete();
    Assert.assertEquals("All contacts should be dropped", Response.ok().build().getStatus(), response.getStatus());
    // 2 - Create a new Contact Invocation
    log.info("Creating a new contact invocation");
    Contact c = new Contact();
    c.setName(CONTACT_NAME);
    c.setPhoneNumber(CONTACT_PHONE);
    Invocation saveContactInvocation = ClientBuilder.newClient().target(getRequestUrl()).request().buildPost(Entity.entity(c, MediaType.APPLICATION_JSON));
    // 3 - Create a new list Contacts Invocation
    log.info("Creating list all contacts invocation");
    Invocation listContactsInvocation = ClientBuilder.newClient().target(getRequestUrl()).request().buildGet();
    // 4 - Synch Save contact
    log.info("invoking the new contact");
    Contact persistedContact = saveContactInvocation.invoke(Contact.class);
    Assert.assertEquals("A contacts should be persisted with Id=1!", (Long) 1L, (Long) persistedContact.getId());
    // 5 - Async List contacts
    log.info("invoking list all contacts ASYNC");
    GenericType<List<Contact>> contactsListType = new GenericType<List<Contact>>() {
    };
    Future<List<Contact>> futureAllContacts = listContactsInvocation.submit(contactsListType);
    List<Contact> allContacts = futureAllContacts.get();
    Assert.assertEquals("Should have a single contact", 1, allContacts.size());
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) Invocation(javax.ws.rs.client.Invocation) List(java.util.List) Contact(org.jboss.as.quickstarts.jaxrsclient.model.Contact) Test(org.junit.Test)

Example 58 with GenericType

use of javax.ws.rs.core.GenericType in project quickstart by wildfly.

the class ContactsRestClientIT method requestResponseFiltersTest.

// Shows how to use Request and Response filters
@Test
public void requestResponseFiltersTest() {
    log.info("### Testing Request and Response Filters ###");
    // 1 - Drop all contacts
    log.info("dropping all contacts");
    Response response = ClientBuilder.newClient().target(getRequestUrl()).request().delete();
    Assert.assertEquals("All contacts should be dropped", Response.ok().build().getStatus(), response.getStatus());
    // 2 - Create a new Contact Invocation
    log.info("Invoking create new contact using a ClientRequestFilter");
    Contact c = new Contact();
    c.setName(CONTACT_NAME);
    c.setPhoneNumber(CONTACT_PHONE);
    Contact persistedContact = ClientBuilder.newClient().register(SavedByClientRequestFilter.class).target(getRequestUrl()).request().post(Entity.entity(c, MediaType.APPLICATION_JSON), Contact.class);
    Assert.assertEquals("A contact should be persisted with savedBy", SavedByClientRequestFilter.USERNAME, persistedContact.getSavedBy());
    // 3 - Fetch all Contacts
    log.info("Invoking list all contacts using a ClientResponseFilter");
    GenericType<List<Contact>> contactsListType = new GenericType<List<Contact>>() {
    };
    List<Contact> allContacts = ClientBuilder.newClient().register(LogResponseFilter.class).target(getRequestUrl()).request().get(contactsListType);
    Assert.assertEquals("Should have a single contact", 1, allContacts.size());
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) Contact(org.jboss.as.quickstarts.jaxrsclient.model.Contact) Test(org.junit.Test)

Example 59 with GenericType

use of javax.ws.rs.core.GenericType in project quickstart by wildfly.

the class ContactsRestClient method requestResponseFiltersTest.

// Shows how to use Request and Response filters
public void requestResponseFiltersTest() {
    log.info("### Testing Request and Response Filters ###");
    // 1 - Drop all contacts
    log.info("dropping all contacts");
    Response response = ClientBuilder.newClient().target(REST_TARGET_URL).request().delete();
    Assert.assertEquals("All contacts should be dropped", Response.ok().build().getStatus(), response.getStatus());
    // 2 - Create a new Contact Invocation
    log.info("Invoking create new contact using a ClientRequestFilter");
    Contact c = new Contact();
    c.setName(CONTACT_NAME);
    c.setPhoneNumber(CONTACT_PHONE);
    Contact persistedContact = ClientBuilder.newClient().register(SavedByClientRequestFilter.class).target(REST_TARGET_URL).request().post(Entity.entity(c, MediaType.APPLICATION_JSON), Contact.class);
    Assert.assertEquals("A contact should be persisted with savedBy", SavedByClientRequestFilter.USERNAME, persistedContact.getSavedBy());
    // 3 - Fetch all Contacts
    log.info("Invoking list all contacts using a ClientResponseFilter");
    GenericType<List<Contact>> contactsListType = new GenericType<List<Contact>>() {
    };
    List<Contact> allContacts = ClientBuilder.newClient().register(LogResponseFilter.class).target(REST_TARGET_URL).request().get(contactsListType);
    Assert.assertEquals("Should have a single contact", 1, allContacts.size());
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) List(java.util.List) Contact(org.jboss.as.quickstarts.jaxrsclient.model.Contact)

Example 60 with GenericType

use of javax.ws.rs.core.GenericType in project quickstart by wildfly.

the class ContactsRestClient method delayedInvocationTest.

// Shows how to use a delayed REST invocation
public void delayedInvocationTest() throws Exception {
    log.info("### Testing Delayed invocaton ###");
    // 1 - Drop all contacts
    log.info("dropping all contacts");
    Response response = ClientBuilder.newClient().target(REST_TARGET_URL).request().delete();
    Assert.assertEquals("All contacts should be dropped", Response.ok().build().getStatus(), response.getStatus());
    // 2 - Create a new Contact Invocation
    log.info("Creating a new contact invocation");
    Contact c = new Contact();
    c.setName(CONTACT_NAME);
    c.setPhoneNumber(CONTACT_PHONE);
    Invocation saveContactInvocation = ClientBuilder.newClient().target(REST_TARGET_URL).request().buildPost(Entity.entity(c, MediaType.APPLICATION_JSON));
    // 3 - Create a new list Contacts Invocation
    log.info("Creating list all contacts invocation");
    Invocation listContactsInvocation = ClientBuilder.newClient().target(REST_TARGET_URL).request().buildGet();
    // 4 - Synch Save contact
    log.info("invoking the new contact");
    Contact persistedContact = saveContactInvocation.invoke(Contact.class);
    Assert.assertEquals("A contacts should be persisted with Id=1!", (Long) 1L, (Long) persistedContact.getId());
    // 5 - Async List contacts
    log.info("invoking list all contacts ASYNC");
    GenericType<List<Contact>> contactsListType = new GenericType<List<Contact>>() {
    };
    Future<List<Contact>> futureAllContacts = listContactsInvocation.submit(contactsListType);
    List<Contact> allContacts = futureAllContacts.get();
    Assert.assertEquals("Should have a single contact", 1, allContacts.size());
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) Invocation(javax.ws.rs.client.Invocation) List(java.util.List) Contact(org.jboss.as.quickstarts.jaxrsclient.model.Contact)

Aggregations

GenericType (javax.ws.rs.core.GenericType)126 List (java.util.List)64 WebTarget (javax.ws.rs.client.WebTarget)64 Response (javax.ws.rs.core.Response)60 Test (org.junit.Test)51 Client (javax.ws.rs.client.Client)24 ArrayList (java.util.ArrayList)17 Message (com.remswork.project.alice.model.support.Message)16 WebClient (org.apache.cxf.jaxrs.client.WebClient)16 GenericEntity (javax.ws.rs.core.GenericEntity)15 MediaType (javax.ws.rs.core.MediaType)15 Collection (java.util.Collection)14 Set (java.util.Set)14 LinkedList (java.util.LinkedList)12 HashSet (java.util.HashSet)11 Test (org.junit.jupiter.api.Test)11 JerseyTest (org.glassfish.jersey.test.JerseyTest)10 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)9 Collections (java.util.Collections)9 Entity (javax.ws.rs.client.Entity)9