1 19 20 package org.netbeans.modules.uihandler.test; 21 22 import java.awt.Component ; 23 import org.netbeans.modules.uihandler.*; 24 import java.util.logging.Level ; 25 import java.util.logging.LogRecord ; 26 import java.util.logging.Logger ; 27 import junit.framework.Test; 28 import junit.framework.TestSuite; 29 import junit.textui.TestRunner; 30 import org.netbeans.jellytools.MainWindowOperator; 31 import org.netbeans.jellytools.NbDialogOperator; 32 import org.netbeans.jemmy.operators.ComponentOperator; 33 import org.netbeans.jemmy.operators.ContainerOperator; 34 import org.netbeans.jemmy.operators.JButtonOperator; 35 import org.netbeans.jemmy.operators.JListOperator; 36 import org.netbeans.jemmy.operators.JTabbedPaneOperator; 37 import org.netbeans.jemmy.operators.JTextAreaOperator; 38 import org.netbeans.jemmy.operators.JTextFieldOperator; 39 import org.netbeans.junit.NbTestCase; 40 import org.netbeans.junit.NbTestSuite; 41 42 46 public class FunctionalTest extends NbTestCase { 47 48 public FunctionalTest(String testName) { 49 super(testName); 50 } 51 52 public void setUp(){ 53 System.setProperty("netbeans.exception.report.min.level", "100"); 54 } 55 56 public void textExceptionThrown()throws Exception { 57 String userName = "testUserName"; 58 String summary = "testSummary"; 59 String comment = "TESTING COMMENT"; 60 Throwable t1 = new NullPointerException ("TESTING EXCEPTION"); 61 Throwable t2 = new ClassNotFoundException ("NESTED EXCEPTION"); 62 t1.initCause(t2); 63 LogRecord log = new LogRecord (Level.INFO, "TESTING LOG"); 64 log.setThrown(t1); 65 Logger.getLogger("").log(log); 66 ErrorDialogOperator errDialOp = new ErrorDialogOperator(); 67 assertNotNull("ERROR DIALOG SHOULD APPEAR", errDialOp); 68 errDialOp.report(); 69 ReportDialogOperator reportOper = new ReportDialogOperator(); 70 reportOper.summary().setText(summary); 71 reportOper.comment().setText(comment); 72 reportOper.userName().setText(userName); 73 reportOper.submitData(); reportOper.viewData().pushNoBlock(); 75 ViewDataDialogOperator viewOper = new ViewDataDialogOperator("Report Problem"); 76 viewOper.submitData(); assertEquals("USER CONFIGURATION SHOULD BE SHOWN", 78 viewOper.listView().getModel().getElementAt(0).toString(), "User Configuration"); 79 assertEquals("TESTING LOG SHOULD BE SHOWN", 80 viewOper.listView().getModel().getElementAt(3).toString(), "TESTING LOG"); 81 String text = viewOper.paneRawContent(); 82 assertTrue(text.contains("<message>TESTING LOG</message>")); 83 assertTrue(text.contains("<message>java.lang.NullPointerException: TESTING EXCEPTION</message>")); 84 assertTrue(text.contains("<method>textExceptionThrown</method>")); 85 assertTrue(text.contains("<key>UI_ENABLED_MODULES</key>")); 86 assertTrue(text.contains("<key>UI_DISABLED_MODULES</key>")); 87 assertTrue(text.contains("<key>UI_USER_CONFIGURATION</key>")); 88 assertTrue(text.contains("<param>testUserName</param>")); 89 assertTrue(text.contains("<param>testSummary</param>")); 90 assertTrue(text.contains("<param>TESTING COMMENT</param>")); 91 viewOper.backtoReport().pushNoBlock(); 92 reportOper = new ReportDialogOperator(); 93 reportOper.cancel(); 94 } 95 96 public void testUIGestures(){ 97 MainWindowOperator mainWindow = MainWindowOperator.getDefault(); 98 ContainerOperator toolbar = mainWindow.getToolbar("UIGestures"); 99 assertNotNull("UIGESTURES Toolbar", toolbar); 100 assertEquals("ToolbarBump, NrButton", 2, toolbar.getComponentCount()); 101 Component label = toolbar.getComponent(1); 102 assertNotNull("UIGESTURES BUTTON", label); 103 new ComponentOperator(label).clickMouse(); 104 WelcomeDialogOperator welcome = new WelcomeDialogOperator(); 105 welcome.submitData(); welcome.viewData().pushNoBlock(); 107 ViewDataDialogOperator viewData = new ViewDataDialogOperator("UI Gestures Collector"); 108 viewData.submitData(); assertEquals("USER CONFIGURATION SHOULD BE SHOWN", 110 viewData.listView().getModel().getElementAt(0).toString(), "User Configuration"); 111 String text = viewData.paneRawContent(); 112 assertTrue(text.contains("<key>UI_ENABLED_MODULES</key>")); 113 assertTrue(text.contains("<key>UI_DISABLED_MODULES</key>")); 114 assertTrue(text.contains("<key>UI_USER_CONFIGURATION</key>")); 115 116 viewData.hideData().pushNoBlock(); 117 welcome = new WelcomeDialogOperator(); 118 welcome.cancel(); 119 } 120 121 private class WelcomeDialogOperator extends NbDialogOperator{ 122 private JButtonOperator viewData; 123 private JButtonOperator submitData; 124 125 public WelcomeDialogOperator() { 126 super("UI Gestures Collector"); 127 } 128 129 public JButtonOperator viewData(){ 130 if (viewData == null){ 131 viewData = new JButtonOperator(this, "View Data"); 132 } 133 assertNotNull("THERE SHOULD BE A VIEW DATA BUTTON", viewData); 134 return viewData; 135 } 136 137 public JButtonOperator submitData(){ 138 if (submitData == null){ 139 submitData = new JButtonOperator(this, "Submit Data"); 140 } 141 assertNotNull("THERE SHOULD BE A SUBMIT DATA BUTTON", submitData); 142 return submitData; 143 } 144 145 146 } 147 148 149 private class ViewDataDialogOperator extends NbDialogOperator{ 150 private JButtonOperator backtoReport; 151 private JButtonOperator submitData; 152 private JTabbedPaneOperator pane; 153 private JButtonOperator hideData; 154 private JListOperator listView; 155 156 public ViewDataDialogOperator(String title) { 157 super(title); 158 } 159 160 public JButtonOperator hideData(){ 161 if (hideData == null){ 162 hideData = new JButtonOperator(this, "Hide Data"); 163 } 164 assertNotNull("THERE SHOULD BE A HIDE DATA BUTTON", hideData); 165 return hideData; 166 } 167 168 public JButtonOperator submitData(){ 169 if (submitData == null){ 170 submitData = new JButtonOperator(this, "Submit Data"); 171 } 172 assertNotNull("THERE SHOULD BE A SUBMIT DATA BUTTON", submitData); 173 return submitData; 174 } 175 176 public JButtonOperator backtoReport(){ 177 if (backtoReport == null){ 178 backtoReport = new JButtonOperator(this, "Back to Report"); 179 } 180 assertNotNull("THERE SHOULD BE A BACK TO REPORT BUTTON", backtoReport); 181 return backtoReport; 182 } 183 184 public String paneRawContent(){ 185 listView(); 186 pane().selectPage("Raw"); 187 JTextAreaOperator textArea; 188 textArea = new JTextAreaOperator(pane(), 0); 189 assertNotNull("THERE SHOULD BE A TEXT AREA", textArea); 190 return textArea.getText(); 191 } 192 193 public JListOperator listView(){ 194 pane().selectPage("Structured"); 195 if (listView == null){ 196 listView = new JListOperator(this, 0); 197 } 198 assertNotNull("THERE SHOULD BE A LIST VIEW ON VIEW DATA WINDOW", listView); 199 return listView; 200 } 201 202 private JTabbedPaneOperator pane(){ 203 if (pane == null) { 204 pane = new JTabbedPaneOperator(this, 0); 205 } 206 assertNotNull("THERE SHOULD BE A PANE", pane); 207 assertEquals("THERE SHOULD BE 2 TABS", 2, pane.getTabCount()); 208 return pane; 209 } 210 } 211 212 213 private class ErrorDialogOperator extends NbDialogOperator{ 214 public ErrorDialogOperator(){ 215 super("Unexpected Exception"); 216 } 217 218 public void report(){ 219 JButtonOperator op = new JButtonOperator(this, "Review and Report Problem"); 220 assertNotNull("THERE SHOULD BE A REPORT BUTTON", op); 221 op.pushNoBlock(); 222 } 223 224 225 } 226 227 private class ReportDialogOperator extends NbDialogOperator{ 228 private JButtonOperator viewData; 229 private JButtonOperator submitData; 230 private JTextFieldOperator summary; 231 private JTextFieldOperator userName; 232 private JTextAreaOperator comment; 233 234 public ReportDialogOperator(){ 235 super("Report Problem"); 236 } 237 238 public JButtonOperator viewData(){ 239 if (viewData == null){ 240 viewData = new JButtonOperator(this, "View Data"); 241 } 242 assertNotNull("THERE SHOULD BE A VIEW DATA BUTTON", viewData); 243 return viewData; 244 } 245 246 public JButtonOperator submitData(){ 247 if (submitData == null){ 248 submitData = new JButtonOperator(this, "Submit Data"); 249 } 250 assertNotNull("THERE SHOULD BE A SUBMIT DATA BUTTON", submitData); 251 return submitData; 252 } 253 254 public JTextFieldOperator summary(){ 255 if (summary == null) { 256 summary = new JTextFieldOperator(this, 1); 257 } 258 assertNotNull("THERE SHOULD BE A SUMMARY FIELD", summary); 259 return summary; 260 } 261 262 public JTextFieldOperator userName(){ 263 if (userName == null) { 264 userName = new JTextFieldOperator(this, 0); 265 } 266 assertNotNull("THERE SHOULD BE A USER NAME FIELD", userName); 267 return userName; 268 } 269 270 public JTextAreaOperator comment(){ 271 if (comment == null) { 272 comment = new JTextAreaOperator(this, 0); 273 } 274 assertNotNull("THERE SHOULD BE A COMMENT AREA", comment); 275 return comment; 276 } 277 } 278 279 280 281 282 public static Test suite() { 283 TestSuite suite = new NbTestSuite(); 284 suite.addTest(new FunctionalTest("textExceptionThrown")); 285 suite.addTest(new FunctionalTest("testUIGestures")); 286 return suite; 287 } 288 289 public static void main(String [] args) throws Exception { 290 TestRunner.run(suite()); 291 } 292 293 } 294 | Popular Tags |