Erro com TestUnit Spring

ola pessoal, estou com um probleminha num exemplo de um livro q estou estudando…fiz um teste unitario e está me retornando o seguinte erro:

[b]
Testcase: gravar(facade.UsuarioFacadeTest): Caused an ERROR
org/apache/commons/logging/LogFactory
java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at org.springframework.context.support.AbstractApplicationContext.(AbstractApplicationContext.java:146)
at org.springframework.context.support.AbstractRefreshableApplicationContext.(AbstractRefreshableApplicationContext.java:84)
at org.springframework.context.support.AbstractRefreshableConfigApplicationContext.(AbstractRefreshableConfigApplicationContext.java:59)
at org.springframework.context.support.AbstractXmlApplicationContext.(AbstractXmlApplicationContext.java:58)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:136)
at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83)
at facade.UsuarioFacadeTest.gravar(UsuarioFacadeTest.java:50)

[/b]

sou iniciante em java e spring…nao sei se o problema é no applicationContext…segue o tal:

<?xml version="1.0" encoding="UTF-8"?>



<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework/schema/aop"
       xmlns:tx="http://www.springframework/schema/tx"
       
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd 
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd 
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

<!-- Configurador que substitui os marcadores ${...} com os valores definidos no arquivo de properties -->
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:/jdbc.properties"/>
        
    </bean>
    <!-- Local C3PO DataSource que Trabalha em qualquer ambiente, em ambientes de produção use jndi -->
    <bean id="dataSource" class="com.mchange.v2.c3po.ComboPooledDataSource" destroy-method="close">
        <property name="driverClass" value="${jdbc.driverClassName}"/>
        <property name="jdbcUrl" value="${jdbc.url}"/>
        <property name="user" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        
    </bean>    
    
    <!--JPA EntityManagerFactory -->
    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="showSql" value="true"/>
                <property name="generateDd1" value="false" />
                <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/>
            </bean>    
        </property>        
        
    </bean>
    
    <!--Transaction Manager para um JPS EntityManagerFactory simples(alternativa ao JTA) -->
    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory"/>
        
    </bean>
    
    <!--Instrui o Spring a realizar gerenciamento transacional declarativo automático nas classes anotadas -->    
    <tx:annotation-driven/>
    
    <!--PostProcessors para realizar injecao de recursos de acordo com a especificação jpa (@PersistenceContext, @PersistenceUnit) -->
    <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
    
    <!--PostProcessors para realizar a conversao de exceçoes nas classes @Repository (das exceções nativas como jpa
     PersistenceExceptions to Sprong's DataAccessException ) -->
    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" /> 
    
    <!--Será automaticamente transacional graças ao @Transactional.
    EntityManager irá ser auto-injetado graças ao @PersistenceContext.
    PersistenceException será automaticamente convertido graças ao @Repository.-->
    
    <bean id="usuario" class="dominio.Usuario" scope="session" />
    <bean id="usuarioDao" class="dao.UsuarioDao" />
    <bean id="usuarioFacade" class="facade.UsuarioFacade">
        <property name="usuarioDao" ref="usuarioDao"/>
    </bean>
    
    <bean id="contato" class="dominio.Contato" scope="session" />
    <bean id="contatoDao" class="dao.ContatoDao" />
    <bean id="contatoFacade" class="facade.ContatoFacade">
        <property name="contatoDao" ref="contatoDao"/>
    </bean>
    
    <bean id="endereco" class="dominio.Endereco" scope="session" />
    <bean id="enderecoDao" class="dao.EnderecoDao" />
    <bean id="enderecoFacade" class="facade.EnderecoFacade">
        <property name="enderecoDao" ref="enderecoDao"/>
    </bean>
    
    <bean id="meioContato" class="dominio.MeioContato" scope="session" />
    <bean id="meioContatoDao" class="dao.MeioContatoDao" />
    <bean id="meioContatoFacade" class="facade.MeioContatoFacade">
        <property name="meioContatoDao" ref="meioContatoDao"/>
    </bean>
    
    
</beans>

aqui segue o metodo:


    @Test
    public void gravar() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
                                                                        
        Usuario usuarioTeste = new Usuario();
        usuarioTeste.setLogin("guest");
        usuarioTeste.setNome("guest");
        usuarioTeste.setSenha("guest");
        
        System.out.println("gravar usuário");
        
        UsuarioFacade instance = (UsuarioFacade) context.getBean("usuarioFacade");
        Usuario result = instance.gravar(usuarioTeste);
        
        try{
            assertNotNull(result.getIdUsuario());
        }catch(AssertionError e){
            fail("Falhou a gravação de usuário.");
        }
        
        

    }

conto com vcs colegas, muito obrigado, abraços.

atualizei umas libs que nao estavam na mesma versao do livro q estou seguindo e o erro mudou…agora é nao linha 59 do applicationContext.xml:

[b]
Testcase: gravar(facade.UsuarioFacadeTest): Caused an ERROR
Line 59 in XML document from class path resource [applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element ‘tx:annotation-driven’.
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 59 in XML document from class path resource [applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element ‘tx:annotation-driven’.

[/b]

Pois é,

Estou seguindo o mesmo livro…

E aí conseguiu alguma luz ???

Estou com o mesmo erro :smiley:

[[]]´s

Resolvido!

O applicationConfig.xml fica assim usando as versões que vêm com o netbeans 6.1 (atualizado ontém 26/09/2008 ) ficaria assim:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
    
       
      
       <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
           <property name="location" value="classpath:jdbc.properties" />
       </bean>
       
       <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
           <property name="jdbcUrl" value="${jdbc.url}"/>
           <property name="user" value="${jdbc.username}"/>
           <property name="password" value="${jdbc.password}"/>
       </bean>
       

       <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
           <property name="dataSource" ref="dataSource"/>
           <property name="jpaVendorAdapter">
               <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                   <property name="showSql" value="true"/>
                   <property name="generateDdl" value="false"/>
                   <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/>
               </bean>
           </property>
       </bean>
       

       <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
           <property name="entityManagerFactory" ref="entityManagerFactory" />
       </bean>
       
       <tx:annotation-driven transaction-manager="transactionManager"/>
              
       <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
       
       <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

       <!-- Aqui vão as classes, os facadaes, os DAOs  e etc...-->
</beans>

Espero que ajude!

[[]]´s!