visualweb.websvcmgr/test/qa-functional/src/org/netbeans/test/websvcmgr/WebServiceAcceptanceTest.java
author Jesse Glick <jglick@netbeans.org>
Wed, 23 Mar 2011 16:50:27 -0400
changeset 3213 c85dcf71e424
parent 2928 62324c1b61ee
child 3214 cf80c1d5c3ea
permissions -rw-r--r--
Tests at least should compile now.
     1 /*
     2 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  *
     4  * Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
     5  *
     6  * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
     7  * Other names may be trademarks of their respective owners.
     8  *
     9  * The contents of this file are subject to the terms of either the GNU
    10  * General Public License Version 2 only ("GPL") or the Common
    11  * Development and Distribution License("CDDL") (collectively, the
    12  * "License"). You may not use this file except in compliance with the
    13  * License. You can obtain a copy of the License at
    14  * http://www.netbeans.org/cddl-gplv2.html
    15  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    16  * specific language governing permissions and limitations under the
    17  * License.  When distributing the software, include this License Header
    18  * Notice in each file and include the License file at
    19  * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
    20  * particular file as subject to the "Classpath" exception as provided
    21  * by Oracle in the GPL Version 2 section of the License file that
    22  * accompanied this code. If applicable, add the following below the
    23  * License Header, with the fields enclosed by brackets [] replaced by
    24  * your own identifying information:
    25  * "Portions Copyrighted [year] [name of copyright owner]"
    26  *
    27  * Contributor(s):
    28  *
    29  * The Original Software is NetBeans. The Initial Developer of the Original
    30  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
    31  * Microsystems, Inc. All Rights Reserved.
    32  *
    33  * If you wish your version of this file to be governed by only the CDDL
    34  * or only the GPL Version 2, indicate your decision by adding
    35  * "[Contributor] elects to include this software in this distribution
    36  * under the [CDDL or GPL Version 2] license." If you do not indicate a
    37  * single choice of license, a recipient has the option to distribute
    38  * your version of this file under either the CDDL, the GPL Version 2 or
    39  * to extend the choice of license to its licensees as provided above.
    40  * However, if you add GPL Version 2 code and therefore, elected the GPL
    41  * Version 2 license, then the option applies only if the new code is
    42  * made subject to such option by the copyright holder.
    43  */
    44 
    45 package org.netbeans.test.websvcmgr;
    46 
    47 import org.netbeans.jemmy.operators.*;
    48 import org.netbeans.junit.NbTestSuite;
    49 import junit.framework.Test;
    50 
    51 import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
    52 import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerExplorerOperator;
    53 import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator;
    54 import org.netbeans.modules.visualweb.gravy.plugins.PluginsOperator;
    55 import org.netbeans.modules.visualweb.gravy.actions.FindAction;
    56 import org.netbeans.modules.visualweb.gravy.websvc.*;
    57 import org.netbeans.modules.visualweb.gravy.model.project.components.*;
    58 import org.netbeans.modules.visualweb.gravy.model.project.*;
    59 import org.netbeans.modules.visualweb.gravy.model.components.*;
    60 import org.netbeans.modules.visualweb.gravy.model.deployment.*;
    61 import org.netbeans.modules.visualweb.gravy.model.*;
    62 import org.netbeans.modules.visualweb.gravy.*;
    63 
    64 import java.util.Properties;
    65 import java.awt.event.KeyEvent;
    66 import java.awt.Point;
    67 import java.io.File;
    68 import java.io.FileInputStream;
    69 
    70 /**
    71  *
    72  * @author Roman Mostyka
    73  */
    74 
    75 public class WebServiceAcceptanceTest extends RaveTestCase {
    76 
    77     private static String addBindingAttribute = Bundle.getStringTrimmed("org.netbeans.modules.visualweb.insync.action.Bundle","LBL_AddBindingAttributeActionName");
    78     private static String sep = File.separator;
    79     private static String wsPath = "Web Services|";
    80     private static String deletePopup = "Delete";
    81     private static String reformatPopup = "Format";
    82     private static String addToPagePopup = "Add to Page";
    83     private static String menuCopy = "Edit|Copy";
    84     private static String menuPaste = "Edit|Paste";
    85     private static String testMethod = "Test Method";
    86     private static String dlgQuestion = "Question";
    87     private static String dlgTestMethod = "Test Web Service Method";
    88     private static String btnYes = "Yes";
    89     private static String btnSubmit = "Submit";
    90     private static String _wsProjectName = "AcceptanceWSProject";
    91     private static String _projectPath = System.getProperty("xtest.workdir") + sep + "projects" + sep;
    92     private static String wsURL = "URL";
    93     private static String wsName = "PATH";
    94     private static String wsMethod = "METHOD";
    95     private static String wsMethodParameter = "PARAMETER";
    96     private static String pluginName = "Visual Web JSF Backwards Compatibility Kit";
    97     private static String javaCode = "CODE";
    98     private static String wsResponse = "RESPONSE";
    99     private static String serverType = "GlassFish V2";
   100 
   101     private static Project prj, J2EE14prj, JavaEE5prj;
   102     private static DeploymentTargetDescriptor dtd;
   103     private static DeploymentTarget dt;
   104     private static ApplicationServer as;
   105     private static Properties properties;
   106 
   107     private ServerNavigatorOperator server;
   108     private JTreeOperator sntree;
   109    
   110     /** constructor required by JUnit
   111      * @param testName method name to be used as testcase
   112      */
   113     public WebServiceAcceptanceTest(String testName) {
   114         super(testName);
   115     }
   116 
   117     public static Test suite() {
   118         NbTestSuite suite = new NbTestSuite("Web Service Consumption Acceptance Tests");
   119         suite.addTest(new WebServiceAcceptanceTest("testPreparation"));
   120         suite.addTest(new WebServiceAcceptanceTest("testAddWebService"));
   121         suite.addTest(new WebServiceAcceptanceTest("testTestMethodDialog"));
   122         suite.addTest(new WebServiceAcceptanceTest("testAddWebServiceToJ2EE14Project"));
   123         suite.addTest(new WebServiceAcceptanceTest("testDeployJ2EE14Project"));
   124         suite.addTest(new WebServiceAcceptanceTest("testAddWebServiceToJavaEE5Project"));
   125         suite.addTest(new WebServiceAcceptanceTest("testDeployJavaEE5Project"));
   126         suite.addTest(new WebServiceAcceptanceTest("testRemoveWebService"));
   127         return suite;
   128     }
   129 
   130     /** method called before each testcase
   131      */
   132     protected void setUp() {
   133     }
   134 
   135     public void testPreparation() {
   136         properties = new Properties();
   137         try {
   138             properties.load(new FileInputStream(System.getProperty("xtest.ws-properties.file")));
   139         } catch(Exception e) {
   140             System.out.println("Properties can not be loaded!");
   141             System.out.println("e=" + e.toString());
   142             return;
   143         }
   144         PluginsOperator.getInstance().installAvailablePlugins(pluginName);
   145         dtd = new DeploymentTargetDescriptor();
   146         dtd.load();
   147         if (serverType != null) dtd.setProperty(dtd.SERVER_TYPE_KEY, serverType);
   148         dt = IDE.getIDE().addDeploymentTarget(dtd);
   149         as = (ApplicationServer) dt;
   150         as.start();
   151         TestUtils.wait(1000);
   152     }
   153 
   154     public void testAddWebService() {
   155         server = ServerNavigatorOperator.showNavigatorOperator();
   156         server.pushPopup("Web Services", "Add Web Service...");
   157         AddWebServiceOperator wsOp = new AddWebServiceOperator();
   158         wsOp.addWebService(properties.get(wsURL).toString());
   159         TestUtils.wait(2000);
   160     }
   161 
   162     public void testTestMethodDialog(){
   163         server = ServerNavigatorOperator.showNavigatorOperator();
   164         TestUtils.wait(4000);
   165         server.pushPopup(wsPath + properties.get(wsMethod).toString(), testMethod);
   166         TestUtils.wait(1000);
   167         JDialogOperator jdo = new JDialogOperator(dlgTestMethod);
   168         TestUtils.wait(1000);
   169         JTableOperator jto1 = new JTableOperator(jdo, 0);
   170         TestUtils.wait(1000);
   171         jto1.changeCellObject(0, 2, properties.get(wsMethodParameter).toString());
   172         TestUtils.wait(1000);
   173         new JButtonOperator(jdo, btnSubmit).push();
   174         TestUtils.wait(10000);
   175         JTableOperator jto2 = new JTableOperator(jdo, 1);
   176         if (jto2.getValueAt(0, 1).toString().indexOf(properties.get(wsResponse).toString()) == -1) {
   177             fail("There is no needed string in response!");
   178             jdo.close();
   179         }
   180         jdo.close();
   181     }
   182     
   183     public void testAddWebServiceToJ2EE14Project() {
   184         J2EE14prj = createProject(ProjectDescriptor.J2EE14);
   185         addComponentToProject(J2EE14prj);
   186         addWebServiceToProject();
   187         editPrerenderMethod(properties.get(javaCode).toString());
   188     }
   189 
   190     public void testDeployJ2EE14Project() {
   191         DeployAndCheckProject(J2EE14prj);
   192         verifyHTTP(J2EE14prj, wsResponse);
   193         projectUndeployAndClose(J2EE14prj);
   194     }
   195 
   196     public void testAddWebServiceToJavaEE5Project() {
   197         JavaEE5prj = createProject(ProjectDescriptor.JavaEE5);
   198         addComponentToProject(JavaEE5prj);
   199         addWebServiceToProject();
   200         editPrerenderMethod(properties.get(javaCode).toString());
   201     }
   202 
   203     public void testDeployJavaEE5Project() {
   204         DeployAndCheckProject(JavaEE5prj);
   205         verifyHTTP(JavaEE5prj, wsResponse);
   206         projectUndeployAndClose(JavaEE5prj);
   207         as.stop();
   208     }
   209     
   210     public void testRemoveWebService() {
   211         server = ServerNavigatorOperator.showNavigatorOperator();
   212         TestUtils.wait(4000);
   213         String wsClientPath = properties.get(wsName).toString();
   214         String realPath = wsPath + 
   215             wsClientPath.substring(0, wsClientPath.indexOf("|"));
   216         server.pushPopup(realPath, deletePopup);
   217         new JButtonOperator(new DialogOperator(dlgQuestion), btnYes).push();
   218         TestUtils.wait(2000);
   219     }
   220 
   221     private Project createProject(String J2EEVersion) {
   222         String J2EEVersion_PREF = J2EEVersion.replace(' ', '_').replace('.', '_');
   223         ProjectDescriptor pd = new ProjectDescriptor(_wsProjectName + "_" + J2EEVersion_PREF, _projectPath, J2EEVersion, as.getName());
   224         Project prj = IDE.getIDE().createProject(pd);
   225         TestUtils.disableBrowser(prj.getName(), true);
   226         TestUtils.wait(1000);
   227         return prj;
   228     }
   229 
   230     private void addComponentToProject(Project prj) {
   231         WebPageFolder wpf = prj.getRoot().getWebPageRootFolder();
   232         WebPage wp = wpf.getWebPage("Page1");
   233         VisualComponent vcmp = (VisualComponent)
   234         wp.add((WebComponent)
   235         IDE.getIDE().getDefaultComponentSet().getComponent(StaticTextComponent.STATIC_TEXT_ID),
   236         new Point(48, 48));
   237         addBindingAttribute(wp.getName(), "page1|html1|body1|form1|" + vcmp.getName());
   238     }
   239 
   240     private void addWebServiceToProject() {
   241         server = ServerNavigatorOperator.showNavigatorOperator();
   242         TestUtils.wait(4000);
   243         sntree = server.getTree();
   244         server.selectPath(wsPath + properties.get(wsName).toString());
   245         Util.getMainMenu().pushMenu(menuCopy);
   246         WebPageFolder wpf = prj.getRoot().getWebPageRootFolder();
   247         WebPage wp = wpf.getWebPage("Page1");
   248         wp.open();
   249         TestUtils.wait(1000);
   250         Util.getMainMenu().pushMenu(menuPaste);
   251         TestUtils.wait(30000);
   252     }
   253 
   254     private void editPrerenderMethod(String code) {
   255         DesignerPaneOperator designer = new DesignerPaneOperator(RaveWindowOperator.getDefaultRave());
   256         designer.switchToJavaSource();
   257         TestUtils.wait(1000);
   258         EditorOperator editor = new EditorOperator(RaveWindowOperator.getDefaultRave(), "Page1.java");
   259         TestUtils.wait(2000);
   260         new FindAction().performShortcut();
   261         TestUtils.wait(2000);
   262         JComboBoxOperator jcbo = new JComboBoxOperator(editor);
   263         TestUtils.wait(500);
   264         jcbo.clearText();
   265         TestUtils.wait(500);
   266         jcbo.enterText("prerender() {");
   267         TestUtils.wait(500);
   268         jcbo.pressKey(KeyEvent.VK_ESCAPE);
   269         TestUtils.wait(500);
   270         jcbo.pressKey(KeyEvent.VK_RIGHT);
   271         TestUtils.wait(500);
   272         editor.setCaretPositionToEndOfLine(editor.getLineNumber());
   273         TestUtils.wait(500);
   274         editor.pressKey(KeyEvent.VK_ENTER);
   275         TestUtils.wait(2000);
   276         editor.txtEditorPane().typeText(code);
   277         editor.txtEditorPane().clickForPopup();
   278         JPopupMenuOperator epm = new JPopupMenuOperator();
   279         TestUtils.wait(1000);
   280         new JMenuItemOperator(epm, reformatPopup).push();
   281         TestUtils.wait(2000);
   282     }
   283 
   284     private void DeployAndCheckProject(Project prj) {
   285         Util.getMainWindow().deploy();
   286         TestUtils.wait(20000);
   287         server = ServerNavigatorOperator.showNavigatorOperator();
   288         TestUtils.wait(4000);
   289         sntree = server.getTree();
   290         server.pushPopup(ServerExplorerOperator.STR_SERVERS_PATH + as.web_applications_path, as.REFRESH);
   291         TestUtils.wait(1000);
   292         try {
   293             sntree.selectPath(sntree.findPath(ServerExplorerOperator.STR_SERVERS_PATH + as.web_applications_path + "|" + as.app_pref + prj.getName()));
   294         }
   295         catch (Exception e) {
   296             fail("There is no " + prj.getName() + " application in Deployed Components node!");
   297         }
   298         TestUtils.wait(1000);
   299     }
   300 
   301     private void verifyHTTP(Project prj, String verificationString) {
   302         /* XXX httpunit not available anywhere
   303         try {
   304             WebConversation conversation = new WebConversation();
   305             WebResponse response = null;
   306             System.out.println("requestPrefix=" + as.requestPrefix);
   307             response = conversation.getResponse(as.requestPrefix + prj.getName());
   308             if (response.getText().indexOf(properties.get(wsResponse).toString()) == -1) fail("There is no needed string in response!");
   309         } catch (Exception e) {
   310             System.out.println("Exception occured: ");
   311             e.printStackTrace();
   312             fail("Excetion in HTTP check : " + e);
   313         }
   314          */
   315     }
   316 
   317     private void projectUndeployAndClose(Project prj) {
   318         TestUtils.wait(1000);
   319         Util.saveAllAPICall();
   320         server.pushPopup(ServerExplorerOperator.STR_SERVERS_PATH + as.web_applications_path, as.REFRESH);
   321         TestUtils.wait(1000);
   322         server.pushPopup(ServerExplorerOperator.STR_SERVERS_PATH + as.web_applications_path + "|" + as.app_pref + prj.getName(), as.APPLICATION_UNDEPLOY);
   323         TestUtils.wait(1000);
   324         prj.close();
   325         TestUtils.wait(1000);
   326     }
   327 
   328     public void addBindingAttribute(String page, String full_component_path) {
   329         DocumentOutlineOperator outline = new DocumentOutlineOperator(RaveWindowOperator.getDefaultRave());
   330         TestUtils.wait(1000);
   331         JTreeOperator aotree = outline.getStructTreeOperator();
   332         aotree.callPopupOnPath(aotree.findPath(page + "|" + full_component_path));
   333         TestUtils.wait(1000);
   334         JPopupMenuOperator aopm = new JPopupMenuOperator();
   335         TestUtils.wait(1000);
   336         new JMenuItemOperator(aopm, addBindingAttribute).pushNoBlock();
   337         TestUtils.wait(1000);
   338     }
   339 }
   340