Skip to content

Commit bc074ac

Browse files
committed
PDFBOX-6026: test serializer result
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1926755 13f79535-47bb-0310-9956-ffa450edef68
1 parent d809e49 commit bc074ac

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

xmpbox/src/test/java/org/apache/xmpbox/parser/DeserializationTest.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
import java.io.ByteArrayOutputStream;
2929
import java.io.IOException;
3030
import java.io.InputStream;
31+
import java.nio.ByteBuffer;
32+
import java.security.MessageDigest;
33+
import java.security.NoSuchAlgorithmException;
3134
import java.util.List;
35+
import javax.xml.transform.TransformerException;
3236

3337
import org.apache.xmpbox.DateConverter;
3438
import org.apache.xmpbox.XMPMetadata;
@@ -98,12 +102,11 @@ void testGetTitle() throws XmpParsingException, BadFieldValueException
98102
}
99103

100104
@Test
101-
void testAltBagSeq() throws XmpParsingException
105+
void testAltBagSeq() throws XmpParsingException, TransformerException, NoSuchAlgorithmException
102106
{
103107
InputStream fis = DomXmpParser.class.getResourceAsStream("/org/apache/xmpbox/parser/AltBagSeqTest.xml");
104-
xdb.parse(fis);
105-
// XMPMetadata metadata=xdb.parse(fis);
106-
// SaveMetadataHelper.serialize(metadata, true, System.out);
108+
XMPMetadata metadata=xdb.parse(fis);
109+
checkTransform(metadata, "AA3B148E4F802DE4");
107110
}
108111

109112
@Test
@@ -322,4 +325,14 @@ void testSpaceTextValues() throws XmpParsingException
322325
// check creator tool
323326
assertEquals("Canon ",meta.getXMPBasicSchema().getCreatorTool());
324327
}
328+
329+
private void checkTransform(XMPMetadata metadata, String expected)
330+
throws TransformerException, NoSuchAlgorithmException
331+
{
332+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
333+
serializer.serialize(metadata, baos, true);
334+
byte[] digest = MessageDigest.getInstance("SHA-256").digest(baos.toByteArray());
335+
String result = String.format("%X", ByteBuffer.wrap(digest).getLong());
336+
assertEquals(expected, result);
337+
}
325338
}

0 commit comments

Comments
 (0)