KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > foedeployer > test > M2MBConversionTestCase


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.foedeployer.test;
8
9 import java.io.IOException JavaDoc;
10 import java.net.InetAddress JavaDoc;
11 import java.rmi.RemoteException JavaDoc;
12 import java.util.Set JavaDoc;
13 import java.util.Collection JavaDoc;
14 import javax.ejb.CreateException JavaDoc;
15 import javax.ejb.Handle JavaDoc;
16 import javax.management.ObjectName JavaDoc;
17 import javax.naming.InitialContext JavaDoc;
18 import javax.naming.NamingException JavaDoc;
19 import javax.rmi.PortableRemoteObject JavaDoc;
20
21 import junit.extensions.TestSetup;
22 import junit.framework.Test;
23 import junit.framework.TestCase;
24 import junit.framework.TestSuite;
25
26 import org.jboss.test.JBossTestCase;
27 import org.jboss.test.JBossTestSetup;
28
29 import org.jboss.test.foedeployer.ejb.m2mb.M2MBManager;
30 import org.jboss.test.foedeployer.ejb.m2mb.M2MBManagerHome;
31
32 /**
33  * Test of relationships conversion
34  *
35  * @author <a HREF="mailto:aloubyansky@hotmail.com">Alex Loubyansky</a>
36  * @version $Revision: 1.2 $
37  */

38 public class M2MBConversionTestCase
39    extends JBossTestCase
40 {
41    // Constants -----------------------------------------------------
42
public static final String JavaDoc FOE_DEPLOYER = "foe-deployer-3.2.sar";
43    public static final String JavaDoc FOE_DEPLOYER_NAME = "jboss:service=FoeDeployer";
44    public static final String JavaDoc CONVERTOR_DEPLOYER_QUERY_NAME = "jboss:service=Convertor,*";
45    public static final String JavaDoc APPLICATION = "foe-deployer-m2mb-test";
46    public static final String JavaDoc MANAGER_SESSION_JNDI_NAME = "M2MBManagerEJB.M2MBManagerHome";
47
48    // Static --------------------------------------------------------
49
/**
50     * Setup the test suite.
51     */

52    public static Test suite() throws Exception JavaDoc
53    {
54       TestSuite suite = new TestSuite();
55       suite.addTest( new TestSuite( M2MBConversionTestCase.class ) );
56
57       // Create an initializer for the test suite
58
TestSetup wrapper = new JBossTestSetup( suite )
59       {
60          protected void setUp() throws Exception JavaDoc
61          {
62             super.setUp();
63          }
64          protected void tearDown() throws Exception JavaDoc
65          {
66             super.tearDown();
67          }
68       };
69       return wrapper;
70    }
71
72    // Constructors --------------------------------------------------
73
public M2MBConversionTestCase( String JavaDoc name )
74    {
75       super( name );
76    }
77
78    // Public --------------------------------------------------------
79
/**
80     * Test a simple conversion
81     **/

82    public void testSimpleConversion()
83       throws Exception JavaDoc
84    {
85       try
86       {
87          log.debug( "+++ testM2MBConversion" );
88
89          // First check if foe-deployer is deployed
90
boolean isInitiallyDeployed = getServer().isRegistered( new ObjectName JavaDoc( FOE_DEPLOYER_NAME ) );
91          if( !isInitiallyDeployed ) deploy(FOE_DEPLOYER);
92
93          boolean isDeployed = getServer().isRegistered(new ObjectName JavaDoc(FOE_DEPLOYER_NAME));
94          assertTrue("Foe-Deployer is not deployed", isDeployed);
95
96          // Count number of convertors (must be a list one)
97
int count = getServer().queryNames(new ObjectName JavaDoc(CONVERTOR_DEPLOYER_QUERY_NAME), null).size();
98          assertTrue("No Convertor found on web server", count > 0);
99
100          // Deploy the simple application
101
deploy(APPLICATION + ".wlar");
102
103          // Because the Foe-Deployer copies the converted JAR back to the original place
104
// it has to be deployed from here again
105
deploy(APPLICATION + ".jar");
106
107          // Access the Session Bean and invoke some methods on it
108
int i;
109          String JavaDoc[] projects = {"JBoss", "Xdoclet", "WebWork"};
110          String JavaDoc[] developers = {"Ivanov", "Petrov", "Sidorov"};
111
112          M2MBManager manager = getM2MBManager();
113
114          log.debug( "cleaning the database" );
115          i = 0;
116          while( i < projects.length)
117             manager.removeProjectIfExists( projects[i++] );
118          i = 0;
119          while( i < developers.length)
120             manager.removeDeveloperIfExists( developers[i++] );
121
122          // create all projects
123
i = 0;
124          while( i < projects.length )
125          {
126             log.debug("creating project: " + projects[i] );
127             manager.createProject( projects[i++] );
128          }
129
130          // create all developers
131
i = 0;
132          while( i < developers.length )
133          {
134             log.debug("creating developer: " + developers[i] );
135             manager.createDeveloper( developers[i++] );
136          }
137
138          // adding projects except the last one to developer 0
139
i = 0;
140          while( i < projects.length - 1 )
141          {
142             log.debug("adding project " + projects[i]
143                + " to developer " + developers[0]);
144             manager.addProjectToDeveloper(developers[0], projects[i++]);
145          }
146
147          log.debug("developer " + developers[0] + " have projects: "
148             + manager.getProjectsForDeveloper(developers[0]) );
149
150          // adding developer 0 to the last project
151
log.debug("adding developer " + developers[0]
152                + " to project " + projects[ projects.length - 1 ]);
153          manager.addDeveloperToProject(projects[ projects.length-1 ], developers[0]);
154
155          // check whether the developer have all the projects
156
Collection JavaDoc prjs = manager.getProjectsForDeveloper(developers[0]);
157          log.debug("developer " + developers[0] + " have projects: " + prjs);
158          for( i=0; i < projects.length; ++i )
159          {
160             assertTrue( "Developer '" + developers[0]
161                + "' doesn't have project '" + projects[i] + "'",
162                prjs.contains(projects[i]) );
163          }
164
165          // Undeploy converted application to clean up
166
undeploy(APPLICATION + ".jar");
167          // undeploy wlar (though it should work without it)
168
undeploy(APPLICATION + ".wlar");
169
170          // Only undeploy if deployed here
171
if(!isInitiallyDeployed) undeploy( FOE_DEPLOYER );
172       }
173       catch(Exception JavaDoc e)
174       {
175          e.printStackTrace();
176          throw e;
177       }
178    }
179
180    // Private -------------------------------------------------------
181
private M2MBManager getM2MBManager()
182       throws Exception JavaDoc
183    {
184       log.debug("looking for M2MBManager");
185       Object JavaDoc ref = getInitialContext().lookup( MANAGER_SESSION_JNDI_NAME );
186       M2MBManagerHome home = (M2MBManagerHome) PortableRemoteObject.narrow(
187          ref, M2MBManagerHome.class );
188       return home.create();
189    }
190 }
191
Popular Tags