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 2010/05/06 21:25:24 UTC
svn commit: r941871 - in
/tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src:
main/java/org/apache/tiles/request/jsp/
main/java/org/apache/tiles/request/jsp/extractor/
test/java/org/apache/tiles/request/jsp/
test/java/org/apache/tiles/request/jsp/...
Author: apetrelli
Date: Thu May 6 19:25:23 2010
New Revision: 941871
URL: http://svn.apache.org/viewvc?rev=941871&view=rev
Log:
TILESSB-31
Refactored JSP support.
100% test code coverage.
Added:
tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/extractor/
tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/extractor/ScopeExtractor.java (with props)
tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/extractor/SessionScopeExtractor.java (with props)
tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspRequestTest.java (with props)
tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspUtilTest.java (with props)
tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/extractor/
tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/extractor/ScopeExtractorTest.java (with props)
tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/extractor/SessionScopeExtractorTest.java (with props)
Removed:
tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/JspScopeMap.java
tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/JspSessionScopeMap.java
Modified:
tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/JspRequest.java
tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspPrintWriterAdapterTest.java
Modified: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/JspRequest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/JspRequest.java?rev=941871&r1=941870&r2=941871&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/JspRequest.java (original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/JspRequest.java Thu May 6 19:25:23 2010
@@ -33,6 +33,9 @@ import javax.servlet.jsp.PageContext;
import org.apache.tiles.request.AbstractViewRequest;
import org.apache.tiles.request.ApplicationContext;
import org.apache.tiles.request.Request;
+import org.apache.tiles.request.collection.ScopeMap;
+import org.apache.tiles.request.jsp.extractor.ScopeExtractor;
+import org.apache.tiles.request.jsp.extractor.SessionScopeExtractor;
import org.apache.tiles.request.servlet.ServletRequest;
import org.apache.tiles.request.servlet.ServletUtil;
@@ -129,28 +132,31 @@ public class JspRequest extends Abstract
public Map<String, Object> getPageScope() {
if ((pageScope == null) && (pageContext != null)) {
- pageScope = new JspScopeMap(pageContext, PageContext.PAGE_SCOPE);
+ pageScope = new ScopeMap(new ScopeExtractor(pageContext,
+ PageContext.PAGE_SCOPE));
}
return (pageScope);
}
public Map<String, Object> getRequestScope() {
if ((requestScope == null) && (pageContext != null)) {
- requestScope = new JspScopeMap(pageContext, PageContext.REQUEST_SCOPE);
+ requestScope = new ScopeMap(new ScopeExtractor(pageContext,
+ PageContext.REQUEST_SCOPE));
}
return (requestScope);
}
public Map<String, Object> getSessionScope() {
if ((sessionScope == null) && (pageContext != null)) {
- sessionScope = new JspSessionScopeMap(pageContext);
+ sessionScope = new ScopeMap(new SessionScopeExtractor(pageContext));
}
return (sessionScope);
}
public Map<String, Object> getApplicationScope() {
if ((applicationScope == null) && (pageContext != null)) {
- applicationScope = new JspScopeMap(pageContext, PageContext.APPLICATION_SCOPE);
+ applicationScope = new ScopeMap(new ScopeExtractor(pageContext,
+ PageContext.APPLICATION_SCOPE));
}
return (applicationScope);
}
Added: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/extractor/ScopeExtractor.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/extractor/ScopeExtractor.java?rev=941871&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/extractor/ScopeExtractor.java (added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/extractor/ScopeExtractor.java Thu May 6 19:25:23 2010
@@ -0,0 +1,39 @@
+package org.apache.tiles.request.jsp.extractor;
+
+import java.util.Enumeration;
+
+import javax.servlet.jsp.JspContext;
+
+import org.apache.tiles.request.collection.extractor.AttributeExtractor;
+
+public class ScopeExtractor implements AttributeExtractor {
+
+ private JspContext context;
+
+ private int scope;
+
+ public ScopeExtractor(JspContext context, int scope) {
+ this.context = context;
+ this.scope = scope;
+ }
+
+ @Override
+ public void removeValue(String name) {
+ context.removeAttribute(name, scope);
+ }
+
+ @Override
+ public Enumeration<String> getKeys() {
+ return context.getAttributeNamesInScope(scope);
+ }
+
+ @Override
+ public Object getValue(String key) {
+ return context.getAttribute(key, scope);
+ }
+
+ @Override
+ public void setValue(String key, Object value) {
+ context.setAttribute(key, value, scope);
+ }
+}
Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/extractor/ScopeExtractor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/extractor/ScopeExtractor.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/extractor/SessionScopeExtractor.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/extractor/SessionScopeExtractor.java?rev=941871&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/extractor/SessionScopeExtractor.java (added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/extractor/SessionScopeExtractor.java Thu May 6 19:25:23 2010
@@ -0,0 +1,48 @@
+package org.apache.tiles.request.jsp.extractor;
+
+import java.util.Enumeration;
+
+import javax.servlet.jsp.PageContext;
+
+import org.apache.tiles.request.collection.extractor.AttributeExtractor;
+
+public class SessionScopeExtractor implements AttributeExtractor {
+
+ private PageContext context;
+
+ public SessionScopeExtractor(PageContext context) {
+ this.context = context;
+ }
+
+ @Override
+ public void removeValue(String name) {
+ if (context.getSession() == null) {
+ return;
+ }
+ context.removeAttribute(name, PageContext.SESSION_SCOPE);
+ }
+
+ @Override
+ public Enumeration<String> getKeys() {
+ if (context.getSession() == null) {
+ return null;
+ }
+ return context.getAttributeNamesInScope(PageContext.SESSION_SCOPE);
+ }
+
+ @Override
+ public Object getValue(String key) {
+ if (context.getSession() == null) {
+ return null;
+ }
+ return context.getAttribute(key, PageContext.SESSION_SCOPE);
+ }
+
+ @Override
+ public void setValue(String key, Object value) {
+ if (context.getSession() == null) {
+ return;
+ }
+ context.setAttribute(key, value, PageContext.SESSION_SCOPE);
+ }
+}
Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/extractor/SessionScopeExtractor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/main/java/org/apache/tiles/request/jsp/extractor/SessionScopeExtractor.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Modified: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspPrintWriterAdapterTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspPrintWriterAdapterTest.java?rev=941871&r1=941870&r2=941871&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspPrintWriterAdapterTest.java (original)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspPrintWriterAdapterTest.java Thu May 6 19:25:23 2010
@@ -20,13 +20,12 @@
*/
package org.apache.tiles.request.jsp;
+import static org.easymock.classextension.EasyMock.*;
+
import java.io.IOException;
import javax.servlet.jsp.JspWriter;
-import org.apache.tiles.request.jsp.JspPrintWriterAdapter;
-import org.easymock.classextension.EasyMock;
-
import junit.framework.TestCase;
/**
@@ -47,12 +46,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testWriteInt() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.write(1);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.write(1);
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -61,13 +60,13 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testWriteCharArray() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
String result = "this is a test";
- writer.write(EasyMock.aryEq(result.toCharArray()));
+ writer.write(aryEq(result.toCharArray()));
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.write(result.toCharArray());
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -76,14 +75,14 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testWriteCharArrayIntInt() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
String result = "this is a test";
- writer.write(EasyMock.aryEq(result.toCharArray()), EasyMock.eq(0),
- EasyMock.eq(STRING_LENGTH));
+ writer.write(aryEq(result.toCharArray()), eq(0),
+ eq(STRING_LENGTH));
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.write(result.toCharArray(), 0, STRING_LENGTH);
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -92,12 +91,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testFlush() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.flush();
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.flush();
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -106,12 +105,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testClose() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.close();
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.close();
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -120,12 +119,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintBoolean() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.print(true);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.print(true);
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -134,12 +133,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintChar() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.print('c');
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.print('c');
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -148,12 +147,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintInt() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.print(1);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.print(1);
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -162,12 +161,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintLong() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.print(1L);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.print(1L);
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -176,12 +175,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintFloat() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.print(1f);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.print(1f);
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -190,12 +189,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintDouble() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.print(1d);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.print(1d);
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -204,13 +203,13 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintCharArray() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
String result = "this is a test";
- writer.print(EasyMock.aryEq(result.toCharArray()));
+ writer.print(aryEq(result.toCharArray()));
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.print(result.toCharArray());
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -219,12 +218,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintln() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.println();
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.println();
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -233,12 +232,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintlnBoolean() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.println(true);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.println(true);
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -247,12 +246,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintlnChar() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.println('c');
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.println('c');
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -261,12 +260,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintlnInt() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.println(1);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.println(1);
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -275,12 +274,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintlnLong() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.println(1L);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.println(1L);
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -289,12 +288,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintlnFloat() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.println(1f);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.println(1f);
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -303,12 +302,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintlnDouble() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.println(1d);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.println(1d);
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -317,20 +316,20 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintlnCharArray() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
String result = "this is a test";
- writer.println(EasyMock.aryEq(result.toCharArray()));
+ writer.println(aryEq(result.toCharArray()));
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.println(result.toCharArray());
- EasyMock.verify(writer);
+ verify(writer);
}
/**
* Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#getJspWriter()}.
*/
public void testGetJspWriter() {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
assertEquals(writer, adapter.getJspWriter());
}
@@ -341,12 +340,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testAppendChar() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
- EasyMock.expect(writer.append('c')).andReturn(writer);
+ JspWriter writer = createMock(JspWriter.class);
+ expect(writer.append('c')).andReturn(writer);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
assertEquals(adapter, adapter.append('c'));
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -356,13 +355,13 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testAppendCharSequenceIntInt() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
- CharSequence sequence = EasyMock.createMock(CharSequence.class);
- EasyMock.expect(writer.append(sequence, 0, STRING_LENGTH)).andReturn(writer);
+ JspWriter writer = createMock(JspWriter.class);
+ CharSequence sequence = createMock(CharSequence.class);
+ expect(writer.append(sequence, 0, STRING_LENGTH)).andReturn(writer);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
assertEquals(adapter, adapter.append(sequence, 0, STRING_LENGTH));
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -371,13 +370,13 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testAppendCharSequence() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
- CharSequence sequence = EasyMock.createMock(CharSequence.class);
- EasyMock.expect(writer.append(sequence)).andReturn(writer);
+ JspWriter writer = createMock(JspWriter.class);
+ CharSequence sequence = createMock(CharSequence.class);
+ expect(writer.append(sequence)).andReturn(writer);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
assertEquals(adapter, adapter.append(sequence));
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -386,13 +385,13 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintObject() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
- Object obj = EasyMock.createMock(Object.class);
+ JspWriter writer = createMock(JspWriter.class);
+ Object obj = createMock(Object.class);
writer.print(obj);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.print(obj);
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -401,12 +400,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintString() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.print("this is a string");
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.print("this is a string");
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -415,13 +414,13 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintlnObject() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
- Object obj = EasyMock.createMock(Object.class);
+ JspWriter writer = createMock(JspWriter.class);
+ Object obj = createMock(Object.class);
writer.println(obj);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.println(obj);
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -430,12 +429,12 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testPrintlnString() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
writer.println("this is a string");
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.println("this is a string");
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -444,13 +443,13 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testWriteStringIntInt() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
String result = "this is a test";
writer.write(result, 0, STRING_LENGTH);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
adapter.write(result, 0, STRING_LENGTH);
- EasyMock.verify(writer);
+ verify(writer);
}
/**
@@ -459,12 +458,514 @@ public class JspPrintWriterAdapterTest e
* @throws IOException If something goes wrong.
*/
public void testWriteString() throws IOException {
- JspWriter writer = EasyMock.createMock(JspWriter.class);
+ JspWriter writer = createMock(JspWriter.class);
String result = "this is a test";
writer.write(result);
JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
- EasyMock.replay(writer);
+ replay(writer);
+ adapter.write(result);
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#write(int)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testWriteIntEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.write(1);
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.write(1);
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#write(char[])}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testWriteCharArrayEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ String result = "this is a test";
+ writer.write(aryEq(result.toCharArray()));
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.write(result.toCharArray());
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#write(char[], int, int)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testWriteCharArrayIntIntEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ String result = "this is a test";
+ writer.write(aryEq(result.toCharArray()), eq(0),
+ eq(STRING_LENGTH));
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.write(result.toCharArray(), 0, STRING_LENGTH);
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#flush()}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testFlushEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.flush();
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.flush();
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#close()}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testCloseEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.close();
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.close();
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#print(boolean)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintBooleanEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.print(true);
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.print(true);
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#print(char)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintCharEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.print('c');
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.print('c');
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#print(int)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintIntEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.print(1);
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.print(1);
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#print(long)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintLongEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.print(1L);
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.print(1L);
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#print(float)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintFloatEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.print(1f);
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.print(1f);
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#print(double)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintDoubleEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.print(1d);
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.print(1d);
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#print(char[])}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintCharArrayEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ String result = "this is a test";
+ writer.print(aryEq(result.toCharArray()));
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.print(result.toCharArray());
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#println()}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintlnEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.println();
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.println();
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#println(boolean)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintlnBooleanEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.println(true);
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.println(true);
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#println(char)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintlnCharEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.println('c');
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.println('c');
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#println(int)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintlnIntEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.println(1);
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.println(1);
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#println(long)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintlnLongEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.println(1L);
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.println(1L);
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#println(float)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintlnFloatEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.println(1f);
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.println(1f);
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#println(double)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintlnDoubleEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.println(1d);
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.println(1d);
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#println(char[])}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintlnCharArrayEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ String result = "this is a test";
+ writer.println(aryEq(result.toCharArray()));
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.println(result.toCharArray());
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#append(char)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testAppendCharEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ expect(writer.append('c')).andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ assertEquals(adapter, adapter.append('c'));
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for
+ * {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#append(java.lang.CharSequence, int, int)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testAppendCharSequenceIntIntEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ CharSequence sequence = createMock(CharSequence.class);
+ expect(writer.append(sequence, 0, STRING_LENGTH)).andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ assertEquals(adapter, adapter.append(sequence, 0, STRING_LENGTH));
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#append(java.lang.CharSequence)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testAppendCharSequenceEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ CharSequence sequence = createMock(CharSequence.class);
+ expect(writer.append(sequence)).andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ assertEquals(adapter, adapter.append(sequence));
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#print(java.lang.Object)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintObjectEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ Object obj = createMock(Object.class);
+ writer.print(obj);
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.print(obj);
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#print(java.lang.String)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintStringEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.print("this is a string");
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.print("this is a string");
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#println(java.lang.Object)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintlnObjectEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ Object obj = createMock(Object.class);
+ writer.println(obj);
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.println(obj);
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#println(java.lang.String)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testPrintlnStringEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ writer.println("this is a string");
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.println("this is a string");
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#write(java.lang.String, int, int)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testWriteStringIntIntEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ String result = "this is a test";
+ writer.write(result, 0, STRING_LENGTH);
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
+ adapter.write(result, 0, STRING_LENGTH);
+ assertTrue(adapter.checkError());
+ verify(writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspPrintWriterAdapter#write(java.lang.String)}.
+ *
+ * @throws IOException If something goes wrong.
+ */
+ public void testWriteStringEx() throws IOException {
+ JspWriter writer = createMock(JspWriter.class);
+ String result = "this is a test";
+ writer.write(result);
+ expectLastCall().andThrow(new IOException());
+ writer.flush();
+ JspPrintWriterAdapter adapter = new JspPrintWriterAdapter(writer);
+ replay(writer);
adapter.write(result);
- EasyMock.verify(writer);
+ assertTrue(adapter.checkError());
+ verify(writer);
}
}
Added: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspRequestTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspRequestTest.java?rev=941871&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspRequestTest.java (added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspRequestTest.java Thu May 6 19:25:23 2010
@@ -0,0 +1,196 @@
+/**
+ *
+ */
+package org.apache.tiles.request.jsp;
+
+import static org.easymock.EasyMock.*;
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.PageContext;
+
+import org.apache.tiles.request.ApplicationContext;
+import org.apache.tiles.request.Request;
+import org.apache.tiles.request.collection.ScopeMap;
+import org.apache.tiles.request.servlet.ServletRequest;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link JspRequest}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JspRequestTest {
+
+ private Request enclosedRequest;
+
+ private PageContext context;
+
+ private JspRequest request;
+
+ /**
+ * Sets up the test.
+ */
+ @Before
+ public void setUp() {
+ enclosedRequest = createMock(Request.class);
+ context = createMock(PageContext.class);
+ request = new JspRequest(enclosedRequest, context);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspRequest#getNativeScopes()}.
+ */
+ @Test
+ public void testGetNativeScopes() {
+ replay(context, enclosedRequest);
+ assertArrayEquals(new String[] { "page", "request", "session",
+ "application" }, request.getNativeScopes());
+ verify(context, enclosedRequest);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspRequest#getWriter()}.
+ */
+ @Test
+ public void testGetWriter() {
+ JspWriter writer = createMock(JspWriter.class);
+
+ expect(context.getOut()).andReturn(writer);
+
+ replay(context, enclosedRequest, writer);
+ assertEquals(writer, request.getWriter());
+ verify(context, enclosedRequest, writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspRequest#getPrintWriter()}.
+ */
+ @Test
+ public void testGetPrintWriter() {
+ JspWriter writer = createMock(JspWriter.class);
+
+ expect(context.getOut()).andReturn(writer);
+
+ replay(context, enclosedRequest, writer);
+ assertEquals(writer, ((JspPrintWriterAdapter) request.getPrintWriter())
+ .getJspWriter());
+ verify(context, enclosedRequest, writer);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspRequest#getRequestObjects()}.
+ */
+ @Test
+ public void testGetRequestObjects() {
+ replay(context, enclosedRequest);
+ assertArrayEquals(new Object[] { context }, request.getRequestObjects());
+ verify(context, enclosedRequest);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspRequest#doInclude(java.lang.String)}.
+ * @throws IOException If something goes wrong.
+ * @throws ServletException If something goes wrong.
+ */
+ @Test
+ public void testDoInclude() throws ServletException, IOException {
+ context.include("/my/path", false);
+
+ replay(context, enclosedRequest);
+ request.doInclude("/my/path");
+ verify(context, enclosedRequest);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspRequest#doInclude(java.lang.String)}.
+ * @throws IOException If something goes wrong.
+ * @throws ServletException If something goes wrong.
+ */
+ @Test(expected=IOException.class)
+ public void testDoIncludeException() throws ServletException, IOException {
+ context.include("/my/path", false);
+ expectLastCall().andThrow(new ServletException());
+
+ replay(context, enclosedRequest);
+ request.doInclude("/my/path");
+ verify(context, enclosedRequest);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspRequest#createServletJspRequest(org.apache.tiles.request.ApplicationContext, javax.servlet.jsp.PageContext)}.
+ */
+ @Test
+ public void testCreateServletJspRequest() {
+ ApplicationContext applicationContext = createMock(ApplicationContext.class);
+ HttpServletRequest servletRequest = createMock(HttpServletRequest.class);
+ HttpServletResponse servletResponse = createMock(HttpServletResponse.class);
+
+ expect(context.getRequest()).andReturn(servletRequest);
+ expect(context.getResponse()).andReturn(servletResponse);
+
+ replay(context, applicationContext, servletRequest, servletResponse);
+ JspRequest request = JspRequest.createServletJspRequest(applicationContext, context);
+ ServletRequest wrappedRequest = (ServletRequest) request.getWrappedRequest();
+ assertEquals(servletRequest, wrappedRequest.getRequest());
+ assertEquals(servletResponse, wrappedRequest.getResponse());
+ verify(context, applicationContext, servletRequest, servletResponse);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspRequest#getPageScope()}.
+ */
+ @Test
+ public void testGetPageScope() {
+ replay(context, enclosedRequest);
+ assertTrue(request.getPageScope() instanceof ScopeMap);
+ verify(context, enclosedRequest);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspRequest#getRequestScope()}.
+ */
+ @Test
+ public void testGetRequestScope() {
+ replay(context, enclosedRequest);
+ assertTrue(request.getRequestScope() instanceof ScopeMap);
+ verify(context, enclosedRequest);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspRequest#getSessionScope()}.
+ */
+ @Test
+ public void testGetSessionScope() {
+ replay(context, enclosedRequest);
+ assertTrue(request.getSessionScope() instanceof ScopeMap);
+ verify(context, enclosedRequest);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspRequest#getApplicationScope()}.
+ */
+ @Test
+ public void testGetApplicationScope() {
+ replay(context, enclosedRequest);
+ assertTrue(request.getApplicationScope() instanceof ScopeMap);
+ verify(context, enclosedRequest);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspRequest#getPageContext()}.
+ */
+ @Test
+ public void testGetPageContext() {
+ replay(context, enclosedRequest);
+ assertEquals(context, request.getPageContext());
+ verify(context, enclosedRequest);
+ }
+}
Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspRequestTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspRequestTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspUtilTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspUtilTest.java?rev=941871&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspUtilTest.java (added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspUtilTest.java Thu May 6 19:25:23 2010
@@ -0,0 +1,39 @@
+/**
+ *
+ */
+package org.apache.tiles.request.jsp;
+
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
+import javax.servlet.jsp.JspContext;
+import javax.servlet.jsp.PageContext;
+
+import org.apache.tiles.request.ApplicationContext;
+import org.apache.tiles.request.util.ApplicationAccess;
+import org.junit.Test;
+
+/**
+ * Tests {@link JspUtil}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JspUtilTest {
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.JspUtil#getApplicationContext(javax.servlet.jsp.JspContext)}.
+ */
+ @Test
+ public void testGetApplicationContext() {
+ ApplicationContext applicationContext = createMock(ApplicationContext.class);
+ JspContext jspContext = createMock(JspContext.class);
+
+ expect(jspContext.getAttribute(ApplicationAccess
+ .APPLICATION_CONTEXT_ATTRIBUTE, PageContext.APPLICATION_SCOPE))
+ .andReturn(applicationContext);
+
+ replay(applicationContext, jspContext);
+ assertEquals(applicationContext, JspUtil.getApplicationContext(jspContext));
+ verify(applicationContext, jspContext);
+ }
+}
Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspUtilTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/JspUtilTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/extractor/ScopeExtractorTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/extractor/ScopeExtractorTest.java?rev=941871&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/extractor/ScopeExtractorTest.java (added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/extractor/ScopeExtractorTest.java Thu May 6 19:25:23 2010
@@ -0,0 +1,87 @@
+/**
+ *
+ */
+package org.apache.tiles.request.jsp.extractor;
+
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Enumeration;
+
+import javax.servlet.jsp.JspContext;
+import javax.servlet.jsp.PageContext;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link ScopeExtractor}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ScopeExtractorTest {
+
+ private JspContext context;
+
+ private ScopeExtractor extractor;
+
+ /**
+ * Sets up the test.
+ */
+ @Before
+ public void setUp() {
+ context = createMock(JspContext.class);
+ extractor = new ScopeExtractor(context, PageContext.PAGE_SCOPE);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.extractor.ScopeExtractor#removeValue(java.lang.String)}.
+ */
+ @Test
+ public void testRemoveValue() {
+ context.removeAttribute("key", PageContext.PAGE_SCOPE);
+
+ replay(context);
+ extractor.removeValue("key");
+ verify(context);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.extractor.ScopeExtractor#getKeys()}.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetKeys() {
+ Enumeration<String> keys = createMock(Enumeration.class);
+ expect(context.getAttributeNamesInScope(PageContext.PAGE_SCOPE)).andReturn(keys);
+
+ replay(context);
+ assertEquals(keys, extractor.getKeys());
+ verify(context);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.extractor.ScopeExtractor#getValue(java.lang.String)}.
+ */
+ @Test
+ public void testGetValue() {
+ expect(context.getAttribute("key", PageContext.PAGE_SCOPE)).andReturn("value");
+
+ replay(context);
+ assertEquals("value", extractor.getValue("key"));
+ verify(context);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.extractor.ScopeExtractor#setValue(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testSetValue() {
+ context.setAttribute("key", "value", PageContext.PAGE_SCOPE);
+
+ replay(context);
+ extractor.setValue("key", "value");
+ verify(context);
+ }
+
+}
Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/extractor/ScopeExtractorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/extractor/ScopeExtractorTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/extractor/SessionScopeExtractorTest.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/extractor/SessionScopeExtractorTest.java?rev=941871&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/extractor/SessionScopeExtractorTest.java (added)
+++ tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/extractor/SessionScopeExtractorTest.java Thu May 6 19:25:23 2010
@@ -0,0 +1,143 @@
+/**
+ *
+ */
+package org.apache.tiles.request.jsp.extractor;
+
+import static org.easymock.EasyMock.*;
+import static org.easymock.classextension.EasyMock.*;
+import static org.junit.Assert.*;
+
+import java.util.Enumeration;
+
+import javax.servlet.http.HttpSession;
+import javax.servlet.jsp.PageContext;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests {@link SessionScopeExtractor}.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SessionScopeExtractorTest {
+
+ private PageContext context;
+
+ private HttpSession session;
+
+ private SessionScopeExtractor extractor;
+
+ /**
+ * Sets up the test.
+ */
+ @Before
+ public void setUp() {
+ context = createMock(PageContext.class);
+ session = createMock(HttpSession.class);
+ extractor = new SessionScopeExtractor(context);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.extractor.ScopeExtractor#removeValue(java.lang.String)}.
+ */
+ @Test
+ public void testRemoveValue() {
+ expect(context.getSession()).andReturn(session);
+ context.removeAttribute("key", PageContext.SESSION_SCOPE);
+
+ replay(context, session);
+ extractor.removeValue("key");
+ verify(context, session);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.extractor.ScopeExtractor#getKeys()}.
+ */
+ @SuppressWarnings("unchecked")
+ @Test
+ public void testGetKeys() {
+ expect(context.getSession()).andReturn(session);
+ Enumeration<String> keys = createMock(Enumeration.class);
+ expect(context.getAttributeNamesInScope(PageContext.SESSION_SCOPE)).andReturn(keys);
+
+ replay(context, session);
+ assertEquals(keys, extractor.getKeys());
+ verify(context, session);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.extractor.ScopeExtractor#getValue(java.lang.String)}.
+ */
+ @Test
+ public void testGetValue() {
+ expect(context.getSession()).andReturn(session);
+ expect(context.getAttribute("key", PageContext.SESSION_SCOPE)).andReturn("value");
+
+ replay(context, session);
+ assertEquals("value", extractor.getValue("key"));
+ verify(context, session);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.extractor.ScopeExtractor#setValue(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testSetValue() {
+ expect(context.getSession()).andReturn(session);
+ context.setAttribute("key", "value", PageContext.SESSION_SCOPE);
+
+ replay(context, session);
+ extractor.setValue("key", "value");
+ verify(context, session);
+ }
+
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.extractor.ScopeExtractor#removeValue(java.lang.String)}.
+ */
+ @Test
+ public void testRemoveValueNoSession() {
+ expect(context.getSession()).andReturn(null);
+
+ replay(context, session);
+ extractor.removeValue("key");
+ verify(context, session);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.extractor.ScopeExtractor#getKeys()}.
+ */
+ @Test
+ public void testGetKeysNoSession() {
+ expect(context.getSession()).andReturn(null);
+
+ replay(context, session);
+ assertNull(extractor.getKeys());
+ verify(context, session);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.extractor.ScopeExtractor#getValue(java.lang.String)}.
+ */
+ @Test
+ public void testGetValueNoSession() {
+ expect(context.getSession()).andReturn(null);
+
+ replay(context, session);
+ assertNull(extractor.getValue("key"));
+ verify(context, session);
+ }
+
+ /**
+ * Test method for {@link org.apache.tiles.request.jsp.extractor.ScopeExtractor#setValue(java.lang.String, java.lang.Object)}.
+ */
+ @Test
+ public void testSetValueNoSession() {
+ expect(context.getSession()).andReturn(null);
+
+ replay(context, session);
+ extractor.setValue("key", "value");
+ verify(context, session);
+ }
+}
Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/extractor/SessionScopeExtractorTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: tiles/sandbox/trunk/tiles-request/tiles-request-jsp/src/test/java/org/apache/tiles/request/jsp/extractor/SessionScopeExtractorTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL