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-2006 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: /*
042: * AdminObjectResourceTest.java
043: *
044: * Created on March 14, 2006, 4:33 PM
045: *
046: * To change this template, choose Tools | Template Manager
047: * and open the template in the editor.
048: */
049:
050: package org.netbeans.modules.j2ee.sun.test;
051:
052: import java.io.File;
053: import java.util.Vector;
054: import org.netbeans.api.db.explorer.ConnectionManager;
055: import org.netbeans.api.db.explorer.DatabaseConnection;
056: import org.netbeans.api.project.Project;
057: import org.netbeans.junit.NbTestCase;
058: import org.netbeans.junit.NbTestSuite;
059: import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
060: import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
061: import org.netbeans.modules.j2ee.sun.api.ServerInterface;
062: import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
063: import org.netbeans.modules.j2ee.sun.dd.api.serverresources.Resources;
064: import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ResourceUtils;
065: import org.netbeans.modules.j2ee.sun.ide.sunresources.wizards.ResourceConfigData;
066: import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants;
067: import org.openide.filesystems.FileObject;
068: import org.openide.filesystems.FileUtil;
069:
070: /**
071: *
072: * @author Amanpreet Kaur
073: */
074: public class AdminObjectResourceTest extends NbTestCase implements
075: WizardConstants {
076:
077: private static String JMS_QUEUE_RESOURCE_NAME = "jmsqResourceTest";
078: private static String JMS_TOPIC_RESOURCE_NAME = "jmstResourceTest";
079:
080: /** Creates a new instance of AdminObjectResourcesTest */
081: public AdminObjectResourceTest(String testName) {
082: super (testName);
083: }
084:
085: public void registerJMSTopicResource() {
086: try {
087: // TODO : retouche migration
088: //Project project = (Project)Util.openProject(new File(Util.EJB_PROJECT_PATH));
089: ResourceConfigData jmsdata = new ResourceConfigData();
090: ServerInstance inst = ServerRegistry.getInstance()
091: .getServerInstance(Util._URL);
092: //JMS Resource Setting
093: jmsdata.setString(__JndiName, JMS_TOPIC_RESOURCE_NAME);
094: jmsdata.setString(__ResType, "javax.jms.Topic");
095: jmsdata.setString(__Enabled, "true");
096: jmsdata.addProperty("Name", JMS_TOPIC_RESOURCE_NAME);
097: // TODO : retouche migration
098: //jmsdata.setTargetFileObject(project.getProjectDirectory());
099: File fpf = File.createTempFile("falseProject", "");
100: fpf.delete();
101: FileObject falseProject = FileUtil.createFolder(fpf);
102: falseProject.createFolder("setup");
103: jmsdata.setTargetFileObject(falseProject);
104: ResourceUtils.saveJMSResourceDatatoXml(jmsdata);
105: File resourceObj = FileUtil.toFile(falseProject
106: .getFileObject("sun-resources.xml"));
107: Resources res = ResourceUtils
108: .getResourcesGraph(resourceObj);
109: ServerInterface mejb = ((SunDeploymentManagerInterface) inst
110: .getDeploymentManager()).getManagement();
111: ResourceUtils.register(res.getAdminObjectResource(0), mejb,
112: false);
113: resourceObj.delete();
114: falseProject.delete();
115: //Util.closeProject(Util.EJB_PROJECT_NAME);
116: Util.sleep(5000);
117: String[] jmsResource = Util.getResourcesNames(
118: "getAdminObjectResource", "jndi-name", mejb);
119: for (int i = 0; i < jmsResource.length; i++) {
120: if (jmsResource[i].equals(JMS_TOPIC_RESOURCE_NAME))
121: return;
122: }
123: throw new Exception(
124: "JMS Admin Object Topic Resource hasn't been created !");
125: } catch (Exception e) {
126: fail(e.getMessage());
127: }
128: }
129:
130: public void registerJMSQueueResource() {
131: try {
132: // TODO : retouche migration
133: //Project project = (Project)Util.openProject(new File(Util.EJB_PROJECT_PATH));
134: ResourceConfigData jmsdata = new ResourceConfigData();
135: ServerInstance inst = ServerRegistry.getInstance()
136: .getServerInstance(Util._URL);
137: //JMS Resource Setting
138: jmsdata.setString(__JndiName, JMS_QUEUE_RESOURCE_NAME);
139: jmsdata.setString(__ResType, "javax.jms.Queue");
140: jmsdata.setString(__Enabled, "true");
141: jmsdata.addProperty("Name", JMS_QUEUE_RESOURCE_NAME);
142: // TODO : retouche migration
143: //jmsdata.setTargetFileObject(project.getProjectDirectory());
144: File fpf = File.createTempFile("falseProject", "");
145: fpf.delete();
146: FileObject falseProject = FileUtil.createFolder(fpf);
147: if (null == falseProject)
148: fail("falseProject is null");
149: if (null == falseProject.createFolder("setup"))
150: fail("falseProject/setup is null");
151: jmsdata.setTargetFileObject(falseProject);
152: ResourceUtils.saveJMSResourceDatatoXml(jmsdata);
153: File resourceObj = FileUtil.toFile(falseProject
154: .getFileObject("sun-resources.xml"));
155: Resources res = ResourceUtils
156: .getResourcesGraph(resourceObj);
157: ServerInterface mejb = ((SunDeploymentManagerInterface) inst
158: .getDeploymentManager()).getManagement();
159: ResourceUtils.register(res.getAdminObjectResource(0), mejb,
160: false);
161: resourceObj.delete();
162: falseProject.delete();
163: //Util.closeProject(Util.EJB_PROJECT_NAME);
164: Util.sleep(5000);
165: String[] jmsResource = Util.getResourcesNames(
166: "getAdminObjectResource", "jndi-name", mejb);
167: for (int i = 0; i < jmsResource.length; i++) {
168: if (jmsResource[i].equals(JMS_QUEUE_RESOURCE_NAME))
169: return;
170: }
171: throw new Exception(
172: "JMS Admin Object Queue Resource hasn't been created !");
173: } catch (Exception e) {
174: fail(e.getMessage());
175: }
176: }
177:
178: public void unregisterJMSQueueResource() {
179: try {
180: ServerInstance inst = ServerRegistry.getInstance()
181: .getServerInstance(Util._URL);
182: ServerInterface mejb = ((SunDeploymentManagerInterface) inst
183: .getDeploymentManager()).getManagement();
184: String[] command = new String[] { "delete-jms-resource",
185: "--user", "admin", JMS_QUEUE_RESOURCE_NAME };
186: Util.runAsadmin(command);
187: Util.closeProject(Util.EJB_PROJECT_NAME);
188: Util.sleep(10000);
189: String[] jmsResource = Util.getResourcesNames(
190: "getAdminObjectResource", "jndi-name", mejb);
191: for (int i = 0; i < jmsResource.length; i++) {
192: if (jmsResource[i].equals(JMS_QUEUE_RESOURCE_NAME))
193: throw new Exception(
194: "JMS Admin Object Queue Resource hasn't been removed !");
195: }
196: } catch (Exception e) {
197: fail(e.getMessage());
198: }
199: }
200:
201: public void unregisterJMSTopicResource() {
202: try {
203: ServerInstance inst = ServerRegistry.getInstance()
204: .getServerInstance(Util._URL);
205: ServerInterface mejb = ((SunDeploymentManagerInterface) inst
206: .getDeploymentManager()).getManagement();
207: String[] command = new String[] { "delete-jms-resource",
208: "--user", "admin", JMS_TOPIC_RESOURCE_NAME };
209: Util.runAsadmin(command);
210: Util.closeProject(Util.EJB_PROJECT_NAME);
211: Util.sleep(10000);
212: String[] jmsResource = Util.getResourcesNames(
213: "getAdminObjectResource", "jndi-name", mejb);
214: for (int i = 0; i < jmsResource.length; i++) {
215: if (jmsResource[i].equals(JMS_TOPIC_RESOURCE_NAME))
216: throw new Exception(
217: "JMS Admin Object Topic Resource hasn't been removed !");
218: }
219: } catch (Exception e) {
220: fail(e.getMessage());
221: }
222: }
223:
224: public static NbTestSuite suite() {
225: NbTestSuite suite = new NbTestSuite(
226: "JMSAdminObjectResourcesTest");
227: suite
228: .addTest(new AddRemoveSjsasInstanceTest(
229: "addSjsasInstance"));
230: suite.addTest(new StartStopServerTest("startServer"));
231: suite.addTest(new AdminObjectResourceTest(
232: "registerJMSQueueResource"));
233: suite.addTest(new AdminObjectResourceTest(
234: "registerJMSTopicResource"));
235: suite.addTest(new AdminObjectResourceTest(
236: "unregisterJMSQueueResource"));
237: suite.addTest(new AdminObjectResourceTest(
238: "unregisterJMSTopicResource"));
239: suite.addTest(new StartStopServerTest("stopServer"));
240: suite.addTest(new AddRemoveSjsasInstanceTest(
241: "removeSjsasInstance"));
242: return suite;
243: }
244: }
|