KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ConnectionFactoryResourceTest.java
21  *
22  * Created on March 23, 2006, 3:17 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 org.netbeans.junit.NbTestCase;
32 import org.netbeans.junit.NbTestSuite;
33 import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
34 import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
35 import org.netbeans.modules.j2ee.sun.api.ServerInterface;
36 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
37 import org.netbeans.modules.j2ee.sun.dd.api.serverresources.Resources;
38 import org.netbeans.modules.j2ee.sun.ide.sunresources.beans.ResourceUtils;
39 import org.netbeans.modules.j2ee.sun.ide.sunresources.resourcesloader.SunResourceDataObject;
40 import org.netbeans.modules.j2ee.sun.ide.sunresources.wizards.ResourceConfigData;
41 import org.netbeans.modules.j2ee.sun.sunresources.beans.WizardConstants;
42 import org.openide.filesystems.FileObject;
43 import org.openide.filesystems.FileUtil;
44
45 /**
46  *
47  * @author Amanpreet Kaur
48  */

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