1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
package org.qedeq.kernel.bo.log; |
17 |
|
|
18 |
|
import java.io.ByteArrayOutputStream; |
19 |
|
import java.io.UnsupportedEncodingException; |
20 |
|
|
21 |
|
import org.apache.log4j.Level; |
22 |
|
import org.apache.log4j.Logger; |
23 |
|
import org.apache.log4j.PatternLayout; |
24 |
|
import org.apache.log4j.WriterAppender; |
25 |
|
import org.qedeq.base.trace.Trace; |
26 |
|
import org.qedeq.kernel.bo.test.QedeqBoTestCase; |
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
@author |
32 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (95) |
Complexity: 10 |
Complexity Density: 0.12 |
|
33 |
|
public class TraceListenerTest extends QedeqBoTestCase { |
34 |
|
|
35 |
|
private TraceListener listener; |
36 |
|
private ByteArrayOutputStream out = new ByteArrayOutputStream(); |
37 |
|
private boolean oldTrace; |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
39 |
7
|
protected void setUp() throws Exception {... |
40 |
7
|
super.setUp(); |
41 |
7
|
out.reset(); |
42 |
7
|
Logger rootLogger = Logger.getRootLogger(); |
43 |
7
|
rootLogger.removeAllAppenders(); |
44 |
7
|
rootLogger.setLevel(Level.DEBUG); |
45 |
7
|
rootLogger.addAppender(new WriterAppender( |
46 |
|
new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN), out)); |
47 |
7
|
oldTrace = Trace.isTraceOn(); |
48 |
7
|
Trace.setTraceOn(true); |
49 |
7
|
listener = new TraceListener(); |
50 |
7
|
QedeqLog.getInstance().addLog(listener); |
51 |
|
|
52 |
|
} |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
54 |
7
|
protected void tearDown() throws Exception {... |
55 |
7
|
QedeqLog.getInstance().removeLog(listener); |
56 |
7
|
Trace.setTraceOn(oldTrace); |
57 |
7
|
super.tearDown(); |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1
PASS
|
|
60 |
1
|
public void testLogFailureReply() throws Exception{... |
61 |
1
|
listener.logFailureReply("failure and error", "http://mysite.org/mymodule.xml", "was this logged?"); |
62 |
1
|
String out = getLogfileContents(); |
63 |
1
|
assertTrue(out.trim().endsWith("was this logged?")); |
64 |
1
|
assertTrue(0 <= out.indexOf("reply")); |
65 |
1
|
assertTrue(0 <= out.indexOf("failure and error")); |
66 |
1
|
assertTrue(0 <= out.indexOf("http://mysite.org/mymodule.xml")); |
67 |
1
|
int pos = out.length(); |
68 |
1
|
listener.logFailureReply("failure and error", "http://mysite.org/mymodule.xml", "this is the end"); |
69 |
1
|
out = getLogfileContents(); |
70 |
1
|
assertTrue(out.trim().endsWith("this is the end")); |
71 |
1
|
assertTrue(pos <= out.indexOf("reply", pos)); |
72 |
1
|
assertTrue(pos <= out.indexOf("failure and error", pos)); |
73 |
1
|
assertTrue(-1 == out.indexOf("http://mysite.org/mymodule.xml", pos)); |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
76 |
14
|
private String getLogfileContents() throws UnsupportedEncodingException {... |
77 |
14
|
return out.toString("UTF-8"); |
78 |
|
} |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1
PASS
|
|
80 |
1
|
public void testLogSuccessfulReply() throws Exception{... |
81 |
1
|
listener.logSuccessfulReply("successfully loaded", "http://mysite.org/mymodule.xml"); |
82 |
1
|
String out = getLogfileContents(); |
83 |
1
|
assertTrue(0 <= out.indexOf("successfully loaded")); |
84 |
1
|
assertTrue(0 <= out.indexOf("http://mysite.org/mymodule.xml")); |
85 |
1
|
int pos = out.length(); |
86 |
1
|
listener.logSuccessfulReply("successfully loaded", "http://mysite.org/mymodule.xml"); |
87 |
1
|
out = getLogfileContents(); |
88 |
1
|
assertTrue(-1 == out.indexOf("http://mysite.org/mymodule.xml", pos)); |
89 |
1
|
assertTrue(pos <= out.indexOf("successfully loaded", pos)); |
90 |
|
} |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1
PASS
|
|
92 |
1
|
public void testLogMessageState() throws Exception{... |
93 |
1
|
listener.logMessageState("loading 10 percent complete", "http://mysite.org/mymodule.xml"); |
94 |
1
|
String out = getLogfileContents(); |
95 |
1
|
assertTrue(0 <= out.indexOf("loading 10 percent complete")); |
96 |
1
|
assertTrue(0 <= out.indexOf("http://mysite.org/mymodule.xml")); |
97 |
|
|
98 |
1
|
int pos = out.length(); |
99 |
1
|
listener.logMessageState("loading 20 percent complete", "http://mysite.org/mymodule.xml"); |
100 |
1
|
out = getLogfileContents(); |
101 |
1
|
assertTrue(pos <= out.indexOf("loading 20 percent complete", pos)); |
102 |
1
|
assertTrue(-1 == out.indexOf("http://mysite.org/mymodule.xml", pos)); |
103 |
|
} |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1
PASS
|
|
105 |
1
|
public void testLogFailureState() throws Exception{... |
106 |
1
|
listener.logFailureState("error state occured", "http://mysite.org/mymodule.xml", "was this logged?"); |
107 |
1
|
String out = getLogfileContents(); |
108 |
1
|
assertTrue(out.trim().endsWith("was this logged?")); |
109 |
1
|
assertTrue(0 <= out.indexOf("failure")); |
110 |
1
|
assertTrue(0 <= out.indexOf("error state occured")); |
111 |
1
|
assertTrue(0 <= out.indexOf("http://mysite.org/mymodule.xml")); |
112 |
1
|
int pos = out.length(); |
113 |
1
|
listener.logFailureState("error state occured", "http://mysite.org/mymodule.xml", "was this logged!"); |
114 |
1
|
out = getLogfileContents(); |
115 |
1
|
assertTrue(out.trim().endsWith("was this logged!")); |
116 |
1
|
assertTrue(pos <= out.indexOf("failure", pos)); |
117 |
1
|
assertTrue(pos <= out.indexOf("error state occured", pos)); |
118 |
1
|
assertTrue(-1 == out.indexOf("http://mysite.org/mymodule.xml", pos)); |
119 |
|
} |
120 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1
PASS
|
|
121 |
1
|
public void testLogSuccesfulState() throws Exception{... |
122 |
1
|
listener.logSuccessfulState("we are the champions", "http://mysite.org/mymodule.xml"); |
123 |
1
|
String out = getLogfileContents(); |
124 |
1
|
assertTrue(0 <= out.indexOf("success")); |
125 |
1
|
assertTrue(0 <= out.indexOf("we are the champions")); |
126 |
1
|
assertTrue(0 <= out.indexOf("http://mysite.org/mymodule.xml")); |
127 |
1
|
int pos = out.length(); |
128 |
1
|
listener.logSuccessfulState("rain begins to fall", "http://mysite.org/mymodule.xml"); |
129 |
1
|
out = getLogfileContents(); |
130 |
1
|
assertTrue(pos <= out.indexOf("success", pos)); |
131 |
1
|
assertTrue(pos <= out.indexOf("rain begins to fall", pos)); |
132 |
1
|
assertTrue(-1 == out.indexOf("http://mysite.org/mymodule.xml", pos)); |
133 |
|
} |
134 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1
PASS
|
|
135 |
1
|
public void testLogRequest() throws Exception{... |
136 |
1
|
listener.logRequest("validating", "http://mysite.org/mymodule.xml"); |
137 |
1
|
String out = getLogfileContents(); |
138 |
1
|
assertTrue(0 <= out.indexOf("validating")); |
139 |
1
|
assertTrue(0 <= out.indexOf("http://mysite.org/mymodule.xml")); |
140 |
1
|
int pos = out.length(); |
141 |
1
|
listener.logRequest("validated", "http://mysite.org/mymodule.xml"); |
142 |
1
|
out = getLogfileContents(); |
143 |
1
|
assertTrue(pos <= out.indexOf("validated", pos)); |
144 |
1
|
assertTrue(-1 == out.indexOf("http://mysite.org/mymodule.xml", pos)); |
145 |
|
} |
146 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
147 |
1
|
public void testLogMessage() throws Exception{... |
148 |
1
|
listener.logMessage("we are on a yellow submarine"); |
149 |
1
|
String out = getLogfileContents(); |
150 |
1
|
assertTrue(0 <= out.indexOf("we are on a yellow submarine")); |
151 |
1
|
int pos = out.length(); |
152 |
1
|
listener.logMessage("we are on a blue submarine"); |
153 |
1
|
out = getLogfileContents(); |
154 |
1
|
assertTrue(pos <= out.indexOf("we are on a blue submarine", pos)); |
155 |
|
} |
156 |
|
|
157 |
|
} |