You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by ap...@apache.org on 2006/12/02 22:33:00 UTC

svn commit: r481630 - in /struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles: config/defs1.xml config/defs1_fr.xml config/defs1_fr_CA.xml definition/TestUrlDefinitionsFactory.java

Author: apetrelli
Date: Sat Dec  2 13:32:59 2006
New Revision: 481630

URL: http://svn.apache.org/viewvc?view=rev&rev=481630
Log:
Added test case to test UrlDefinitionsFactory.getDefinition method.

Added:
    struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1_fr_CA.xml   (with props)
Modified:
    struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1.xml
    struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1_fr.xml
    struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/TestUrlDefinitionsFactory.java

Modified: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1.xml?view=diff&rev=481630&r1=481629&r2=481630
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1.xml (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1.xml Sat Dec  2 13:32:59 2006
@@ -34,6 +34,16 @@
   <!-- Master definition  									-->
   <!-- =======================================================  -->
 
+  <!-- This definition will remain the same for all locales -->
+  <definition name="test.common" template="/test.jsp">
+      <put name="country" value="none"/>
+	  <put name="title"  value="Common Definition" />
+	  <put name="header" value="/common/header.jsp" />
+	  <put name="menu"   value="doc.menu.main" />
+	  <put name="footer" value="/common/footer.jsp" />
+	  <put name="body"   value="doc.portal.body" />
+  </definition>
+
   <!-- Doc index page description  -->
   <definition name="test.def1" template="/test.jsp">
           <put name="country" value="default"/>

Modified: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1_fr.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1_fr.xml?view=diff&rev=481630&r1=481629&r2=481630
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1_fr.xml (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1_fr.xml Sat Dec  2 13:32:59 2006
@@ -44,4 +44,13 @@
 	  <put name="body"   value="doc.portal.body" />
   </definition>
 
+  <definition name="test.common.french" template="/test.jsp">
+          <put name="country" value="France"/>
+    <put name="title"  value="Common Definition for French" />
+    <put name="header" value="/common/header.jsp" />
+    <put name="menu"   value="doc.menu.main" />
+    <put name="footer" value="/common/footer.jsp" />
+    <put name="body"   value="doc.portal.body" />
+  </definition>
+
 </tiles-definitions>

Added: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1_fr_CA.xml
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1_fr_CA.xml?view=auto&rev=481630
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1_fr_CA.xml (added)
+++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1_fr_CA.xml Sat Dec  2 13:32:59 2006
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!--
+/*
+ * $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.
+ */
+-->
+
+ <!DOCTYPE tiles-definitions PUBLIC
+       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
+       "http://struts.apache.org/dtds/tiles-config_2_0.dtd">
+
+<!-- Definitions for Tiles documentation   -->
+
+<tiles-definitions>
+
+  <!-- =======================================================  -->
+  <!-- Master definition  									-->
+  <!-- =======================================================  -->
+
+  <!-- Doc index page description  -->
+  <definition name="test.def1" template="/test.jsp">
+          <put name="country" value="Canada"/>
+	  <put name="title"  value="Tiles Library Documentation" />
+	  <put name="header" value="/common/header.jsp" />
+	  <put name="menu"   value="doc.menu.main" />
+	  <put name="footer" value="/common/footer.jsp" />
+	  <put name="body"   value="doc.portal.body" />
+  </definition>
+
+</tiles-definitions>

Propchange: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1_fr_CA.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/config/defs1_fr_CA.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/TestUrlDefinitionsFactory.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/TestUrlDefinitionsFactory.java?view=diff&rev=481630&r1=481629&r2=481630
==============================================================================
--- struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/TestUrlDefinitionsFactory.java (original)
+++ struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/TestUrlDefinitionsFactory.java Sat Dec  2 13:32:59 2006
@@ -98,8 +98,59 @@
         ComponentDefinitions definitions = factory.readDefinitions();
 
         assertNotNull("test.def1 definition not found.", definitions.getDefinition("test.def1"));
-        assertNotNull("test.def2 definition not found.", definitions.getDefinition("test.def1"));
-        assertNotNull("test.def3 definition not found.", definitions.getDefinition("test.def1"));
+        assertNotNull("test.def2 definition not found.", definitions.getDefinition("test.def2"));
+        assertNotNull("test.def3 definition not found.", definitions.getDefinition("test.def3"));
+    }
+
+    /**
+     * Tests the getDefinition method.
+     */
+    public void testGetDefinition() throws Exception {
+        DefinitionsFactory factory = new UrlDefinitionsFactory();
+
+        // Set up multiple data sources.
+        URL url1 = this.getClass().getClassLoader().getResource(
+                "org/apache/tiles/config/defs1.xml");
+        assertNotNull("Could not load defs1 file.", url1);
+        URL url2 = this.getClass().getClassLoader().getResource(
+                "org/apache/tiles/config/defs2.xml");
+        assertNotNull("Could not load defs2 file.", url2);
+        URL url3 = this.getClass().getClassLoader().getResource(
+                "org/apache/tiles/config/defs3.xml");
+        assertNotNull("Could not load defs3 file.", url3);
+
+        factory.init(Collections.EMPTY_MAP);
+        factory.addSource(url1);
+        factory.addSource(url2);
+        factory.addSource(url3);
+
+        // Parse files.
+        factory.readDefinitions();
+        
+        TilesRequestContext emptyContext = new MockOnlyLocaleTilesContext(null);
+        TilesRequestContext usContext = new MockOnlyLocaleTilesContext(Locale.US);
+        TilesRequestContext frenchContext = new MockOnlyLocaleTilesContext(Locale.FRENCH);
+        TilesRequestContext chinaContext = new MockOnlyLocaleTilesContext(Locale.CHINA);
+        TilesRequestContext canadaFrenchContext = new MockOnlyLocaleTilesContext(Locale.CANADA_FRENCH);
+
+        assertNotNull("test.def1 definition not found.", factory.getDefinition("test.def1", emptyContext));
+        assertNotNull("test.def2 definition not found.", factory.getDefinition("test.def2", emptyContext));
+        assertNotNull("test.def3 definition not found.", factory.getDefinition("test.def3", emptyContext));
+        assertNotNull("test.common definition not found.", factory.getDefinition("test.common", emptyContext));
+        assertNotNull("test.common definition in US locale not found.", factory.getDefinition("test.common", usContext));
+        assertNotNull("test.common definition in FRENCH locale not found.", factory.getDefinition("test.common", frenchContext));
+        assertNotNull("test.common definition in CHINA locale not found.", factory.getDefinition("test.common", chinaContext));
+        assertNotNull("test.common.french definition in FRENCH locale not found.", factory.getDefinition("test.common.french", frenchContext));
+        assertNotNull("test.common.french definition in CANADA_FRENCH locale not found.", factory.getDefinition("test.common.french", canadaFrenchContext));
+
+        assertEquals("Incorrect default country value", "default",
+                factory.getDefinition("test.def1", emptyContext).getAttribute("country"));
+        assertEquals("Incorrect US country value", "US",
+                factory.getDefinition("test.def1", usContext).getAttribute("country"));
+        assertEquals("Incorrect France country value", "France",
+                factory.getDefinition("test.def1", frenchContext).getAttribute("country"));
+        assertEquals("Incorrect Chinese country value (should be default)", "default",
+                factory.getDefinition("test.def1", chinaContext).getAttribute("country"));
     }
 
     /**