String headerMHTMLName = "HeaderMHTML1";
String headerMHTMLValue = "value1";
MessageAttachments attachments = new MessageAttachments();
DeviceMessageAttachment attachment = new DeviceMessageAttachment();
String attachmentChannel = "SMTP";
String attachmentDevice = "Outlook";
String attachmentMimeType = "text/plain";
String attachmentValue = LOCAL_FILE_URLS[0];
MultiChannelMessageImpl message = new MultiChannelMessageImpl();
message.setMessage(messageText);
message.setMessageURL(url);
message.setSubject(subject);
message.addHeader(MultiChannelMessage.ALL,
headerAllName,
headerAllValue);
message.addHeader(MultiChannelMessage.MMS,
headerMMSName,
headerMMSValue);
message.addHeader(MultiChannelMessage.MHTML,
headerMHTMLName,
headerMHTMLValue);
attachment.setChannelName(attachmentChannel);
attachment.setDeviceName(attachmentDevice);
attachment.setMimeType(attachmentMimeType);
attachment.setValue(attachmentValue);
attachment.setValueType(DeviceMessageAttachment.URL);
attachments.addAttachment(attachment);
message.addAttachments(attachments);
MultiChannelMessage clone = (MultiChannelMessage) message.clone();
message.removeAttachments();
message.setMessage(null);
message.setMessageURL(null);
message.setSubject(null);
message = null;
assertEquals(clone.getMessage(), messageText);
assertEquals(clone.getMessageURL(), url);
assertEquals(clone.getSubject(), subject);
MessageAttachments retrievedMessageAttachments =
clone.getAttachments();
Iterator i = retrievedMessageAttachments.iterator();
int count = 0;
while (i.hasNext()) {
count++;
DeviceMessageAttachment retrievedAttachment =
(DeviceMessageAttachment) i.next();
assertEquals(retrievedAttachment.getChannelName(),
attachmentChannel);
assertEquals(retrievedAttachment.getDeviceName(),
attachmentDevice);
assertEquals(retrievedAttachment.getMimeType(),
attachmentMimeType);
assertEquals(retrievedAttachment.getValue(),
attachmentValue);
}
if (count != 1) {
fail("Expected one attachment got " + count);