Search in sources :

Example 61 with MediaType

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

the class StreamDataBodyPartTest method testCreateStreamEntityNameStreamFilename.

@Test
public void testCreateStreamEntityNameStreamFilename() {
    String expectedName = "foo";
    String expectedFilename = "bar.txt";
    MediaType expectedMediaType = StreamDataBodyPart.getDefaultMediaType();
    cut = new StreamDataBodyPart(expectedName, new ByteArrayInputStream(new byte[] {}), expectedFilename);
    boolean actualIsSimpleBodyPart = cut.isSimple();
    String actualName = cut.getName();
    String actualFilename = cut.getFilename();
    // MediaType is to be the default one.
    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 62 with MediaType

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

the class StreamDataBodyPartTest method testCreateStreamEntityNullMediaType.

@Test
public void testCreateStreamEntityNullMediaType() {
    MediaType expectedMediaType = StreamDataBodyPart.getDefaultMediaType();
    // MediaType is nullable - it takes the default value in such situation.
    cut = new StreamDataBodyPart("foo", new ByteArrayInputStream(new byte[] {}), "bar.txt", null);
    MediaType actualMediaType = cut.getMediaType();
    assertEquals(expectedMediaType, actualMediaType);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) MediaType(javax.ws.rs.core.MediaType) Test(org.junit.Test) BodyPartTest(org.glassfish.jersey.media.multipart.BodyPartTest)

Example 63 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 64 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 65 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)

Aggregations

MediaType (javax.ws.rs.core.MediaType)477 Test (org.junit.Test)184 Path (javax.ws.rs.Path)44 Produces (javax.ws.rs.Produces)44 ByteArrayInputStream (java.io.ByteArrayInputStream)42 WebApplicationException (javax.ws.rs.WebApplicationException)41 IOException (java.io.IOException)40 Response (javax.ws.rs.core.Response)40 InputStream (java.io.InputStream)38 ArrayList (java.util.ArrayList)31 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)31 Type (java.lang.reflect.Type)30 Consumes (javax.ws.rs.Consumes)27 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)27 GET (javax.ws.rs.GET)25 OutputStream (java.io.OutputStream)23 Annotation (java.lang.annotation.Annotation)23 HashSet (java.util.HashSet)22 Locale (java.util.Locale)22 HashMap (java.util.HashMap)21