Search in sources :

Example 11 with GenericType

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

the class JsonMoxyTest method testJAXBListRepresentationJSONCollection.

@Test
public void testJAXBListRepresentationJSONCollection() throws Exception {
    final WebTarget target = target("JAXBListResourceJSON");
    final Collection<JaxbBean> a = target.request().get(new GenericType<Collection<JaxbBean>>() {
    });
    Collection<JaxbBean> b = target.request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
    }, "application/json"), new GenericType<Collection<JaxbBean>>() {
    });
    assertEquals(a, b);
    b = target.path("type").request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
    }, "application/json"), new GenericType<Collection<JaxbBean>>() {
    });
    assertEquals(a, b);
}
Also used : GenericType(javax.ws.rs.core.GenericType) GenericEntity(javax.ws.rs.core.GenericEntity) Collection(java.util.Collection) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Example 12 with GenericType

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

the class JsonMoxyTest method testJAXBListRepresentationJSONStack.

@Test
public void testJAXBListRepresentationJSONStack() throws Exception {
    final WebTarget target = target("JAXBListResourceJSON");
    final Collection<JaxbBean> a = target.request().get(new GenericType<Collection<JaxbBean>>() {
    });
    final Collection<JaxbBean> b;
    final Stack<JaxbBean> s = new Stack<>();
    s.addAll(a);
    b = target.path("stack").request().post(Entity.entity(new GenericEntity<Stack<JaxbBean>>(s) {
    }, "application/json"), new GenericType<Stack<JaxbBean>>() {
    });
    assertEquals(s, b);
}
Also used : GenericType(javax.ws.rs.core.GenericType) Collection(java.util.Collection) WebTarget(javax.ws.rs.client.WebTarget) Stack(java.util.Stack) Test(org.junit.Test)

Example 13 with GenericType

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

the class JsonMoxyTest method testJAXBListRepresentationJSONSet.

@Test
public void testJAXBListRepresentationJSONSet() throws Exception {
    final WebTarget target = target("JAXBListResourceJSON");
    Collection<JaxbBean> a = target.request().get(new GenericType<Collection<JaxbBean>>() {
    });
    final Collection<JaxbBean> b;
    a = new HashSet<>(a);
    b = target.path("set").request().post(Entity.entity(new GenericEntity<Set<JaxbBean>>((Set<JaxbBean>) a) {
    }, "application/json"), new GenericType<Set<JaxbBean>>() {
    });
    final Comparator<JaxbBean> c = new Comparator<JaxbBean>() {

        @Override
        public int compare(final JaxbBean t, final JaxbBean t1) {
            return t.value.compareTo(t1.value);
        }
    };
    final TreeSet<JaxbBean> t1 = new TreeSet<>(c);
    final TreeSet<JaxbBean> t2 = new TreeSet<>(c);
    t1.addAll(a);
    t2.addAll(b);
    assertEquals(t1, t2);
}
Also used : GenericType(javax.ws.rs.core.GenericType) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) Comparator(java.util.Comparator) TreeSet(java.util.TreeSet) Collection(java.util.Collection) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test)

Example 14 with GenericType

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

the class GenericResponseTest method testAsyncPost.

@Test
public void testAsyncPost() throws ExecutionException, InterruptedException {
    GenericType<Response> generic = new GenericType<Response>(Response.class);
    Entity entity = Entity.entity("entity", MediaType.WILDCARD_TYPE);
    WebTarget target = target("resource");
    final AsyncInvoker async = target.request().async();
    Response response = async.post(entity, generic).get();
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("entity", response.readEntity(String.class));
}
Also used : Response(javax.ws.rs.core.Response) Entity(javax.ws.rs.client.Entity) GenericType(javax.ws.rs.core.GenericType) AsyncInvoker(javax.ws.rs.client.AsyncInvoker) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 15 with GenericType

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

the class GenericResponseTest method testAsyncGet.

@Test
public void testAsyncGet() throws ExecutionException, InterruptedException {
    GenericType<Response> generic = new GenericType<Response>(Response.class);
    WebTarget target = target("resource");
    final AsyncInvoker async = target.request().async();
    Response response = async.get(generic).get();
    Assert.assertEquals(200, response.getStatus());
    Assert.assertEquals("get", response.readEntity(String.class));
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) AsyncInvoker(javax.ws.rs.client.AsyncInvoker) WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Aggregations

GenericType (javax.ws.rs.core.GenericType)52 WebTarget (javax.ws.rs.client.WebTarget)38 Test (org.junit.Test)26 List (java.util.List)17 GenericEntity (javax.ws.rs.core.GenericEntity)13 Response (javax.ws.rs.core.Response)13 Collection (java.util.Collection)12 JerseyTest (org.glassfish.jersey.test.JerseyTest)9 ArrayList (java.util.ArrayList)8 Queue (java.util.Queue)8 GET (javax.ws.rs.GET)7 Produces (javax.ws.rs.Produces)7 MediaType (javax.ws.rs.core.MediaType)7 Type (java.lang.reflect.Type)6 HashSet (java.util.HashSet)6 Path (javax.ws.rs.Path)6 Comparator (java.util.Comparator)5 Set (java.util.Set)5 Stack (java.util.Stack)5 TreeSet (java.util.TreeSet)5