Modified: 
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestUrlDefinitionsFactory.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestUrlDefinitionsFactory.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestUrlDefinitionsFactory.java
 (original)
+++ 
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/TestUrlDefinitionsFactory.java
 Wed Nov  1 12:15:09 2006
@@ -22,11 +22,12 @@
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Collections;
+
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 import org.apache.tiles.definition.UrlDefinitionsFactory;
-import org.apache.tiles.mock.MockComponentDefinitions;
 import org.apache.tiles.mock.MockPublicUrlDefinitionsFactory;
 import org.apache.tiles.mock.MockDefinitionsReader;
 import org.apache.tiles.mock.MockOnlyLocaleTilesContext;
@@ -34,11 +35,13 @@
 /**
  * Tests the UrlDefinitionsFactory component.
  *
- * @version $Rev$ $Date$ 
+ * @version $Rev$ $Date$
  */
 public class TestUrlDefinitionsFactory extends TestCase {
-    
-    /** Creates a new instance of TestUrlDefinitionsFactory */
+
+    /**
+     * Creates a new instance of TestUrlDefinitionsFactory
+     */
     public TestUrlDefinitionsFactory(String name) {
         super(name);
     }
@@ -50,7 +53,7 @@
      */
     public static void main(String[] theArgs) {
         junit.textui.TestRunner.main(
-            new String[] { TestUrlDefinitionsFactory.class.getName()});
+                new String[]{TestUrlDefinitionsFactory.class.getName()});
     }
 
     /**
@@ -64,190 +67,143 @@
     /**
      * Tests the readDefinitions method under normal conditions.
      */
-    public void testReadDefinitions() {
-        try {
-            DefinitionsFactory factory = new UrlDefinitionsFactory();
+    public void testReadDefinitions() 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(null);
-            factory.addSource(url1);
-            factory.addSource(url2);
-            factory.addSource(url3);
-
-            // Parse files.
-            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"));
-        } catch (Exception e) {
-            fail("Error running test: " + e);
-        }
+        // 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.
+        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"));
     }
-    
+
     /**
      * Tests addSource with a bad source object type.
      */
-    public void testBadSourceType() {
+    public void testBadSourceType() throws Exception {
         try {
             DefinitionsFactory factory = new UrlDefinitionsFactory();
 
-            factory.init(null);
+            factory.init(Collections.EMPTY_MAP);
             factory.addSource("Bad object.");
-            
+
             fail("Should've thrown exception.");
         } catch (DefinitionsFactoryException e) {
             // success.
-        } catch (Exception e) {
-            fail("Error running test: " + e);
         }
     }
-    
+
     /**
      * Tests the addDefinitions method under normal
      * circumstances.
      */
-    public void testReadByLocale() {
-        try {
-            MockPublicUrlDefinitionsFactory factory = new 
MockPublicUrlDefinitionsFactory();
+    public void testReadByLocale() throws Exception {
+        MockPublicUrlDefinitionsFactory factory = new 
MockPublicUrlDefinitionsFactory();
 
-            // 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(null);
-            factory.addSource(url1);
-            factory.addSource(url2);
-            factory.addSource(url3);
-
-            // Parse files.
-            ComponentDefinitions definitions = factory.readDefinitions();
-            factory.addDefinitions(definitions,
-                    new MockOnlyLocaleTilesContext(Locale.US));
-            factory.addDefinitions(definitions,
-                    new MockOnlyLocaleTilesContext(Locale.FRENCH));
-            
-            assertNotNull("test.def1 definition not found.", 
definitions.getDefinition("test.def1"));
-            assertNotNull("test.def1 US definition not found.", 
definitions.getDefinition("test.def1", Locale.US));
-            assertNotNull("test.def1 France definition not found.", 
definitions.getDefinition("test.def1", Locale.FRENCH));
-            assertNotNull("test.def1 China should return default.", 
definitions.getDefinition("test.def1", Locale.CHINA));
-            
-            assertEquals("Incorrect default country value", "default",
-                    
definitions.getDefinition("test.def1").getAttribute("country"));
-            assertEquals("Incorrect US country value", "US",
-                    definitions.getDefinition("test.def1", 
Locale.US).getAttribute("country"));
-            assertEquals("Incorrect France country value", "France",
-                    definitions.getDefinition("test.def1", 
Locale.FRENCH).getAttribute("country"));
-            assertEquals("Incorrect Chinese country value (should default)", 
"default",
-                    definitions.getDefinition("test.def1", 
Locale.CHINA).getAttribute("country"));
-        } catch (Exception e) {
-            fail("Error running test: " + e);
-        }
-        
+        // 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.
+        ComponentDefinitions definitions = factory.readDefinitions();
+        factory.addDefinitions(definitions,
+                new MockOnlyLocaleTilesContext(Locale.US));
+        factory.addDefinitions(definitions,
+                new MockOnlyLocaleTilesContext(Locale.FRENCH));
+
+        assertNotNull("test.def1 definition not found.", 
definitions.getDefinition("test.def1"));
+        assertNotNull("test.def1 US definition not found.", 
definitions.getDefinition("test.def1", Locale.US));
+        assertNotNull("test.def1 France definition not found.", 
definitions.getDefinition("test.def1", Locale.FRENCH));
+        assertNotNull("test.def1 China should return default.", 
definitions.getDefinition("test.def1", Locale.CHINA));
+
+        assertEquals("Incorrect default country value", "default",
+                
definitions.getDefinition("test.def1").getAttribute("country"));
+        assertEquals("Incorrect US country value", "US",
+                definitions.getDefinition("test.def1", 
Locale.US).getAttribute("country"));
+        assertEquals("Incorrect France country value", "France",
+                definitions.getDefinition("test.def1", 
Locale.FRENCH).getAttribute("country"));
+        assertEquals("Incorrect Chinese country value (should default)", 
"default",
+                definitions.getDefinition("test.def1", 
Locale.CHINA).getAttribute("country"));
     }
-    
+
     /**
      * Tests the isLocaleProcessed method.
      */
-    public void testIsLocaleProcessed() {
-        try {
-            MockPublicUrlDefinitionsFactory factory = new 
MockPublicUrlDefinitionsFactory();
+    public void testIsLocaleProcessed() throws Exception {
+        MockPublicUrlDefinitionsFactory factory = new 
MockPublicUrlDefinitionsFactory();
 
-            // Set up multiple data sources.
-            URL url1 = this.getClass().getClassLoader().getResource(
-                    "org/apache/tiles/config/defs1.xml");
-            assertNotNull("Could not load defs1 file.", url1);
-
-            factory.init(null);
-            factory.addSource(url1);
-
-            // Parse files.
-            ComponentDefinitions definitions = factory.readDefinitions();
-            TilesRequestContext tilesContext =
-                    new MockOnlyLocaleTilesContext(Locale.US);
-            assertFalse("Locale should not be processed.", 
-                    factory.isContextProcessed(tilesContext));
-            
-            factory.addDefinitions(definitions, tilesContext);
-            assertTrue("Locale should be processed.",
-                    factory.isContextProcessed(tilesContext));
-            
-        } catch (Exception e) {
-            fail("Error running test: " + e);
-        }
+        // Set up multiple data sources.
+        URL url1 = this.getClass().getClassLoader().getResource(
+                "org/apache/tiles/config/defs1.xml");
+        assertNotNull("Could not load defs1 file.", url1);
+
+        factory.init(Collections.EMPTY_MAP);
+        factory.addSource(url1);
+
+        // Parse files.
+        ComponentDefinitions definitions = factory.readDefinitions();
+        TilesRequestContext tilesContext =
+                new MockOnlyLocaleTilesContext(Locale.US);
+        assertFalse("Locale should not be processed.",
+                factory.isLocaleProcessed(tilesContext));
+
+        factory.addDefinitions(definitions, tilesContext);
+        assertTrue("Locale should be processed.",
+                factory.isLocaleProcessed(tilesContext));
     }
-    
+
     /**
      * Tests the reader init param.
      */
-    public void testReaderParam() {
+    public void testReaderParam() throws Exception {
         Map params = new HashMap();
-        params.put(DefinitionsFactory.READER_IMPL_PROPERTY, 
+        params.put(DefinitionsFactory.READER_IMPL_PROPERTY,
                 "org.apache.tiles.mock.MockDefinitionsReader");
 
         int instanceCount = MockDefinitionsReader.getInstanceCount();
-        
-        try {
-            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);
-
-            factory.init(params);
-            factory.addSource(url1);
-
-            assertEquals("MockDefinitionsReader not used.",  
-                    instanceCount + 1,
-                    MockDefinitionsReader.getInstanceCount());
-        } catch (Exception e) {
-            fail("Error running test: " + e);
-        }
-    }
-    
-    /**
-     * Tests the ComponentDefinitions init param.
-     */
-    public void testComponentDefinitionsParam() {
-        Map params = new HashMap();
-        params.put(DefinitionsFactory.DEFINITIONS_IMPL_PROPERTY, 
-                "org.apache.tiles.mock.MockComponentDefinitions");
 
-        try {
-            DefinitionsFactory factory = new UrlDefinitionsFactory();
+        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);
-
-            factory.init(params);
-            factory.addSource(url1);
-            ComponentDefinitions defs = factory.readDefinitions();
-
-            assertNotNull("Definitions not read.", defs);
-            assertTrue("Incorrect definitions type.", 
-                    defs instanceof MockComponentDefinitions);
-        } catch (Exception e) {
-            fail("Error running test: " + e);
-        }
+        // Set up multiple data sources.
+        URL url1 = this.getClass().getClassLoader().getResource(
+                "org/apache/tiles/config/defs1.xml");
+        assertNotNull("Could not load defs1 file.", url1);
+
+        factory.init(params);
+        factory.addSource(url1);
+
+        assertEquals("MockDefinitionsReader not used.",
+                instanceCount + 1,
+                MockDefinitionsReader.getInstanceCount());
     }
+
 }

Added: 
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/UrlDefinitionsFactoryTest.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/UrlDefinitionsFactoryTest.java?view=auto&rev=470071
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/UrlDefinitionsFactoryTest.java
 (added)
+++ 
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/UrlDefinitionsFactoryTest.java
 Wed Nov  1 12:15:09 2006
@@ -0,0 +1,56 @@
+/*
+ * $Id$
+ *
+ * Copyright 2006 The Apache Software Foundation.
+ *
+ * Licensed 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.definition;
+
+import junit.framework.TestCase;
+
+import java.util.Locale;
+import java.util.List;
+
+
+public class UrlDefinitionsFactoryTest extends TestCase {
+
+    private UrlDefinitionsFactory factory; 
+
+    public void setUp() {
+        factory = new UrlDefinitionsFactory();
+    }
+
+    public void testCalculatePostfixes() {
+        Locale locale = Locale.US;
+
+        List<String> posts = UrlDefinitionsFactory.calculatePostixes(locale);
+        assertEquals(2, posts.size());
+        assertTrue(posts.contains("_en_US"));
+        assertTrue(posts.contains("_en"));
+
+        locale = Locale.ENGLISH;
+        posts = UrlDefinitionsFactory.calculatePostixes(locale);
+        assertEquals(1, posts.size());
+        assertTrue(posts.contains("_en"));
+    }
+
+    public void testCancatPostfix() {
+        String postfix = "_en_US";
+        assertEquals("a_en_US", factory.concatPostfix("a", postfix));
+        assertEquals("a_en_US.jsp", factory.concatPostfix("a.jsp", postfix));
+        assertEquals("file_en_US.jsp", factory.concatPostfix("file.jsp", 
postfix));
+        assertEquals("./path/file_en_US.jsp", 
factory.concatPostfix("./path/file.jsp", postfix));
+    }
+
+}

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

Propchange: 
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/definition/UrlDefinitionsFactoryTest.java
------------------------------------------------------------------------------
    svn:keywords = Id Author Date

Modified: 
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockDefinitionsReader.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockDefinitionsReader.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockDefinitionsReader.java
 (original)
+++ 
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockDefinitionsReader.java
 Wed Nov  1 12:15:09 2006
@@ -20,6 +20,8 @@
 
 import org.apache.tiles.DefinitionsReader;
 
+import java.util.Collections;
+
 /**
  * Mock Defintions Reader implementation.  Stubs out all functionality.
  *
@@ -45,27 +47,27 @@
     }
 
     /**
-     * Reads <code>[EMAIL PROTECTED] ComponentDefinition}</code> objects from 
a source.
+     * Reads <code>[EMAIL PROTECTED] 
org.apache.tiles.ComponentDefinition}</code> objects from a source.
      * 
      * Implementations should publish what type of source object is expected.
      * 
      * @param source The source from which definitions will be read.
      * @return a Map of <code>ComponentDefinition</code> objects read from
      *  the source.
-     * @throws DefinitionsFactoryException if the source is invalid or
+     * @throws org.apache.tiles.DefinitionsFactoryException if the source is 
invalid or
      *  an error occurs when reading definitions.
      */
     public java.util.Map read(Object source) throws 
org.apache.tiles.DefinitionsFactoryException {
-        return null;
+        return Collections.EMPTY_MAP;
     }
 
     /**
      * Initializes the <code>DefinitionsReader</code> object.
      * 
-     * This method must be called before the [EMAIL PROTECTED] read} method is 
called.
+     * This method must be called before the [EMAIL PROTECTED] #read} method 
is called.
      * 
      * @param params A map of properties used to set up the reader.
-     * @throws DefinitionsFactoryException if required properties are not
+     * @throws org.apache.tiles.DefinitionsFactoryException if required 
properties are not
      *  passed in or the initialization fails.
      */
     public void init(java.util.Map params) throws 
org.apache.tiles.DefinitionsFactoryException {

Modified: 
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockPublicUrlDefinitionsFactory.java
URL: 
http://svn.apache.org/viewvc/struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockPublicUrlDefinitionsFactory.java?view=diff&rev=470071&r1=470070&r2=470071
==============================================================================
--- 
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockPublicUrlDefinitionsFactory.java
 (original)
+++ 
struts/sandbox/trunk/tiles/tiles-core/src/test/java/org/apache/tiles/mock/MockPublicUrlDefinitionsFactory.java
 Wed Nov  1 12:15:09 2006
@@ -45,12 +45,12 @@
 
     /**
      * 
-     * Exposes the <code>isContextProcessed</code> method of
+     * Exposes the <code>isLocaleProcessed</code> method of
      * <code>UrlDefinitionsFactory</code>
      * 
-     * @see 
org.apache.tiles.definition.UrlDefinitionsFactory#isContextProcessed(org.apache.tiles.TilesRequestContext)
+     * @see 
org.apache.tiles.definition.UrlDefinitionsFactory#isLocaleProcessed(org.apache.tiles.TilesRequestContext)
      */
-    public boolean isContextProcessed(TilesRequestContext tilesContext) {
-        return super.isContextProcessed(tilesContext);
+    public boolean isLocaleProcessed(TilesRequestContext tilesContext) {
+        return super.isLocaleProcessed(tilesContext);
     }
 }


Reply via email to