Announcement Announcement Module
Collapse
No announcement yet.
Junit test failure Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Junit test failure

    Hi
    I have written a simple application consists of Hibernate-Spring and JSF, everthing works fine in the WebContainer. But when i test the services that are in the application with JUNIT, spring throws the following exception:
    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kullaniciGirisDAO' defined in class path resource [test/testContext.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.springframework.orm.hibernate.LocalSessionFactoryBean] to required type [net.sf.hibernate.SessionFactory] for property 'sessionFactory']
    PropertyAccessExceptionsException (1 errors)
    org.springframework.beans.TypeMismatchException: Failed to convert property value of type [org.springframework.orm.hibernate.LocalSessionFactoryBean] to required type [net.sf.hibernate.SessionFactory] for property 'sessionFactory'
    As i said before spring works well with the same configuration file in the web container. Configuratiın file:
    Code:
    <beans>
    	<!-- ========================= Start of PERSISTENCE DEFINITIONS ========================= -->
    
    	<!-- DataSource Definition -->
    	<bean id="dataSource"
    		class="org.apache.commons.dbcp.BasicDataSource"
    		destroy-method="close">
    		<property name="driverClassName">
    			<value>COM.ibm.db2.jdbc.app.DB2Driver</value>
    		</property>
    		<property name="url">
    			<value>jdbc&#58;db2&#58;xxxx</value>
    		</property>
    		<property name="username">
    			<value>xxxx</value>
    		</property>
    		<property name="password">
    			<value>xxx</value>
    		</property>
    	</bean>
    
    	<!-- Hibernate SessionFactory Definition -->
    	<bean id="sessionFactory"
    		class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
    		<property name="mappingResources">
    			<list>
    				<value>
    					maps/Tuserbl.hbm
    				</value>				
    			</list>
    		</property>
    
    		<property name="hibernateProperties">
    			<props>
    				<prop key="hibernate.dialect">
    					net.sf.hibernate.dialect.DB2Dialect
    				</prop>
    				<prop key="hibernate.connection.isolation">2</prop>
    				<prop key="hibernate.show_sql">true</prop>				
    			</props>
    		</property>
    
    		<property name="dataSource">
    			<ref bean="dataSource" />
    		</property>
    	</bean>
    
    	<!-- Spring Data Access Exception Translator Defintion -->
    	<bean id="jdbcExceptionTranslator"
    		class="org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator">
    		<property name="dataSource">
    			<ref bean="dataSource" />
    		</property>
    	</bean>
    
    	<!-- DAO Definition&#58; Hibernate implementation -->
    	<bean id="kullaniciGirisDAO"
    		class="dao.impl.KullaniciGirisDAOImpl">
    		<property name="sessionFactory">
    			<ref bean="sessionFactory" />
    		</property>
    	</bean>
    	
    	<!-- ========================= Start of SERVICE DEFINITIONS ========================= -->
    
    	<!-- Hibernate Transaction Manager Definition -->
    	<bean id="transactionManager"
    		class="org.springframework.orm.hibernate.HibernateTransactionManager">
    		<property name="sessionFactory">
    			<ref local="sessionFactory" />
    		</property>
    	</bean>
    
    	<!-- User Service Definition -->
    	<bean id="kullaniciGirisServiceTarget"
    		class=services.impl.KullaniciGirisServicesImpl">
    		<property name="kullaniciGirisDAO">
    			<ref local="kullaniciGirisDAO" />
    		</property>
    	</bean>	
    
    	<!-- Transactional proxy for the User Service -->
    	<bean id="kullaniciGirisService"
    		class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    		<property name="transactionManager">
    			<ref local="transactionManager" />
    		</property>
    		<property name="target">
    			<ref local="kullaniciGirisServiceTarget" />
    		</property>
    		<property name="transactionAttributes">
    			<props>
    				<prop key="check*">PROPAGATION_REQUIRED,readOnly</prop>
    			</props>
    		</property>
    	</bean>	
    </beans>
    jUnit test class is:

    Code:
    public class LogServicesImplTest extends TestCase &#123;
    
        public static void main&#40;String&#91;&#93; args&#41; &#123;
            TestRunner.run&#40;LogServicesImplTest.class&#41;;
        &#125;
    
        public void test_Log&#40;&#41; &#123;
            try &#123;
                ApplicationContext xml = new ClassPathXmlApplicationContext&#40;"/test/testContext.xml"&#41;;
                DokumLogServicesImpl dokumLogServicesImpl = &#40;DokumLogServicesImpl&#41; xml
                        .getBean&#40;"kullaniciGirisService"&#41;;
    
      .....
    
            &#125; catch &#40;Exception e&#41; &#123;
                e.printStackTrace&#40;&#41;;
            &#125;
        &#125;
    &#125;
    Any suggestion.

    Thanks to everyone.

  • #2
    Can you try removing the DAO for a while and see if the transaction manager complains? It also has a refernece to the SF so if it doesn't complain there must be something wrong with your DAO (maybe private/protected methods, wrong method signatures for the SessionFactoryBean setter/getter?). Have you used the DaoSupport classes that come with Spring?

    rgds,
    Alef

    Comment

    Working...
    X