KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > server > uihandler > TipOfTheDayTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.server.uihandler;
21
22 import java.io.ByteArrayInputStream JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.logging.Handler JavaDoc;
26 import java.util.logging.Level JavaDoc;
27 import java.util.logging.LogRecord JavaDoc;
28 import org.netbeans.junit.Log;
29 import org.netbeans.junit.NbTestCase;
30 import org.netbeans.lib.uihandler.LogRecords;
31 import org.netbeans.lib.uihandler.ProjectOp;
32 import org.netbeans.server.uihandler.TipOfTheDay.Tip;
33 import org.netbeans.server.uihandler.statistics.ProjectTypes;
34
35 /**
36  *
37  * @author Jaroslav Tulach
38  */

39 public class TipOfTheDayTest extends NbTestCase {
40     private TipOfTheDay db;
41     
42     
43     public TipOfTheDayTest(String JavaDoc testName) {
44         super(testName);
45     }
46     
47     protected void setUp() throws Exception JavaDoc {
48         clearWorkDir();
49         
50     }
51     
52     protected void tearDown() throws Exception JavaDoc {
53         super.tearDown();
54     }
55     
56     protected Level JavaDoc logLevel() {
57         return Level.INFO;
58     }
59     
60     public void testGetDefaultReturnsSomething() throws Exception JavaDoc {
61         CharSequence JavaDoc log = Log.enable("org.netbeans", Level.WARNING);
62         TipOfTheDay t = TipOfTheDay.getDefault();
63         assertNotNull(t);
64         if (log.toString().indexOf("env") == -1) {
65             fail("There should be a warning about environment variables:\n" + log);
66         }
67         assertNull("no help", t.find(null));
68     }
69
70     public void testTipOfTheDayIsParseable() throws Exception JavaDoc {
71         db = TipOfTheDay.create(getClass().getResource("kb-2007-03-08.xml"));
72
73         String JavaDoc log =
74 "<record>" +
75   "<date>2007-01-09T09:53:09</date>" +
76   "<millis>1168332789249</millis>" +
77   "<sequence>43</sequence>" +
78   "<logger>UIHandler:</logger>" +
79   "<level>CONFIG</level>" +
80   "<thread>10</thread>" +
81   "<message>Opening 1 FreeformProject Projects</message>" +
82   "<key>UI_OPEN_PROJECTS</key>" +
83   "<catalog>&lt;null&gt;</catalog>" +
84   "<param>org.netbeans.modules.ant.freeform.FreeformProject</param>" +
85   "<param>FreeformProject</param>" +
86   "<param>1</param>" +
87 "</record>" +
88 "<record>" +
89   "<date>2007-01-09T09:53:09</date>" +
90   "<millis>1168332789249</millis>" +
91   "<sequence>44</sequence>" +
92   "<logger>UIHandler:</logger>" +
93   "<level>CONFIG</level>" +
94   "<thread>10</thread>" +
95   "<message>Opening 6 J2SEProject Projects</message>" +
96   "<key>UI_OPEN_PROJECTS</key>" +
97   "<catalog>&lt;null&gt;</catalog>" +
98   "<param>org.netbeans.modules.java.j2seproject.J2SEProject</param>" +
99   "<param>J2SEProject</param>" +
100   "<param>6</param>" +
101 "</record>";
102         
103         class H extends Handler JavaDoc {
104             LogRecord JavaDoc one;
105             LogRecord JavaDoc two;
106             
107             public void publish(LogRecord JavaDoc arg0) {
108                 if (one == null) {
109                     one = arg0;
110                     return;
111                 }
112                 if (two == null) {
113                     two = arg0;
114                     return;
115                 }
116                 fail("One two records expected");
117             }
118
119             public void flush() {
120             }
121
122             public void close() throws SecurityException JavaDoc {
123             }
124         }
125         H h = new H();
126         LogRecords.scan(new ByteArrayInputStream JavaDoc(log.getBytes()), h);
127         assertNotNull("Two parsed", h.two);
128         
129         ProjectTypes types = new ProjectTypes();
130         Statistics<ProjectTypes.Counts> stats = types;
131         
132         ProjectTypes.Counts one = stats.process(h.one);
133         ProjectTypes.Counts two = stats.process(h.two);
134         
135         ProjectTypes.Counts res = stats.join(one, two);
136         
137         List JavaDoc<? extends Tip> tips = db.findAll(res);
138         
139         assertNotNull("There is some tip for J2SE", tips);
140         
141         if (tips.isEmpty()) {
142             fail("should not be empty");
143         }
144         
145         if (tips.size() < 25) {
146             fail("There is at least 25 tips for J2SE was " + tips.size() + ":\n" + tips);
147         }
148     }
149     
150 }
151
Popular Tags