Search in sources :

Example 1 with FormDataContentDisposition

use of org.glassfish.jersey.media.multipart.FormDataContentDisposition in project jersey by jersey.

the class FormDataContentDispositionTest method testCreate.

@Test
@Override
public void testCreate() {
    final Date date = new Date();
    FormDataContentDisposition contentDisposition;
    contentDisposition = FormDataContentDisposition.name("testData").fileName("test.file").creationDate(date).modificationDate(date).readDate(date).size(1222).build();
    assertFormDataContentDisposition(contentDisposition, date);
    try {
        final String dateString = HttpDateFormat.getPreferredDateFormat().format(date);
        final String header = contentDispositionType + ";filename=\"test.file\";creation-date=\"" + dateString + "\";modification-date=\"" + dateString + "\";read-date=\"" + dateString + "\";size=1222" + ";name=\"testData\"";
        contentDisposition = new FormDataContentDisposition(contentDisposition.toString());
        assertFormDataContentDisposition(contentDisposition, date);
        contentDisposition = new FormDataContentDisposition(header);
        assertFormDataContentDisposition(contentDisposition, date);
        contentDisposition = new FormDataContentDisposition(HttpHeaderReader.newInstance(header), true);
        assertFormDataContentDisposition(contentDisposition, date);
    } catch (final ParseException ex) {
        fail(ex.getMessage());
    }
    try {
        new FormDataContentDisposition((HttpHeaderReader) null, true);
        fail("NullPointerException was expected to be thrown.");
    } catch (final ParseException exception) {
        fail(exception.getMessage());
    } catch (final NullPointerException exception) {
    //expected
    }
    try {
        new FormDataContentDisposition("form-data;filename=\"test.file\"");
        fail("IllegalArgumentException was expected to be thrown.");
    } catch (final ParseException exception) {
        fail(exception.getMessage());
    } catch (final IllegalArgumentException exception) {
    //expected
    }
    try {
        FormDataContentDisposition.name(null).build();
        fail("IllegalArgumentException was expected to be thrown.");
    } catch (final IllegalArgumentException exception) {
    //expected
    } catch (final Exception exception) {
        fail(exception.getMessage());
    }
}
Also used : FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) ParseException(java.text.ParseException) Date(java.util.Date) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 2 with FormDataContentDisposition

use of org.glassfish.jersey.media.multipart.FormDataContentDisposition in project jersey by jersey.

the class FormDataContentDispositionTest method testToString.

@Test
@Override
public void testToString() {
    final Date date = new Date();
    final FormDataContentDisposition contentDisposition = FormDataContentDisposition.name("testData").fileName("test.file").creationDate(date).modificationDate(date).readDate(date).size(1222).build();
    final String dateString = HttpDateFormat.getPreferredDateFormat().format(date);
    final String header = contentDispositionType + "; filename=\"test.file\"; creation-date=\"" + dateString + "\"; modification-date=\"" + dateString + "\"; read-date=\"" + dateString + "\"; size=1222" + "; name=\"testData\"";
    assertEquals(header, contentDisposition.toString());
}
Also used : FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Date (java.util.Date)2 FormDataContentDisposition (org.glassfish.jersey.media.multipart.FormDataContentDisposition)2 Test (org.junit.Test)2 ParseException (java.text.ParseException)1