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-2007 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.jellytools;
042:
043: import junit.framework.Test;
044: import junit.textui.TestRunner;
045: import org.netbeans.jellytools.nodes.Node;
046: import org.netbeans.jellytools.nodes.SourcePackagesNode;
047: import org.netbeans.jemmy.operators.Operator.DefaultStringComparator;
048: import org.netbeans.junit.NbTestSuite;
049:
050: /** Test of org.netbeans.jellytools.SaveAsTemplateOperator.
051: */
052: public class SaveAsTemplateOperatorTest extends JellyTestCase {
053:
054: /** Use for internal test execution inside IDE
055: * @param args command line arguments
056: */
057: public static void main(java.lang.String[] args) {
058: TestRunner.run(suite());
059: }
060:
061: /** Method used for explicit testsuite definition
062: * @return created suite
063: */
064: public static Test suite() {
065: NbTestSuite suite = new NbTestSuite();
066: suite.addTest(new SaveAsTemplateOperatorTest("testInvoke"));
067: suite.addTest(new SaveAsTemplateOperatorTest("testTree"));
068: suite.addTest(new SaveAsTemplateOperatorTest(
069: "testLblSelectTheCategory"));
070: suite
071: .addTest(new SaveAsTemplateOperatorTest(
072: "testGetRootNode"));
073: suite.addTest(new SaveAsTemplateOperatorTest(
074: "testSelectTemplate"));
075: return suite;
076: }
077:
078: protected void setUp() {
079: System.out.println("### " + getName() + " ###");
080: }
081:
082: /** Constructor required by JUnit.
083: * @param testName method name to be used as testcase
084: */
085: public SaveAsTemplateOperatorTest(String testName) {
086: super (testName);
087: }
088:
089: /** Test of invoke method. */
090: public void testInvoke() {
091: Node sample1 = new Node(
092: new SourcePackagesNode("SampleProject"), "sample1"); // NOI18N
093: Node sampleClass1 = new Node(sample1, "SampleClass1.java"); // NOI18N
094: SaveAsTemplateOperator.invoke(sampleClass1);
095: }
096:
097: /** Test of tree method. */
098: public void testTree() {
099: SaveAsTemplateOperator sato = new SaveAsTemplateOperator();
100: sato.tree();
101: }
102:
103: /** Test of lblSelectTheCategory method. */
104: public void testLblSelectTheCategory() {
105: SaveAsTemplateOperator sato = new SaveAsTemplateOperator();
106: String labelText = sato.lblSelectTheCategory().getText();
107: String expectedText = Bundle.getStringTrimmed(
108: "org.openide.loaders.Bundle", "CTL_SaveAsTemplate");
109: assertEquals("Wrong label found.", expectedText, labelText);
110: }
111:
112: /** Test of getRootNode method. */
113: public void testGetRootNode() {
114: SaveAsTemplateOperator sato = new SaveAsTemplateOperator();
115: String text = sato.getRootNode().getText();
116: String expectedText = "Templates"; // NOI18N
117: assertEquals("Wrong root node.", expectedText, text);
118: }
119:
120: /** Test of selectTemplate method. */
121: public void testSelectTemplate() {
122: SaveAsTemplateOperator sato = new SaveAsTemplateOperator();
123: String mainClass = Bundle.getString(
124: "org.netbeans.modules.java.project.Bundle",
125: "Templates/Classes/Main.java");
126: // "Java Classes|Java Main Class"
127: String templatePath = Bundle.getString(
128: "org.netbeans.modules.java.project.Bundle",
129: "Templates/Classes")
130: + "|" + mainClass;
131: sato.setComparator(new DefaultStringComparator(true, true));
132: sato.selectTemplate(templatePath);
133: String selected = sato.tree().getSelectionPath()
134: .getLastPathComponent().toString();
135: sato.close();
136: assertEquals("Path \"" + templatePath + "\" not selected.",
137: mainClass, selected);
138: }
139: }
|