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: * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
027: */
028:
029: package org.netbeans.lib.uihandlerserver;
030:
031: import java.io.ByteArrayInputStream;
032: import java.io.InputStream;
033: import java.util.logging.Level;
034: import java.util.logging.LogRecord;
035: import java.util.logging.Logger;
036: import org.netbeans.junit.NbTestCase;
037: import org.netbeans.lib.uihandler.ProjectOp;
038: import org.netbeans.lib.uihandler.TestHandler;
039:
040: /**
041: *
042: * @author Jaroslav Tulach
043: */
044: public class ProjectOpTest extends NbTestCase {
045: private Logger LOG;
046:
047: public ProjectOpTest(String testName) {
048: super (testName);
049: }
050:
051: protected Level logLevel() {
052: return Level.FINEST;
053: }
054:
055: protected void setUp() throws Exception {
056: LOG = Logger.getLogger("TEST-" + getName());
057: }
058:
059: protected void tearDown() throws Exception {
060: }
061:
062: public void testOpenAndCloseAProject() throws Exception {
063: String what = "<record>"
064: + "<date>2007-02-05T14:14:17</date>"
065: + "<millis>1170681257194</millis>"
066: + "<sequence>1148</sequence>"
067: + "<logger>org.netbeans.ui.projects</logger>"
068: + "<level>CONFIG</level>"
069: + "<thread>11</thread>"
070: + "<message>Closing 1 NbModuleProject Projects</message>"
071: + "<key>UI_CLOSED_PROJECTS</key>"
072: + "<catalog><null></catalog>"
073: + "<param>org.netbeans.modules.apisupport.project.NbModuleProject</param>"
074: + "<param>NbModuleProject</param>"
075: + "<param>1</param>"
076: + "</record>"
077: + "<record>"
078: + "<date>2007-02-06T09:08:03</date>"
079: + "<millis>1170749283986</millis>"
080: + "<sequence>1441</sequence>"
081: + "<logger>org.netbeans.ui.actions.editor</logger>"
082: + "<level>FINE</level>"
083: + "<thread>11</thread>"
084: + "<message>Invoking copy-to-clipboard implemented as org.netbeans.editor.BaseKit$CopyAction@e29e2c thru java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=,when=1170749283985,modifiers=Ctrl] on org.openide.text.QuietEditorPane[,0,-931,1048x1485,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.basic.BasicBorders$MarginBorder@aec245,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=java.awt.Color[r=255,g=255,b=255],disabledTextColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],editable=true,margin=java.awt.Insets[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],kit=org.netbeans.modules.editor.java.JavaKit@1e6cecc,typeHandlers=]</message>"
085: + "<key>UI_ACTION_EDITOR</key>"
086: + "<catalog><null></catalog>"
087: + "<param>java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=,when=1170749283985,modifiers=Ctrl] on org.openide.text.QuietEditorPane[,0,-931,1041x1515,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.basic.BasicBorders$MarginBorder@aec245,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=java.awt.Color[r=255,g=255,b=255],disabledTextColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],editable=true,margin=java.awt.Insets[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],kit=org.netbeans.modules.editor.java.JavaKit@1e6cecc,typeHandlers=]</param>"
088: + "<param>java.awt.event.ActionEvent[ACTION_PERFORMED,cmd=,when=1170749283985,modifiers=Ctrl] on org.openide.text.QuietEditorPane[,0,-931,1048x1485,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=javax.swing.plaf.basic.BasicBorders$MarginBorder@aec245,flags=296,maximumSize=,minimumSize=,preferredSize=,caretColor=java.awt.Color[r=255,g=255,b=255],disabledTextColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],editable=true,margin=java.awt.Insets[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],kit=org.netbeans.modules.editor.java.JavaKit@1e6cecc,typeHandlers=]</param>"
089: + "<param>org.netbeans.editor.BaseKit$CopyAction@e29e2c</param>"
090: + "<param>org.netbeans.editor.BaseKit$CopyAction@e29e2c</param>"
091: + "<param>copy-to-clipboard</param>"
092: + "</record>"
093: + "<record>"
094: + " <date>2007-02-06T09:05:59</date>"
095: + " <millis>1170749159147</millis>"
096: + " <sequence>1399</sequence>"
097: + " <logger>org.netbeans.ui.projects</logger>"
098: + " <level>CONFIG</level>"
099: + " <thread>11</thread>"
100: + " <message>Opening 1 NbModuleProject Projects</message>"
101: + " <key>UI_OPEN_PROJECTS</key>"
102: + " <catalog><null></catalog>"
103: + " <param>org.netbeans.modules.apisupport.project.NbModuleProject</param>"
104: + " <param>NbModuleProject</param>"
105: + " <param>1</param>" + "</record>";
106:
107: InputStream is = new ByteArrayInputStream(what.getBytes());
108: TestHandler records = new TestHandler(is);
109: LogRecord rec = records.read();
110: LogRecord rec2 = records.read();
111: LogRecord rec3 = records.read();
112: is.close();
113:
114: ProjectOp op = ProjectOp.valueOf(rec);
115:
116: assertNotNull("This record is project operation", op);
117: assertEquals(
118: "org.netbeans.modules.apisupport.project.NbModuleProject",
119: op.getProjectType());
120: assertEquals(-1, op.getDelta());
121: assertEquals("NbModuleProject", op.getProjectDisplayName());
122:
123: op = ProjectOp.valueOf(rec2);
124: assertNull("No project operation", op);
125:
126: op = ProjectOp.valueOf(rec3);
127: assertNotNull("This record is project operation", op);
128: assertEquals(
129: "org.netbeans.modules.apisupport.project.NbModuleProject",
130: op.getProjectType());
131: assertEquals("One project added", 1, op.getDelta());
132: assertEquals("NbModuleProject", op.getProjectDisplayName());
133:
134: }
135:
136: public void testAntProjectStyle() throws Exception {
137:
138: String log = "<record>"
139: + " <date>2007-09-11T14:41:41</date>"
140: + " <millis>1189514501494</millis>"
141: + " <sequence>90</sequence>"
142: + " <level>CONFIG</level>"
143: + " <thread>12</thread>"
144: + " <message>Opening 1 FreeformProject Projects</message>"
145: + " <key>UI_OPEN_PROJECTS</key>"
146: + " <catalog>org.netbeans.modules.project.ui.Bundle</catalog>"
147: + " <param>org.netbeans.modules.ant.freeform.FreeformProject</param>"
148: + " <param>FreeformProject</param>"
149: + " <param>1</param>" + "</record>";
150:
151: InputStream is = new ByteArrayInputStream(log.getBytes());
152: TestHandler records = new TestHandler(is);
153: LogRecord rec = records.read();
154: is.close();
155:
156: ProjectOp op = ProjectOp.valueOf(rec);
157: assertEquals("One change", 1, op.getDelta());
158: assertEquals(
159: "org.netbeans.modules.ant.freeform.FreeformProject", op
160: .getProjectType());
161: assertEquals("FreeformProject", op.getProjectDisplayName());
162: }
163:
164: public void testProjectOpError() throws Exception {
165: LogRecord rec = new LogRecord(Level.WARNING,
166: "UI_CLOSED_PROJECTS");
167: rec.setParameters(new Object[] { "kuk", "buch",
168: "org.netbeans.modules.xml.schema.model/1" });
169:
170: ProjectOp op = ProjectOp.valueOf(rec);
171: assertNull("Not recognized log", op);
172: }
173: }
|