Erste fachliche Strukturregel ergänzen: UNH-/UNT-Referenznummer prüfen

This commit is contained in:
2026-03-26 08:21:13 +01:00
parent 1b4b22b073
commit 6a7d150007
6 changed files with 222 additions and 47 deletions

View File

@@ -2,6 +2,9 @@ package de.gecheckt.asv.validation.structure;
import static org.junit.jupiter.api.Assertions.*;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;
@@ -12,6 +15,10 @@ import de.gecheckt.asv.domain.model.Field;
import de.gecheckt.asv.domain.model.InputFile;
import de.gecheckt.asv.domain.model.Message;
import de.gecheckt.asv.domain.model.Segment;
import de.gecheckt.asv.parser.DefaultInputFileParser;
import de.gecheckt.asv.parser.DefaultSegmentLineTokenizer;
import de.gecheckt.asv.parser.InputFileParseException;
import de.gecheckt.asv.parser.SegmentLineTokenizer;
import de.gecheckt.asv.validation.model.ValidationError;
import de.gecheckt.asv.validation.model.ValidationResult;
@@ -119,4 +126,89 @@ class DefaultStructureValidatorTest {
assertFalse(result.hasInfos());
assertTrue(result.getAllErrors().isEmpty());
}
@Test
void validate_shouldReportErrorWhenUnhAndUntReferenceNumbersDoNotMatch() throws IOException, InputFileParseException {
// Given
SegmentLineTokenizer tokenizer = new DefaultSegmentLineTokenizer();
DefaultInputFileParser parser = new DefaultInputFileParser(tokenizer);
String fileName = "unh-unt-mismatch.asv";
Path filePath = Path.of("src/test/resources/unh-unt-mismatch.asv");
String fileContent = Files.readString(filePath);
// When
InputFile inputFile = parser.parse(fileName, fileContent);
ValidationResult result = validator.validate(inputFile);
// Then
assertTrue(result.hasErrors());
assertEquals(1, result.getErrors().size());
ValidationError error = result.getErrors().get(0);
assertEquals("STRUCTURE_007", error.errorCode());
assertEquals("UNH and UNT reference numbers do not match", error.description());
assertEquals("UNH/UNT", error.segmentName());
assertEquals(1, error.segmentPosition());
assertEquals("12345 != 54321", error.actualValue());
assertEquals("Reference numbers in UNH and UNT must match", error.expectedRule());
}
@Test
void validate_shouldNotReportErrorWhenUnhAndUntReferenceNumbersMatch() throws IOException, InputFileParseException {
// Given
SegmentLineTokenizer tokenizer = new DefaultSegmentLineTokenizer();
DefaultInputFileParser parser = new DefaultInputFileParser(tokenizer);
String fileName = "unh-unt-match.asv";
Path filePath = Path.of("src/test/resources/unh-unt-match.asv");
String fileContent = Files.readString(filePath);
// When
InputFile inputFile = parser.parse(fileName, fileContent);
ValidationResult result = validator.validate(inputFile);
// Then
// Check that we don't have the STRUCTURE_007 error
assertFalse(result.getErrors().stream()
.anyMatch(error -> "STRUCTURE_007".equals(error.errorCode())));
}
@Test
void validate_shouldNotReportAdditionalErrorWhenUnhIsMissing() throws IOException, InputFileParseException {
// Given
SegmentLineTokenizer tokenizer = new DefaultSegmentLineTokenizer();
DefaultInputFileParser parser = new DefaultInputFileParser(tokenizer);
String fileName = "no-unh.asv";
Path filePath = Path.of("src/test/resources/no-unh.asv");
String fileContent = Files.readString(filePath);
// When
InputFile inputFile = parser.parse(fileName, fileContent);
ValidationResult result = validator.validate(inputFile);
// Then
// Should not have STRUCTURE_007 error for mismatch
// Any existing structural errors are acceptable but not our new error
assertFalse(result.getErrors().stream()
.anyMatch(error -> "STRUCTURE_007".equals(error.errorCode())));
}
@Test
void validate_shouldNotReportAdditionalErrorWhenUntIsMissing() throws IOException, InputFileParseException {
// Given
SegmentLineTokenizer tokenizer = new DefaultSegmentLineTokenizer();
DefaultInputFileParser parser = new DefaultInputFileParser(tokenizer);
String fileName = "no-unt.asv";
Path filePath = Path.of("src/test/resources/no-unt.asv");
String fileContent = Files.readString(filePath);
// When
InputFile inputFile = parser.parse(fileName, fileContent);
ValidationResult result = validator.validate(inputFile);
// Then
// Should not have STRUCTURE_007 error for mismatch
// Any existing structural errors are acceptable but not our new error
assertFalse(result.getErrors().stream()
.anyMatch(error -> "STRUCTURE_007".equals(error.errorCode())));
}
}

View File

@@ -0,0 +1,8 @@
BGM+220+100001'
DTM+137:20260325:102'
NAD+BY+5000000000000:16++Customer Name'
LIN+1++Product123:SA'
QTY+21:10:PCE'
UNS+S'
CNT+2:1'
UNT+9+12345'

View File

@@ -0,0 +1,8 @@
UNH+12345+ORDERS:D:03B:UN:EAN008'
BGM+220+100001'
DTM+137:20260325:102'
NAD+BY+5000000000000:16++Customer Name'
LIN+1++Product123:SA'
QTY+21:10:PCE'
UNS+S'
CNT+2:1'

View File

@@ -0,0 +1,9 @@
UNH+12345+ORDERS:D:03B:UN:EAN008'
BGM+220+100001'
DTM+137:20260325:102'
NAD+BY+5000000000000:16++Customer Name'
LIN+1++Product123:SA'
QTY+21:10:PCE'
UNS+S'
CNT+2:1'
UNT+9+12345'

View File

@@ -0,0 +1,9 @@
UNH+12345+ORDERS:D:03B:UN:EAN008'
BGM+220+100001'
DTM+137:20260325:102'
NAD+BY+5000000000000:16++Customer Name'
LIN+1++Product123:SA'
QTY+21:10:PCE'
UNS+S'
CNT+2:1'
UNT+6+54321'