Search in sources :

Example 76 with GenericType

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

the class XmlMoxyTest method testJAXBListRepresentationMediaType.

@Test
public void testJAXBListRepresentationMediaType() {
    final WebTarget target = target("JAXBListResourceMediaType");
    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+xml"), new GenericType<Collection<JaxbBean>>() {
    });
    assertEquals(a, b);
    b = target.path("type").request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
    }, "application/foo+xml"), 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/foo+xml"), 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/foo+xml"), 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/foo+xml"), 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/foo+xml"), new GenericType<MyArrayList<JaxbBean>>() {
    });
    assertEquals(a, b);
}
Also used : GenericType(javax.ws.rs.core.GenericType) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) 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) Test(org.junit.Test)

Example 77 with GenericType

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

the class EntityTypesTest method testJAXBListRepresentationMediaType.

@Test
public void testJAXBListRepresentationMediaType() {
    final WebTarget target = target("JAXBListResourceMediaType");
    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+xml"), new GenericType<Collection<JaxbBean>>() {
    });
    assertEquals(a, b);
    b = target.path("type").request().post(Entity.entity(new GenericEntity<Collection<JaxbBean>>(a) {
    }, "application/foo+xml"), 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/foo+xml"), 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/foo+xml"), 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/foo+xml"), 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/foo+xml"), 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) Test(org.junit.Test)

Example 78 with GenericType

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

the class JsonMoxyTest method _testListOrArray.

@SuppressWarnings("unchecked")
public void _testListOrArray(final boolean isList, final MediaType mt) {
    final Object in = isList ? getJAXBElementList() : getJAXBElementArray();
    final GenericType gt = isList ? new GenericType<List<JAXBElement<String>>>() {
    } : new GenericType<JAXBElement<String>[]>() {
    };
    final WebTarget target = target(isList ? "JAXBElementListResource" : "JAXBElementArrayResource");
    final Object out = target.request(mt).post(Entity.entity(new GenericEntity(in, gt.getType()), mt), gt);
    final List<JAXBElement<String>> inList = isList ? ((List<JAXBElement<String>>) in) : Arrays.asList((JAXBElement<String>[]) in);
    final List<JAXBElement<String>> outList = isList ? ((List<JAXBElement<String>>) out) : Arrays.asList((JAXBElement<String>[]) out);
    assertEquals("Lengths differ", inList.size(), outList.size());
    for (int i = 0; i < inList.size(); i++) {
        assertEquals("Names of elements at index " + i + " differ", inList.get(i).getName(), outList.get(i).getName());
        assertEquals("Values of elements at index " + i + " differ", inList.get(i).getValue(), outList.get(i).getValue());
    }
}
Also used : GenericType(javax.ws.rs.core.GenericType) GenericEntity(javax.ws.rs.core.GenericEntity) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget) JAXBElement(javax.xml.bind.JAXBElement)

Example 79 with GenericType

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

the class JsonMoxyTest method testJAXBListRepresentationJSONArrayList.

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

Example 80 with GenericType

use of javax.ws.rs.core.GenericType in project opennms by OpenNMS.

the class RestClient method getEvents.

public List<OnmsEvent> getEvents() {
    GenericType<List<OnmsEvent>> events = new GenericType<List<OnmsEvent>>() {
    };
    final WebTarget target = getTarget().path("events");
    return getBuilder(target).get(events);
}
Also used : GenericType(javax.ws.rs.core.GenericType) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) List(java.util.List) WebTarget(javax.ws.rs.client.WebTarget)

Aggregations

GenericType (javax.ws.rs.core.GenericType)126 List (java.util.List)64 WebTarget (javax.ws.rs.client.WebTarget)64 Response (javax.ws.rs.core.Response)60 Test (org.junit.Test)51 Client (javax.ws.rs.client.Client)24 ArrayList (java.util.ArrayList)17 Message (com.remswork.project.alice.model.support.Message)16 WebClient (org.apache.cxf.jaxrs.client.WebClient)16 GenericEntity (javax.ws.rs.core.GenericEntity)15 MediaType (javax.ws.rs.core.MediaType)15 Collection (java.util.Collection)14 Set (java.util.Set)14 LinkedList (java.util.LinkedList)12 HashSet (java.util.HashSet)11 Test (org.junit.jupiter.api.Test)11 JerseyTest (org.glassfish.jersey.test.JerseyTest)10 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)9 Collections (java.util.Collections)9 Entity (javax.ws.rs.client.Entity)9