Search in sources :

Example 16 with BodyPart

use of jakarta.mail.BodyPart in project resteasy by resteasy.

the class HeaderFlushedOutputStreamTest method testGet.

/**
 * @tpTestDetails Test get method
 * @tpSince RESTEasy 3.0.16
 */
@Test
public void testGet() throws Exception {
    Response response = client.target(TEST_URI).request().get();
    Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    BufferedInputStream in = new BufferedInputStream(response.readEntity(InputStream.class));
    String contentType = response.getHeaderString("content-type");
    ByteArrayDataSource ds = new ByteArrayDataSource(in, contentType);
    MimeMultipart mimeMultipart = new MimeMultipart(ds);
    Assert.assertEquals("Wrong count of parts of response", mimeMultipart.getCount(), 1);
    BodyPart part = mimeMultipart.getBodyPart(0);
    InputStream is = part.getInputStream();
    Assert.assertEquals("Wrong count of parts of response", 3, part.getSize());
    char[] output = new char[3];
    output[0] = (char) is.read();
    output[1] = (char) is.read();
    output[2] = (char) is.read();
    String str = new String(output);
    Assert.assertEquals("Wrong content of first part of response", "bla", str);
}
Also used : Response(jakarta.ws.rs.core.Response) HttpServletResponse(jakarta.servlet.http.HttpServletResponse) BodyPart(jakarta.mail.BodyPart) BufferedInputStream(java.io.BufferedInputStream) MimeMultipart(jakarta.mail.internet.MimeMultipart) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ByteArrayDataSource(jakarta.mail.util.ByteArrayDataSource) Test(org.junit.Test)

Aggregations

BodyPart (jakarta.mail.BodyPart)16 MimeMultipart (jakarta.mail.internet.MimeMultipart)11 MimeBodyPart (jakarta.mail.internet.MimeBodyPart)8 DataHandler (jakarta.activation.DataHandler)6 Multipart (jakarta.mail.Multipart)6 MimeMessage (jakarta.mail.internet.MimeMessage)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 InputStream (java.io.InputStream)4 Test (org.junit.Test)4 Message (jakarta.mail.Message)3 MessagingException (jakarta.mail.MessagingException)3 Retriever (com.icegreen.greenmail.util.Retriever)2 ServerSetupTest (com.icegreen.greenmail.util.ServerSetupTest)2 DataSource (jakarta.activation.DataSource)2 ContentType (jakarta.mail.internet.ContentType)2 ParameterList (jakarta.mail.internet.ParameterList)2 ByteArrayDataSource (jakarta.mail.util.ByteArrayDataSource)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 ByteArrayDataSource (org.apache.openmeetings.util.mail.ByteArrayDataSource)2