Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
package gov.va.oneconsult.seoc.api.repository;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import java.util.Set;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import gov.va.oneconsult.seoc.api.model.Hptc;
/**
* @author AbleVets
*/
@RunWith(SpringJUnit4ClassRunner.class)
@DataJpaTest
public class HptcRepositoryTest {
@Autowired
private HptcRepository HptcRepository;
@Autowired
private TestEntityManager entityManager;
private int initialSize = 0;
private int recordsCreated = 0;
private Hptc hptc = null;
@Before
public void setUp()
{
Set<Hptc>allHptcs = HptcRepository.findAllHptcs();
if (allHptcs != null)
{
initialSize = allHptcs.size();
}
hptc = new Hptc();
hptc.setHptc("hptc107");
hptc.setClassification("TYPE2");
hptc.setSpecialization("SPEC2");
hptc.setGrouping("GROUP2");
recordsCreated++;
entityManager.persist(hptc);
}
@After
public void tearDown()
{
entityManager.detach(hptc);
}
/**
* Description: Test Verify that Hptc object is persisted
*/
@Test
public void findAllHptc_Data()
{
int expectedSize = initialSize + recordsCreated;
Set<Hptc> allHptcData = HptcRepository.findAllHptcs();
assertThat(allHptcData.size()).isEqualTo(expectedSize);
}
/**
* Description: Test to verify that hptc collection is not null or empty.
*/
@Test
public void findAllHptc_IsNotNullOrEmpty()
{
Set<Hptc> allHptcData = HptcRepository.findAllHptcs();
assertThat(allHptcData).isNotEmpty();
assertThat(allHptcData).isNotNull();
}
/**
* Description: Verify if findByHptc returns Hptc object if it is existing
*/
@Test
public void findByHptc()
{
List<Hptc> expectedHptcs = HptcRepository.findByHptc("hptc107");
assertThat(expectedHptcs.size()).isEqualTo(1);
assertThat(expectedHptcs.get(0).getHptc()).isEqualTo("hptc107");
}
/**
* Description: Verify if findByHptc returns empty list if Hptc is not existing
*/
@Test
public void findByHptc_NotFound()
{
List<Hptc> expectedHptcs = HptcRepository.findByHptc("NoHptcLikeThis");
assertThat(expectedHptcs.size()).isEqualTo(0);
}
}