1   /*******************************************************************************
2    *  Copyright (c) 2005, 2006, 2007 Imola Informatica.
3    *  All rights reserved. This program and the accompanying materials
4    *  are made available under the terms of the LGPL License v2.1
5    *  which accompanies this distribution, and is available at
6    *  http://www.gnu.org/licenses/lgpl.html
7    *******************************************************************************/
8   package it.imolinfo.jbi4ejb.test.integration;
9   
10  import it.imolinfo.jbi4ejb.runtime.ejbproxy.StatelessEJBProxy;
11  import it.imolinfo.jbi4ejb.runtime.ejbproxy.StatelessEJBProxyFactory;
12  import it.imolinfo.jbi4ejb.test.TestUtils;
13  import it.imolinfo.jbi4ejb.webservice.generator.DynamicEJBWSDLGenerator;
14  import it.imolinfo.jbi4ejb.webservice.generator.WSDLDescriptor;
15  
16  import java.util.Properties;
17  
18  import junit.framework.TestCase;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  
23  /**
24   * The Class TestEJB.
25   */
26  public class TestEJBJNDI extends TestCase {
27  
28      /** Logger. */
29      private static final Log LOG = LogFactory.getLog(TestEJBJNDI.class);   
30      
31      /**
32       * Test user profile.
33       */
34      @SuppressWarnings("unchecked")
35      public void _testGFUserProfile() {
36          // TODO remove local dependencies ("marco")
37          testEJBJNDIRemoteInterface(
38                  "it.imolinfo.test14.complex.TestComplexSessionRemote",
39                  "/home/marco/NetBeansProjects/EJBModule14/dist/EJBModule14.jar",
40                  "ejb/TestComplexSessionBean",                
41                  "getUserProfile", new Object[] { "pippo" }, TestUtils.GLASSFISH_v2);
42      }
43  
44  
45      /**
46       * Test user profile.
47       */
48      @SuppressWarnings("unchecked")
49      public void _testIBMUserProfile() {
50          // TODO remove local dependencies ("marco")
51          testEJBJNDIRemoteInterface(
52                  "it.imolinfo.test14.complex.TestComplexSessionRemote",
53                  "/home/marco/IBM/rationalsdp7.0/workspace/TestEJBClient/TestEJBClient.jar",
54                  "ejb/TestComplexSessionBeanWS",
55                  "getUserProfile", new Object[] { "pippo" }, TestUtils.WEBSPHERE_6);
56      }
57      
58      /**
59       * Test user profile.
60       */
61      @SuppressWarnings("unchecked")
62      public void _testUserProfileJBoss() {
63          // TODO remove local dependencies ("marco")
64          testEJBJNDIRemoteInterface(
65                  "it.imolinfo.test14.complex.TestComplexSessionRemote",
66                  "/home/marco/NetBeansProjects/EJBModule14/dist/EJBModule14.jar",
67                  "ejb/TestComplexSessionBean",                   
68                  "getUserProfile", new Object[] { "pippo" }, TestUtils.JBOSS_V4);
69      }    
70  
71      /**
72       * Test EJB remote interface.
73       * 
74       * @param remoteInterfaceName
75       * @param jarPath
76       * @param corbaName
77       * @param methodName
78       * @param args
79       */
80      @SuppressWarnings("unchecked")
81      private void testEJBJNDIRemoteInterface(String remoteInterfaceName,
82              String jarPath, String jndiName, String methodName, Object[] args, String asType) {
83  
84          if (System.getProperty("localRepository") == null) {
85              fail("Set the localRepository variable to the maven repository");
86          }
87  
88          try {
89              
90           // Gets the SUIDs
91              Properties classesId = TestUtils.getClassesIdFromJar(remoteInterfaceName, jarPath);
92              
93              // Design-time. Creates the WSDL and gets the classesId from the value types, exception and return classes
94              WSDLDescriptor descriptor = new WSDLDescriptor(jndiName, "jndi");
95              descriptor.setJndiProperties(TestUtils.getJndiProperties(asType));
96              
97              // Design-time. Creates the WSDL and gets the classesId from the value types, exception and return classes
98              String wsdlFileName = DynamicEJBWSDLGenerator
99              .generateWSDLFromRemoteInterface(remoteInterfaceName,
100                     jarPath, descriptor);
101             
102             // Deploy-time: creates dinamically the ejb client classes
103             StatelessEJBProxy ejbProxy = StatelessEJBProxyFactory.getEJBFromJNDIName(wsdlFileName,
104                     remoteInterfaceName, jndiName, TestUtils.getJndiProperties(asType), TestUtils.getOrbProperties(asType),
105                     classesId, TestUtils.getJarFilesName("1.2.2"));
106             
107 
108             // Runtime: invoke the method
109             Object res = ejbProxy.invokeMethod(methodName, args);
110 
111             LOG.debug(res);
112 
113         } catch (Throwable ex) {
114             ex.printStackTrace();
115             fail(ex.getMessage());
116         }
117     }
118     
119     
120     
121 
122 
123 }