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
/*
* SeocRepositoryTest.java
* Copyright (c) 2017 Veterans Affairs.
*/
package gov.va.oneconsult.seoc.api.repository;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
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.controller.SeocObjectGenerator;
import gov.va.oneconsult.seoc.api.model.BillingCode;
import gov.va.oneconsult.seoc.api.model.CategoryOfCare;
import gov.va.oneconsult.seoc.api.model.ClinicalService;
import gov.va.oneconsult.seoc.api.model.Hptc;
import gov.va.oneconsult.seoc.api.model.PayableService;
import gov.va.oneconsult.seoc.api.model.Qasp;
import gov.va.oneconsult.seoc.api.model.Seoc;
import gov.va.oneconsult.seoc.api.model.ServiceLine;
import gov.va.oneconsult.seoc.api.model.Status;
import gov.va.oneconsult.seoc.api.util.ApiUtil;
import gov.va.oneconsult.seoc.api.util.Constants;
import gov.va.oneconsult.seoc.api.util.TestUtil;
/**
* Description: SeocRepository Level Test Cases
*
* @author AbleVets
*/
@RunWith(SpringJUnit4ClassRunner.class)
@DataJpaTest
public class SeocRepositoryTest {
@Autowired
private SeocRepository seocRepository;
@Autowired
private StatusRepository statusRepository;
@Autowired
private BillingCodeRepository billingCodeRepo;
@Autowired
private PayableServiceRepository serviceRepository;
@Autowired
private TestEntityManager entityManager;
private String TEST_SEOC_NAME = "SEOCTEST 1.0.2";
private int TEST_SEOC_SEOCKEY = 5;
private int TEST_SEOC_SEOCKEY1 = 15;
private int TEST_SEOC_SEOCKEY2 = 25;
private int TEST_SEOC_SEOCKEY3 = 35;
private CategoryOfCare coc = null;
private CategoryOfCare anotherCoc = null;
private ServiceLine sl = null;
private Qasp q = null;
private ClinicalService cs = null;
private Status draft = null;
private Status dateHold = null;
private Status inprogress = null;
private Status active = null;
private Seoc seocTest = null;
private Seoc seocKey1Active = null;
private Seoc seocKey1Discontinued = null;
private Seoc seocKey2DateHold = null;
private Seoc seocKey2Inprogress = null;
private Seoc seocKey3Inprogress = null;
private int initialSize = 0;
private Hptc hptc1 = null;
private Set<Seoc> initialActiveSeocs = null;
private Set<ClinicalService> clinicalServices = new HashSet<ClinicalService>();
/**
* Description:SetUp method run before each test case
*/
@Before
public void setUp() {
sl = new ServiceLine();
sl.setId(100);
sl.setServiceAbbreviation("ABR");
sl.setDescription("TestServiceLine");
coc = new CategoryOfCare();
coc.setId(100);
coc.setDescription("TestCategoryOfCare");
coc.setServiceLine(sl);
anotherCoc = new CategoryOfCare();
anotherCoc.setId(101);
anotherCoc.setDescription("CategoryOfCare");
anotherCoc.setServiceLine(sl);
q = new Qasp();
q.setId(100);
q.setDescription("TestQasp");
cs = new ClinicalService();
cs.setId(100);
cs.setDescription("TestClinicalService");
draft = new Status();
draft.setId(100);
draft.setDescription("TestDraft");
hptc1 = new Hptc();
hptc1.setHptc("hptc107");
hptc1.setSpecialization("Spec");
hptc1.setClassification("Classification");
hptc1.setGrouping("");
Set<Hptc> hptcs = new HashSet<Hptc>();
hptcs.add(hptc1);
entityManager.persist(sl);
entityManager.persist(coc);
entityManager.persist(cs);
entityManager.persist(draft);
entityManager.persist(q);
dateHold = statusRepository.findByDescription(Constants.STATUS_DATEHOLD);
inprogress = statusRepository.findByDescription(Constants.STATUS_INPROGRESS);
active = statusRepository.findByDescription(Constants.STATUS_ACTIVE);
// Create a seoc record for testing
seocTest = SeocObjectGenerator.getSeoc(TEST_SEOC_NAME, TEST_SEOC_SEOCKEY, null, null, null, "disclaimer", 6,
"description", false, "proceduralOverview", 10, null, null, null, null, coc, sl, draft, q, null);
// Seockey 1 active Seoc
Date effectiveDate = ApiUtil.getUTCZoneDateTime("09-07-2018 05:01:00 AM");
Date endDate = ApiUtil.getUTCZoneDateTime("09-10-2018 05:01:00 AM");
seocKey1Active = SeocObjectGenerator.getSeoc("SeocKey1", TEST_SEOC_SEOCKEY1, "1.1.2", effectiveDate, null,
"disclaimer", 6, "description", false, "proceduralOverview", 10, effectiveDate, null, null, null, coc,
sl, dateHold, q, null);
BillingCode bc1 = findByBillingCodeCall("code101");
Set<BillingCode> billingCodes = new HashSet<BillingCode>();
billingCodes.add(bc1);
clinicalServices.add(cs);
PayableService service2 = SeocObjectGenerator.getPayableService("Service", 4, "weeks", 5, "YES", null, null,
clinicalServices, seocKey1Active, new HashSet<BillingCode>());
service2.getBillingCodes().add(bc1);
List<PayableService> services = new ArrayList<PayableService>();
services.add(service2);
seocKey1Active.setServices(services);
seocKey1Active.setHptcs(hptcs);
// Seockey 1 discontinued Seoc
seocKey1Discontinued = SeocObjectGenerator.getSeoc("SeocKey1", TEST_SEOC_SEOCKEY1, "1.1.1", effectiveDate,
endDate, "disclaimer", 6, "description", false, "proceduralOverview", 10, effectiveDate, null, endDate,
null, coc, sl, dateHold, q, null);
bc1 = findByBillingCodeCall("code102");
billingCodes = new HashSet<BillingCode>();
billingCodes.add(bc1);
service2 = SeocObjectGenerator.getPayableService("Service", 4, "weeks", 5, "YES", null, null, clinicalServices,
seocKey1Discontinued, new HashSet<BillingCode>());
service2.getBillingCodes().add(bc1);
services = new ArrayList<PayableService>();
services.add(service2);
seocKey1Discontinued.setServices(services);
seocKey1Discontinued.setHptcs(hptcs);
// Seockey 2 datehold Seoc
Date tomorrow = TestUtil.getEffectiveDate();
seocKey2DateHold = SeocObjectGenerator.getSeoc("SeocKey2", TEST_SEOC_SEOCKEY2, "1.1.1", tomorrow, null,
"disclaimer", 6, "description", false, "proceduralOverview", 10, tomorrow, null, null, null, coc, sl,
active, q, null);
bc1 = findByBillingCodeCall("code103");
billingCodes = new HashSet<BillingCode>();
billingCodes.add(bc1);
service2 = SeocObjectGenerator.getPayableService("Service", 4, "weeks", 5, "YES", null, null, clinicalServices,
seocKey2DateHold, new HashSet<BillingCode>());
service2.getBillingCodes().add(bc1);
services = new ArrayList<PayableService>();
services.add(service2);
seocKey2DateHold.setServices(services);
// Seockey 2 inprogress Seoc
seocKey2Inprogress = SeocObjectGenerator.getSeoc("SeocKey2", TEST_SEOC_SEOCKEY2, null, null, null, "disclaimer",
6, "description", false, "proceduralOverview", 10, null, null, null, null, coc, sl, inprogress, q,
null);
// Seockey 3 inprogress Seoc
seocKey3Inprogress = SeocObjectGenerator.getSeoc("SeocKey2", TEST_SEOC_SEOCKEY3, "1.0.1", null, null,
"disclaimer", 6, "description", false, "proceduralOverview", 10, null, null, null, null, coc, sl,
inprogress, q, null);
bc1 = findByBillingCodeCall("code103");
billingCodes = new HashSet<BillingCode>();
billingCodes.add(bc1);
service2 = SeocObjectGenerator.getPayableService("Service", 4, "weeks", 5, "YES", null, null, clinicalServices,
seocKey3Inprogress, new HashSet<BillingCode>());
service2.getBillingCodes().add(bc1);
services = new ArrayList<PayableService>();
services.add(service2);
seocKey3Inprogress.setServices(services);
entityManager.persist(seocKey1Active);
entityManager.persist(seocKey1Discontinued);
entityManager.persist(seocKey2DateHold);
entityManager.persist(seocKey2Inprogress);
Set<Seoc> allSeocs = seocRepository.findAllSeocs();
// find the number of seocs available in the DB before starting the test case
if (allSeocs != null) {
initialSize = allSeocs.size();
initialActiveSeocs = allSeocs.stream().filter(s -> s.getCalculatedStatus().equals(Constants.STATUS_ACTIVE))
.collect(Collectors.toSet());
}
// Persist the test seoc
entityManager.persist(seocTest);
}
/**
* Description:TearDown to be run after each test case.
*/
@After
public void tearDown() {
// Detach the test seoc after unit testing
entityManager.detach(seocTest);
entityManager.detach(seocKey1Active);
entityManager.detach(seocKey1Discontinued);
entityManager.detach(seocKey2DateHold);
entityManager.detach(seocKey2Inprogress);
entityManager.detach(cs);
entityManager.detach(draft);
entityManager.detach(coc);
entityManager.detach(sl);
entityManager.detach(q);
}
@Test
public void findActiveSeocs() {
Set<Seoc> activeSeocsBefore = seocRepository.findActiveSeocs();
assertThat(initialActiveSeocs).hasSameSizeAs(activeSeocsBefore);
// Datehold
Date effectiveDate = TestUtil.getEffectiveDate();
Seoc seocWithDateHold = SeocObjectGenerator.getSeoc("SeocKeyDateHold", TEST_SEOC_SEOCKEY2, "1.1.3",
effectiveDate, null, "disclaimer", 6, "description", false, "proceduralOverview", 10, effectiveDate,
null, null, null, coc, sl, active, q, null);
BillingCode bc = findByBillingCodeCall("code103");
Set<BillingCode> billingCodes = new HashSet<BillingCode>();
billingCodes.add(bc);
PayableService service = SeocObjectGenerator.getPayableService("Service11", 4, "weeks", 5, "YES", null, null,
clinicalServices, seocKey2DateHold, new HashSet<BillingCode>());
service.getBillingCodes().add(bc);
List<PayableService> services = new ArrayList<PayableService>();
services.add(service);
seocWithDateHold.setServices(services);
Set<Hptc> hptcs = new HashSet<Hptc>();
hptcs.add(hptc1);
seocWithDateHold.setHptcs(hptcs);
// Seockey 1 active Seoc
effectiveDate = ApiUtil.getUTCZoneDateTime("09-07-2018 05:01:00 AM");
Seoc seocActive = SeocObjectGenerator.getSeoc("SeocKeyActive", TEST_SEOC_SEOCKEY1, "1.1.4", effectiveDate, null,
"disclaimer", 6, "description", false, "proceduralOverview", 10, effectiveDate, null, null, null, coc,
sl, dateHold, q, null);
bc = findByBillingCodeCall("code101");
billingCodes = new HashSet<BillingCode>();
billingCodes.add(bc);
PayableService service2 = SeocObjectGenerator.getPayableService("Service12", 4, "weeks", 5, "YES", null, null,
clinicalServices, seocKey1Active, new HashSet<BillingCode>());
service2.getBillingCodes().add(bc);
services = new ArrayList<PayableService>();
services.add(service2);
seocActive.setServices(services);
seocActive.setHptcs(hptcs);
// persist new active seocs
entityManager.persist(seocWithDateHold);
entityManager.persist(seocActive);
Seoc seocWithDateHoldFound = seocRepository.findByNameSeocKey("SeocKeyDateHold", TEST_SEOC_SEOCKEY2);
Seoc seocActiveFound = seocRepository.findByNameSeocKey("SeocKeyActive", TEST_SEOC_SEOCKEY1);
Set<Seoc> activeSeocsAfter = seocRepository.findActiveSeocs();
// Not found in the initial list of active seocs
assertThat(initialActiveSeocs).doesNotContain(seocWithDateHoldFound);
assertThat(initialActiveSeocs).doesNotContain(seocActiveFound);
// Found in the current list of active seocs
assertThat(activeSeocsAfter).contains(seocWithDateHoldFound);
assertThat(activeSeocsAfter).contains(seocActiveFound);
entityManager.detach(seocWithDateHold);
entityManager.detach(seocActive);
}
/**
* Description:Test case to check the correctness of seoc record obtained by
* using seoc name.
*/
@Test
public void testFindByName() {
Set<Seoc> seocsFound = seocRepository.findByName(TEST_SEOC_NAME);
seocsFound.forEach(s -> {
assertThat(s).hasFieldOrPropertyWithValue("name", TEST_SEOC_NAME);
});
}
/**
* Description:Test case to check the correctness of seoc record obtained by
* using seoc name match.
*/
@Test
public void testFindByNameMatch() {
Set<Seoc> seocFound = seocRepository.findSeocByNameMatch("test");
assertThat(seocFound).hasSize(1).contains(seocTest);
}
/**
* Description:Test case to check the correctness of the seoc record obtained by
* ID
*/
@Test
public void testFindById() {
Seoc seocFound = seocRepository.findById(seocTest.getId());
assertThat(seocFound).hasFieldOrPropertyWithValue("name", TEST_SEOC_NAME);
assertEquals(seocFound.getId(), seocTest.getId());
}
/**
* Description:Test case to check the correctness of seoc record obtained by
* using seoc name and seocKey.
*/
@Test
public void testFindBySeocNameKeyFound() {
Seoc seocFound = seocRepository.findByNameSeocKey(TEST_SEOC_NAME, TEST_SEOC_SEOCKEY);
assertEquals(TEST_SEOC_NAME, seocFound.getName());
assertEquals(TEST_SEOC_SEOCKEY, seocFound.getSeocKey());
}
/**
* Description: Test case to check if Spaces are ignored when finding duplicates
* Seoc names
*
*/
@Test
public void testFindDuplicateSeocNamesIgnoreSpace() {
String seocName = "Pulmonary SEOC 1.0.1";
Set<Seoc> seocFound = seocRepository.findDuplicateSeocNames(seocName);
assertFalse(seocFound.isEmpty());
}
/**
* Description: Test case to check if Case is ignored when finding duplicates
* Seoc names
*
*/
@Test
public void testFindDuplicateSeocNamesIgnoreCase() {
String seocName = "PULMONARY SEOC 1.0.1";
Set<Seoc> seocFound = seocRepository.findDuplicateSeocNames(seocName);
assertFalse(seocFound.isEmpty());
}
/**
* Description:Test case to check if the query will return empty when seoc name
* does not exist in the database when finding duplicates seoc names.
*
*/
@Test
public void testFindDuplicateSeocNamesIgnoreCaseNULLCheck() {
String seocName = "Null Name";
Set<Seoc> seocFound = seocRepository.findDuplicateSeocNames(seocName);
assertTrue(seocFound.isEmpty());
}
/**
* Description: Test case to check <code>findAllSeocs()</code> always returns
* list of all seocs.
*/
@Test
public void testFindAll() {
Set<Seoc> allSeocs = seocRepository.findAllSeocs();
// Assert the current size of list has grown by one and contains the newly added
// seoc
assertThat(allSeocs).hasSize(initialSize + 1).contains(seocTest);
}
/**
* Description: Test case to ensure finaMaxSeocKey() always returns maximum
* seocKey value among the existing records
*/
@Test
public void testFindMaxSeocKey() {
// Max key value before saving new seoc
Optional<Integer> maxKey = seocRepository.findMaxSeocKey();
// Persist new seoc with current maxKey + 1 value
Seoc seocNew = entityManager.persist(SeocObjectGenerator.getSeoc("TestMaxKey", maxKey.get() + 1, null, null,
null, "disclaimer", 6, "description", false, "proceduralOverview", 10, null, null, null, null, coc, sl,
draft, q, null));
// Find maxKey after saving the seoc
Optional<Integer> newMaxKey = seocRepository.findMaxSeocKey();
// Assert that new maxKey is greater than old maxkey. This implies
// findMaxSeocKey() always returns max key value from the DB
assertThat(newMaxKey.get().intValue()).isGreaterThan(maxKey.get().intValue());
// Assert that the new Seoc created is inducing the newMaxKey value.
assertEquals(seocNew.getSeocKey(), newMaxKey.get().intValue());
entityManager.detach(seocNew);
}
/**
* Description: Test case to check save functionality of seocRepository. Made
* sure a seoc which did not exist before is available after saving the seoc
* using save method.
*/
@Test
public void save_withServiceAndBillingCodes() {
Set<Seoc> seocsBeforeSave = seocRepository.findByName("SeocCreateTest");
Seoc seocToBeSaved = SeocObjectGenerator.getSeoc("SeocCreateTest", 0, null, null, null, "disclaimer", 6,
"description", false, "proceduralOverview", 10, null, null, null, null, coc, sl, draft, q, null);
Set<BillingCode> billingCodes = new HashSet<BillingCode>();
billingCodes.add(findByBillingCodeCall("code101"));
billingCodes.add(findByBillingCodeCall("code102"));
List<PayableService> services = new ArrayList<PayableService>();
PayableService service1 = SeocObjectGenerator.getPayableService("Service11", 4, "weeks", 5, "YES", null, null,
clinicalServices, seocToBeSaved, null);
PayableService service2 = SeocObjectGenerator.getPayableService("Service21", 4, "weeks", 5, "YES", null, null,
clinicalServices, seocToBeSaved, billingCodes);
services.add(service1);
services.add(service2);
seocToBeSaved.setServices(services);
Seoc seocSaved = seocRepository.save(seocToBeSaved);
Set<Seoc> seocAfterSave = seocRepository.findByName("SeocCreateTest");
// Assert that before saving the seocSaved there is no seoc with that name
assertThat(seocsBeforeSave).isEmpty();
// Assert after save object has same id as the saved object
assertThat(seocAfterSave).size().isEqualTo(1);
assertThat(seocAfterSave.stream().anyMatch(s -> s.getId() == seocSaved.getId())).isEqualTo(true);
assertThat(seocSaved.getServices()).size().isEqualTo(2);
assertThat(seocSaved.getServices()).contains(service1);
assertThat(seocSaved.getServices()).contains(service2);
PayableService serviceWithNoBC = seocSaved.getServices().stream()
.filter(s -> s.getDescription().equals(service1.getDescription())).findFirst().get();
PayableService serviceWithBC = seocSaved.getServices().stream()
.filter(s -> s.getDescription().equals(service2.getDescription())).findFirst().get();
assertThat(serviceWithNoBC.getBillingCodes()).isNull();
assertThat(serviceWithBC.getBillingCodes()).size().isEqualTo(2);
entityManager.detach(serviceWithNoBC);
entityManager.detach(serviceWithBC);
entityManager.detach(seocSaved);
}
/**
* Description: Save should update an existing seoc. Add service to already
* existing Seoc and delete exitsing billingcodes
*/
@Test
public void update_addBillinCodestoExistingService() {
Set<Seoc> savedSeocs = seocRepository.findByName(TEST_SEOC_NAME);
Seoc savedSeoc = savedSeocs.stream().findFirst().filter(s -> s.getName().equals(TEST_SEOC_NAME)).get();
Set<BillingCode> billingCodes = new HashSet<BillingCode>();
billingCodes.add(findByBillingCodeCall("code101"));
billingCodes.add(findByBillingCodeCall("code102"));
List<PayableService> services = new ArrayList<PayableService>();
PayableService service1 = SeocObjectGenerator.getPayableService("Service223", 4, "weeks", 5, "YES", null, null,
clinicalServices, savedSeoc, billingCodes);
services.add(service1);
savedSeoc.setServices(services);
// Add new Service with billing codes
Seoc updatedSeoc = seocRepository.save(savedSeoc);
assertThat(updatedSeoc.getId()).isEqualTo(savedSeoc.getId());
assertThat(updatedSeoc.getServices()).size().isEqualTo(1);
services = updatedSeoc.getServices();
PayableService serviceUpdated = services.stream().findFirst().get();
assertThat(serviceUpdated.getBillingCodes()).size().isEqualTo(2);
// Delete BillingCodes
serviceUpdated.getBillingCodes().remove(findByBillingCodeCall("code101"));
services = new ArrayList<PayableService>();
services.add(serviceUpdated);
updatedSeoc.setServices(services);
updatedSeoc = seocRepository.save(updatedSeoc);
serviceUpdated = updatedSeoc.getServices().stream().findFirst().get();
assertThat(serviceUpdated.getBillingCodes()).size().isEqualTo(1);
entityManager.detach(serviceUpdated);
entityManager.detach(savedSeoc);
}
/**
* Description: Find by SeocKey
*/
@Test
public void findBySeocKey_test() {
int seocKey = 10;
Seoc seoc1 = SeocObjectGenerator.getSeoc("Seoc1", seocKey, null, null, null, "disclaimer", 6, "description",
false, "proceduralOverview", 10, null, null, null, null, coc, sl, draft, q, null);
Seoc seoc2 = SeocObjectGenerator.getSeoc("Seoc2", seocKey, null, null, null, "disclaimer", 6, "description",
false, "proceduralOverview", 10, null, null, null, null, coc, sl, draft, q, null);
Seoc seoc3 = SeocObjectGenerator.getSeoc("Seoc3", 11, null, null, null, "disclaimer", 6, "description", false,
"proceduralOverview", 10, null, null, null, null, coc, sl, draft, q, null);
entityManager.persist(seoc1);
entityManager.persist(seoc2);
entityManager.persist(seoc3);
Set<Seoc> sameSeocKey = seocRepository.findBySeocKey(seocKey);
assertThat(sameSeocKey.size()).isEqualTo(2);
sameSeocKey.forEach(s -> {
assertThat(s.getSeocKey()).isEqualTo(seocKey);
});
entityManager.detach(seoc1);
entityManager.detach(seoc2);
entityManager.detach(seoc3);
}
/**
* Description: Check delete functionality works as expected. Services should be
* deleted when seoc is deleted. Billing codes should not be deleted.
*/
@Test
public void delete() {
Seoc seocToBeSaved = SeocObjectGenerator.getSeoc("SeocCreateTest", 5, null, null, null, "disclaimer", 6,
"description", false, "proceduralOverview", 10, null, null, null, null, coc, sl,
SeocObjectGenerator.inprogress, q, new ArrayList<PayableService>());
BillingCode bc1 = findByBillingCodeCall("code101");
BillingCode bc2 = findByBillingCodeCall("code102");
Set<BillingCode> billingCodes = new HashSet<BillingCode>();
billingCodes.add(bc1);
billingCodes.add(bc2);
PayableService service1 = SeocObjectGenerator.getPayableService("Service", 4, "weeks", 5, "YES", null, null,
clinicalServices, seocToBeSaved, null);
PayableService service2 = SeocObjectGenerator.getPayableService("Service", 4, "weeks", 5, "YES", null, null,
clinicalServices, seocToBeSaved, new HashSet<BillingCode>());
service2.getBillingCodes().add(bc1);
service2.getBillingCodes().add(bc2);
seocToBeSaved.getServices().add(service1);
seocToBeSaved.getServices().add(service2);
// Saved a seoc with payable services
Seoc seocSaved = entityManager.persist(seocToBeSaved);
// Assert seoc has services
assertThat(seocSaved.getServices()).size().isEqualTo(2);
assertThat(seocSaved.getServices()).contains(service1);
assertThat(seocSaved.getServices()).contains(service2);
// delete saved seoc
seocRepository.delete(seocSaved);
// check the saved seoc is not in the DB
List<Seoc> allSeocs = (ArrayList<Seoc>) seocRepository.findAll();
assertThat(allSeocs).doesNotContain(seocSaved);
// get all services
List<PayableService> servicesList = (ArrayList<PayableService>) serviceRepository.findAll();
// check if services from deleted seoc are available in the DB -- shouldn't be
// available
assertThat(servicesList).doesNotContain(seocSaved.getServices().get(0));
assertThat(servicesList).doesNotContain(seocSaved.getServices().get(1));
List<BillingCode> allBillingCodes = (ArrayList<BillingCode>) billingCodeRepo.findAll();
// Assert that billing codes are not deleted
assertThat(allBillingCodes).contains(bc1, bc2);
}
/**
* Description: Seocs found for COC Seocs with TEST_SEOC_SEOCKEY1 - 1 active , 1
* discontinued Seocs with TEST_SEOC_SEOCKEY2 - 1 datehold, 1 inprogress Seocs
* with TEST_SEOC_SEOCKEY3 - 1 inprogress findSeocsPublishedWithCategoryOfCare()
* should contain TEST_SEOC_SEOCKEY1, TEST_SEOC_SEOCKEY2 but not
* TEST_SEOC_SEOCKEY3
*/
@Test
public void findSeocsForCategoryOfCareReturnsSeocKeys() {
int[] actualCount = seocRepository.findSeocsPublishedWithCategoryOfCare(coc.getDescription());
assertThat(actualCount).isNotNull();
assertThat(actualCount).contains(TEST_SEOC_SEOCKEY1, TEST_SEOC_SEOCKEY2);
assertThat(actualCount).doesNotContain(TEST_SEOC_SEOCKEY3);
}
/**
* Description: No Seocs found for anotherCoc
* findSeocsPublishedWithCategoryOfCare() should return empty array
*/
@Test
public void findSeocsForCategoryOfCareReturnsEmptyArray() {
int[] actualCount = seocRepository.findSeocsPublishedWithCategoryOfCare(anotherCoc.getDescription());
assertThat(actualCount).isEmpty();
}
@Test
public void findPayableServicesByBillingCode() {
String code = "code101";
BillingCode bc = findByBillingCodeCall(code);
assertThat(bc.getBillingCode()).isEqualTo(code);
Set<PayableService> services = serviceRepository.findByBillingCodesId(bc.getId());
services.forEach(serv -> {
assertThat(serv.getBillingCodes()).contains(bc);
});
}
@Test
public void findSeocsByBillingCodes() {
String code = "code101";
BillingCode bc = findByBillingCodeCall(code);
assertThat(bc.getBillingCode()).isEqualTo(code);
Set<PayableService> services = serviceRepository.findByBillingCodesId(bc.getId());
Integer[] serviceIds = services.stream().map(PayableService::getId).collect(Collectors.toList()).stream()
.toArray(Integer[]::new);
Set<Seoc> seocs = seocRepository.findByServicesIdIn(serviceIds);
seocs.forEach(s -> {
Set<PayableService> matchingServices = s.getServices().stream().filter(serv -> services.contains(serv))
.collect(Collectors.toSet());
assertThat(services).containsAll(matchingServices);
});
}
public BillingCode findByBillingCodeCall(String code) {
Set<BillingCode> bcs = billingCodeRepo.findByBillingCode(code);
Optional<BillingCode> billingCode = bcs.stream()
.filter(b -> !b.getDeactivated()).findAny();
if (billingCode.isPresent()) {
return billingCode.get();
}
return null;
}
}