use of javax.ws.rs.core.MediaType in project jersey by jersey.
the class FormDataMultiPartReaderWriterTest method testDefaultFormDataParamResource.
@Test
public void testDefaultFormDataParamResource() {
final Invocation.Builder request = target().path("DefaultFormDataParamResource").request("text/plain");
final MultiPartBean bean = new MultiPartBean("myname", "myvalue");
final FormDataMultiPart entity = new FormDataMultiPart().field("bean", bean, new MediaType("x-application", "x-format"));
final String response = request.put(Entity.entity(entity, "multipart/form-data"), String.class);
assertEquals("OK", response);
}
use of javax.ws.rs.core.MediaType in project jersey by jersey.
the class MultiPartHeaderModificationTest method testLogMessage.
@Test
public void testLogMessage() {
final WebTarget target = target().path("multipart/ten");
MultiPartBean bean = new MultiPartBean("myname", "myvalue");
MultiPart entity = new MultiPart().bodyPart(bean, new MediaType("x-application", "x-format")).bodyPart("", MediaType.APPLICATION_OCTET_STREAM_TYPE);
final String UNSENT_HEADER_CHANGES = "Unsent header changes";
try {
target.request("text/plain").put(Entity.entity(entity, "multipart/mixed"), String.class);
assertFalse("BadRequestException can not be thrown just in case JERSEY-2341 is not fixed.", messageLogged);
LogRecord logRecord = findLogRecord(UNSENT_HEADER_CHANGES);
assertNull(logRecord);
} catch (BadRequestException brex) {
assertTrue("BadRequestException can be thrown just in case JERSEY-2341 is not fixed.", messageLogged);
LogRecord logRecord = findLogRecord(UNSENT_HEADER_CHANGES);
assertNotNull("Missing LogRecord for message '" + UNSENT_HEADER_CHANGES + "'.", logRecord);
assertThat(logRecord.getMessage(), containsString("MIME-Version"));
assertThat(logRecord.getMessage(), containsString("Content-Type"));
}
}
use of javax.ws.rs.core.MediaType in project jersey by jersey.
the class FileDataBodyPartTest method testCreateFDBP.
@Test
public void testCreateFDBP() throws Exception {
FileDataBodyPart fdbp = (FileDataBodyPart) bodyPart;
assertNull(fdbp.getFormDataContentDisposition());
assertNull(fdbp.getName());
assertNull(fdbp.getValue());
assertTrue(fdbp.isSimple());
String name;
File file = new File("pom.xml");
name = "xml";
fdbp = new FileDataBodyPart(name, file);
MediaType expectedType = MediaType.APPLICATION_XML_TYPE;
checkEntityAttributes(name, fdbp, file, expectedType);
fdbp.setName(name);
checkEntityAttributes(name, fdbp, file, expectedType);
fdbp.setFileEntity(file);
checkEntityAttributes(name, fdbp, file, expectedType);
fdbp = new FileDataBodyPart(name, file, expectedType);
checkEntityAttributes(name, fdbp, file, expectedType);
fdbp.setFileEntity(file, expectedType);
checkEntityAttributes(name, fdbp, file, expectedType);
file = new File("pom.png");
name = "png";
fdbp = new FileDataBodyPart("png", file);
expectedType = DefaultMediaTypePredictor.CommonMediaTypes.PNG.getMediaType();
checkEntityAttributes(name, fdbp, file, expectedType);
file = new File("pom.zip");
fdbp = new FileDataBodyPart(name, file);
expectedType = DefaultMediaTypePredictor.CommonMediaTypes.ZIP.getMediaType();
checkEntityAttributes(name, fdbp, file, expectedType);
file = new File("pom.avi");
fdbp = new FileDataBodyPart(name, file);
expectedType = DefaultMediaTypePredictor.CommonMediaTypes.AVI.getMediaType();
checkEntityAttributes(name, fdbp, file, expectedType);
}
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);
}
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);
}
Aggregations