From 694f2cd0e3341dd2d4eaf61467ef9f91881ddb4d Mon Sep 17 00:00:00 2001
From: lkolla447 <46097644+lkolla447@users.noreply.github.com>
Date: Wed, 6 Dec 2023 14:44:21 -0500
Subject: [PATCH] Change ASN 856 parsing error messages (#153)
---
pom.xml | 2 +-
.../txset/asn856/DefaultAsn856TransactionSetParser.java | 8 +++++---
.../java/com/walmartlabs/x12/util/loop/X12LoopUtil.java | 9 ++++-----
.../x12/standard/txset/asn856/Asn856ParserTest.java | 2 +-
.../asn856/DefaultAsn856TransactionSetParserTest.java | 8 +++++---
.../x12/standard/txset/generic/GenericParserTest.java | 4 ++--
.../com/walmartlabs/x12/util/loop/X12LoopUtilTest.java | 4 ++--
7 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/pom.xml b/pom.xml
index 5588a32..b272462 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
com.walmartlabs.x12
gozer
gozer
- 0.3.5-SNAPSHOT
+ 0.3.6-SNAPSHOT
takari-jar
diff --git a/src/main/java/com/walmartlabs/x12/standard/txset/asn856/DefaultAsn856TransactionSetParser.java b/src/main/java/com/walmartlabs/x12/standard/txset/asn856/DefaultAsn856TransactionSetParser.java
index f068299..efd2d94 100644
--- a/src/main/java/com/walmartlabs/x12/standard/txset/asn856/DefaultAsn856TransactionSetParser.java
+++ b/src/main/java/com/walmartlabs/x12/standard/txset/asn856/DefaultAsn856TransactionSetParser.java
@@ -214,7 +214,8 @@ private void parseShipmentLoop(X12Loop unparsedLoop, AsnTransactionSet asnTx) {
}
} else {
asnTx.addX12ErrorDetailForLoop(
- new X12ErrorDetail("HL", "03", "first HL is not a shipment it was " + unparsedLoop.getCode()));
+ new X12ErrorDetail("HL", "03", "Invalid Looping Structure",
+ "first HL is not a shipment it was " + unparsedLoop.getCode()));
}
}
@@ -247,7 +248,7 @@ private void parseOrderLoop(X12Loop unparsedLoop, Shipment shipment, AsnTransact
} else {
asnTx.addX12ErrorDetailForLoop(
- new X12ErrorDetail("HL", "03", "Unexpected child loop", "expected Order HL but got " + unparsedLoop.getCode()));
+ new X12ErrorDetail("HL", "03", "Invalid Looping Structure", "expected Order HL but got " + unparsedLoop.getCode()));
}
}
@@ -680,7 +681,8 @@ protected void handleLooping(SegmentIterator segments, AsnTransactionSet asnTx)
} else {
// doesn't start w/ HL
asnTx.addX12ErrorDetailForLoop(
- new X12ErrorDetail(currentSegment.getIdentifier(), null, "missing shipment loop"));
+ new X12ErrorDetail(currentSegment.getIdentifier(), null, "Invalid Looping Structure",
+ "missing shipment loop"));
// we should back it up
// and let the parser keep going
// with that segment
diff --git a/src/main/java/com/walmartlabs/x12/util/loop/X12LoopUtil.java b/src/main/java/com/walmartlabs/x12/util/loop/X12LoopUtil.java
index 38c0400..2b2b22f 100644
--- a/src/main/java/com/walmartlabs/x12/util/loop/X12LoopUtil.java
+++ b/src/main/java/com/walmartlabs/x12/util/loop/X12LoopUtil.java
@@ -29,9 +29,8 @@
public final class X12LoopUtil {
- private static final String MISSING_PARENT_ERROR = "HL segment is missing parent";
- private static final String ALREADY_EXISTS_ERROR = "HL segment already exists";
-
+ private static final String INVALID_LOOPING_STRUCTURE_ERROR = "Invalid Looping Structure";
+
/**
* check the segment for the start of HL
* @param segment
@@ -170,14 +169,14 @@ private static X12ErrorDetail loopAlreadyExistsErrorDetail(X12Loop loop) {
sb.append("HL segment with id (")
.append(loop.getHierarchicalId())
.append(") already exists");
- return new X12ErrorDetail(X12Loop.HIERARCHY_LOOP_ID, null, ALREADY_EXISTS_ERROR, sb.toString());
+ return new X12ErrorDetail(X12Loop.HIERARCHY_LOOP_ID, null, INVALID_LOOPING_STRUCTURE_ERROR, sb.toString());
}
private static X12ErrorDetail loopMissingParentErrorDetail(X12Loop loop) {
StringBuilder sb = new StringBuilder();
sb.append("HL segment with id (").append(loop.getHierarchicalId()).append(")");
sb.append(" is missing parent (").append(loop.getParentHierarchicalId()).append(")");
- return new X12ErrorDetail(X12Loop.HIERARCHY_LOOP_ID, null, MISSING_PARENT_ERROR, sb.toString());
+ return new X12ErrorDetail(X12Loop.HIERARCHY_LOOP_ID, null, INVALID_LOOPING_STRUCTURE_ERROR, sb.toString());
}
private X12LoopUtil() {
diff --git a/src/test/java/com/walmartlabs/x12/standard/txset/asn856/Asn856ParserTest.java b/src/test/java/com/walmartlabs/x12/standard/txset/asn856/Asn856ParserTest.java
index 89603fb..bdd97eb 100644
--- a/src/test/java/com/walmartlabs/x12/standard/txset/asn856/Asn856ParserTest.java
+++ b/src/test/java/com/walmartlabs/x12/standard/txset/asn856/Asn856ParserTest.java
@@ -171,7 +171,7 @@ public void test_Parsing_Asn856_badLoops() throws IOException {
X12ErrorDetail loopError = loopErrors.get(0);
assertEquals("HL", loopError.getSegmentId());
assertNull(loopError.getElementId());
- assertEquals("HL segment is missing parent", loopError.getIssueText());
+ assertEquals("Invalid Looping Structure", loopError.getIssueText());
assertEquals("HL segment with id (2) is missing parent (99)", loopError.getInvalidValue());
// BSN
diff --git a/src/test/java/com/walmartlabs/x12/standard/txset/asn856/DefaultAsn856TransactionSetParserTest.java b/src/test/java/com/walmartlabs/x12/standard/txset/asn856/DefaultAsn856TransactionSetParserTest.java
index d09e404..3776a16 100644
--- a/src/test/java/com/walmartlabs/x12/standard/txset/asn856/DefaultAsn856TransactionSetParserTest.java
+++ b/src/test/java/com/walmartlabs/x12/standard/txset/asn856/DefaultAsn856TransactionSetParserTest.java
@@ -157,7 +157,8 @@ public void test_doParse_NoHierarchicalLoops() {
List loopErrors = asnTx.getLoopingErrors();
assertNotNull(loopErrors);
assertEquals(1, loopErrors.size());
- assertEquals("missing shipment loop", loopErrors.get(0).getIssueText());
+ assertEquals("Invalid Looping Structure", loopErrors.get(0).getIssueText());
+ assertEquals("missing shipment loop", loopErrors.get(0).getInvalidValue());
// BSN
assertEquals("05755986", asnTx.getShipmentIdentification());
@@ -175,7 +176,8 @@ public void test_doParse_FirstLoop_NotShipment() {
// looping check
List loopErrors = asnTx.getLoopingErrors();
assertEquals(1, loopErrors.size());
- assertEquals("first HL is not a shipment it was X", loopErrors.get(0).getIssueText());
+ assertEquals("Invalid Looping Structure", loopErrors.get(0).getIssueText());
+ assertEquals("first HL is not a shipment it was X", loopErrors.get(0).getInvalidValue());
// BSN
assertEquals("05755986", asnTx.getShipmentIdentification());
@@ -193,7 +195,7 @@ public void test_doParseSecondLoop_NotOrder() {
// looping check
List loopErrors = asnTx.getLoopingErrors();
assertEquals(1, loopErrors.size());
- assertEquals("Unexpected child loop", loopErrors.get(0).getIssueText());
+ assertEquals("Invalid Looping Structure", loopErrors.get(0).getIssueText());
assertEquals("expected Order HL but got X", loopErrors.get(0).getInvalidValue());
// BSN
diff --git a/src/test/java/com/walmartlabs/x12/standard/txset/generic/GenericParserTest.java b/src/test/java/com/walmartlabs/x12/standard/txset/generic/GenericParserTest.java
index d9afd1a..98b553f 100644
--- a/src/test/java/com/walmartlabs/x12/standard/txset/generic/GenericParserTest.java
+++ b/src/test/java/com/walmartlabs/x12/standard/txset/generic/GenericParserTest.java
@@ -419,10 +419,10 @@ public void test_Parsing_AdvanceShipNoticeDocument_bad_loop() {
assertNotNull(loopErrors);
assertEquals(2, loopErrors.size());
// loop error 1
- assertEquals("HL segment already exists", loopErrors.get(0).getIssueText());
+ assertEquals("Invalid Looping Structure", loopErrors.get(0).getIssueText());
assertEquals("HL segment with id (1) already exists", loopErrors.get(0).getInvalidValue());
// loop error 2
- assertEquals("HL segment is missing parent", loopErrors.get(1).getIssueText());
+ assertEquals("Invalid Looping Structure", loopErrors.get(1).getIssueText());
assertEquals("HL segment with id (3) is missing parent (2)", loopErrors.get(1).getInvalidValue());
// Shipment
diff --git a/src/test/java/com/walmartlabs/x12/util/loop/X12LoopUtilTest.java b/src/test/java/com/walmartlabs/x12/util/loop/X12LoopUtilTest.java
index c2e75f5..88f2f75 100644
--- a/src/test/java/com/walmartlabs/x12/util/loop/X12LoopUtilTest.java
+++ b/src/test/java/com/walmartlabs/x12/util/loop/X12LoopUtilTest.java
@@ -274,7 +274,7 @@ public void test_findHierarchicalLoops_one_loop_missing_parent() {
X12ErrorDetail loopError = loopErrors.get(0);
assertEquals("HL", loopError.getSegmentId());
assertNull(loopError.getElementId());
- assertEquals("HL segment is missing parent", loopError.getIssueText());
+ assertEquals("Invalid Looping Structure", loopError.getIssueText());
assertEquals("HL segment with id (4) is missing parent (3)", loopError.getInvalidValue());
}
@@ -347,7 +347,7 @@ public void test_findHierarchicalLoops_one_loop_repeated_id() {
X12ErrorDetail loopError = loopErrors.get(0);
assertEquals("HL", loopError.getSegmentId());
assertNull(loopError.getElementId());
- assertEquals("HL segment already exists", loopError.getIssueText());
+ assertEquals("Invalid Looping Structure", loopError.getIssueText());
assertEquals("HL segment with id (2) already exists", loopError.getInvalidValue());
}