Package org.apache.cxf.jaxrs.client

Examples of org.apache.cxf.jaxrs.client.WebClient.accept()


    public void testPostObjectGetCollection() throws Exception {
       
        String endpointAddress =
            "http://localhost:" + PORT + "/bookstore/collectionBook";
        WebClient wc = WebClient.create(endpointAddress);
        wc.accept("application/xml").type("application/xml");
        Book b1 = new Book("Book", 666L);
        List<Book> books = new ArrayList<Book>(wc.postObjectGetCollection(b1, Book.class));
        assertNotNull(books);
        assertEquals(1, books.size());
        Book b = books.get(0);
View Full Code Here


    }
   
    @Test
    public void testServerWebApplicationException() throws Exception {
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/webappexception");
        wc.accept("application/xml");
        try {
            wc.get(Book.class);
            fail("Exception expected");
        } catch (ServerWebApplicationException ex) {
            assertEquals(500, ex.getStatus());
View Full Code Here

    }
   
    @Test
    public void testServerWebApplicationExceptionResponse() throws Exception {
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/webappexception");
        wc.accept("application/xml");
        try {
            Response r = wc.get(Response.class);
            assertEquals(500, r.getStatus());
        } catch (ServerWebApplicationException ex) {
            fail("Unexpected exception");
View Full Code Here

    public void testServerWebApplicationExceptionXML() throws Exception {
        ResponseReader reader = new ResponseReader();
        reader.setEntityClass(Book.class);
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/webappexceptionXML",
                                        Collections.singletonList(reader));
        wc.accept("application/xml");
        try {
            wc.get(Book.class);
            fail("Exception expected");
        } catch (ServerWebApplicationException ex) {
            assertEquals(406, ex.getStatus());
View Full Code Here

   
    @Test
    public void testMalformedAcceptType() {
        WebClient wc =
            WebClient.create("http://localhost:" + PORT + "/bookstore/books/123");
        wc.accept("application");
        Response r = wc.get();
        assertEquals(406, r.getStatus());
    }
   
    public void testGetBookWithCustomHeader() throws Exception {
View Full Code Here

    public void testGetCollectionOfBooks() throws Exception {
       
        String endpointAddress =
            "http://localhost:" + PORT + "/bookstore/collections";
        WebClient wc = WebClient.create(endpointAddress);
        wc.accept("application/xml");
        Collection<? extends Book> collection = wc.getCollection(Book.class);
        assertEquals(1, collection.size());
        Book book = collection.iterator().next();
        assertEquals(123L, book.getId());
    }
View Full Code Here

    }
   
    @Test
    public void testServerWebApplicationException() throws Exception {
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/webappexception");
        wc.accept("application/xml");
        try {
            wc.get(Book.class);
            fail("Exception expected");
        } catch (ServerWebApplicationException ex) {
            assertEquals(500, ex.getStatus());
View Full Code Here

    public void testServerWebApplicationExceptionXML() throws Exception {
        ResponseReader reader = new ResponseReader();
        reader.setEntityClass(Book.class);
        WebClient wc = WebClient.create("http://localhost:" + PORT + "/bookstore/webappexceptionXML",
                                        Collections.singletonList(reader));
        wc.accept("application/xml");
        try {
            wc.get(Book.class);
            fail("Exception expected");
        } catch (ServerWebApplicationException ex) {
            assertEquals(406, ex.getStatus());
View Full Code Here

    public void testGetBookFromResponseWithWebClient() throws Exception {
        String address = "http://localhost:" + PORT + "/bookstore/genericresponse/123";
        WebClient wc = WebClient.create(address,
                                        Collections.singletonList(
                                        new ResponseReader(Book.class)));
        Response r = wc.accept("application/xml").get();
        assertEquals(200, r.getStatus());
        Book book = (Book)r.getEntity();
        assertEquals(123L, book.getId());
    }
   
View Full Code Here

    public void testGetGenericBook() throws Exception {
        String baseAddress = "http://localhost:" + PORT + "/the/thebooks8/books";
        WebClient wc = WebClient.create(baseAddress);
        Long id = wc.type("application/xml").accept("text/plain").post(new Book("CXF", 1L), Long.class);
        assertEquals(new Long(1), id);
        Book book = wc.accept("application/xml").query("id", 1L).get(Book.class);
        assertEquals("CXF", book.getName());
    }
   
    @Test
    public void testPostGeneratedBook() throws Exception {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.