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.sequential;
021:
022: import java.awt.Point;
023: import java.util.LinkedList;
024: import javax.swing.JSplitPane;
025: import org.netbeans.jellytools.EditorOperator;
026: import org.netbeans.jellytools.MainWindowOperator;
027: import org.netbeans.jellytools.ProjectsTabOperator;
028: import org.netbeans.jellytools.TopComponentOperator;
029: import org.netbeans.jellytools.actions.AttachWindowAction;
030: import org.netbeans.jellytools.actions.OpenAction;
031: import org.netbeans.jellytools.actions.SaveAllAction;
032: import org.netbeans.jellytools.nodes.ProjectRootNode;
033: import org.netbeans.jemmy.operators.JComponentOperator;
034: import org.netbeans.jemmy.operators.JSplitPaneOperator;
035: import org.netbeans.test.xslt.lib.Helpers;
036: import org.netbeans.test.xslt.lib.PaletteOperator;
037: import org.netbeans.test.xslt.lib.XSLTEditorOperator;
038: import org.netbeans.test.xslt.lib.sequential.SequentialTest;
039: import org.netbeans.test.xslt.lib.sequential.TestSequence;
040:
041: /**
042: *
043: * @author ca@netbeans.org
044: */
045:
046: public class PaletteVerifier extends TestSequence {
047: static final int NO_EVENT_TIMEOUT = 500;
048: static final String FILE_NAME = "newXslFile1.xsl";
049:
050: private XSLTEditorOperator m_opEditor = null;;
051: private Point m_point = new Point(50, 50);
052:
053: public void setupOnce() {
054: final String PROJECT_NAME = "XSLTTestProject";
055: final String J_SPLIT_PANE = "javax.swing.JSplitPane";
056:
057: MainWindowOperator.getDefault().maximize();
058:
059: ProjectsTabOperator pto = ProjectsTabOperator.invoke();
060:
061: ProjectRootNode nodeProjectRoot = pto
062: .getProjectRootNode(PROJECT_NAME);
063: nodeProjectRoot.select();
064: org.netbeans.jellytools.nodes.Node nodeXSL = new org.netbeans.jellytools.nodes.Node(
065: nodeProjectRoot, "Transformation Files|" + FILE_NAME);
066:
067: new OpenAction().performPopup(nodeXSL);
068: waitNoEvent();
069:
070: Helpers.closeTopComponentIfOpened("Navigator");
071: Helpers.closeTopComponentIfOpened("Properties");
072: PaletteOperator opPalette = new PaletteOperator();
073: new AttachWindowAction("Projects", AttachWindowAction.BOTTOM)
074: .perform(opPalette);
075: waitNoEvent();
076:
077: TopComponentOperator opTopComponent = new TopComponentOperator(
078: FILE_NAME);
079:
080: JComponentOperator opComponent = Helpers.getComponentOperator(
081: opTopComponent, J_SPLIT_PANE, 0);
082: JSplitPaneOperator opTargetSplitter = new JSplitPaneOperator(
083: (JSplitPane) opComponent.getSource());
084: opTargetSplitter.moveDivider(0.7);
085: waitNoEvent();
086:
087: opComponent = Helpers.getComponentOperator(opTopComponent,
088: J_SPLIT_PANE, 1);
089: JSplitPaneOperator opSourceSplitter = new JSplitPaneOperator(
090: (JSplitPane) opComponent.getSource());
091: opSourceSplitter.moveDivider(0.4);
092: waitNoEvent();
093:
094: m_opEditor = new XSLTEditorOperator(FILE_NAME);
095:
096: m_testList = new LinkedList<SequentialTest>();
097:
098: m_testList.add(new PaletteItemTestSequence(
099: PaletteOperator.Groups.OPERATOR, "equal", "Equal", 2,
100: 1259604289L));
101: m_testList.add(new PaletteItemTestSequence(
102: PaletteOperator.Groups.OPERATOR, "greater_or_equal",
103: "Greater or Equal", 2, 3562843263L));
104: m_testList.add(new PaletteItemTestSequence(
105: PaletteOperator.Groups.OPERATOR, "greater_than",
106: "Greater Than", 2, 274115667L));
107: m_testList.add(new PaletteItemTestSequence(
108: PaletteOperator.Groups.OPERATOR, "not_equal",
109: "Not Equal", 2, 1264736979L));
110: m_testList.add(new PaletteItemTestSequence(
111: PaletteOperator.Groups.OPERATOR, "less_than",
112: "Less Than", 2, 4180514297L));
113: m_testList.add(new PaletteItemTestSequence(
114: PaletteOperator.Groups.OPERATOR, "less_or_equal",
115: "Less or Equal", 2, 3803618736L));
116:
117: m_testList.add(new PaletteItemTestSequence(
118: PaletteOperator.Groups.OPERATOR, "addition",
119: "Addition", 2, 2444918072L));
120: m_testList.add(new PaletteItemTestSequence(
121: PaletteOperator.Groups.OPERATOR, "subtraction",
122: "Subtraction", 2, 658454300L));
123: m_testList.add(new PaletteItemTestSequence(
124: PaletteOperator.Groups.OPERATOR, "multiplication",
125: "Multiplication", 2, 296426505L));
126: m_testList.add(new PaletteItemTestSequence(
127: PaletteOperator.Groups.OPERATOR, "division", "Div", 2,
128: 963691707L));
129: m_testList.add(new PaletteItemTestSequence(
130: PaletteOperator.Groups.OPERATOR, "mod", "Mod", 2,
131: 3302433631L));
132: m_testList.add(new PaletteItemTestSequence(
133: PaletteOperator.Groups.OPERATOR, "negative",
134: "Negative", 1, 2719633178L));
135:
136: m_testList.add(new PaletteItemTestSequence(
137: PaletteOperator.Groups.STRING, "string-literal",
138: "String Literal", 0, 3785901851L));
139: m_testList.add(new PaletteItemTestSequence(
140: PaletteOperator.Groups.STRING, "string", "String", 1,
141: 987964481L));
142: m_testList.add(new PaletteItemTestSequence(
143: PaletteOperator.Groups.STRING, "concat", "Concat", 3,
144: 571814599L));
145: m_testList.add(new PaletteItemTestSequence(
146: PaletteOperator.Groups.STRING, "starts-with",
147: "Starts With", 2, 2967593260L));
148: m_testList.add(new PaletteItemTestSequence(
149: PaletteOperator.Groups.STRING, "contains", "Contains",
150: 2, 3178659884L));
151: m_testList.add(new PaletteItemTestSequence(
152: PaletteOperator.Groups.STRING, "substring-before",
153: "Substring Before", 2, 3249169143L));
154: m_testList.add(new PaletteItemTestSequence(
155: PaletteOperator.Groups.STRING, "substring-after",
156: "Substring After", 2, 2021827526L));
157: m_testList.add(new PaletteItemTestSequence(
158: PaletteOperator.Groups.STRING, "substring",
159: "Substring", 3, 1077252319L));
160: m_testList.add(new PaletteItemTestSequence(
161: PaletteOperator.Groups.STRING, "normalize-space",
162: "Normalize Space", 1, 350959450L));
163: m_testList.add(new PaletteItemTestSequence(
164: PaletteOperator.Groups.STRING, "translate",
165: "Translate", 3, 2350529303L));
166: m_testList.add(new PaletteItemTestSequence(
167: PaletteOperator.Groups.STRING, "string-length",
168: "String Length", 1, 2135201417L));
169:
170: m_testList.add(new PaletteItemTestSequence(
171: PaletteOperator.Groups.NUMBER, "number", "Number", 1,
172: 3877202165L));
173: m_testList.add(new PaletteItemTestSequence(
174: PaletteOperator.Groups.NUMBER, "sum", "Sum", 1,
175: 3522810582L));
176: m_testList.add(new PaletteItemTestSequence(
177: PaletteOperator.Groups.NUMBER, "floor", "Floor", 1,
178: 105863058L));
179: m_testList.add(new PaletteItemTestSequence(
180: PaletteOperator.Groups.NUMBER, "ceiling", "Ceiling", 1,
181: 1518032065L));
182: m_testList.add(new PaletteItemTestSequence(
183: PaletteOperator.Groups.NUMBER, "round", "Round", 1,
184: 2152844442L));
185: m_testList.add(new PaletteItemTestSequence(
186: PaletteOperator.Groups.NUMBER, "numeric-literal",
187: "Numeric Literal", 0, 3180052806L));
188:
189: m_testList.add(new PaletteItemTestSequence(
190: PaletteOperator.Groups.BOOLEAN, "boolean", "Boolean",
191: 1, 1723479037L));
192: m_testList.add(new PaletteItemTestSequence(
193: PaletteOperator.Groups.BOOLEAN, "not", "Not", 1,
194: 3486937687L));
195: m_testList.add(new PaletteItemTestSequence(
196: PaletteOperator.Groups.BOOLEAN, "true", "True", 0,
197: 35389258L));
198: m_testList.add(new PaletteItemTestSequence(
199: PaletteOperator.Groups.BOOLEAN, "false", "False", 0,
200: 2685725001L));
201: m_testList.add(new PaletteItemTestSequence(
202: PaletteOperator.Groups.BOOLEAN, "lang", "Lang", 1,
203: 2595635305L));
204: m_testList.add(new PaletteItemTestSequence(
205: PaletteOperator.Groups.BOOLEAN, "or", "Or", 2,
206: 1082682017L));
207: m_testList.add(new PaletteItemTestSequence(
208: PaletteOperator.Groups.BOOLEAN, "and", "And", 2,
209: 1514851678L));
210:
211: m_testList.add(new PaletteItemTestSequence(
212: PaletteOperator.Groups.NODES, "last", "Last", 0,
213: 90976362L));
214: m_testList.add(new PaletteItemTestSequence(
215: PaletteOperator.Groups.NODES, "position", "Position",
216: 0, 1779060867L));
217: m_testList.add(new PaletteItemTestSequence(
218: PaletteOperator.Groups.NODES, "count", "Count", 1,
219: 387503695L));
220: m_testList.add(new PaletteItemTestSequence(
221: PaletteOperator.Groups.NODES, "local-name",
222: "Local Name", 1, 105668041L));
223: m_testList.add(new PaletteItemTestSequence(
224: PaletteOperator.Groups.NODES, "namespace-uri",
225: "Namespace URI", 1, 3424196234L));
226: m_testList.add(new PaletteItemTestSequence(
227: PaletteOperator.Groups.NODES, "name", "Name", 1,
228: 190429898L));
229: }
230:
231: public void finalCleanup() {
232: if (m_opEditor != null) {
233: new SaveAllAction().performAPI();
234: }
235: }
236:
237: public class PaletteItemTestSequence extends TestSequence {
238: private PaletteOperator.Groups m_group;
239: private String m_strItem;
240: private String m_strMethoidName;
241: private int m_inPorts;
242: private long m_checkSum;
243:
244: private boolean m_itemCreated = false;
245:
246: public PaletteItemTestSequence(PaletteOperator.Groups group,
247: String strItem, String strMethoidName, int inPorts,
248: long checkSum) {
249: m_group = group;
250: m_strItem = strItem;
251: m_strMethoidName = strMethoidName;
252: m_inPorts = inPorts;
253: m_checkSum = checkSum;
254: }
255:
256: public void setupOnce() {
257: m_testList = new LinkedList<SequentialTest>();
258: m_testList.add(new DropItem());
259: m_testList.add(new VerifyChangesInSource(m_checkSum));
260: m_testList.add(new RemoveItem());
261: }
262:
263: public void setup() {
264: clearTestStatus();
265: }
266:
267: public class DropItem extends SequentialTest {
268: public void execute() {
269: startTest();
270:
271: m_opEditor.dropPaletteItemOnCanvas(m_group, m_strItem,
272: m_point);
273:
274: if (m_inPorts > 0) {
275: m_opEditor.bindSourceToMethoid("shipTo|name",
276: m_strMethoidName, 0, 0);
277: }
278:
279: if (m_inPorts > 1) {
280: m_opEditor.bindSourceToMethoid("shipTo|street",
281: m_strMethoidName, 0, 1);
282: }
283:
284: if (m_inPorts > 2) {
285: m_opEditor.bindSourceToMethoid("shipTo|city",
286: m_strMethoidName, 0, 2);
287: }
288:
289: m_opEditor.bindMethoidToTarget(m_strMethoidName, 0,
290: "purchaseOrder2|shipTo|name");
291:
292: m_itemCreated = true;
293:
294: endTest();
295: }
296:
297: public String getTestName() {
298: return Helpers.getFullTestName("DropItem-[" + m_strItem
299: + "]");
300: }
301:
302: }
303:
304: public class VerifyChangesInSource extends SequentialTest {
305: private long m_checkSum;
306:
307: public VerifyChangesInSource(long checkSum) {
308: m_checkSum = checkSum;
309: }
310:
311: public void execute() {
312: startTest();
313:
314: m_opEditor.switchToSource();
315:
316: EditorOperator opNBEditor = new EditorOperator(
317: FILE_NAME);
318: String strText = opNBEditor.getText();
319: Helpers.writeJemmyLog("{" + strText + "}");
320:
321: m_opEditor.switchToDesign();
322:
323: if (!Helpers.isCRC32Equal(strText, m_checkSum)) {
324: fail("The source check sum doesn't match the golden value");
325: }
326: }
327:
328: public String getTestName() {
329: return Helpers
330: .getFullTestName("VerifyChangesInSource-["
331: + m_strItem + "]");
332: }
333: }
334:
335: public class RemoveItem extends SequentialTest {
336: public void execute() {
337: if (m_itemCreated) {
338: clearTestStatus();
339: }
340:
341: startTest();
342:
343: m_opEditor.removeMethoid(m_strMethoidName, 0);
344:
345: endTest();
346: }
347:
348: public String getTestName() {
349: return Helpers.getFullTestName("RemoveItem-["
350: + m_strItem + "]");
351: }
352: }
353: }
354:
355: private void waitNoEvent() {
356: Helpers.waitNoEvent(NO_EVENT_TIMEOUT);
357: }
358:
359: }
|