package com.hida.dao;

import com.hida.model.TokenType;
import com.hida.model.UsedSetting;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.Test;

/**
 * Tests the functionality of UsedSettingDaoImpl.
 *
 * @author lruffin
 */
public class UsedSettingDaoImplTest extends EntityDaoImplTest {

    @Autowired
    UsedSettingDao UsedSettingDao;

    /**
     * Returns a data set that Hibernate assumes to be in persistence.
     *
     * @return
     * @throws Exception
     */
    @Override
    protected IDataSet getDataSet() throws Exception {
        IDataSet dataSet = new FlatXmlDataSet(this.getClass().getClassLoader().
                getResourceAsStream("UsedSetting.xml"));

        return dataSet;
    }

    /**
     * Tests the functionality of UsedSettingDao save.
     */
    @Test
    public void saveTest() {
        UsedSettingDao.save(getSampleUsedSetting());
        Assert.assertEquals(UsedSettingDao.findAllUsedSettings().size(), 2);
    }

    /**
     * Tests to see if UsedSettingDao can find an entity by it's id.
     */
    @Test
    public void findUsedSettingByIdTest() {
        UsedSetting entity = UsedSettingDao.findUsedSettingById(1);
        Assert.assertNotNull(entity);
    }

    /**
     * Tests to see if UsedSettingDao can list and return all the UsedSetting
     * lists.
     */
    @Test
    public void findAllUsedSettingsTest() {
        int size = UsedSettingDao.findAllUsedSettings().size();
        Assert.assertEquals(size, 1);
    }

    /**
     * Attempts to find a UsedSetting by the fields. 
     */
    @Test
    public void findUsedSettingTest() {
        UsedSetting sampleSetting = getSampleUsedSetting();
        UsedSetting entity = UsedSettingDao.findUsedSetting(sampleSetting);
        Assert.assertNotNull(entity);
    }

    /**
     * Returns a sample UsedSetting entity.
     *
     * @return
     */
    private UsedSetting getSampleUsedSetting() {
        UsedSetting setting = new UsedSetting("",
                TokenType.DIGIT,
                "d",
                1,
                true,
                1);

        return setting;
    }
}

@@ -84,16 +84,43 @@
 etting;%0A
+import java.util.Iterator;%0A
 import o
@@ -139,32 +139,32 @@
 taset.IDataSet;%0A
-
 import org.dbuni
@@ -479,24 +479,32 @@
 towired%0A    
+private 
 UsedSettingD
@@ -521,16 +521,87 @@
 tingDao;
+%0A    %0A    @Autowired%0A    private UsedSettingRepository UsedSettingRepo;
 %0A%0A    /*
@@ -1076,32 +1076,38 @@
 est() %7B%0A        
+final 
 UsedSettingDao.s
@@ -1105,17 +1105,19 @@
 ting
-Dao.save(
+ setting = 
 getS
@@ -1134,17 +1134,16 @@
 etting()
-)
 ;%0A      
@@ -1148,50 +1148,73 @@
     
-Assert.assertEquals(UsedSettingDao.findAll
+setting.setId(1);%0A        %0A        UsedSettingRepo.save(getSample
 Used
@@ -1224,21 +1224,119 @@
 ting
-s
 ()
-.size(), 2
+);%0A        UsedSetting entity = UsedSettingRepo.findOne(setting.getId());%0A        Assert.assertNotNull(entity
 );%0A 
@@ -1524,31 +1524,20 @@
 ting
-Da
+Rep
 o.find
-UsedSettingById
+One
 (1);
@@ -1756,16 +1756,38 @@
     
-int size
+Iterator%3CUsedSetting%3E iterator
  = U
@@ -1792,26 +1792,27 @@
  UsedSetting
-Da
+Rep
 o.findAllUse
@@ -1812,30 +1812,156 @@
 dAll
-UsedSettings().size();
+().iterator();%0A        %0A        int size = 0;%0A        while(iterator.hasNext())%7B%0A            iterator.next();%0A            size++;%0A        %7D%0A        
 %0A   
@@ -2222,18 +2222,19 @@
 dSetting
-Da
+Rep
 o.findUs

Use Dao-equivalent Repo in UsedDaoTest