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

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

parent 65722e08
Branches
Tags
No related merge requests found
...@@ -23,9 +23,11 @@ public record Patch( ...@@ -23,9 +23,11 @@ public record Patch(
var patchedContent = new StringBuilder(); var patchedContent = new StringBuilder();
try { try {
for (var hunk : hunks) { for (var hunk : hunks) {
for (var patchedLine : hunk.apply(lines, lineOffset)) { var patchResult = hunk.apply(lines, lineOffset);
patchedContent.append(patchedLine).append("\n"); for (var patchLine : patchResult.lines()) {
patchedContent.append(patchLine).append("\n");
} }
lineOffset = patchResult.lineOffset();
} }
lines.forEachRemaining(patchedContent::append); lines.forEachRemaining(patchedContent::append);
} catch (TechnicalException exception) { } catch (TechnicalException exception) {
......
...@@ -11,14 +11,21 @@ public record PatchHunk( ...@@ -11,14 +11,21 @@ public record PatchHunk(
List<HunkLine> hunkLines 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>(); var patchedLines = new ArrayList<String>();
skipToContextStart(lines, lineOffset, patchedLines); lineOffset = skipToContextStart(lines, lineOffset, patchedLines);
for (var hunkLine : hunkLines) { for (var hunkLine : hunkLines) {
switch (hunkLine.operation) { switch (hunkLine.operation) {
case CONTEXT -> { case CONTEXT -> {
var contextLine = lines.next(); var contextLine = lines.next();
lineOffset++;
if (!hunkLine.line.equals(contextLine)) { if (!hunkLine.line.equals(contextLine)) {
throw new TechnicalException( throw new TechnicalException(
"Unexpected context line! expected='" + hunkLine.line + "' actual='" + contextLine + "', lineOffset=" + lineOffset); "Unexpected context line! expected='" + hunkLine.line + "' actual='" + contextLine + "', lineOffset=" + lineOffset);
...@@ -28,6 +35,7 @@ public record PatchHunk( ...@@ -28,6 +35,7 @@ public record PatchHunk(
case ADD -> patchedLines.add(hunkLine.line); case ADD -> patchedLines.add(hunkLine.line);
case REMOVE -> { case REMOVE -> {
var removeLine = lines.next(); var removeLine = lines.next();
lineOffset++;
if (!hunkLine.line.equals(removeLine)) { if (!hunkLine.line.equals(removeLine)) {
throw new TechnicalException( throw new TechnicalException(
"Unexpected remove line! expected='" + hunkLine.line + "' actual='" + removeLine + "', lineOffset=" + lineOffset); "Unexpected remove line! expected='" + hunkLine.line + "' actual='" + removeLine + "', lineOffset=" + lineOffset);
...@@ -35,16 +43,17 @@ public record PatchHunk( ...@@ -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++) { for (; lineOffset < contextStartLineNumber - 1; lineOffset++) {
if (!lines.hasNext()) { if (!lines.hasNext()) {
throw new TechnicalException("Unexpected end of target file! lineOffset=" + lineOffset); throw new TechnicalException("Unexpected end of target file! lineOffset=" + lineOffset);
} }
patchedLines.add(lines.next()); patchedLines.add(lines.next());
} }
return lineOffset;
} }
public record HunkLine( public record HunkLine(
......
...@@ -117,6 +117,18 @@ class XdomeaXtaMessageCreatorITCase { ...@@ -117,6 +117,18 @@ class XdomeaXtaMessageCreatorITCase {
.isInstanceOf(ClientException.class); .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() { 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