package com.hida.repositories;

import com.hida.configuration.RepositoryConfiguration;
import com.hida.model.AutoId;
import com.hida.model.CustomId;
import com.hida.model.Pid;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.testng.Assert;

/**
 * Tests the functionality of PidDao and ensures that it properly interacts with
 * Hibernate.
 *
 * @author lruffin
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = {RepositoryConfiguration.class})
@TestPropertySource(locations = "classpath:testConfig.properties")
public class PidRepositoryTest {

    private PidRepository PidRepo;

    @Autowired
    public void setPidRepository(PidRepository PidRepo) {
        this.PidRepo = PidRepo;
    }

    /**
     * Tests to see if all the Pids can be listed and returned.
     */
    @Test
    public void testFindAllPids() {
        Pid autoSample = getSampleAutoId();
        Pid customSample = getSampleCustomId();

        PidRepo.save(autoSample);
        PidRepo.save(customSample);

        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, 1);
    }

    /**
     * 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, 1);
    }

    /**
     * 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;
    }

    /**
     * Deletes all entries in the in-memory database after each test
     */
    @After
    public void tearDown() {
        PidRepo.deleteAll();
    }
}

@@ -84,70 +84,8 @@
 on;%0A
-import com.hida.model.AutoId;%0Aimport com.hida.model.CustomId;%0A
 impo
@@ -1089,24 +1089,35 @@
 AllPids() %7B%0A
+        /*%0A
         Pid 
@@ -1352,106 +1352,25 @@
     
-%7D%0A%0A
     
-/*
 *
+/
 %0A    
- * Tests to see if AutoIds with the same name can be added to the database.
+%7D
 %0A    
- */
 %0A   
@@ -1404,19 +1404,15 @@
 Uniq
-ueAutoId
+eness
 ()
- 
 %7B%0A  
@@ -1421,349 +1421,144 @@
     
-Pid autoSample1 = getSampleAutoId();%0A        Pid autoSample2 = getSampleAutoId();%0A
+Assert.fail(%22unimplemented%22);%0A    %7D
 %0A    
+%0A
     
-PidRepo.save(autoSample1);%0A        PidRepo.save(autoSample2);%0A%0A        long size = PidRepo.count();%0A%0A        Assert.assertEquals(size, 1);%0A    %7D%0A%0A    /**%0A     * Tests to see if CustomIds with the same name can be added to the%0A     * database.
+@Test%0A    public void testSaveAndDelete()%7B%0A        Assert.fail(%22unimplemented%22);%0A    %7D
 %0A    
- */
 %0A   
@@ -1588,75 +1588,21 @@
 test
-UniqueCustomId() %7B%0A        Pid customSample1 = getSampleCustomId();
+FindByName()%7B
 %0A   
@@ -1610,277 +1610,54 @@
     
-Pid customSample2 = getSampleCustomId();%0A%0A        PidRepo.save(customSample1);%0A        PidRepo.save(customSample2);%0A%0A        long size = PidRepo.count();%0A%0A        Assert.assertEquals(size, 1);%0A    %7D%0A%0A    /**%0A     * returns a sample AutoId.%0A     *%0A     * @return%0A     */
+Assert.fail(%22unimplemented%22);%0A    %7D      %0A    
 %0A   
@@ -1682,17 +1682,13 @@
 mple
-AutoI
+Pi
 d()
- 
 %7B%0A  
@@ -1714,27 +1714,20 @@
 new 
-AutoId(%22%22, 
+Pid(
 new int%5B
 1%5D, 
@@ -1726,14 +1726,16 @@
 int%5B
-1
 %5D
+ %7B1%7D
 , %22
-a
 %22);%0A
@@ -1753,256 +1753,30 @@
 ple.
-g
+s
 etName(
-);%0A%0A        return sample;%0A    %7D%0A%0A    /**%0A     * Returns a sample CustomId.%0A     *%0A     * @return%0A     */%0A    private Pid getSampleCustomId() %7B%0A        Pid sample = new CustomId(%22%22, new int%5B1%5D, new String%5B%5D%7B%22b%22%7D);%0A        sample.getName();%0A
+%22a%22);%0A        
 %0A   

Remove references to AutoId and CustomId