I've got 2 problems:
1) For some reason, I only reach the first problem when running the Eclipse plugin.
I'm using (trying) the JBoss embeddable EJB3.0 library to access my EJBs. When I call the following code I get a PersistenceException saying "No Persistence provider for EntityManager named "myproject".
EntityManagerFactory emf = Persistence.createEntityManagerFactory("myproject");
...I can't figure out what I need to do to get it to pick up all of my config files for the EJB project (persistence.xml and perhaps hibernate.propeties?).
The main motivation for me to get proactive about testing is that I'm using custom spatial extensions for MySQL, so for the testing to be effective, it really needs to be using an identical config to the actual web app.
---------
2) When I run TestNG from build.xml it skips my @BeforeXxxx methods (I've tried @BeforeGroups(groups = {"persistence"}) and @BeforeSuite(groups = {"persistence"})
Here's my testng.xml:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="myProject" verbose="1" parallel="tests" thread-count="5">
<test name="persistence">
<classes>
<class name="com.myproject.ClassA"/>
<class name="com.myproject.ClassB"/>
<class name="com.myproject.ClassC"/>
</classes>
</test>
</suite>
Here's my build.xml:
<project name="myProject" default="test" basedir="..">
<property name="script.dir" location="${basedir}/scripts"/>
<property name="src.dir" location="${basedir}/classes"/>
<property name="build.dir" location="${basedir}/classes"/>
<property name="sw.java.dir" location="C:\sw_dev\java"/>
<property name="jboss.dir" location="${sw.java.dir}/jboss-4.0.5.GA"/>
<path id="cp">
<pathelement location="${sw.java.dir}\j2ee\lib\testng\testng-5.1-jdk15.jar"/>
<pathelement location="${sw.java.dir}\openmap-4.6.3\jts\lib\jts-1.9.jar"/>
<pathelement location="${sw.java.dir}\jboss-embeddable\conf"/>
<fileset dir="${sw.java.dir}\jboss-embeddable\lib">
<include name="*.jar"/>
</fileset>
<fileset dir="${src.dir}">
<include name="META-INF/persistence.xml"/>
</fileset>
<pathelement location="${build.dir}"/>
</path>
<taskdef name="testng" classpathref="cp"
classname="org.testng.TestNGAntTask" />
<target name="test">
<testng classpathref="cp" verbose="2">
<classfileset dir="${build.dir}" includes="com.myproject/*.class"/>
<xmlfileset dir="${script.dir}" includes="testng.xml" />
</testng>
</target>
</project>
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=80954&messageID=146363#146363
2. I've had better experiences running EJB with the oracle toplink JAR
embedded than with JBoss. Maybe it has improved, but the list of JARs
needed to maybe get it working was pretty steep a year ago.
>
> 1. you are better running your tests in the app server, if you can
> come up with a way. There have been discussions on this list in the
> past on this topic.
>
> 2. I've had better experiences running EJB with the oracle toplink JAR
> embedded than with JBoss. Maybe it has improved, but the list of JARs
> needed to maybe get it working was pretty steep a year ago.
>
Much easier and lighter is to use pitchfork with spring, 90mb vs 3mb!
I've had to modify the Factory, but it's still not working:
public class BeanRunnerFactory {
@Factory
public IInstanceInfo[] createObjectsWithInstanceInfo() {
IInstanceInfo[] instances = null;
try {
Properties properties = new Properties();
properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs","=org.jboss.naming:org.jnp.interfaces");
properties.put("java.naming.provider.url","localhost:1099");
InitialContext ctx = new InitialContext(properties);
// InitialContext ctx = new InitialContext();
// List the test classes to be executed
Class[] testClasses = new Class[] { ServiceProviderTestLocal.class,
StationTestLocal.class,
RouteTestLocal.class };
int i = testClasses.length;
instances = new IInstanceInfo[i];
while( i-- != 0 ) {
Class clazz = testClasses[i];
String className = clazz.getName();
className = className.substring(className.lastIndexOf('.') + 1)
.replaceAll("Local", "/local");
Object test = ctx.lookup(className);
instances[i] = new BeanInstanceInfo(test, clazz);
}
} catch (Exception e) {
System.err.println("Error connecting to remote tests: " + e.getMessage());
}
return instances;
}
}
here's the exception message I get:
java.lang.NullPointerException
at org.jboss.ejb3.stateless.StatelessLocalProxy.toString(StatelessLocalProxy.java:114)
at org.jboss.ejb3.ProxyUtils.handleCallLocally(ProxyUtils.java:152)
at org.jboss.ejb3.ProxyUtils.handleCallLocally(ProxyUtils.java:137)
at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:68)
at $Proxy6.hashCode(Unknown Source)
at org.testng.internal.ClassImpl.getInstances(ClassImpl.java:90)
at org.testng.TestClass.getInstances(TestClass.java:94)
at org.testng.TestClass.initTestClassesAndInstances(TestClass.java:82)
at org.testng.TestClass.init(TestClass.java:75)
at org.testng.TestClass.<init>(TestClass.java:43)
at org.testng.TestRunner.initMethods(TestRunner.java:268)
at org.testng.TestRunner.init(TestRunner.java:198)
at org.testng.TestRunner.init(TestRunner.java:168)
at org.testng.TestRunner.<init>(TestRunner.java:135)
at org.testng.remote.RemoteTestNG$1.newTestRunner(RemoteTestNG.java:102)
at org.testng.remote.RemoteTestNG$DelegatingTestRunnerFactory.newTestRunner(RemoteTestNG.java:152)
at org.testng.SuiteRunner$ProxyTestRunnerFactory.newTestRunner(SuiteRunner.java:457)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:212)
at org.testng.SuiteRunner.run(SuiteRunner.java:168)
at org.testng.TestNG.createAndRunSuiteRunners(TestNG.java:987)
at org.testng.TestNG.runSuitesLocally(TestNG.java:951)
at org.testng.TestNG.run(TestNG.java:719)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:73)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:122)
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=80954&messageID=146531#146531
What is your toString() method doing? Because the NPE occurs in that
method, I don't think TestNG is directly responsible for that.
./alex
--
.w( the_mindstorm )p.
TestNG co-founder
EclipseTestNG Creator
package com.mojoplanner.server.provider.ejb;
import javax.ejb.Stateless;
import javax.persistence.*;
import org.testng.annotations.Test;
import com.mojoplanner.server.provider.interfaces.IStationTest;
@Stateless
public class StationTest implements IStationTest
{
@PersistenceContext private static EntityManager em;
@Test(groups = {"persistence"})
public void testGeometry() {
System.out.println("hello");
}
}
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=80954&messageID=146545#146545
java.lang.NullPointerException
at org.jboss.ejb3.stateless.StatelessLocalProxy.toString(StatelessLocalProxy.java:114)
at org.jboss.ejb3.ProxyUtils.handleCallLocally(ProxyUtils.java:152)
at org.jboss.ejb3.ProxyUtils.handleCallLocally(ProxyUtils.java:137)
at org.jboss.ejb3.stateless.StatelessLocalProxy.invoke(StatelessLocalProxy.java:68)
at $Proxy6.hashCode(Unknown Source)
It's the toString of the proxy object that EJB creates for you that is
failing. I have no idea what is going on, and have no intention of
finding out. As I said before: get your tests running in the server;
do not waste time getting EJB3 embedded to work, as it is just a
distraction. Even if you do get the tests working, there is no
guarantee that it will work in the server, with its different
classloaders, database binding, transactions, ....
Yes, there must be something wrong with the way my test app connects to the container.
> As I said before: get your tests running in the server;
> do not waste time getting EJB3 embedded to work, as
> it is just a distraction.
Yes, that's what I'm trying to do.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=80954&messageID=146561#146561
there's clearly something going wrong with JBoss's client code.
Although OSS gives you the right to edit the apps source, its always a
shame when a product forces you to edit it to get it working.
-steve
Well, I am not sure this is a bug in JBoss... I mean I wouldn't say
this without a good proof. There may be a lot of other options before
saying that JBoss code is buggy: your code bug, a limitation of the
embedded environment, etc. Oh... and I guess everybody knows I am not
associated with JBoss; I just want to keep things clear and fair :-).
./alex
--
.w( the_mindstorm )p.
TestNG co-founder
EclipseTestNG Creator
> -steve
>
> >
>
...So I should go back to the servlet approach? So far I've sketched out this SLSB, but I'm not sure on the best way to report the results.
------------------
package com.mojoplanner.server.web.ejb;
import java.util.ArrayList;
import java.util.Date;
import javax.annotation.Resource;
import javax.ejb.SessionContext;
import javax.ejb.Stateless;
import javax.ejb.Timeout;
import javax.ejb.Timer;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.testng.TestNG;
import org.testng.annotations.BeforeSuite;
import com.mojoplanner.server.web.interfaces.ITest;
import com.mojoplanner.server.web.interfaces.TestRemote;
/**
* SLSB to perform automated tests on the EJBs
*/
@Stateless
public class TestBean implements ITest {
@Resource private SessionContext ctx;
@PersistenceContext private static EntityManager em;
private static final long INITIAL_DELAY = 5000;
private static final long INTERVAL = 24 * 60 * 60 * 1000;
private static ArrayList<String> suites;
public TestBean() {
init();
}
public void init() {
suites = new ArrayList<String>();
suites.add("testng.xml");
//scheduleTimer(INITIAL_DELAY, INTERVAL);
}
public void scheduleTimer(long initialDelay, long interval) {
ctx.getTimerService().createTimer( initialDelay, interval, suites );
}
@Timeout
public void timeoutHandler(Timer timer) {
runTests( (ArrayList<String>)timer.getInfo() );
}
public void runTests( String suiteXml ) {
ArrayList<String> suite = new ArrayList<String>();
suite.add(suiteXml);
runTests(suite);
}
public void runTests() {
runTests( suites );
}
public void runTests( ArrayList<String> suites ) {
TestNG tng = new TestNG();
tng.setTestSuites(suites);
tng.run();
}
}
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=80954&messageID=146569#146569
That's reasonable. What is likely is that the client isnt binding
right, and jboss's toString NPEs in that situation...it also seems to
use the toString value in creating a hash code.
However, in my limited experience of EJB3 with JBoss, I found some of
the method's semantics to be closer to hibernate's than to the EJB
spec, especially in fault handling and rollback. the JPA spec is very
close top toplink, hibernate has had to be reworked or wrapped to
match, and when things go wrong you'd suddenly fall through the
wrapping into hibernate. Hibernate does run embedded very nicely,
incidentally :)
-steve