package com.hida.dao;

import com.hida.model.AutoId;
import com.hida.model.CustomId;
import com.hida.model.Pid;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSet;
import org.hibernate.NonUniqueObjectException;
import org.springframework.beans.factory.annotation.Autowired;
import org.testng.Assert;
import org.testng.annotations.Test;

/**
 *
 * @author lruffin
 */
public class PidDaoImplTest extends EntityDaoImplTest {

    @Autowired
    PidDao PidDao;

    /**
     *
     * @return @throws Exception
     */
    @Override
    protected IDataSet getDataSet() throws Exception {
        IDataSet dataSet = new FlatXmlDataSet(this.getClass().getClassLoader().
                getResourceAsStream("Pid.xml"));
        return dataSet;
    }

    /**
     *
     */
    @Test
    public void testFindByName() {
        Pid entity1 = PidDao.findByName("1");
        Pid entity2 = PidDao.findByName("2");
        Assert.assertNotNull(entity1);
        Assert.assertNotNull(entity2);
    }

    /**
     * missing javadoc
     *
     */
    @Test
    public void testSavePid() {
        Pid autoSample = getSampleAutoId();
        Pid customSample = getSampleCustomId();

        PidDao.savePid(autoSample);
        PidDao.savePid(customSample);

        Assert.assertEquals(PidDao.findAllPids().size(), 4);
    }        

    /**
     * missing javadoc
     *
     */
    @Test
    public void testFindAllPids() {
        int size = PidDao.findAllPids().size();
        
        Assert.assertEquals(size, 2);
    }
    
    /**
     * 
     */
    @Test(expectedExceptions = NonUniqueObjectException.class)
    public void testNonUniqueObjectExceptionWithAutoId(){
        Pid autoSample1 = getSampleAutoId();
        Pid autoSample2 = getSampleAutoId();
        
        PidDao.savePid(autoSample1);
        PidDao.savePid(autoSample2);
    }
    
    /**
     * 
     */
    @Test(expectedExceptions = NonUniqueObjectException.class)
    public void testNonUniqueObjectExceptionWithCustomId(){
        Pid customSample1 = getSampleCustomId();
        Pid customSample2 = getSampleCustomId();
        
        PidDao.savePid(customSample1);
        PidDao.savePid(customSample2);
    }

    private Pid getSampleAutoId() {
        Pid sample = new AutoId("", new int[1], "a");
        sample.getName();

        return sample;
    }

    private Pid getSampleCustomId() {
        Pid sample = new CustomId("", new int[1], new String[]{"b"});
        sample.getName();

        return sample;
    }

}

@@ -364,16 +364,111 @@
 t;%0A%0A/**%0A
+ * Tests the functionality of PidDao and ensures that it properly interacts with%0A * Hibernate.%0A
  *%0A * @a
@@ -595,23 +595,100 @@
    *
-%0A     * @return
+ Retrieves data from an xml file sheet to mock Pids.%0A     *%0A     * @return a data set%0A     *
  @th
@@ -949,24 +949,77 @@
   /**%0A     *
+ Tests to see if PidDao can find an Pid by it's name.
 %0A     */%0A   
@@ -1252,38 +1252,49 @@
 %0A     * 
-missing javadoc%0A     *
+Tests to see if Pid can be saved.
 %0A     */
@@ -1570,24 +1570,16 @@
 );%0A    %7D
-        
 %0A%0A    /*
@@ -1591,30 +1591,64 @@
   * 
-missing javadoc%0A     *
+Tests to see if all the Pids can be listed and returned.
 %0A   
@@ -1742,32 +1742,24 @@
 s().size();%0A
-        
 %0A        Ass
@@ -1783,36 +1783,32 @@
 size, 2);%0A    %7D%0A
-    
 %0A    /**%0A     * 
@@ -1799,32 +1799,104 @@
 %0A    /**%0A     * 
+Tests to see if AutoIds with the same name can be added to the database.
 %0A     */%0A    @Te
@@ -2003,24 +2003,25 @@
 WithAutoId()
+ 
 %7B%0A        Pi
@@ -2096,32 +2096,24 @@
 leAutoId();%0A
-        
 %0A        Pid
@@ -2181,20 +2181,16 @@
 ;%0A    %7D%0A
-    
 %0A    /**
@@ -2197,16 +2197,97 @@
 %0A     * 
+Tests to see if CustomIds with the same name can be added to the%0A     * database.
 %0A     */
@@ -2408,16 +2408,17 @@
 stomId()
+ 
 %7B%0A      
@@ -2509,24 +2509,16 @@
 omId();%0A
-        
 %0A       
@@ -2587,32 +2587,102 @@
 ample2);%0A    %7D%0A%0A
+    /**%0A     * returns a sample AutoId.%0A     *%0A     * @return%0A     */%0A
     private Pid 
@@ -2808,24 +2808,96 @@
 ple;%0A    %7D%0A%0A
+    /**%0A     * Returns a sample CustomId.%0A     *%0A     * @return%0A     */%0A
     private 

Add javadocs to PidDaoImplTest