package com.hida.dao;

import com.hida.configuration.RepositoryConfiguration;
import com.hida.model.AutoId;
import com.hida.model.CustomId;
import com.hida.model.Pid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.testng.Assert;
import org.testng.annotations.Test;

/**
 * Tests the functionality of PidDao and ensures that it properly interacts with
 * Hibernate.
 *
 * @author lruffin
 */
@SpringApplicationConfiguration(classes = {RepositoryConfiguration.class})
@TestPropertySource(locations="classpath:testConfig.properties")
public class PidDaoImplTest {
        
    private PidRepository PidRepo;
        
    @Autowired
    public void setPidRepository(PidRepository PidRepo) {
        this.PidRepo = PidRepo;
    } 
        
    /**
     * Tests to see if Pid can be saved and found.
     */
    @Test
    public void testFindAndSave() {
        Pid autoSample = getSampleAutoId();
        Pid customSample = getSampleCustomId();
        
        PidRepo.save(autoSample);
        PidRepo.save(customSample);
                
        Pid autoEntity = PidRepo.findOne(autoSample.getName());
        Pid customEntity = PidRepo.findOne(customSample.getName());
        
        Assert.assertEquals(autoSample.getName(), autoEntity.getName());
        Assert.assertEquals(customSample.getName(), customEntity.getName());
    }

    /**
     * Tests to see if all the Pids can be listed and returned.
     */
    @Test
    public void testFindAllPids() {
        long size = PidRepo.count();                        
        
        Assert.assertEquals(size, 2);        
    }

    /**
     * Tests to see if AutoIds with the same name can be added to the database.
     */
    @Test
    public void testUniqueAutoId() {        
        Pid autoSample1 = getSampleAutoId();
        Pid autoSample2 = getSampleAutoId();

        PidRepo.save(autoSample1);
        PidRepo.save(autoSample2);
        
        long size = PidRepo.count();
        
        Assert.assertEquals(size, 2);
        
    }

    /**
     * Tests to see if CustomIds with the same name can be added to the
     * database.
     */
    @Test
    public void testUniqueCustomId() {
        Pid customSample1 = getSampleCustomId();
        Pid customSample2 = getSampleCustomId();

        PidRepo.save(customSample1);
        PidRepo.save(customSample2);
        
        long size = PidRepo.count();
        
        Assert.assertEquals(size, 2);
    }

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

        return sample;
    }

    /**
     * Returns a sample CustomId.
     *
     * @return
     */
    private Pid getSampleCustomId() {
        Pid sample = new CustomId("", new int[1], new String[]{"b"});
        sample.getName();

        return sample;
    }
    
    }

@@ -160,16 +160,96 @@
 el.Pid;%0A
+import org.junit.After;%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0A
 import o
@@ -447,21 +447,67 @@
 org.
-testng.Ass
+springframework.test.context.junit4.SpringJUnit4ClassRunn
 er
-t
 ;%0Aim
@@ -526,23 +526,13 @@
 tng.
-annotations.Tes
+Asser
 t;%0A%0A
@@ -656,16 +656,56 @@
 fin%0A */%0A
+@RunWith(SpringJUnit4ClassRunner.class)%0A
 @SpringA
@@ -800,17 +800,19 @@
 ocations
-=
+ = 
 %22classpa
@@ -868,24 +868,16 @@
 lTest %7B%0A
-        
 %0A    pri
@@ -904,24 +904,16 @@
 idRepo;%0A
-        
 %0A    @Au
@@ -1015,26 +1015,17 @@
 o;%0A    %7D
- %0A        
+%0A
 %0A    /**
@@ -1052,19 +1052,28 @@
  if 
+all the 
 Pid
+s
  can be 
 save
@@ -1072,22 +1072,26 @@
  be 
-sav
+list
 ed and 
-foun
+returne
 d.%0A 
@@ -1136,14 +1136,14 @@
 indA
-ndSave
+llPids
 () %7B
@@ -1231,32 +1231,24 @@
 CustomId();%0A
-        
 %0A        Pid
@@ -1310,448 +1310,8 @@
 e);%0A
-                %0A        Pid autoEntity = PidRepo.findOne(autoSample.getName());%0A        Pid customEntity = PidRepo.findOne(customSample.getName());%0A        %0A        Assert.assertEquals(autoSample.getName(), autoEntity.getName());%0A        Assert.assertEquals(customSample.getName(), customEntity.getName());%0A    %7D%0A%0A    /**%0A     * Tests to see if all the Pids can be listed and returned.%0A     */%0A    @Test%0A    public void testFindAllPids() %7B
 %0A   
@@ -1347,41 +1347,9 @@
 t();
-                        %0A        
+%0A
 %0A   
@@ -1382,24 +1382,16 @@
 ize, 2);
-        
 %0A    %7D%0A%0A
@@ -1532,24 +1532,16 @@
 toId() %7B
-        
 %0A       
@@ -1690,32 +1690,24 @@
 toSample2);%0A
-        
 %0A        lon
@@ -1728,32 +1728,24 @@
 po.count();%0A
-        
 %0A        Ass
@@ -1767,29 +1767,20 @@
 s(size, 
-2
+1
 );%0A
-        %0A
     %7D%0A%0A 
@@ -2105,24 +2105,16 @@
 mple2);%0A
-        
 %0A       
@@ -2143,24 +2143,16 @@
 ount();%0A
-        
 %0A       
@@ -2170,33 +2170,33 @@
 ertEquals(size, 
-2
+1
 );%0A    %7D%0A%0A    /*
@@ -2646,15 +2646,167 @@
   %7D%0A
-    
 %0A    
+/**%0A     * Deletes all entries in the in-memory database after each test%0A     */%0A    @After%0A    public void tearDown() %7B%0A        PidRepo.deleteAll();%0A    %7D%0A
 %7D%0A

Replace TestNg for Junit in PidDaoTest