Search in sources :

Example 26 with MediaType

use of javax.ws.rs.core.MediaType in project jersey by jersey.

the class StreamDataBodyPartTest method testCreateStreamEntity.

@Test
public void testCreateStreamEntity() {
    String expectedName = "foo";
    String expectedFilename = "bar.txt";
    MediaType expectedMediaType = MediaType.TEXT_HTML_TYPE;
    cut = new StreamDataBodyPart(expectedName, new ByteArrayInputStream(new byte[] {}), expectedFilename, expectedMediaType);
    // All parameters must be set as the user requested. No defaults.
    boolean actualIsSimpleBodyPart = cut.isSimple();
    String actualName = cut.getName();
    String actualFilename = cut.getFilename();
    MediaType actualMediaType = cut.getMediaType();
    assertEquals(expectedName, actualName);
    assertEquals(expectedMediaType, actualMediaType);
    assertEquals(expectedFilename, actualFilename);
    assertFalse(actualIsSimpleBodyPart);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MediaType(javax.ws.rs.core.MediaType) Test(org.junit.Test) BodyPartTest(org.glassfish.jersey.media.multipart.BodyPartTest)

Example 27 with MediaType

use of javax.ws.rs.core.MediaType in project jersey by jersey.

the class StreamDataBodyPartTest method testStreamEntityStreamMediaType.

///////////////////////////////////////////////////////////////////////////
// Stream entity setter tests
///////////////////////////////////////////////////////////////////////////
@Test
public void testStreamEntityStreamMediaType() {
    MediaType expectedMediaType = MediaType.APPLICATION_SVG_XML_TYPE;
    InputStream expectedInputStream = new ByteArrayInputStream(new byte[] { 0x002, 0x003 });
    assertSetEntityStream(expectedMediaType, expectedInputStream);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MediaType(javax.ws.rs.core.MediaType) Test(org.junit.Test) BodyPartTest(org.glassfish.jersey.media.multipart.BodyPartTest)

Example 28 with MediaType

use of javax.ws.rs.core.MediaType in project jersey by jersey.

the class StreamDataBodyPartTest method testCreateStreamEntityNameStream.

///////////////////////////////////////////////////////////////////////////
// Constructor tests
///////////////////////////////////////////////////////////////////////////
@Test
public void testCreateStreamEntityNameStream() {
    String expectedName = "foo";
    MediaType expectedMediaType = StreamDataBodyPart.getDefaultMediaType();
    cut = new StreamDataBodyPart(expectedName, new ByteArrayInputStream(new byte[] {}));
    boolean actualIsSimpleBodyPart = cut.isSimple();
    String actualName = cut.getName();
    // Filename and mediaType are to be the default ones.
    String actualFilename = cut.getFilename();
    MediaType actualMediaType = cut.getMediaType();
    assertEquals(expectedName, actualName);
    assertEquals(expectedMediaType, actualMediaType);
    assertNull(actualFilename);
    assertFalse(actualIsSimpleBodyPart);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MediaType(javax.ws.rs.core.MediaType) Test(org.junit.Test) BodyPartTest(org.glassfish.jersey.media.multipart.BodyPartTest)

Example 29 with MediaType

use of javax.ws.rs.core.MediaType in project jersey by jersey.

the class FormDataMultiPartBufferTest method testConsumesFormDataResource.

@Test
public void testConsumesFormDataResource() {
    MultiPartBean bean = new MultiPartBean("myname", "myvalue");
    FormDataMultiPart entity = new FormDataMultiPart().field("foo", "bar").field("baz", "bop").field("bean", bean, new MediaType("x-application", "x-format"));
    String response = target().path("ConsumesFormDataResource").request("text/plain").put(Entity.entity(entity, "multipart/form-data"), String.class);
    if (!response.startsWith("SUCCESS:")) {
        fail("Response is '" + response + "'");
    }
}
Also used : FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) MediaType(javax.ws.rs.core.MediaType) Test(org.junit.Test)

Example 30 with MediaType

use of javax.ws.rs.core.MediaType in project jersey by jersey.

the class FormDataMultiPartReaderWriterTest method testProducesFormDataResource.

@Test
public void testProducesFormDataResource() throws Exception {
    final Invocation.Builder request = target().path("ProducesFormDataResource").request("multipart/form-data");
    final FormDataMultiPart result = request.get(FormDataMultiPart.class);
    checkMediaType(new MediaType("multipart", "form-data"), result.getMediaType());
    assertEquals(3, result.getFields().size());
    assertNotNull(result.getField("foo"));
    assertEquals("bar", result.getField("foo").getValue());
    assertNotNull(result.getField("baz"));
    assertEquals("bop", result.getField("baz").getValue());
    assertNotNull(result.getField("bean"));
    final MultiPartBean bean = result.getField("bean").getValueAs(MultiPartBean.class);
    assertNotNull(bean);
    assertEquals("myname", bean.getName());
    assertEquals("myvalue", bean.getValue());
    result.cleanup();
}
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

MediaType (javax.ws.rs.core.MediaType)228 Test (org.junit.Test)112 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)29 Path (javax.ws.rs.Path)25 Produces (javax.ws.rs.Produces)24 WebApplicationException (javax.ws.rs.WebApplicationException)24 ByteArrayInputStream (java.io.ByteArrayInputStream)20 HashSet (java.util.HashSet)20 MediaTypeUtil.getAcceptableMediaType (org.apache.stanbol.commons.web.base.utils.MediaTypeUtil.getAcceptableMediaType)20 IOException (java.io.IOException)18 AcceptableMediaType (org.glassfish.jersey.message.internal.AcceptableMediaType)18 InputStream (java.io.InputStream)16 GET (javax.ws.rs.GET)16 ContainerResponse (org.glassfish.jersey.server.ContainerResponse)16 EntityhubLDPath (org.apache.stanbol.entityhub.ldpath.EntityhubLDPath)15 ArrayList (java.util.ArrayList)14 Consumes (javax.ws.rs.Consumes)14 HashMap (java.util.HashMap)13 Viewable (org.apache.stanbol.commons.web.viewable.Viewable)12 MultiPart (org.glassfish.jersey.media.multipart.MultiPart)12