Skip to content

Commit

Permalink
Fix top-level MARC record leader not being reset between records. (#524
Browse files Browse the repository at this point in the history
…, #538)
  • Loading branch information
blackwinter committed Jun 25, 2024
1 parent 83a02b9 commit 32beffb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ private void prettyPrintNewLine() {
private void sendAndClearData() {
getReceiver().process(builder.toString());
builder.delete(0, builder.length());
leaderBuilder.delete(0, leaderBuilder.length());
recordAttributeOffset = 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@ public void emitExceptionWhenEntityLengthNot5() {
encoder.startEntity("123456");
}

private void createRecordWithLeader(final String id, final String... leader) {
encoder.startRecord(id);
encoder.startEntity(Marc21EventNames.LEADER_ENTITY);
encoder.literal(Marc21EventNames.RECORD_STATUS_LITERAL, leader[0]);
encoder.literal(Marc21EventNames.RECORD_TYPE_LITERAL, leader[1]);
encoder.literal(Marc21EventNames.BIBLIOGRAPHIC_LEVEL_LITERAL, leader[2]);
encoder.literal(Marc21EventNames.TYPE_OF_CONTROL_LITERAL, leader[3]);
encoder.literal(Marc21EventNames.CHARACTER_CODING_LITERAL, leader[4]);
encoder.literal(Marc21EventNames.ENCODING_LEVEL_LITERAL, leader[5]);
encoder.literal(Marc21EventNames.CATALOGING_FORM_LITERAL, leader[6]);
encoder.literal(Marc21EventNames.MULTIPART_LEVEL_LITERAL, leader[7]);
encoder.endEntity();
encoder.endRecord();
}

@Test
public void createRecordWithLeader() {
encoder.startRecord("1");
Expand Down Expand Up @@ -242,33 +257,20 @@ private void issue336_createRecordWithTopLevelLeader(final MarcXmlEncoder encode

@Test
public void issue527_shouldEmitLeaderAlwaysAsWholeString() {
issue527_shouldEmitLeaderAlwaysAsWholeString(encoder);
createRecordWithLeader("1", "a", "o", "a", " ", "a", "z", "u", " ");
createRecordWithLeader("2", "d", "u", "m", " ", "m", "y", "#", " ");
encoder.closeStream();
String expected = XML_DECLARATION + XML_ROOT_OPEN
+ "<marc:record><marc:leader>aoa azu </marc:leader></marc:record>"
+ "<marc:record><marc:leader>dum my# </marc:leader></marc:record>" + XML_MARC_COLLECTION_END_TAG;
String actual = resultCollector.toString();
assertEquals(expected, actual);
}

@Test(expected = MissingIdException.class)
public void issue527_shouldEmitLeaderAlwaysAsWholeString_ensureCorrectMarc21Xml() {
encoder.setEnsureCorrectMarc21Xml(true);
issue527_shouldEmitLeaderAlwaysAsWholeString(encoder);
}

private void issue527_shouldEmitLeaderAlwaysAsWholeString(final MarcXmlEncoder encoder) {
encoder.startRecord("1");
encoder.startEntity(Marc21EventNames.LEADER_ENTITY);
encoder.literal(Marc21EventNames.RECORD_STATUS_LITERAL, "a");
encoder.literal(Marc21EventNames.RECORD_TYPE_LITERAL, "o");
encoder.literal(Marc21EventNames.BIBLIOGRAPHIC_LEVEL_LITERAL, "a");
encoder.literal(Marc21EventNames.TYPE_OF_CONTROL_LITERAL, " ");
encoder.literal(Marc21EventNames.CHARACTER_CODING_LITERAL, "a");
encoder.literal(Marc21EventNames.ENCODING_LEVEL_LITERAL, "z");
encoder.literal(Marc21EventNames.CATALOGING_FORM_LITERAL, "u");
encoder.literal(Marc21EventNames.MULTIPART_LEVEL_LITERAL, " ");
encoder.endEntity();
encoder.endRecord();
encoder.closeStream();
String expected = XML_DECLARATION + XML_ROOT_OPEN
+ "<marc:record><marc:leader>aoa azu </marc:leader></marc:record>" + XML_MARC_COLLECTION_END_TAG;
String actual = resultCollector.toString();
assertEquals(expected, actual);
issue527_shouldEmitLeaderAlwaysAsWholeString();
}

@Test
Expand Down

1 comment on commit 32beffb

@blackwinter
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Messed up the issue reference, should have been #527.

Please sign in to comment.