001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008:
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.test.xslt;
021:
022: import java.awt.Point;
023: import java.awt.Rectangle;
024: import java.awt.event.InputEvent;
025: import javax.swing.JTable;
026: import javax.swing.tree.TreePath;
027: import org.netbeans.jellytools.EditorOperator;
028: import org.netbeans.jellytools.JellyTestCase;
029: import org.netbeans.jellytools.MainWindowOperator;
030: import org.netbeans.jellytools.NewFileNameLocationStepOperator;
031: import org.netbeans.jellytools.NewFileWizardOperator;
032: import org.netbeans.jellytools.NewProjectNameLocationStepOperator;
033: import org.netbeans.jellytools.NewProjectWizardOperator;
034: import org.netbeans.jellytools.actions.SaveAllAction;
035: import org.netbeans.jemmy.Timeout;
036: import org.netbeans.jemmy.drivers.input.MouseEventDriver;
037: import org.netbeans.jemmy.operators.JButtonOperator;
038: import org.netbeans.jemmy.operators.JComboBoxOperator;
039: import org.netbeans.jemmy.operators.JComponentOperator;
040: import org.netbeans.jemmy.operators.JDialogOperator;
041: import org.netbeans.jemmy.operators.JLabelOperator;
042: import org.netbeans.jemmy.operators.JRadioButtonOperator;
043: import org.netbeans.jemmy.operators.JTableOperator;
044: import org.netbeans.jemmy.operators.JTextFieldOperator;
045: import org.netbeans.jemmy.operators.JTreeOperator;
046: import org.netbeans.test.xslt.lib.Helpers;
047: import org.netbeans.test.xslt.lib.PaletteOperator;
048: import org.netbeans.test.xslt.lib.XSLTEditorOperator;
049:
050: /**
051: *
052: * @author ca@netbeans.org
053: */
054:
055: public class AcceptanceTestCase extends JellyTestCase {
056:
057: static final String[] m_aTestMethods = { "createNewXSLTModule",
058: "createSchemas", "createWSDL", "createXSLT", "editXSLT",
059: "checkSource" };
060:
061: static final String SCHEMA_NAME = "schema";
062: static final String SCHEMA_EXTENSION = ".xsd";
063: static final String strWSDLFileName = "testWSDL";
064:
065: static final String FILE_NAME = "testXSLFile.xsl";
066:
067: static final String TEST_PROJECT_NAME = "AcceptanceTestProject";
068:
069: static final String CONCAT_TITLE = "Concat";
070:
071: public AcceptanceTestCase(String arg0) {
072: super (arg0);
073: }
074:
075: public static junit.framework.TestSuite suite() {
076: junit.framework.TestSuite testSuite = new junit.framework.TestSuite(
077: AcceptanceTestCase.class.getName());
078:
079: for (String strMethodName : m_aTestMethods) {
080: testSuite.addTest(new AcceptanceTestCase(strMethodName));
081: }
082:
083: return testSuite;
084: }
085:
086: public void createNewXSLTModule() {
087: startTest();
088:
089: String strDirectory = System.getProperties().getProperty(
090: "xtest.sketchpad");
091:
092: MainWindowOperator.getDefault().maximize();
093:
094: NewProjectWizardOperator opWizard = NewProjectWizardOperator
095: .invoke();
096: opWizard.selectCategory("SOA");
097: opWizard.selectProject("XSLT Module");
098: opWizard.next();
099:
100: NewProjectNameLocationStepOperator opLocationStep = new NewProjectNameLocationStepOperator();
101: opLocationStep.txtProjectName().setText(TEST_PROJECT_NAME);
102: opLocationStep.txtProjectLocation().setText(strDirectory);
103: opWizard.finish();
104:
105: endTest();
106: }
107:
108: public void createSchemas() {
109: startTest();
110:
111: for (int i = 0; i < 2; i++) {
112: createSchema(SCHEMA_NAME + i, i);
113: }
114:
115: endTest();
116: }
117:
118: private void createSchema(String strName, int index) {
119: final String strSampleSchemas = "XML";
120: final String strFileType = "Purchase Order Sample Schema";
121: final String strSrc = "src";
122:
123: final int FOLDER_FIELD_INDEX = 2;
124:
125: final String strNameSpace = "http://xml.netbeans.org/schema/test";
126:
127: NewFileWizardOperator opNewFileWizard = NewFileWizardOperator
128: .invoke();
129: opNewFileWizard.selectCategory(strSampleSchemas);
130: opNewFileWizard.selectFileType(strFileType);
131: opNewFileWizard.next();
132:
133: NewFileNameLocationStepOperator opNewFileNameLocationStep = new NewFileNameLocationStepOperator();
134: opNewFileNameLocationStep.setObjectName(strName);
135: new JTextFieldOperator(opNewFileNameLocationStep,
136: FOLDER_FIELD_INDEX).setText(strSrc);
137: opNewFileWizard.finish();
138: }
139:
140: public void createWSDL() {
141: startTest();
142:
143: final String JTABLE_CLASS = "javax.swing.JTable";
144:
145: final String strWSDLDocument = "XML";
146: final String strFileType = "WSDL Document";
147:
148: final int FOLDER_FIELD_INDEX = 2;
149:
150: NewFileWizardOperator opNewFileWizard = NewFileWizardOperator
151: .invoke();
152: opNewFileWizard.selectCategory(strWSDLDocument);
153: opNewFileWizard.selectFileType(strFileType);
154: opNewFileWizard.next();
155:
156: final String strSrc = "src";
157:
158: NewFileNameLocationStepOperator opNewFileNameLocationStep = new NewFileNameLocationStepOperator();
159: opNewFileNameLocationStep.setObjectName(strWSDLFileName);
160: new JTextFieldOperator(opNewFileNameLocationStep,
161: FOLDER_FIELD_INDEX).setText(strSrc);
162: opNewFileWizard.next();
163:
164: JDialogOperator opAbstractConfigStep = new JDialogOperator(
165: "New WSDL Document");
166:
167: JComponentOperator opComponent = Helpers.getComponentOperator(
168: opAbstractConfigStep, JTABLE_CLASS, 2);
169: JTable table = (JTable) opComponent.getSource();
170: JTableOperator opInputTable = new JTableOperator(table);
171:
172: opComponent = Helpers.getComponentOperator(
173: opAbstractConfigStep, JTABLE_CLASS, 1);
174: table = (JTable) opComponent.getSource();
175: JTableOperator opOutputTable = new JTableOperator(table);
176:
177: Rectangle r = opInputTable.getCellRect(0, 1, false);
178: new MouseEventDriver().clickMouse(opInputTable, r.x + r.width
179: - 5, r.y + r.height - 5, 1, InputEvent.BUTTON1_MASK, 0,
180: new Timeout("timeout", 500));
181:
182: JDialogOperator opSelectElementOrType = new JDialogOperator(
183: "Select Element Or Type");
184:
185: JTreeOperator opTree = new JTreeOperator(opSelectElementOrType);
186: TreePath treePath = opTree.findPath("By File|"
187: + TEST_PROJECT_NAME
188: + "|src/schema0.xsd|Elements|purchaseOrder");
189: opTree.selectPath(treePath);
190: new JButtonOperator(opSelectElementOrType, "OK").pushNoBlock();
191: opSelectElementOrType.waitClosed();
192:
193: r = opOutputTable.getCellRect(0, 1, false);
194: new MouseEventDriver().clickMouse(opOutputTable, r.x + r.width
195: - 5, r.y + r.height - 5, 1, InputEvent.BUTTON1_MASK, 0,
196: new Timeout("timeout", 500));
197:
198: opSelectElementOrType = new JDialogOperator(
199: "Select Element Or Type");
200: opTree = new JTreeOperator(opSelectElementOrType);
201: treePath = opTree.findPath("By File|" + TEST_PROJECT_NAME
202: + "|src/schema1.xsd|Elements|purchaseOrder");
203: opTree.selectPath(treePath);
204: new JButtonOperator(opSelectElementOrType, "OK").pushNoBlock();
205: opSelectElementOrType.waitClosed();
206:
207: opNewFileWizard.next();
208:
209: JDialogOperator opConcreteConfigStep = new JDialogOperator(
210: "New WSDL Document");
211:
212: JComboBoxOperator opCombo = new JComboBoxOperator(
213: opConcreteConfigStep);
214: opCombo.selectItem("SOAP");
215:
216: JRadioButtonOperator opRadio = new JRadioButtonOperator(
217: opConcreteConfigStep, "Document Literal");
218: opRadio.pushNoBlock();
219:
220: opNewFileWizard.finish();
221:
222: endTest();
223: }
224:
225: public void createXSLT() {
226: startTest();
227:
228: // final String strSOADocument = "Service Oriented Architecture";
229: final String strSOADocument = "SOA";
230: final String strFileType = "XSLT Service";
231: final String strXSLFile = "XSL File:";
232:
233: NewFileWizardOperator opNewFileWizard = NewFileWizardOperator
234: .invoke();
235: opNewFileWizard.selectCategory(strSOADocument);
236: opNewFileWizard.selectFileType(strFileType);
237: opNewFileWizard.next();
238:
239: new JRadioButtonOperator(opNewFileWizard,
240: "Request-Reply Service").pushNoBlock();
241:
242: opNewFileWizard.next();
243:
244: opNewFileWizard.next();
245:
246: JLabelOperator opLabel = new JLabelOperator(opNewFileWizard,
247: strXSLFile);
248: Helpers.getTextFieldOpByLabel(opLabel).setText(FILE_NAME);
249:
250: opNewFileWizard.finish();
251:
252: endTest();
253: }
254:
255: public void editXSLT() {
256: startTest();
257:
258: XSLTEditorOperator opEditor = new XSLTEditorOperator(FILE_NAME);
259:
260: opEditor.dropPaletteItemOnCanvas(PaletteOperator.Groups.STRING,
261: "concat", new Point(50, 50));
262:
263: opEditor.bindSourceToMethoid("billTo|street", CONCAT_TITLE, 0,
264: 0);
265: opEditor.bindSourceToMethoid("billTo|city", CONCAT_TITLE, 0, 1);
266: opEditor.bindMethoidToTarget(CONCAT_TITLE, 0,
267: "purchaseOrder|billTo|name");
268:
269: opEditor.bindSourceToTarget("shipTo|name",
270: "purchaseOrder|shipTo|name");
271: opEditor.bindSourceToTarget("shipTo|city",
272: "purchaseOrder|shipTo|city");
273: opEditor.bindSourceToTarget("shipTo|street",
274: "purchaseOrder|shipTo|street");
275:
276: endTest();
277: }
278:
279: public void checkSource() {
280: final long goldenCheckSum = 181301011L; // 708657604L
281:
282: startTest();
283:
284: XSLTEditorOperator opEditor = new XSLTEditorOperator(FILE_NAME);
285:
286: opEditor.switchToSource();
287:
288: EditorOperator opNBEditor = new EditorOperator(FILE_NAME);
289: String strText = opNBEditor.getText();
290: Helpers.writeJemmyLog("{" + strText + "}");
291:
292: opEditor.switchToDesign();
293:
294: if (!Helpers.isCRC32Equal(strText, goldenCheckSum)) {
295: fail("The source check sum doesn't match the golden value");
296: }
297:
298: endTest();
299: }
300:
301: public void tearDown() {
302: new SaveAllAction().performAPI();
303: }
304: }
|