Negativtests im StructureValidator fachlich härten
This commit is contained in:
@@ -42,7 +42,7 @@ public class DefaultStructureValidator implements StructureValidator {
|
|||||||
if (inputFile.messages().isEmpty()) {
|
if (inputFile.messages().isEmpty()) {
|
||||||
errors.add(createError(
|
errors.add(createError(
|
||||||
"STRUCTURE_001",
|
"STRUCTURE_001",
|
||||||
"Input file must contain at least one message",
|
"Eingabedatei muss mindestens eine Nachricht enthalten",
|
||||||
ValidationSeverity.ERROR,
|
ValidationSeverity.ERROR,
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
@@ -277,14 +277,14 @@ public class DefaultStructureValidator implements StructureValidator {
|
|||||||
if (!unhReference.equals(normalizedUntReference)) {
|
if (!unhReference.equals(normalizedUntReference)) {
|
||||||
errors.add(createError(
|
errors.add(createError(
|
||||||
"STRUCTURE_007",
|
"STRUCTURE_007",
|
||||||
"UNH and UNT reference numbers do not match",
|
"UNH- und UNT-Referenznummern stimmen nicht überein",
|
||||||
ValidationSeverity.ERROR,
|
ValidationSeverity.ERROR,
|
||||||
"UNH/UNT",
|
"UNH/UNT",
|
||||||
message.messagePosition(),
|
message.messagePosition(),
|
||||||
"",
|
"",
|
||||||
0,
|
0,
|
||||||
unhReference + " != " + normalizedUntReference,
|
unhReference + " != " + normalizedUntReference,
|
||||||
"Reference numbers in UNH and UNT must match"
|
"Referenznummern in UNH und UNT müssen übereinstimmen"
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -303,7 +303,7 @@ public class DefaultStructureValidator implements StructureValidator {
|
|||||||
if (segments.isEmpty()) {
|
if (segments.isEmpty()) {
|
||||||
errors.add(createError(
|
errors.add(createError(
|
||||||
"STRUCTURE_002",
|
"STRUCTURE_002",
|
||||||
"Message must contain at least one segment",
|
"Nachricht muss mindestens ein Segment enthalten",
|
||||||
ValidationSeverity.ERROR,
|
ValidationSeverity.ERROR,
|
||||||
"",
|
"",
|
||||||
messagePosition,
|
messagePosition,
|
||||||
@@ -340,7 +340,7 @@ public class DefaultStructureValidator implements StructureValidator {
|
|||||||
if (!segmentPositions.add(segmentPosition)) {
|
if (!segmentPositions.add(segmentPosition)) {
|
||||||
errors.add(createError(
|
errors.add(createError(
|
||||||
"STRUCTURE_005",
|
"STRUCTURE_005",
|
||||||
"Duplicate segment position: " + segmentPosition,
|
"Doppelte Segmentposition: " + segmentPosition,
|
||||||
ValidationSeverity.ERROR,
|
ValidationSeverity.ERROR,
|
||||||
segmentName,
|
segmentName,
|
||||||
segmentPosition,
|
segmentPosition,
|
||||||
@@ -380,7 +380,7 @@ public class DefaultStructureValidator implements StructureValidator {
|
|||||||
if (!fieldPositions.add(fieldPosition)) {
|
if (!fieldPositions.add(fieldPosition)) {
|
||||||
errors.add(createError(
|
errors.add(createError(
|
||||||
"STRUCTURE_004",
|
"STRUCTURE_004",
|
||||||
"Duplicate field position: " + fieldPosition,
|
"Doppelte Feldposition: " + fieldPosition,
|
||||||
ValidationSeverity.ERROR,
|
ValidationSeverity.ERROR,
|
||||||
segmentName,
|
segmentName,
|
||||||
segmentPosition,
|
segmentPosition,
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class DefaultStructureValidatorTest {
|
|||||||
|
|
||||||
ValidationError error = result.getErrors().get(0);
|
ValidationError error = result.getErrors().get(0);
|
||||||
assertEquals("STRUCTURE_001", error.errorCode());
|
assertEquals("STRUCTURE_001", error.errorCode());
|
||||||
assertEquals("Input file must contain at least one message", error.description());
|
assertEquals("Eingabedatei muss mindestens eine Nachricht enthalten", error.description());
|
||||||
assertEquals("", error.segmentName());
|
assertEquals("", error.segmentName());
|
||||||
assertEquals(0, error.segmentPosition());
|
assertEquals(0, error.segmentPosition());
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ class DefaultStructureValidatorTest {
|
|||||||
|
|
||||||
ValidationError error = result.getErrors().get(0);
|
ValidationError error = result.getErrors().get(0);
|
||||||
assertEquals("STRUCTURE_002", error.errorCode());
|
assertEquals("STRUCTURE_002", error.errorCode());
|
||||||
assertEquals("Message must contain at least one segment", error.description());
|
assertEquals("Nachricht muss mindestens ein Segment enthalten", error.description());
|
||||||
assertEquals("", error.segmentName());
|
assertEquals("", error.segmentName());
|
||||||
assertEquals(1, error.segmentPosition());
|
assertEquals(1, error.segmentPosition());
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ class DefaultStructureValidatorTest {
|
|||||||
|
|
||||||
ValidationError error = result.getErrors().get(0);
|
ValidationError error = result.getErrors().get(0);
|
||||||
assertEquals("STRUCTURE_005", error.errorCode());
|
assertEquals("STRUCTURE_005", error.errorCode());
|
||||||
assertEquals("Duplicate segment position: 2", error.description());
|
assertEquals("Doppelte Segmentposition: 2", error.description());
|
||||||
assertEquals("SEG2", error.segmentName());
|
assertEquals("SEG2", error.segmentName());
|
||||||
assertEquals(2, error.segmentPosition());
|
assertEquals(2, error.segmentPosition());
|
||||||
}
|
}
|
||||||
@@ -117,7 +117,7 @@ class DefaultStructureValidatorTest {
|
|||||||
|
|
||||||
ValidationError error = result.getErrors().get(0);
|
ValidationError error = result.getErrors().get(0);
|
||||||
assertEquals("STRUCTURE_004", error.errorCode());
|
assertEquals("STRUCTURE_004", error.errorCode());
|
||||||
assertEquals("Duplicate field position: 1", error.description());
|
assertEquals("Doppelte Feldposition: 1", error.description());
|
||||||
assertEquals("SEG1", error.segmentName());
|
assertEquals("SEG1", error.segmentName());
|
||||||
assertEquals(2, error.segmentPosition());
|
assertEquals(2, error.segmentPosition());
|
||||||
assertEquals(1, error.fieldPosition());
|
assertEquals(1, error.fieldPosition());
|
||||||
@@ -160,11 +160,11 @@ class DefaultStructureValidatorTest {
|
|||||||
|
|
||||||
ValidationError error = result.getErrors().get(0);
|
ValidationError error = result.getErrors().get(0);
|
||||||
assertEquals("STRUCTURE_007", error.errorCode());
|
assertEquals("STRUCTURE_007", error.errorCode());
|
||||||
assertEquals("UNH and UNT reference numbers do not match", error.description());
|
assertEquals("UNH- und UNT-Referenznummern stimmen nicht überein", error.description());
|
||||||
assertEquals("UNH/UNT", error.segmentName());
|
assertEquals("UNH/UNT", error.segmentName());
|
||||||
assertEquals(1, error.segmentPosition());
|
assertEquals(1, error.segmentPosition());
|
||||||
assertEquals("12345 != 54321", error.actualValue());
|
assertEquals("12345 != 54321", error.actualValue());
|
||||||
assertEquals("Reference numbers in UNH and UNT must match", error.expectedRule());
|
assertEquals("Referenznummern in UNH und UNT müssen übereinstimmen", error.expectedRule());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -181,9 +181,10 @@ class DefaultStructureValidatorTest {
|
|||||||
ValidationResult result = validator.validate(inputFile);
|
ValidationResult result = validator.validate(inputFile);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
// Check that we don't have the STRUCTURE_007 error
|
// Should not have STRUCTURE_007 error and should have no errors overall
|
||||||
assertFalse(result.getErrors().stream()
|
assertFalse(result.getErrors().stream()
|
||||||
.anyMatch(error -> "STRUCTURE_007".equals(error.errorCode())));
|
.anyMatch(error -> "STRUCTURE_007".equals(error.errorCode())));
|
||||||
|
assertFalse(result.hasErrors(), "There should be no validation errors for valid UNH/UNT reference numbers");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -204,6 +205,9 @@ class DefaultStructureValidatorTest {
|
|||||||
// Any existing structural errors are acceptable but not our new error
|
// Any existing structural errors are acceptable but not our new error
|
||||||
assertFalse(result.getErrors().stream()
|
assertFalse(result.getErrors().stream()
|
||||||
.anyMatch(error -> "STRUCTURE_007".equals(error.errorCode())));
|
.anyMatch(error -> "STRUCTURE_007".equals(error.errorCode())));
|
||||||
|
// Should have exactly one error for missing UNH (STRUCTURE_009)
|
||||||
|
assertEquals(1, result.getErrors().size(), "Should have exactly one error for missing UNH");
|
||||||
|
assertEquals("STRUCTURE_009", result.getErrors().get(0).errorCode(), "Error should be STRUCTURE_009 for missing UNH");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -224,6 +228,9 @@ class DefaultStructureValidatorTest {
|
|||||||
// Any existing structural errors are acceptable but not our new error
|
// Any existing structural errors are acceptable but not our new error
|
||||||
assertFalse(result.getErrors().stream()
|
assertFalse(result.getErrors().stream()
|
||||||
.anyMatch(error -> "STRUCTURE_007".equals(error.errorCode())));
|
.anyMatch(error -> "STRUCTURE_007".equals(error.errorCode())));
|
||||||
|
// Should have exactly one error for missing UNT (STRUCTURE_010)
|
||||||
|
assertEquals(1, result.getErrors().size(), "Should have exactly one error for missing UNT");
|
||||||
|
assertEquals("STRUCTURE_010", result.getErrors().get(0).errorCode(), "Error should be STRUCTURE_010 for missing UNT");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -268,9 +275,10 @@ class DefaultStructureValidatorTest {
|
|||||||
ValidationResult result = validator.validate(inputFile);
|
ValidationResult result = validator.validate(inputFile);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
// Should not have STRUCTURE_008 error
|
// Should not have STRUCTURE_008 error and should have no errors overall
|
||||||
assertFalse(result.getErrors().stream()
|
assertFalse(result.getErrors().stream()
|
||||||
.anyMatch(error -> "STRUCTURE_008".equals(error.errorCode())));
|
.anyMatch(error -> "STRUCTURE_008".equals(error.errorCode())));
|
||||||
|
assertFalse(result.hasErrors(), "There should be no validation errors for valid segment count");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -287,9 +295,10 @@ class DefaultStructureValidatorTest {
|
|||||||
ValidationResult result = validator.validate(inputFile);
|
ValidationResult result = validator.validate(inputFile);
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
// Should not have STRUCTURE_008 error (because count field is non-numeric)
|
// Should not have STRUCTURE_008 error (because count field is non-numeric) and should have no errors overall
|
||||||
assertFalse(result.getErrors().stream()
|
assertFalse(result.getErrors().stream()
|
||||||
.anyMatch(error -> "STRUCTURE_008".equals(error.errorCode())));
|
.anyMatch(error -> "STRUCTURE_008".equals(error.errorCode())));
|
||||||
|
assertFalse(result.hasErrors(), "There should be no validation errors for non-numeric segment count");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -437,6 +446,9 @@ class DefaultStructureValidatorTest {
|
|||||||
// Should not have STRUCTURE_008 error for segment count mismatch when UNT is missing
|
// Should not have STRUCTURE_008 error for segment count mismatch when UNT is missing
|
||||||
assertFalse(result.getErrors().stream()
|
assertFalse(result.getErrors().stream()
|
||||||
.anyMatch(error -> "STRUCTURE_008".equals(error.errorCode())));
|
.anyMatch(error -> "STRUCTURE_008".equals(error.errorCode())));
|
||||||
|
// Should have exactly one error for missing UNT (STRUCTURE_010)
|
||||||
|
assertEquals(1, result.getErrors().size(), "Should have exactly one error for missing UNT");
|
||||||
|
assertEquals("STRUCTURE_010", result.getErrors().get(0).errorCode(), "Error should be STRUCTURE_010 for missing UNT");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -501,6 +513,9 @@ class DefaultStructureValidatorTest {
|
|||||||
// Should not have STRUCTURE_011 error for UNH/UNT order when UNH is missing
|
// Should not have STRUCTURE_011 error for UNH/UNT order when UNH is missing
|
||||||
assertFalse(result.getErrors().stream()
|
assertFalse(result.getErrors().stream()
|
||||||
.anyMatch(error -> "STRUCTURE_011".equals(error.errorCode())));
|
.anyMatch(error -> "STRUCTURE_011".equals(error.errorCode())));
|
||||||
|
// Should have exactly one error for missing UNH (STRUCTURE_009)
|
||||||
|
assertEquals(1, result.getErrors().size(), "Should have exactly one error for missing UNH");
|
||||||
|
assertEquals("STRUCTURE_009", result.getErrors().get(0).errorCode(), "Error should be STRUCTURE_009 for missing UNH");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -520,5 +535,8 @@ class DefaultStructureValidatorTest {
|
|||||||
// Should not have STRUCTURE_011 error for UNH/UNT order when UNT is missing
|
// Should not have STRUCTURE_011 error for UNH/UNT order when UNT is missing
|
||||||
assertFalse(result.getErrors().stream()
|
assertFalse(result.getErrors().stream()
|
||||||
.anyMatch(error -> "STRUCTURE_011".equals(error.errorCode())));
|
.anyMatch(error -> "STRUCTURE_011".equals(error.errorCode())));
|
||||||
|
// Should have exactly one error for missing UNT (STRUCTURE_010)
|
||||||
|
assertEquals(1, result.getErrors().size(), "Should have exactly one error for missing UNT");
|
||||||
|
assertEquals("STRUCTURE_010", result.getErrors().get(0).errorCode(), "Error should be STRUCTURE_010 for missing UNT");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
UNH+12345+ORDERS:D:03B:UN:EAN008'
|
|
||||||
BGM+220+100001'
|
BGM+220+100001'
|
||||||
DTM+137:20260325:102'
|
DTM+137:20260325:102'
|
||||||
NAD+BY+5000000000000:16++Customer Name'
|
NAD+BY+5000000000000:16++Customer Name'
|
||||||
@@ -6,4 +5,4 @@ LIN+1++Product123:SA'
|
|||||||
QTY+21:10:PCE'
|
QTY+21:10:PCE'
|
||||||
UNS+S'
|
UNS+S'
|
||||||
CNT+2:1'
|
CNT+2:1'
|
||||||
UNT+9+12345'
|
UNT+8+12345'
|
||||||
Reference in New Issue
Block a user