01: /*
02: * Copyright (c) 2002-2006 by OpenSymphony
03: * All rights reserved.
04: */
05: package com.opensymphony.webwork.views.jsp.ui;
06:
07: import java.io.ByteArrayOutputStream;
08: import java.io.InputStream;
09:
10: import com.mockobjects.servlet.MockHttpServletResponse;
11: import com.opensymphony.webwork.ServletActionContext;
12: import com.opensymphony.webwork.views.jsp.AbstractUITagTest;
13: import com.opensymphony.xwork.mock.MockActionInvocation;
14: import com.opensymphony.xwork.util.OgnlValueStack;
15:
16: import junit.framework.TestCase;
17:
18: /**
19: * Abstract test case for all RichTextEditor based test case. (contains common methods)
20: *
21: * @author tm_jee
22: * @version $Date: 2006-03-04 16:07:50 +0100 (Sat, 04 Mar 2006) $ $Id: AbstractRichtexteditorTest.java 2308 2006-03-04 15:07:50Z rainerh $
23: */
24: public abstract class AbstractRichtexteditorTest extends TestCase {
25:
26: protected MockActionInvocation invocation;
27: protected MockHttpServletResponse response;
28:
29: protected void setUp() throws Exception {
30: super .setUp();
31: //ActionProxy actionProxy = ActionProxyFactory.getFactory().createActionProxy("namespace", "actionName", new HashMap());
32: //ActionProxy actionProxy = new MockActionProxy();
33: //invocation = ActionProxyFactory.getFactory().createActionInvocation(actionProxy);
34: invocation = new MockActionInvocation();
35: invocation.setStack(new OgnlValueStack());
36: response = new MockHttpServletResponse();
37: ServletActionContext.setResponse(response);
38: }
39:
40: protected void tearDown() throws Exception {
41: super .tearDown();
42: invocation = null;
43: response = null;
44: }
45:
46: protected void verify(InputStream is) throws Exception {
47: String result1 = response.getOutputStreamContents();
48:
49: ByteArrayOutputStream baos = new ByteArrayOutputStream();
50: byte[] tmpBytes = new byte[1024];
51: while (is.read(tmpBytes) != -1) {
52: baos.write(tmpBytes);
53: }
54: String result2 = new String(baos.toByteArray());
55: baos.close();
56:
57: //System.out.println("*** result1 (p)="+result1);
58: //System.out.println("*** result2 (p)="+result2);
59:
60: assertEquals(
61: AbstractUITagTest.normalize(result2.trim(), false),
62: AbstractUITagTest.normalize(result1.trim(), false));
63: }
64: }
|