Search in sources :

Example 36 with Book

use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.

the class JAXRSJmsTest method testGetBookFromWebClientWithPathWithTextJMSMessage.

@Test
public void testGetBookFromWebClientWithPathWithTextJMSMessage() throws Exception {
    // setup the the client
    String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text" + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory" + "&replyToName=dynamicQueues/test.jmstransport.response" + "&jndiURL=tcp://localhost:" + JMS_PORT + "&jndiConnectionFactoryName=ConnectionFactory" + "&messageType=text";
    WebClient client = WebClient.create(endpointAddressUrlEncoded);
    client.path("bookstore").path("books").path("123");
    Book book = client.get(Book.class);
    assertEquals("Get a wrong response code.", 200, client.getResponse().getStatus());
    assertEquals("Get a wrong book id.", 123, book.getId());
}
Also used : Book(org.apache.cxf.systest.jaxrs.Book) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 37 with Book

use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.

the class JAXRSJmsTest method testGetBookFromProxyClientWithTextJMSMessage.

@Test
public void testGetBookFromProxyClientWithTextJMSMessage() throws Exception {
    // setup the the client
    String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text" + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory" + "&replyToName=dynamicQueues/test.jmstransport.response" + "&jndiURL=tcp://localhost:" + JMS_PORT + "&jndiConnectionFactoryName=ConnectionFactory" + "&messageType=text";
    JMSBookStore client = JAXRSClientFactory.create(endpointAddressUrlEncoded, JMSBookStore.class);
    Book book = client.getBook("123");
    assertEquals("Get a wrong response code.", 200, WebClient.client(client).getResponse().getStatus());
    assertEquals("Get a wrong book id.", 123, book.getId());
}
Also used : JMSBookStore(org.apache.cxf.systest.jaxrs.JMSBookStore) Book(org.apache.cxf.systest.jaxrs.Book) Test(org.junit.Test)

Example 38 with Book

use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.

the class JAXRSJmsTest method testGetBookFromProxyClientWithQueryWithTextJMSMessage.

@Test
public void testGetBookFromProxyClientWithQueryWithTextJMSMessage() throws Exception {
    // setup the the client
    String endpointAddressUrlEncoded = "jms:jndi:dynamicQueues/test.jmstransport.text" + "?jndiInitialContextFactory=org.apache.activemq.jndi.ActiveMQInitialContextFactory" + "&replyToName=dynamicQueues/test.jmstransport.response" + "&jndiURL=tcp://localhost:" + JMS_PORT + "&jndiConnectionFactoryName=ConnectionFactory" + "&messageType=text";
    JMSBookStore client = JAXRSClientFactory.create(endpointAddressUrlEncoded, JMSBookStore.class);
    Book book = client.getBookByURLQuery(new String[] { "1", "2", "3" });
    assertEquals("Get a wrong response code.", 200, WebClient.client(client).getResponse().getStatus());
    assertEquals("Get a wrong book id.", 123, book.getId());
}
Also used : JMSBookStore(org.apache.cxf.systest.jaxrs.JMSBookStore) Book(org.apache.cxf.systest.jaxrs.Book) Test(org.junit.Test)

Example 39 with Book

use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.

the class JAXRSCompletionStageTest method testGetBookAsyncStageThenAcceptAsync.

@Test
public void testGetBookAsyncStageThenAcceptAsync() throws Exception {
    String address = "http://localhost:" + PORT + "/completable/books";
    WebClient wc = createWebClient(address);
    CompletionStage<Book> stage = wc.path("123").rx().get(Book.class);
    Holder<Book> holder = new Holder<Book>();
    stage.thenApply(v -> {
        v.setId(v.getId() * 2);
        return v;
    }).thenAcceptAsync(v -> {
        holder.value = v;
    });
    Thread.sleep(3000);
    assertEquals(246L, holder.value.getId());
}
Also used : ExecutionException(java.util.concurrent.ExecutionException) AbstractResourceInfo(org.apache.cxf.jaxrs.model.AbstractResourceInfo) CompletionStage(java.util.concurrent.CompletionStage) Book(org.apache.cxf.systest.jaxrs.Book) BeforeClass(org.junit.BeforeClass) WebClient(org.apache.cxf.jaxrs.client.WebClient) AbstractBusClientServerTestBase(org.apache.cxf.testutil.common.AbstractBusClientServerTestBase) Holder(javax.xml.ws.Holder) Test(org.junit.Test) NotFoundException(javax.ws.rs.NotFoundException) Book(org.apache.cxf.systest.jaxrs.Book) Holder(javax.xml.ws.Holder) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 40 with Book

use of org.apache.cxf.systest.jaxrs.Book in project cxf by apache.

the class JAXRSCompletionStageTest method testGetBookAsyncStage404.

@Test
public void testGetBookAsyncStage404() throws Exception {
    String address = "http://localhost:" + PORT + "/completable/books";
    WebClient wc = createWebClient(address);
    CompletionStage<Book> stage = wc.path("124").rx().get(Book.class);
    try {
        stage.toCompletableFuture().get();
        fail("Exception expected");
    } catch (ExecutionException ex) {
        assertTrue(ex.getCause() instanceof NotFoundException);
    }
}
Also used : Book(org.apache.cxf.systest.jaxrs.Book) NotFoundException(javax.ws.rs.NotFoundException) ExecutionException(java.util.concurrent.ExecutionException) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Aggregations

Book (org.apache.cxf.systest.jaxrs.Book)46 Test (org.junit.Test)31 WebClient (org.apache.cxf.jaxrs.client.WebClient)22 BookStore (org.apache.cxf.systest.jaxrs.BookStore)8 JMSBookStore (org.apache.cxf.systest.jaxrs.JMSBookStore)6 SequentialStrategy (org.apache.cxf.clustering.SequentialStrategy)5 Response (javax.ws.rs.core.Response)4 ArrayList (java.util.ArrayList)3 BytesMessage (javax.jms.BytesMessage)3 JAXBContext (javax.xml.bind.JAXBContext)3 InputStream (java.io.InputStream)2 ExecutionException (java.util.concurrent.ExecutionException)2 MessageProducer (javax.jms.MessageProducer)2 InternalServerErrorException (javax.ws.rs.InternalServerErrorException)2 NotFoundException (javax.ws.rs.NotFoundException)2 ProcessingException (javax.ws.rs.ProcessingException)2 Client (javax.ws.rs.client.Client)2 ClientBuilder (javax.ws.rs.client.ClientBuilder)2 WebTarget (javax.ws.rs.client.WebTarget)2 Form (javax.ws.rs.core.Form)2