TILES-186
Merge from trunk to TILES_2_0_X branch.
Added functionality tests for roles in attributes and definitions.

git-svn-id: https://svn.apache.org/repos/asf/tiles/framework/branches/TILES_2_0_X@586909 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/tiles-test/src/main/java/org/apache/tiles/test/filter/SecurityWrappingFilter.java b/tiles-test/src/main/java/org/apache/tiles/test/filter/SecurityWrappingFilter.java
new file mode 100644
index 0000000..06c3164
--- /dev/null
+++ b/tiles-test/src/main/java/org/apache/tiles/test/filter/SecurityWrappingFilter.java
@@ -0,0 +1,79 @@
+/*
+ * $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.test.filter;
+
+import java.io.IOException;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+
+/**
+ * Filter that wraps an HttpServletRequest to override "isUserInRole".
+ *
+ * @version $Rev$ $Date$
+ */
+public class SecurityWrappingFilter implements Filter {
+
+    /**
+     * The role that the current user is supposed to use.
+     */
+    public static final String GOOD_ROLE = "goodrole";
+
+    /** {@inheritDoc} */
+    public void init(FilterConfig filterConfig) throws ServletException {
+        // No operation
+    }
+
+    /** {@inheritDoc} */
+    public void doFilter(ServletRequest servletRequest,
+            ServletResponse servletResponse, FilterChain filterChain)
+            throws IOException, ServletException {
+        HttpServletRequest wrappedRequest = new SecurityWrapperHttpServletRequest(
+                (HttpServletRequest) servletRequest);
+        filterChain.doFilter(wrappedRequest, servletResponse);
+    }
+
+    /** {@inheritDoc} */
+    public void destroy() {
+        // No operation
+    }
+
+    /**
+     * Request wrapper that overrides "isUserInRole" method.
+     *
+     * @version $Rev$ $Date$
+     */
+    private static class SecurityWrapperHttpServletRequest extends
+            HttpServletRequestWrapper {
+        public SecurityWrapperHttpServletRequest(HttpServletRequest request) {
+            super(request);
+        }
+
+        public boolean isUserInRole(String role) {
+            return GOOD_ROLE.equals(role);
+        }
+    }
+}
diff --git a/tiles-test/src/main/webapp/WEB-INF/tiles-defs.xml b/tiles-test/src/main/webapp/WEB-INF/tiles-defs.xml
index 3f744fd..e47b4ee 100644
--- a/tiles-test/src/main/webapp/WEB-INF/tiles-defs.xml
+++ b/tiles-test/src/main/webapp/WEB-INF/tiles-defs.xml
@@ -102,4 +102,23 @@
       <put-attribute name="body" value="/defaultlocale.jsp" />
   </definition>
 
+  <definition name="test.definition.appears" extends="test.definition">
+      <put-attribute name="title"  value="This definition appears."/>
+  </definition>
+
+  <definition name="test.definition.does_not_appear" extends="test.definition">
+      <put-attribute name="title"  value="This definition does not appear."/>
+  </definition>
+
+  <definition name="test.definition.appears.configured"
+    extends="test.definition.appears" role="goodrole" />
+
+  <definition name="test.definition.does_not_appear.configured"
+    extends="test.definition.does_not_appear" role="badrole" />
+
+  <definition name="test.definition.roles" template="/layout.jsp">
+      <put-attribute name="title"  value="This is the title."/>
+      <put-attribute name="header" value="/header.jsp" role="goodrole" />
+      <put-attribute name="body"   value="/body.jsp" role="badrole" />
+  </definition>
 </tiles-definitions>
diff --git a/tiles-test/src/main/webapp/WEB-INF/web.xml b/tiles-test/src/main/webapp/WEB-INF/web.xml
index dad7e42..c112416 100644
--- a/tiles-test/src/main/webapp/WEB-INF/web.xml
+++ b/tiles-test/src/main/webapp/WEB-INF/web.xml
@@ -53,12 +53,23 @@
         </init-param>
     </filter>
 
+    <filter>
+        <filter-name>Security Wrapping Filter</filter-name>
+        <filter-class>org.apache.tiles.test.filter.SecurityWrappingFilter</filter-class>
+    </filter>
+
     <filter-mapping>
         <filter-name>Tiles Decoration Filter</filter-name>
         <url-pattern>/testdecorationfilter.jsp</url-pattern>
         <dispatcher>REQUEST</dispatcher>
     </filter-mapping>
 
+    <filter-mapping>
+        <filter-name>Security Wrapping Filter</filter-name>
+        <url-pattern>/*</url-pattern>
+        <dispatcher>REQUEST</dispatcher>
+    </filter-mapping>
+
     <!-- Standard Action Servlet Configuration -->
     <servlet>
         <servlet-name>tiles</servlet-name>
diff --git a/tiles-test/src/main/webapp/index.jsp b/tiles-test/src/main/webapp/index.jsp
index c918917..f561527 100644
--- a/tiles-test/src/main/webapp/index.jsp
+++ b/tiles-test/src/main/webapp/index.jsp
@@ -64,6 +64,11 @@
     <a href="testinsertdefinition_composite_tags.jsp">Test Insert Definition that contains another definition inside using JSP tags</a><br/>
     <a href="testinsertdefinition_composite_tags_includes_configured_notype.jsp">Test Insert Definition that contains another definition inside (configured via tiles-defs.xml) using JSP tags without types</a><br/>
     <a href="testinsertdefinition_composite_tags_notype.jsp">Test Insert Definition that contains another definition inside using JSP tags without types</a><br/></body>
+    
+    <h3>Roles Verification tests</h3>
+    <a href="testinsertdefinition_role.jsp">Test Insert Configured Definition with Specified Role</a><br/>
+    <a href="testinsertdefinition_role_tag.jsp">Test Insert Configured Definition with Specified Role in Tag</a><br/>
+    <a href="testinsertdefinition_attribute_roles.jsp">Test Insert Configured Definition with Attribute that have Roles</a><br/>
 
     <h2>Currently not working tests</h2>
 
diff --git a/tiles-test/src/main/webapp/testinsertdefinition_attribute_roles.jsp b/tiles-test/src/main/webapp/testinsertdefinition_attribute_roles.jsp
new file mode 100644
index 0000000..995ae3f
--- /dev/null
+++ b/tiles-test/src/main/webapp/testinsertdefinition_attribute_roles.jsp
@@ -0,0 +1,27 @@
+<%@ page session="false" %>
+<%--
+/*
+ * $Id: testinsertdefinition.jsp 573035 2007-09-05 19:27:22Z apetrelli $
+ *
+ * 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.
+ *
+ */
+--%>
+<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
+
+<tiles:insertDefinition name="test.definition.roles" />
diff --git a/tiles-test/src/main/webapp/testinsertdefinition_role.jsp b/tiles-test/src/main/webapp/testinsertdefinition_role.jsp
new file mode 100644
index 0000000..09e0258
--- /dev/null
+++ b/tiles-test/src/main/webapp/testinsertdefinition_role.jsp
@@ -0,0 +1,28 @@
+<%@ page session="false" %>
+<%--
+/*
+ * $Id: testinsertdefinition.jsp 573035 2007-09-05 19:27:22Z apetrelli $
+ *
+ * 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.
+ *
+ */
+--%>
+<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
+
+<tiles:insertDefinition name="test.definition.appears.configured" />
+<tiles:insertDefinition name="test.definition.does_not_appear.configured" />
diff --git a/tiles-test/src/main/webapp/testinsertdefinition_role_tag.jsp b/tiles-test/src/main/webapp/testinsertdefinition_role_tag.jsp
new file mode 100644
index 0000000..84041d1
--- /dev/null
+++ b/tiles-test/src/main/webapp/testinsertdefinition_role_tag.jsp
@@ -0,0 +1,28 @@
+<%@ page session="false" %>
+<%--
+/*
+ * $Id: testinsertdefinition.jsp 573035 2007-09-05 19:27:22Z apetrelli $
+ *
+ * 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.
+ *
+ */
+--%>
+<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
+
+<tiles:insertDefinition name="test.definition.appears" role="goodrole" />
+<tiles:insertDefinition name="test.definition.does_not_appear" role="badrole" />
diff --git a/tiles-test/src/test/selenium/ConfiguredDefinitionAttributeRolesTest.html b/tiles-test/src/test/selenium/ConfiguredDefinitionAttributeRolesTest.html
new file mode 100644
index 0000000..f365b11
--- /dev/null
+++ b/tiles-test/src/test/selenium/ConfiguredDefinitionAttributeRolesTest.html
@@ -0,0 +1,61 @@
+<!--
+/*
+ * $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.
+ */
+-->
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Configured Definition Attribute Roles Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">Configured Definition Attribute Roles Test</td></tr>
+</thead><tbody>
+<tr>
+	<td>open</td>
+	<td>/tiles-test/index.jsp</td>
+	<td></td>
+</tr>
+<tr>
+	<td>clickAndWait</td>
+	<td>link=Test Insert Configured Definition with Attribute that have Roles</td>
+	<td></td>
+</tr>
+<tr>
+	<td>assertTextPresent</td>
+	<td>This is the title.</td>
+	<td></td>
+</tr>
+<tr>
+	<td>assertTextPresent</td>
+	<td>This is the header</td>
+	<td></td>
+</tr>
+<tr>
+	<td>assertTextNotPresent</td>
+	<td>This is a body</td>
+	<td></td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tiles-test/src/test/selenium/ConfiguredDefinitionRoleTagTest.html b/tiles-test/src/test/selenium/ConfiguredDefinitionRoleTagTest.html
new file mode 100644
index 0000000..3fcfbdf
--- /dev/null
+++ b/tiles-test/src/test/selenium/ConfiguredDefinitionRoleTagTest.html
@@ -0,0 +1,66 @@
+<!--
+/*
+ * $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.
+ */
+-->
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Configured Definition Role Tag Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">Configured Definition Role Tag Test</td></tr>
+</thead><tbody>
+<tr>
+	<td>open</td>
+	<td>/tiles-test/index.jsp</td>
+	<td></td>
+</tr>
+<tr>
+	<td>clickAndWait</td>
+	<td>link=Test Insert Configured Definition with Specified Role in Tag</td>
+	<td></td>
+</tr>
+<tr>
+	<td>assertTextPresent</td>
+	<td>This definition appears.</td>
+	<td></td>
+</tr>
+<tr>
+	<td>assertTextPresent</td>
+	<td>This is the header</td>
+	<td></td>
+</tr>
+<tr>
+	<td>assertTextPresent</td>
+	<td>This is a body</td>
+	<td></td>
+</tr>
+<tr>
+	<td>assertTextNotPresent</td>
+	<td>This definition does not appear.</td>
+	<td></td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tiles-test/src/test/selenium/ConfiguredDefinitionRoleTest.html b/tiles-test/src/test/selenium/ConfiguredDefinitionRoleTest.html
new file mode 100644
index 0000000..1a2a9b0
--- /dev/null
+++ b/tiles-test/src/test/selenium/ConfiguredDefinitionRoleTest.html
@@ -0,0 +1,66 @@
+<!--
+/*
+ * $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.
+ */
+-->
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+<title>Configured Definition Role Test</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">Configured Definition Role Test</td></tr>
+</thead><tbody>
+<tr>
+	<td>open</td>
+	<td>/tiles-test/index.jsp</td>
+	<td></td>
+</tr>
+<tr>
+	<td>clickAndWait</td>
+	<td>link=Test Insert Configured Definition with Specified Role</td>
+	<td></td>
+</tr>
+<tr>
+	<td>assertTextPresent</td>
+	<td>This definition appears.</td>
+	<td></td>
+</tr>
+<tr>
+	<td>assertTextPresent</td>
+	<td>This is the header</td>
+	<td></td>
+</tr>
+<tr>
+	<td>assertTextPresent</td>
+	<td>This is a body</td>
+	<td></td>
+</tr>
+<tr>
+	<td>assertTextNotPresent</td>
+	<td>This definition does not appear.</td>
+	<td></td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/tiles-test/src/test/selenium/TestSuite.html b/tiles-test/src/test/selenium/TestSuite.html
index 3b93bc5..e4c6e13 100644
--- a/tiles-test/src/test/selenium/TestSuite.html
+++ b/tiles-test/src/test/selenium/TestSuite.html
@@ -117,6 +117,15 @@
     <tr>
         <td><a href="CompositeDefinitionWithInnerDefinitionNoTypeTest.html">Composite Definition with inner Definition with no Type Test</a></td>
     </tr>
+    <tr>
+        <td><a href="ConfiguredDefinitionRoleTest.html">Configured Definition Role Test</a></td>
+    </tr>
+    <tr>
+        <td><a href="ConfiguredDefinitionRoleTagTest.html">Configured Definition Role Tag Test</a></td>
+    </tr>
+    <tr>
+        <td><a href="ConfiguredDefinitionAttributeRolesTest.html">Configured Definition Attribute Roles Test</a></td>
+    </tr>
 </table>
 </body>
 </html>
\ No newline at end of file