websvc.restkit/test/qa-functional/src/org/netbeans/modules/ws/qaf/rest/FromDBTest.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sun Nov 22 11:35:02 2009 +0100 (10 hours ago)
changeset 154033 fa8b12981306
parent 1510496ce099212066
permissions -rw-r--r--
Merge RP javadoc improvements
     1 /*
     2  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     3  *
     4  * Copyright 2008 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.rest;
    40 
    41 import java.io.File;
    42 import java.io.IOException;
    43 import java.util.Set;
    44 import javax.swing.JDialog;
    45 import junit.framework.Test;
    46 import org.netbeans.jellytools.Bundle;
    47 import org.netbeans.jellytools.WizardOperator;
    48 import org.netbeans.jellytools.actions.ActionNoBlock;
    49 import org.netbeans.jellytools.actions.OutputWindowViewAction;
    50 import org.netbeans.jemmy.EventTool;
    51 import org.netbeans.jemmy.operators.JButtonOperator;
    52 import org.netbeans.jemmy.operators.JComboBoxOperator;
    53 import org.netbeans.jemmy.operators.JDialogOperator;
    54 import org.netbeans.junit.NbModuleSuite;
    55 import org.netbeans.modules.ws.qaf.utilities.RestWizardOperator;
    56 
    57 /**
    58  * Tests for New REST web services from Database wizard
    59  *
    60  * @author lukas
    61  */
    62 public class FromDBTest extends CRUDTest {
    63 
    64     public FromDBTest(String name) {
    65         super(name);
    66     }
    67 
    68     @Override
    69     protected String getProjectName() {
    70         return "FromDB"; //NOI18N
    71     }
    72 
    73     @Override
    74     protected String getRestPackage() {
    75         return "o.n.m.ws.qaf.rest.fromdb"; //NOI18N
    76     }
    77 
    78     public void testFromDB() throws IOException {
    79          // closing Tasks tab
    80         new OutputWindowViewAction().performMenu();
    81         new ActionNoBlock("Window|Tasks", null).performMenu();
    82         new ActionNoBlock("Window|Close Window", null).performMenu();
    83         copyDBSchema();
    84         createPU();
    85         //RESTful Web Services from Database
    86         String restLabel = Bundle.getStringTrimmed("org.netbeans.modules.websvc.rest.wizard.Bundle", "Templates/WebServices/RestServicesFromDatabase");
    87         createNewWSFile(getProject(), restLabel);
    88         //Entity Classes from Database
    89         String fromDbLabel = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.persistence.wizard.fromdb.Bundle", "Templates/Persistence/RelatedCMP");
    90         WizardOperator wo = prepareEntityClasses(new RestWizardOperator(fromDbLabel), false);
    91         wo.next();
    92         JComboBoxOperator jcbo = new JComboBoxOperator(wo, 1);
    93         jcbo.clearText();
    94         jcbo.typeText(getRestPackage() + ".service"); //NOI18N
    95         jcbo = new JComboBoxOperator(wo, 2);
    96         jcbo.clearText();
    97         jcbo.typeText(getRestPackage() + ".converter"); //NOI18N
    98         wo.finish();
    99         Runnable r = new Runnable() {
   100 
   101             private boolean found = false;
   102             public void run() {
   103                 while (!found) {
   104                     String dlgLbl = "REST Resources Configuration";
   105                     JDialog dlg = JDialogOperator.findJDialog(dlgLbl, true, true);
   106                     if (null != dlg) {
   107                         found = true;
   108                         new JButtonOperator(new JDialogOperator(dlg), "OK").push();
   109                     }
   110                 }
   111             }
   112         };
   113         new Thread(r).start();
   114         String generationTitle = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.persistence.wizard.fromdb.Bundle", "TXT_EntityClassesGeneration");
   115         waitDialogClosed(generationTitle);
   116         new EventTool().waitNoEvent(1500);
   117         waitScanFinished();
   118         Set<File> files = getFiles(getRestPackage() + ".service"); //NOI18N
   119         files.addAll(getFiles(getRestPackage() + ".converter")); //NOI18N
   120         assertEquals("Some files were not generated", 30, files.size()); //NOI18N
   121         //make sure all REST services nodes are visible in project log. view
   122         assertEquals("missing nodes?", 14, getRestNode().getChildren().length);
   123     }
   124 
   125     private void createPU() {
   126         //Persistence
   127         String category = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.persistence.ui.resources.Bundle", "Templates/Persistence");
   128         //Persistence Unit
   129         String puLabel = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.persistence.wizard.unit.Bundle", "Templates/Persistence/PersistenceUnit");
   130         createNewFile(getProject(), category, puLabel);
   131         String title = Bundle.getStringTrimmed("org.netbeans.modules.j2ee.persistence.unit.Bundle", "LBL_NewPersistenceUnit");
   132         WizardOperator wo = new WizardOperator(title);
   133         new JComboBoxOperator(wo, 1).selectItem("jdbc/sample"); //NOI18N
   134         wo.finish();
   135     }
   136 
   137     /**
   138      * Creates suite from particular test cases. You can define order of testcases here.
   139      */
   140     public static Test suite() {
   141         return NbModuleSuite.create(addServerTests(Server.GLASSFISH_V3, NbModuleSuite.createConfiguration(FromDBTest.class),
   142                 "testFromDB", //NOI18N
   143                 "testDeploy", //NOI18N
   144                 "testUndeploy").enableModules(".*").clusters(".*")); //NOI18N
   145     }
   146 }