Erste fachliche Strukturregel ergänzen: UNH-/UNT-Referenznummer prüfen
This commit is contained in:
@@ -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())));
|
||||
}
|
||||
}
|
||||
8
src/test/resources/no-unh.asv
Normal file
8
src/test/resources/no-unh.asv
Normal 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'
|
||||
8
src/test/resources/no-unt.asv
Normal file
8
src/test/resources/no-unt.asv
Normal 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'
|
||||
9
src/test/resources/unh-unt-match.asv
Normal file
9
src/test/resources/unh-unt-match.asv
Normal 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'
|
||||
9
src/test/resources/unh-unt-mismatch.asv
Normal file
9
src/test/resources/unh-unt-mismatch.asv
Normal 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'
|
||||
Reference in New Issue
Block a user