Looks like you have "several" UsuarioFacade beans in your
applicationContext.xml file ...Simpliest workaround is to use "autowire by
name" instead of "autowire by type" (by default) in your test configuration.

I personnaly switch this by calling 'setAutowireMode(AUTOWIRE_BY_NAME)" in
my test constructor (I think you should be able to call this with
annotations.. but I don't know how since I work with junit 3.8 tests ;)).
Then, all you have to do is define a setXXX() method in your test class,
where XXX matches your bean id.

On Sun, Jul 5, 2009 at 1:33 PM, Chávez, Carlos <[email protected]> wrote:

> Hello everyone.
>
> I configured the test cases to use annotations and autowire, everything
> works
> as expected when i run "mvn test" or install.
>
> But when I try to run the surefire plugin the autowire did not work.
>
>
> *********************************************************************************
> The Following is the dependecy tree:
>
> *********************************************************************************
> [INFO] [dependency:tree {execution: default-cli}]
> [INFO] ni.gob.cgr.siirci:dao:jar:1.0-SNAPSHOT
> [INFO] +- ni.gob.cgr.siirci:bean:jar:1.0-SNAPSHOT:compile
> [INFO] |  \- commons-lang:commons-lang:jar:2.4:compile
> [INFO] +- ni.gob.cgr.siirci:hibernate:jar:1.0-SNAPSHOT:compile
> [INFO] |  +- org.hibernate:hibernate-annotations:jar:3.4.0.GA:compile
> [INFO] |  |  +- org.hibernate:ejb3-persistence:jar:1.0.2.GA:compile
> [INFO] |  |  +- org.hibernate:hibernate-core:jar:3.3.0.SP1:compile
> [INFO] |  |  |  +- antlr:antlr:jar:2.7.6:compile
> [INFO] |  |  |  \- javax.transaction:jta:jar:1.1:compile
> [INFO] |  |  \- dom4j:dom4j:jar:1.6.1:compile
> [INFO] |  +- org.hibernate:hibernate-commons-annotations:jar:3.3.0.ga:
> compile
> [INFO] |  |  \- org.hibernate:hibernate:jar:3.2.1.ga:compile
> [INFO] |  |     +- asm:asm-attrs:jar:1.5.3:compile
> [INFO] |  |     +- cglib:cglib:jar:2.1_3:compile
> [INFO] |  |     \- asm:asm:jar:1.5.3:compile
> [INFO] |  +- org.slf4j:slf4j-nop:jar:1.5.8:compile
> [INFO] |  +- org.slf4j:slf4j-api:jar:1.5.8:compile
> [INFO] |  +- commons-collections:commons-collections:jar:3.2.1:compile
> [INFO] |  \- javassist:javassist:jar:3.8.0.GA:compile
> [INFO] +- postgresql:postgresql:jar:8.3-604.jdbc3:compile
> [INFO] +- org.springframework:spring:jar:2.5.6.SEC01:compile
> [INFO] |  \- commons-logging:commons-logging:jar:1.1.1:compile
> [INFO] +- org.springframework:spring-hibernate3:jar:2.0.8:compile
> [INFO] |  +- aopalliance:aopalliance:jar:1.0:compile
> [INFO] |  +- org.springframework:spring-beans:jar:2.0.8:compile
> [INFO] |  +- org.springframework:spring-context:jar:2.0.8:compile
> [INFO] |  +- org.springframework:spring-core:jar:2.0.8:compile
> [INFO] |  +- org.springframework:spring-dao:jar:2.0.8:compile
> [INFO] |  \- org.springframework:spring-jdbc:jar:2.0.8:compile
> [INFO] +- commons-dbcp:commons-dbcp:jar:1.2.2:compile
> [INFO] |  \- commons-pool:commons-pool:jar:1.3:compile
> [INFO] +- junit:junit:jar:4.6:test
> [INFO] \- org.springframework:spring-test:jar:2.5.6.SEC01:test
>
>
> *********************************************************************************
> The following is the stacktrace:
>
> *********************************************************************************
> [INFO] skip non existing resourceDirectory
> /home/cchavez/workspace/siirci/dao/src/test/resources
> [INFO] [compiler:testCompile]
> [INFO] Nothing to compile - all classes are up to date
> [INFO] [surefire:test]
> [INFO] Surefire report directory:
> /home/cchavez/workspace/siirci/dao/target/surefire-reports
> 07-05-2009 04:56:55 AM org.springframework.test.context.TestContextManager
> retrieveTestExecutionListeners
> INFO: @TestExecutionListeners is not present for class [class
> ni.gob.cgr.siirci.facade.UsuarioFacadeTestCase]: using defaults.
>
> -------------------------------------------------------
>  T E S T S
> -------------------------------------------------------
> Running ni.gob.cgr.siirci.facade.UsuarioFacadeTestCase
> 07-05-2009 04:56:55 AM
> org.springframework.beans.factory.xml.XmlBeanDefinitionReader
> loadBeanDefinitions
> INFO: Loading XML bean definitions from class path resource
> [applicationContext.xml]
> 07-05-2009 04:56:56 AM
> org.springframework.context.support.AbstractApplicationContext
> prepareRefresh
> INFO: Refreshing
> org.springframework.context.support.genericapplicationcont...@fbb7cb:
> display
> name [org.springframework.context.support.genericapplicationcont...@fbb7cb
> ];
> startup date [Sun Jul 05 04:56:56 CST 2009]; root of context hierarchy
> 07-05-2009 04:56:56 AM
> org.springframework.context.support.AbstractApplicationContext
> obtainFreshBeanFactory
> INFO: Bean factory for application context
> [org.springframework.context.support.genericapplicationcont...@fbb7cb]:
> org.springframework.beans.factory.support.defaultlistablebeanfact...@aeea66
> 07-05-2009 04:56:56 AM
> org.springframework.core.io.support.PropertiesLoaderSupport loadProperties
> INFO: Loading properties file from class path resource
> [hibernate.properties]
> 07-05-2009 04:56:56 AM
> org.springframework.beans.factory.support.DefaultListableBeanFactory
> preInstantiateSingletons
> INFO: Pre-instantiating singletons in
> org.springframework.beans.factory.support.defaultlistablebeanfact...@aeea66
> :
> defining beans
>
> [org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,dataSource,sessionFactory,transactionManager,sessionUtil,baseFacade,usuarioFacade];
> root of factory hierarchy
> 07-05-2009 04:56:56 AM
> org.springframework.orm.hibernate3.LocalSessionFactoryBean
> buildSessionFactory
> INFO: Building new Hibernate SessionFactory
> 07-05-2009 04:56:57 AM
> org.springframework.orm.hibernate3.HibernateTransactionManager
> afterPropertiesSet
> INFO: Using DataSource [org.apache.commons.dbcp.basicdatasou...@7a36a2] of
> Hibernate SessionFactory for HibernateTransactionManager
> 07-05-2009 04:56:57 AM org.springframework.test.context.TestContextManager
> prepareTestInstance
> GRAVE: Caught exception while allowing TestExecutionListener
>
> [org.springframework.test.context.support.dependencyinjectiontestexecutionliste...@5ff916
> ]
> to prepare test instance
> [null(ni.gob.cgr.siirci.facade.UsuarioFacadeTestCase)]
> org.springframework.beans.factory.BeanCreationException: Error creating
> bean
> with name 'ni.gob.cgr.siirci.facade.UsuarioFacadeTestCase': Autowiring of
> methods failed; nested exception is
> org.springframework.beans.factory.BeanCreationException: Could not autowire
> method: public void
>
> ni.gob.cgr.siirci.facade.UsuarioFacadeTestCase.setUsuarioFacade(ni.gob.cgr.siirci.facade.UsuarioFacade);
> nested exception is
> org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique
> bean
> of type [ni.gob.cgr.siirci.facade.UsuarioFacade] is defined: Unsatisfied
> dependency of type [class ni.gob.cgr.siirci.facade.UsuarioFacade]: expected
> at
> least 1 matching bean
>        at
>
> org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:256)
>        at
>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:998)
>        at
>
> org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireBeanProperties(AbstractAutowireCapableBeanFactory.java:329)
>        at
>
> org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:110)
>        at
>
> org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
>        at
>
> org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:255)
>        at
>
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:111)
>        at
>
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:148)
>        at
>
> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:61)
>        at
>
> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:54)
>        at
> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
>        at
> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
>        at
> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:52)
>        at
>
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
>        at
>
> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
>        at
>
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
>        at
>
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
>        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
>        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:597)
>        at
>
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
>        at
>
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
> Caused by: org.springframework.beans.factory.BeanCreationException: Could
> not
> autowire method: public void
>
> ni.gob.cgr.siirci.facade.UsuarioFacadeTestCase.setUsuarioFacade(ni.gob.cgr.siirci.facade.UsuarioFacade);
> nested exception is
> org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique
> bean
> of type [ni.gob.cgr.siirci.facade.UsuarioFacade] is defined: Unsatisfied
> dependency of type [class ni.gob.cgr.siirci.facade.UsuarioFacade]: expected
> at
> least 1 matching bean
>        at
>
> org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:543)
>        at
>
> org.springframework.beans.factory.annotation.InjectionMetadata.injectMethods(InjectionMetadata.java:117)
>        at
>
> org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:253)
>        ... 23 more
> Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException:
> No
> unique bean of type [ni.gob.cgr.siirci.facade.UsuarioFacade] is defined:
> Unsatisfied dependency of type [class
> ni.gob.cgr.siirci.facade.UsuarioFacade]:
> expected at least 1 matching bean
>        at
>
> org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:613)
>        at
>
> org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:499)
>        ... 25 more
> org.apache.maven.surefire.booter.SurefireExecutionException:
>
> org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/runner/Description;Ljava/lang/Throwable;)V;
> nested exception is java.lang.NoSuchMethodError:
>
> org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/runner/Description;Ljava/lang/Throwable;)V
> java.lang.NoSuchMethodError:
>
> org.junit.runner.notification.RunNotifier.testAborted(Lorg/junit/runner/Description;Ljava/lang/Throwable;)V
>        at
>
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:155)
>        at
>
> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:61)
>        at
>
> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:54)
>        at
> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
>        at
> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
>        at
> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:52)
>        at
>
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:97)
>        at
>
> org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
>        at
>
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
>        at
>
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
>        at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
>        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:597)
>        at
>
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
>        at
>
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
> 07-05-2009 04:56:57 AM
> org.springframework.context.support.AbstractApplicationContext doClose
> INFO: Closing
> org.springframework.context.support.genericapplicationcont...@fbb7cb:
> display
> name [org.springframework.context.support.genericapplicationcont...@fbb7cb
> ];
> startup date [Sun Jul 05 04:56:56 CST 2009]; root of context hierarchy
> 07-05-2009 04:56:57 AM
> org.springframework.beans.factory.support.DefaultSingletonBeanRegistry
> destroySingletons
> INFO: Destroying singletons in
> org.springframework.beans.factory.support.defaultlistablebeanfact...@aeea66
> :
> defining beans
>
> [org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,dataSource,sessionFactory,transactionManager,sessionUtil,baseFacade,usuarioFacade];
> root of factory hierarchy
> 07-05-2009 04:56:57 AM
> org.springframework.orm.hibernate3.AbstractSessionFactoryBean destroy
> INFO: Closing Hibernate SessionFactory
>
>
>
> *********************************************************************************
> The class is very simple:
>
> *********************************************************************************
> @RunWith(SpringJUnit4ClassRunner.class)
> @ContextConfiguration(locations={"/applicationContext.xml"})
> @TransactionConfiguration
> @Transactional
> public class UsuarioFacadeTestCase extends TestCase {
>    private UsuarioFacade usuarioFacade;
>
>    public UsuarioFacade getUsuarioFacade() {
>        return usuarioFacade;
>    }
>
>    @Autowired
>    public void setUsuarioFacade(final UsuarioFacade usuarioFacade) {
>        this.usuarioFacade = usuarioFacade;
>    }
>
>    @Test
>    public void testUsuarioFacade() {
>        assertNotNull(usuarioFacade);
>        usuarioFacade.setUsrLogin("MI_LOGIN");
>        usuarioFacade.setUsrFullName("MI_FULL_NAME");
>        usuarioFacade.setUsrCargo("MI_CARGO");
>        usuarioFacade.save();
>        assertNotNull(usuarioFacade.getDelegate().getUsrId());
>        assertTrue(usuarioFacade.getDelegate().getUsrId() > 0);
>    }
> }
>
>
> As i said before, everything works as expected when I ran test or install
> goal, but the surefire plugin does not work.
>
> I tried with every 2.4.x version of the surefire plugin.
>
> --
> Cheers.
> Carlos Chávez.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>

Reply via email to