visualweb.websvcmgr/test/qa-functional/src/org/netbeans/test/websvcmgr/WebServiceAcceptanceTest.java
author Jesse Glick <jglick@netbeans.org>
Wed, 23 Mar 2011 17:17:42 -0400
changeset 3214 cf80c1d5c3ea
parent 3213 c85dcf71e424
permissions -rw-r--r--
Really making tests compilable.
     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 com.meterware.httpunit.WebConversation;
    48 import com.meterware.httpunit.WebResponse;
    49 import org.netbeans.jemmy.operators.*;
    50 import org.netbeans.junit.NbTestSuite;
    51 import junit.framework.Test;
    52 
    53 import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerNavigatorOperator;
    54 import org.netbeans.modules.visualweb.gravy.dataconnectivity.ServerExplorerOperator;
    55 import org.netbeans.modules.visualweb.gravy.designer.DesignerPaneOperator;
    56 import org.netbeans.modules.visualweb.gravy.plugins.PluginsOperator;
    57 import org.netbeans.modules.visualweb.gravy.actions.FindAction;
    58 import org.netbeans.modules.visualweb.gravy.websvc.*;
    59 import org.netbeans.modules.visualweb.gravy.model.project.components.*;
    60 import org.netbeans.modules.visualweb.gravy.model.project.*;
    61 import org.netbeans.modules.visualweb.gravy.model.components.*;
    62 import org.netbeans.modules.visualweb.gravy.model.deployment.*;
    63 import org.netbeans.modules.visualweb.gravy.model.*;
    64 import org.netbeans.modules.visualweb.gravy.*;
    65 
    66 import java.util.Properties;
    67 import java.awt.event.KeyEvent;
    68 import java.awt.Point;
    69 import java.io.File;
    70 import java.io.FileInputStream;
    71 
    72 /**
    73  *
    74  * @author Roman Mostyka
    75  */
    76 
    77 public class WebServiceAcceptanceTest extends RaveTestCase {
    78 
    79     private static String addBindingAttribute = Bundle.getStringTrimmed("org.netbeans.modules.visualweb.insync.action.Bundle","LBL_AddBindingAttributeActionName");
    80     private static String sep = File.separator;
    81     private static String wsPath = "Web Services|";
    82     private static String deletePopup = "Delete";
    83     private static String reformatPopup = "Format";
    84     private static String addToPagePopup = "Add to Page";
    85     private static String menuCopy = "Edit|Copy";
    86     private static String menuPaste = "Edit|Paste";
    87     private static String testMethod = "Test Method";
    88     private static String dlgQuestion = "Question";
    89     private static String dlgTestMethod = "Test Web Service Method";
    90     private static String btnYes = "Yes";
    91     private static String btnSubmit = "Submit";
    92     private static String _wsProjectName = "AcceptanceWSProject";
    93     private static String _projectPath = System.getProperty("xtest.workdir") + sep + "projects" + sep;
    94     private static String wsURL = "URL";
    95     private static String wsName = "PATH";
    96     private static String wsMethod = "METHOD";
    97     private static String wsMethodParameter = "PARAMETER";
    98     private static String pluginName = "Visual Web JSF Backwards Compatibility Kit";
    99     private static String javaCode = "CODE";
   100     private static String wsResponse = "RESPONSE";
   101     private static String serverType = "GlassFish V2";
   102 
   103     private static Project prj, J2EE14prj, JavaEE5prj;
   104     private static DeploymentTargetDescriptor dtd;
   105     private static DeploymentTarget dt;
   106     private static ApplicationServer as;
   107     private static Properties properties;
   108 
   109     private ServerNavigatorOperator server;
   110     private JTreeOperator sntree;
   111    
   112     /** constructor required by JUnit
   113      * @param testName method name to be used as testcase
   114      */
   115     public WebServiceAcceptanceTest(String testName) {
   116         super(testName);
   117     }
   118 
   119     public static Test suite() {
   120         NbTestSuite suite = new NbTestSuite("Web Service Consumption Acceptance Tests");
   121         suite.addTest(new WebServiceAcceptanceTest("testPreparation"));
   122         suite.addTest(new WebServiceAcceptanceTest("testAddWebService"));
   123         suite.addTest(new WebServiceAcceptanceTest("testTestMethodDialog"));
   124         suite.addTest(new WebServiceAcceptanceTest("testAddWebServiceToJ2EE14Project"));
   125         suite.addTest(new WebServiceAcceptanceTest("testDeployJ2EE14Project"));
   126         suite.addTest(new WebServiceAcceptanceTest("testAddWebServiceToJavaEE5Project"));
   127         suite.addTest(new WebServiceAcceptanceTest("testDeployJavaEE5Project"));
   128         suite.addTest(new WebServiceAcceptanceTest("testRemoveWebService"));
   129         return suite;
   130     }
   131 
   132     /** method called before each testcase
   133      */
   134     protected void setUp() {
   135     }
   136 
   137     public void testPreparation() {
   138         properties = new Properties();
   139         try {
   140             properties.load(new FileInputStream(System.getProperty("xtest.ws-properties.file")));
   141         } catch(Exception e) {
   142             System.out.println("Properties can not be loaded!");
   143             System.out.println("e=" + e.toString());
   144             return;
   145         }
   146         PluginsOperator.getInstance().installAvailablePlugins(pluginName);
   147         dtd = new DeploymentTargetDescriptor();
   148         dtd.load();
   149         if (serverType != null) dtd.setProperty(dtd.SERVER_TYPE_KEY, serverType);
   150         dt = IDE.getIDE().addDeploymentTarget(dtd);
   151         as = (ApplicationServer) dt;
   152         as.start();
   153         TestUtils.wait(1000);
   154     }
   155 
   156     public void testAddWebService() {
   157         server = ServerNavigatorOperator.showNavigatorOperator();
   158         server.pushPopup("Web Services", "Add Web Service...");
   159         AddWebServiceOperator wsOp = new AddWebServiceOperator();
   160         wsOp.addWebService(properties.get(wsURL).toString());
   161         TestUtils.wait(2000);
   162     }
   163 
   164     public void testTestMethodDialog(){
   165         server = ServerNavigatorOperator.showNavigatorOperator();
   166         TestUtils.wait(4000);
   167         server.pushPopup(wsPath + properties.get(wsMethod).toString(), testMethod);
   168         TestUtils.wait(1000);
   169         JDialogOperator jdo = new JDialogOperator(dlgTestMethod);
   170         TestUtils.wait(1000);
   171         JTableOperator jto1 = new JTableOperator(jdo, 0);
   172         TestUtils.wait(1000);
   173         jto1.changeCellObject(0, 2, properties.get(wsMethodParameter).toString());
   174         TestUtils.wait(1000);
   175         new JButtonOperator(jdo, btnSubmit).push();
   176         TestUtils.wait(10000);
   177         JTableOperator jto2 = new JTableOperator(jdo, 1);
   178         if (jto2.getValueAt(0, 1).toString().indexOf(properties.get(wsResponse).toString()) == -1) {
   179             fail("There is no needed string in response!");
   180             jdo.close();
   181         }
   182         jdo.close();
   183     }
   184     
   185     public void testAddWebServiceToJ2EE14Project() {
   186         J2EE14prj = createProject(ProjectDescriptor.J2EE14);
   187         addComponentToProject(J2EE14prj);
   188         addWebServiceToProject();
   189         editPrerenderMethod(properties.get(javaCode).toString());
   190     }
   191 
   192     public void testDeployJ2EE14Project() {
   193         DeployAndCheckProject(J2EE14prj);
   194         verifyHTTP(J2EE14prj, wsResponse);
   195         projectUndeployAndClose(J2EE14prj);
   196     }
   197 
   198     public void testAddWebServiceToJavaEE5Project() {
   199         JavaEE5prj = createProject(ProjectDescriptor.JavaEE5);
   200         addComponentToProject(JavaEE5prj);
   201         addWebServiceToProject();
   202         editPrerenderMethod(properties.get(javaCode).toString());
   203     }
   204 
   205     public void testDeployJavaEE5Project() {
   206         DeployAndCheckProject(JavaEE5prj);
   207         verifyHTTP(JavaEE5prj, wsResponse);
   208         projectUndeployAndClose(JavaEE5prj);
   209         as.stop();
   210     }
   211     
   212     public void testRemoveWebService() {
   213         server = ServerNavigatorOperator.showNavigatorOperator();
   214         TestUtils.wait(4000);
   215         String wsClientPath = properties.get(wsName).toString();
   216         String realPath = wsPath + 
   217             wsClientPath.substring(0, wsClientPath.indexOf("|"));
   218         server.pushPopup(realPath, deletePopup);
   219         new JButtonOperator(new DialogOperator(dlgQuestion), btnYes).push();
   220         TestUtils.wait(2000);
   221     }
   222 
   223     private Project createProject(String J2EEVersion) {
   224         String J2EEVersion_PREF = J2EEVersion.replace(' ', '_').replace('.', '_');
   225         ProjectDescriptor pd = new ProjectDescriptor(_wsProjectName + "_" + J2EEVersion_PREF, _projectPath, J2EEVersion, as.getName());
   226         Project prj = IDE.getIDE().createProject(pd);
   227         TestUtils.disableBrowser(prj.getName(), true);
   228         TestUtils.wait(1000);
   229         return prj;
   230     }
   231 
   232     private void addComponentToProject(Project prj) {
   233         WebPageFolder wpf = prj.getRoot().getWebPageRootFolder();
   234         WebPage wp = wpf.getWebPage("Page1");
   235         VisualComponent vcmp = (VisualComponent)
   236         wp.add((WebComponent)
   237         IDE.getIDE().getDefaultComponentSet().getComponent(StaticTextComponent.STATIC_TEXT_ID),
   238         new Point(48, 48));
   239         addBindingAttribute(wp.getName(), "page1|html1|body1|form1|" + vcmp.getName());
   240     }
   241 
   242     private void addWebServiceToProject() {
   243         server = ServerNavigatorOperator.showNavigatorOperator();
   244         TestUtils.wait(4000);
   245         sntree = server.getTree();
   246         server.selectPath(wsPath + properties.get(wsName).toString());
   247         Util.getMainMenu().pushMenu(menuCopy);
   248         WebPageFolder wpf = prj.getRoot().getWebPageRootFolder();
   249         WebPage wp = wpf.getWebPage("Page1");
   250         wp.open();
   251         TestUtils.wait(1000);
   252         Util.getMainMenu().pushMenu(menuPaste);
   253         TestUtils.wait(30000);
   254     }
   255 
   256     private void editPrerenderMethod(String code) {
   257         DesignerPaneOperator designer = new DesignerPaneOperator(RaveWindowOperator.getDefaultRave());
   258         designer.switchToJavaSource();
   259         TestUtils.wait(1000);
   260         EditorOperator editor = new EditorOperator(RaveWindowOperator.getDefaultRave(), "Page1.java");
   261         TestUtils.wait(2000);
   262         new FindAction().performShortcut();
   263         TestUtils.wait(2000);
   264         JComboBoxOperator jcbo = new JComboBoxOperator(editor);
   265         TestUtils.wait(500);
   266         jcbo.clearText();
   267         TestUtils.wait(500);
   268         jcbo.enterText("prerender() {");
   269         TestUtils.wait(500);
   270         jcbo.pressKey(KeyEvent.VK_ESCAPE);
   271         TestUtils.wait(500);
   272         jcbo.pressKey(KeyEvent.VK_RIGHT);
   273         TestUtils.wait(500);
   274         editor.setCaretPositionToEndOfLine(editor.getLineNumber());
   275         TestUtils.wait(500);
   276         editor.pressKey(KeyEvent.VK_ENTER);
   277         TestUtils.wait(2000);
   278         editor.txtEditorPane().typeText(code);
   279         editor.txtEditorPane().clickForPopup();
   280         JPopupMenuOperator epm = new JPopupMenuOperator();
   281         TestUtils.wait(1000);
   282         new JMenuItemOperator(epm, reformatPopup).push();
   283         TestUtils.wait(2000);
   284     }
   285 
   286     private void DeployAndCheckProject(Project prj) {
   287         Util.getMainWindow().deploy();
   288         TestUtils.wait(20000);
   289         server = ServerNavigatorOperator.showNavigatorOperator();
   290         TestUtils.wait(4000);
   291         sntree = server.getTree();
   292         server.pushPopup(ServerExplorerOperator.STR_SERVERS_PATH + as.web_applications_path, as.REFRESH);
   293         TestUtils.wait(1000);
   294         try {
   295             sntree.selectPath(sntree.findPath(ServerExplorerOperator.STR_SERVERS_PATH + as.web_applications_path + "|" + as.app_pref + prj.getName()));
   296         }
   297         catch (Exception e) {
   298             fail("There is no " + prj.getName() + " application in Deployed Components node!");
   299         }
   300         TestUtils.wait(1000);
   301     }
   302 
   303     private void verifyHTTP(Project prj, String verificationString) {
   304         try {
   305             WebConversation conversation = new WebConversation();
   306             WebResponse response = null;
   307             System.out.println("requestPrefix=" + as.requestPrefix);
   308             response = conversation.getResponse(as.requestPrefix + prj.getName());
   309             if (response.getText().indexOf(properties.get(wsResponse).toString()) == -1) fail("There is no needed string in response!");
   310         } catch (Exception e) {
   311             System.out.println("Exception occured: ");
   312             e.printStackTrace();
   313             fail("Excetion in HTTP check : " + e);
   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