use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project jersey by jersey.
the class FormDataMultiPartReaderWriterTest method testConsumesFormDataResource.
@Test
public void testConsumesFormDataResource() {
final Invocation.Builder request = target().path("ConsumesFormDataResource").request("text/plain");
final MultiPartBean bean = new MultiPartBean("myname", "myvalue");
final FormDataMultiPart entity = new FormDataMultiPart().field("foo", "bar").field("baz", "bop").field("bean", bean, new MediaType("x-application", "x-format"));
final String response = request.put(Entity.entity(entity, "multipart/form-data"), String.class);
if (!response.startsWith("SUCCESS:")) {
fail("Response is '" + response + "'");
}
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project jersey by jersey.
the class FormDataMultiPartReaderWriterTest method testFormDataCollectionTypesResource.
@Test
public void testFormDataCollectionTypesResource() {
final Invocation.Builder request = target().path("FormDataCollectionTypesResource").request("text/plain");
final FormDataMultiPart entity = new FormDataMultiPart().field("foo", "bar").field("foo", "bar2").field("baz", "bop").field("baz", "bop2");
final String response = request.put(Entity.entity(entity, "multipart/form-data"), String.class);
assertEquals("OK", response);
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart 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.FormDataMultiPart in project jersey by jersey.
the class FormDataMultiPartReaderWriterTest method testProducesFormDataCharsetResource.
@Test
public void testProducesFormDataCharsetResource() throws Exception {
final String c = "© CONTENT ÿ ∀ ⋿";
for (final String charset : Arrays.asList("US-ASCII", "ISO-8859-1", "UTF-8", "UTF-16BE", "UTF-16LE", "UTF-16")) {
final FormDataMultiPart p = target().path("ProducesFormDataCharsetResource").queryParam("charset", charset).request("multipart/form-data").get(FormDataMultiPart.class);
final String expected = new String(c.getBytes(charset), charset);
assertEquals(expected, p.getField("foo").getValue());
}
}
use of org.glassfish.jersey.media.multipart.FormDataMultiPart in project jersey by jersey.
the class FormDataMultiPartReaderWriterTest method testConsumesFormDataParamResource.
@Test
public void testConsumesFormDataParamResource() {
final Invocation.Builder request = target().path("ConsumesFormDataParamResource").request("text/plain");
final MultiPartBean bean = new MultiPartBean("myname", "myvalue");
final FormDataMultiPart entity = new FormDataMultiPart().field("foo", "bar").field("baz", "bop").field("bean", bean, new MediaType("x-application", "x-format"));
final String response = request.put(Entity.entity(entity, "multipart/form-data"), String.class);
if (!response.startsWith("SUCCESS:")) {
fail("Response is '" + response + "'");
}
}
Aggregations