tiles-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r931640 - in /tiles/sandbox/trunk/tiles-request/tiles-request-api: ./ src/main/java/org/apache/tiles/request/ src/test/java/org/ src/test/java/org/apache/ src/test/java/org/apache/tiles/ src/test/java/org/apache/tiles/request/
Date Wed, 07 Apr 2010 18:54:13 GMT
Author: apetrelli
Date: Wed Apr  7 18:54:13 2010
New Revision: 931640

URL: http://svn.apache.org/viewvc?rev=931640&view=rev
Log:
TILESSB-11
Some tests for tiles-request-api.

Added:
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractClientRequestTest.java
  (with props)
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractRequestTest.java
  (with props)
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractViewRequestTest.java
  (with props)
Modified:
    tiles/sandbox/trunk/tiles-request/tiles-request-api/pom.xml
    tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/AbstractClientRequest.java

Modified: tiles/sandbox/trunk/tiles-request/tiles-request-api/pom.xml
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/pom.xml?rev=931640&r1=931639&r2=931640&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/pom.xml (original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/pom.xml Wed Apr  7 18:54:13 2010
@@ -18,5 +18,11 @@
 			<version>4.7</version>
 			<scope>test</scope>
 		</dependency>
+		<dependency>
+			<groupId>org.easymock</groupId>
+			<artifactId>easymockclassextension</artifactId>
+			<version>2.5.2</version>
+			<scope>test</scope>
+		</dependency>
 	</dependencies>
 </project>
\ No newline at end of file

Modified: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/AbstractClientRequest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/AbstractClientRequest.java?rev=931640&r1=931639&r2=931640&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/AbstractClientRequest.java
(original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/main/java/org/apache/tiles/request/AbstractClientRequest.java
Wed Apr  7 18:54:13 2010
@@ -18,10 +18,10 @@ public abstract class AbstractClientRequ
     @Override
     public void dispatch(String path) throws IOException {
         if (isForceInclude()) {
+            doInclude(path);
+        } else {
             setForceInclude(true);
             doForward(path);
-        } else {
-            doInclude(path);
         }
     }
 

Added: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractClientRequestTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractClientRequestTest.java?rev=931640&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractClientRequestTest.java
(added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractClientRequestTest.java
Wed Apr  7 18:54:13 2010
@@ -0,0 +1,134 @@
+/**
+ *
+ */
+package org.apache.tiles.request;
+
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tiles.request.scope.ContextResolver;
+import org.apache.tiles.request.util.ApplicationAccess;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link AbstractClientRequest}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class AbstractClientRequestTest {
+
+    private AbstractClientRequest request;
+
+    private ApplicationContext applicationContext;
+
+    private Map<String, Object> applicationScope;
+
+    private ContextResolver contextResolver;
+
+    /**
+     * Sets up the test.
+     */
+    @Before
+    public void setUp() {
+        applicationContext = createMock(ApplicationContext.class);
+        applicationScope = new HashMap<String, Object>();
+        contextResolver = createMock(ContextResolver.class);
+        applicationScope.put(ApplicationAccess.CONTEXT_RESOLVER_ATTRIBUTE, contextResolver);
+        request = createMockBuilder(AbstractClientRequest.class)
+                .withConstructor(applicationContext).createMock();
+
+        expect(applicationContext.getApplicationScope()).andReturn(applicationScope).anyTimes();
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.AbstractClientRequest#dispatch(java.lang.String)}.
+     * @throws IOException If something goes wrong.
+     */
+    @Test
+    public void testDispatch() throws IOException {
+        Map<String, Object> requestScope = new HashMap<String, Object>();
+
+        expect(contextResolver.getContext(request, "request")).andReturn(
+                requestScope).anyTimes();
+        request.doForward("/my/path.html");
+        request.doInclude("/my/path2.html");
+
+        replay(request, applicationContext, contextResolver);
+        request.dispatch("/my/path.html");
+        request.dispatch("/my/path2.html");
+        verify(request, applicationContext, contextResolver);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.AbstractClientRequest#include(java.lang.String)}.
+     * @throws IOException If something goes wrong.
+     */
+    @Test
+    public void testInclude() throws IOException {
+        Map<String, Object> requestScope = new HashMap<String, Object>();
+
+        expect(contextResolver.getContext(request, "request")).andReturn(
+                requestScope).anyTimes();
+        request.doInclude("/my/path2.html");
+
+        replay(request, applicationContext, contextResolver);
+        request.include("/my/path2.html");
+        assertTrue((Boolean) requestScope.get(AbstractRequest.FORCE_INCLUDE_ATTRIBUTE_NAME));
+        verify(request, applicationContext, contextResolver);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.AbstractClientRequest#getApplicationContext()}.
+     */
+    @Test
+    public void testGetApplicationContext() {
+        replay(request, applicationContext, contextResolver);
+        assertEquals(applicationContext, request.getApplicationContext());
+        verify(request, applicationContext, contextResolver);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.AbstractClientRequest#getContext(java.lang.String)}.
+     */
+    @SuppressWarnings("unchecked")
+    @Test
+    public void testGetContext() {
+        Map<String, Object> scope = createMock(Map.class);
+
+        expect(contextResolver.getContext(request, "myScope")).andReturn(scope);
+
+        replay(request, applicationContext, contextResolver, scope);
+        assertEquals(scope, request.getContext("myScope"));
+        verify(request, applicationContext, contextResolver, scope);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.AbstractClientRequest#getAvailableScopes()}.
+     */
+    @Test
+    public void testGetAvailableScopes() {
+        String[] scopes = new String[] {"one", "two", "three"};
+
+        expect(contextResolver.getAvailableScopes(request)).andReturn(scopes);
+
+        replay(request, applicationContext, contextResolver);
+        assertArrayEquals(scopes, request.getAvailableScopes());
+        verify(request, applicationContext, contextResolver);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.AbstractClientRequest#getApplicationScope()}.
+     */
+    @Test
+    public void testGetApplicationScope() {
+        replay(request, applicationContext, contextResolver);
+        assertEquals(applicationScope, request.getApplicationScope());
+        verify(request, applicationContext, contextResolver);
+    }
+
+}

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractClientRequestTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractClientRequestTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractRequestTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractRequestTest.java?rev=931640&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractRequestTest.java
(added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractRequestTest.java
Wed Apr  7 18:54:13 2010
@@ -0,0 +1,37 @@
+/**
+ *
+ */
+package org.apache.tiles.request;
+
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+
+/**
+ * Tests {@link AbstractRequest}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class AbstractRequestTest {
+
+    /**
+     * Test method for {@link org.apache.tiles.request.AbstractRequest#setForceInclude(boolean)}.
+     */
+    @Test
+    public void testSetForceInclude() {
+        AbstractRequest request = createMockBuilder(AbstractRequest.class).createMock();
+        Map<String, Object> scope = new HashMap<String, Object>();
+
+        expect(request.getContext("request")).andReturn(scope).anyTimes();
+
+        replay(request);
+        assertFalse(request.isForceInclude());
+        request.setForceInclude(true);
+        assertTrue(request.isForceInclude());
+        verify(request);
+    }
+}

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractRequestTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractRequestTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractViewRequestTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractViewRequestTest.java?rev=931640&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractViewRequestTest.java
(added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractViewRequestTest.java
Wed Apr  7 18:54:13 2010
@@ -0,0 +1,99 @@
+/**
+ *
+ */
+package org.apache.tiles.request;
+
+import static org.junit.Assert.*;
+import static org.easymock.classextension.EasyMock.*;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tiles.request.scope.ContextResolver;
+import org.apache.tiles.request.util.ApplicationAccess;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @author antonio
+ *
+ * @version $Rev$ $Date$
+ */
+public class AbstractViewRequestTest {
+
+    private AbstractViewRequest request;
+
+    private Request wrappedRequest;
+
+    private ApplicationContext applicationContext;
+
+    private ContextResolver contextResolver;
+
+    private Map<String, Object> applicationScope;
+
+    /**
+     * Sets up the test.
+     */
+    @Before
+    public void setUp() {
+        wrappedRequest = createMock(Request.class);
+        request = createMockBuilder(AbstractViewRequest.class).withConstructor(
+                wrappedRequest).createMock();
+        applicationContext = createMock(ApplicationContext.class);
+        applicationScope = new HashMap<String, Object>();
+        contextResolver = createMock(ContextResolver.class);
+        applicationScope.put(ApplicationAccess.CONTEXT_RESOLVER_ATTRIBUTE, contextResolver);
+
+        expect(wrappedRequest.getApplicationContext()).andReturn(applicationContext).anyTimes();
+        expect(applicationContext.getApplicationScope()).andReturn(applicationScope).anyTimes();
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.AbstractViewRequest#dispatch(java.lang.String)}.
+     * @throws IOException If something goes wrong.
+     */
+    @Test
+    public void testDispatch() throws IOException {
+        Map<String, Object> requestScope = new HashMap<String, Object>();
+
+        expect(contextResolver.getContext(request, "request")).andReturn(requestScope);
+        wrappedRequest.include("/my/path.html");
+
+        replay(wrappedRequest, request, applicationContext, contextResolver);
+        request.dispatch("/my/path.html");
+        assertTrue((Boolean) requestScope.get(AbstractRequest.FORCE_INCLUDE_ATTRIBUTE_NAME));
+        verify(wrappedRequest, request, applicationContext, contextResolver);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.AbstractViewRequest#include(java.lang.String)}.
+     * @throws IOException If something goes wrong.
+     */
+    @Test
+    public void testInclude() throws IOException {
+        Map<String, Object> requestScope = new HashMap<String, Object>();
+
+        expect(contextResolver.getContext(request, "request")).andReturn(requestScope);
+        wrappedRequest.include("/my/path.html");
+
+        replay(wrappedRequest, request, applicationContext, contextResolver);
+        request.include("/my/path.html");
+        assertTrue((Boolean) requestScope.get(AbstractRequest.FORCE_INCLUDE_ATTRIBUTE_NAME));
+        verify(wrappedRequest, request, applicationContext, contextResolver);
+    }
+
+    /**
+     * Test method for {@link org.apache.tiles.request.AbstractViewRequest#doInclude(java.lang.String)}.
+     * @throws IOException If something goes wrong.
+     */
+    @Test
+    public void testDoInclude() throws IOException {
+        wrappedRequest.include("/my/path.html");
+
+        replay(wrappedRequest, request, applicationContext, contextResolver);
+        request.doInclude("/my/path.html");
+        verify(wrappedRequest, request, applicationContext, contextResolver);
+    }
+
+}

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractViewRequestTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-api/src/test/java/org/apache/tiles/request/AbstractViewRequestTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL



Mime
View raw message