Skip to content
Snippets Groups Projects
Commit 92533741 authored by Jan Zickermann's avatar Jan Zickermann
Browse files

OZG-6754 KOP-2674 abgabe0401: Add test with unknown and remote schemas

parent 2b7ca8c3
No related branches found
No related tags found
No related merge requests found
......@@ -23,9 +23,11 @@ public record Patch(
var patchedContent = new StringBuilder();
try {
for (var hunk : hunks) {
for (var patchedLine : hunk.apply(lines, lineOffset)) {
patchedContent.append(patchedLine).append("\n");
var patchResult = hunk.apply(lines, lineOffset);
for (var patchLine : patchResult.lines()) {
patchedContent.append(patchLine).append("\n");
}
lineOffset = patchResult.lineOffset();
}
lines.forEachRemaining(patchedContent::append);
} catch (TechnicalException exception) {
......
......@@ -11,14 +11,21 @@ public record PatchHunk(
List<HunkLine> hunkLines
) {
public List<String> apply(Iterator<String> lines, int lineOffset) {
public record PatchResult(
List<String> lines,
int lineOffset
) {
}
public PatchResult apply(Iterator<String> lines, int lineOffset) {
var patchedLines = new ArrayList<String>();
skipToContextStart(lines, lineOffset, patchedLines);
lineOffset = skipToContextStart(lines, lineOffset, patchedLines);
for (var hunkLine : hunkLines) {
switch (hunkLine.operation) {
case CONTEXT -> {
var contextLine = lines.next();
lineOffset++;
if (!hunkLine.line.equals(contextLine)) {
throw new TechnicalException(
"Unexpected context line! expected='" + hunkLine.line + "' actual='" + contextLine + "', lineOffset=" + lineOffset);
......@@ -28,6 +35,7 @@ public record PatchHunk(
case ADD -> patchedLines.add(hunkLine.line);
case REMOVE -> {
var removeLine = lines.next();
lineOffset++;
if (!hunkLine.line.equals(removeLine)) {
throw new TechnicalException(
"Unexpected remove line! expected='" + hunkLine.line + "' actual='" + removeLine + "', lineOffset=" + lineOffset);
......@@ -35,16 +43,17 @@ public record PatchHunk(
}
}
}
return patchedLines;
return new PatchResult(patchedLines, lineOffset);
}
private void skipToContextStart(Iterator<String> lines, int lineOffset, List<String> patchedLines) {
private int skipToContextStart(Iterator<String> lines, int lineOffset, List<String> patchedLines) {
for (; lineOffset < contextStartLineNumber - 1; lineOffset++) {
if (!lines.hasNext()) {
throw new TechnicalException("Unexpected end of target file! lineOffset=" + lineOffset);
}
patchedLines.add(lines.next());
}
return lineOffset;
}
public record HunkLine(
......
......@@ -117,6 +117,18 @@ class XdomeaXtaMessageCreatorITCase {
.isInstanceOf(ClientException.class);
}
@DisplayName("should not throw with valid message 0401")
@Test
void shouldNotThrowWithValidMessage0401() {
var validMessageZipFile = loadMessageFileWithPatch(
"abgabe0401-kleiner-waffenschein",
"valid-unknown-namespaces.patch"
);
assertThatCode(() -> creator.createMessage(validMessageZipFile))
.doesNotThrowAnyException();
}
}
private XtaMessageExampleLoader.MessageExampleConfig.MessageExampleConfigBuilder createExampleConfigBuilder() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment