KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.ejb.CreateException JavaDoc;
14 import javax.ejb.Handle JavaDoc;
15 import javax.management.ObjectName JavaDoc;
16 import javax.naming.InitialContext JavaDoc;
17 import javax.naming.NamingException JavaDoc;
18 import javax.rmi.PortableRemoteObject JavaDoc;
19
20 import junit.extensions.TestSetup;
21 import junit.framework.Test;
22 import junit.framework.TestCase;
23 import junit.framework.TestSuite;
24
25 import org.jboss.test.JBossTestCase;
26 import org.jboss.test.JBossTestSetup;
27
28 import org.jboss.test.foedeployer.ejb.simple.SecretManager;
29 import org.jboss.test.foedeployer.ejb.simple.SecretManagerHome;
30
31 /**
32  * Test of a simple WebLogic Application Conversion
33  *
34  * @author <a HREF="mailto:andreas@jboss.org">Andreas Schaefer</a>.
35  * @author <a HREF="mailto:loubyansky@hotmail.com">Alex Loubyansky</a>
36  * @version $Revision: 1.6 $
37  */

38 public class SimpleConversionTestCase
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 SIMPLE_APPLICATION = "foe-deployer-simple-test";
46    public static final String JavaDoc SECRET_SESSION_JNDI_NAME = "ejb/SecretManager";
47
48    // Static --------------------------------------------------------
49
/**
50     * Setup the test suite.
51     */

52    public static Test suite() throws Exception JavaDoc
53    {
54       TestSuite lSuite = new TestSuite();
55       lSuite.addTest( new TestSuite( SimpleConversionTestCase.class ) );
56
57       // Create an initializer for the test suite
58
TestSetup lWrapper = new JBossTestSetup( lSuite )
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 lWrapper;
70    }
71
72    // Constructors --------------------------------------------------
73
public SimpleConversionTestCase( String JavaDoc pName )
74    {
75       super( pName );
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("+++ testSimpleConversion");
88
89          // First check if foe-deployer is deployed
90
boolean lIsInitiallyDeployed = getServer().isRegistered( new ObjectName JavaDoc( FOE_DEPLOYER_NAME ) );
91          if(!lIsInitiallyDeployed)
92             deploy(FOE_DEPLOYER);
93
94          boolean lIsDeployed = getServer().isRegistered(new ObjectName JavaDoc(FOE_DEPLOYER_NAME));
95          assertTrue("Foe-Deployer is not deployed", lIsDeployed);
96
97          // Count number of convertors (must be a list one)
98
int lCount = getServer().queryNames(new ObjectName JavaDoc(CONVERTOR_DEPLOYER_QUERY_NAME), null).size();
99          assertTrue("No Convertor found on web server", lCount > 0);
100
101          // Deploy the simple application
102
deploy(SIMPLE_APPLICATION + ".wlar");
103
104          // Because the Foe-Deployer copies the converted JAR back to the original place
105
// it has to be deployed from here again
106
deploy(SIMPLE_APPLICATION + ".jar");
107
108          // Access the Session Bean and invoke some methods on it
109
SecretManager session = getSecretManagerEJB();
110          String JavaDoc key = "xxx";
111          String JavaDoc secret = "the sun is shining brightly";
112
113          session.createSecret( key, secret );
114          assertTrue( "the secret read is not equal to secret set", secret.equals(session.getSecret(key)) );
115          session.removeSecret(key);
116
117          // Undeploy converted application to clean up
118
undeploy(SIMPLE_APPLICATION + ".jar");
119          // undeploy wlar (though it should work without it)
120
undeploy(SIMPLE_APPLICATION + ".wlar");
121
122          // Only undeploy if deployed here
123
if(!lIsInitiallyDeployed)
124             undeploy(FOE_DEPLOYER);
125       }
126       catch(Exception JavaDoc e)
127       {
128          e.printStackTrace();
129          throw e;
130       }
131    }
132
133    // Private -------------------------------------------------------
134
private SecretManager getSecretManagerEJB()
135       throws Exception JavaDoc
136    {
137       log.debug("+++ getSecretManagerEJB()");
138       Object JavaDoc lObject = getInitialContext().lookup( SECRET_SESSION_JNDI_NAME );
139       SecretManagerHome lHome = (SecretManagerHome) PortableRemoteObject.narrow(
140          lObject,
141          SecretManagerHome.class
142       );
143       log.debug( "Found SecretManagerBean" );
144       return lHome.create();
145    }
146 }
147
Popular Tags