KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > test > AdminObjectResourceTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * AdminObjectResourceTest.java
21  *
22  * Created on March 14, 2006, 4:33 PM
23  *
24  * To change this template, choose Tools | Template Manager
25  * and open the template in the editor.
26  */

27
28 package org.netbeans.modules.j2ee.sun.test;
29
30 import java.io.File JavaDoc;
31 import java.util.Vector JavaDoc;
32 import org.netbeans.api.db.explorer.ConnectionManager;
33 import org.netbeans.api.db.explorer.DatabaseConnection;
34 import org.netbeans.api.project.Project;
35 import org.netbeans.junit.NbTestCase;
36 import org.netbeans.junit.NbTestSuite;
37 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
38 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
39 import org.netbeans.modules.j2ee.sun.api.ServerInterface;
40 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
41 import org.netbeans.modules.j2ee.sun.dd.api.serverresources.Resources;
42 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ResourceUtils;
43 import org.netbeans.modules.j2ee.sun.ide.sunresources.resourcesloader.SunResourceDataObject;
44 import org.netbeans.modules.j2ee.sun.ide.sunresources.wizards.ResourceConfigData;
45 import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants;
46 import org.openide.filesystems.FileObject;
47 import org.openide.filesystems.FileUtil;
48
49 /**
50  *
51  * @author Amanpreet Kaur
52  */

53 public class AdminObjectResourceTest extends NbTestCase implements WizardConstants{
54     
55     private static String JavaDoc JMS_QUEUE_RESOURCE_NAME = "jmsqResourceTest";
56     private static String JavaDoc JMS_TOPIC_RESOURCE_NAME = "jmstResourceTest";
57     
58     /** Creates a new instance of AdminObjectResourcesTest */
59     public AdminObjectResourceTest(String JavaDoc testName) {
60         super(testName);
61     }
62     
63     public void registerJMSTopicResource() {
64         try {
65             // TODO : retouche migration
66
//Project project = (Project)Util.openProject(new File(Util.EJB_PROJECT_PATH));
67
ResourceConfigData jmsdata = new ResourceConfigData();
68             ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL);
69             //JMS Resource Setting
70
jmsdata.setString(__JndiName, JMS_TOPIC_RESOURCE_NAME);
71             jmsdata.setString(__ResType, "javax.jms.Topic");
72             jmsdata.setString(__Enabled, "true");
73             jmsdata.addProperty("Name",JMS_TOPIC_RESOURCE_NAME);
74             // TODO : retouche migration
75
//jmsdata.setTargetFileObject(project.getProjectDirectory());
76
File JavaDoc fpf = File.createTempFile("falseProject","");
77             fpf.delete();
78             FileObject falseProject = FileUtil.createFolder(fpf);
79             falseProject.createFolder("setup");
80             jmsdata.setTargetFileObject(falseProject);
81             jmsdata.setTargetFile("jmstResourceTest");
82             ResourceUtils.saveJMSResourceDatatoXml(jmsdata);
83             SunResourceDataObject resourceObj = (SunResourceDataObject)SunResourceDataObject.find(falseProject.getFileObject("setup/jmstResourceTest.sun-resource"));
84             Resources res = Util.getResourcesObject(resourceObj);
85             ServerInterface mejb = ((SunDeploymentManagerInterface)inst.getDeploymentManager()).getManagement();
86             ResourceUtils.register(res.getAdminObjectResource(0), mejb, false);
87             resourceObj.delete();
88             falseProject.delete();
89             //Util.closeProject(Util.EJB_PROJECT_NAME);
90
Util.sleep(5000);
91             String JavaDoc[] jmsResource=Util.getResourcesNames("getAdminObjectResource","jndi-name",mejb);
92             for(int i=0;i<jmsResource.length;i++) {
93                 if(jmsResource[i].equals(JMS_TOPIC_RESOURCE_NAME))
94                     return;
95             }
96             throw new Exception JavaDoc("JMS Admin Object Topic Resource hasn't been created !");
97         } catch(Exception JavaDoc e) {
98             fail(e.getMessage());
99         }
100     }
101     public void registerJMSQueueResource() {
102         try {
103             // TODO : retouche migration
104
//Project project = (Project)Util.openProject(new File(Util.EJB_PROJECT_PATH));
105
ResourceConfigData jmsdata = new ResourceConfigData();
106             ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL);
107             //JMS Resource Setting
108
jmsdata.setString(__JndiName, JMS_QUEUE_RESOURCE_NAME);
109             jmsdata.setString(__ResType, "javax.jms.Queue");
110             jmsdata.setString(__Enabled, "true");
111             jmsdata.addProperty("Name",JMS_QUEUE_RESOURCE_NAME);
112             // TODO : retouche migration
113
//jmsdata.setTargetFileObject(project.getProjectDirectory());
114
File JavaDoc fpf = File.createTempFile("falseProject","");
115             fpf.delete();
116             FileObject falseProject = FileUtil.createFolder(fpf);
117             if (null == falseProject)
118                 fail("falseProject is null");
119             if (null == falseProject.createFolder("setup"))
120                 fail("falseProject/setup is null");
121             jmsdata.setTargetFileObject(falseProject);
122             jmsdata.setTargetFile("jmsqResourceTest");
123             ResourceUtils.saveJMSResourceDatatoXml(jmsdata);
124             SunResourceDataObject resourceObj = (SunResourceDataObject)SunResourceDataObject.find(falseProject.getFileObject("setup/jmsqResourceTest.sun-resource"));
125             Resources res = Util.getResourcesObject(resourceObj);
126             ServerInterface mejb = ((SunDeploymentManagerInterface)inst.getDeploymentManager()).getManagement();
127             ResourceUtils.register(res.getAdminObjectResource(0), mejb, false);
128             resourceObj.delete();
129             falseProject.delete();
130             //Util.closeProject(Util.EJB_PROJECT_NAME);
131
Util.sleep(5000);
132             String JavaDoc[] jmsResource=Util.getResourcesNames("getAdminObjectResource","jndi-name",mejb);
133             for(int i=0;i<jmsResource.length;i++) {
134                 if(jmsResource[i].equals(JMS_QUEUE_RESOURCE_NAME))
135                     return;
136             }
137             throw new Exception JavaDoc("JMS Admin Object Queue Resource hasn't been created !");
138         } catch(Exception JavaDoc e) {
139             fail(e.getMessage());
140         }
141     }
142     
143     public void unregisterJMSQueueResource() {
144         try {
145             ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL);
146             ServerInterface mejb = ((SunDeploymentManagerInterface)inst.getDeploymentManager()).getManagement();
147             String JavaDoc[] command = new String JavaDoc[] {"delete-jms-resource", "--user", "admin", JMS_QUEUE_RESOURCE_NAME};
148             Util.runAsadmin(command);
149             Util.closeProject(Util.EJB_PROJECT_NAME);
150             Util.sleep(10000);
151             String JavaDoc[] jmsResource = Util.getResourcesNames("getAdminObjectResource", "jndi-name", mejb);
152             for(int i=0;i<jmsResource.length;i++) {
153                 if(jmsResource[i].equals(JMS_QUEUE_RESOURCE_NAME))
154                     throw new Exception JavaDoc("JMS Admin Object Queue Resource hasn't been removed !");
155             }
156         } catch(Exception JavaDoc e) {
157             fail(e.getMessage());
158         }
159     }
160     public void unregisterJMSTopicResource() {
161         try {
162             ServerInstance inst = ServerRegistry.getInstance().getServerInstance(Util._URL);
163             ServerInterface mejb = ((SunDeploymentManagerInterface)inst.getDeploymentManager()).getManagement();
164             String JavaDoc[] command = new String JavaDoc[] {"delete-jms-resource", "--user", "admin", JMS_TOPIC_RESOURCE_NAME};
165             Util.runAsadmin(command);
166             Util.closeProject(Util.EJB_PROJECT_NAME);
167             Util.sleep(10000);
168             String JavaDoc[] jmsResource = Util.getResourcesNames("getAdminObjectResource", "jndi-name", mejb);
169             for(int i=0;i<jmsResource.length;i++) {
170                 if(jmsResource[i].equals(JMS_TOPIC_RESOURCE_NAME))
171                     throw new Exception JavaDoc("JMS Admin Object Topic Resource hasn't been removed !");
172             }
173         } catch(Exception JavaDoc e) {
174             fail(e.getMessage());
175         }
176     }
177     public static NbTestSuite suite() {
178         NbTestSuite suite = new NbTestSuite("JMSAdminObjectResourcesTest");
179         suite.addTest(new AddRemoveSjsasInstanceTest("addSjsasInstance"));
180         suite.addTest(new StartStopServerTest("startServer"));
181         suite.addTest(new AdminObjectResourceTest("registerJMSQueueResource"));
182         suite.addTest(new AdminObjectResourceTest("registerJMSTopicResource"));
183         suite.addTest(new AdminObjectResourceTest("unregisterJMSQueueResource"));
184         suite.addTest(new AdminObjectResourceTest("unregisterJMSTopicResource"));
185         suite.addTest(new StartStopServerTest("stopServer"));
186         suite.addTest(new AddRemoveSjsasInstanceTest("removeSjsasInstance"));
187         return suite;
188     }
189 }
190
Popular Tags