websvc.kit/test/qa-functional/src/org/netbeans/modules/ws/qaf/designer/WebServiceDesignerTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sun Nov 22 11:35:02 2009 +0100 (10 hours ago)
changeset 154033 fa8b12981306
parent 1130470f1ab58db526
permissions -rw-r--r--
Merge RP javadoc improvements
     1 /*
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  *
     4  * Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.
     5  *
     6  * The contents of this file are subject to the terms of either the GNU
     7  * General Public License Version 2 only ("GPL") or the Common
     8  * Development and Distribution License("CDDL") (collectively, the
     9  * "License"). You may not use this file except in compliance with the
    10  * License. You can obtain a copy of the License at
    11  * http://www.netbeans.org/cddl-gplv2.html
    12  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    13  * specific language governing permissions and limitations under the
    14  * License.  When distributing the software, include this License Header
    15  * Notice in each file and include the License file at
    16  * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    17  * particular file as subject to the "Classpath" exception as provided
    18  * by Sun in the GPL Version 2 section of the License file that
    19  * accompanied this code. If applicable, add the following below the
    20  * License Header, with the fields enclosed by brackets [] replaced by
    21  * your own identifying information:
    22  * "Portions Copyrighted [year] [name of copyright owner]"
    23  *
    24  * If you wish your version of this file to be governed by only the CDDL
    25  * or only the GPL Version 2, indicate your decision by adding
    26  * "[Contributor] elects to include this software in this distribution
    27  * under the [CDDL or GPL Version 2] license." If you do not indicate a
    28  * single choice of license, a recipient has the option to distribute
    29  * your version of this file under either the CDDL, the GPL Version 2 or
    30  * to extend the choice of license to its licensees as provided above.
    31  * However, if you add GPL Version 2 code and therefore, elected the GPL
    32  * Version 2 license, then the option applies only if the new code is
    33  * made subject to such option by the copyright holder.
    34  *
    35  * Contributor(s):
    36  *
    37  * Portions Copyrighted 2008 Sun Microsystems, Inc.
    38  */
    39 package org.netbeans.modules.ws.qaf.designer;
    40 
    41 import junit.framework.Test;
    42 import org.netbeans.jellytools.Bundle;
    43 import org.netbeans.jellytools.EditorOperator;
    44 import org.netbeans.jellytools.NbDialogOperator;
    45 import org.netbeans.jellytools.actions.OpenAction;
    46 import org.netbeans.jellytools.actions.SaveAllAction;
    47 import org.netbeans.jellytools.nodes.Node;
    48 import org.netbeans.jellytools.nodes.SourcePackagesNode;
    49 import org.netbeans.jemmy.operators.JTextFieldOperator;
    50 import org.netbeans.junit.NbModuleSuite;
    51 import org.netbeans.modules.ws.qaf.WebServicesTestBase;
    52 
    53 /**
    54  *  Basic validation suite for web service designer
    55  *
    56  *  Duration of this test suite: aprox. 3min
    57  *
    58  * @author lukas.jungmann@sun.com
    59  */
    60 public class WebServiceDesignerTest extends WebServicesTestBase {
    61 
    62     public WebServiceDesignerTest(String name) {
    63         super(name);
    64     }
    65 
    66     @Override
    67     protected String getProjectName() {
    68         return getName().indexOf("Ejb") < 0 ? "60_webapp" : "65_ejbmodule"; //NOI18N
    69     }
    70 
    71     public void testAddOperation() {
    72         addOperation("EmptyWs", 0, false); //NOI18N
    73     }
    74 
    75     public void testRemoveOperation() {
    76         removeOperation("EmptyWs", 1, false); //NOI18N
    77     }
    78 
    79     public void testAddOperation2() {
    80         addOperation("SampleWs", 2, false); //NOI18N
    81     }
    82 
    83     public void testRemoveOperation2() {
    84         removeOperation("SampleWs", 3, false); //NOI18N
    85     }
    86 
    87     public void testAddOperationToIntf() {
    88         addOperation("WsImpl", 1, true); //NOI18N
    89     }
    90 
    91     public void testRemoveOperationFromIntf() {
    92         removeOperation("WsImpl", 2, true); //NOI18N
    93     }
    94 
    95     public void testEjbAddOperation() {
    96         String wsName = "FromWSDL";
    97         int opCount = 2;
    98         openFileInEditor(wsName);
    99         assertEquals(opCount, WsDesignerUtilities.operationsCount(wsName));
   100         WsDesignerUtilities.invokeAddOperation(wsName);
   101         try {
   102             Thread.sleep(5000);
   103         } catch (InterruptedException ex) {
   104             //ignore
   105         }
   106         //Add Operation...
   107         String actionName = Bundle.getStringTrimmed("org.netbeans.modules.websvc.design.view.actions.Bundle", "TTL_AddWsOperation");
   108         NbDialogOperator dialog = new NbDialogOperator(actionName);
   109         JTextFieldOperator jtfo = new JTextFieldOperator(dialog, "operation");
   110         jtfo.clearText();
   111         jtfo.typeText("addedOp");
   112         dialog.ok();
   113         try {
   114             Thread.sleep(10000);
   115         } catch (InterruptedException ex) {
   116             //ignore
   117         }
   118 //        new JTextFieldOperator(dialog, 2).setText("test1"); //NOI18N
   119 //        new JTextFieldOperator(dialog, 1).setText("String"); //NOI18N
   120     }
   121 
   122     public void testEjbRemoveOperation() {
   123         String wsName = "FromWSDL";
   124         openFileInEditor(wsName);
   125         WsDesignerUtilities.invokeRemoveOperation(wsName, "addedOp", false); //NOI18N
   126         NbDialogOperator ndo = new NbDialogOperator("Question"); //NOI18N
   127         ndo.yes();
   128         try {
   129             Thread.sleep(5000);
   130         } catch (InterruptedException ex) {
   131             //ignore
   132         }
   133     }
   134 
   135     public void testGoToSource() {
   136         String wsName = "EmptyWs"; //NOI18N
   137         String opName = "test1"; //NOI18N
   138         openFileInEditor(wsName);
   139         WsDesignerUtilities.invokeGoToSource(wsName, opName);
   140         try {
   141             Thread.sleep(1000);
   142         } catch (InterruptedException ex) {
   143             //ignore
   144         }
   145         EditorOperator eo = new EditorOperator(wsName);
   146         assertEquals(24, eo.getLineNumber());
   147 //      see: http://www.netbeans.org/issues/show_bug.cgi?id=150923
   148 //        wsName = "WsImpl"; //NOI18N
   149 //        openFileInEditor(wsName);
   150 //        WsDesignerUtilities.invokeGoToSource(wsName, opName);
   151 //        try {
   152 //            Thread.sleep(1000);
   153 //        } catch (InterruptedException ex) {
   154 //            //ignore
   155 //        }
   156 //        eo = new EditorOperator(wsName);
   157 //        assertEquals(18, eo.getLineNumber());
   158         wsName = "SampleWs"; //NOI18N
   159         opName = "sayHi"; //NOI18N
   160         openFileInEditor(wsName);
   161         WsDesignerUtilities.invokeGoToSource(wsName, opName);
   162         try {
   163             Thread.sleep(1000);
   164         } catch (InterruptedException ex) {
   165             //ignore
   166         }
   167         eo = new EditorOperator(wsName);
   168         assertEquals(33, eo.getLineNumber());
   169     }
   170 
   171     //only sanity test (see if there's no exception)
   172     //some checks can be added later
   173     public void testOperationButtons() {
   174         String wsName = "SampleWs"; //NOI18N
   175         WsDesignerUtilities.invokeAdvanced(wsName);
   176         try {
   177             //slow down a bit
   178             Thread.sleep(1000);
   179         } catch (InterruptedException ex) {
   180             //ignore
   181         }
   182         NbDialogOperator o = new NbDialogOperator(wsName);
   183         o.cancel();
   184         String opName = "voidOperation"; //NOI18N
   185         WsDesignerUtilities.clickOnButton(wsName, opName, 0);
   186         WsDesignerUtilities.clickOnButton(wsName, opName, 2);
   187         WsDesignerUtilities.clickOnExpander(wsName, opName);
   188         WsDesignerUtilities.clickOnExpander(wsName, opName);
   189         WsDesignerUtilities.clickOnButton(wsName, opName, 1);
   190         opName = "sayHi"; //NOI18N
   191         WsDesignerUtilities.clickOnButton(wsName, opName, 1);
   192         WsDesignerUtilities.clickOnButton(wsName, opName, 0);
   193         WsDesignerUtilities.clickOnExpander(wsName, opName);
   194         WsDesignerUtilities.clickOnExpander(wsName, opName);
   195         WsDesignerUtilities.clickOnButton(wsName, opName, 0);
   196         WsDesignerUtilities.clickOnButton(wsName, opName, 2);
   197         WsDesignerUtilities.clickOnButton(wsName, opName, 0);
   198     }
   199 
   200     private void addOperation(String wsName, int opCount, boolean hasInterface) {
   201         openFileInEditor(wsName);
   202         assertEquals(opCount, WsDesignerUtilities.operationsCount(wsName));
   203         WsDesignerUtilities.invokeAddOperation(wsName);
   204         //Add Operation...
   205         String actionName = Bundle.getStringTrimmed("org.netbeans.modules.websvc.core.jaxws.actions.Bundle", "LBL_OperationAction");
   206         NbDialogOperator dialog = new NbDialogOperator(actionName);
   207         new JTextFieldOperator(dialog, "operation").setText("test1"); //NOI18N
   208         new JTextFieldOperator(dialog, "java.lang.String").setText("String"); //NOI18N
   209         dialog.ok();
   210         try {
   211             //slow down a bit
   212             Thread.sleep(1500);
   213         } catch (InterruptedException ex) {
   214             //ignore
   215         }
   216         new SaveAllAction().performAPI();
   217         WsDesignerUtilities.source(wsName);
   218         EditorOperator eo = new EditorOperator(wsName);
   219         assertNotNull(eo);
   220         if (hasInterface) {
   221             assertFalse(eo.contains("import javax.jws.WebMethod;")); //NOI18N
   222             assertFalse(eo.contains("@WebMethod(operationName = \"test1\")")); //NOI18N
   223 //            see http://www.netbeans.org/issues/show_bug.cgi?id=150896
   224 //            assertEquals(opCount + 1, WsDesignerUtilities.operationsCount(wsName));
   225         } else {
   226             assertTrue(eo.contains("import javax.jws.WebMethod;")); //NOI18N
   227             assertTrue(eo.contains("@WebMethod(operationName = \"test1\")")); //NOI18N
   228             assertEquals(opCount + 1, WsDesignerUtilities.operationsCount(wsName));
   229         }
   230         assertTrue(eo.contains("public String test1() {")); //NOI18N
   231         //check ws endpoint interface
   232         if (hasInterface) {
   233             //XXX-rather should find interface from the source
   234             String iName = "EndpointI"; //NOI18N
   235             openFileInEditor(iName);
   236             EditorOperator eo2 = new EditorOperator(iName);
   237             assertTrue(eo2.contains("public String test1();")); //NOI18N
   238             eo2.close();
   239         }
   240     }
   241 
   242     private void removeOperation(String wsName, int opCount, boolean hasInterface) {
   243         openFileInEditor(wsName);
   244         WsDesignerUtilities.invokeRemoveOperation(wsName, "test1", opCount % 2 == 0); //NOI18N
   245         NbDialogOperator ndo = new NbDialogOperator("Question"); //NOI18N
   246         ndo.yes();
   247         //see: http://www.netbeans.org/issues/show_bug.cgi?id=150896
   248         if (!hasInterface) {
   249             assertEquals(opCount - 1, WsDesignerUtilities.operationsCount(wsName));
   250         }
   251         new SaveAllAction().performAPI();
   252         WsDesignerUtilities.source(wsName);
   253         EditorOperator eo = new EditorOperator(wsName);
   254         assertNotNull(eo);
   255         assertFalse(eo.contains("@WebMethod(operationName = \"test1\")")); //NOI18N
   256         if (hasInterface) {
   257             assertTrue(eo.contains("public String test1() {")); //NOI18N
   258         } else {
   259             assertFalse(eo.contains("public String test1() {")); //NOI18N
   260         }
   261         //check ws endpoint interface
   262         if (hasInterface) {
   263             //XXX-rather should find interface from the source
   264             String iName = "EndpointI"; //NOI18N
   265             openFileInEditor(iName);
   266             EditorOperator eo2 = new EditorOperator(iName);
   267             assertNotNull(eo2);
   268             assertFalse(eo2.contains("public String test1();")); //NOI18N
   269             eo2.close();
   270         }
   271     }
   272 
   273     private void openFileInEditor(String fileName) {
   274         //XXX:
   275         //there's some weird bug:
   276         //if project with webservices is checked out from VCS (cvs)
   277         //and its class is opened in the editor then there's no
   278         //web service designer or it is not initialized correctly :(
   279         Node wsNode = new Node(getProjectRootNode(), "Web Services");
   280         if (wsNode.isCollapsed()) {
   281             wsNode.expand();
   282         }
   283         //end
   284         SourcePackagesNode spn = new SourcePackagesNode(getProjectRootNode());
   285         Node n = new Node(spn, "samples|" + fileName); //NOI18N
   286         new OpenAction().perform(n);
   287     }
   288 
   289     public static Test suite() {
   290         return NbModuleSuite.create(addServerTests(Server.GLASSFISH,
   291                 NbModuleSuite.createConfiguration(WebServiceDesignerTest.class),
   292                 "testAddOperation", //NOI18N
   293                 "testAddOperation2", //NOI18N
   294                 "testAddOperationToIntf", //NOI18N
   295                 "testOperationButtons", //NOI18N
   296                 "testGoToSource", //NOI18N
   297                 "testRemoveOperation", //NOI18N
   298                 "testRemoveOperation2", //NOI18N
   299                 "testRemoveOperationFromIntf" //NOI18N
   300 //                "testEjbAddOperation", //NOI18N
   301 //                "testEjbRemoveOperation" //NOI18N
   302                 ).enableModules(".*").clusters(".*")); //NOI18N
   303     }
   304 }