Skip to main content

[SOLVED] How to add automated testing to client application runned from acc

3 replies [Last post]
anaq
Offline
Joined: 2006-04-04

Dear all,
I want to add automated testing to my swing client, but I have some troubles. I'm using fest 1.2 framework for swing testing, but I don't know how to run my application from the code. I can run the main method, but I'm using dependency injection @EJB to call sessionbeans and these are not setted, when the client is runned from the test file.
My project is an enterprise application with a ejb module and a swing application client.
My env: java 1.6.24, netbeans 7, gf 3.1, windows 7

Thank you

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
tjquinn
Offline
Joined: 2005-03-30

First, make sure your injection works correction when you run without your test framework using the appclient command.
Next, when using your test framework you need to give the ACC a chance to actually do the injection. Just invoking your main class main method is not sufficient because you have given the ACC no opportunity to prepare the client for execution.
One way to do this is to use the embedded ACC API, documented here: http://download.oracle.com/docs/cd/E18930_01/html/821-2418/beakv.html#gipkt
You could write a new, small main program that uses the embedded ACC API to launch your app client. The API basically lets you specify from a program everything you would normally specify on the appclient command. Then you could tell the test framework to run this new, small main program rather than your app client's main class.
- Tim

anaq
Offline
Joined: 2006-04-04

Thank you for reply.
I can run my client application using appclient command without problems.
I' ve tried two ways, how to initialize the session connection from client:
1. For testing, manual set the field, which is normally injected. This works, when I run the application normal way, but not from the testing framework. Code:

<br />
Properties jndiProps = new Properties();<br />
jndiProps.put("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");<br />
jndiProps.put("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");<br />
jndiProps.put("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");<br />
jndiProps.setProperty("org.omg.CORBA.ORBInitialHost", "127.0.0.1");<br />
jndiProps.setProperty("org.omg.CORBA.ORBInitialPort", "3700");<br />
try {<br />
   Context ctx = new InitialContext(jndiProps);<br />
   homeSessionBean = (HomeSessionBeanRemote)ctx.lookup("com.xxx.yyy.HomeSessionBeanRemote");<br />
} catch (Exception e) {<br />
     e.printStackTrace();<br />
}<br />

2. Using embedded acc api. My code:
<br />
public static void main(String args[]) {<br />
        TargetServer[] servers = new TargetServer[]{new TargetServer("localhost", 3700)};<br />
        AppClientContainer.Builder builder = AppClientContainer.newBuilder(servers);<br />
        try {<br />
            URI clientURI = new URI("file:///c://...//TestClient.jar");<br />
            AppClientContainer acc = builder.newContainer(clientURI);  // also tried with the main class<br />
            acc.prepare(null);<br />
            acc.startClient(new String[0]);<br />
        } catch (Exception ex) {<br />
            Logger.getLogger(ClientApplication.class.getName()).log(Level.SEVERE, null, ex);<br />
        } catch (UserError ex) {<br />
            Logger.getLogger(ClientApplication.class.getName()).log(Level.SEVERE, null, ex);<br />
        }<br />
}<br />

Both of these methods throw very similar exception (error):
<br />
Caused  by: java.lang.LinkageError: injection failed on class  org.glassfish.appclient.client.acc.ACCAppClientArchivist from  sun.misc.Launcher$AppClassLoader@1a16869<br />
    at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:254)<br />
...<br />
Caused  by: java.lang.LinkageError: injection failed on class  com.sun.enterprise.deployment.annotation.factory.SJSASFactory from  sun.misc.Launcher$AppClassLoader@1a16869<br />
    at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:254)<br />
...<br />
Caused  by: java.lang.LinkageError: injection failed on class  org.glassfish.ejb.deployment.annotation.handlers.TransactionAttributeHandler  from sun.misc.Launcher$AppClassLoader@1a16869<br />
    at org.jvnet.hk2.component.InjectionManager.inject(InjectionManager.java:254)<br />
...<br />
Caused  by: java.lang.ClassFormatError: Absent Code attribute in method that is  not native or abstract in class file javax/ejb/TransactionAttributeType<br />
    at java.lang.ClassLoader.defineClass1(Native Method)<br />
 

I've found, that this can involve a problem with javaee library, so I've played with the libraries, but without success...
Code from test file is simple:
<br />
@Before<br />
public void setUp() {<br />
     org.fest.swing.launcher.ApplicationLauncher.application(TestClientApplication.class).start();<br />
}<br />

I've created another application, which uses embedded acc api to run my client and this works, so it doesn't work only for the testing framework...
Any idea?
Thank you very much

anaq
Offline
Joined: 2006-04-04

I have found a solution - Marathon. It is blackbox testing, but it works as expected without problems. Anyway thank you for your time.

Michael