Hi there,
I created a new enterprise project from netbean, and i created two modules
logic and model.
I created one bean and I'm trying look it back from my unit test but im
getting a weird execption
Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 4.657 sec
<<< FAILURE!
testCreateUser(com.altobridge.omc.orm.dao.UserDaoLocalTest) Time elapsed:
4.581 sec <<< ERROR!
java.lang.ClassCastException: $Proxy42 cannot be cast to
com.altobridge.omc.orm.dao.UserDao
at
com.altobridge.omc.orm.dao.UserDaoLocalTest.testCreateUser(UserDaoLocalTest.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at
org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53)
at
org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123)
at
org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at
org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164)
at
org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110)
at
org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175)
at
org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107)
at
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68)
Here is my Bean Code
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.altobridge.omc.orm.dao;
import com.altobridge.omc.orm.entities.User;
import javax.ejb.Local;
/**
*
* @author antonio
*/
@Local
public interface UserDaoLocal
{
public void createUser (User user);
public void deleteUser (User user);
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.altobridge.omc.orm.dao;
import com.altobridge.omc.orm.entities.User;
import javax.ejb.Stateful;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
/**
*
* @author antonio
*/
@Stateless
@PersistenceContext( name = "dynamic" )
public class UserDao implements UserDaoLocal
{
@PersistenceContext
private EntityManager entityManager;
@Override
public void createUser( User user )
{
entityManager.persist(user);
}
@Override
public void deleteUser( User user )
{
entityManager.remove(user);
}
}
Here my unit test
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.altobridge.omc.orm.dao;
import com.altobridge.omc.orm.entities.User;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.junit.Test;
/**
*
* @author antonio
*/
public class UserDaoLocalTest {
public UserDaoLocalTest() {
}
/**
* Test of createUser method, of class UserDaoLocal.
*/
@Test
public void testCreateUser() throws NamingException
{
Properties p =
new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,
"org.apache.openejb.core.LocalInitialContextFactory");
p.put("openejb.deployments.classpath.ear", "true");
p.put("postgresDatabase", "new://Resource?type=DataSource");
p.put("postgresDatabase.JdbcDriver", "org.postgresql.Driver");
p.put("postgresDatabase.JdbcUrl",
"jdbc:postgresql://localhost:5432/aomdb");
Context context =
new InitialContext(p);
UserDao users =
(UserDao) context.lookup("UserDaoLocal");
User user =
new User();
user.setUsername("Quentin Tarantino");
user.setId("QuentinTarantino.0");
users.createUser(user);
}
/**
* Test of deleteUser method, of class UserDaoLocal.
*/
@Test
public void testDeleteUser() {
}
}
And here the trace back
Scanning for projects...
------------------------------------------------------------------------
Building omc_aomdb_logic 1.0-SNAPSHOT
------------------------------------------------------------------------
[clean:clean]
Deleting /home/antonio/NetBeansProjects/omc/omc_aomdb_logic/target
[dependency:copy]
[resources:resources]
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
Copying 1 resource
[compiler:compile]
Compiling 4 source files to
/home/antonio/NetBeansProjects/omc/omc_aomdb_logic/target/classes
[resources:testResources]
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory
/home/antonio/NetBeansProjects/omc/omc_aomdb_logic/src/test/resources
[compiler:testCompile]
Compiling 1 source file to
/home/antonio/NetBeansProjects/omc/omc_aomdb_logic/target/test-classes
[surefire:test]
Surefire report directory:
/home/antonio/NetBeansProjects/omc/omc_aomdb_logic/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.altobridge.omc.orm.dao.UserDaoLocalTest
INFO -
********************************************************************************
INFO - OpenEJB http://openejb.apache.org/
INFO - Startup: Wed Feb 20 17:43:07 GMT 2013
INFO - Copyright 1999-2012 (C) Apache OpenEJB Project, All Rights Reserved.
INFO - Version: 4.5.1
INFO - Build date: 20121209
INFO - Build time: 08:47
INFO -
********************************************************************************
INFO - openejb.home = /home/antonio/NetBeansProjects/omc/omc_aomdb_logic
INFO - openejb.base = /home/antonio/NetBeansProjects/omc/omc_aomdb_logic
INFO - Created new singletonService
org.apache.openejb.cdi.ThreadSingletonServiceImpl@1d272e52
INFO - Succeeded in installing singleton service
INFO - Cannot find the configuration file [conf/openejb.xml]. Will attempt
to create one for the beans deployed.
INFO - Configuring Service(id=Default Security Service,
type=SecurityService, provider-id=Default Security Service)
INFO - Configuring Service(id=Default Transaction Manager,
type=TransactionManager, provider-id=Default Transaction Manager)
INFO - Configuring Service(id=postgresDatabase, type=Resource,
provider-id=Default JDBC Database)
INFO - Found PersistenceModule in classpath:
/home/antonio/.m2/repository/com/altobridge/omc_aomdb_model/1.0-SNAPSHOT/omc_aomdb_model-1.0-SNAPSHOT.jar
INFO - Found EjbModule in classpath:
/home/antonio/NetBeansProjects/omc/omc_aomdb_logic/target/classes
INFO - Using 'openejb.deployments.classpath.ear=true'
INFO - Beginning load:
/home/antonio/.m2/repository/com/altobridge/omc_aomdb_model/1.0-SNAPSHOT/omc_aomdb_model-1.0-SNAPSHOT.jar
INFO - Beginning load:
/home/antonio/NetBeansProjects/omc/omc_aomdb_logic/target/classes
INFO - Configuring enterprise application:
/home/antonio/NetBeansProjects/omc/omc_aomdb_logic/classpath.ear
INFO - PersistenceUnit 'com.altobridge_omc-aomdb_ejb_1.0-SNAPSHOTPU' is a
RESOURCE_LOCAL one, you'll have to manage @PersistenceContext yourself.
INFO - PersistenceUnit 'com.altobridge_omc-aomdb_ejb_1.0-SNAPSHOTPU' is a
RESOURCE_LOCAL one, you'll have to manage @PersistenceContext yourself.
INFO - Auto-deploying ejb UserDao: EjbDeployment(deployment-id=UserDao)
INFO - Auto-deploying ejb Authentication:
EjbDeployment(deployment-id=Authentication)
INFO - Configuring Service(id=Default Stateless Container, type=Container,
provider-id=Default Stateless Container)
INFO - Auto-creating a container for bean UserDao: Container(type=STATELESS,
id=Default Stateless Container)
INFO - Configuring
PersistenceUnit(name=com.altobridge_omc-aomdb_ejb_1.0-SNAPSHOTPU,
provider=org.eclipse.persistence.jpa.PersistenceProvider)
INFO - Auto-creating a Resource with id 'postgresDatabaseNonJta' of type
'DataSource for 'com.altobridge_omc-aomdb_ejb_1.0-SNAPSHOTPU'.
INFO - Configuring Service(id=postgresDatabaseNonJta, type=Resource,
provider-id=postgresDatabase)
INFO - Adjusting PersistenceUnit com.altobridge_omc-aomdb_ejb_1.0-SNAPSHOTPU
<jta-data-source> to Resource ID 'postgresDatabase' from 'null'
INFO - Adjusting PersistenceUnit com.altobridge_omc-aomdb_ejb_1.0-SNAPSHOTPU
<non-jta-data-source> to Resource ID 'postgresDatabaseNonJta' from 'null'
INFO - Enterprise application
"/home/antonio/NetBeansProjects/omc/omc_aomdb_logic/classpath.ear" loaded.
INFO - Creating TransactionManager(id=Default Transaction Manager)
INFO - Creating SecurityService(id=Default Security Service)
INFO - Creating Resource(id=postgresDatabase)
INFO - Creating Resource(id=postgresDatabaseNonJta)
INFO - Creating Container(id=Default Stateless Container)
INFO - Assembling app:
/home/antonio/NetBeansProjects/omc/omc_aomdb_logic/classpath.ear
SEVERE - JAVA AGENT NOT INSTALLED. The JPA Persistence Provider requested
installation of a ClassFileTransformer which requires a JavaAgent. See
http://openejb.apache.org/3.0/javaagent.html
INFO - PersistenceUnit(name=com.altobridge_omc-aomdb_ejb_1.0-SNAPSHOTPU,
provider=org.eclipse.persistence.jpa.PersistenceProvider) - provider time
1220ms
INFO - Jndi(name=UserDaoLocal) --> Ejb(deployment-id=UserDao)
INFO -
Jndi(name=global/classpath.ear/omc_aomdb_logic/UserDao!com.altobridge.omc.orm.dao.UserDaoLocal)
--> Ejb(deployment-id=UserDao)
INFO - Jndi(name=global/classpath.ear/omc_aomdb_logic/UserDao) -->
Ejb(deployment-id=UserDao)
INFO - Jndi(name=AuthenticationLocal) --> Ejb(deployment-id=Authentication)
INFO -
Jndi(name=global/classpath.ear/omc_aomdb_logic/Authentication!com.altobridge.omc.gui.login.AuthenticationLocal)
--> Ejb(deployment-id=Authentication)
INFO - Jndi(name=global/classpath.ear/omc_aomdb_logic/Authentication) -->
Ejb(deployment-id=Authentication)
INFO - Existing thread singleton service in SystemInstance()
org.apache.openejb.cdi.ThreadSingletonServiceImpl@1d272e52
INFO - OpenWebBeans Container is starting...
INFO - Adding OpenWebBeansPlugin : [CdiPlugin]
INFO - All injection points are validated successfully.
INFO - OpenWebBeans Container has started, it took 337 ms.
INFO - Created Ejb(deployment-id=UserDao, ejb-name=UserDao,
container=Default Stateless Container)
INFO - Created Ejb(deployment-id=Authentication, ejb-name=Authentication,
container=Default Stateless Container)
INFO - Started Ejb(deployment-id=UserDao, ejb-name=UserDao,
container=Default Stateless Container)
INFO - Started Ejb(deployment-id=Authentication, ejb-name=Authentication,
container=Default Stateless Container)
INFO - Deployed
Application(path=/home/antonio/NetBeansProjects/omc/omc_aomdb_logic/classpath.ear)
Tests run: 2, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 4.656 sec
<<< FAILURE!
Results :
Tests in error:
testCreateUser(com.altobridge.omc.orm.dao.UserDaoLocalTest): $Proxy42
cannot be cast to com.altobridge.omc.orm.dao.UserDao
Tests run: 2, Failures: 0, Errors: 1, Skipped: 0
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 10.764s
Finished at: Wed Feb 20 17:43:12 GMT 2013
Final Memory: 26M/161M
------------------------------------------------------------------------
Failed to execute goal
org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on
project omc_aomdb_logic: There are test failures.
Please refer to
/home/antonio/NetBeansProjects/omc/omc_aomdb_logic/target/surefire-reports
for the individual test results.
-> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read
the following articles:
[Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
--
View this message in context:
http://openejb.979440.n4.nabble.com/I-can-not-look-up-for-a-bean-in-my-Unit-test-tp4660917.html
Sent from the OpenEJB User mailing list archive at Nabble.com.