public void testCreateMultipartMimeContent() throws Exception {
MessageExt sipMessage = (MessageExt) messageFactory.createRequest(messageString);
ContentTypeHeader cth = headerFactory.createContentTypeHeader("multipart", "alternative");
cth.setParameter("boundary", "myboundary");
MultipartMimeContent mmc = messageFactory.createMultipartMimeContent(cth, type, subtype, content);
Iterator<Content> contentIterator = mmc.getContents();
int i = 0;
while (contentIterator.hasNext()) {
Content contentImpl = contentIterator.next();
assertEquals("Content must match", content[i], contentImpl.getContent());
assertEquals("Content Type match", type[i], contentImpl.getContentTypeHeader().getContentType());
assertEquals("Content subtype match", subtype[i], contentImpl.getContentTypeHeader().getContentSubType());
i++;
}
String mmcContentString = mmc.toString();
sipMessage.setContent(mmcContentString, cth);
MultipartMimeContent mmc1 = sipMessage.getMultipartMimeContent();
contentIterator = mmc1.getContents();
i = 0;
while (contentIterator.hasNext()) {
Content contentImpl = contentIterator.next();
assertEquals("Content must match", content[i], contentImpl.getContent().toString());
assertEquals("Content Type match", type[i], contentImpl.getContentTypeHeader().getContentType());
assertEquals("Content subtype match", subtype[i], contentImpl.getContentTypeHeader().getContentSubType());
i++;
}
MessageExt message1 = (MessageExt) messageFactory.createRequest(messageSting1);
ContentTypeHeader cth1 = (ContentTypeHeader) ((HeaderFactoryExt) headerFactory).createHeader(contentType1);
message1.setContent(contentString1, cth1);
System.out.println("SIP Message after adding content " + message1);
MultipartMimeContent mmc2 = message1.getMultipartMimeContent();
Iterator<Content> contents = mmc2.getContents();
while (contents.hasNext()) {
Content content = contents.next();
System.out.println("contentTypeHeader = " + content.getContentTypeHeader());
System.out.println("content = " + content.getContent());
}
Request request2 = messageFactory.createRequest(message1.toString());
MultipartMimeContent mmc3 = ((MessageExt) request2).getMultipartMimeContent();
Iterator<Content> contents2 = mmc3.getContents();
contents = mmc2.getContents();
assertTrue("number of fragments dont match", mmc2.getContentCount() == mmc3.getContentCount());
while (contents2.hasNext()) {
Content c1 = contents.next();
Content c2 = contents2.next();
assertTrue("contents must match", c1.getContent().equals(c2.getContent()));