use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class MultiPartWebAppTest method testApplicationWadl.
@Test
public void testApplicationWadl() throws Exception {
final WebTarget target = target().path("application.wadl");
final Response response = target.request().get();
assertEquals(200, response.getStatus());
final File tmpFile = response.readEntity(File.class);
final DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
bf.setNamespaceAware(true);
bf.setValidating(false);
if (!SaxHelper.isXdkDocumentBuilderFactory(bf)) {
bf.setXIncludeAware(false);
}
final DocumentBuilder b = bf.newDocumentBuilder();
final Document d = b.parse(tmpFile);
final XPath xp = XPathFactory.newInstance().newXPath();
xp.setNamespaceContext(new SimpleNamespaceResolver("wadl", "http://wadl.dev.java.net/2009/02"));
String val = (String) xp.evaluate("//wadl:resource[@path='part']/wadl:method[@name='POST']/wadl:request/wadl:representation/@mediaType", d, XPathConstants.STRING);
assertEquals("multipart/form-data", val);
}
use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class MultiPartWebAppTest method testFieldInjectedXmlJAXBPart.
@Test
public void testFieldInjectedXmlJAXBPart() {
final WebTarget target = target().path("form-field-injected/xml-jaxb-part");
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("bean").fileName("bean").build(), new Bean("BEAN"), MediaType.APPLICATION_XML_TYPE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("string").fileName("string").build(), "STRING"));
final String s = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), String.class);
assertEquals("STRING:string,BEAN:bean", s);
}
use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class JacksonTest method testEmptyArrayPresent.
@Test
public void testEmptyArrayPresent() {
WebTarget target = target();
String responseMsg = target.path("emptyArrayResource").request(MediaType.APPLICATION_JSON).get(String.class);
assertTrue(responseMsg.replaceAll("[ \t]*", "").contains("[]"));
}
use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class JacksonTest method testJSONPBean.
@Test
@Ignore
public // TODO un-ignore once a JSON reader for "application/javascript" is supported
void testJSONPBean() {
WebTarget target = target();
NonJaxbBean responseMsg = target.path("nonJaxbResource").request("application/javascript").get(NonJaxbBean.class);
assertNotNull(responseMsg);
}
use of javax.ws.rs.client.WebTarget in project jersey by jersey.
the class JacksonTest method testJSONPPresent.
@Test
public void testJSONPPresent() {
WebTarget target = target();
String responseMsg = target.path("nonJaxbResource").request("application/javascript").get(String.class);
assertTrue(responseMsg.startsWith("callback("));
}
Aggregations