Author: apetrelli
Date: Sun Feb 24 08:14:56 2008
New Revision: 630632

URL: http://svn.apache.org/viewvc?rev=630632&view=rev
Log:
TILES-190
TILES-191
Added tests for attribute renderers.

Added:
    tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/
    
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/
    
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/AbstractBaseAttributeRendererTest.java
   (with props)
    
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/DefinitionAttributeRendererTest.java
   (with props)
    
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/StringAttributeRendererTest.java
   (with props)
    
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/TemplateAttributeRendererTest.java
   (with props)
    
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/UntypedAttributeRendererTest.java
   (with props)

Added: 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/AbstractBaseAttributeRendererTest.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/AbstractBaseAttributeRendererTest.java?rev=630632&view=auto
==============================================================================
--- 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/AbstractBaseAttributeRendererTest.java
 (added)
+++ 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/AbstractBaseAttributeRendererTest.java
 Sun Feb 24 08:14:56 2008
@@ -0,0 +1,168 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.renderer.impl;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.tiles.Attribute;
+import org.apache.tiles.TilesApplicationContext;
+import org.apache.tiles.TilesException;
+import org.apache.tiles.context.TilesContextFactory;
+import org.apache.tiles.context.TilesRequestContext;
+import org.easymock.EasyMock;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests [EMAIL PROTECTED] AbstractBaseAttributeRenderer}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class AbstractBaseAttributeRendererTest extends TestCase {
+
+    /**
+     * The renderer, no more abstract.
+     */
+    private MockAttributeRenderer renderer;
+
+    /** [EMAIL PROTECTED] */
+    @Override
+    protected void setUp() throws Exception {
+        renderer = new MockAttributeRenderer();
+    }
+
+    /**
+     * Tests
+     * [EMAIL PROTECTED] 
AbstractBaseAttributeRenderer#setContextFactory(TilesContextFactory)}.
+     */
+    public void testSetContextFactory() {
+        TilesContextFactory contextFactory = EasyMock
+                .createMock(TilesContextFactory.class);
+        EasyMock.replay(contextFactory);
+        renderer.setContextFactory(contextFactory);
+        assertNotNull("The context factory is null", renderer.contextFactory);
+    }
+
+    /**
+     * Tests
+     * [EMAIL PROTECTED] 
AbstractBaseAttributeRenderer#setApplicationContext(TilesApplicationContext)}.
+     */
+    public void testSetApplicationContext() {
+        TilesApplicationContext applicationContext = EasyMock
+                .createMock(TilesApplicationContext.class);
+        EasyMock.replay(applicationContext);
+        renderer.setApplicationContext(applicationContext);
+        assertNotNull("The application context is null", 
renderer.applicationContext);
+    }
+
+    /**
+     * Tests
+     * [EMAIL PROTECTED] AbstractBaseAttributeRenderer#render(Attribute, 
Writer, Object...)}.
+     *
+     * @throws IOException If something goes wrong during rendition.
+     * @throws TilesException If something goes wrong during the usage of 
Tiles.
+     */
+    public void testRender() throws IOException, TilesException {
+        Attribute attribute = new Attribute();
+        StringWriter writer = new StringWriter();
+        TilesApplicationContext applicationContext = EasyMock
+                .createMock(TilesApplicationContext.class);
+        TilesContextFactory contextFactory = EasyMock
+                .createMock(TilesContextFactory.class);
+        TilesRequestContext requestContext = EasyMock
+                .createMock(TilesRequestContext.class);
+        
EasyMock.expect(contextFactory.createRequestContext(applicationContext))
+                .andReturn(requestContext);
+        EasyMock.replay(applicationContext, contextFactory, requestContext);
+        renderer.setApplicationContext(applicationContext);
+        renderer.setContextFactory(contextFactory);
+        renderer.render(attribute, writer);
+        writer.close();
+        assertEquals("Wrongly written", "wrote", writer.toString());
+    }
+
+    /**
+     * Tests [EMAIL PROTECTED] 
AbstractBaseAttributeRenderer#getRequestContext(Object...)}.
+     */
+    public void testGetRequestContext() {
+        TilesApplicationContext applicationContext = EasyMock
+                .createMock(TilesApplicationContext.class);
+        TilesContextFactory contextFactory = EasyMock
+                .createMock(TilesContextFactory.class);
+        TilesRequestContext requestContext = EasyMock
+                .createMock(TilesRequestContext.class);
+        
EasyMock.expect(contextFactory.createRequestContext(applicationContext))
+                .andReturn(requestContext);
+        EasyMock.replay(applicationContext, contextFactory, requestContext);
+        renderer.setApplicationContext(applicationContext);
+        renderer.setContextFactory(contextFactory);
+        assertTrue("This is not the expected request",
+                requestContext == renderer.getRequestContext());
+    }
+
+    /**
+     * Tests
+     * [EMAIL PROTECTED] 
AbstractBaseAttributeRenderer#isPermitted(TilesRequestContext, Set)}.
+     */
+    public void testIsPermitted() {
+        TilesApplicationContext applicationContext = EasyMock
+                .createMock(TilesApplicationContext.class);
+        TilesContextFactory contextFactory = EasyMock
+                .createMock(TilesContextFactory.class);
+        TilesRequestContext requestContext = EasyMock
+                .createMock(TilesRequestContext.class);
+        
EasyMock.expect(contextFactory.createRequestContext(applicationContext))
+                .andReturn(requestContext);
+        EasyMock.expect(requestContext.isUserInRole("first")).andReturn(
+                Boolean.TRUE).anyTimes();
+        EasyMock.expect(requestContext.isUserInRole("second")).andReturn(
+                Boolean.FALSE).anyTimes();
+        EasyMock.replay(applicationContext, contextFactory, requestContext);
+        renderer.setApplicationContext(applicationContext);
+        renderer.setContextFactory(contextFactory);
+        Set<String> roles = new HashSet<String>();
+        roles.add("first");
+        assertTrue("The role is not permitted", renderer.isPermitted(
+                requestContext, roles));
+        roles.clear();
+        roles.add("second");
+        assertFalse("The role is not permitted", renderer.isPermitted(
+                requestContext, roles));
+    }
+
+    /**
+     * The renderer with "write" implementation.
+     */
+    private static class MockAttributeRenderer extends 
AbstractBaseAttributeRenderer {
+
+        /** [EMAIL PROTECTED] */
+        @Override
+        public void write(Attribute attribute, Writer writer,
+                TilesRequestContext request, Object... requestItems)
+                throws IOException, TilesException {
+            writer.write("wrote");
+        }
+    }
+}

Propchange: 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/AbstractBaseAttributeRendererTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/AbstractBaseAttributeRendererTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/DefinitionAttributeRendererTest.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/DefinitionAttributeRendererTest.java?rev=630632&view=auto
==============================================================================
--- 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/DefinitionAttributeRendererTest.java
 (added)
+++ 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/DefinitionAttributeRendererTest.java
 Sun Feb 24 08:14:56 2008
@@ -0,0 +1,82 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.renderer.impl;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+import org.apache.tiles.Attribute;
+import org.apache.tiles.TilesApplicationContext;
+import org.apache.tiles.TilesContainer;
+import org.apache.tiles.TilesException;
+import org.apache.tiles.context.TilesContextFactory;
+import org.apache.tiles.context.TilesRequestContext;
+import org.easymock.EasyMock;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests [EMAIL PROTECTED] DefinitionAttributeRenderer}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefinitionAttributeRendererTest extends TestCase {
+
+    /**
+     * The renderer.
+     */
+    private DefinitionAttributeRenderer renderer;
+
+    /** [EMAIL PROTECTED] */
+    @Override
+    protected void setUp() throws Exception {
+        renderer = new DefinitionAttributeRenderer();
+    }
+
+    /**
+     * Tests
+     * [EMAIL PROTECTED] StringAttributeRenderer#write(Attribute, 
java.io.Writer, TilesRequestContext, Object...)}.
+     *
+     * @throws IOException If something goes wrong during rendition.
+     * @throws TilesException If something goes wrong during the usage of 
Tiles.
+     */
+    public void testWrite() throws IOException, TilesException {
+        StringWriter writer = new StringWriter();
+        Attribute attribute = new Attribute("my.definition", null, 
"definition");
+        TilesApplicationContext applicationContext = EasyMock
+                .createMock(TilesApplicationContext.class);
+        TilesContextFactory contextFactory = EasyMock
+                .createMock(TilesContextFactory.class);
+        TilesContainer container = EasyMock.createMock(TilesContainer.class);
+        TilesRequestContext requestContext = EasyMock
+                .createMock(TilesRequestContext.class);
+        
EasyMock.expect(contextFactory.createRequestContext(applicationContext))
+                .andReturn(requestContext);
+        container.render("my.definition");
+        EasyMock.replay(applicationContext, contextFactory, requestContext,
+                container);
+        renderer.setApplicationContext(applicationContext);
+        renderer.setContextFactory(contextFactory);
+        renderer.setContainer(container);
+        renderer.render(attribute, writer);
+        writer.close();
+    }
+}

Propchange: 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/DefinitionAttributeRendererTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/DefinitionAttributeRendererTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/StringAttributeRendererTest.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/StringAttributeRendererTest.java?rev=630632&view=auto
==============================================================================
--- 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/StringAttributeRendererTest.java
 (added)
+++ 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/StringAttributeRendererTest.java
 Sun Feb 24 08:14:56 2008
@@ -0,0 +1,78 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.renderer.impl;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+import org.apache.tiles.Attribute;
+import org.apache.tiles.TilesApplicationContext;
+import org.apache.tiles.TilesException;
+import org.apache.tiles.context.TilesContextFactory;
+import org.apache.tiles.context.TilesRequestContext;
+import org.easymock.EasyMock;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests [EMAIL PROTECTED] StringAttributeRenderer}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class StringAttributeRendererTest extends TestCase {
+
+    /**
+     * The renderer.
+     */
+    private StringAttributeRenderer renderer;
+
+    /** [EMAIL PROTECTED] */
+    @Override
+    protected void setUp() throws Exception {
+        renderer = new StringAttributeRenderer();
+    }
+
+    /**
+     * Tests
+     * [EMAIL PROTECTED] StringAttributeRenderer#write(Attribute, 
java.io.Writer, TilesRequestContext, Object...)}.
+     *
+     * @throws IOException If something goes wrong during rendition.
+     * @throws TilesException If something goes wrong during the usage of 
Tiles.
+     */
+    public void testWrite() throws IOException, TilesException {
+        StringWriter writer = new StringWriter();
+        Attribute attribute = new Attribute("Result", null, "string");
+        TilesApplicationContext applicationContext = EasyMock
+                .createMock(TilesApplicationContext.class);
+        TilesContextFactory contextFactory = EasyMock
+                .createMock(TilesContextFactory.class);
+        TilesRequestContext requestContext = EasyMock
+                .createMock(TilesRequestContext.class);
+        
EasyMock.expect(contextFactory.createRequestContext(applicationContext))
+                .andReturn(requestContext);
+        EasyMock.replay(applicationContext, contextFactory, requestContext);
+        renderer.setApplicationContext(applicationContext);
+        renderer.setContextFactory(contextFactory);
+        renderer.render(attribute, writer);
+        writer.close();
+        assertEquals("Not written 'Result'", "Result", writer.toString());
+    }
+}

Propchange: 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/StringAttributeRendererTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/StringAttributeRendererTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/TemplateAttributeRendererTest.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/TemplateAttributeRendererTest.java?rev=630632&view=auto
==============================================================================
--- 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/TemplateAttributeRendererTest.java
 (added)
+++ 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/TemplateAttributeRendererTest.java
 Sun Feb 24 08:14:56 2008
@@ -0,0 +1,78 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.renderer.impl;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+import org.apache.tiles.Attribute;
+import org.apache.tiles.TilesApplicationContext;
+import org.apache.tiles.TilesException;
+import org.apache.tiles.context.TilesContextFactory;
+import org.apache.tiles.context.TilesRequestContext;
+import org.easymock.EasyMock;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests [EMAIL PROTECTED] TemplateAttributeRenderer}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TemplateAttributeRendererTest extends TestCase {
+
+    /**
+     * The renderer.
+     */
+    private TemplateAttributeRenderer renderer;
+
+    /** [EMAIL PROTECTED] */
+    @Override
+    protected void setUp() throws Exception {
+        renderer = new TemplateAttributeRenderer();
+    }
+
+    /**
+     * Tests
+     * [EMAIL PROTECTED] StringAttributeRenderer#write(Attribute, 
java.io.Writer, TilesRequestContext, Object...)}.
+     *
+     * @throws IOException If something goes wrong during rendition.
+     * @throws TilesException If something goes wrong during the usage of 
Tiles.
+     */
+    public void testWrite() throws IOException, TilesException {
+        StringWriter writer = new StringWriter();
+        Attribute attribute = new Attribute("/myTemplate.jsp", null, 
"template");
+        TilesApplicationContext applicationContext = EasyMock
+                .createMock(TilesApplicationContext.class);
+        TilesContextFactory contextFactory = EasyMock
+                .createMock(TilesContextFactory.class);
+        TilesRequestContext requestContext = EasyMock
+                .createMock(TilesRequestContext.class);
+        
EasyMock.expect(contextFactory.createRequestContext(applicationContext))
+                .andReturn(requestContext);
+        requestContext.dispatch("/myTemplate.jsp");
+        EasyMock.replay(applicationContext, contextFactory, requestContext);
+        renderer.setApplicationContext(applicationContext);
+        renderer.setContextFactory(contextFactory);
+        renderer.render(attribute, writer);
+        writer.close();
+    }
+}

Propchange: 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/TemplateAttributeRendererTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/TemplateAttributeRendererTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/UntypedAttributeRendererTest.java
URL: 
http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/UntypedAttributeRendererTest.java?rev=630632&view=auto
==============================================================================
--- 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/UntypedAttributeRendererTest.java
 (added)
+++ 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/UntypedAttributeRendererTest.java
 Sun Feb 24 08:14:56 2008
@@ -0,0 +1,147 @@
+/*
+ * $Id$
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tiles.renderer.impl;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+import org.apache.tiles.Attribute;
+import org.apache.tiles.TilesApplicationContext;
+import org.apache.tiles.TilesContainer;
+import org.apache.tiles.TilesException;
+import org.apache.tiles.context.TilesContextFactory;
+import org.apache.tiles.context.TilesRequestContext;
+import org.easymock.EasyMock;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests [EMAIL PROTECTED] UntypedAttributeRenderer}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class UntypedAttributeRendererTest extends TestCase {
+
+    /**
+     * The renderer.
+     */
+    private UntypedAttributeRenderer renderer;
+
+    /** [EMAIL PROTECTED] */
+    @Override
+    protected void setUp() throws Exception {
+        renderer = new UntypedAttributeRenderer();
+    }
+
+    /**
+     * Tests
+     * [EMAIL PROTECTED] StringAttributeRenderer#write(Attribute, 
java.io.Writer, TilesRequestContext, Object...)}
+     * writing a Definition.
+     *
+     * @throws IOException If something goes wrong during rendition.
+     * @throws TilesException If something goes wrong during the usage of 
Tiles.
+     */
+    public void testWriteDefinition() throws IOException, TilesException {
+        StringWriter writer = new StringWriter();
+        Attribute attribute = new Attribute("my.definition", null, 
"definition");
+        TilesApplicationContext applicationContext = EasyMock
+                .createMock(TilesApplicationContext.class);
+        TilesContextFactory contextFactory = EasyMock
+                .createMock(TilesContextFactory.class);
+        TilesContainer container = EasyMock.createMock(TilesContainer.class);
+        TilesRequestContext requestContext = EasyMock
+                .createMock(TilesRequestContext.class);
+        
EasyMock.expect(contextFactory.createRequestContext(applicationContext))
+                .andReturn(requestContext);
+        EasyMock.expect(container.isValidDefinition("my.definition"))
+                .andReturn(Boolean.TRUE);
+        container.render("my.definition");
+        EasyMock.replay(applicationContext, contextFactory, requestContext,
+                container);
+        renderer.setApplicationContext(applicationContext);
+        renderer.setContextFactory(contextFactory);
+        renderer.setContainer(container);
+        renderer.render(attribute, writer);
+        writer.close();
+    }
+
+    /**
+     * Tests
+     * [EMAIL PROTECTED] StringAttributeRenderer#write(Attribute, 
java.io.Writer, TilesRequestContext, Object...)}
+     * writing a string.
+     *
+     * @throws IOException If something goes wrong during rendition.
+     * @throws TilesException If something goes wrong during the usage of 
Tiles.
+     */
+    public void testWriteString() throws IOException, TilesException {
+        StringWriter writer = new StringWriter();
+        Attribute attribute = new Attribute("Result", null, "string");
+        TilesApplicationContext applicationContext = EasyMock
+                .createMock(TilesApplicationContext.class);
+        TilesContextFactory contextFactory = EasyMock
+                .createMock(TilesContextFactory.class);
+        TilesContainer container = EasyMock.createMock(TilesContainer.class);
+        TilesRequestContext requestContext = EasyMock
+                .createMock(TilesRequestContext.class);
+        
EasyMock.expect(contextFactory.createRequestContext(applicationContext))
+                .andReturn(requestContext);
+        EasyMock.expect(container.isValidDefinition("my.definition"))
+                .andReturn(Boolean.TRUE);
+        EasyMock.replay(applicationContext, contextFactory, requestContext);
+        renderer.setApplicationContext(applicationContext);
+        renderer.setContextFactory(contextFactory);
+        renderer.setContainer(container);
+        renderer.render(attribute, writer);
+        writer.close();
+        assertEquals("Not written 'Result'", "Result", writer.toString());
+    }
+
+    /**
+     * Tests
+     * [EMAIL PROTECTED] StringAttributeRenderer#write(Attribute, 
java.io.Writer, TilesRequestContext, Object...)}
+     * writing a template.
+     *
+     * @throws IOException If something goes wrong during rendition.
+     * @throws TilesException If something goes wrong during the usage of 
Tiles.
+     */
+    public void testWriteTemplate() throws IOException, TilesException {
+        StringWriter writer = new StringWriter();
+        Attribute attribute = new Attribute("/myTemplate.jsp", null, 
"template");
+        TilesApplicationContext applicationContext = EasyMock
+                .createMock(TilesApplicationContext.class);
+        TilesContextFactory contextFactory = EasyMock
+                .createMock(TilesContextFactory.class);
+        TilesContainer container = EasyMock.createMock(TilesContainer.class);
+        TilesRequestContext requestContext = EasyMock
+                .createMock(TilesRequestContext.class);
+        
EasyMock.expect(contextFactory.createRequestContext(applicationContext))
+                .andReturn(requestContext);
+        requestContext.dispatch("/myTemplate.jsp");
+        EasyMock.expect(container.isValidDefinition("my.definition"))
+                .andReturn(Boolean.TRUE);
+        EasyMock.replay(applicationContext, contextFactory, requestContext);
+        renderer.setApplicationContext(applicationContext);
+        renderer.setContextFactory(contextFactory);
+        renderer.setContainer(container);
+        renderer.render(attribute, writer);
+        writer.close();
+    }
+}

Propchange: 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/UntypedAttributeRendererTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/renderer/impl/UntypedAttributeRendererTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL


Reply via email to