Search in sources :

Example 21 with Response

use of javax.ws.rs.core.Response in project jersey by jersey.

the class ProgrammaticResourceMethodsTest method testGet.

@Test
public void testGet() throws Exception {
    final ResourceConfig rc = new ResourceConfig();
    final Resource.Builder resourceBuilder = Resource.builder("test");
    resourceBuilder.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext request) {
            return Response.ok().build();
        }
    });
    rc.registerResources(resourceBuilder.build());
    final ApplicationHandler application = new ApplicationHandler(rc);
    checkReturnedStatus(RequestContextBuilder.from("/test", "GET").build(), application);
}
Also used : Response(javax.ws.rs.core.Response) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 22 with Response

use of javax.ws.rs.core.Response in project jersey by jersey.

the class ProgrammaticResourceMethodsTest method testTwoBindersSamePath.

@Test
public void testTwoBindersSamePath() throws Exception {
    final ResourceConfig rc = new ResourceConfig();
    final Resource.Builder resourceBuilder = Resource.builder("/");
    final Resource.Builder childTest1Builder = resourceBuilder.addChildResource("test1");
    childTest1Builder.addMethod("GET").handledBy(new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext request) {
            return Response.created(URI.create("/foo")).build();
        }
    });
    Inflector<ContainerRequestContext, Response> inflector1 = new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext request) {
            return Response.accepted().build();
        }
    };
    final Resource.Builder childTest2Builder = resourceBuilder.addChildResource("test2");
    childTest2Builder.addMethod("GET").handledBy(inflector1);
    childTest2Builder.addMethod("HEAD").handledBy(inflector1);
    Inflector<ContainerRequestContext, Response> inflector2 = new Inflector<ContainerRequestContext, Response>() {

        @Override
        public Response apply(ContainerRequestContext request) {
            return Response.status(203).build();
        }
    };
    childTest1Builder.addMethod("OPTIONS").handledBy(inflector2);
    childTest1Builder.addMethod("HEAD").handledBy(inflector2);
    final Resource resource = resourceBuilder.build();
    rc.registerResources(resource);
    final ApplicationHandler application = new ApplicationHandler(rc);
    checkReturnedStatusEquals(201, RequestContextBuilder.from("/test1", "GET").build(), application);
//        checkReturnedStatusEquals(203, Requests.from("/test1", "HEAD").build(), application);
//        checkReturnedStatusEquals(203, Requests.from("/test1", "OPTIONS").build(), application);
//        checkReturnedStatusEquals(202, Requests.from("/test2", "GET").build(), application);
//        checkReturnedStatusEquals(202, Requests.from("/test2", "HEAD").build(), application);
//        checkReturnedStatusEquals(202, Requests.from("/test2", "OPTIONS").build(), application);
}
Also used : Response(javax.ws.rs.core.Response) ContainerRequestContext(javax.ws.rs.container.ContainerRequestContext) Inflector(org.glassfish.jersey.process.Inflector) ApplicationHandler(org.glassfish.jersey.server.ApplicationHandler) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Test(org.junit.Test)

Example 23 with Response

use of javax.ws.rs.core.Response in project jersey by jersey.

the class AbstractTypeTester method _test.

protected <T> void _test(T in, Class resource, MediaType m, boolean verify) {
    WebTarget target = target(resource.getSimpleName());
    Response response = target.request().post(Entity.entity(in, m));
    byte[] inBytes = requestEntity;
    byte[] outBytes = getEntityAsByteArray(response);
    if (verify) {
        _verify(inBytes, outBytes);
    }
}
Also used : Response(javax.ws.rs.core.Response) WebTarget(javax.ws.rs.client.WebTarget)

Example 24 with Response

use of javax.ws.rs.core.Response in project jersey by jersey.

the class RxObservableTest method testInvoker.

private void testInvoker(final RxObservableInvoker rx, final int expectedStatus, final boolean testDedicatedThread) throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<Response> responseRef = new AtomicReference<>();
    final AtomicReference<Throwable> errorRef = new AtomicReference<>();
    rx.get().subscribe(new Subscriber<Response>() {

        @Override
        public void onCompleted() {
            latch.countDown();
        }

        @Override
        public void onError(final Throwable e) {
            errorRef.set(e);
            latch.countDown();
        }

        @Override
        public void onNext(final Response response) {
            responseRef.set(response);
        }
    });
    latch.await();
    if (errorRef.get() == null) {
        testResponse(responseRef.get(), expectedStatus, testDedicatedThread);
    } else {
        throw (Exception) errorRef.get();
    }
}
Also used : Response(javax.ws.rs.core.Response) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) NotFoundException(javax.ws.rs.NotFoundException)

Example 25 with Response

use of javax.ws.rs.core.Response in project jersey by jersey.

the class RxFlowableTest method testInvoker.

private void testInvoker(final RxFlowableInvoker rx, final int expectedStatus, final boolean testDedicatedThread) throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    final AtomicReference<Response> responseRef = new AtomicReference<>();
    final AtomicReference<Throwable> errorRef = new AtomicReference<>();
    rx.get().subscribe(new Subscriber<Response>() {

        @Override
        public void onSubscribe(Subscription s) {
            s.request(Long.MAX_VALUE);
        }

        @Override
        public void onComplete() {
            latch.countDown();
        }

        @Override
        public void onError(final Throwable e) {
            errorRef.set(e);
            latch.countDown();
        }

        @Override
        public void onNext(final Response response) {
            responseRef.set(response);
        }
    });
    latch.await();
    if (errorRef.get() == null) {
        testResponse(responseRef.get(), expectedStatus, testDedicatedThread);
    } else {
        throw (Exception) errorRef.get();
    }
}
Also used : Response(javax.ws.rs.core.Response) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) Subscription(org.reactivestreams.Subscription) NotFoundException(javax.ws.rs.NotFoundException)

Aggregations

Response (javax.ws.rs.core.Response)10205 Test (org.junit.Test)5764 Test (org.testng.annotations.Test)1113 JerseyTest (org.glassfish.jersey.test.JerseyTest)870 Test (org.junit.jupiter.api.Test)701 WebTarget (javax.ws.rs.client.WebTarget)668 Builder (javax.ws.rs.client.Invocation.Builder)638 WebClient (org.apache.cxf.jaxrs.client.WebClient)620 DBUnitTest (org.orcid.test.DBUnitTest)611 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)577 Parameters (org.testng.annotations.Parameters)537 URI (java.net.URI)515 HashMap (java.util.HashMap)508 Path (javax.ws.rs.Path)506 List (java.util.List)465 ArrayList (java.util.ArrayList)419 Produces (javax.ws.rs.Produces)396 IOException (java.io.IOException)393 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)354 GET (javax.ws.rs.GET)348