Repository: xlate/staedi (java)

Issue:
Validator should be reset at end of interchange
To support multiple interchanges, the validator should be reset at the end of each interchange. The current behavior flags interchanges after the first as "too many occurrences". See [1]

Relates to:
#358 
#352 

[1] https://github.com/xlate/staedi/discussions/352#discussioncomment-5866280

Pull request:
fix: Reset validator at end of interchange
Fixes #366

Patch:
diff --git a/src/main/java/io/xlate/edi/internal/stream/tokenization/ProxyEventHandler.java b/src/main/java/io/xlate/edi/internal/stream/tokenization/ProxyEventHandler.java
index 2d8fbcd..0238d55 100644
--- a/src/main/java/io/xlate/edi/internal/stream/tokenization/ProxyEventHandler.java
+++ b/src/main/java/io/xlate/edi/internal/stream/tokenization/ProxyEventHandler.java
@@ -197,6 +197,7 @@ public class ProxyEventHandler implements EventHandler {
 
         if (validator != null) {
             validator.validateLoopSyntax(this);
+            validator.reset();
         }
 
         enqueueEvent(EDIStreamEvent.END_INTERCHANGE, EDIStreamValidationError.NONE, "", null, location);


Test patch:
diff --git a/src/test/java/io/xlate/edi/internal/stream/StaEDIStreamReaderTest.java b/src/test/java/io/xlate/edi/internal/stream/StaEDIStreamReaderTest.java
index 155c934..a766f49 100644
--- a/src/test/java/io/xlate/edi/internal/stream/StaEDIStreamReaderTest.java
+++ b/src/test/java/io/xlate/edi/internal/stream/StaEDIStreamReaderTest.java
@@ -67,7 +67,6 @@ import io.xlate.edi.schema.Schema;
 import io.xlate.edi.schema.SchemaFactory;
 import io.xlate.edi.stream.EDIInputFactory;
 import io.xlate.edi.stream.EDIStreamConstants.Delimiters;
-import io.xlate.edi.test.StaEDITestUtil;
 import io.xlate.edi.stream.EDIStreamEvent;
 import io.xlate.edi.stream.EDIStreamException;
 import io.xlate.edi.stream.EDIStreamReader;
@@ -2124,6 +2123,10 @@ class StaEDIStreamReaderTest implements ConstantsTest {
                 case END_INTERCHANGE:
                     interchangeEnd++;
                     break;
+                case SEGMENT_ERROR:
+                case ELEMENT_OCCURRENCE_ERROR:
+                case ELEMENT_DATA_ERROR:
+                    fail("Unexpected error: " + reader.getErrorType());
                 default:
                     break;
                 }
@@ -2132,7 +2135,7 @@ class StaEDIStreamReaderTest implements ConstantsTest {
             reader.close();
         }
 
-        assertEquals(2, interchangeStart);
-        assertEquals(2, interchangeEnd);
+        assertEquals(3, interchangeStart);
+        assertEquals(3, interchangeEnd);
     }
 }
diff --git a/src/test/resources/x12/simple997-multiple-interchanges.edi b/src/test/resources/x12/simple997-multiple-interchanges.edi
index df07c8e..934d5c1 100644
--- a/src/test/resources/x12/simple997-multiple-interchanges.edi
+++ b/src/test/resources/x12/simple997-multiple-interchanges.edi
@@ -1,4 +1,4 @@
-ISA*00*          *00*          *ZZ*ReceiverID     *ZZ*Sender         *050812*1953*^*00501*508121953*0*P*:~
+ISA*00*          *00*          *ZZ*ReceiverID     *ZZ*Sender         *050812*1953*^*00501*000000001*0*P*:~
 GS*FA*ReceiverDept*SenderDept*20050812*195335*000005*X*005010X230~
 ST*997*0001~
 AK1*HC*000001~
@@ -9,8 +9,8 @@ AK5*R*5~
 AK9*R*1*1*0~
 SE*8*0001~
 GE*1*000005~
-IEA*1*508121953~
-ISA*00*          *00*          *ZZ*ReceiverID     *ZZ*Sender         *050812*1953*^*00501*508121953*0*P*:~
+IEA*1*000000001~
+ISA*00*          *00*          *ZZ*ReceiverID     *ZZ*Sender         *050812*1953*^*00501*000000002*0*P*:~
 GS*FA*ReceiverDept*SenderDept*20050812*195335*000005*X*005010X230~
 ST*997*0001~
 AK1*HC*000001~
@@ -21,4 +21,16 @@ AK5*R*5~
 AK9*R*1*1*0~
 SE*8*0001~
 GE*1*000005~
-IEA*1*508121953~
+IEA*1*000000002~
+ISA*00*          *00*          *ZZ*ReceiverID     *ZZ*Sender         *050812*1953*^*00501*000000003*0*P*:~
+GS*FA*ReceiverDept*SenderDept*20050812*195335*000005*X*005010X230~
+ST*997*0001~
+AK1*HC*000001~
+AK2*837*0021~
+AK3*NM1*8**8~
+AK4*8*66*7*MI~
+AK5*R*5~
+AK9*R*1*1*0~
+SE*8*0001~
+GE*1*000005~
+IEA*1*000000003~