KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > test > editor > app > core > Test


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 package org.netbeans.test.editor.app.core;
20
21 import java.beans.*;
22 import java.util.ArrayList JavaDoc;
23 import javax.swing.*;
24
25 import java.util.Vector JavaDoc;
26 import java.util.Collection JavaDoc;
27 import org.netbeans.test.editor.app.Main;
28 import org.netbeans.test.editor.app.core.actions.ActionRegistry;
29 import org.netbeans.test.editor.app.core.cookies.PerformCookie;
30 import org.netbeans.test.editor.app.core.properties.BadPropertyNameException;
31 import org.netbeans.test.editor.app.core.properties.MultiLineStringProperty;
32 import org.netbeans.test.editor.app.core.properties.Properties;
33 import org.netbeans.test.editor.app.core.properties.StringProperty;
34 import org.netbeans.test.editor.app.gui.QuestionDialog;
35 import org.netbeans.test.editor.app.gui.actions.TreeNewType;
36 import org.netbeans.test.editor.app.util.ParsingUtils;
37 //import java.util.Iterator;
38
import org.w3c.dom.Element JavaDoc;
39 import org.w3c.dom.Document JavaDoc;
40 import org.w3c.dom.NodeList JavaDoc;
41 import org.w3c.dom.Node JavaDoc;
42
43
44 /**
45  *
46  * @author ehucka
47  * @version
48  */

49 public class Test extends TestGroup {
50     
51     public static final String JavaDoc AUTHOR = "Author";
52     public static final String JavaDoc VERSION = "Version";
53     public static final String JavaDoc COMMENT = "Comment";
54     
55     private String JavaDoc author,version,comment;
56     
57     public JEditorPane editor;
58     public Logger logger;
59     
60     private static boolean testing = false; /*Are we inside of test suite?*/
61     
62     /** Creates new Test */
63     public Test(String JavaDoc name) {
64     super(name);
65     if ((author=System.getProperty("user.name")) == null) {
66         author = "NoAuthor";
67     }
68     version = "1.0";
69     comment = "";
70     }
71     
72     public Test(Element JavaDoc node) {
73     super(node);
74     author = node.getAttribute(AUTHOR);
75     version = node.getAttribute(VERSION);
76     comment = ParsingUtils.loadString(node, COMMENT);
77     logger = new Logger(Main.frame.getEditor());
78     }
79     
80     public Element JavaDoc toXML(Element JavaDoc node) {
81     node = super.toXML(node);
82     node.setAttribute(AUTHOR, author);
83     node.setAttribute(VERSION, version);
84     return ParsingUtils.saveString(node, COMMENT, comment);
85     }
86     
87     public void fromXML(Element JavaDoc node) throws BadPropertyNameException {
88     super.fromXML(node);
89     author = node.getAttribute(AUTHOR);
90     version = node.getAttribute(VERSION);
91     comment = ParsingUtils.loadString(node, COMMENT);
92     }
93     
94     public Properties getProperties() {
95     Properties ret=super.getProperties();
96     ret.put(AUTHOR, new StringProperty(author));
97     ret.put(VERSION, new StringProperty(version));
98     ret.put(COMMENT, new MultiLineStringProperty(comment));
99     return ret;
100     }
101     
102     public Object JavaDoc getProperty(String JavaDoc name) throws BadPropertyNameException {
103     if (name.compareTo(AUTHOR) == 0) {
104         return new StringProperty(author);
105     } else if (name.compareTo(VERSION) == 0) {
106         return new StringProperty(version);
107     } else if (name.compareTo(COMMENT) == 0) {
108         return new MultiLineStringProperty(comment);
109     } else {
110         return super.getProperty(name);
111     }
112     }
113     
114     public void setProperty(String JavaDoc name, Object JavaDoc value) throws BadPropertyNameException {
115     if (name.compareTo(AUTHOR) == 0) {
116         setAuthor(((StringProperty)(value)).getProperty());
117     } else if (name.compareTo(VERSION) == 0) {
118         setVersion(((StringProperty)(value)).getProperty());
119     } else if (name.compareTo(COMMENT) == 0) {
120         setComment(((MultiLineStringProperty)(value)).getProperty());
121     } else {
122         super.setProperty(name,value);
123     }
124     }
125     
126     public JEditorPane getEditor() {
127     return editor;
128     }
129     
130     public static void setTesting() {
131     testing = true;
132     }
133     
134     public static boolean isTesting() {
135     return testing;
136     }
137     
138     public Logger getLogger() {
139     return logger;
140     }
141     
142     public String JavaDoc getAuthor() {
143     return author;
144     }
145     
146     public void setAuthor(String JavaDoc value) {
147     String JavaDoc oldValue = author;
148     author = value;
149     firePropertyChange(AUTHOR, oldValue, author);
150     }
151     
152     public String JavaDoc getVersion() {
153     return version;
154     }
155     
156     public void setVersion(String JavaDoc value) {
157     String JavaDoc oldValue = version;
158     version = value;
159     firePropertyChange(VERSION, oldValue, version);
160     }
161     
162     public String JavaDoc getComment() {
163     return comment;
164     }
165     
166     public void setComment(String JavaDoc value) {
167     String JavaDoc oldValue = comment;
168     comment = value;
169     firePropertyChange(COMMENT, oldValue, comment);
170     }
171     
172     public void rebuidlLoggers() {
173     Test t;
174     for(int i=0;i < getChildCount();i++) {
175         if (get(i) instanceof TestSubTest) {
176         t=(Test)(get(i));
177         if (t.logger == null)
178             t.logger=logger;
179         }
180     }
181     }
182     
183     public void perform() {
184     TestNode n;
185     
186     System.err.println("\nTest "+getName()+" starts performing.");
187     isPerforming=true;
188     for(int i=0;i < getChildCount();i++) {
189         if (!isPerforming) break;
190         n=get(i);
191         if (n instanceof TestAction ) {
192         n.perform();
193         } else {
194         if (n instanceof TestSubTest) {
195             n.perform();
196         }
197         }
198     }
199     isPerforming=false;
200     }
201     
202     public void stop() {
203     getLogger().stopPerforming();
204     isPerforming=false;
205     }
206     
207     //******************************************************************************
208

209     public TestCallAction[] getCallActions() {
210     ArrayList JavaDoc ret=new ArrayList JavaDoc();
211     TestNode n,n2;
212     TestGroup g;
213     for (int i=0;i < getChildCount();i++) {
214         n=(TestNode)(get(i));
215         if (n instanceof TestCallAction) {
216         ret.add(n);
217         } else if (n instanceof TestSubTest) {
218         g=(TestGroup)(n);
219         for (int j=0;j < g.getChildCount();j++) {
220             n2=(TestNode)(g.get(j));
221             if (n2 instanceof TestCallAction) {
222             ret.add(n2);
223             }
224         }
225         }
226     }
227     return (TestCallAction[])(ret.toArray(new TestCallAction[] {}));
228     }
229     
230     protected void registerNewTypes() {
231     ActionRegistry.getDefault().addRegisteredNewType(getClass(), TestSubTest.class);
232     ActionRegistry.getDefault().addRegisteredNewType(getClass(), TestStep.class);
233     ActionRegistry.getDefault().addRegisteredNewType(getClass(), TestCallAction.class);
234     }
235     
236     protected void registerCookies() {
237     getCookieSet().put(PerformCookie.class,new PerformCookie() {
238         public void perform() {
239         Test.this.perform();
240         }
241         
242         public boolean isPerforming() {
243         return Test.this.isPerforming;
244         }
245     });
246     }
247 }
Popular Tags