*/
public class GenericAttachmentTestCase extends JBossWSTest
{
public void testEncodingDecoding() throws Exception
{
MessageFactoryImpl factory = new MessageFactoryImpl();
SOAPMessage msg1 = factory.createMessage();
AttachmentPart attachment1 = msg1.createAttachmentPart();
attachment1.setContent("this is a test", "text/plain; charset=UTF-8");
attachment1.setContentId("<attachment1@test.ws.jboss.org>");
msg1.addAttachmentPart(attachment1);
BufferedImage img = new BufferedImage(2, 2, 1);
img.setRGB(0, 0, 5);
img.setRGB(0, 1, 6);
img.setRGB(1, 0, 101);
img.setRGB(1, 1, 102);
AttachmentPart attachment2 = msg1.createAttachmentPart();
attachment2.setContent(img, "image/png");
attachment2.setContentId("<attachment2@test.ws.jboss.org>");
msg1.addAttachmentPart(attachment2);
if (msg1.saveRequired())
msg1.saveChanges();
String type = msg1.getMimeHeaders().getHeader(MimeConstants.CONTENT_TYPE)[0];
File file = File.createTempFile("JBossWSAttachmentTest", ".dat");
file.deleteOnExit();
FileOutputStream os = new FileOutputStream(file);
msg1.writeTo(os);
os.flush();
os.close();
FileInputStream is = new FileInputStream(file);
MimeHeaders headers = new MimeHeaders();
headers.addHeader(MimeConstants.CONTENT_TYPE, type);
SOAPMessage msg2 = new MessageFactoryImpl().createMessage(headers, is);
// Verify SOAP body is the same
SOAPEnvelope expEnv = msg1.getSOAPPart().getEnvelope();
SOAPEnvelope wasEnv = msg2.getSOAPPart().getEnvelope();
assertEquals(expEnv, wasEnv);