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 2008/11/06 11:12:17 UTC

svn commit: r711831 - /tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/tiles/jsp/context/JspTilesContextFactoryTest.java

Author: apetrelli
Date: Thu Nov  6 02:12:15 2008
New Revision: 711831

URL: http://svn.apache.org/viewvc?rev=711831&view=rev
Log:
TILES-329
Added test for JspTilesContextFactory.

Added:
    tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/tiles/jsp/context/JspTilesContextFactoryTest.java   (with props)

Added: tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/tiles/jsp/context/JspTilesContextFactoryTest.java
URL: http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/tiles/jsp/context/JspTilesContextFactoryTest.java?rev=711831&view=auto
==============================================================================
--- tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/tiles/jsp/context/JspTilesContextFactoryTest.java (added)
+++ tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/tiles/jsp/context/JspTilesContextFactoryTest.java Thu Nov  6 02:12:15 2008
@@ -0,0 +1,108 @@
+/*
+ * $Id: JspUtilTest.java 657919 2008-05-19 18:52:49Z 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.
+ */
+
+package org.apache.tiles.jsp.context;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.PageContext;
+
+import org.apache.tiles.TilesApplicationContext;
+import org.apache.tiles.context.TilesContextFactory;
+import org.apache.tiles.context.TilesRequestContext;
+import org.apache.tiles.servlet.context.ServletTilesRequestContext;
+import org.easymock.classextension.EasyMock;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests {@link JspTilesContextFactory}.
+ *
+ * @version $Rev: 657919 $ $Date: 2008-05-19 20:52:49 +0200 (lun, 19 mag 2008) $
+ */
+public class JspTilesContextFactoryTest extends TestCase {
+
+    /**
+     * The object under test.
+     */
+    private JspTilesContextFactory factory;
+
+    /** {@inheritDoc} */
+    @Override
+    protected void setUp() throws Exception {
+        factory = new JspTilesContextFactory();
+    }
+
+    /**
+     * Tests
+     * {@link JspTilesContextFactory#createRequestContext(org.apache.tiles.TilesApplicationContext, Object...)}
+     * .
+     */
+    public void testCreateRequestContextWithoutParent() {
+        TilesApplicationContext context = EasyMock
+                .createMock(TilesApplicationContext.class);
+        PageContext pageContext = EasyMock.createMock(PageContext.class);
+        HttpServletRequest httpRequest = EasyMock
+                .createMock(HttpServletRequest.class);
+        HttpServletResponse httpResponse = EasyMock
+                .createMock(HttpServletResponse.class);
+        EasyMock.expect(pageContext.getRequest()).andReturn(httpRequest);
+        EasyMock.expect(pageContext.getResponse()).andReturn(httpResponse);
+        EasyMock.replay(context, pageContext, httpRequest, httpResponse);
+        JspTilesRequestContext request = (JspTilesRequestContext) factory
+                .createRequestContext(context, pageContext);
+        assertTrue("The enclosed request is not of the correct class", request
+                .getWrappedRequest() instanceof ServletTilesRequestContext);
+        EasyMock.verify(context, pageContext, httpRequest, httpResponse);
+    }
+
+    /**
+     * Tests
+     * {@link JspTilesContextFactory#createRequestContext(org.apache.tiles.TilesApplicationContext, Object...)}
+     * .
+     */
+    public void testCreateRequestContextWithParent() {
+        TilesApplicationContext context = EasyMock
+                .createMock(TilesApplicationContext.class);
+        PageContext pageContext = EasyMock.createMock(PageContext.class);
+        HttpServletRequest httpRequest = EasyMock
+                .createMock(HttpServletRequest.class);
+        HttpServletResponse httpResponse = EasyMock
+                .createMock(HttpServletResponse.class);
+        EasyMock.expect(pageContext.getRequest()).andReturn(httpRequest);
+        EasyMock.expect(pageContext.getResponse()).andReturn(httpResponse);
+
+        TilesContextFactory parent = EasyMock
+                .createMock(TilesContextFactory.class);
+        TilesRequestContext enclosedRequest = EasyMock
+                .createMock(TilesRequestContext.class);
+        EasyMock.expect(parent.createRequestContext(context, httpRequest,
+                httpResponse)).andReturn(enclosedRequest);
+        factory.setRequestContextFactory(parent);
+
+        EasyMock.replay(context, pageContext, httpRequest, httpResponse, parent);
+        JspTilesRequestContext request = (JspTilesRequestContext) factory
+                .createRequestContext(context, pageContext);
+        assertTrue("The enclosed request is not the correct one", request
+                .getWrappedRequest() == enclosedRequest);
+        EasyMock.verify(context, pageContext, httpRequest, httpResponse, parent);
+    }
+}

Propchange: tiles/framework/trunk/tiles-jsp/src/test/java/org/apache/tiles/jsp/context/JspTilesContextFactoryTest.java
------------------------------------------------------------------------------
    svn:mergeinfo =