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);
}
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);
}
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);
}
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 + "'");
}
}
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();
}
Aggregations