001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.ws.qaf;
042:
043: import java.io.File;
044: import java.io.IOException;
045: import java.util.Collection;
046: import junit.framework.Test;
047: import junit.framework.TestSuite;
048: import junit.textui.TestRunner;
049: import org.netbeans.api.project.Project;
050: import org.netbeans.jellytools.Bundle;
051: import org.netbeans.jellytools.EditorOperator;
052: import org.netbeans.jellytools.NbDialogOperator;
053: import org.netbeans.jellytools.NewFileNameLocationStepOperator;
054: import org.netbeans.jellytools.OutputTabOperator;
055: import org.netbeans.jellytools.ProjectsTabOperator;
056: import org.netbeans.jellytools.actions.ActionNoBlock;
057: import org.netbeans.jellytools.modules.web.NewJspFileNameStepOperator;
058: import org.netbeans.jellytools.nodes.Node;
059: import org.netbeans.jellytools.nodes.ProjectRootNode;
060: import org.netbeans.jemmy.JemmyException;
061: import org.netbeans.jemmy.JemmyProperties;
062: import org.netbeans.jemmy.TimeoutExpiredException;
063: import org.netbeans.jemmy.Waitable;
064: import org.netbeans.jemmy.Waiter;
065: import org.netbeans.jemmy.operators.JButtonOperator;
066: import org.netbeans.jemmy.operators.JComboBoxOperator;
067: import org.netbeans.jemmy.operators.JTableOperator;
068: import org.netbeans.jemmy.operators.JTextFieldOperator;
069: import org.netbeans.jemmy.operators.JTreeOperator;
070: import org.netbeans.junit.NbTestSuite;
071: import org.netbeans.modules.j2ee.dd.api.web.DDProvider;
072: import org.netbeans.modules.j2ee.dd.api.web.Listener;
073: import org.netbeans.modules.j2ee.dd.api.web.Servlet;
074: import org.netbeans.modules.j2ee.dd.api.web.ServletMapping;
075: import org.netbeans.modules.j2ee.dd.api.web.WebApp;
076: import org.netbeans.modules.websvc.api.jaxws.project.config.Endpoint;
077: import org.netbeans.modules.websvc.api.jaxws.project.config.Endpoints;
078: import org.netbeans.modules.websvc.api.jaxws.project.config.EndpointsProvider;
079: import org.netbeans.modules.websvc.api.jaxws.project.config.Handler;
080: import org.netbeans.modules.websvc.api.jaxws.project.config.HandlerChain;
081: import org.netbeans.modules.websvc.api.jaxws.project.config.HandlerChains;
082: import org.netbeans.modules.websvc.api.jaxws.project.config.HandlerChainsProvider;
083: import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsHandler;
084: import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsHandlerChain;
085: import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsHandlerChains;
086: import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsModel;
087: import org.netbeans.modules.websvc.core.jaxws.bindings.model.BindingsModelFactory;
088: import org.netbeans.modules.xml.retriever.catalog.Utilities;
089: import org.netbeans.modules.xml.xam.ModelSource;
090: import org.openide.filesystems.FileObject;
091: import org.openide.filesystems.FileUtil;
092:
093: /**
094: * Basic validation suite for web services support in the IDE
095: *
096: * @author lukas.jungmann@sun.com
097: */
098: public class WsValidation extends WebServicesTestBase {
099:
100: protected static final String WEB_SERVICES_NODE_NAME = Bundle
101: .getStringTrimmed(
102: "org.netbeans.modules.websvc.core.jaxws.nodes.Bundle",
103: "LBL_WebServices");
104: private static final String WEB_SERVICE_CLIENTS_NODE_NAME = Bundle
105: .getStringTrimmed(
106: "org.netbeans.modules.websvc.core.jaxws.nodes.Bundle",
107: "LBL_ServiceReferences");
108: private static int foId = 0;
109:
110: protected enum HandlerType {
111:
112: LOGICAL, MESSAGE;
113:
114: public String getFileTypeLabel() {
115: switch (this ) {
116: case LOGICAL:
117: return Bundle
118: .getStringTrimmed(
119: "org.netbeans.modules.websvc.core.dev.wizard.Bundle",
120: "Templates/WebServices/LogicalHandler.java");
121: case MESSAGE:
122: return Bundle
123: .getStringTrimmed(
124: "org.netbeans.modules.websvc.core.dev.wizard.Bundle",
125: "Templates/WebServices/SOAPMessageHandler.java");
126: }
127: throw new AssertionError("Unknown type: " + this ); //NOI18N
128: }
129:
130: public String getMessageType() {
131: switch (this ) {
132: case LOGICAL:
133: return "LogicalMessage"; //NOI18N
134: case MESSAGE:
135: return "SOAPMessage"; //NOI18N
136: }
137: throw new AssertionError("Unknown type: " + this ); //NOI18N
138: }
139: }
140:
141: /** Creates a new instance of WsValidation */
142: public WsValidation(String name) {
143: super (name);
144: }
145:
146: public String getProjectName() {
147: return getName().indexOf("Client") > -1 //NOI18N
148: ? getWsClientProjectName()
149: : getWsProjectName();
150: }
151:
152: protected String getWsProjectName() {
153: return "WsInWeb"; //NOI18N
154: }
155:
156: protected String getWsClientProjectName() {
157: return "WsClientInWeb"; //NOI18N
158: }
159:
160: protected String getWsName() {
161: return "MyWebWs"; //NOI18N
162: }
163:
164: protected String getWsPackage() {
165: return "o.n.m.ws.qaf.ws"; //NOI18N
166: }
167:
168: protected String getWsClientPackage() {
169: return "o.n.m.ws.qaf.client"; //NOI18N
170: }
171:
172: /**
173: * Creates a new web service in a web project and checks whether web service
174: * node has been created in the project view and web service implementation
175: * class has been opened in the editor
176: * @throws java.io.IOException
177: */
178: public void testCreateNewWs() throws IOException {
179: // Web Service
180: String webServiceLabel = Bundle.getStringTrimmed(
181: "org.netbeans.modules.websvc.core.dev.wizard.Bundle",
182: "Templates/WebServices/WebService.java");
183: createNewWSFile(getProject(), webServiceLabel);
184: NewFileNameLocationStepOperator op = new NewFileNameLocationStepOperator();
185: op.setObjectName(getWsName());
186: op.setPackage(getWsPackage());
187: op.finish();
188: // needed for slower machines
189: JemmyProperties.setCurrentTimeout(
190: "JTreeOperator.WaitNextNodeTimeout", 30000); //NOI18N
191: //TODO: following nodes should be expanded by default - this test should check it as well
192: Node wsRootNode = new Node(getProjectRootNode(),
193: WEB_SERVICES_NODE_NAME);
194: wsRootNode.expand();
195: new Node(wsRootNode, getWsName());
196: new EditorOperator(getWsName());
197: checkNonJSR109Service();
198: }
199:
200: /**
201: * Tests adding operation to webservice using
202: * - add operation action from editor's popup menu
203: * - add operation action from ws node's context menu
204: */
205: public void testAddOperation() {
206: final EditorOperator eo = new EditorOperator(getWsName());
207: //Web Service
208: String actionGroupName = Bundle
209: .getStringTrimmed(
210: "org.netbeans.modules.websvc.core.webservices.action.Bundle",
211: "LBL_WebServiceActionGroup");
212: //Add Operation...
213: String actionName = Bundle
214: .getStringTrimmed(
215: "org.netbeans.modules.websvc.core.webservices.action.Bundle",
216: "LBL_OperationAction");
217: //invoke action from editor's context menu
218: new ActionNoBlock(null, actionGroupName + "|" + actionName)
219: .performPopup(eo);
220: addWsOperation(eo, "myStringMethod", "String"); //NOI18N
221: //invoke action from ws node's context menu
222: Node wsRootNode = new Node(getProjectRootNode(),
223: WEB_SERVICES_NODE_NAME);
224: wsRootNode.expand();
225: Node wsImplNode = new Node(wsRootNode, getWsName());
226: wsImplNode.callPopup().pushMenuNoBlock(actionName);
227: addWsOperation(eo, "myIntMethod", "int[]"); //NOI18N
228: // wsImplNode.expand();
229: // assertTrue(wsImplNode.isChildPresent("myMethod")); //NOI18N
230: // assertTrue(wsImplNode.isChildPresent("myMethod2")); //NOI18N
231: }
232:
233: public void testDeployWsProject() throws IOException {
234: deployProject(getProjectName());
235: }
236:
237: public void testDeployWsClientProject() throws IOException {
238: deployProject(getProjectName());
239: }
240:
241: /**
242: * Creates a new web service client in a web project and checks whether web
243: * service client node has been created in the project view
244: * @throws java.io.IOException
245: */
246: public void testCreateWsClient() throws IOException {
247: //Web Service Client
248: String wsClientLabel = Bundle
249: .getStringTrimmed(
250: "org.netbeans.modules.websvc.core.client.wizard.Bundle",
251: "Templates/WebServices/WebServiceClient");
252: createNewWSFile(getProject(), wsClientLabel);
253: NewFileNameLocationStepOperator op = new NewFileNameLocationStepOperator();
254: new JButtonOperator(op, 3).push();
255: //Browse Web Services
256: String browseWsLabel = Bundle
257: .getStringTrimmed(
258: "org.netbeans.modules.websvc.core.client.wizard.Bundle",
259: "TTL_SelectService");
260: NbDialogOperator ndo = new NbDialogOperator(browseWsLabel);
261: JTreeOperator jto = new JTreeOperator(ndo);
262: jto.selectPath(jto.findPath(getWsProjectName() + "|"
263: + getWsName())); //NOI18N
264: ndo.ok();
265: new JComboBoxOperator(op, 0).typeText(getWsClientPackage()); //NOI18N
266: op.finish();
267: try {
268: Thread.sleep(1000);
269: } catch (InterruptedException ie) {
270: }
271: //expand ws client node
272: // needed for slower machines
273: JemmyProperties.setCurrentTimeout(
274: "JTreeOperator.WaitNextNodeTimeout", 60000); //NOI18N
275: Node wsClientRootNode = new Node(getProjectRootNode(),
276: WEB_SERVICE_CLIENTS_NODE_NAME);
277: wsClientRootNode.expand();
278: Node wsClientNode = new Node(wsClientRootNode, getWsName()); //NOI18N
279: wsClientNode.expand();
280: waitForWsImport("wsimport-client-compile)"); //NOI18N
281: Node wsClientServiceNode = new Node(wsClientNode, getWsName()); //NOI18N
282: wsClientServiceNode.expand();
283: Node wsClientPortNode = new Node(wsClientServiceNode,
284: getWsName()); //NOI18N
285: wsClientPortNode.expand();
286: assertTrue(wsClientPortNode.isChildPresent("myStringMethod")); //NOI18N
287: assertTrue(wsClientPortNode.isChildPresent("myIntMethod")); //NOI18N
288: assertEquals(wsClientPortNode.getChildren().length, 2);
289: }
290:
291: /**
292: * Tests Call Web Service Operation action in a servlet
293: */
294: public void testCallWsOperationInServlet() {
295: //create a servlet
296: //Web
297: String webLabel = Bundle.getStringTrimmed(
298: "org.netbeans.modules.web.core.Bundle",
299: "Templates/JSP_Servlet");
300: //Servlet
301: String servletLabel = Bundle.getStringTrimmed(
302: "org.netbeans.modules.web.core.Bundle",
303: "Templates/JSP_Servlet/Servlet.java");
304: createNewFile(getWsClientProject(), webLabel, servletLabel);
305: NewFileNameLocationStepOperator op = new NewFileNameLocationStepOperator();
306: JComboBoxOperator jcbo = new JComboBoxOperator(op, 1);
307: jcbo.typeText("org.mycompany.servlets"); //NOI18N
308: op.finish();
309: //edit code in the servlet
310: EditorOperator eo = new EditorOperator("NewServlet"); //NOI18N
311: // delete comments
312: eo.replace("/* TODO output your page here", ""); //NOI18N
313: eo.replace(" */", ""); //NOI18N
314: // add new line and select it
315: eo.setCaretPosition("\"</h1>\");", false); //NOI18N
316: eo.insert("\n//xxx"); //NOI18N
317: eo.select("//xxx"); //NOI18N
318: callWsOperation(eo, "myIntMethod", 40); //NOI18N
319: assertTrue("@WebServiceRef has not been found", eo
320: .contains("@WebServiceRef")); //NOI18N
321: assertFalse("Lookup present", eo
322: .contains(getWsClientLookupCall())); //NOI18N
323: eo.close(true);
324: }
325:
326: /**
327: * Test Call Web Service Operation action in a JSP
328: */
329: public void testCallWsOperationInJSP() {
330: //create new JSP
331: //Web
332: String webLabel = Bundle.getStringTrimmed(
333: "org.netbeans.modules.web.core.Bundle",
334: "Templates/JSP_Servlet");
335: //JSP
336: String servletLabel = Bundle.getStringTrimmed(
337: "org.netbeans.modules.web.core.Bundle",
338: "Templates/JSP_Servlet/JSP.jsp");
339: createNewFile(getWsClientProject(), webLabel, servletLabel);
340: NewJspFileNameStepOperator op = new NewJspFileNameStepOperator();
341: op.setJSPFileName("index1"); //NOI18N
342: op.finish();
343: //edit code in JSP
344: EditorOperator eo = new EditorOperator("index1"); //NOI18N
345: eo.setCaretPosition("</h2>", false); //NOI18N
346: eo.insert("\n<!-- xxx -->"); //NOI18N
347: eo.select("<!-- xxx -->"); //NOI18N
348: callWsOperation(eo, "myStringMethod", 14); //NOI18N
349: assertTrue("Lookup class has not been found", eo
350: .contains(getWsClientLookupCall())); //NOI18N
351: assertFalse("@WebServiceRef present", eo
352: .contains("@WebServiceRef")); //NOI18N
353: eo.close(true);
354: }
355:
356: /**
357: * Test Call Web Service Operation action in a regular java file
358: */
359: public void testCallWsOperationInJavaClass() {
360: //Create new Java class
361: //Java
362: String javaAppLabel = Bundle.getStringTrimmed(
363: "org.netbeans.modules.java.project.Bundle",
364: "Templates/Classes"); //NOI18N
365: //Java Class
366: String javaFileLabel = Bundle.getStringTrimmed(
367: "org.netbeans.modules.java.project.Bundle",
368: "Templates/Classes/Class.java"); //NOI18N
369: createNewFile(getWsClientProject(), javaAppLabel, javaFileLabel);
370: NewFileNameLocationStepOperator op = new NewFileNameLocationStepOperator();
371: op.setPackage("org.mycompany.classes"); //NOI18N
372: op.finish();
373: final EditorOperator eo = new EditorOperator("NewClass"); //NOI18N
374: eo.select(13); //NOI18N
375: eo.insert(" public void callMethod() {\n\t//xxx\n }\n"); //NOI18N
376: eo.select("//xxx"); //NOI18N
377: callWsOperation(eo, "myIntMethod", 13); //NOI18N
378: assertTrue("Lookup class has not been found", eo
379: .contains(getWsClientLookupCall())); //NOI18N
380: assertFalse("@WebServiceRef present", eo
381: .contains("@WebServiceRef")); //NOI18N
382: eo.close(true);
383: }
384:
385: public void testWsHandlers() throws IOException {
386: createHandler(getHandlersPackage(), "WsMsgHandler1",
387: HandlerType.MESSAGE); //NOI18N
388: createHandler(getHandlersPackage(), "WsMsgHandler2",
389: HandlerType.MESSAGE); //NOI18N
390: createHandler(getHandlersPackage(), "WsLogHandler1",
391: HandlerType.LOGICAL); //NOI18N
392: createHandler(getHandlersPackage(), "WsLogHandler2",
393: HandlerType.LOGICAL); //NOI18N
394: FileObject fo = getProject().getProjectDirectory()
395: .getFileObject(
396: "src/java/" + getWsPackage().replace('.', '/')); //NOI18N
397: File handlerCfg = new File(FileUtil.toFile(fo), getWsName()
398: + "_handler.xml"); //NOI18N
399: Node serviceNode = new Node(getProjectRootNode(),
400: WEB_SERVICES_NODE_NAME + "|" + getWsName()); //NOI18N
401: configureHandlers(serviceNode, handlerCfg, true);
402: }
403:
404: public void testWsClientHandlers() throws IOException {
405: createHandler(getHandlersPackage(), "WsMsgHandler1",
406: HandlerType.MESSAGE); //NOI18N
407: createHandler(getHandlersPackage(), "WsMsgHandler2",
408: HandlerType.MESSAGE); //NOI18N
409: createHandler(getHandlersPackage(), "WsLogHandler1",
410: HandlerType.LOGICAL); //NOI18N
411: createHandler(getHandlersPackage(), "WsLogHandler2",
412: HandlerType.LOGICAL); //NOI18N
413: String path = "xml-resources/web-service-references/"
414: + getWsName() + "Service/bindings/"; //NOI18N
415: FileObject fo = getProject().getProjectDirectory()
416: .getFileObject("src/conf/"); //NOI18N
417: if (fo == null) {
418: fo = getProject().getProjectDirectory();
419: }
420: File handlerCfg = new File(FileUtil.toFile(fo), path
421: + getWsName() + "Service_handler.xml"); //NOI18N
422: Node clientNode = new Node(getProjectRootNode(),
423: WEB_SERVICE_CLIENTS_NODE_NAME + "|" + getWsName()); //NOI18N
424: configureHandlers(clientNode, handlerCfg, false);
425: }
426:
427: /**
428: * Cleanup method - undeploys projects deployed by this suite
429: */
430: public void testUndeployProjects() throws IOException {
431: undeployProject(getWsProjectName());
432: undeployProject(getWsClientProjectName());
433: }
434:
435: public static TestSuite suite() {
436: TestSuite suite = new NbTestSuite();
437: suite.addTest(new WsValidation("testCreateNewWs")); //NOI18N
438: suite.addTest(new WsValidation("testAddOperation")); //NOI18N
439: suite.addTest(new WsValidation("testStartServer")); //NOI18N
440: suite.addTest(new WsValidation("testWsHandlers")); //NOI18N
441: suite.addTest(new WsValidation("testDeployWsProject")); //NOI18N
442: suite.addTest(new WsValidation("testCreateWsClient")); //NOI18N
443: suite.addTest(new WsValidation("testCallWsOperationInServlet")); //NOI18N
444: suite.addTest(new WsValidation("testCallWsOperationInJSP")); //NOI18N
445: suite
446: .addTest(new WsValidation(
447: "testCallWsOperationInJavaClass")); //NOI18N
448: suite.addTest(new WsValidation("testWsClientHandlers")); //NOI18N
449: suite.addTest(new WsValidation("testDeployWsClientProject")); //NOI18N
450: suite.addTest(new WsValidation("testUndeployProjects")); //NOI18N
451: suite.addTest(new WsValidation("testStopServer")); //NOI18N
452: return suite;
453: }
454:
455: public static void main(java.lang.String[] args) {
456: TestRunner.run(suite());
457: }
458:
459: protected void addWsOperation(EditorOperator eo, String opName,
460: String opRetVal) {
461: //Add Operation...
462: String actionName = Bundle
463: .getStringTrimmed(
464: "org.netbeans.modules.websvc.core.webservices.action.Bundle",
465: "LBL_OperationAction");
466: addMethod(eo, actionName, opName, opRetVal);
467: }
468:
469: protected void addMethod(final EditorOperator eo, String dlgTitle,
470: String opName, String opRetVal) {
471: NbDialogOperator dialog = new NbDialogOperator(dlgTitle);
472: new JTextFieldOperator(dialog, 2).setText(opName);
473: new JTextFieldOperator(dialog, 1).setText(opRetVal);
474: dialog.ok();
475: eo.save();
476: waitForTextInEditor(eo, opName);
477: }
478:
479: protected void callWsOperation(final EditorOperator eo,
480: String opName, int line) {
481: //Web Service Client Resources
482: String actionGroupName = Bundle
483: .getStringTrimmed(
484: "org.netbeans.modules.websvc.core.webservices.action.Bundle",
485: "LBL_WebServiceClientActionGroup");
486: //Call Web Service Operation...
487: String actionName = Bundle
488: .getStringTrimmed(
489: "org.netbeans.modules.websvc.core.webservices.action.Bundle",
490: "LBL_CallWebServiceOperation");
491: try {
492: new ActionNoBlock(null, actionGroupName + "|" + actionName)
493: .performPopup(eo); //NOI18N
494: } catch (TimeoutExpiredException tee) {
495: eo.select(line);
496: new ActionNoBlock(null, actionGroupName + "|" + actionName)
497: .performPopup(eo); //NOI18N
498: }
499: //Select Operation to Invoke
500: String dlgTitle = org.netbeans.jellytools.Bundle
501: .getStringTrimmed(
502: "org.netbeans.modules.websvc.core.webservices.action.Bundle",
503: "TTL_SelectOperation");
504: NbDialogOperator ndo = new NbDialogOperator(dlgTitle);
505: JTreeOperator jto = new JTreeOperator(ndo);
506: jto.selectPath(jto.findPath(getWsClientProjectName() + "|"
507: + getWsName()//NOI18N
508: + "|" + getWsName() + "Service|" //NOI18N
509: + getWsName() + "Port|" + opName)); //NOI18N
510: ndo.ok();
511: waitForTextInEditor(eo, "port." + opName); //NOI18N
512: }
513:
514: protected String getWsClientLookupCall() {
515: return getWsClientPackage() + "." + getWsName() + "Service "
516: + "service = new " + getWsClientPackage() + "."
517: + getWsName() + "Service();";
518: }
519:
520: protected void createHandler(String pkg, String name,
521: HandlerType type) {
522: createNewWSFile(getProject(), type.getFileTypeLabel());
523: NewFileNameLocationStepOperator op = new NewFileNameLocationStepOperator();
524: op.txtObjectName().clearText();
525: op.txtObjectName().typeText(name);
526: op.cboPackage().clearText();
527: op.cboPackage().typeText(pkg);
528: op.finish();
529: EditorOperator eo = new EditorOperator(name);
530: assertTrue(eo.contains(type.getMessageType()));
531: eo.close();
532: }
533:
534: private void configureHandlers(Node n, File handlerCfg,
535: boolean isService) throws IOException {
536: assertFalse(handlerCfg.exists());
537: //Configure Handlers...
538: String handlersLabel = Bundle.getStringTrimmed(
539: "org.netbeans.modules.websvc.core.Bundle",
540: "LBL_ConfigureHandlerAction");
541: n.performPopupActionNoBlock(handlersLabel);
542: //Configure Message Handlers
543: String handlersDlgLabel = Bundle.getStringTrimmed(
544: "org.netbeans.modules.websvc.core.jaxws.nodes.Bundle",
545: "TTL_MessageHandlerPanel");
546: NbDialogOperator ndo = new NbDialogOperator(handlersDlgLabel);
547:
548: //add 2 handlers
549: String[] handlers = { "WsMsgHandler1", "WsLogHandler1" }; //NOI18N
550: addHandlers(ndo, handlers);
551: ndo.ok();
552: EditorOperator eo = null;
553: if (isService) {
554: eo = new EditorOperator(getWsName());
555: assertTrue("missing @HandlerChain", //NOI18N
556: eo.contains("@HandlerChain(file = \"" + getWsName()
557: + "_handler.xml\")")); //NOI18N
558: }
559: assertTrue(handlerCfg.exists());
560: FileObject fo = FileUtil.toFileObject(handlerCfg);
561: checkHandlers(new String[] { "WsLogHandler1", "WsMsgHandler1" //NOI18N
562: }, fo, isService);
563:
564: //remove one handler
565: n.performPopupActionNoBlock(handlersLabel);
566: ndo = new NbDialogOperator(handlersDlgLabel);
567: removeHandlers(ndo, new String[] { "WsLogHandler1" }); //NOI18N
568: ndo.ok();
569: if (isService) {
570: assertTrue(
571: "missing @HandlerChain", //NOI18N
572: eo
573: .contains("@HandlerChain(file = \"MyWebWs_handler.xml\")")); //NOI18N
574: }
575: assertTrue(handlerCfg.exists());
576: checkHandlers(new String[] { "WsMsgHandler1" }, fo, isService); //NOI18N
577:
578: //add remaining handlers
579: n.performPopupActionNoBlock(handlersLabel);
580: ndo = new NbDialogOperator(handlersDlgLabel);
581: addHandlers(ndo, new String[] { "WsLogHandler1",
582: "WsLogHandler2", "WsMsgHandler2" }); //NOI18N
583: ndo.ok();
584: if (isService) {
585: assertTrue(
586: "missing @HandlerChain", //NOI18N
587: eo
588: .contains("@HandlerChain(file = \"MyWebWs_handler.xml\")")); //NOI18N
589: }
590: assertTrue(handlerCfg.exists());
591: checkHandlers(new String[] { "WsLogHandler1", "WsLogHandler2", //NOI18N
592: "WsMsgHandler1", "WsMsgHandler2" //NOI18N
593: }, fo, isService);
594:
595: //move up one handler
596: n.performPopupActionNoBlock(handlersLabel);
597: ndo = new NbDialogOperator(handlersDlgLabel);
598: moveUpHandler(ndo, "WsLogHandler2"); //NOI18N
599: ndo.ok();
600: if (isService) {
601: assertTrue(
602: "missing @HandlerChain", //NOI18N
603: eo
604: .contains("@HandlerChain(file = \"MyWebWs_handler.xml\")")); //NOI18N
605: }
606: assertTrue(handlerCfg.exists());
607: checkHandlers(new String[] { "WsLogHandler2", "WsLogHandler1", //NOI18N
608: "WsMsgHandler1", "WsMsgHandler2" //NOI18N
609: }, fo, isService);
610:
611: //move down another one
612: n.performPopupActionNoBlock(handlersLabel);
613: ndo = new NbDialogOperator(handlersDlgLabel);
614: moveDownHandler(ndo, "WsMsgHandler1"); //NOI18N
615: ndo.ok();
616: if (isService) {
617: assertTrue(
618: "missing @HandlerChain", //NOI18N
619: eo
620: .contains("@HandlerChain(file = \"MyWebWs_handler.xml\")")); //NOI18N
621: }
622: assertTrue(handlerCfg.exists());
623: checkHandlers(new String[] { "WsLogHandler2", "WsLogHandler1", //NOI18N
624: "WsMsgHandler2", "WsMsgHandler1" //NOI18N
625: }, fo, isService);
626:
627: //finally remove all handlers
628: n.performPopupActionNoBlock(handlersLabel);
629: ndo = new NbDialogOperator(handlersDlgLabel);
630: removeHandlers(ndo, new String[] { "WsMsgHandler2",
631: "WsLogHandler2", //NOI18N
632: "WsLogHandler1", "WsMsgHandler1" }); //NOI18N
633: ndo.ok();
634:
635: if (isService) {
636: assertFalse(
637: "offending @HandlerChain", //NOI18N
638: eo
639: .contains("@HandlerChain(file = \"MyWebWs_handler.xml\")")); //NOI18N
640: assertFalse(handlerCfg.exists());
641: }
642: }
643:
644: /**
645: * Check non-JSR-109 service (web service DD, application DD)
646: *
647: * @throws java.io.IOException
648: */
649: protected void checkNonJSR109Service() throws IOException {
650: if (ServerType.TOMCAT.equals(REGISTERED_SERVER)) {
651: FileObject projectHome = getProject().getProjectDirectory();
652: FileObject webInfFO = projectHome
653: .getFileObject("web/WEB-INF"); //NOI18N
654: //check sun-jaxws.xml
655: FileObject sunJaxWsFO = webInfFO
656: .getFileObject("sun-jaxws.xml"); //NOI18N
657: assertNotNull("sun-jaxws.xml present", sunJaxWsFO); //NOI18N
658: assertTrue("sun-jaxws.xml present", FileUtil.toFile(
659: sunJaxWsFO).exists()); //NOI18N
660: Endpoints endpoints = EndpointsProvider.getDefault()
661: .getEndpoints(sunJaxWsFO);
662: assertEquals("Should have one endpoint", 1, endpoints
663: .getEndpoints().length); //NOI18N
664: Endpoint endpoint = endpoints
665: .findEndpointByName(getWsName());
666: assertNotNull(getWsName() + " is missing in sun-jaxws.xml",
667: endpoint); //NOI18N
668: //check web.xml
669: FileObject webXmlFO = webInfFO.getFileObject("web.xml"); //NOI18N
670: WebApp webDD = DDProvider.getDefault().getDDRoot(webXmlFO);
671: Listener[] listeners = webDD.getListener();
672: assertEquals("1 listener present", 1, listeners.length); //NOI18N
673: assertEquals(
674: "Invalid listener class", //NOI18N
675: "com.sun.xml.ws.transport.http.servlet.WSServletContextListener", //NOI18N
676: listeners[0].getListenerClass());
677: Servlet[] servlets = webDD.getServlet();
678: assertEquals("1 servlet present", 1, servlets.length); //NOI18N
679: assertEquals("Invalid servlet name", getWsName(),
680: servlets[0].getServletName()); //NOI18N
681: assertEquals("Invalid servlet class", //NOI18N
682: "com.sun.xml.ws.transport.http.servlet.WSServlet", //NOI18N
683: servlets[0].getServletClass());
684: ServletMapping[] mappings = webDD.getServletMapping();
685: assertEquals("1 servlet mapping present", 1,
686: mappings.length); //NOI18N
687: assertEquals("Invalid servlet mapping name", getWsName(),
688: mappings[0].getServletName()); //NOI18N
689: assertEquals("Invalid url pattern", "/" + getWsName(), //NOI18N
690: mappings[0].getUrlPattern());
691: }
692: }
693:
694: protected void waitForWsImport(String targetName)
695: throws IOException {
696: OutputTabOperator oto = new OutputTabOperator(targetName); //NOI18N
697: JemmyProperties.setCurrentTimeout(
698: "ComponentOperator.WaitStateTimeout", 240000); //NOI18N
699: oto.waitText("(total time: "); //NOI18N
700: dumpOutput();
701: assertTrue(oto.getText().indexOf("BUILD SUCCESSFUL") > -1); //NOI18N
702: }
703:
704: protected void waitForTextInEditor(final EditorOperator eo,
705: final String text) {
706: try {
707: new Waiter(new Waitable() {
708:
709: public Object actionProduced(Object obj) {
710: return eo.contains(text) ? Boolean.TRUE : null; //NOI18N
711: }
712:
713: public String getDescription() {
714: return ("Editor contains " + text); //NOI18N
715: }
716: }).waitAction(null);
717: } catch (InterruptedException ie) {
718: throw new JemmyException("Interrupted.", ie); //NOI18N
719: }
720: }
721:
722: protected Project getWsClientProject() {
723: ProjectRootNode node = new ProjectsTabOperator()
724: .getProjectRootNode(getWsClientProjectName());
725: Project p = ((org.openide.nodes.Node) node.getOpenideNode())
726: .getLookup().lookup(Project.class);
727: assertNotNull("Project can't be null", p); //NOI18N
728: return p;
729: }
730:
731: protected String getHandlersPackage() {
732: return "o.n.m.ws.qaf.handlers"; //NOI18N
733: }
734:
735: private void addHandlers(NbDialogOperator ndo, String[] handlers) {
736: //Add...
737: JButtonOperator jbo = new JButtonOperator(ndo, 0);
738: //Add Message Handler Class
739: String addHandlerDlg = Bundle.getStringTrimmed(
740: "org.netbeans.modules.websvc.core.jaxws.nodes.Bundle",
741: "TTL_SelectHandler");
742: //Source Packages
743: String srcPkgLabel = Bundle.getStringTrimmed(
744: "org.netbeans.modules.java.j2seproject.Bundle",
745: "NAME_src.dir");
746: for (int i = 0; i < handlers.length; i++) {
747: jbo.pushNoBlock();
748: NbDialogOperator ndo2 = new NbDialogOperator(addHandlerDlg);
749: JTreeOperator jto2 = new JTreeOperator(ndo2);
750: Node spn = new Node(jto2, srcPkgLabel);
751: Node pkg = new Node(spn, getHandlersPackage());
752: Node handler = new Node(pkg, handlers[i]);
753: handler.select();
754: ndo2.ok();
755: }
756: }
757:
758: private void removeHandlers(NbDialogOperator ndo, String[] handlers) {
759: //Confirm Handler Configuration Change
760: String changeTitle = Bundle
761: .getStringTrimmed(
762: "org.netbeans.modules.websvc.core.webservices.ui.panels.Bundle",
763: "TTL_CONFIRM_DELETE");
764: JTableOperator jto = new JTableOperator(ndo);
765: for (int i = 0; i < handlers.length; i++) {
766: jto.selectCell(jto.findCellRow(handlers[i]), jto
767: .findCellColumn(handlers[i]));
768: //Remove
769: new JButtonOperator(ndo, 2).pushNoBlock();
770: new NbDialogOperator(changeTitle).yes();
771: }
772: }
773:
774: private void moveUpHandler(NbDialogOperator ndo, String handler) {
775: JTableOperator jto = new JTableOperator(ndo);
776: jto.selectCell(jto.findCellRow(handler), jto
777: .findCellColumn(handler));
778: //Move Up
779: new JButtonOperator(ndo, 1).pushNoBlock();
780: }
781:
782: private void moveDownHandler(NbDialogOperator ndo, String handler) {
783: JTableOperator jto = new JTableOperator(ndo);
784: jto.selectCell(jto.findCellRow(handler), jto
785: .findCellColumn(handler));
786: //Move Down
787: new JButtonOperator(ndo, 3).pushNoBlock();
788: }
789:
790: private void checkHandlers(String[] handlerClasses,
791: FileObject handlerConfigFO, boolean isService)
792: throws IOException {
793: //Let's keep the config file to resolve possible issues
794: handlerConfigFO.copy(FileUtil.toFileObject(getWorkDir()),
795: handlerConfigFO.getName() + foId++, "xml"); //NOI18N
796: if (isService) {
797: HandlerChains hChains = HandlerChainsProvider.getDefault()
798: .getHandlerChains(handlerConfigFO);
799: HandlerChain[] chains = hChains.getHandlerChains();
800: assertEquals(1, chains.length);
801: Handler[] handlers = chains[0].getHandlers();
802: assertEquals("Some handler is missing?",
803: handlerClasses.length, handlers.length); //NOI18N
804: for (int i = 0; i < handlerClasses.length; i++) {
805: Handler h = handlers[i];
806: assertEquals(getHandlersPackage() + "."
807: + handlerClasses[i], h.getHandlerName());
808: assertEquals(getHandlersPackage() + "."
809: + handlerClasses[i], h.getHandlerClass());
810: }
811: } else {
812: ModelSource ms = Utilities.getModelSource(handlerConfigFO,
813: false);
814: BindingsModel bindingsModel = BindingsModelFactory
815: .getDefault().getModel(ms);
816: BindingsHandlerChains bChains = bindingsModel
817: .getGlobalBindings().getDefinitionsBindings()
818: .getHandlerChains();
819: Collection<BindingsHandlerChain> bHChains = bChains
820: .getHandlerChains();
821: assertEquals(1, bHChains.size());
822: Collection<BindingsHandler> bHandlers = bHChains.iterator()
823: .next().getHandlers();
824: assertEquals(handlerClasses.length, bHandlers.size());
825: int i = 0;
826: for (BindingsHandler h : bHandlers) {
827: assertEquals(getHandlersPackage() + "."
828: + handlerClasses[i], h.getHandlerClass()
829: .getClassName());
830: i++;
831: }
832: }
833: }
834: }
|