Package org.apache.velocity.runtime.parser.node

Examples of org.apache.velocity.runtime.parser.node.ASTBlock


     * @throws IOException If something goes wrong.
     */
    @Test
    public void testEvaluateWriter() throws IOException {
        InternalContextAdapter internalContextAdapter = createMock(InternalContextAdapter.class);
        ASTBlock body = createMock(ASTBlock.class);
        Writer writer = createMock(Writer.class);
        expect(body.render(internalContextAdapter, writer)).andReturn(true);

        replay(internalContextAdapter, body, writer);
        VelocityModelBody modelBody = createMockBuilder(VelocityModelBody.class)
                .withConstructor(internalContextAdapter, body, writer)
                .createMock();
View Full Code Here


    @Test
    public void testCreateModelBody() {
        InternalContextAdapter context = createMock(InternalContextAdapter.class);
        Writer writer = createMock(Writer.class);
        Node node = createMock(Node.class);
        ASTBlock block = createMock(ASTBlock.class);
        expect(node.jjtGetChild(1)).andReturn(block);
        replay(context, writer, node, block);
        VelocityAutotagRuntime runtime = new VelocityAutotagRuntime();
        runtime.render(context, writer, node);
        ModelBody modelBody = runtime.createModelBody();
View Full Code Here

    }

    /** {@inheritDoc} */
    @Override
    public ModelBody createModelBody() {
        ASTBlock block = (ASTBlock) node.jjtGetChild(1);
        return new VelocityModelBody(context, block, writer);
    }
View Full Code Here

     * @throws IOException If something goes wrong.
     */
    @Test
    public void testEvaluateWriter() throws IOException {
        InternalContextAdapter internalContextAdapter = createMock(InternalContextAdapter.class);
        ASTBlock body = createMock(ASTBlock.class);
        Writer writer = createMock(Writer.class);
        expect(body.render(internalContextAdapter, writer)).andReturn(true);

        replay(internalContextAdapter, body, writer);
        VelocityModelBody modelBody = createMockBuilder(VelocityModelBody.class)
                .withConstructor(internalContextAdapter, body, writer)
                .createMock();
View Full Code Here

        ViewToolContext viewContext = createMock(ViewToolContext.class);
        HttpServletRequest request = createMock(HttpServletRequest.class);
        HttpServletResponse response = createMock(HttpServletResponse.class);
        ServletContext servletContext = createMock(ServletContext.class);
        ASTMap astMap = createMock(ASTMap.class);
        ASTBlock block = createMock(ASTBlock.class);
        Map<String, Object> params = createMock(Map.class);

        expect(context.getInternalUserContext()).andReturn(viewContext);
        expect(viewContext.getRequest()).andReturn(request);
        expect(viewContext.getResponse()).andReturn(response);
        expect(viewContext.getServletContext()).andReturn(servletContext);
        expect(node.jjtGetChild(0)).andReturn(astMap);
        expect(astMap.value(context)).andReturn(params);
        expect(node.jjtGetChild(1)).andReturn(block);
        expect(block.render(context, writer)).andReturn(true);

        directive.start(context, writer, params, request, response, servletContext);
        directive.end(context, writer, params, request, response, servletContext);

        replay(directive, context, writer, node, viewContext, servletContext, request, response, astMap, params, block);
View Full Code Here

        ViewToolContext viewContext = createMock(ViewToolContext.class);
        HttpServletRequest request = createMock(HttpServletRequest.class);
        HttpServletResponse response = createMock(HttpServletResponse.class);
        ServletContext servletContext = createMock(ServletContext.class);
        ASTMap astMap = createMock(ASTMap.class);
        ASTBlock block = createMock(ASTBlock.class);
        Map<String, Object> params = createMock(Map.class);

        expect(context.getInternalUserContext()).andReturn(viewContext);
        expect(viewContext.getRequest()).andReturn(request);
        expect(viewContext.getResponse()).andReturn(response);
        expect(viewContext.getServletContext()).andReturn(servletContext);
        expect(node.jjtGetChild(0)).andReturn(astMap);
        expect(astMap.value(context)).andReturn(params);
        expect(node.jjtGetChild(1)).andReturn(block);
        expect(block.render(eq(context), isA(StringWriter.class))).andReturn(true);

        directive.start(context, writer, params, request, response, servletContext);
        directive.end(context, writer, params, null, request, response, servletContext);

        replay(directive, context, writer, node, viewContext, servletContext, request, response, astMap, params, block);
View Full Code Here

     */
    @Test
    public void testGetBodyAsString() throws IOException {
        InternalContextAdapter context = createMock(InternalContextAdapter.class);
        Node node = createMock(Node.class);
        ASTBlock block = new CustomBlock();

        expect(node.jjtGetChild(1)).andReturn(block);

        replay(context, node);
        assertEquals("myBody", VelocityUtil.getBodyAsString(context, node));
View Full Code Here

    @Test
    public void testEvaluateBody() throws IOException {
        InternalContextAdapter context = createMock(InternalContextAdapter.class);
        Node node = createMock(Node.class);
        Writer writer = createMock(Writer.class);
        ASTBlock block = createMock(ASTBlock.class);

        expect(node.jjtGetChild(1)).andReturn(block);

        replay(context, node, writer);
        VelocityUtil.evaluateBody(context, writer, node);
View Full Code Here

     * @throws IOException If something goes wrong.
     * @since 2.2.2
     */
    public static String getBodyAsString(InternalContextAdapter context, Node node)
            throws IOException {
        ASTBlock block = (ASTBlock) node.jjtGetChild(1);
        StringWriter stringWriter = new StringWriter();
        block.render(context, stringWriter);
        stringWriter.close();
        String body = stringWriter.toString();
        if (body != null) {
            body = body.replaceAll("^\\s*|\\s*$", "");
            if (body.length() <= 0) {
View Full Code Here

     * @throws IOException If something goes wrong.
     * @since 2.2.2
     */
    public static void evaluateBody(InternalContextAdapter context, Writer writer,
            Node node) throws IOException {
        ASTBlock block = (ASTBlock) node.jjtGetChild(1);
        block.render(context, writer);
    }
View Full Code Here

TOP

Related Classes of org.apache.velocity.runtime.parser.node.ASTBlock

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.