Skip to content

Commit

Permalink
DebatcherTest passes 100%: fixes nullbucket#4
Browse files Browse the repository at this point in the history
  • Loading branch information
short000 committed Mar 22, 2018
1 parent d511812 commit 99ad703
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 68 deletions.
15 changes: 13 additions & 2 deletions src/main/java/org/null0/edi/debatcher/Debatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public void debatch(String transactionId, InputStream inputStream) throws Except

public Map<String, Long> debatch(String transactionId, long batchIdMetadata, InputStream inputStream) throws Exception {
logger.info("debatching started..." + transactionId);
if (inputStream == null) {
final String msg = "Null input stream, nothing to do!";
logger.error(msg);
throw new NullPointerException(msg);
}

this.transactionId = transactionId;
this.inputStream = inputStream;
this.batchIdMetadata = batchIdMetadata < 0 ? this.metadataLogger.logBatchSubmissionData(transactionId) : batchIdMetadata;
Expand All @@ -117,12 +123,17 @@ public Map<String, Long> debatch(String transactionId, long batchIdMetadata, Inp
private void readInterchangeControls() throws Exception {
while (!fileReadCompleted) {
getNextSegment();
if (delimiters.getOsNewLine().equals(segment)) {

if (StringUtils.isAllBlank(segment)) {
logger.warn("Ignoring unexpected whitespace.");
continue;
}

/* TODO: we should probably delete this
if (segment == null || segment.equals("\r\n")) {
throw new DebatcherException ("Invalid Control Structure", EdiValidatorDefault.TA1_ERROR_ISAIEA, ERROR.TYPE_TA1, ERROR_LEVEL.Batch, batchIdMetadata);
}
}*/

isaSegment = segment.replaceAll("\\r|\\n", "");
ediValidator.validate(batchIdMetadata, X12_ELEMENT.DATA_SEPARATOR, fieldDlm, null);
isa13 = readField(segment, 13);
Expand Down
24 changes: 8 additions & 16 deletions src/main/java/org/null0/edi/debatcher/Delimiters.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Delimiters {
private char dataElementSeparator;
private char segmentTerminator;
private EdiWrapStyle ediWrap;
private String eol;
private String osNewLine;

enum EdiWrapStyle {
Expand Down Expand Up @@ -51,33 +52,24 @@ public void setLineWrap(EdiWrapStyle ediWrap) {
* @return EdiWrapStyle This setter returns the wrap style (same as calling getLineWrap)
*/
public EdiWrapStyle setLineWrap(byte[] dataChunk, int maxBytesToScan) {
this.ediWrap = EdiWrapStyle.Unwrapped;
eol = "";
ediWrap = EdiWrapStyle.Unwrapped;
int max = Math.min(dataChunk.length, maxBytesToScan);
for (int i = 0; i < max - 1; i++) {
if (dataChunk[i] == 0x0D && dataChunk[i + 1] == 0x0A) {
this.ediWrap = EdiWrapStyle.Windows; // \r\n
ediWrap = EdiWrapStyle.Windows;
eol = "\r\n";
break;
} else if (dataChunk[i] == 0x0A) {
this.ediWrap = EdiWrapStyle.Unix; // \n
ediWrap = EdiWrapStyle.Unix; // \n
eol = "\n";
break;
}
}
return this.ediWrap;
return ediWrap;
}

public String getEOL() {
String eol;
switch (this.ediWrap) {
case Windows:
eol = "\r\n";
break;
case Unix:
eol = "\n";
break;
default:
eol = "";
break;
}
return eol;
}

Expand Down
73 changes: 23 additions & 50 deletions src/test/java/org/null0/edi/debatcher/test/DebatcherTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@

import java.io.InputStream;

import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.null0.edi.debatcher.Debatcher;

// TODO: This is scary. All the useful tests have been commented out! Why?
// First we'll get the other unit tests to pass (and verify their accuracy)
// then we'll start enabling and verify these unit tests.
//
public class DebatcherTest {
private static final Logger logger = LoggerFactory.getLogger(DebatcherTest.class);
private static Debatcher debatcher;
Expand All @@ -34,122 +29,100 @@ public void setUp() throws Exception {
// value in Submission table. So, test cases will fail when there is no entry in
// submission table.

@org.junit.Test
public void test_00() {
try {
test ("BAD_FILE");
} catch (Exception e) {
Assert.fail(e.getMessage());
}
@Test(expected=NullPointerException.class)
public void test_00() throws Exception {
test ("BAD_FILE_DOES_NOT_EXIST");
}

// TODO: Begin to uncomment these tests and get them to work. This one reads past the last segment (IEA) and throws null pointer exception comparing IEA-02 to ISA-13.
@org.junit.Test
@Test
public void test_01() throws Exception {
test ("1 ISA - 1 GS - 1 ST - 1 HL 20 - 1 HL 22 - 1 CLM");
}

@Ignore
@org.junit.Test
@Test
public void test_02() throws Exception {
test ("1 ISA - 1 GS - 1 ST - 1 HL 20 - 1 HL 22 - 2 CLMs");
}

@Ignore
@org.junit.Test
@Test
public void test_03() throws Exception {
test ("1 ISA - 1 GS - 1 ST - 1 HL 20 - 1 HL 22 - 3 CLMs");
}

@Ignore
@org.junit.Test
@Test
public void test_04() throws Exception {
test ("1 ISA - 1 GS - 1 ST - 1 HL 20 - 2 HL 22 - 1 CLM FOR EACH SUBSCRIBER");
}

@Ignore
@org.junit.Test
@Test
public void test_05() throws Exception {
test ("1 ISA - 1 GS - 1 ST - 1 HL 20 - 2 HL 22 - 2 CLMs FOR EACH SUBSCRIBER");
}

@Ignore
@org.junit.Test
@Test
public void test_06() throws Exception {
test ("1 ISA - 1 GS - 1 ST - 1 HL 20 - 1 HL 22 - 1 CLM - 1 HL 20 - 1 HL 22 - 1 CLM");
}

@Ignore
@org.junit.Test
@Test
public void test_07() throws Exception {
test ("1 ISA - 1 GS - 1 ST - 1 HL 20 - 1 HL 22 - 2 CLMs - 1 HL 20 - 1 HL 22 - 2 CLMs");
}

@Ignore
@org.junit.Test
@Test
public void test_08() throws Exception {
test ("1 ISA - 1 GS - 1 ST - 1 HL 20 - 1 HL 22 - 1 CLM - 1 ST - 1 HL 20 - 1 HL 22 - 1 CLM");
}

@Ignore
@org.junit.Test
@Test
public void test_09() throws Exception {
test ("1 ISA - 1 GS - 3 STs");
}

@Ignore
@org.junit.Test
@Test
public void test_10() throws Exception {
test ("1 ISA - 2 GSs");
}

@Ignore
@org.junit.Test
@Test
public void test_11() throws Exception {
test ("2 ISAs");
}

@Ignore
@org.junit.Test
@Test
public void test_12() throws Exception {
test ("837PFile_for de-batcher_multiple_fil_configs_inonefile");
}

@Ignore
@org.junit.Test
@Test
public void test_13() throws Exception {
test ("Patient");
}

@Ignore
@org.junit.Test
@Test
public void test_Large() throws Exception {
long startTime = System.currentTimeMillis();
test ("LargeP");
test ("837PFile_Large");
long endTime = System.currentTimeMillis();
logger.info("That took " + (endTime - startTime) + " milliseconds");
}

@Ignore
@org.junit.Test
@Test
public void test_P_NoRefD9() throws Exception {
test ("NoRefD9_P");
}

@Ignore
@org.junit.Test
@Test
public void test_P_RefD9() throws Exception {
test ("RefD9_P");
}

@Ignore
@org.junit.Test
@Test
public void test_I_NoRefD9() throws Exception {
test ("NoRefD9_I");
}

@Ignore
@org.junit.Test
@Test
public void test_I_RefD9() throws Exception {
test ("RefD9_I");
}
Expand Down

0 comments on commit 99ad703

Please sign in to comment.