use of javax.ws.rs.core.MultivaluedMap in project cxf by apache.
the class FormEncodingProviderTest method testWriteMultipleValues.
@Test
public void testWriteMultipleValues() throws Exception {
MultivaluedMap<String, String> mvMap = new MetadataMap<>();
mvMap.add("a", "a1");
mvMap.add("a", "a2");
FormEncodingProvider<MultivaluedMap<?, ?>> ferp = new FormEncodingProvider<>();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ferp.writeTo(mvMap, MultivaluedMap.class, MultivaluedMap.class, new Annotation[0], MediaType.APPLICATION_FORM_URLENCODED_TYPE, new MetadataMap<String, Object>(), bos);
String result = bos.toString();
assertEquals("Wrong value", "a=a1&a=a2", result);
}
use of javax.ws.rs.core.MultivaluedMap in project cxf by apache.
the class FormEncodingProviderTest method testReadFromMultiples.
@SuppressWarnings("unchecked")
@Test
public void testReadFromMultiples() throws Exception {
InputStream is = getClass().getResourceAsStream("multiValPostBody.txt");
@SuppressWarnings("rawtypes") FormEncodingProvider<MultivaluedMap> ferp = new FormEncodingProvider<>();
MultivaluedMap<String, String> mvMap = ferp.readFrom(MultivaluedMap.class, null, new Annotation[] {}, MediaType.APPLICATION_FORM_URLENCODED_TYPE, null, is);
List<String> vals = mvMap.get("foo");
assertEquals("Wrong size for foo params", 2, vals.size());
assertEquals("Wrong size for foo params", 1, mvMap.get("boo").size());
assertEquals("Wrong entry for foo 0", "bar", vals.get(0));
assertEquals("Wrong entry for foo 1", "bar2", vals.get(1));
assertEquals("Wrong entry for boo", "far", mvMap.getFirst("boo"));
}
use of javax.ws.rs.core.MultivaluedMap in project cxf by apache.
the class FormEncodingProviderTest method testReadFromISO.
@SuppressWarnings("unchecked")
@Test
public void testReadFromISO() throws Exception {
String eWithAcute = "\u00E9";
String helloStringUTF16 = "name=F" + eWithAcute + "lix";
byte[] iso88591bytes = helloStringUTF16.getBytes("ISO-8859-1");
String helloStringISO88591 = new String(iso88591bytes, "ISO-8859-1");
@SuppressWarnings("rawtypes") FormEncodingProvider<MultivaluedMap> ferp = new FormEncodingProvider<>();
MultivaluedMap<String, String> mvMap = ferp.readFrom(MultivaluedMap.class, null, new Annotation[] {}, MediaType.valueOf(MediaType.APPLICATION_FORM_URLENCODED + ";charset=ISO-8859-1"), null, new ByteArrayInputStream(iso88591bytes));
String value = mvMap.getFirst("name");
assertEquals(helloStringISO88591, "name=" + value);
}
use of javax.ws.rs.core.MultivaluedMap in project cxf by apache.
the class FormEncodingProviderTest method testWrite.
@Test
public void testWrite() throws Exception {
MultivaluedMap<String, String> mvMap = new MetadataMap<>();
mvMap.add("a", "a1");
mvMap.add("b", "b1");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
FormEncodingProvider<MultivaluedMap<?, ?>> ferp = new FormEncodingProvider<>();
ferp.writeTo(mvMap, MultivaluedMap.class, MultivaluedMap.class, new Annotation[0], MediaType.APPLICATION_FORM_URLENCODED_TYPE, new MetadataMap<String, Object>(), bos);
String result = bos.toString();
assertEquals("Wrong value", "a=a1&b=b1", result);
}
use of javax.ws.rs.core.MultivaluedMap in project cxf by apache.
the class FormEncodingProviderTest method testEncoded.
@SuppressWarnings("unchecked")
@Test
public void testEncoded() throws Exception {
String values = "foo=1+2&bar=1+3";
@SuppressWarnings("rawtypes") FormEncodingProvider<MultivaluedMap> ferp = new FormEncodingProvider<>();
MultivaluedMap<String, String> mvMap = ferp.readFrom(MultivaluedMap.class, null, new Annotation[] { CustomMap.class.getAnnotations()[0] }, MediaType.APPLICATION_FORM_URLENCODED_TYPE, null, new ByteArrayInputStream(values.getBytes()));
assertEquals("Wrong entry for foo", "1+2", mvMap.getFirst("foo"));
assertEquals("Wrong entry for boo", "1+3", mvMap.getFirst("bar"));
}
Aggregations