Skip to Content
0
Former Member
Jul 02, 2015 at 02:54 PM

Test case bean cannot be found

497 Views

Hello Experts

I am developing a new extension following the documentation, and while I conduct the TDD approach via documentation(https://wiki.hybris.com/display/R5T/Trail+~+Testing+the+DAO) the bean cannot be found. Can you help me out what I am missing

Thanks

myextension-beans.xml

 <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:context="http://www.springframework.org/schema/context"
     xsi:schemaLocation="http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/context
            http://www.springframework.org/schema/context/spring-context-3.1.xsd">
 
     <context:component-scan base-package="com.tugrulaslan" />
 
 </beans>

myextension-items.xml

 <itemtypes>
     <itemtype code="Person" generate="true" autocreate="true">
         <deployment table="HRPerson" typecode="10241" />
         <attributes>
             <attribute type="java.lang.Integer" qualifier="candidateID">
                 <persistence type="property" />
                 <modifiers optional="false" unique="true" />
             </attribute>
             <attribute type="java.lang.String" qualifier="candidateName">
                 <persistence type="property" />
                 <modifiers optional="false" unique="true" />
             </attribute>
             <attribute type="java.lang.String" qualifier="candidateLastName">
                 <persistence type="property" />
                 <modifiers optional="false" unique="true" />
             </attribute>
         </attributes>
     </itemtype>

 

HRDAO

 public interface HRDAO
 {
     List<PersonModel> listPersons();
 
 }

DefaultHRDao

 @Component(value = "hrDAO")
 public class DefaultHRDao implements HRDAO
 {
 
     @Autowired
     private FlexibleSearchService searchService;
 
 
     /*
      * (non-Javadoc)
      * 
      * @see com.tugrulaslan.daos.HRDAO#listPersons()
      */
     @Override
     public List<PersonModel> listPersons()
     {
         // YTODO Auto-generated method stub
         final String q = "select {p:" + PersonModel.PK + "}" + "FROM{" + PersonModel._TYPECODE + " AS p";
         final FlexibleSearchQuery query = new FlexibleSearchQuery(q);
         return searchService.<PersonModel> search(query).getResult();
     }
 
 }


HRDAOIntegrationTest

 public class HRDAOIntegrationTest extends ServicelayerTransactionalTest
 {
     @Resource
     private HRDAO hrDAO;
 
     @Resource
     private ModelService modelService;
 
     private final static String personName = "Tugrul";
 
     private final static Integer personId = Integer.valueOf(123456);
 
     @Test
     public void hrDAOTest()
     {
         final List<PersonModel> persons = hrDAO.listPersons();
         assertTrue(persons.isEmpty());
 
     }
 
 }


Error message

 ERROR [main] (junit) [ServicelayerBaseTest] error fetching bean hrDAO : No bean named 'hrDAO' is defined
 org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'hrDAO' is defined
     at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:694)
     at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1168)
     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:281)
     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)

if I issue ant all this is what I eventually get

 ERROR BeanGenerator -  Cannot find the declaration of element 'beans'. Syntax error occurred at line :10, column :60. Problem found during processing the file C:\hybris\bin\custom\myextension\resources\myextension-beans.xml for extension <myextension>