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

/*
* PayableServiceTest.java
* Copyright (c) 2017 Veterans Affairs.
*/
package gov.va.oneconsult.seoc.api.model;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import org.junit.Test;

import gov.va.oneconsult.seoc.api.controller.SeocObjectGenerator;
import gov.va.oneconsult.seoc.api.util.ApiUtil;

/**
*
* @author AbleVets
*
*/
public class PayableServiceTest
{

@Test
public void codeRequiredEqualsNull()
{
PayableService psThat = new PayableService();

psThat.setCodeRequired(null);

assertFalse("Returns false if codeRequired is null", psThat.codeRequiredEquals("NO"));
}

@Test
public void codeRequiredEqualsWhiteSpaceMixedCase()
{
PayableService psThat = new PayableService();

psThat.setCodeRequired("NO ");

assertTrue("Trims whitespace and ignores casing for the codeRequired attribute", psThat.codeRequiredEquals("No"));
}

@Test
public void codeRequiredEqualsWhiteSpaceParam()
{
PayableService psThat = new PayableService();

psThat.setCodeRequired("NO");

assertTrue("Trims whitespace and ignores casing for the compareVal parameter", psThat.codeRequiredEquals("No "));
}

@Test
public void codeRequiredEqualsSameSpaceSameCase()
{
PayableService psThat = new PayableService();

psThat.setCodeRequired("YES");

assertTrue("Returns true if the values are equivalent", psThat.codeRequiredEquals("YES"));
}

@Test
public void codeRequiredEqualsNotEqual()
{
PayableService psThat = new PayableService();

psThat.setCodeRequired("ANY");

assertFalse("Returns false if the values are not equivalent", psThat.codeRequiredEquals("YES"));
}

/**
* Description: Deep clone non recursive properties
*/
@Test
public void deepCloneNonRecursiveProperties()
{
PayableService psThat = new PayableService();
Date today = ApiUtil.today_UTC();

psThat.setDescription("Description1");
psThat.setCodedBy("System");
psThat.setCodedTimestamp(new Date());
psThat.setCodeRequired("YES");
psThat.setFrequency(new Integer(3));
psThat.setFrequencyType("/week");
psThat.setClinicalServices(SeocObjectGenerator.cs1Set);
psThat.setBillingCodes(new HashSet<BillingCode>());

PayableService psThis = psThat.deepClone();

psThis.setDescription("Description2");
psThis.setCodedBy("System2");
psThis.setCodedTimestamp(today);
psThis.setCodeRequired("NO");
psThis.setFrequency(4);
psThis.setFrequencyType("/days");
psThis.setClinicalServices(SeocObjectGenerator.cs1Set);
psThis.setBillingCodes(new HashSet<BillingCode>());

assertThat(psThat.getDescription()).isNotEqualTo(psThis.getDescription());
assertThat(psThat.getCodedBy()).isNotEqualTo(psThis.getCodedBy());
assertThat(psThat.getCodedTimestamp()).isNotEqualTo(psThis.getCodedTimestamp());
assertThat(psThat.getCodeRequired()).isNotEqualTo(psThis.getCodeRequired());
assertThat(psThat.getFrequency()).isNotEqualTo(psThis.getFrequency());
assertThat(psThat.getFrequencyType()).isNotEqualTo(psThis.getFrequencyType());
}

/**
* Description: Deep clone recursive attributes on service
*/
@Test
public void deepCloneRecursiveProperties()
{
PayableService psThat = new PayableService();

Set<BillingCode> bcThat = new HashSet<BillingCode>();
BillingCode bc1 = SeocObjectGenerator.bc1;
BillingCode bc2 = SeocObjectGenerator.bc2;

bcThat.add(bc1);
bcThat.add(bc2);

psThat.setBillingCodes(bcThat);

Set<ClinicalService> csThat = new HashSet<ClinicalService>();
ClinicalService cs1 = SeocObjectGenerator.cs1;
ClinicalService cs2 = SeocObjectGenerator.cs2;

csThat.add(cs1);
csThat.add(cs2);

psThat.setClinicalServices(csThat);

PayableService psThis = psThat.deepClone();

Set<BillingCode> bcThis = psThis.getBillingCodes();
Set<ClinicalService> csThis = psThis.getClinicalServices();

bcThis.forEach(bc -> {
assertThat(bcThat).contains(bc);
});

//edit cloned version of billing codes - check if that affects the actual one
bcThis.remove(bc1);

assertThat(bcThis.size()).isNotEqualTo(bcThat.size());

csThis.forEach(cs -> {
assertThat(csThat).contains(cs);
});

//edit cloned version of clinical Services - check if that affects the actual one
csThis.remove(cs1);

assertThat(csThis.size()).isNotEqualTo(csThat.size());
}

/**
* Description: Deep clone when a clinicalService is discontinued
*/
@Test
public void deepCloneClinicalServiceDiscontinued()
{
PayableService psThat = new PayableService();

psThat.setDescription("Description1");
psThat.setCodedBy("System");
psThat.setCodedTimestamp(new Date());
psThat.setCodeRequired("YES");
psThat.setFrequency(new Integer(3));
psThat.setFrequencyType("/week");
psThat.setClinicalServices(SeocObjectGenerator.cs4Set);
psThat.setBillingCodes(new HashSet<BillingCode>());

PayableService psThis = psThat.deepClone();

assertThat(psThis.getClinicalServices()).isEqualTo(SeocObjectGenerator.cs12Set);
}

/**
* Description: Deep clone when a billingCode is deactivated
*/
@Test
public void deepCloneBillingCodeDiscontinued()
{
PayableService psThat = new PayableService();

psThat.setDescription("Description1");
psThat.setCodedBy("System");
psThat.setCodedTimestamp(new Date());
psThat.setCodeRequired("YES");
psThat.setFrequency(new Integer(3));
psThat.setFrequencyType("/week");
psThat.setClinicalServices(SeocObjectGenerator.cs1Set);
psThat.setBillingCodes(SeocObjectGenerator.bc5Set);

PayableService psThis = psThat.deepClone();

assertThat(psThis.getBillingCodes()).isEqualTo(SeocObjectGenerator.bc5Set);
}

/**
* Description: Deep clone when noDeactivatedBillingCodes is true
*/
@Test
public void deepCloneNoDeactivatedBillingCodes()
{
PayableService psThat = new PayableService();

psThat.setDescription("Description1");
psThat.setCodedBy("System");
psThat.setCodedTimestamp(new Date());
psThat.setCodeRequired("YES");
psThat.setFrequency(new Integer(3));
psThat.setFrequencyType("/week");
psThat.setClinicalServices(SeocObjectGenerator.cs1Set);
psThat.setBillingCodes(SeocObjectGenerator.bc5Set);

PayableService psThis = psThat.deepClone(true);

assertThat(psThis.getBillingCodes()).isEqualTo(SeocObjectGenerator.bc1234Set);
}

/**
* Description: Deep clone when noDeactivatedBillingCodes is null
*/
@Test
public void deepCloneNoDeactivatedBillingCodesNull()
{
PayableService psThat = new PayableService();

psThat.setDescription("Description1");
psThat.setCodedBy("System");
psThat.setCodedTimestamp(new Date());
psThat.setCodeRequired("YES");
psThat.setFrequency(new Integer(3));
psThat.setFrequencyType("/week");
psThat.setClinicalServices(SeocObjectGenerator.cs1Set);
psThat.setBillingCodes(SeocObjectGenerator.bc5Set);

PayableService psThis = psThat.deepClone(null);

assertThat(psThis.getBillingCodes()).isEqualTo(SeocObjectGenerator.bc5Set);
}

/**
* Description: Deep clone when noDeactivatedBillingCodes is false
*/
@Test
public void deepCloneNoDeactivatedBillingCodesFalse()
{
PayableService psThat = new PayableService();

psThat.setDescription("Description1");
psThat.setCodedBy("System");
psThat.setCodedTimestamp(new Date());
psThat.setCodeRequired("YES");
psThat.setFrequency(new Integer(3));
psThat.setFrequencyType("/week");
psThat.setClinicalServices(SeocObjectGenerator.cs1Set);
psThat.setBillingCodes(SeocObjectGenerator.bc5Set);

PayableService psThis = psThat.deepClone(false);

assertThat(psThis.getBillingCodes()).isEqualTo(SeocObjectGenerator.bc5Set);
}

@Test
public void removeBillingCodeSuccess()
{
Seoc testSeoc = SeocObjectGenerator.getSeoc("Name", 1, null, null, null, null, 0, null,
false, null, 0, null, "System", null, "System", SeocObjectGenerator.cc1,
SeocObjectGenerator.sl1, SeocObjectGenerator.active, SeocObjectGenerator.qasp1,null);
PayableService serv = SeocObjectGenerator.getPayableService(1, "description", 4, "TEST", 4, CodeRequired.YES.getValue(), "System", new Date(), SeocObjectGenerator.cs1Set, testSeoc);
BillingCode bc1 = SeocObjectGenerator.getBillingCode(5, "BC1", "CPT", "DESC", true);
serv.setBillingCodes(new HashSet<BillingCode>());
serv.getBillingCodes().add(bc1);
testSeoc.setServices(new ArrayList<PayableService>());
testSeoc.getServices().add(serv);
assertThat(serv.getBillingCodes()).contains(bc1);
serv.removeBillingCode(bc1);
assertThat(serv.getBillingCodes()).doesNotContain(bc1);
}

@Test
public void updateBillingCodeSuccess()
{
Seoc testSeoc = SeocObjectGenerator.getSeoc("Name", 1, null, null, null, null, 0, null,
false, null, 0, null, "System", null, "System", SeocObjectGenerator.cc1,
SeocObjectGenerator.sl1, SeocObjectGenerator.active, SeocObjectGenerator.qasp1,null);
PayableService serv = SeocObjectGenerator.getPayableService(1, "description", 4, "TEST", 4, CodeRequired.YES.getValue(), "System", new Date(), SeocObjectGenerator.cs1Set, testSeoc);

BillingCode bc1 = SeocObjectGenerator.getBillingCode(5, "BC1", "CPT", "DESC", true);
BillingCode bc2 = SeocObjectGenerator.getBillingCode(6, "BC2", "CPT", "DESC", true);

serv.setBillingCodes(new HashSet<BillingCode>());
serv.getBillingCodes().add(bc1);
testSeoc.setServices(new ArrayList<PayableService>());
testSeoc.getServices().add(serv);
assertThat(serv.getBillingCodes()).contains(bc1);
serv.updateBillingCode(bc1, bc2);
assertThat(serv.getBillingCodes()).doesNotContain(bc1);
assertThat(serv.getBillingCodes()).contains(bc2);
}

@Test
public void updateBillingCodeNullBillingCodes()
{
Seoc testSeoc = SeocObjectGenerator.getSeoc("Name", 1, null, null, null, null, 0, null,
false, null, 0, null, "System", null, "System", SeocObjectGenerator.cc1,
SeocObjectGenerator.sl1, SeocObjectGenerator.active, SeocObjectGenerator.qasp1,null);
PayableService serv = SeocObjectGenerator.getPayableService(1, "description", 4, "TEST", 4, CodeRequired.YES.getValue(), "System", new Date(), SeocObjectGenerator.cs1Set, testSeoc);

BillingCode bc1 = SeocObjectGenerator.getBillingCode(5, "BC1", "CPT", "DESC", true);
BillingCode bc2 = SeocObjectGenerator.getBillingCode(6, "BC2", "CPT", "DESC", true);

testSeoc.setServices(new ArrayList<PayableService>());
testSeoc.getServices().add(serv);
assertThat(serv.getBillingCodes()).isNull();
serv.updateBillingCode(bc1, bc2);
assertThat(serv.getBillingCodes()).isNull();
}

@Test
public void updateBillingCodeEmptyServices()
{
Seoc testSeoc = SeocObjectGenerator.getSeoc("Name", 1, null, null, null, null, 0, null,
false, null, 0, null, "System", null, "System", SeocObjectGenerator.cc1,
SeocObjectGenerator.sl1, SeocObjectGenerator.active, SeocObjectGenerator.qasp1,null);
PayableService serv = SeocObjectGenerator.getPayableService(1, "description", 4, "TEST", 4, CodeRequired.YES.getValue(), "System", new Date(), SeocObjectGenerator.cs1Set, testSeoc);

BillingCode bc1 = SeocObjectGenerator.getBillingCode(5, "BC1", "CPT", "DESC", true);
BillingCode bc2 = SeocObjectGenerator.getBillingCode(6, "BC2", "CPT", "DESC", true);

serv.setBillingCodes(new HashSet<BillingCode>());
testSeoc.setServices(new ArrayList<PayableService>());
testSeoc.getServices().add(serv);
assertThat(serv.getBillingCodes().isEmpty()).isTrue();
serv.updateBillingCode(bc1, bc2);
assertThat(serv.getBillingCodes().isEmpty()).isTrue();
}

@Test
public void updateBillingCodePreviousBillingCodeNotInService()
{
Seoc testSeoc = SeocObjectGenerator.getSeoc("Name", 1, null, null, null, null, 0, null,
false, null, 0, null, "System", null, "System", SeocObjectGenerator.cc1,
SeocObjectGenerator.sl1, SeocObjectGenerator.active, SeocObjectGenerator.qasp1,null);
PayableService serv = SeocObjectGenerator.getPayableService(1, "description", 4, "TEST", 4, CodeRequired.YES.getValue(), "System", new Date(), SeocObjectGenerator.cs1Set, testSeoc);

BillingCode bc1 = SeocObjectGenerator.getBillingCode(5, "BC1", "CPT", "DESC", true);
BillingCode bc2 = SeocObjectGenerator.getBillingCode(6, "BC2", "CPT", "DESC", true);

serv.setBillingCodes(new HashSet<BillingCode>());
testSeoc.setServices(new ArrayList<PayableService>());
testSeoc.getServices().add(serv);
assertThat(testSeoc.getServices().get(0).getBillingCodes().isEmpty()).isTrue();
testSeoc.updateBillingCode(bc1, bc2);
assertThat(testSeoc.getServices().get(0).getBillingCodes().isEmpty()).isTrue();
}
}