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.HashSet;
import java.util.Optional;
import java.util.Set;

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.test.context.junit4.SpringJUnit4ClassRunner;

import gov.va.oneconsult.seoc.api.controller.SeocObjectGenerator;
import gov.va.oneconsult.seoc.api.model.BillingCode;

/**
* @author AbleVets
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@DataJpaTest
public class BillingCodeRepositoryTest
{
@Autowired
private BillingCodeRepository billingCodeRepository;

@Test
public void findAllBillingCodes_returnsOnlyActiveBillingCodes()
{
BillingCode bc = SeocObjectGenerator.
getBillingCode(0, "CodeTest", "CPT", "Description", true);
BillingCode savedBC = billingCodeRepository.save(bc);

Set<BillingCode> billingCodes1 = billingCodeRepository.findAllBillingCodes();
assertThat(billingCodes1).isNotNull();
assertThat(billingCodes1).contains(savedBC);

Set<BillingCode> bcs = billingCodeRepository.findByBillingCode("CodeTest");
Optional<BillingCode> bcAfter = bcs.stream().filter(b -> b.getDeactivated() == null || b.getDeactivated().booleanValue() == false).findAny();
if (bcAfter.isPresent())
{
bcAfter.get().setDeactivated(true);
savedBC = billingCodeRepository.save(bcAfter.get());
}

Set<BillingCode> billingCodesAfter = billingCodeRepository.findAllBillingCodes();
assertThat(billingCodesAfter).isNotNull();
assertThat(billingCodesAfter).doesNotContain(savedBC);

}

@Test
public void fetchBybillingCode_returnsOnlyActiveBillingCodes()
{
BillingCode bcDraft = SeocObjectGenerator.
getBillingCode(0, "codeTest", "CPT", "Description", true);
BillingCode savedBC = billingCodeRepository.save(bcDraft);

Set<BillingCode> activeBillingCodesBefore = billingCodeRepository.findAllBillingCodes();
Set<BillingCode> activeBillingCodesByBC = new HashSet<BillingCode>();
String code = "code";

if (activeBillingCodesBefore != null)
{
for(BillingCode bc: activeBillingCodesBefore) {
if(bc.getBillingCode().contains(code)) {
activeBillingCodesByBC.add(bc);
}
}
}
//Assert that billing codes obtained from findAll and filtered by billing code is same as the fetchBybillingCode() from repository
Set<BillingCode> billingCodeFromRepByBC = billingCodeRepository.fetchBybillingCode(code);
assertThat(billingCodeFromRepByBC).isNotNull();
assertThat(activeBillingCodesByBC).contains(savedBC);
assertThat(billingCodeFromRepByBC).containsAll(activeBillingCodesByBC);
assertThat(billingCodeFromRepByBC).contains(savedBC);

//deactivated created billing code
savedBC.setDeactivated(true);
savedBC = billingCodeRepository.save(savedBC);

//Deactivated BC should not appear in the list of Billing Codes from repository using fetchBybillingCode()
Set<BillingCode> billingCodeFromRepByBCAfter = billingCodeRepository.fetchBybillingCode(code);
assertThat(billingCodeFromRepByBCAfter).isNotNull();
assertThat(billingCodeFromRepByBCAfter).doesNotContain(savedBC);
}

@Test
public void findByBillingCode_returnsActiveOrDiscontinuedBillingCode()
{
BillingCode bc = SeocObjectGenerator.
getBillingCode(0, "CodeTest", "CPT", "Description", true);
BillingCode savedBC = billingCodeRepository.save(bc);
Set<BillingCode> foundBCs = billingCodeRepository.findByBillingCode("CodeTest");
Optional<BillingCode> foundBC = foundBCs.stream().filter(b -> b.getDeactivated() == null || b.getDeactivated().booleanValue() == false).findAny();
if (foundBC.isPresent())
{
//Found Billing code with deactivated field null
assertThat(foundBC.get()).isSameAs(savedBC);
assertThat(foundBC.get().getDeactivated()).isNull();
foundBC.get().setDeactivated(false);
}

savedBC = billingCodeRepository.save(foundBC.get());
foundBCs = billingCodeRepository.findByBillingCode("CodeTest");
foundBC = foundBCs.stream().filter(b -> b.getDeactivated() == null || b.getDeactivated().booleanValue() == false).findAny();
if (foundBC.isPresent())
{
//Found Billing code with deactivated field false
assertThat(foundBC.get()).isSameAs(savedBC);
assertThat(foundBC.get().getDeactivated()).isFalse();

foundBC.get().setDeactivated(true);
}
savedBC = billingCodeRepository.save(foundBC.get());
foundBCs = billingCodeRepository.findByBillingCode("CodeTest");
foundBC = foundBCs.stream().filter(b -> b.getDeactivated() == null || b.getDeactivated().booleanValue() == false).findAny();
if (foundBC.isPresent())
{
//Found Billing code with deactivated field false
assertThat(foundBC.get()).isSameAs(savedBC);
assertThat(foundBC.get().getDeactivated()).isTrue();

foundBC.get().setDeactivated(true);
}
}

}