1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.formats.webp;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertNotNull;
21 import static org.junit.jupiter.api.Assertions.assertTrue;
22
23 import java.io.File;
24
25 import org.apache.commons.imaging.ImageInfo;
26 import org.apache.commons.imaging.bytesource.ByteSource;
27 import org.apache.commons.imaging.formats.tiff.TiffImageMetadata;
28 import org.apache.commons.imaging.formats.tiff.taginfos.TagInfo;
29 import org.apache.commons.imaging.formats.tiff.taginfos.TagInfoAscii;
30 import org.junit.jupiter.api.Test;
31
32
33
34
35 public class WebPMetadataTest extends WebPBaseTest {
36
37
38
39
40 @Test
41 public void testReadAlpha() throws Exception {
42 final File imageFile = new File(WebPMetadataTest.class.getResource("/images/webp/alpha/alpha.webp").getFile());
43 final WebPImageParser parser = new WebPImageParser();
44 final ImageInfo imageInfo = parser.getImageInfo(ByteSource.file(imageFile), parser.getDefaultParameters());
45 assertNotNull(imageInfo);
46 }
47
48
49
50
51 @Test
52 public void testReadMetadata() throws Exception {
53 final File imageFile = new File(WebPMetadataTest.class.getResource("/images/webp/exif/_DSC6099.webp").getFile());
54 final WebPImageParser parser = new WebPImageParser();
55 final WebPImageMetadata metadata = parser.getMetadata(ByteSource.file(imageFile), parser.getDefaultParameters());
56 assertEquals(56, metadata.getItems().size());
57
58 final TiffImageMetadata tiffImageMetadata = metadata.getExif();
59 assertNotNull(tiffImageMetadata);
60
61
62 final TagInfo make = new TagInfoAscii("", 271, 0, null);
63 final Object field = tiffImageMetadata.getFieldValue(make);
64 assertEquals("sony", field.toString().trim().toLowerCase());
65 }
66
67
68
69
70 @Test
71 public void testReadXmp() throws Exception {
72 final File imageFile = new File(WebPMetadataTest.class.getResource("/images/webp/xmp/test.webp").getFile());
73 final WebPImageParser parser = new WebPImageParser();
74
75 final String xml = parser.getXmpXml(ByteSource.file(imageFile), parser.getDefaultParameters());
76 assertTrue(xml.contains("Apache License"));
77 }
78 }