final MultipartPackageHandler handler =
new MultipartPackageHandler();
MarinerPageContext pageContext = createContexts(handler);
MarinerRequestContext requestContext =
pageContext.getRequestContext();
TestEnvironmentContext envContext =
(TestEnvironmentContext)pageContext.getEnvironmentContext();
// This asset exists
final DeviceImageAsset imageAsset =
new DeviceImageAsset(
"jug", 15, 15, 1,
ImageAsset.MONOCHROME, ImageAsset.JPEG,
"Master", null,
"/com/volantis/mcs/runtime/packagers/mime/jug.jpg");
// This asset does not
final DeviceImageAsset noImageAsset =
new DeviceImageAsset(
"nojug", 15, 15, 1,
ImageAsset.MONOCHROME, ImageAsset.JPEG,
"Master", null,
"/com/volantis/mcs/runtime/packagers/mime/nojug.jpg");
final StringBuffer bodyContent = new StringBuffer();
PackageBodySource bodySource = new PackageBodySource() {
public void write(PackageBodyOutput writer,
MarinerRequestContext context, Object bodyContext)
throws PackagingException {
try {
bodyContent.append("<html><body><div><img src=\"").
append(handler.rewriteAssetURL(
context, imageAsset,
null, new MarinerURL(imageAsset.getValue())).
getExternalForm()).
append("\"/></div><div><img src=\"").
append(handler.rewriteAssetURL(
context, noImageAsset,
null, new MarinerURL(noImageAsset.getValue())).
getExternalForm()).
append("\"/></div></body></html>");
writer.getWriter().write(bodyContent.toString());
} catch (RepositoryException e) {
throw new PackagingException(e);
} catch (IOException e) {
throw new PackagingException(e);
}
}
public String getBodyType(MarinerRequestContext context) {
return "text/html";
}
};
handler.createPackage(requestContext, bodySource, null);
try {
InputStream inputStream = envContext.getResponseInputStream();
MimeMessage message = new MimeMessage(Session.getInstance(
System.getProperties(), null), inputStream);
MimeMultipart multipart = (MimeMultipart)message.getContent();
assertTrue("message content type " + message.getContentType() +
" doesn't start with multipart/mixed as expected",