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.PrintStream; |
20 |
|
|
21 |
|
import org.qedeq.kernel.bo.test.QedeqBoTestCase; |
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
@author |
27 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (84) |
Complexity: 10 |
Complexity Density: 0.14 |
|
28 |
|
public class LogListenerImplTest extends QedeqBoTestCase { |
29 |
|
|
30 |
|
private LogListenerImpl listener; |
31 |
|
private ByteArrayOutputStream out; |
32 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
33 |
9
|
protected void setUp() throws Exception {... |
34 |
9
|
super.setUp(); |
35 |
9
|
out = new ByteArrayOutputStream(); |
36 |
9
|
listener = new LogListenerImpl(new PrintStream(out)); |
37 |
|
} |
38 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1
PASS
|
|
39 |
1
|
public void testLogFailureReply() throws Exception{... |
40 |
1
|
listener.logFailureReply("failure and error", "http://mysite.org/mymodule.xml", "was this logged?"); |
41 |
|
|
42 |
1
|
assertTrue(out.toString("UTF-8").trim().endsWith("was this logged?")); |
43 |
1
|
assertTrue(0 <= out.toString("UTF-8").indexOf("reply")); |
44 |
1
|
assertTrue(0 <= out.toString("UTF-8").indexOf("failure and error")); |
45 |
1
|
assertTrue(0 <= out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml")); |
46 |
1
|
int pos = out.toString("UTF-8").length(); |
47 |
1
|
listener.logFailureReply("failure and error", "http://mysite.org/mymodule.xml", "this is the end"); |
48 |
1
|
assertTrue(out.toString("UTF-8").trim().endsWith("this is the end")); |
49 |
1
|
assertTrue(pos <= out.toString("UTF-8").indexOf("reply", pos)); |
50 |
1
|
assertTrue(pos <= out.toString("UTF-8").indexOf("failure and error", pos)); |
51 |
1
|
assertTrue(-1 == out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml", pos)); |
52 |
|
} |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
54 |
1
|
public void testLogSuccessfulReply() throws Exception{... |
55 |
1
|
listener.logSuccessfulReply("successfully loaded", "http://mysite.org/mymodule.xml"); |
56 |
|
|
57 |
1
|
assertTrue(0 <= out.toString("UTF-8").indexOf("successfully loaded")); |
58 |
1
|
assertTrue(0 <= out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml")); |
59 |
1
|
int pos = out.toString("UTF-8").length(); |
60 |
1
|
listener.logSuccessfulReply("successfully loaded", "http://mysite.org/mymodule.xml"); |
61 |
1
|
assertTrue(-1 == out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml", pos)); |
62 |
1
|
assertTrue(pos <= out.toString("UTF-8").indexOf("successfully loaded", pos)); |
63 |
|
} |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
65 |
1
|
public void testLogMessageState() throws Exception{... |
66 |
1
|
listener.logMessageState("loading 10 percent complete", "http://mysite.org/mymodule.xml"); |
67 |
|
|
68 |
1
|
assertTrue(0 <= out.toString("UTF-8").indexOf("loading 10 percent complete")); |
69 |
1
|
assertTrue(0 <= out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml")); |
70 |
|
|
71 |
1
|
int pos = out.toString("UTF-8").length(); |
72 |
1
|
listener.logMessageState("loading 20 percent complete", "http://mysite.org/mymodule.xml"); |
73 |
1
|
assertTrue(pos <= out.toString("UTF-8").indexOf("loading 20 percent complete", pos)); |
74 |
1
|
assertTrue(-1 == out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml", pos)); |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1
PASS
|
|
77 |
1
|
public void testLogFailureState() throws Exception{... |
78 |
1
|
listener.logFailureState("error state occured", "http://mysite.org/mymodule.xml", "was this logged?"); |
79 |
|
|
80 |
1
|
assertTrue(out.toString("UTF-8").trim().endsWith("was this logged?")); |
81 |
1
|
assertTrue(0 <= out.toString("UTF-8").indexOf("failure")); |
82 |
1
|
assertTrue(0 <= out.toString("UTF-8").indexOf("error state occured")); |
83 |
1
|
assertTrue(0 <= out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml")); |
84 |
1
|
int pos = out.toString("UTF-8").length(); |
85 |
1
|
listener.logFailureState("error state occured", "http://mysite.org/mymodule.xml", "was this logged!"); |
86 |
1
|
assertTrue(out.toString("UTF-8").trim().endsWith("was this logged!")); |
87 |
1
|
assertTrue(pos <= out.toString("UTF-8").indexOf("failure", pos)); |
88 |
1
|
assertTrue(pos <= out.toString("UTF-8").indexOf("error state occured", pos)); |
89 |
1
|
assertTrue(-1 == out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml", pos)); |
90 |
|
} |
91 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1
PASS
|
|
92 |
1
|
public void testLogSuccesfulState() throws Exception{... |
93 |
1
|
listener.logSuccessfulState("we are the champions", "http://mysite.org/mymodule.xml"); |
94 |
|
|
95 |
1
|
assertTrue(0 <= out.toString("UTF-8").indexOf("success")); |
96 |
1
|
assertTrue(0 <= out.toString("UTF-8").indexOf("we are the champions")); |
97 |
1
|
assertTrue(0 <= out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml")); |
98 |
1
|
int pos = out.toString("UTF-8").length(); |
99 |
1
|
listener.logSuccessfulState("rain begins to fall", "http://mysite.org/mymodule.xml"); |
100 |
1
|
assertTrue(pos <= out.toString("UTF-8").indexOf("success", pos)); |
101 |
1
|
assertTrue(pos <= out.toString("UTF-8").indexOf("rain begins to fall", pos)); |
102 |
1
|
assertTrue(-1 == out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml", pos)); |
103 |
|
} |
104 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
105 |
1
|
public void testLogRequest() throws Exception{... |
106 |
1
|
listener.logRequest("validating", "http://mysite.org/mymodule.xml"); |
107 |
|
|
108 |
1
|
assertTrue(0 <= out.toString("UTF-8").indexOf("validating")); |
109 |
1
|
assertTrue(0 <= out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml")); |
110 |
1
|
int pos = out.toString("UTF-8").length(); |
111 |
1
|
listener.logRequest("validated", "http://mysite.org/mymodule.xml"); |
112 |
1
|
assertTrue(pos <= out.toString("UTF-8").indexOf("validated", pos)); |
113 |
1
|
assertTrue(-1 == out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml", pos)); |
114 |
|
} |
115 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1
PASS
|
|
116 |
1
|
public void testLogMessage() throws Exception{... |
117 |
1
|
listener.logMessage("we are on a yellow submarine"); |
118 |
1
|
assertTrue(0 <= out.toString("UTF-8").indexOf("we are on a yellow submarine")); |
119 |
1
|
int pos = out.toString("UTF-8").length(); |
120 |
1
|
listener.logMessage("we are on a blue submarine"); |
121 |
1
|
assertTrue(pos <= out.toString("UTF-8").indexOf("we are on a blue submarine", pos)); |
122 |
|
} |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
124 |
1
|
public void testSetPrintStream() throws Exception {... |
125 |
1
|
ByteArrayOutputStream out2 = new ByteArrayOutputStream(); |
126 |
1
|
listener.setPrintStream(new PrintStream(out2)); |
127 |
1
|
listener.logFailureReply("failure", "http://mysite.org/mymodule.xml", "was this logged?"); |
128 |
|
|
129 |
1
|
assertTrue(out2.toString("UTF-8").trim().endsWith("was this logged?")); |
130 |
1
|
assertTrue(0 <= out2.toString("UTF-8").indexOf("reply")); |
131 |
1
|
assertTrue(0 <= out2.toString("UTF-8").indexOf("failure")); |
132 |
1
|
assertTrue(0 <= out2.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml")); |
133 |
|
} |
134 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
135 |
1
|
public void testConstructor() throws Exception {... |
136 |
1
|
ByteArrayOutputStream out2 = new ByteArrayOutputStream(); |
137 |
1
|
LogListenerImpl listener2 = new LogListenerImpl(new PrintStream(out2)); |
138 |
1
|
listener2.logFailureReply("failure", "http://mysite.org/mymodule.xml", "was this logged?"); |
139 |
|
|
140 |
1
|
assertTrue(out2.toString("UTF-8").trim().endsWith("was this logged?")); |
141 |
1
|
assertTrue(0 <= out2.toString("UTF-8").indexOf("reply")); |
142 |
1
|
assertTrue(0 <= out2.toString("UTF-8").indexOf("failure")); |
143 |
1
|
assertTrue(0 <= out2.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml")); |
144 |
|
} |
145 |
|
|
146 |
|
} |