[JBoss Seam] - Re: How do I test simple SLSBs?
by mzeijen
I am also pretty new to this stuff, but here is some info to probably can help you. I got it working in eclipse.
I think that If you want use TestNG to test your stuff in a Seam/EJB3 environment then you must write the tests as in the registration example:
|
| package org.jboss.seam.example.registration.test;
|
| import org.jboss.seam.Component;
| import org.jboss.seam.example.registration.Register;
| import org.jboss.seam.example.registration.User;
| import org.jboss.seam.mock.SeamTest;
| import org.testng.annotations.Test;
|
| public class RegisterTest extends SeamTest
| {
|
| @Test
| public void testLogin() throws Exception
| {
|
| new Script() {
|
| @Override
| protected void updateModelValues() throws Exception
| {
| User user = (User) Component.getInstance("user", true);
| assert user!=null;
| user.setUsername("1ovthafew");
| user.setPassword("secret");
| user.setName("Gavin King");
| }
|
| @Override
| protected void invokeApplication()
| {
| Register register = (Register) Component.getInstance("register", true);
| String outcome = register.register();
| assert "/registered.jsp".equals( outcome );
| }
|
| @Override
| protected void renderResponse()
| {
| User user = (User) Component.getInstance("user", false);
| assert user!=null;
| assert user.getName().equals("Gavin King");
| assert user.getUsername().equals("1ovthafew");
| assert user.getPassword().equals("secret");
| }
|
| }.run();
|
| }
|
| }
|
|
Take a special look at the class override of new Script() { ... }. It simulates a complete request loop.
You must make sure that you configured your TestNG for an Embedded Seam application because it needs to run with the JBoss micro container.
The extra configuration files you need are:
- default.persistence.properties
- ejb3-interceptors-aop.xml
- embedded-jboss-beans.xml
- jndi.properties
- log4j.xml
In your components.xml will probably look something like this:
|
| <components>
|
| <component name="org.jboss.seam.core.init">
| <property name="debug">true</property>
| <property name="myFacesLifecycleBug">@myFacesLifecycleBug@</property>
| <property name="jndiPattern">@jndiPattern@</property>
| </component>
|
| <!-- 120 second conversation timeout -->
| <component name="org.jboss.seam.core.manager">
| <property name="conversationTimeout">120000</property>
| </component>
|
| <component class="org.jboss.seam.core.Ejb" installed="@embeddedEjb@"/>
|
| </components>
|
|
Use the components.properties file to set the following properties of the component.xml (those tags with @):
|
| myFacesLifecycleBug : false
| embeddedEjb : true
| jndiPattern : #{ejbName}/local
|
|
I eclipse I have a seperate folder for all those embedded configuration. I add it to the classpath when I run TestNG.
Good luck
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3968487#3968487
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3968487
19 years, 7 months
[JBoss Seam] - How do I test simple SLSBs?
by chuckadams
I'm trying to do the simplest possible test, and have a stateless bean called GreeterBean, with its @Name set to greeter, with a getHello() method that returns "Hello, world!", so I can plug it into a page as #{greeter.hello}. This works perfectly. My troubles come when trying to write a test for it.
| public class GreeterTest extends SeamTest {
|
| @Test
| public void testGreeterHello() {
| Greeter g = (Greeter) Component.getInstance("greeter", true);
| assert g.getHello().equals("Hello, world!");
| }
| }
|
Unfortunately, this fails, and I don't mean the test, but Component.getInstance dies with a NPE because Contexts.getApplicationContext() returns null. I notice there's a MockApplication class lying around, but I'm stumped on how to actually use it, and the docs are rather sparse on the subject.
I tried dispensing with mocks and just going with embedded ejb3, but that's been a frightful experience, also replete with java's favorite catch-all error, the NPE (I curse the very invention of null). I found that I could make my embedded ejb3 test work if I commented out @Name, but obviously this doesn't constitute much of a test. I don't have the TB handy at the moment since I've deleted my embedded ejb3 launch configuration, but IIRC, it was croaking somewhere in the PostConstruct method of some long interceptor call chain.
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3968485#3968485
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3968485
19 years, 7 months
[JBoss Getting Started Documentation] - EJB spec violation when deploying JBossDukesBank.ear
by vmystic
Following the directions in the Getting Started Guide for JBoss 4.0, I'm getting many errors when I run the deploy step (ant -f jboss-build.xml deploy) in the Duke's Bank example. Any help would be appreciated.
My environment is as follows:
OS: RedHat ES 4 Update 3
JDK: 1.4.2_12
Ant: 1.6.5
JBoss: 4.0.4
J2EE Tutorial: J2EE 1.4 Tutorial Update 7 (for Sun Java System Application Server Platform Edition 8.2) January 27, 2006
Errors:
12:42:24,524 INFO [EARDeployer] Init J2EE application: file:/opt/jboss-4.0.4.GA/server/default/deploy/JBossDukesBank.ear
12:42:24,944 WARN [verifier] EJB spec violation:
Bean : CustomerBean
Section: 12.2.2
Warning: The class must be defined as public and must not be abstract.
12:42:24,953 WARN [verifier] EJB spec violation:
Bean : CustomerBean
Section: 12.2.5
Warning: Every entity bean must define the ejbFindByPrimaryKey method.
12:42:24,956 WARN [verifier] EJB spec violation:
Bean : CustomerBean
Section: 22.2
Warning: The bean provider must specify the fully-qualified name of the enterprise bean's local home interface, if any, in the <local-home> element.
Info : Class not found on 'com.sun.ebank.ejb.customer.CustomerHome': No ClassLoaders found for: com.sun.ebank.ejb.customer.CustomerHome
12:42:24,957 WARN [verifier] EJB spec violation:
Bean : CustomerBean
Section: 22.2
Warning: The bean provider must specify the fully-qualified name of the enterprise bean's local interface, if any, in the element.
Info : Class not found on 'com.sun.ebank.ejb.customer.Customer': No ClassLoaders found for: com.sun.ebank.ejb.customer.Customer
12:42:24,957 WARN [verifier] EJB spec violation:
Bean : CustomerBean
Section: 12.2.1
Warning: The Bean Provider must provide a remote interface and a remote home interface or a local interface and a local home interface for the bean.
12:42:24,960 WARN [verifier] EJB spec violation:
Bean : AccountBean
Section: 12.2.2
Warning: The class must be defined as public and must not be abstract.
12:42:24,966 WARN [verifier] EJB spec violation:
Bean : AccountBean
Section: 12.2.5
Warning: Every entity bean must define the ejbFindByPrimaryKey method.
12:42:24,969 WARN [verifier] EJB spec violation:
Bean : AccountBean
Section: 22.2
Warning: The bean provider must specify the fully-qualified name of the enterprise bean's local home interface, if any, in the <local-home> element.
Info : Class not found on 'com.sun.ebank.ejb.account.AccountHome': No ClassLoaders found for: com.sun.ebank.ejb.account.AccountHome
12:42:24,970 WARN [verifier] EJB spec violation:
Bean : AccountBean
Section: 22.2
Warning: The bean provider must specify the fully-qualified name of the enterprise bean's local interface, if any, in the element.
Info : Class not found on 'com.sun.ebank.ejb.account.Account': No ClassLoaders found for: com.sun.ebank.ejb.account.Account
12:42:24,970 WARN [verifier] EJB spec violation:
Bean : AccountBean
Section: 12.2.1
Warning: The Bean Provider must provide a remote interface and a remote home interface or a local interface and a local home interface for the bean.
12:42:24,973 WARN [verifier] EJB spec violation:
Bean : TxBean
Section: 12.2.2
Warning: The class must be defined as public and must not be abstract.
12:42:24,976 WARN [verifier] EJB spec violation:
Bean : TxBean
Section: 12.2.5
Warning: Every entity bean must define the ejbFindByPrimaryKey method.
12:42:24,980 WARN [verifier] EJB spec violation:
Bean : TxBean
Section: 22.2
Warning: The bean provider must specify the fully-qualified name of the enterprise bean's local home interface, if any, in the <local-home> element.
Info : Class not found on 'com.sun.ebank.ejb.tx.TxHome': No ClassLoaders found for: com.sun.ebank.ejb.tx.TxHome
12:42:24,982 WARN [verifier] EJB spec violation:
Bean : TxBean
Section: 22.2
Warning: The bean provider must specify the fully-qualified name of the enterprise bean's local interface, if any, in the element.
Info : Class not found on 'com.sun.ebank.ejb.tx.Tx': No ClassLoaders found for: com.sun.ebank.ejb.tx.Tx
12:42:24,982 WARN [verifier] EJB spec violation:
Bean : TxBean
Section: 12.2.1
Warning: The Bean Provider must provide a remote interface and a remote home interface or a local interface and a local home interface for the bean.
12:42:25,055 ERROR [MainDeployer] Could not create deployment: file:/opt/jboss-4.0.4.GA/server/default/tmp/deploy/tmp55721JBossDukesBank.ear-contents/bank-ejb.jar
org.jboss.deployment.DeploymentException: Verification of Enterprise Beans failed, see above for error messages.
at org.jboss.ejb.EJBDeployer.create(EJBDeployer.java:610)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.interceptor.DynamicInterceptor.invoke(DynamicInterceptor.java:97)
at org.jboss.system.InterceptorServiceMBeanSupport.invokeNext(InterceptorServiceMBeanSupport.java:238)
at org.jboss.ws.server.WebServiceDeployer.create(WebServiceDeployer.java:99)
at org.jboss.deployment.SubDeployerInterceptorSupport$XMBeanInterceptor.create(SubDeployerInterceptorSupport.java:180)
at org.jboss.deployment.SubDeployerInterceptor.invoke(SubDeployerInterceptor.java:91)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy42.create(Unknown Source)
at org.jboss.deployment.MainDeployer.create(MainDeployer.java:953)
at org.jboss.deployment.MainDeployer.create(MainDeployer.java:943)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:807)
at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:771)
at sun.reflect.GeneratedMethodAccessor12.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
at $Proxy6.deploy(Unknown Source)
at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3968479#3968479
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3968479
19 years, 7 months