Package org.glassfish.jersey.server

Examples of org.glassfish.jersey.server.ApplicationHandler


* @author Jakub Podlesak (jakub.podlesak at oracle.com)
*/
public class ConsumeProduceSimpleTest  {

    private ApplicationHandler createApplication(Class<?>... classes) {
        return new ApplicationHandler(new ResourceConfig(classes));
    }
View Full Code Here


        }
    }

    @Test
    public void testConsumeSimpleBean() throws Exception {
        ApplicationHandler app = createApplication(ConsumeSimpleBean.class);

        assertEquals("HTML", app.apply(RequestContextBuilder.from("/a/b", "POST").entity("").type("text/html").build()).get().getEntity());
        assertEquals("XHTML", app.apply(RequestContextBuilder.from("/a/b", "POST").entity("").type("text/xhtml").build()).get().getEntity());
    }
View Full Code Here

        assertEquals("XHTML", app.apply(RequestContextBuilder.from("/a/b", "POST").entity("").type("text/xhtml").build()).get().getEntity());
    }

    @Test
    public void testProduceSimpleBean() throws Exception {
        ApplicationHandler app = createApplication(ProduceSimpleBean.class);

        assertEquals("HTML", app.apply(RequestContextBuilder.from("/a/b", "GET").accept("text/html").build()).get().getEntity());
        assertEquals("XHTML", app.apply(RequestContextBuilder.from("/a/b", "GET").accept("text/xhtml").build()).get().getEntity());
    }
View Full Code Here

        assertEquals("XHTML", app.apply(RequestContextBuilder.from("/a/b", "GET").accept("text/xhtml").build()).get().getEntity());
    }

    @Test
    public void testConsumeProduceSimpleBean() throws Exception {
        ApplicationHandler app = createApplication(ConsumeProduceSimpleBean.class);

        assertEquals("HTML", app.apply(RequestContextBuilder.from("/a/b", "POST").entity("").type("text/html").accept("text/html").build()).get().getEntity());
        assertEquals("XHTML", app.apply(RequestContextBuilder.from("/a/b", "POST").entity("").type("text/xhtml").accept("text/xhtml").build()).get().getEntity());
        assertEquals("HTML", app.apply(RequestContextBuilder.from("/a/b", "GET").accept("text/html").build()).get().getEntity());
        assertEquals("XHTML", app.apply(RequestContextBuilder.from("/a/b", "GET").accept("text/xhtml").build()).get().getEntity());
    }
View Full Code Here

        }
    }

    @Test
    public void testProduceWithParameters() throws Exception {
        ApplicationHandler app = createApplication(ConsumeProduceWithParameters.class);

        assertEquals("{a=b, c=d}", app.apply(RequestContextBuilder.from("/", "POST").entity("<html>content</html>").type("text/html;a=b;c=d").build()).get().getEntity());
    }
View Full Code Here

        }
    }

    @Test
    public void testImplicitProduces() throws Exception {
        final ApplicationHandler application = createApplication(ImplicitProducesResource.class);
        final ContainerResponse response = application.
                apply(RequestContextBuilder.from("/", "GET").accept(MediaType.TEXT_PLAIN_TYPE).build()).get();

        assertEquals("text/plain", response.getEntity());
        assertEquals("text-plain", response.getHeaderString("HEAD"));
    }
View Full Code Here

    }

    @Test()
    public void testEagerConverter() throws Exception {
        try {
            new ApplicationHandler(new ResourceConfig(MyEagerParamProvider.class, Resource.class));
            fail("ExtractorException expected.");
        } catch (final ExtractorException expected) {
            // ok
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testLazyConverter() throws Exception {
        final ApplicationHandler application = new ApplicationHandler(new ResourceConfig(MyLazyParamProvider.class, Resource.class));
        final ContainerResponse response = application.apply(RequestContextBuilder.from("/resource", "GET").build()).get();
        assertEquals(400, response.getStatus());
    }
View Full Code Here

        }
    }

    @Test
    public void testGet() throws ExecutionException, InterruptedException {
        ApplicationHandler handler = getApplication();
        final ContainerResponse response = handler.apply(RequestContextBuilder.from("/resource", "GET").build()).get();
        assertEquals(200, response.getStatus());
        assertEquals("get", response.getEntity());
        assertResponseHeaders(response, "MyResource", "get");
    }
View Full Code Here

    }


    @Test
    public void testGetMultiple() throws ExecutionException, InterruptedException {
        ApplicationHandler handler = getApplication();
        ContainerResponse response = handler.apply(RequestContextBuilder.from("/resource", "GET").build()).get();
        assertEquals(200, response.getStatus());
        assertEquals("get", response.getEntity());
        assertResponseHeaders(response, "MyResource", "get");
        response = handler.apply(RequestContextBuilder.from("/resource/get-child", "GET").build()).get();
        assertEquals(200, response.getStatus());
        assertEquals("get-child", response.getEntity());
        assertResponseHeaders(response, "MyResource", "getChild");
    }
View Full Code Here

TOP

Related Classes of org.glassfish.jersey.server.ApplicationHandler

Copyright © 2018 www.massapicom. 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.