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: * If you wish your version of this file to be governed by only the CDDL
025: * or only the GPL Version 2, indicate your decision by adding
026: * "[Contributor] elects to include this software in this distribution
027: * under the [CDDL or GPL Version 2] license." If you do not indicate a
028: * single choice of license, a recipient has the option to distribute
029: * your version of this file under either the CDDL, the GPL Version 2 or
030: * to extend the choice of license to its licensees as provided above.
031: * However, if you add GPL Version 2 code and therefore, elected the GPL
032: * Version 2 license, then the option applies only if the new code is
033: * made subject to such option by the copyright holder.
034: *
035: * Contributor(s):
036: *
037: * Portions Copyrighted 2008 Sun Microsystems, Inc.
038: *
039: */
040: package org.netbeans.modules.identity.qaf;
041:
042: import java.io.File;
043: import java.io.IOException;
044: import junit.textui.TestRunner;
045: import org.netbeans.jellytools.Bundle;
046: import org.netbeans.jellytools.NbDialogOperator;
047: import org.netbeans.jellytools.ProjectsTabOperator;
048: import org.netbeans.jellytools.nodes.Node;
049: import org.netbeans.junit.NbTestSuite;
050: import org.netbeans.jemmy.EventTool;
051: import org.netbeans.jellytools.modules.j2ee.nodes.J2eeServerNode;
052: import org.netbeans.jellytools.nodes.ProjectRootNode;
053: import org.netbeans.jellytools.OutputTabOperator;
054: import org.netbeans.jemmy.JemmyProperties;
055: import org.netbeans.jemmy.operators.JCheckBoxOperator;
056: import org.netbeans.jemmy.operators.JComboBoxOperator;
057: import org.netbeans.jemmy.operators.JTreeOperator;
058: import org.netbeans.jellytools.NewFileNameLocationStepOperator;
059: import org.netbeans.jellytools.EditorOperator;
060: import org.netbeans.jellytools.actions.ActionNoBlock;
061: import org.netbeans.jemmy.TimeoutExpiredException;
062: import org.netbeans.modules.ws.qaf.EjbWsValidation;
063:
064: /**
065: *
066: * @author jp154641
067: */
068: public class IdentityValidationInEJB extends EjbWsValidation {
069:
070: /**
071: * Initialization of suite properties
072: */
073: public static String SERVER_PATH;
074: public static File PROJECTS_FOLDER_FILE;
075: public static File WSP_PROJECT_FILE;
076: public static File WSC_PROJECT_FILE;
077:
078: @Override
079: protected ProjectType getProjectType() {
080: return ProjectType.EJB;
081: }
082:
083: @Override
084: protected String getWsProjectName() {
085: return "TestIdentityWSEJB"; //NOI18N
086: }
087:
088: @Override
089: protected String getWsClientProjectName() {
090: return "TestIdentityWSCEJB"; //NOI18N
091: }
092:
093: @Override
094: protected String getWsName() {
095: return "TestEJBWS"; //NOI18N
096: }
097:
098: @Override
099: protected String getWsPackage() {
100: return "org.identity.ejbws.test"; //NOI18N
101: }
102:
103: @Override
104: protected String getWsClientPackage() {
105: return "org.identity.ejbwsc.test"; //NOI18N
106: }
107:
108: /** Creates a new instance of IdentityValidation */
109: public IdentityValidationInEJB(String name) {
110: super (name);
111: }
112:
113: /**
114: * This method creates test web project with web service and two
115: * operations, then deploys it.
116: * @throws java.io.IOException
117: */
118: public void prepareWSProject() throws IOException {
119: testCreateNewWs();
120: testAddOperation();
121: testDeployWsProject();
122: }
123:
124: /**
125: * This method creates web module and web service client to previously
126: * deployed web service. The word Client in name ot the suite method
127: * is essential for correct working of this method!
128: * @throws java.io.IOException
129: */
130: public void prepareWSClientProject() throws IOException {
131: testCreateWsClient();
132: testCallWsOperationInSessionEJB();
133: testDeployWsClientProject();
134: }
135:
136: /**
137: * Test of AM security in ejb project
138: * - both ws provider and client
139: * - sets AM security in WS provider, deploys WS and then sets AM security in WSC and deploys it
140: */
141: public void testAMSecurityInEJB() {
142: System.out.println("######## TestCase: " + getName()
143: + " #######"); //NOI18N
144: secureWSinEJBModule();
145: secureWSCinEJBModule();
146: }
147:
148: /**
149: * Setting AM security for WS provider in ejb module
150: */
151: public void secureWSinEJBModule() {
152: ProjectsTabOperator prj = new ProjectsTabOperator();
153: JTreeOperator prjtree = new JTreeOperator(prj);
154: ProjectRootNode prjnd = new ProjectRootNode(prjtree,
155: getWsProjectName());
156: Node websvc = new Node(prjnd, "Web Services|TestEJBWS"); //NOI18N
157: websvc
158: .performPopupActionNoBlock(org.netbeans.jellytools.Bundle
159: .getStringTrimmed(
160: "org.netbeans.modules.websvc.customization.core.ui.Bundle",
161: "CTL_EditAttributesAction")); //NOI18N
162: NbDialogOperator dialog = new NbDialogOperator("TestEJBWS"); //NOI18N
163: JCheckBoxOperator activate = new JCheckBoxOperator(dialog, 0);
164: activate.push();
165: JComboBoxOperator profiles = new JComboBoxOperator(dialog, 0);
166: profiles.selectItem("SAML-HolderOfKey"); //NOI18N
167: new EventTool().waitNoEvent(1000);
168: dialog.ok();
169: prjnd.performPopupActionNoBlock("Undeploy and Deploy"); //NOI18N
170: OutputTabOperator oto = new OutputTabOperator(
171: getWsProjectName());
172: JemmyProperties.setCurrentTimeout(
173: "ComponentOperator.WaitStateTimeout", 120000); //NOI18N
174: oto.waitText("(total time: "); //NOI18N
175: assertTrue(oto.getText().indexOf("BUILD SUCCESSFUL") > -1); //NOI18N
176: }
177:
178: /**
179: * Setting AM security for WS client in ejb module
180: */
181: public void secureWSCinEJBModule() {
182: ProjectsTabOperator prj = new ProjectsTabOperator();
183: JTreeOperator prjtree = new JTreeOperator(prj);
184: ProjectRootNode prjnd = new ProjectRootNode(prjtree,
185: getWsClientProjectName());
186: Node websvc = new Node(prjnd,
187: "Web Service References|TestEJBWS"); //NOI18N
188: new EventTool().waitNoEvent(10000);
189: websvc
190: .performPopupActionNoBlock(org.netbeans.jellytools.Bundle
191: .getStringTrimmed(
192: "org.netbeans.modules.websvc.core.jaxws.actions.Bundle",
193: "LBL_RefreshClientAction")); //NOI18N
194: NbDialogOperator ccr = new NbDialogOperator(
195: "Confirm Client Refresh"); //NOI18N
196: ccr.yes();
197: new EventTool().waitNoEvent(10000);
198: websvc
199: .performPopupActionNoBlock(org.netbeans.jellytools.Bundle
200: .getStringTrimmed(
201: "org.netbeans.modules.websvc.customization.core.ui.Bundle",
202: "CTL_EditAttributesAction")); //NOI18N
203: NbDialogOperator dialog = new NbDialogOperator("TestEJBWS"); //NOI18N
204: JCheckBoxOperator activate = new JCheckBoxOperator(
205: dialog,
206: org.netbeans.jellytools.Bundle
207: .getStringTrimmed(
208: "org.netbeans.modules.identity.profile.ui.Bundle",
209: "LBL_EnableSecurity")); //NOI18N
210: activate.push();
211: JComboBoxOperator profiles = new JComboBoxOperator(dialog, 0);
212: profiles.selectItem("SAML-HolderOfKey"); //NOI18N
213: new EventTool().waitNoEvent(1000);
214: dialog.ok();
215: prjnd.performPopupActionNoBlock("Undeploy and Deploy"); //NOI18N
216: OutputTabOperator oto = new OutputTabOperator(
217: getWsClientProjectName());
218: JemmyProperties.setCurrentTimeout(
219: "ComponentOperator.WaitStateTimeout", 120000); //NOI18N
220: oto.waitText("(total time: "); //NOI18N
221: assertTrue(oto.getText().indexOf("BUILD SUCCESSFUL") > -1); //NOI18N
222: }
223:
224: /**
225: * Tests Call Web Service Operation action in a servlet
226: */
227: public void testCallWsOperationInSessionEJB() {
228: //create a session bean
229: String ejbName = "NewSession";
230: //Enterprise
231: String enterpriseLabel = Bundle.getStringTrimmed(
232: "org.netbeans.modules.j2ee.ejbcore.resources.Bundle",
233: "Templates/J2EE");
234: //Session Bean
235: String sessionBeanLabel = Bundle
236: .getStringTrimmed(
237: "org.netbeans.modules.j2ee.ejbcore.ejb.wizard.session.Bundle",
238: "Templates/J2EE/Session");
239: createNewFile(getWsClientProject(), enterpriseLabel,
240: sessionBeanLabel);
241: NewFileNameLocationStepOperator op = new NewFileNameLocationStepOperator();
242: op.txtObjectName().clearText();
243: op.txtObjectName().typeText(ejbName);
244: op.cboPackage().clearText();
245: op.cboPackage().typeText("org.mycompany.ejbs"); //NOI18N
246: op.finish();
247: new org.netbeans.jemmy.EventTool().waitNoEvent(2000); //Temporary hack preventing occurence of issue
248: //Add business method
249: final EditorOperator eo = new EditorOperator(ejbName); //NOI18N
250: addBusinessMethod(eo, "myBm", "String"); //NOI18N
251: //edit code in the EJB
252: // add new line and select it
253: eo.setCaretPosition("myBm() {", false); //NOI18N
254: eo.insert("\n//xxx"); //NOI18N
255: eo.select("//xxx"); //NOI18N
256: callWsOperation(eo, "myIntMethod", 16); //NOI18N
257: eo.close(true);
258: }
259:
260: protected void addBusinessMethod(EditorOperator eo, String mName,
261: String mRetVal) {
262: //EJB Methods
263: String actionGroupName = Bundle
264: .getStringTrimmed(
265: "org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle",
266: "LBL_EJBActionGroup");
267: //Add Business Method...
268: String actionName = Bundle
269: .getStringTrimmed(
270: "org.netbeans.modules.j2ee.ejbcore.ui.logicalview.ejb.action.Bundle",
271: "LBL_AddBusinessMethodAction");
272: try {
273: Thread.sleep(1000);
274: } catch (InterruptedException ie) {
275: }
276: try {
277: new ActionNoBlock(null, actionGroupName + "|" + actionName)
278: .performPopup(eo);
279: } catch (TimeoutExpiredException tee) {
280: eo.select(16);
281: new ActionNoBlock(null, actionGroupName + "|" + actionName)
282: .performPopup(eo);
283: }
284: addMethod(eo, actionName, mName, mRetVal);
285: }
286: }
|