1 19 package org.netbeans.test.editor.app.core; 20 21 import java.beans.*; 22 import java.util.ArrayList ; 23 import javax.swing.*; 24 25 import java.util.Vector ; 26 import java.util.Collection ; 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 org.w3c.dom.Element ; 39 import org.w3c.dom.Document ; 40 import org.w3c.dom.NodeList ; 41 import org.w3c.dom.Node ; 42 43 44 49 public class Test extends TestGroup { 50 51 public static final String AUTHOR = "Author"; 52 public static final String VERSION = "Version"; 53 public static final String COMMENT = "Comment"; 54 55 private String author,version,comment; 56 57 public JEditorPane editor; 58 public Logger logger; 59 60 private static boolean testing = false; 61 62 63 public Test(String 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 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 toXML(Element 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 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 getProperty(String 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 name, Object 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 getAuthor() { 143 return author; 144 } 145 146 public void setAuthor(String value) { 147 String oldValue = author; 148 author = value; 149 firePropertyChange(AUTHOR, oldValue, author); 150 } 151 152 public String getVersion() { 153 return version; 154 } 155 156 public void setVersion(String value) { 157 String oldValue = version; 158 version = value; 159 firePropertyChange(VERSION, oldValue, version); 160 } 161 162 public String getComment() { 163 return comment; 164 } 165 166 public void setComment(String value) { 167 String 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 209 public TestCallAction[] getCallActions() { 210 ArrayList ret=new ArrayList (); 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 |