Search in sources :

Example 6 with GenericType

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

the class EntityTypesTest method testJAXBListRepresentationFastInfoset.

/**
     * TODO, the unmarshalling fails.
     */
@Test
@Ignore("TODO: unignore once fi support implemented (JERSEY-1190)")
public // TODO: unignore once fi support implemented (JERSEY-1190)
void testJAXBListRepresentationFastInfoset() {
    final WebTarget target = target("JAXBListResourceFastInfoset");
    Collection<JaxbBean> a = target.request().get(new GenericType<Collection<JaxbBean>>() {
    });
    Collection<JaxbBean> b = target.request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
    }, "application/fastinfoset"), new GenericType<Collection<JaxbBean>>() {
    });
    assertEquals(a, b);
    b = target.path("type").request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
    }, "application/fastinfoset"), new GenericType<Collection<JaxbBean>>() {
    });
    assertEquals(a, b);
    a = new LinkedList<>(a);
    b = target.path("queue").request().post(Entity.entity(new GenericEntity<Queue<JaxbBean>>((Queue<JaxbBean>) a) {
    }, "application/fastinfoset"), new GenericType<Queue<JaxbBean>>() {
    });
    assertEquals(a, b);
    a = new HashSet<>(a);
    b = target.path("set").request().post(Entity.entity(new GenericEntity<Set<JaxbBean>>((Set<JaxbBean>) a) {
    }, "application/fastinfoset"), 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);
    final Stack<JaxbBean> s = new Stack<>();
    s.addAll(a);
    b = target.path("stack").request().post(Entity.entity(new GenericEntity<Stack<JaxbBean>>(s) {
    }, "application/fastinfoset"), new GenericType<Stack<JaxbBean>>() {
    });
    assertEquals(s, b);
    a = new MyArrayList<>(a);
    b = target.path("custom").request().post(Entity.entity(new GenericEntity<MyArrayList<JaxbBean>>((MyArrayList<JaxbBean>) a) {
    }, "application/fastinfoset"), new GenericType<MyArrayList<JaxbBean>>() {
    });
    assertEquals(a, b);
}
Also used : GenericType(javax.ws.rs.core.GenericType) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Comparator(java.util.Comparator) Stack(java.util.Stack) GenericEntity(javax.ws.rs.core.GenericEntity) TreeSet(java.util.TreeSet) Collection(java.util.Collection) WebTarget(javax.ws.rs.client.WebTarget) Queue(java.util.Queue) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with GenericType

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

the class EntityTypesTest method testJAXBListRepresentationJSONMediaType.

@Test
public void testJAXBListRepresentationJSONMediaType() throws Exception {
    final WebTarget target = target("JAXBListResourceJSONMediaType");
    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/foo+json"), new GenericType<Collection<JaxbBean>>() {
    });
    assertEquals(a, b);
    b = target.path("type").request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
    }, "application/foo+json"), new GenericType<Collection<JaxbBean>>() {
    });
    assertEquals(a, b);
// TODO: would be nice to produce/consume a real JSON array like following
// instead of what we have now:
//        JSONArray a = r.get(JSONArray.class);
//        JSONArray b = new JSONArray().
//                put(new JSONObject().put("value", "one")).
//                put(new JSONObject().put("value", "two")).
//                put(new JSONObject().put("value", "three"));
//        assertEquals(a.toString(), b.toString());
//        JSONArray c = r.post(JSONArray.class, b);
//        assertEquals(a.toString(), c.toString());
}
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 8 with GenericType

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

the class JsonMoxyTest method testJAXBListRepresentationJSONMediaType.

@Test
public void testJAXBListRepresentationJSONMediaType() throws Exception {
    final WebTarget target = target("JAXBListResourceJSONMediaType");
    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/foo+json"), new GenericType<Collection<JaxbBean>>() {
    });
    assertEquals(a, b);
    b = target.path("type").request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
    }, "application/foo+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 9 with GenericType

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

the class JsonMoxyTest method testJAXBElementBeanJSONRepresentation.

@Test
public void testJAXBElementBeanJSONRepresentation() {
    final WebTarget target = target("JAXBElementBeanJSONResource");
    final GenericType<JAXBElement<String>> genericType = new GenericType<JAXBElement<String>>() {
    };
    final GenericEntity<JAXBElement<String>> jaxbElementGenericEntity = new GenericEntity<>(new JAXBElement<>(new QName("test"), String.class, "CONTENT"), genericType.getType());
    final Response rib = target.request().post(Entity.entity(jaxbElementGenericEntity, "application/json"));
    // TODO: the following would not be needed if i knew how to workaround JAXBElement<String>.class literal
    final byte[] inBytes = getRequestEntity();
    final byte[] outBytes = getEntityAsByteArray(rib);
    assertEquals(new String(outBytes), inBytes.length, outBytes.length);
    for (int i = 0; i < inBytes.length; i++) {
        if (inBytes[i] != outBytes[i]) {
            assertEquals("Index: " + i, inBytes[i], outBytes[i]);
        }
    }
}
Also used : Response(javax.ws.rs.core.Response) GenericType(javax.ws.rs.core.GenericType) GenericEntity(javax.ws.rs.core.GenericEntity) QName(javax.xml.namespace.QName) WebTarget(javax.ws.rs.client.WebTarget) JAXBElement(javax.xml.bind.JAXBElement) Test(org.junit.Test)

Example 10 with GenericType

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

the class JsonMoxyTest method testJAXBListRepresentationJSONLinkedList.

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

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