File: BlackBoxTest.java

package info (click to toggle)
pdftk-java 3.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,876 kB
  • sloc: java: 47,187; xml: 73; sh: 47; makefile: 10
file content (94 lines) | stat: -rw-r--r-- 3,342 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import static org.junit.Assert.assertEquals;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.SystemOutRule;
import org.junit.contrib.java.lang.system.ExpectedSystemExit;
import org.junit.contrib.java.lang.system.TextFromStandardInputStream;

import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.IOException;

import com.gitlab.pdftk_java.pdftk;

public class BlackBoxTest {
  @Rule
  public final SystemOutRule systemOutRule =
    new SystemOutRule().muteForSuccessfulTests();

  @Rule
  public final ExpectedSystemExit exit = ExpectedSystemExit.none();

  @Rule
  public final TextFromStandardInputStream systemInMock
    = TextFromStandardInputStream.emptyStandardInputStream();

  public String slurp(String filename) throws IOException {
    return new String(slurpBytes(filename));
  }
  public byte[] slurpBytes(String filename) throws IOException {
    return Files.readAllBytes(Paths.get(filename));
  }
  
  @Test
  public void dump_data() throws IOException {
    exit.expectSystemExitWithStatus(0);
    pdftk.main(new String[]{"test/files/blank.pdf", "dump_data_utf8"});
    String expectedData = slurp("test/files/blank.data");
    assertEquals(expectedData, systemOutRule.getLog());    
  }

  @Test
  public void cat() throws IOException {
    exit.expectSystemExitWithStatus(0);
    pdftk.main(new String[]{"test/files/refs.pdf",
                            "test/files/refsalt.pdf",
                            "cat", "output", "-"});
    byte[] expectedData = slurpBytes("test/files/cat-refs-refsalt.pdf");
    assertEquals(expectedData, systemOutRule.getLogAsBytes());
  }

  @Test
  public void cat_rotate_page_no_op() throws IOException {
    exit.expectSystemExitWithStatus(0);
    pdftk.main(new String[]{"test/files/blank.pdf",
                            "cat", "1north", "output", "-"});
    byte[] expectedData = slurpBytes("test/files/blank.pdf");
    assertEquals(expectedData, systemOutRule.getLogAsBytes());
  }

  @Test
  public void cat_rotate_range_no_op() throws IOException {
    exit.expectSystemExitWithStatus(0);
    pdftk.main(new String[]{"test/files/blank.pdf",
                            "cat", "1-1north", "output", "-"});
    byte[] expectedData = slurpBytes("test/files/blank.pdf");
    assertEquals(expectedData, systemOutRule.getLogAsBytes());
  }

  @Test
  public void cat_rotate_page() throws IOException {
    exit.expectSystemExitWithStatus(0);
    pdftk.main(new String[]{"test/files/blank.pdf",
                            "cat", "1east", "output", "-"});
    byte[] expectedData = slurpBytes("test/files/blank.pdf");
    assertEquals(expectedData, systemOutRule.getLogAsBytes());
  }

  @Test
  public void cat_rotate_range() throws IOException {
    exit.expectSystemExitWithStatus(0);
    pdftk.main(new String[]{"test/files/blank.pdf",
                            "cat", "1-1east", "output", "-"});
    byte[] expectedData = slurpBytes("test/files/blank.pdf");
    assertEquals(expectedData, systemOutRule.getLogAsBytes());
  }

  @Test
  public void update_info_incomplete_record() {
    exit.expectSystemExitWithStatus(0);
    systemInMock.provideLines("InfoBegin", "InfoKey: Title", " ","InfoBegin", "InfoKey: Author", " ");
    pdftk.main(new String[]{"test/files/blank.pdf", "update_info", "-", "output", "-"});
  }

};