Skip to content

Commit 507b7bd

Browse files
committed
PDFBOX-5993: add test for embedded files
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1925230 13f79535-47bb-0310-9956-ffa450edef68
1 parent afc39b3 commit 507b7bd

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2025 The Apache Software Foundation.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.pdfbox.examples.pdmodel;
17+
18+
import java.io.File;
19+
import java.io.IOException;
20+
import java.nio.charset.StandardCharsets;
21+
import java.nio.file.Files;
22+
import java.nio.file.Paths;
23+
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import org.junit.jupiter.api.Test;
25+
26+
/**
27+
*
28+
* @author Tilman Hausherr
29+
*/
30+
class ExtractEmbeddedFilesTest
31+
{
32+
/**
33+
* Test that the correct attachments are extracted from a portable collection.
34+
*
35+
* @throws IOException
36+
*/
37+
@Test
38+
void testExtractEmbeddedFiles() throws IOException
39+
{
40+
String dir = "target/test-output";
41+
String collectionFilename = dir + "/PortableCollection.pdf";
42+
String attachment1Filename = dir + "/Test1.txt";
43+
String attachment2Filename = dir + "/Test2.txt";
44+
String[] args = new String[] { collectionFilename };
45+
CreatePortableCollection.main(args);
46+
ExtractEmbeddedFiles.main(args);
47+
byte[] ba1 = Files.readAllBytes(new File(attachment1Filename).toPath());
48+
byte[] ba2 = Files.readAllBytes(new File(attachment2Filename).toPath());
49+
String s1 = new String(ba1, StandardCharsets.US_ASCII);
50+
String s2 = new String(ba2, StandardCharsets.US_ASCII);
51+
assertEquals(s1, "This is the contents of the first embedded file");
52+
assertEquals(s2, "This is the contents of the second embedded file");
53+
Files.delete(Paths.get(collectionFilename));
54+
Files.delete(Paths.get(attachment1Filename));
55+
Files.delete(Paths.get(attachment2Filename));
56+
}
57+
}

0 commit comments

Comments
 (0)