use of org.glassfish.jersey.media.multipart.FormDataBodyPart in project jersey by jersey.
the class MultiPartWebAppTest method testPartWithFileName.
@Test
public void testPartWithFileName() {
final WebTarget target = target().path("form/part-file-name");
final FormDataMultiPart mp = new FormDataMultiPart();
final FormDataBodyPart p = new FormDataBodyPart(FormDataContentDisposition.name("part").fileName("file").build(), "CONTENT");
mp.bodyPart(p);
final String s = target.request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), String.class);
assertEquals("CONTENT:file", s);
}
use of org.glassfish.jersey.media.multipart.FormDataBodyPart in project jersey by jersey.
the class FormDataMultiPartReaderWriterTest method testInjectedFileNotCopied.
/**
* JERSEY-2663 reproducer. Make sure that temporary file created by MIMEPull is not copied into new temporary file created
* by Jersey.
*/
@Test
public void testInjectedFileNotCopied(@Mocked final BodyPartEntity entity) throws Exception {
final FormDataMultiPart multipart = new FormDataMultiPart();
final FormDataBodyPart bodypart = new FormDataBodyPart(FormDataContentDisposition.name("file").fileName("file").build(), "CONTENT");
multipart.bodyPart(bodypart);
final Response response = target().path("FileResource").path("InjectedFileNotCopied").request().post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA));
// Make sure that the Mimepull temp file has been moved to specific file.
new Verifications() {
{
entity.moveTo(withInstanceOf(File.class));
times = 1;
}
};
// Make sure that the temp file has been removed.
final String pathname = response.readEntity(String.class);
// Wait a second to make sure the file doesn't exist.
Thread.sleep(1000);
assertThat("Temporary file, " + pathname + ", on the server has not been removed", new File(pathname).exists(), is(false));
}
use of org.glassfish.jersey.media.multipart.FormDataBodyPart in project jersey by jersey.
the class FormDataMultiPartReaderWriterTest method tempFileDeletedAfterExceptionInMethod.
/**
* JERSEY-2846 reproducer. Make sure that temporary file created by MIMEPull deleted after an unsuccessful request.
*/
@Test
public void tempFileDeletedAfterExceptionInMethod() throws Exception {
final FormDataMultiPart multipart = new FormDataMultiPart();
final FormDataBodyPart bodypart = new FormDataBodyPart(FormDataContentDisposition.name("file").fileName("file").build(), "CONTENT");
multipart.bodyPart(bodypart);
final Response response = target().path("FileResource").path("ExceptionInMethod").request().post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA));
// Make sure that the temp file has been removed.
final String pathname = response.readEntity(String.class);
// Wait a second to make sure the file doesn't exist.
Thread.sleep(1000);
assertThat("Temporary file, " + pathname + ", on the server has not been removed", new File(pathname).exists(), is(false));
}
use of org.glassfish.jersey.media.multipart.FormDataBodyPart in project jersey by jersey.
the class FormDataMultiPartReaderWriterTest method tempFileDeletedAfterSuccessfulProcessing.
/**
* JERSEY-2846 reproducer. Make sure that temporary file created by MIMEPull deleted after a successful request.
*/
@Test
public void tempFileDeletedAfterSuccessfulProcessing() throws Exception {
final FormDataMultiPart multipart = new FormDataMultiPart();
final FormDataBodyPart bodypart = new FormDataBodyPart(FormDataContentDisposition.name("file").fileName("file").build(), "CONTENT");
multipart.bodyPart(bodypart);
final Response response = target().path("FileResource").path("SuccessfulMethod").request().post(Entity.entity(multipart, MediaType.MULTIPART_FORM_DATA));
// Make sure that the temp file has been removed.
final String pathname = response.readEntity(String.class);
// Wait a second to make sure the file doesn't exist.
Thread.sleep(1000);
assertThat("Temporary file, " + pathname + ", on the server has not been removed", new File(pathname).exists(), is(false));
}
use of org.glassfish.jersey.media.multipart.FormDataBodyPart in project jersey by jersey.
the class MultipartTest method testSpecificListAsParameter.
/**
* Test that injection of a list (specific type) works.
*/
@Test
public void testSpecificListAsParameter() throws Exception {
final MyObject object = new MyObject("object");
final List<MyObject> list = Arrays.asList(new MyObject("list1"), new MyObject("list2"));
final FormDataMultiPart mp = new FormDataMultiPart();
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("object").fileName("object").build(), object, MediaType.APPLICATION_JSON_TYPE));
mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("list").fileName("list").build(), list, MediaType.APPLICATION_JSON_TYPE));
final Response response = target("listAsParameter").request().post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE));
assertThat(response.readEntity(String.class), is("object_list1_list2"));
}
Aggregations