Dao Test Help.

4 messages Options
Embed this post
Permalink
shendel_18

Dao Test Help.

Reply Threaded More More options
Print post
Permalink

Hello, I'm trying to check the size of the return list in one of my
method in DAO. But it always return 0;
When executing "mvn test -Dtest=NameDaoTest" does it create and populate
new data in my database? I noticed that all my data in database is gone.
I guest it automatically call the "mvn hibernate3:hbm2ddl
dbunit:operation".. how can i bypass it so that i can retrieve data in
my database. I am expecting the size of the list to be 142882 and i want
to put assert in my test. Here is my code

DaoTest:

 public void testGetProduct() {
        for(int i = 1; i <= 5; i++) {
            List countries =
groupProductDao.findByServiceIdAndSubList("6561", "U");
            assertEquals(countries.size(),142882);
       
        }
    }

DaoHibernate:

    public List<GroupProduct> findByServiceIdAndSubList(String
serviceId, String subList) {
        Long serviceIdLong = Long.valueOf(serviceId);
        List<GroupProduct> gpDTOList = new ArrayList<GroupProduct>();

        if (subList.equals("")) {
            List<String> descList = new ArrayList<String>();  
            descList = getHibernateTemplate().find("select description
from GroupProduct where version=0 and serviceID=? order by description
asc", serviceIdLong);
            if (descList.size() != 0) {
                subList = descList.get(0).substring(0,1);
            }
        }
        gpDTOList = getHibernateTemplate().find("from GroupProduct where
version=0 and serviceID=? and description like '"+subList+"%' order by
description asc", serviceIdLong);

         return gpDTOList;
    }



Please help..






---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

mraible

Re: Dao Test Help.

Reply Threaded More More options
Print post
Permalink
The tests rollback any transactions that modified data when you're in
the database. However, if you're only doing a get, it should work
fine. Does your sample-data.xml populate the database with 142,882
countries?

Matt

On Mon, Oct 19, 2009 at 2:07 AM, Nelson Biasura
<[hidden email]> wrote:

>
> Hello, I'm trying to check the size of the return list in one of my method
> in DAO. But it always return 0;
> When executing "mvn test -Dtest=NameDaoTest" does it create and populate new
> data in my database? I noticed that all my data in database is gone.
> I guest it automatically call the "mvn hibernate3:hbm2ddl
> dbunit:operation".. how can i bypass it so that i can retrieve data in my
> database. I am expecting the size of the list to be 142882 and i want to put
> assert in my test. Here is my code
>
> DaoTest:
>
> public void testGetProduct() {
>       for(int i = 1; i <= 5; i++) {
>           List countries = groupProductDao.findByServiceIdAndSubList("6561",
> "U");
>           assertEquals(countries.size(),142882);
>             }
>   }
>
> DaoHibernate:
>
>   public List<GroupProduct> findByServiceIdAndSubList(String serviceId,
> String subList) {
>       Long serviceIdLong = Long.valueOf(serviceId);
>       List<GroupProduct> gpDTOList = new ArrayList<GroupProduct>();
>
>       if (subList.equals("")) {
>           List<String> descList = new ArrayList<String>();
> descList = getHibernateTemplate().find("select description from GroupProduct
> where version=0 and serviceID=? order by description asc", serviceIdLong);
>           if (descList.size() != 0) {
>               subList = descList.get(0).substring(0,1);
>           }
>       }
>       gpDTOList = getHibernateTemplate().find("from GroupProduct where
> version=0 and serviceID=? and description like '"+subList+"%' order by
> description asc", serviceIdLong);
>
>        return gpDTOList;
>   }
>
>
>
> Please help..
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

shendel_18

Re: Dao Test Help.

Reply Threaded More More options
Print post
Permalink
No, i don't use sample-data.xml to populate it. I populated my database
using sql file that i created
from mysqldump. What do you mean "if you're only doing a get, it should
work fine"?..

Thanks a lot Matt.


Matt Raible wrote:

> The tests rollback any transactions that modified data when you're in
> the database. However, if you're only doing a get, it should work
> fine. Does your sample-data.xml populate the database with 142,882
> countries?
>
> Matt
>
> On Mon, Oct 19, 2009 at 2:07 AM, Nelson Biasura
> <[hidden email]> wrote:
>  
>> Hello, I'm trying to check the size of the return list in one of my method
>> in DAO. But it always return 0;
>> When executing "mvn test -Dtest=NameDaoTest" does it create and populate new
>> data in my database? I noticed that all my data in database is gone.
>> I guest it automatically call the "mvn hibernate3:hbm2ddl
>> dbunit:operation".. how can i bypass it so that i can retrieve data in my
>> database. I am expecting the size of the list to be 142882 and i want to put
>> assert in my test. Here is my code
>>
>> DaoTest:
>>
>> public void testGetProduct() {
>>       for(int i = 1; i <= 5; i++) {
>>           List countries = groupProductDao.findByServiceIdAndSubList("6561",
>> "U");
>>           assertEquals(countries.size(),142882);
>>             }
>>   }
>>
>> DaoHibernate:
>>
>>   public List<GroupProduct> findByServiceIdAndSubList(String serviceId,
>> String subList) {
>>       Long serviceIdLong = Long.valueOf(serviceId);
>>       List<GroupProduct> gpDTOList = new ArrayList<GroupProduct>();
>>
>>       if (subList.equals("")) {
>>           List<String> descList = new ArrayList<String>();
>> descList = getHibernateTemplate().find("select description from GroupProduct
>> where version=0 and serviceID=? order by description asc", serviceIdLong);
>>           if (descList.size() != 0) {
>>               subList = descList.get(0).substring(0,1);
>>           }
>>       }
>>       gpDTOList = getHibernateTemplate().find("from GroupProduct where
>> version=0 and serviceID=? and description like '"+subList+"%' order by
>> description asc", serviceIdLong);
>>
>>        return gpDTOList;
>>   }
>>
>>
>>
>> Please help..
>>
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>>    
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>  


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

mraible

Re: Dao Test Help.

Reply Threaded More More options
Print post
Permalink
By default, DbUnit does a CLEAN_INSERT, which means it wipes out your
data and populates your database with what's in sample-data.xml. If
you want to change this, modify the following property:

<dbunit.operation.type>CLEAN_INSERT</dbunit.operation.type>

Options are as follows:

http://mojo.codehaus.org/dbunit-maven-plugin/operation-mojo.html#type

Matt

On Mon, Oct 19, 2009 at 7:30 PM, Nelson Biasura
<[hidden email]> wrote:

> No, i don't use sample-data.xml to populate it. I populated my database
> using sql file that i created
> from mysqldump. What do you mean "if you're only doing a get, it should work
> fine"?..
>
> Thanks a lot Matt.
>
>
> Matt Raible wrote:
>>
>> The tests rollback any transactions that modified data when you're in
>> the database. However, if you're only doing a get, it should work
>> fine. Does your sample-data.xml populate the database with 142,882
>> countries?
>>
>> Matt
>>
>> On Mon, Oct 19, 2009 at 2:07 AM, Nelson Biasura
>> <[hidden email]> wrote:
>>
>>>
>>> Hello, I'm trying to check the size of the return list in one of my
>>> method
>>> in DAO. But it always return 0;
>>> When executing "mvn test -Dtest=NameDaoTest" does it create and populate
>>> new
>>> data in my database? I noticed that all my data in database is gone.
>>> I guest it automatically call the "mvn hibernate3:hbm2ddl
>>> dbunit:operation".. how can i bypass it so that i can retrieve data in my
>>> database. I am expecting the size of the list to be 142882 and i want to
>>> put
>>> assert in my test. Here is my code
>>>
>>> DaoTest:
>>>
>>> public void testGetProduct() {
>>>      for(int i = 1; i <= 5; i++) {
>>>          List countries =
>>> groupProductDao.findByServiceIdAndSubList("6561",
>>> "U");
>>>          assertEquals(countries.size(),142882);
>>>            }
>>>  }
>>>
>>> DaoHibernate:
>>>
>>>  public List<GroupProduct> findByServiceIdAndSubList(String serviceId,
>>> String subList) {
>>>      Long serviceIdLong = Long.valueOf(serviceId);
>>>      List<GroupProduct> gpDTOList = new ArrayList<GroupProduct>();
>>>
>>>      if (subList.equals("")) {
>>>          List<String> descList = new ArrayList<String>();
>>> descList = getHibernateTemplate().find("select description from
>>> GroupProduct
>>> where version=0 and serviceID=? order by description asc",
>>> serviceIdLong);
>>>          if (descList.size() != 0) {
>>>              subList = descList.get(0).substring(0,1);
>>>          }
>>>      }
>>>      gpDTOList = getHibernateTemplate().find("from GroupProduct where
>>> version=0 and serviceID=? and description like '"+subList+"%' order by
>>> description asc", serviceIdLong);
>>>
>>>       return gpDTOList;
>>>  }
>>>
>>>
>>>
>>> Please help..
>>>
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]