use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.
the class MultiPartReaderWriterTest method testFourBiz.
@Test
public void testFourBiz() {
final WebTarget target = target().path("multipart/four");
final MultiPartBean bean = new MultiPartBean("myname", "myvalue");
final MultiPart entity = new MultiPart().bodyPart("This is the first segment", new MediaType("text", "plain")).bodyPart(bean, new MediaType("x-application", "x-format"));
final String response = target.request("text/plain").header("Content-Type", "multipart/mixed").put(Entity.entity(entity, "multipart/mixed"), String.class);
if (!response.startsWith("SUCCESS:")) {
fail("Response is '" + response + "'");
}
}
use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.
the class MultiPartReaderWriterTest method testThirteen.
/**
* Call clean up explicitly.
*/
@Test
public void testThirteen() {
final WebTarget target = target().path("multipart/thirteen");
final MultiPart entity = new MultiPart().bodyPart("CONTENT", MediaType.TEXT_PLAIN_TYPE);
final String response = target.request("multipart/mixed").put(Entity.entity(entity, "multipart/mixed"), String.class);
assertEquals("cleanup", response);
}
use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.
the class MultiPartReaderWriterTest method testETag.
@Test
public void testETag() {
final WebTarget target = target().path("multipart/etag");
try {
final MultiPart result = target.request("multipart/mixed").get(MultiPart.class);
checkMediaType(new MediaType("multipart", "mixed"), result.getMediaType());
assertEquals(1, result.getBodyParts().size());
final BodyPart part = result.getBodyParts().get(0);
checkMediaType(new MediaType("text", "plain"), part.getMediaType());
checkEntity("This is the only segment", (BodyPartEntity) part.getEntity());
assertEquals("\"value\"", part.getHeaders().getFirst("ETag"));
result.getParameterizedHeaders();
result.cleanup();
} catch (final IOException | ParseException e) {
e.printStackTrace(System.out);
fail("Caught exception: " + e);
}
}
use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.
the class MultiPartReaderWriterTest method testThree.
@Test
public void testThree() {
final WebTarget target = target().path("multipart/three");
try {
final MultiPart result = target.request("multipart/mixed").get(MultiPart.class);
checkMediaType(new MediaType("multipart", "mixed"), result.getMediaType());
assertEquals(2, result.getBodyParts().size());
final BodyPart part1 = result.getBodyParts().get(0);
checkMediaType(new MediaType("text", "plain"), part1.getMediaType());
checkEntity("This is the first segment", (BodyPartEntity) part1.getEntity());
final BodyPart part2 = result.getBodyParts().get(1);
checkMediaType(new MediaType("x-application", "x-format"), part2.getMediaType());
final MultiPartBean entity = part2.getEntityAs(MultiPartBean.class);
assertEquals("myname", entity.getName());
assertEquals("myvalue", entity.getValue());
result.getParameterizedHeaders();
result.cleanup();
} catch (final IOException | ParseException e) {
e.printStackTrace(System.out);
fail("Caught exception: " + e);
}
}
use of org.glassfish.jersey.media.multipart.MultiPart in project jersey by jersey.
the class MultiPartReaderWriterTest method testTwelve.
/**
* Echo back the multipart that was sent.
*/
@Test
public void testTwelve() throws Exception {
final WebTarget target = target().path("multipart/twelve");
final MultiPart entity = new MultiPart().bodyPart("CONTENT", MediaType.TEXT_PLAIN_TYPE);
final MultiPart response = target.request("multipart/mixed").put(Entity.entity(entity, "multipart/mixed"), MultiPart.class);
final String actual = response.getBodyParts().get(0).getEntityAs(String.class);
assertEquals("CONTENT", actual);
response.cleanup();
}
Aggregations