1 19 20 package org.netbeans.test.j2ee; 21 22 import java.io.*; 23 import junit.textui.TestRunner; 24 import org.netbeans.jellytools.Bundle; 25 import org.netbeans.jellytools.EditorOperator; 26 import org.netbeans.jellytools.EditorWindowOperator; 27 import org.netbeans.jellytools.JellyTestCase; 28 import org.netbeans.jellytools.MainWindowOperator; 29 import org.netbeans.jellytools.NbDialogOperator; 30 import org.netbeans.jellytools.NewFileWizardOperator; 31 import org.netbeans.jellytools.ProjectsTabOperator; 32 import org.netbeans.jellytools.RuntimeTabOperator; 33 import org.netbeans.jellytools.actions.ActionNoBlock; 34 import org.netbeans.jellytools.actions.DeleteAction; 35 import org.netbeans.jellytools.actions.NewFileAction; 36 import org.netbeans.jellytools.actions.OpenAction; 37 import org.netbeans.jellytools.nodes.Node; 38 import org.netbeans.jemmy.operators.JButtonOperator; 39 import org.netbeans.jemmy.operators.JComboBoxOperator; 40 import org.netbeans.jemmy.operators.JDialogOperator; 41 import org.netbeans.jemmy.operators.JRadioButtonOperator; 42 import org.netbeans.jemmy.operators.JTableOperator; 43 import org.netbeans.jemmy.operators.JTextFieldOperator; 44 import org.netbeans.jemmy.operators.JTreeOperator; 45 import org.netbeans.jemmy.TimeoutExpiredException; 46 import org.netbeans.junit.NbTestSuite; 47 import org.netbeans.junit.ide.ProjectSupport; 48 import org.netbeans.test.j2ee.addmethod.AddOperationTest; 49 import org.netbeans.test.j2ee.addmethod.CallEJBTest; 50 import org.netbeans.test.j2ee.lib.ProgressSupport; 51 import org.netbeans.test.j2ee.lib.Utils; 52 53 59 public class WSValidation extends JellyTestCase { 60 61 public static final String EAR_SAMPLE_PROJECT_NAME = "SampleApp"; 62 public static final String WEB_SAMPLE_PROJECT_NAME = EAR_SAMPLE_PROJECT_NAME + "-WebModule"; 63 public static final String EJB_SAMPLE_PROJECT_NAME = EAR_SAMPLE_PROJECT_NAME + "-EJBModule"; 64 public static final String WSC_SAMPLE_PROJECT_NAME = EAR_SAMPLE_PROJECT_NAME + "-WSClient"; 65 66 public static final String EAR_SAMPLE_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_SAMPLE_PROJECT_NAME; 67 public static final String EJB_SAMPLE_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_SAMPLE_PROJECT_NAME + File.separator + EAR_SAMPLE_PROJECT_NAME + "-ejb"; 68 public static final String WEB_SAMPLE_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_SAMPLE_PROJECT_NAME + File.separator + EAR_SAMPLE_PROJECT_NAME + "-war"; 69 public static final String WSC_SAMPLE_PROJECT_PATH = System.getProperty("xtest.tmpdir") + File.separator + EAR_SAMPLE_PROJECT_NAME + File.separator + WSC_SAMPLE_PROJECT_NAME; 70 71 72 public WSValidation(String name) { 73 super(name); 74 } 75 76 public static NbTestSuite suite() { 77 NbTestSuite suite = new NbTestSuite(); 78 79 suite.addTest(new WSValidation("openProjects")); 80 suite.addTest(new EJBValidation("testStartServer")); 81 82 suite.addTest(new AddOperationTest("testAddOperation1")); 83 suite.addTest(new AddOperationTest("testAddOperation2")); 84 suite.addTest(new CallEJBTest("testCallEJBInWS")); 85 suite.addTest(new WSValidation("testDeploymentWS")); 86 89 suite.addTest(new WSValidation("testCreateWSClient")); 90 suite.addTest(new WSValidation("testCallWS")); 91 suite.addTest(new WSValidation("testRunWSClient")); 92 suite.addTest(new WSValidation("testUndeployWSClient")); 93 94 suite.addTest(new WSValidation("testUndeployWS")); 95 96 suite.addTest(new WSValidation("testDeleteWSinWeb")); 97 98 suite.addTest(new EJBValidation("testStopServer")); 100 suite.addTest(new WSValidation("closeProjects")); 101 return suite; 102 } 103 104 105 public static void main(java.lang.String [] args) { 106 TestRunner.run(suite()); 108 } 109 110 public void openProjects() { 111 ProjectSupport.openProject(EAR_SAMPLE_PROJECT_PATH); 112 ProjectSupport.waitScanFinished(); 113 ProjectSupport.openProject(EJB_SAMPLE_PROJECT_PATH); 114 ProjectSupport.waitScanFinished(); 115 ProjectSupport.openProject(WEB_SAMPLE_PROJECT_PATH); 116 ProjectSupport.waitScanFinished(); 117 ProjectSupport.openProject(WSC_SAMPLE_PROJECT_PATH); 118 ProjectSupport.waitScanFinished(); 119 120 try { new NbDialogOperator("Open Project").ok(); } 122 catch (TimeoutExpiredException e) {} 123 124 new org.netbeans.jemmy.EventTool().waitNoEvent(5000); 125 } 126 127 public void closeProjects() { 128 ProjectSupport.closeProject(EAR_SAMPLE_PROJECT_NAME); 129 ProjectSupport.closeProject(EJB_SAMPLE_PROJECT_NAME); 130 ProjectSupport.closeProject(WEB_SAMPLE_PROJECT_NAME); 131 ProjectSupport.closeProject(WSC_SAMPLE_PROJECT_NAME); 132 } 133 public void testDeploymentWS() throws IOException { 134 String CONTROL_TEXT = "name=\"SampleWebService\""; 135 String page = Utils.deploy(EAR_SAMPLE_PROJECT_NAME, "http://localhost:8080/SampleApp-WebModule/SampleWebService?WSDL"); 136 log(page); 137 assertTrue("WSDL doesn't contain expected text '"+CONTROL_TEXT+"'. See log for content.", page.indexOf(CONTROL_TEXT)>=0); 138 } 139 140 public void testUndeployWS() { 141 Utils.undeploy(EAR_SAMPLE_PROJECT_NAME); 142 } 143 144 public void testDeleteWSinWeb() throws IOException { 145 Node node = new Node(new ProjectsTabOperator().getProjectRootNode(WEB_SAMPLE_PROJECT_NAME), 146 "Web Services|SampleWebService"); 147 new DeleteAction().performAPI(node); 148 NbDialogOperator dialog = new NbDialogOperator("Confirm Web Service Deletion"); 149 dialog.yes(); 150 151 new org.netbeans.jemmy.EventTool().waitNoEvent(2000); 152 Utils utils = new Utils(this); 153 String ddNames[] = { "web.xml", 154 "sun-web.xml" }; 155 utils.assertFiles(new File(WEB_SAMPLE_PROJECT_PATH + File.separator + "web" + File.separator + "WEB-INF"), ddNames, getName()+"_"); 156 157 File dir = new File(WEB_SAMPLE_PROJECT_PATH + File.separator + "src" + File.separator + "java" + File.separator + "sample"); 158 String deletedFiles[] = dir.list(new FilenameFilter () { 159 public boolean accept(File dir, String name) { 160 return name.startsWith("SampleWebService"); 161 } 162 }); 163 File file = new File(WEB_SAMPLE_PROJECT_PATH + File.separator + "web" + File.separator + "WEB-INF" + File.separator + "webservices.xml"); 164 if (file.exists()) 165 fail("File "+file.getAbsolutePath()+" was not deleted."); 166 172 } 173 174 public void testRegisterWS() { 175 Node node = new Node(new ProjectsTabOperator().getProjectRootNode(WEB_SAMPLE_PROJECT_NAME), 176 "Web Services|SampleWebService"); 177 node.performPopupActionNoBlock(Bundle.getStringTrimmed("org.netbeans.modules.websvc.core.webservices.action.Bundle", "LBL_WSRegisterAction")); 178 new NbDialogOperator(Bundle.getStringTrimmed("org.netbeans.modules.websvc.core.webservices.ui.Bundle", "Enter_WSDL_Url")).ok(); 179 MainWindowOperator.getDefault().getTimeouts().setTimeout("Waiter.WaitingTime", 120000); 180 MainWindowOperator.getDefault().waitStatusText("Successfully compiled web service client code."); 181 new Node(new RuntimeTabOperator().getRootNode(), "Web Services|SampleWebService|SampleWebServiceSEIPort|operation1"); 182 } 183 184 public void testTestOperation() { 185 String popup = "Test Operation"; 186 new Node(new RuntimeTabOperator().getRootNode(), "Web Services|SampleWebService|SampleWebServiceSEIPort|operation1").performPopupAction(popup); 187 NbDialogOperator dialog = new NbDialogOperator("Test Web Service Operation"); 188 new JButtonOperator(dialog, "Submit").push(); 189 JTableOperator table = new JTableOperator(dialog,1); 190 table.waitCell("sampleValue",0,1); 191 dialog.close(); 192 } 193 194 public void testCreateWSClient() { 195 new NewFileAction().performMenu(); 196 NewFileWizardOperator wizard = new NewFileWizardOperator(); 197 new org.netbeans.jemmy.EventTool().waitNoEvent(2000); 198 wizard.selectProject(WSC_SAMPLE_PROJECT_NAME); 199 wizard.selectCategory("Web Services"); 200 wizard.selectFileType("Web Service Client"); 201 wizard.next(); 202 new JTextFieldOperator(wizard, 0).setText("http://localhost:8080/SampleApp-WebModule/SampleWebService?WSDL"); 203 new JComboBoxOperator(wizard,0).clearText(); 204 new JComboBoxOperator(wizard,0).typeText("test"); 205 new JButtonOperator(wizard, "Retrieve WSDL").push(); 206 wizard.finish(); 207 ProgressSupport.waitFinished("Creating webservice client", 30000); 208 } 209 210 public void testCallWS() { 211 Node openFile = new Node(new ProjectsTabOperator().getProjectRootNode(WSC_SAMPLE_PROJECT_NAME), 212 "Source Packages|servlet|TestServlet.java"); 213 new OpenAction().performAPI(openFile); 214 EditorOperator editor = new EditorWindowOperator().getEditor("TestServlet.java"); 215 new org.netbeans.jemmy.EventTool().waitNoEvent(2000); 216 editor.select(35); 217 new org.netbeans.jemmy.EventTool().waitNoEvent(2000); 218 new ActionNoBlock(null,"Web Service Client Resources|Call Web Service Operation").perform(editor); 219 NbDialogOperator dialog = new NbDialogOperator("Select Operation to Invoke"); 220 new Node(new JTreeOperator(dialog),"SampleWebService|SampleWebServiceSEIPort|operation1").select(); 221 new org.netbeans.jemmy.EventTool().waitNoEvent(2000); 222 dialog.ok(); 223 new org.netbeans.jemmy.EventTool().waitNoEvent(5000); 224 new Utils(this).checkAndModify("TestServlet.java", 37, "getSampleWebServiceSEIPort().operation1(/* TODO enter operation arguments */);", 225 0, null, 37, true, "out.println(getSampleWebServiceSEIPort().operation1());"); 226 } 227 228 public void testRunWSClient() throws IOException { 229 String CONTROL_TEXT = "sampleValue"; 230 String page = Utils.deploy(WSC_SAMPLE_PROJECT_NAME, "http://localhost:8080/SampleApp-WSClient/TestServlet", true); 231 log(page); 232 assertTrue("TestServlet doesn't contain expected text '"+CONTROL_TEXT+"'. See log for content.", page.indexOf(CONTROL_TEXT)>=0); 233 } 234 235 public void testUndeployWSClient() { 236 Utils.undeploy(Bundle.getStringTrimmed("org.netbeans.modules.j2ee.sun.ide.j2ee.runtime.nodes.Bundle", "LBL_WebModules"), WSC_SAMPLE_PROJECT_NAME); 237 } 238 239 public void testNewWebServiceFromWSDL() { 240 String dataDir = System.getProperty("xtest.data"); 241 String wsdlFile = dataDir + File.separator + "QuotesService.wsdl"; 242 File file = new File(wsdlFile); 243 if (!file.exists()) 244 throw new RuntimeException ("WSDL file not found:"+file.getAbsolutePath()); 245 new NewFileAction().performMenu(); 246 NewFileWizardOperator wizard = new NewFileWizardOperator(); 247 new org.netbeans.jemmy.EventTool().waitNoEvent(2000); 248 wizard.selectProject(EAR_SAMPLE_PROJECT_NAME+"-war"); 249 wizard.selectCategory("Web Services"); 250 wizard.selectFileType("Web Service"); 251 wizard.next(); 252 new JTextFieldOperator(wizard, 0).setText("QuotesWebService"); 253 new JTextFieldOperator(wizard,2).typeText("quotes"); 254 new JRadioButtonOperator(wizard,"From Local WSDL File").push(); 255 new JTextFieldOperator(wizard,3).setText(file.getAbsolutePath()); 256 wizard.finish(); 257 JDialogOperator status = new JDialogOperator("Progress"); 258 status.getTimeouts().setTimeout("ComponentOperator.WaitStateTimeout", 120000); 259 status.waitClosed(); 260 } 261 262 } 263 | Popular Tags |