add MarcWriter test
This commit is contained in:
parent
7a3ccf94a4
commit
ddae3f750c
2 changed files with 23 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
||||||
group = org.xbib
|
group = org.xbib
|
||||||
name = marc
|
name = marc
|
||||||
version = 2.9.9
|
version = 2.9.10
|
||||||
|
|
||||||
org.gradle.warning.mode = ALL
|
org.gradle.warning.mode = ALL
|
||||||
|
|
|
@ -15,15 +15,37 @@
|
||||||
*/
|
*/
|
||||||
package org.xbib.marc;
|
package org.xbib.marc;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.xbib.marc.transformer.value.MarcValueTransformers;
|
import org.xbib.marc.transformer.value.MarcValueTransformers;
|
||||||
import org.xbib.marc.xml.MarcXchangeWriter;
|
import org.xbib.marc.xml.MarcXchangeWriter;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.StringWriter;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public class MarcWriterTest {
|
public class MarcWriterTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMarcWriter() throws Exception {
|
||||||
|
Map<String, Object> map = new TreeMap<>(Map.of("001", "123",
|
||||||
|
"100", Map.of("_", Map.of("a", "Hello World"))));
|
||||||
|
MarcRecord marcRecord = MarcRecord.from(map);
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
try (MarcWriter writer = new MarcWriter(outputStream, StandardCharsets.UTF_8)) {
|
||||||
|
writer.startDocument();
|
||||||
|
writer.record(marcRecord);
|
||||||
|
writer.endDocument();
|
||||||
|
assertNull(writer.getException());
|
||||||
|
}
|
||||||
|
assertEquals("\u001D00000 0000000 000 \u001E100 \u001FaHello World\u001E001123\u001D\u001C",
|
||||||
|
outputStream.toString(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUtf8MarcWriter() throws Exception {
|
public void testUtf8MarcWriter() throws Exception {
|
||||||
for (String s : new String[]{
|
for (String s : new String[]{
|
||||||
|
|
Loading…
Reference in a new issue