Search in sources :

Example 21 with FormDataMultiPart

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 + "'");
    }
}
Also used : Invocation(javax.ws.rs.client.Invocation) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) MediaType(javax.ws.rs.core.MediaType) Test(org.junit.Test)

Example 22 with FormDataMultiPart

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);
}
Also used : Invocation(javax.ws.rs.client.Invocation) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) Test(org.junit.Test)

Example 23 with FormDataMultiPart

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));
}
Also used : Response(javax.ws.rs.core.Response) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) Verifications(mockit.Verifications) File(java.io.File) Test(org.junit.Test)

Example 24 with FormDataMultiPart

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());
    }
}
Also used : FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) Test(org.junit.Test)

Example 25 with FormDataMultiPart

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 + "'");
    }
}
Also used : Invocation(javax.ws.rs.client.Invocation) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) MediaType(javax.ws.rs.core.MediaType) Test(org.junit.Test)

Aggregations

FormDataMultiPart (org.glassfish.jersey.media.multipart.FormDataMultiPart)32 Test (org.junit.Test)25 FormDataBodyPart (org.glassfish.jersey.media.multipart.FormDataBodyPart)16 Response (javax.ws.rs.core.Response)10 Invocation (javax.ws.rs.client.Invocation)9 WebTarget (javax.ws.rs.client.WebTarget)7 JerseyTest (org.glassfish.jersey.test.JerseyTest)7 MediaType (javax.ws.rs.core.MediaType)6 File (java.io.File)5 MultiPart (org.glassfish.jersey.media.multipart.MultiPart)5 Client (javax.ws.rs.client.Client)3 PayaraClientException (fish.payara.arquillian.container.payara.clientutils.PayaraClientException)2 JerseyClientBuilder (io.dropwizard.client.JerseyClientBuilder)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 List (java.util.List)2 DeploymentException (org.jboss.arquillian.container.spi.client.container.DeploymentException)2 ErrorMessage (io.dropwizard.jersey.errors.ErrorMessage)1 FileOutputStream (java.io.FileOutputStream)1 Map (java.util.Map)1