|
51 | 51 |
|
52 | 52 | import static org.junit.jupiter.api.Assertions.assertEquals; |
53 | 53 | import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 54 | +import static org.junit.jupiter.api.Assertions.assertNull; |
54 | 55 | import static org.junit.jupiter.api.Assertions.assertThrows; |
55 | 56 | import org.junit.jupiter.api.Test; |
56 | 57 |
|
@@ -818,6 +819,80 @@ void testBadAttr3() throws XmpParsingException, TransformerException |
818 | 819 | assertEquals("[creator=TextType:Creator]", dublinCoreSchema.getProperty(DublinCoreSchema.CREATOR).toString()); |
819 | 820 | } |
820 | 821 |
|
| 822 | + /** |
| 823 | + * Test empty attribute where an array is expected. The attribute is skipped in lenient mode. |
| 824 | + * |
| 825 | + * @throws XmpParsingException |
| 826 | + * @throws TransformerException |
| 827 | + * @throws BadFieldValueException |
| 828 | + */ |
| 829 | + @Test |
| 830 | + void testBadAttr4() throws XmpParsingException, TransformerException, BadFieldValueException |
| 831 | + { |
| 832 | + String s = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + |
| 833 | +"<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d' bytes='1206'?><rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" >\n" + |
| 834 | +" <rdf:Description xmlns=\"http://purl.org/dc/elements/1.1/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" about=\"\" dc:creator=\"\">\n" + |
| 835 | +" <dc:coverage>Coverage</dc:coverage>\n" + |
| 836 | +" </rdf:Description>\n" + |
| 837 | +"</rdf:RDF><?xpacket end='r'?>"; |
| 838 | + final DomXmpParser xmpParser1 = new DomXmpParser(); |
| 839 | + XmpParsingException ex = assertThrows(XmpParsingException.class, |
| 840 | + () -> xmpParser1.parse(s.getBytes(StandardCharsets.UTF_8))); |
| 841 | + assertEquals("The type 'Text' in 'dc:creator=' is a structured or array type, but attributes are simple types", ex.getMessage()); |
| 842 | + DomXmpParser xmpParser2 = new DomXmpParser(); |
| 843 | + xmpParser2.setStrictParsing(false); |
| 844 | + XMPMetadata xmp2 = xmpParser2.parse(s.getBytes(StandardCharsets.UTF_8)); |
| 845 | + DublinCoreSchema dublinCoreSchema2 = xmp2.getDublinCoreSchema(); |
| 846 | + assertEquals("Coverage", dublinCoreSchema2.getCoverage()); |
| 847 | + assertNull(dublinCoreSchema2.getProperty(DublinCoreSchema.CREATOR)); |
| 848 | + XmpSerializer serializer = new XmpSerializer(); |
| 849 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 850 | + serializer.serialize(xmp2, baos, true); |
| 851 | + DomXmpParser xmpParser3 = new DomXmpParser(); |
| 852 | + xmpParser3.setStrictParsing(false); |
| 853 | + XMPMetadata xmp3 = xmpParser3.parse(baos.toByteArray()); |
| 854 | + DublinCoreSchema dublinCoreSchema3 = xmp3.getDublinCoreSchema(); |
| 855 | + assertEquals("Coverage", dublinCoreSchema3.getCoverage()); |
| 856 | + assertNull(dublinCoreSchema2.getProperty(DublinCoreSchema.CREATOR)); |
| 857 | + } |
| 858 | + |
| 859 | + /** |
| 860 | + * Test empty attribute where an LangAlt is expected. The attribute is skipped in lenient mode. |
| 861 | + * |
| 862 | + * @throws XmpParsingException |
| 863 | + * @throws TransformerException |
| 864 | + * @throws BadFieldValueException |
| 865 | + */ |
| 866 | + @Test |
| 867 | + void testBadAttr5() throws XmpParsingException, TransformerException, BadFieldValueException |
| 868 | + { |
| 869 | + String s = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + |
| 870 | +"<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d' bytes='987'?><rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:iX=\"http://ns.adobe.com/iX/1.0/\">\n" + |
| 871 | +" <rdf:Description xmlns=\"http://purl.org/dc/elements/1.1/\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" about=\"\" dc:title=\"\" dc:coverage=\"COVER\"/>\n" + |
| 872 | +"</rdf:RDF><?xpacket end='r'?>"; |
| 873 | + final DomXmpParser xmpParser1 = new DomXmpParser(); |
| 874 | + XmpParsingException ex = assertThrows(XmpParsingException.class, |
| 875 | + () -> xmpParser1.parse(s.getBytes(StandardCharsets.UTF_8))); |
| 876 | + assertEquals("The type 'LangAlt' in 'dc:title=' is a structured or array type, but attributes are simple types", ex.getMessage()); |
| 877 | + DomXmpParser xmpParser2 = new DomXmpParser(); |
| 878 | + xmpParser2.setStrictParsing(false); |
| 879 | + XMPMetadata xmp2 = xmpParser2.parse(s.getBytes(StandardCharsets.UTF_8)); |
| 880 | + DublinCoreSchema dublinCoreSchema2 = xmp2.getDublinCoreSchema(); |
| 881 | + assertNull(dublinCoreSchema2.getTitle()); |
| 882 | + assertNull(dublinCoreSchema2.getProperty(DublinCoreSchema.TITLE)); |
| 883 | + assertEquals("COVER", dublinCoreSchema2.getCoverage()); |
| 884 | + XmpSerializer serializer = new XmpSerializer(); |
| 885 | + ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
| 886 | + serializer.serialize(xmp2, baos, true); |
| 887 | + DomXmpParser xmpParser3 = new DomXmpParser(); |
| 888 | + xmpParser3.setStrictParsing(false); |
| 889 | + XMPMetadata xmp3 = xmpParser3.parse(baos.toByteArray()); |
| 890 | + DublinCoreSchema dublinCoreSchema3 = xmp3.getDublinCoreSchema(); |
| 891 | + assertNull(dublinCoreSchema3.getTitle()); |
| 892 | + assertNull(dublinCoreSchema3.getProperty(DublinCoreSchema.TITLE)); |
| 893 | + assertEquals("COVER", dublinCoreSchema3.getCoverage()); |
| 894 | + } |
| 895 | + |
821 | 896 | @Test |
822 | 897 | void testBadSchema() throws XmpParsingException |
823 | 898 | { |
|
0 commit comments