1 package org.apache.maven.continuum.web.action;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
23
24 import java.io.BufferedOutputStream;
25 import java.io.FileOutputStream;
26 import java.io.FilterOutputStream;
27 import java.io.IOException;
28 import java.io.OutputStream;
29 import java.io.PrintStream;
30
31
32
33
34
35
36
37 public class ContinuumActionLoggingTest
38 extends PlexusInSpringTestCase
39 {
40
41 StringBuffer testOutput = new StringBuffer();
42
43
44 public void setUp()
45 throws Exception
46 {
47 super.setUp();
48
49 PrintStream systemPrintStream = new PrintStream( new FilteredStream( System.out ), true );
50 System.setOut( systemPrintStream );
51 }
52
53
54 public void tearDown()
55 {
56 System.setOut( new PrintStream( new BufferedOutputStream( new FileOutputStream( java.io.FileDescriptor.out ),
57 128 ), true ) );
58 }
59
60
61 public void testActionLogging()
62 throws Exception
63 {
64 TestAction testAction = (TestAction) lookup( "com.opensymphony.xwork2.Action", "testAction" );
65 String testString = "action test string";
66 testAction.setTestString( testString );
67
68 testAction.execute();
69
70 assertTrue( testOutput.toString().indexOf( testString ) != -1 );
71 }
72
73
74 class FilteredStream
75 extends FilterOutputStream
76 {
77 OutputStream stream;
78
79 public FilteredStream( OutputStream stream )
80 {
81 super( stream );
82 this.stream = stream;
83 }
84
85 public void write( byte byteArray[] )
86 throws IOException
87 {
88 testOutput.append( new String( byteArray ) );
89 stream.write( byteArray );
90 }
91
92 public void write( byte byteArray[], int offset, int length )
93 throws IOException
94 {
95 testOutput.append( new String( byteArray, offset, length ) );
96 stream.write( byteArray, offset, length );
97 }
98 }
99 }