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.med.ars.service.impl;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.commons.lang.SerializationUtils;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import gov.va.med.ars.dao.ars.ClaimLevel277CARepository;
import gov.va.med.ars.dao.ars.IHeaderRecord277CARepository;
import gov.va.med.ars.dao.ars.ITrailerRec277CARepository;
import gov.va.med.ars.dao.ars.LineLevel277CARepository;
import gov.va.med.ars.util.DateUtil;
import gov.va.med.domain.ars.ClaimLevelRecordsDetail;
import gov.va.med.domain.ars.ClaimStatusRecordDetail;
import gov.va.med.domain.ars.HeaderRecordDetail;
import gov.va.med.domain.ars.LineLevelRecordsDetail;
import gov.va.med.domain.ars.TrailerRecordDetail;

@RunWith(MockitoJUnitRunner.class)
public class CstatGeneratorServiceImplTest {

@InjectMocks
CstatGeneratorServiceImpl cstatService;

@Mock
ClaimLevel277CARepository clrdRepo;

@Mock
LineLevel277CARepository llrdRepo;

@Mock
IHeaderRecord277CARepository hdrRepo;

@Mock
ITrailerRec277CARepository trlrRepo;

@Mock
DateUtil dateUtil;

@Test
public void testMockIsWorking() {
assertNotNull("CstatGeneratorServiceImpl Injection Failed", cstatService);
}

HeaderRecordDetail headerRecord;
TrailerRecordDetail trailerRecord;
ClaimLevelRecordsDetail clrd;
List<ClaimLevelRecordsDetail> clrdList;

List<HeaderRecordDetail> headerRecordList = new ArrayList<>();

LineLevelRecordsDetail lineLevelRecordsDetail;
List<LineLevelRecordsDetail> lineLevelRecordsDetails;

ClaimStatusRecordDetail clsrec;
List<ClaimStatusRecordDetail> clsr;

Date date;

private Date headerDate;
private static final SimpleDateFormat headerTimeFormat = new SimpleDateFormat("HHmmss");

AtomicInteger lineCounter;

@Before
public void reUse() {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
LocalDate date1 = LocalDate.parse("20180724", formatter);
date = java.sql.Date.valueOf(date1);

headerDate = new Date();

headerRecord = new HeaderRecordDetail();
headerRecord.setHrecid((long) 35L);
headerRecord.setRecid("HDR");
headerRecord.setBatchId("1HD");
headerRecord.setFileGrpSeqnum((short) 222);
headerRecord.setFileGrpCount((short) 10);
headerRecord.setBht04CreationDate(headerDate);
headerRecord.setBht05CreationTime(headerTimeFormat.format(headerDate));
headerRecord.setHl21Nm10946Tpid("VAFNH");
headerRecord.setHl21Nm10310441Sn("VA Fee Basis Program");
headerRecord.setLoadtype('I');
headerRecord.setPudid("20180724122930");
headerRecord.setFiletype("CSTAT");
headerRecord.setVersioncode("03");
headerRecord.setReleasecode("00");

headerRecordList.add(headerRecord);

trailerRecord = new TrailerRecordDetail();
trailerRecord.setHeaderRecordDetail(headerRecord);
trailerRecord.setRecid("TRLR");
trailerRecord.setTrecid(35L);

clrdList = new ArrayList<ClaimLevelRecordsDetail>();

clrd = new ClaimLevelRecordsDetail();
clrd.setClrecid(11L);
clrd.setRecid("CLM");
clrd.setHl320Nm1092100aFiPayerid("123123");
clrd.setMaintenancetypecode("021");
clrd.setHl319Nm1092100cXxBpnpid(9898989898L);
clrd.setHl319Nm1032100cBplastname("Veteran");
clrd.setHl3ptNm1092100d1Patid("987654");
clrd.setHl3ptNm1032100d1Patlastname("PatienLName");
clrd.setHl3ptNm1042100d1Patfrstname("PatientFirstName");
clrd.setPatdob(null);
clrd.setHl3ptStc042200dCca((double) 103.88);
clrd.setHl3ptRef022200d1kPcidnum("UB067815EDI0025");
clrd.setHl3ptDtp032200d472D8Csds(date);
clrd.setHl3ptDtp032200d472D8Csde(date);
clrd.setCstatStatus("PENDING");
clrd.setHeaderRecordDetail(headerRecord);

lineLevelRecordsDetails = new ArrayList<LineLevelRecordsDetail>();
lineLevelRecordsDetail = new LineLevelRecordsDetail();
lineLevelRecordsDetail.setLlrecid(99L);
lineLevelRecordsDetail.setRecid("DTL");
lineLevelRecordsDetail.setHl20Nm1092100aFiPayerid("12115");
lineLevelRecordsDetail.setHlptRef021kPyrclmidentnum("UB067815EDI0025");
lineLevelRecordsDetail.setHlptRef02FjLnitmctrlnum("357896");
lineLevelRecordsDetail.setHlptSvc011Svcqualid("951248");
lineLevelRecordsDetail.setHlptSvc012Svcidntcd("842159");
lineLevelRecordsDetail.setHlptSvc02Lnitmchrgamt((double) 5656565);
lineLevelRecordsDetail.setHlptSvc03Lnitmprvpymamt((double) 9899898);
lineLevelRecordsDetail.setHlptDtp03Dtsvcstart(date);
lineLevelRecordsDetail.setHlptDtp03Dtsvcend(date);
lineLevelRecordsDetail.setClaimLevelRecordsDetail(clrd);

clsr = new ArrayList<>();
clsrec = new ClaimStatusRecordDetail();
clsrec.setRecid("STC");
clsrec.setCsrecid(07L);
clsrec.setHl320Nm1092100aFiPayerid("123123");
clsrec.setHl3ptRef022200d1kPcidnum("UB067815EDI0025");
clsrec.setHlptStc02Stciedate(date);
clsrec.setHlptStc011Cscc("A3");
clsrec.setHlptStc012Csc("19");
clsrec.setClaimLevelRecordsDetail(clrd);
// clsrec.setLineLevelRecordsDetail(lineLevelRecordsDetail);

lineCounter = new AtomicInteger(2);

when(dateUtil.getNewDate()).thenReturn(headerDate);
}

@Test
public void buildHdrTrlrString_Success() {

clrd = new ClaimLevelRecordsDetail();

when(hdrRepo.findBybatchId(String.valueOf(35))).thenReturn(headerRecordList);
when(clrdRepo.findPendingCLMWithLines(35L)).thenReturn(new ArrayList<>());
when(clrdRepo.findPendingCLMWithoutLines(35L)).thenReturn(new ArrayList<>());
when(trlrRepo.findByheaderRecordDetail(headerRecord)).thenReturn(trailerRecord);
//when(dateUtil.getNewDate()).thenReturn(headerDate);


List<String> returnRes = cstatService.buildAllSegments(35L, lineCounter);

String cstat[] = { "HDR|1HD|01|01|" + new SimpleDateFormat("yyyyMMdd").format(new Date()) + "|"
+ headerTimeFormat.format(headerDate) + "|VAFNH|VA Fee Basis Program||||I|20180724122930|CSTAT|03|00",
"TRLR|0" };

assertEquals(cstat[0], returnRes.get(0));
assertEquals(cstat[1], returnRes.get(1));
verify(hdrRepo, times(1)).findBybatchId(String.valueOf(35));
verify(trlrRepo, times(1)).findByheaderRecordDetail(headerRecord);
assertEquals(2, returnRes.size());
verify(clrdRepo, times(0)).updateStatus(new ArrayList<>(), "COMPLETE");

// to make sure the segment starts with their respective recid
assertEquals("HDR", returnRes.get(0).substring(0, 3));
assertEquals("TRLR", returnRes.get(1).substring(0, 4));
}

@Test
public void buildHdrTrlrString_Failure() {

headerRecord.setBht04CreationDate(null);

when(hdrRepo.findBybatchId(String.valueOf(35))).thenReturn(headerRecordList);

List<String> returnRes = cstatService.buildAllSegments(35L, lineCounter);

assertEquals(null, returnRes);
verify(clrdRepo, times(0)).findPendingCLMWithLines(35L);
}

@Test
public void testBuildCLMSegmentWithOutLines_success() {
clrdList.add(clrd);
assertNotNull(headerRecord);

when(hdrRepo.findBybatchId(String.valueOf(35))).thenReturn(headerRecordList);
when(clrdRepo.findPendingCLMWithLines(35L)).thenReturn(new ArrayList<>());
when(clrdRepo.findPendingCLMWithoutLines(35L)).thenReturn(clrdList);
when(trlrRepo.findByheaderRecordDetail(headerRecord)).thenReturn(trailerRecord);

List<Long> clrdUpdate = new ArrayList<>();
clrdUpdate.add(11L);
doNothing().when(clrdRepo).updateStatus(clrdUpdate, "COMPLETE");
List<String> returnRes = cstatService.buildAllSegments(35L, lineCounter);

String[] cstat = {
"CLM|2|VAFEE|021|||9898989898|Veteran|||||||||||||987654|PatienLName|PatientFirstName||||PatienLName|PatientFirstName|||19850818|||103.88||||||UB067815EDI0025||||||20180724|20180724",
"TRLR|1" };

assertEquals(cstat[0], returnRes.get(1));
assertEquals(cstat[1], returnRes.get(2));
assertEquals(3, returnRes.size());
verify(hdrRepo, times(1)).findBybatchId(String.valueOf(35));
verify(trlrRepo, times(1)).findByheaderRecordDetail(headerRecord);
verify(clrdRepo, times(1)).updateStatus(clrdUpdate, "COMPLETE");
assertTrue(clrd.getClaimStatusRecordDetails().isEmpty());
assertTrue(clrd.getLineLevelRecordsDetails().isEmpty());

// to make sure the segment starts with their respective recid
assertEquals("CLM", returnRes.get(1).substring(0, 3));
}

@Test
public void testBuildCLMSTCSegmentWithOutLines_success() {

lineLevelRecordsDetails = new ArrayList<LineLevelRecordsDetail>();
clsrec.setLineLevelRecordsDetail(null);
clsr.add(clsrec);
clrd.setLineLevelRecordsDetails(lineLevelRecordsDetails);
assertNotNull(headerRecord);
assertNotNull(this.clsr);
clrd.setClaimStatusRecordDetails(this.clsr);
clrdList.add(clrd);

when(hdrRepo.findBybatchId(String.valueOf(35))).thenReturn(headerRecordList);
when(clrdRepo.findPendingCLMWithLines(35L)).thenReturn(new ArrayList<>());
when(clrdRepo.findPendingCLMWithoutLines(35L)).thenReturn(clrdList);
when(trlrRepo.findByheaderRecordDetail(headerRecord)).thenReturn(trailerRecord);

List<String> returnRes = cstatService.buildAllSegments(35L, lineCounter);

String[] cstat = {
"CLM|2|VAFEE|021|||9898989898|Veteran|||||||||||||987654|PatienLName|PatientFirstName||||PatienLName|PatientFirstName|||19850818|||103.88||||||UB067815EDI0025||||||20180724|20180724",
"STC|3|VAFEE|UB067815EDI0025||20180724|A3|19|||" };

assertEquals(cstat[0], returnRes.get(1));
assertEquals(cstat[1], returnRes.get(2));
verify(hdrRepo, times(1)).findBybatchId(String.valueOf(35));
assertEquals(4, returnRes.size());
assertFalse(clrd.getClaimStatusRecordDetails().isEmpty());
assertTrue(clrd.getLineLevelRecordsDetails().isEmpty());
// to make sure the segment starts with their respective recid
assertEquals("STC", returnRes.get(2).substring(0, 3));
}

@Test
public void testBuildCLMDTLSegment_success() {
assertNotNull(headerRecord);

lineLevelRecordsDetail.setClaimStatusRecordDetails(new ArrayList<>());
lineLevelRecordsDetails.add(lineLevelRecordsDetail);

clrd.setLineLevelRecordsDetails(lineLevelRecordsDetails);
clrdList.add(clrd);

when(hdrRepo.findBybatchId(String.valueOf(35))).thenReturn(headerRecordList);
when(clrdRepo.findPendingCLMWithLines(35L)).thenReturn(clrdList);
when(clrdRepo.findPendingCLMWithoutLines(35L)).thenReturn(new ArrayList<>());
when(trlrRepo.findByheaderRecordDetail(headerRecord)).thenReturn(trailerRecord);

List<String> returnRes = cstatService.buildAllSegments(35L, lineCounter);

String[] cstat = {
"CLM|2|VAFEE|021|||9898989898|Veteran|||||||||||||987654|PatienLName|PatientFirstName||||PatienLName|PatientFirstName|||19850818|||103.88||||||UB067815EDI0025||||||20180724|20180724",
"DTL|3|VAFEE|UB067815EDI0025|357896|951248|842159|||||5656565.0|9899898.0||||20180724|20180724" };

assertEquals(cstat[0], returnRes.get(1));
assertEquals(cstat[1], returnRes.get(2));
assertEquals(4, returnRes.size());

verify(hdrRepo, times(1)).findBybatchId(String.valueOf(35));
assertFalse(clrd.getLineLevelRecordsDetails().isEmpty());
assertTrue(lineLevelRecordsDetail.getClaimStatusRecordDetails().isEmpty());
}

@Test
public void testBuildCLMDTLSTCSegment_success() {
assertNotNull(headerRecord);

clsr.add(clsrec);
clrd.setClaimStatusRecordDetails(clsr);

assertNotNull(clsr);

ClaimStatusRecordDetail lineLevelStatus = (ClaimStatusRecordDetail) SerializationUtils.clone(clsrec);
lineLevelStatus.setHlptStc02Stciedate(null);
lineLevelStatus.setLineLevelRecordsDetail(lineLevelRecordsDetail);
lineLevelStatus.setHl3ptRef022200d1kPcidnum("Line Payer Claim Identification Number");
List<ClaimStatusRecordDetail> lineLevelStatusList = new ArrayList<>();
lineLevelStatusList.add(lineLevelStatus);

lineLevelRecordsDetail.setClaimStatusRecordDetails(lineLevelStatusList);
lineLevelRecordsDetails.add(lineLevelRecordsDetail);

clrd.setLineLevelRecordsDetails(lineLevelRecordsDetails);
clrdList.add(clrd);
//
when(hdrRepo.findBybatchId(String.valueOf(35))).thenReturn(headerRecordList);
when(clrdRepo.findPendingCLMWithLines(35L)).thenReturn(clrdList);
when(clrdRepo.findPendingCLMWithoutLines(35L)).thenReturn(new ArrayList<>());
when(trlrRepo.findByheaderRecordDetail(headerRecord)).thenReturn(trailerRecord);

List<String> returnRes = cstatService.buildAllSegments(35L, lineCounter);

String[] cstat = {
"CLM|2|VAFEE|021|||9898989898|Veteran|||||||||||||987654|PatienLName|PatientFirstName||||PatienLName|PatientFirstName|||19850818|||103.88||||||UB067815EDI0025||||||20180724|20180724",
"STC|3|VAFEE|UB067815EDI0025||20180724|A3|19|||",
"DTL|4|VAFEE|UB067815EDI0025|357896|951248|842159|||||5656565.0|9899898.0||||20180724|20180724",
"STC|5|VAFEE|Line Payer Claim Identification Number||20180724|A3|19|||" };

assertEquals(cstat[0], returnRes.get(1));
assertEquals(cstat[1], returnRes.get(2));
assertEquals(cstat[2], returnRes.get(3));
assertEquals(cstat[3], returnRes.get(4));
assertEquals(6, returnRes.size());

verify(hdrRepo, times(1)).findBybatchId(String.valueOf(35));
assertFalse(clrd.getLineLevelRecordsDetails().isEmpty());
assertFalse(lineLevelRecordsDetail.getClaimStatusRecordDetails().isEmpty());
}

}