soa.kit/test/qa-functional/src/org/netbeans/test/xslt/AcceptanceTestCase.java
author ivansidorkin <ivansidorkin@netbeans.org>
Thu Jun 26 18:33:49 2008 +0400 (7 days ago)
changeset 86640 a83f9813329a
parent 79553e8fa84f87da2
permissions -rw-r--r--
Migrated commit validation tests from xtest
        1 /*
        2  * The contents of this file are subject to the terms of the Common Development
        3  * and Distribution License (the License). You may not use this file except in
        4  * compliance with the License.
        5  *
        6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
        7  * or http://www.netbeans.org/cddl.txt.
        8  
        9  * When distributing Covered Code, include this CDDL Header Notice in each file
       10  * and include the License file at http://www.netbeans.org/cddl.txt.
       11  * If applicable, add the following below the CDDL Header, with the fields
       12  * enclosed by brackets [] replaced by your own identifying information:
       13  * "Portions Copyrighted [year] [name of copyright owner]"
       14  *
       15  * The Original Software is NetBeans. The Initial Developer of the Original
       16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
       17  * Microsystems, Inc. All Rights Reserved.
       18  */
       19 
       20 package org.netbeans.test.xslt;
       21 
       22 import java.awt.Point;
       23 import java.awt.Rectangle;
       24 import java.awt.event.InputEvent;
       25 import javax.swing.JTable;
       26 import javax.swing.tree.TreePath;
       27 import org.netbeans.jellytools.EditorOperator;
       28 import org.netbeans.jellytools.JellyTestCase;
       29 import org.netbeans.jellytools.MainWindowOperator;
       30 import org.netbeans.jellytools.NewFileNameLocationStepOperator;
       31 import org.netbeans.jellytools.NewFileWizardOperator;
       32 import org.netbeans.jellytools.NewProjectNameLocationStepOperator;
       33 import org.netbeans.jellytools.NewProjectWizardOperator;
       34 import org.netbeans.jellytools.actions.SaveAllAction;
       35 import org.netbeans.jemmy.Timeout;
       36 import org.netbeans.jemmy.drivers.input.MouseEventDriver;
       37 import org.netbeans.jemmy.operators.JButtonOperator;
       38 import org.netbeans.jemmy.operators.JComboBoxOperator;
       39 import org.netbeans.jemmy.operators.JComponentOperator;
       40 import org.netbeans.jemmy.operators.JDialogOperator;
       41 import org.netbeans.jemmy.operators.JLabelOperator;
       42 import org.netbeans.jemmy.operators.JRadioButtonOperator;
       43 import org.netbeans.jemmy.operators.JTableOperator;
       44 import org.netbeans.jemmy.operators.JTextFieldOperator;
       45 import org.netbeans.jemmy.operators.JTreeOperator;
       46 import org.netbeans.test.xslt.lib.Helpers;
       47 import org.netbeans.test.xslt.lib.PaletteOperator;
       48 import org.netbeans.test.xslt.lib.XSLTEditorOperator;
       49 import org.netbeans.junit.NbTestCase;
       50 import org.netbeans.junit.NbModuleSuite;
       51 
       52 /**
       53  *
       54  * @author ca@netbeans.org
       55  */
       56 
       57 public class AcceptanceTestCase  extends JellyTestCase {
       58     
       59     static final String [] m_aTestMethods = {
       60         "createNewXSLTModule",
       61                 "createSchemas",
       62                 "createWSDL",
       63                 "createXSLT"//,
       64               //  "editXSLT",
       65               //  "checkSource"
       66     };
       67     
       68     static final String SCHEMA_NAME = "schema";
       69     static final String SCHEMA_EXTENSION = ".xsd";
       70     static final String strWSDLFileName = "testWSDL";
       71     
       72     static final String FILE_NAME = "testXSLFile.xsl";
       73     
       74     static final String TEST_PROJECT_NAME = "AcceptanceTestProject";
       75     
       76     static final String CONCAT_TITLE = "Concat";
       77     
       78     public AcceptanceTestCase(String arg0) {
       79         super(arg0);
       80     }
       81     
       82     public static junit.framework.Test suite() {
       83         return NbModuleSuite.create(
       84                 NbModuleSuite.createConfiguration(AcceptanceTestCase.class)
       85                 .addTest(m_aTestMethods)
       86                 .clusters(".*")
       87                 .enableModules(".*")
       88                 .gui(true)
       89                 );
       90     }
       91     
       92     public void createNewXSLTModule() {
       93         startTest();
       94         
       95         String strDirectory = System.getProperties().getProperty("nbjunit.workdir");
       96 
       97         MainWindowOperator.getDefault().maximize();
       98         
       99         NewProjectWizardOperator opWizard = NewProjectWizardOperator.invoke();
      100         opWizard.selectCategory("SOA");
      101         opWizard.selectProject("XSLT Module");
      102         opWizard.next();
      103         
      104         NewProjectNameLocationStepOperator opLocationStep = new NewProjectNameLocationStepOperator();
      105         opLocationStep.txtProjectName().setText(TEST_PROJECT_NAME);
      106         opLocationStep.txtProjectLocation().setText(strDirectory);
      107         opWizard.finish();
      108         
      109         endTest();
      110     }
      111     
      112     public void createSchemas() {
      113         startTest();
      114         
      115         for (int i = 0; i < 2; i++) {
      116             createSchema(SCHEMA_NAME + i, i);
      117         }
      118         
      119         endTest();
      120     }
      121     
      122     private void createSchema(String strName, int index) {
      123         final String strSampleSchemas = "XML";
      124         final String strFileType = "Purchase Order Sample Schema";
      125         final String strSrc = "src";
      126         
      127         final int FOLDER_FIELD_INDEX = 2;
      128         
      129         final String strNameSpace = "http://xml.netbeans.org/schema/test";
      130         
      131         NewFileWizardOperator opNewFileWizard = NewFileWizardOperator.invoke();
      132         opNewFileWizard.selectCategory(strSampleSchemas);
      133         opNewFileWizard.selectFileType(strFileType);
      134         opNewFileWizard.next();
      135         
      136         NewFileNameLocationStepOperator opNewFileNameLocationStep = new NewFileNameLocationStepOperator();
      137         opNewFileNameLocationStep.setObjectName(strName);
      138         new JTextFieldOperator(opNewFileNameLocationStep, FOLDER_FIELD_INDEX).setText(strSrc);
      139         opNewFileWizard.finish();
      140     }
      141     
      142     public void createWSDL() {
      143         startTest();
      144         
      145         final String JTABLE_CLASS = "javax.swing.JTable";
      146         
      147         final String strWSDLDocument = "XML";
      148         final String strFileType = "WSDL Document";
      149         
      150         final int FOLDER_FIELD_INDEX = 2;
      151         
      152         NewFileWizardOperator opNewFileWizard = NewFileWizardOperator.invoke();
      153         opNewFileWizard.selectCategory(strWSDLDocument);
      154         opNewFileWizard.selectFileType(strFileType);
      155         opNewFileWizard.next();
      156         
      157         final String strSrc = "src";
      158         
      159         NewFileNameLocationStepOperator opNewFileNameLocationStep = new NewFileNameLocationStepOperator();
      160         opNewFileNameLocationStep.setObjectName(strWSDLFileName);
      161         new JTextFieldOperator(opNewFileNameLocationStep, FOLDER_FIELD_INDEX).setText(strSrc);
      162         opNewFileWizard.next();
      163         
      164         JDialogOperator opAbstractConfigStep = new JDialogOperator("New WSDL Document");
      165         
      166         JComponentOperator opComponent = Helpers.getComponentOperator(opAbstractConfigStep, JTABLE_CLASS, 2);
      167         JTable table = (JTable) opComponent.getSource();
      168         JTableOperator opInputTable = new JTableOperator(table);
      169         
      170         opComponent = Helpers.getComponentOperator(opAbstractConfigStep, JTABLE_CLASS, 1);
      171         table = (JTable) opComponent.getSource();
      172         JTableOperator opOutputTable = new JTableOperator(table);
      173         
      174         Rectangle r = opInputTable.getCellRect(0, 1, false);
      175         new MouseEventDriver().clickMouse(opInputTable, r.x + r.width - 5, r.y + r.height - 5, 1, InputEvent.BUTTON1_MASK, 0, new Timeout("timeout", 500));
      176         
      177         JDialogOperator opSelectElementOrType = new JDialogOperator("Select Element Or Type");
      178         
      179         JTreeOperator opTree = new JTreeOperator(opSelectElementOrType);
      180         TreePath treePath = opTree.findPath("By File|" + TEST_PROJECT_NAME + "|src/schema0.xsd|Elements|purchaseOrder");
      181         opTree.selectPath(treePath);
      182         new JButtonOperator(opSelectElementOrType, "OK").pushNoBlock();
      183         opSelectElementOrType.waitClosed();
      184         
      185         r = opOutputTable.getCellRect(0, 1, false);
      186         new MouseEventDriver().clickMouse(opOutputTable, r.x + r.width - 5, r.y + r.height - 5, 1, InputEvent.BUTTON1_MASK, 0, new Timeout("timeout", 500));
      187         
      188         opSelectElementOrType = new JDialogOperator("Select Element Or Type");
      189         opTree = new JTreeOperator(opSelectElementOrType);
      190         treePath = opTree.findPath("By File|" + TEST_PROJECT_NAME + "|src/schema1.xsd|Elements|purchaseOrder");
      191         opTree.selectPath(treePath);
      192         new JButtonOperator(opSelectElementOrType, "OK").pushNoBlock();
      193         opSelectElementOrType.waitClosed();
      194         
      195         opNewFileWizard.next();
      196         
      197         JDialogOperator opConcreteConfigStep = new JDialogOperator("New WSDL Document");
      198         
      199         JComboBoxOperator opCombo = new JComboBoxOperator(opConcreteConfigStep);
      200         opCombo.selectItem("SOAP");
      201         
      202         JRadioButtonOperator opRadio = new JRadioButtonOperator(opConcreteConfigStep, "Document Literal");
      203         opRadio.pushNoBlock();
      204         
      205         opNewFileWizard.finish();
      206         
      207         endTest();
      208     }
      209     
      210     public void createXSLT() {
      211         startTest();
      212         
      213 //        final String strSOADocument = "Service Oriented Architecture";
      214         final String strSOADocument = "SOA";
      215         final String strFileType = "XSLT Service";
      216         final String strXSLFile = "XSL File:";
      217         
      218         NewFileWizardOperator opNewFileWizard = NewFileWizardOperator.invoke();
      219         opNewFileWizard.selectCategory(strSOADocument);
      220         opNewFileWizard.selectFileType(strFileType);
      221         opNewFileWizard.next();
      222         
      223         new JRadioButtonOperator(opNewFileWizard, "Request-Reply Service").pushNoBlock();
      224         
      225         opNewFileWizard.next();
      226         
      227         opNewFileWizard.next();
      228         
      229         JLabelOperator opLabel = new JLabelOperator(opNewFileWizard, strXSLFile);
      230         Helpers.getTextFieldOpByLabel(opLabel).setText(FILE_NAME);
      231         
      232         opNewFileWizard.finish();
      233         
      234         endTest();
      235     }
      236     
      237     public void editXSLT() {
      238         startTest();
      239         
      240         XSLTEditorOperator opEditor = new XSLTEditorOperator(FILE_NAME);
      241         
      242         opEditor.dropPaletteItemOnCanvas(PaletteOperator.Groups.STRING, "concat", new Point(50, 50));
      243         
      244         opEditor.bindSourceToMethoid("billTo|street", CONCAT_TITLE, 0, 0);
      245         opEditor.bindSourceToMethoid("billTo|city", CONCAT_TITLE, 0, 1);
      246         opEditor.bindMethoidToTarget(CONCAT_TITLE, 0, "purchaseOrder|billTo|name");
      247         
      248         opEditor.bindSourceToTarget("shipTo|name", "purchaseOrder|shipTo|name");
      249         opEditor.bindSourceToTarget("shipTo|city", "purchaseOrder|shipTo|city");
      250         opEditor.bindSourceToTarget("shipTo|street", "purchaseOrder|shipTo|street");
      251         
      252         endTest();
      253     }
      254     
      255     public void checkSource() {
      256         final long goldenCheckSum = 181301011L; // 708657604L
      257         
      258         startTest();
      259         
      260         XSLTEditorOperator opEditor = new XSLTEditorOperator(FILE_NAME);
      261         
      262         opEditor.switchToSource();
      263         
      264         EditorOperator opNBEditor = new EditorOperator(FILE_NAME);
      265         String strText = opNBEditor.getText();
      266         Helpers.writeJemmyLog("{" + strText + "}");
      267         
      268         opEditor.switchToDesign();
      269         
      270         if (!Helpers.isCRC32Equal(strText, goldenCheckSum)) {
      271             fail("The source check sum doesn't match the golden value");
      272         }
      273         
      274         endTest();
      275     }
      276     
      277     
      278     public void tearDown() {
      279         new SaveAllAction().performAPI();
      280     }
      281 }