use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class JAXRSUtilsTest method testCookieParameters.
@Test
public void testCookieParameters() throws Exception {
Class<?>[] argType = { String.class, Set.class, String.class, Set.class };
Method m = Customer.class.getMethod("testCookieParam", argType);
Message messageImpl = createMessage();
MultivaluedMap<String, String> headers = new MetadataMap<String, String>();
headers.add("Cookie", "c1=c1Value");
messageImpl.put(Message.PROTOCOL_HEADERS, headers);
List<Object> params = JAXRSUtils.processParameters(new OperationResourceInfo(m, new ClassResourceInfo(Customer.class)), null, messageImpl);
assertEquals(params.size(), 4);
assertEquals("c1Value", params.get(0));
Set<Cookie> set1 = CastUtils.cast((Set<?>) params.get(1));
assertEquals(1, set1.size());
assertTrue(set1.contains(Cookie.valueOf("c1=c1Value")));
assertEquals("c2Value", params.get(2));
Set<Cookie> set2 = CastUtils.cast((Set<?>) params.get(3));
assertTrue(set2.contains((Object) "c2Value"));
assertEquals(1, set2.size());
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class BinaryDataProviderTest method testReadFrom.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testReadFrom() throws Exception {
MessageBodyReader p = new BinaryDataProvider();
byte[] bytes = (byte[]) p.readFrom(byte[].class, byte[].class, new Annotation[] {}, MediaType.APPLICATION_OCTET_STREAM_TYPE, new MetadataMap<String, Object>(), new ByteArrayInputStream("hi".getBytes()));
assertTrue(Arrays.equals(new String("hi").getBytes(), bytes));
InputStream is = (InputStream) p.readFrom(InputStream.class, InputStream.class, new Annotation[] {}, MediaType.APPLICATION_OCTET_STREAM_TYPE, new MetadataMap<String, Object>(), new ByteArrayInputStream("hi".getBytes()));
bytes = IOUtils.readBytesFromStream(is);
assertTrue(Arrays.equals(new String("hi").getBytes(), bytes));
Reader r = (Reader) p.readFrom(Reader.class, Reader.class, new Annotation[] {}, MediaType.APPLICATION_OCTET_STREAM_TYPE, new MetadataMap<String, Object>(), new ByteArrayInputStream("hi".getBytes()));
assertEquals(IOUtils.toString(r), "hi");
StreamingOutput so = (StreamingOutput) p.readFrom(StreamingOutput.class, StreamingOutput.class, new Annotation[] {}, MediaType.APPLICATION_OCTET_STREAM_TYPE, new MetadataMap<String, Object>(), new ByteArrayInputStream("hi".getBytes()));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
so.write(baos);
bytes = baos.toByteArray();
assertTrue(Arrays.equals(new String("hi").getBytes(), bytes));
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class DataSourceProviderTest method testWriteDataSourceWithDiffCT.
@Test
public void testWriteDataSourceWithDiffCT() throws Exception {
DataSourceProvider<DataSource> p = new DataSourceProvider<DataSource>();
p.setUseDataSourceContentType(true);
DataSource ds = new InputStreamDataSource(new ByteArrayInputStream("image".getBytes()), "image/png");
MultivaluedMap<String, Object> outHeaders = new MetadataMap<String, Object>();
try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
p.writeTo(ds, DataSource.class, DataSource.class, new Annotation[] {}, MediaType.valueOf("image/jpeg"), outHeaders, os);
assertEquals("image", os.toString());
}
assertEquals("image/png", outHeaders.getFirst("Content-Type"));
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class FormEncodingProviderTest method testWriteMultipleValues2.
@Test
public void testWriteMultipleValues2() throws Exception {
MultivaluedMap<String, String> mvMap = new MetadataMap<String, String>();
mvMap.add("a", "a1");
mvMap.add("a", "a2");
mvMap.add("b", "b1");
FormEncodingProvider<MultivaluedMap<?, ?>> ferp = new FormEncodingProvider<MultivaluedMap<?, ?>>();
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&b=b1", result);
}
use of org.apache.cxf.jaxrs.impl.MetadataMap in project cxf by apache.
the class FormEncodingProviderTest method testWrite.
@Test
public void testWrite() throws Exception {
MultivaluedMap<String, String> mvMap = new MetadataMap<String, String>();
mvMap.add("a", "a1");
mvMap.add("b", "b1");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
FormEncodingProvider<MultivaluedMap<?, ?>> ferp = new FormEncodingProvider<MultivaluedMap<?, ?>>();
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);
}
Aggregations