Package com.volantis.mcs.context

Examples of com.volantis.mcs.context.TestEnvironmentContext


        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",
View Full Code Here


            new TestMarinerRequestContext();
        TestMarinerPageContext pageContext = new TestMarinerPageContext();
        pageContext.setVolantis(volantis);
        ApplicationContext appContext =
            new MultipartApplicationContext(requestContext);
        TestEnvironmentContext envContext =
            new TestEnvironmentContext(getClass().getName() + ".message");

        pageContext.pushRequestContext(requestContext);
        ContextInternals.setEnvironmentContext(requestContext, envContext);
        ContextInternals.setMarinerPageContext(requestContext, pageContext);
        ContextInternals.setApplicationContext(requestContext, appContext);
        appContext.setPackager(handler);
        appContext.setAssetURLRewriter(handler);
        appContext.getPackageResources().setContentType("multipart/mixed");
        appContext.setEncodingManager(encodingManager);
        envContext.setContextPathURL("http://localhost:" + port);
        requestContext.setCharacterEncoding("iso-8859-1");
        return pageContext;
    }
View Full Code Here

TOP

Related Classes of com.volantis.mcs.context.TestEnvironmentContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.