001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.timers;
042:
043: import java.lang.ref.Reference;
044: import java.lang.ref.WeakReference;
045: import java.util.ArrayList;
046: import java.util.Collection;
047: import java.util.List;
048: import java.util.ResourceBundle;
049: import java.util.logging.Level;
050: import java.util.logging.LogRecord;
051: import java.util.logging.Logger;
052: import org.netbeans.junit.NbTestCase;
053: import org.netbeans.modules.timers.TimesCollectorPeer.Description;
054: import org.openide.filesystems.FileObject;
055: import org.openide.filesystems.FileSystem;
056: import org.openide.filesystems.Repository;
057:
058: /**
059: *
060: * @author Jaroslav Tulach
061: */
062: public class HandlerTest extends NbTestCase {
063:
064: public HandlerTest(String name) {
065: super (name);
066: }
067:
068: @Override
069: protected boolean runInEQ() {
070: return true;
071: }
072:
073: @Override
074: protected void setUp() throws Exception {
075: Install.findObject(Install.class, true).restored();
076: }
077:
078: @Override
079: @SuppressWarnings("deprecation")
080: protected void tearDown() throws Exception {
081: for (FileSystem fs : Repository.getDefault().toArray()) {
082: Repository.getDefault().removeFileSystem(fs);
083: }
084:
085: List<Reference> gc = new ArrayList<Reference>();
086:
087: for (Object key : TimesCollectorPeer.getDefault().getFiles()) {
088: gc.add(new WeakReference<Object>(key));
089: }
090:
091: for (Reference<?> reference : gc) {
092: assertGC("GC it", reference);
093: }
094:
095: }
096:
097: public void testLoggingMessageWithBundle() throws Exception {
098: FileObject dir = TimesCollectorPeerTest.makeScratchDir(this );
099:
100: Logger LOG = Logger.getLogger("TIMER.instance.of.my.object");
101: LogRecord rec = new LogRecord(Level.FINE, "LOG_Project"); // NOI18N
102: rec.setParameters(new Object[] { dir, dir });
103: rec.setResourceBundle(ResourceBundle
104: .getBundle(HandlerTest.class.getName()));
105: LOG.log(rec);
106:
107: Collection<Object> files = TimesCollectorPeer.getDefault()
108: .getFiles();
109: assertEquals("One object " + files, 1, files.size());
110:
111: Description descr = TimesCollectorPeer.getDefault()
112: .getDescription(files.iterator().next(), "LOG_Project");
113: assertNotNull(descr);
114:
115: if (descr.getMessage().indexOf("My Project") == -1) {
116: fail("Localized msg should contain 'My Project': "
117: + descr.getMessage());
118: }
119: }
120:
121: public void testLoggingMessageWithBundleAndArg() throws Exception {
122: FileObject dir = TimesCollectorPeerTest.makeScratchDir(this );
123:
124: Logger LOG = Logger.getLogger("TIMER.instance.of.my.object");
125: LogRecord rec = new LogRecord(Level.FINE, "LOG_ProjectWithArg"); // NOI18N
126: rec.setParameters(new Object[] { dir, dir, "Lovely" });
127: rec.setResourceBundle(ResourceBundle
128: .getBundle(HandlerTest.class.getName()));
129: LOG.log(rec);
130:
131: Collection<Object> files = TimesCollectorPeer.getDefault()
132: .getFiles();
133: assertEquals("One object " + files, 1, files.size());
134:
135: Description descr = TimesCollectorPeer.getDefault()
136: .getDescription(files.iterator().next(),
137: "LOG_ProjectWithArg");
138: assertNotNull(descr);
139:
140: if (descr.getMessage().indexOf("My Lovely Project") == -1) {
141: fail("Localized msg should contain 'My Lovely Project': "
142: + descr.getMessage());
143: }
144: }
145:
146: }
|