Hybris Learning Note: Trail ~ Testing the DAO

Source: Internet
Author: User

In the previous exercise, the data model was defined by Xxx-items.xml, and the system was updated (in order to update the definition of the database table) in the HMC management interface, and the information was added (Popuulate the model).

After this exercise, the data is accessed through Java code.


In this chapter, we will test the results of the previous exercises through test-driven development testing driven development, or TDD.

Ready to initialize the JUnit tenent in the Hybris admin interface

Writing DAO's Interface code

Write the DAO's test code (note that this is the first to write the test code, and then write the implementation code ~~~~~~~~)

Write the DAO Implementation code-this uses the Hybris ' flexible Search query, the specific Query syntax depends on the training ppt handout, or the Hybris wiki site

Performing JUnit Tests


===============================================

The test above will fail because in the integration test code, the call to Stadiumdao is not generated in my test code and invoked, but instead is generated with the spring framework, which I then use.

The specific test code snippet is as follows:

@Resource//If the comment is applied to a field or method, the container (Spring) injects an instance of the requested resource into it when the application component is initialized. Private Stadiumdao Stadiumdao
@Test
public void Stadiumdaotest ()
{
list<stadiummodel> Stadiumsbycode = Stadiumdao.findstadiumsbycode (stadium_name); Note that there is no way to generate Stadiumdao objects directly using the

The specific Defaultstadiumdao implementation code is as follows: @Component (value = "Stadiumdao")
public class Defaultstadiumdao implements Stadiumdao

How do I get hybris/spring to generate this object? English: This is telling Spring, we have a beans called Stadiumdao that it can use for wiring. However we need to tell Spring, it should browse this package to find the annotation. To does this we need to add a context:component-scan tag to Cuppy-trail's application context, as described by Spring her E in their discussion on the component-scan tag

English: Modify the Hybrpis cupptytail-spring.xml file, configure the Bean-dao implementation Class (code) in the spring framework
<context:component-scan base-package= "De.hybris.platform.cuppytrail"/>

Reference: Spring container build Annotations @component and resouces implement full annotation configuration http://www.2cto.com/kf/201206/137806.html

-------------------------------------------------my question: Why does the Stadiumdao need to do a class scan, and the Stadiumservice in the later exercises do not need to be scanned, Instead, it is defined by the bean. There are two ways to do this. The difference is where it is. To yourself: The possible answer is that there is no @Component (value = "xxxxx") in the Defaultstadiumservice code public class Defaultstadiumservice implements Stadiumservice

The following is the spring bean Life of Stadiumservice: <alias name= "Defaultstadiumservice" alias= "Stadiumservice"/>
<bean id= "Defaultstadiumservice" class= "De.hybris.platform.cuppytrail.impl.DefaultStadiumService" >
<property name= "Stadiumdao" ref= "Stadiumdao"/>
</bean>

===============================================

Java mockup Test Reference: 5 minutes to learn about Mockitto

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.