Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
67   170   20   3.35
0   119   0.3   20
20     1  
1    
 
  QedeqLogTest       Line # 28 67 20 100% 1.0
 
  (11)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
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    * Test class.
25    *
26    * @author Michael Meyling
27    */
 
28    public class QedeqLogTest extends QedeqBoTestCase {
29   
30    private QedeqLog listener;
31    private LogListenerImpl listenerBasis;
32    private ByteArrayOutputStream out;
33    private LogListener thrower;
34   
 
35  11 toggle protected void setUp() throws Exception {
36  11 super.setUp();
37  11 out = new ByteArrayOutputStream();
38  11 listenerBasis = new LogListenerImpl(new PrintStream(out));
39  11 listener = QedeqLog.getInstance();
40  11 listener.addLog(listenerBasis);
41  11 thrower = new LogListener() {
 
42  3 toggle public void logMessage(String text) {
43  3 throw new RuntimeException("Boo! This test exception is ok!");
44    }
45   
 
46  1 toggle public void logRequest(String text, String url) {
47  1 throw new RuntimeException("Boo! This test exception is ok!");
48    }
49   
 
50  1 toggle public void logSuccessfulReply(String text, String url) {
51  1 throw new RuntimeException("Boo! This test exception is ok!");
52    }
53   
 
54  2 toggle public void logFailureReply(String text, String url,
55    String description) {
56  2 throw new RuntimeException("Boo! This test exception is ok!");
57    }
58   
 
59  1 toggle public void logMessageState(String text, String url) {
60  1 throw new RuntimeException("Boo! This test exception is ok!");
61    }
62   
 
63  1 toggle public void logFailureState(String text, String url,
64    String description) {
65  1 throw new RuntimeException("Boo! This test exception is ok!");
66    }
67   
 
68  1 toggle public void logSuccessfulState(String text, String url) {
69  1 throw new RuntimeException("Boo! This test exception is ok!");
70    }
71    };
72  11 listener.addLog(thrower);
73    }
74   
 
75  11 toggle public void tearDown() throws Exception {
76  11 listener.removeLog(thrower);
77  11 listener.removeLog(listenerBasis);
78  11 super.tearDown();
79    }
80   
 
81  1 toggle public void testLogFailureReply() throws Exception{
82  1 listener.logFailureReply("failure and error", "http://mysite.org/mymodule.xml", "was this logged?");
83  1 System.out.println(out.toString("UTF-8"));
84  1 assertTrue(out.toString("UTF-8").trim().endsWith("was this logged?"));
85  1 assertTrue(0 <= out.toString("UTF-8").indexOf("reply"));
86  1 assertTrue(0 <= out.toString("UTF-8").indexOf("failure and error"));
87  1 assertTrue(0 <= out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml"));
88    }
89   
 
90  1 toggle public void testLogSuccessfulReply() throws Exception{
91  1 listener.logSuccessfulReply("successfully loaded", "http://mysite.org/mymodule.xml");
92    // System.out.println(out.toString("UTF-8"));
93  1 assertTrue(0 <= out.toString("UTF-8").indexOf("successfully loaded"));
94  1 assertTrue(0 <= out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml"));
95    }
96   
 
97  1 toggle public void testLogMessageState() throws Exception{
98  1 listener.logMessageState("loading 10 percent complete", "http://mysite.org/mymodule.xml");
99    // System.out.println(out.toString("UTF-8"));
100  1 assertTrue(0 <= out.toString("UTF-8").indexOf("loading 10 percent complete"));
101  1 assertTrue(0 <= out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml"));
102    }
103   
 
104  1 toggle public void testLogFailureState() throws Exception{
105  1 listener.logFailureState("error state occured", "http://mysite.org/mymodule.xml", "was this logged?");
106    // System.out.println(out.toString("UTF-8"));
107  1 assertTrue(out.toString("UTF-8").trim().endsWith("was this logged?"));
108  1 assertTrue(0 <= out.toString("UTF-8").indexOf("failure"));
109  1 assertTrue(0 <= out.toString("UTF-8").indexOf("error state occured"));
110  1 assertTrue(0 <= out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml"));
111    }
112   
 
113  1 toggle public void testLogSuccesfulState() throws Exception{
114  1 listener.logSuccessfulState("we are the champions", "http://mysite.org/mymodule.xml");
115    // System.out.println(out.toString("UTF-8"));
116  1 assertTrue(0 <= out.toString("UTF-8").indexOf("success"));
117  1 assertTrue(0 <= out.toString("UTF-8").indexOf("we are the champions"));
118  1 assertTrue(0 <= out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml"));
119    }
120   
 
121  1 toggle public void testLogRequest() throws Exception{
122  1 listener.logRequest("validate", "http://mysite.org/mymodule.xml");
123    // System.out.println(out.toString("UTF-8"));
124  1 assertTrue(0 <= out.toString("UTF-8").indexOf("validate"));
125  1 assertTrue(0 <= out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml"));
126    }
127   
 
128  1 toggle public void testLogMessage() throws Exception{
129  1 listener.logMessage("we are on a yellow submarine");
130  1 assertTrue(0 <= out.toString("UTF-8").indexOf("we are on a yellow submarine"));
131    }
132   
 
133  1 toggle public void testRemoveLog() throws Exception{
134  1 listener.removeLog(null);
135  1 listener.logMessage("we are on a yellow submarine");
136  1 assertTrue(0 <= out.toString("UTF-8").indexOf("we are on a yellow submarine"));
137    }
138   
 
139  1 toggle public void testRemoveLog2() throws Exception{
140  1 listener.removeLog(listenerBasis);
141  1 listener.logMessage("we are on a yellow submarine");
142  1 assertEquals(0, out.size());
143    }
144   
 
145  1 toggle public void testAddLog() throws Exception {
146  1 ByteArrayOutputStream out2 = new ByteArrayOutputStream();
147  1 listener.addLog(new LogListenerImpl(new PrintStream(out2)));
148  1 listener.logFailureReply("failure", "http://mysite.org/mymodule.xml", "was this logged?");
149  1 assertTrue(out.toString("UTF-8").trim().endsWith("was this logged?"));
150  1 assertTrue(0 <= out.toString("UTF-8").indexOf("reply"));
151  1 assertTrue(0 <= out.toString("UTF-8").indexOf("failure"));
152  1 assertTrue(0 <= out.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml"));
153  1 assertTrue(out2.toString("UTF-8").trim().endsWith("was this logged?"));
154  1 assertTrue(0 <= out2.toString("UTF-8").indexOf("reply"));
155  1 assertTrue(0 <= out2.toString("UTF-8").indexOf("failure"));
156  1 assertTrue(0 <= out2.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml"));
157    }
158   
 
159  1 toggle public void testConstructor() throws Exception {
160  1 ByteArrayOutputStream out2 = new ByteArrayOutputStream();
161  1 LogListenerImpl listener2 = new LogListenerImpl(new PrintStream(out2));
162  1 listener2.logFailureReply("failure", "http://mysite.org/mymodule.xml", "was this logged?");
163    // System.out.println(out2.toString("UTF-8"));
164  1 assertTrue(out2.toString("UTF-8").trim().endsWith("was this logged?"));
165  1 assertTrue(0 <= out2.toString("UTF-8").indexOf("reply"));
166  1 assertTrue(0 <= out2.toString("UTF-8").indexOf("failure"));
167  1 assertTrue(0 <= out2.toString("UTF-8").indexOf("http://mysite.org/mymodule.xml"));
168    }
169   
170    }