You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tiles.apache.org by ap...@apache.org on 2007/04/24 14:33:19 UTC

svn commit: r531904 - in /tiles/framework/trunk/tiles-core/src: main/java/org/apache/tiles/context/ChainedTilesContextFactory.java test/java/org/apache/tiles/context/ChainedTilesContextFactoryTest.java

Author: apetrelli
Date: Tue Apr 24 05:33:18 2007
New Revision: 531904

URL: http://svn.apache.org/viewvc?view=rev&rev=531904
Log:
TILES-161
Now the ChainedTilesContextFactory.factories array has no null values.
Created a test case.

Added:
    tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/context/ChainedTilesContextFactoryTest.java   (with props)
Modified:
    tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/ChainedTilesContextFactory.java

Modified: tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/ChainedTilesContextFactory.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/ChainedTilesContextFactory.java?view=diff&rev=531904&r1=531903&r2=531904
==============================================================================
--- tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/ChainedTilesContextFactory.java (original)
+++ tiles/framework/trunk/tiles-core/src/main/java/org/apache/tiles/context/ChainedTilesContextFactory.java Tue Apr 24 05:33:18 2007
@@ -25,6 +25,8 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.tiles.TilesApplicationContext;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -72,13 +74,15 @@
             classNames = DEFAULT_FACTORY_CLASS_NAMES;
         }
 
-        factories = new TilesContextFactory[classNames.length];
+        List<TilesContextFactory> factoryList =
+            new ArrayList<TilesContextFactory>();
         for (int i = 0; i < classNames.length; i++) {
             try {
                 Class<TilesContextFactory> clazz = (Class<TilesContextFactory>) Class
                         .forName(classNames[i]);
                 if (TilesContextFactory.class.isAssignableFrom(clazz)) {
-                    factories[i] = clazz.newInstance();
+                    TilesContextFactory factory = clazz.newInstance();
+                    factoryList.add(factory);
                 } else {
                     throw new IllegalArgumentException("The class "
                             + classNames[i]
@@ -99,6 +103,8 @@
                                 + " default constructor", e);
             }
         }
+        factories = new TilesContextFactory[factoryList.size()];
+        factoryList.toArray(factories);
     }
 
     /** {@inheritDoc} */

Added: tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/context/ChainedTilesContextFactoryTest.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/context/ChainedTilesContextFactoryTest.java?view=auto&rev=531904
==============================================================================
--- tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/context/ChainedTilesContextFactoryTest.java (added)
+++ tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/context/ChainedTilesContextFactoryTest.java Tue Apr 24 05:33:18 2007
@@ -0,0 +1,87 @@
+/*
+ * $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.context;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.shale.test.mock.MockHttpServletRequest;
+import org.apache.shale.test.mock.MockHttpServletResponse;
+import org.apache.shale.test.mock.MockHttpSession;
+import org.apache.shale.test.mock.MockServletContext;
+import org.apache.tiles.TilesApplicationContext;
+import org.apache.tiles.servlet.context.ServletTilesApplicationContext;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ChainedTilesContextFactoryTest extends TestCase {
+
+    /**
+     * The request object.
+     */
+    private HttpServletRequest request;
+
+    /**
+     * The request object.
+     */
+    private HttpServletResponse response;
+
+    /**
+     * The Tiles application context.
+     */
+    private TilesApplicationContext appContext;
+
+    /** {@inheritDoc} */
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        MockServletContext servletContext = new MockServletContext();
+        appContext = new ServletTilesApplicationContext(servletContext);
+        MockHttpSession session = new MockHttpSession(servletContext);
+        MockHttpServletRequest request = new MockHttpServletRequest(session);
+        MockHttpServletResponse response = new MockHttpServletResponse();
+        this.request = request;
+        this.response = response;
+    }
+
+    /**
+     * Tests the initialization method.
+     *
+     * @throws Exception If something goes wrong during testing.
+     */
+    public void testInit() throws Exception {
+        Map<String, String> config = new HashMap<String, String>();
+        config.put(ChainedTilesContextFactory.FACTORY_CLASS_NAMES,
+                "this.is.not.a.class.Name,"
+                + "org.apache.tiles.servlet.context.ServletTilesContextFactory");
+        ChainedTilesContextFactory factory = new ChainedTilesContextFactory();
+        factory.init(config);
+        TilesRequestContext context = factory.createRequestContext(appContext,
+                request, response);
+        assertNotNull("The request context cannot be null", context);
+    }
+}

Propchange: tiles/framework/trunk/tiles-core/src/test/java/org/apache/tiles/context/ChainedTilesContextFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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