Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
74   146   10   7.4
0   101   0.14   10
10     1  
1    
 
  LogListenerImplTest       Line # 28 74 10 100% 1.0
 
  (9)
 
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 LogListenerImplTest extends QedeqBoTestCase {
29   
30    private LogListenerImpl listener;
31    private ByteArrayOutputStream out;
32   
 
33  9 toggle protected void setUp() throws Exception {
34  9 super.setUp();
35  9 out = new ByteArrayOutputStream();
36  9 listener = new LogListenerImpl(new PrintStream(out));
37    }
38   
 
39  1 toggle public void testLogFailureReply() throws Exception{
40  1 listener.logFailureReply("failure and error", "http://mysite.org/mymodule.xml", "was this logged?");
41    // System.out.println(out.toString("UTF-8"));
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   
 
54  1 toggle public void testLogSuccessfulReply() throws Exception{
55  1 listener.logSuccessfulReply("successfully loaded", "http://mysite.org/mymodule.xml");
56    // System.out.println(out.toString("UTF-8"));
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   
 
65  1 toggle public void testLogMessageState() throws Exception{
66  1 listener.logMessageState("loading 10 percent complete", "http://mysite.org/mymodule.xml");
67    // System.out.println(out.toString("UTF-8"));
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    // System.out.println(out.toString("UTF-8"));
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   
 
77  1 toggle public void testLogFailureState() throws Exception{
78  1 listener.logFailureState("error state occured", "http://mysite.org/mymodule.xml", "was this logged?");
79    // System.out.println(out.toString("UTF-8"));
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   
 
92  1 toggle public void testLogSuccesfulState() throws Exception{
93  1 listener.logSuccessfulState("we are the champions", "http://mysite.org/mymodule.xml");
94    // System.out.println(out.toString("UTF-8"));
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   
 
105  1 toggle public void testLogRequest() throws Exception{
106  1 listener.logRequest("validating", "http://mysite.org/mymodule.xml");
107    // System.out.println(out.toString("UTF-8"));
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   
 
116  1 toggle 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   
 
124  1 toggle 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    // System.out.println(out2.toString("UTF-8"));
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   
 
135  1 toggle 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    // System.out.println(out2.toString("UTF-8"));
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    }