1 19 20 package org.netbeans.test.xml.schema.core; 21 22 import java.awt.Point ; 23 import java.util.zip.CRC32 ; 24 import javax.swing.tree.TreePath ; 25 import org.netbeans.jellytools.EditorOperator; 26 import org.netbeans.jellytools.JellyTestCase; 27 import org.netbeans.jellytools.NewFileNameLocationStepOperator; 28 import org.netbeans.jellytools.NewFileWizardOperator; 29 import org.netbeans.jellytools.OutputOperator; 30 import org.netbeans.jellytools.ProjectsTabOperator; 31 import org.netbeans.jellytools.TopComponentOperator; 32 import org.netbeans.jellytools.WizardOperator; 33 import org.netbeans.jellytools.actions.SaveAllAction; 34 import org.netbeans.jellytools.nodes.Node; 35 import org.netbeans.jellytools.nodes.ProjectRootNode; 36 import org.netbeans.jemmy.operators.JButtonOperator; 37 import org.netbeans.jemmy.operators.JCheckBoxOperator; 38 import org.netbeans.jemmy.operators.JDialogOperator; 39 import org.netbeans.jemmy.operators.JListOperator; 40 import org.netbeans.jemmy.operators.JPopupMenuOperator; 41 import org.netbeans.jemmy.operators.JRadioButtonOperator; 42 import org.netbeans.jemmy.operators.JTextFieldOperator; 43 import org.netbeans.jemmy.operators.JTreeOperator; 44 import org.netbeans.test.xml.schema.core.lib.SchemaMultiView; 45 import org.netbeans.test.xml.schema.core.lib.util.Helpers; 46 47 51 52 public class AcceptanceTestCase extends JellyTestCase { 53 54 static final String [] m_aTestMethods = { 55 "createNewSchema", 56 "createSchemaComponents", 57 "customizeSchema", 58 "checkSourceCRC", 59 "refactorComplexType", 60 "applyDesignPattern" 61 }; 62 63 static final String TEST_SCHEMA_NAME = "testSchema"; 64 static final String SCHEMA_EXTENSION = ".xsd"; 65 66 public AcceptanceTestCase(String arg0) { 67 super(arg0); 68 } 69 70 public static junit.framework.TestSuite suite() { 71 junit.framework.TestSuite testSuite = new junit.framework.TestSuite("Acceptance suite"); 72 73 for (String strMethodName : m_aTestMethods) { 74 testSuite.addTest(new AcceptanceTestCase(strMethodName)); 75 } 76 77 return testSuite; 78 } 79 80 public void createNewSchema() { 81 startTest(); 82 83 NewFileWizardOperator opNewFileWizard = NewFileWizardOperator.invoke(); 84 opNewFileWizard.selectCategory("XML"); 85 opNewFileWizard.selectFileType("XML Schema"); 86 opNewFileWizard.next(); 87 88 NewFileNameLocationStepOperator opNewFileNameLocationStep = new NewFileNameLocationStepOperator(); 89 opNewFileNameLocationStep.setObjectName(TEST_SCHEMA_NAME); 90 opNewFileWizard.finish(); 91 92 TopComponentOperator opTopComponent = new TopComponentOperator(TEST_SCHEMA_NAME + SCHEMA_EXTENSION); 93 94 endTest(); 95 } 96 97 public void createSchemaComponents() { 98 startTest(); 99 100 String [][] aComponentsMenu = { 101 {"Complex Type...", "CT"}, 102 {"Simple Type...", "ST"}, 103 {"Element...", "E"}, 104 {"Attribute...", "A"} 105 }; 106 107 SchemaMultiView opMultiView = new SchemaMultiView(TEST_SCHEMA_NAME); 108 JListOperator opList = opMultiView.getColumnListOperator(0); 109 110 for (int i = 0; i <aComponentsMenu.length; i++) { 111 Point p = opList.getClickPoint(0); 112 opList.clickForPopup(p.x, p.y); 113 new JPopupMenuOperator().pushMenuNoBlock("Add|" + aComponentsMenu[i][0]); 114 Helpers.waitNoEvent(); 115 116 JDialogOperator opCustomizer = new JDialogOperator(); 117 new JTextFieldOperator(opCustomizer, 0).setText(aComponentsMenu[i][1]); 118 new JButtonOperator(opCustomizer, "OK").pushNoBlock(); 119 Helpers.waitNoEvent(); 120 } 121 122 endTest(); 123 } 124 125 public void customizeSchema() { 126 startTest(); 127 128 SchemaMultiView opMultiView = new SchemaMultiView(TEST_SCHEMA_NAME); 129 130 JListOperator opList0 = opMultiView.getColumnListOperator(0); 132 opList0.selectItem("Elements"); 133 134 JListOperator opList1 = opMultiView.getColumnListOperator(1); 135 callPopupOnListItem(opList1, "E", "Customize"); 136 137 JDialogOperator opCustomizer = new JDialogOperator(); 138 new JRadioButtonOperator(opCustomizer, "Use Existing Type").pushNoBlock(); 139 Helpers.waitNoEvent(); 140 141 JTreeOperator opTree = new JTreeOperator(opCustomizer); 142 TreePath treePath = opTree.findPath("Complex Types|CT"); 143 opTree.selectPath(treePath); 144 145 new JButtonOperator(opCustomizer, "OK").pushNoBlock(); 146 Helpers.waitNoEvent(); 147 148 opList0.selectItem("Attributes"); 150 151 opList1 = opMultiView.getColumnListOperator(1); 152 callPopupOnListItem(opList1, "A", "Customize"); 153 154 opCustomizer = new JDialogOperator(); 155 new JRadioButtonOperator(opCustomizer, "Use Existing Type").pushNoBlock(); 156 Helpers.waitNoEvent(); 157 158 opTree = new JTreeOperator(opCustomizer); 159 treePath = opTree.findPath("Simple Types|ST"); 160 opTree.selectPath(treePath); 161 162 new JButtonOperator(opCustomizer, "OK").pushNoBlock(); 163 Helpers.waitNoEvent(); 164 165 opList0.selectItem("Complex Types"); 167 168 opList1 = opMultiView.getColumnListOperator(1); 169 callPopupOnListItem(opList1, "CT", "Add|Attribute Reference"); 170 171 opCustomizer = new JDialogOperator(); 172 173 opTree = new JTreeOperator(opCustomizer); 174 treePath = opTree.findPath("Attributes|A"); 175 opTree.selectPath(treePath); 176 177 new JButtonOperator(opCustomizer, "OK").pushNoBlock(); 178 Helpers.waitNoEvent(); 179 180 endTest(); 181 } 182 183 public void checkSourceCRC() { 184 startTest(); 185 186 final long goldenCRC32 = 2295334600L; 187 188 SchemaMultiView opMultiView = new SchemaMultiView(TEST_SCHEMA_NAME); 189 opMultiView.switchToSource(); 190 191 EditorOperator opEditor = new EditorOperator(TEST_SCHEMA_NAME); 192 String strText = opEditor.getText(); 193 194 opMultiView.switchToSchema(); 195 196 strText = strText.replaceAll("[ [\t\f\r]]", ""); 197 Helpers.writeJemmyLog("{" + strText + "}"); 198 199 CRC32 crc32 = new CRC32 (); 200 crc32.update(strText.getBytes()); 201 long checkSum = crc32.getValue(); 202 Helpers.writeJemmyLog("CRC32=" + checkSum); 203 if ( checkSum != goldenCRC32) { 204 fail("Schema source check sum doesn't match golden value"); 205 } 206 207 endTest(); 208 } 209 210 public void refactorComplexType() { 211 startTest(); 212 213 SchemaMultiView opMultiView = new SchemaMultiView(TEST_SCHEMA_NAME); 214 215 JListOperator opList0 = opMultiView.getColumnListOperator(0); 216 opList0.selectItem("Complex Types"); 217 218 JListOperator opList1 = opMultiView.getColumnListOperator(1); 219 callPopupOnListItem(opList1, "CT", "Refactor|Rename..."); 220 221 JDialogOperator opDialog = new JDialogOperator(); 222 new JCheckBoxOperator(opDialog, "Preview All Changes").changeSelection(false); 223 Helpers.waitNoEvent(); 224 new JTextFieldOperator(opDialog).setText("CT1"); 225 new JButtonOperator(opDialog, "Next").pushNoBlock(); 226 opDialog.waitClosed(); 227 228 opList0 = opMultiView.getColumnListOperator(0); 229 opList0.selectItem("Elements"); 230 Helpers.waitNoEvent(); 231 232 opList1 = opMultiView.getColumnListOperator(1); 233 opList1.selectItem("E"); 234 Helpers.waitNoEvent(); 235 236 JListOperator opList2 = opMultiView.getColumnListOperator(2); 237 opList2.selectItem("CT1"); 238 239 opMultiView.switchToSource(); 240 boolean bValid = isSchemaValid(TEST_SCHEMA_NAME); 241 opMultiView.switchToSchema(); 242 243 if (!bValid) { 244 failInvalidSchema(); 245 } 246 247 endTest(); 248 } 249 250 public void applyDesignPattern() { 251 startTest(); 252 253 ProjectsTabOperator pto = new ProjectsTabOperator(); 254 255 JTreeOperator opTree = pto.tree(); 256 257 ProjectRootNode prn = pto.getProjectRootNode("XSDTestProject"); 259 Node node = new Node(prn, "Source Packages|<default package>|" + TEST_SCHEMA_NAME + SCHEMA_EXTENSION); 260 261 node.callPopup().pushMenuNoBlock("Apply Design Pattern..."); 262 Helpers.waitNoEvent(); 263 264 WizardOperator opWizard = new WizardOperator("Apply Design Pattern"); 265 new JRadioButtonOperator(opWizard, "Create a Single Global Element").pushNoBlock(); 266 Helpers.waitNoEvent(); 267 268 new JRadioButtonOperator(opWizard, "Do not Create Type(s)").pushNoBlock(); 269 Helpers.waitNoEvent(); 270 271 opWizard.finish(); 272 Helpers.waitNoEvent(); 273 274 SchemaMultiView opMultiView = new SchemaMultiView(TEST_SCHEMA_NAME); 275 opMultiView.switchToSource(); 276 boolean bValid = isSchemaValid(TEST_SCHEMA_NAME); 277 opMultiView.switchToSchema(); 278 279 if (!bValid) { 280 failInvalidSchema(); 281 } 282 283 endTest(); 284 } 285 286 private boolean isSchemaValid(String strSchemaName) { 287 boolean bValid = true; 288 289 EditorOperator opEditor = new EditorOperator(strSchemaName); 290 291 opEditor.clickForPopup(); 292 new JPopupMenuOperator().pushMenu("Validate XML"); 293 Helpers.waitNoEvent(); 294 295 OutputOperator opOutput = new OutputOperator(); 296 String strOutput = opOutput.getText(); 297 298 if (!strOutput.matches("\\D*0 Error\\(s\\), 0 Warning\\(s\\)\\.\\D*")) { 299 Helpers.writeJemmyLog("Validate XML output:\n" + strOutput); 300 bValid = false; 301 } 302 303 return bValid; 304 } 305 306 private void failInvalidSchema() { 307 fail("Schema validation failed."); 308 } 309 310 private void callPopupOnListItem(JListOperator opList, String strItem, String strMenuPath) { 311 opList.selectItem(strItem); 312 313 int index = opList.getSelectedIndex(); 314 Point p = opList.getClickPoint(index); 315 opList.clickForPopup(p.x, p.y); 316 new JPopupMenuOperator().pushMenuNoBlock(strMenuPath); 317 } 318 319 public void tearDown() { 320 new SaveAllAction().performAPI(); 321 } 322 } 323 | Popular Tags |