@@ -56,12 +56,12 @@ This file is part of the iText (R) project.
56
56
57
57
@ Category (IntegrationTest .class )
58
58
public class GhostscriptHelperTest extends ExtendedITextTest {
59
- private final static String sourceFolder = "./src/test/resources/com/itextpdf/io/util/GhostscriptHelperTest/" ;
60
- private static final String destinationFolder = "./target/test/com/itextpdf/io/GhostscriptHelperTest/" ;
59
+ private final static String SOURCE_FOLDER = "./src/test/resources/com/itextpdf/io/util/GhostscriptHelperTest/" ;
60
+ private static final String DESTINATION_FOLDER = "./target/test/com/itextpdf/io/GhostscriptHelperTest/" ;
61
61
62
62
@ Before
63
63
public void setUp () {
64
- createOrClearDestinationFolder (destinationFolder );
64
+ createOrClearDestinationFolder (DESTINATION_FOLDER );
65
65
}
66
66
67
67
@ Test
@@ -99,7 +99,7 @@ public void ghostScriptEnvVarIsIncorrect() {
99
99
100
100
@ Test
101
101
public void runGhostScriptIncorrectOutputDirectory () throws IOException , InterruptedException {
102
- String inputPdf = sourceFolder + "imageHandlerUtilTest.pdf" ;
102
+ String inputPdf = SOURCE_FOLDER + "imageHandlerUtilTest.pdf" ;
103
103
String exceptionMessage = "Cannot open output directory for " + inputPdf ;
104
104
105
105
GhostscriptHelper ghostscriptHelper = new GhostscriptHelper ();
@@ -113,67 +113,67 @@ public void runGhostScriptIncorrectOutputDirectory() throws IOException, Interru
113
113
114
114
@ Test
115
115
public void runGhostScriptIncorrectParams () throws IOException , InterruptedException {
116
- String inputPdf = sourceFolder + "imageHandlerUtilTest.pdf" ;
116
+ String inputPdf = SOURCE_FOLDER + "imageHandlerUtilTest.pdf" ;
117
117
String exceptionMessage = "GhostScript failed for " + inputPdf ;
118
118
119
119
GhostscriptHelper ghostscriptHelper = new GhostscriptHelper ();
120
120
121
121
Exception e = Assert .assertThrows (GhostscriptHelper .GhostscriptExecutionException .class ,
122
- () -> ghostscriptHelper .runGhostScriptImageGeneration (inputPdf , destinationFolder ,
122
+ () -> ghostscriptHelper .runGhostScriptImageGeneration (inputPdf , DESTINATION_FOLDER ,
123
123
"outputPageImage.png" , "q@W" )
124
124
);
125
125
Assert .assertEquals (exceptionMessage , e .getMessage ());
126
126
}
127
127
128
128
@ Test
129
129
public void runGhostScriptTestForSpecificPage () throws IOException , InterruptedException {
130
- String inputPdf = sourceFolder + "imageHandlerUtilTest.pdf" ;
130
+ String inputPdf = SOURCE_FOLDER + "imageHandlerUtilTest.pdf" ;
131
131
132
132
GhostscriptHelper ghostscriptHelper = new GhostscriptHelper ();
133
- ghostscriptHelper .runGhostScriptImageGeneration (inputPdf , destinationFolder ,
133
+ ghostscriptHelper .runGhostScriptImageGeneration (inputPdf , DESTINATION_FOLDER ,
134
134
"specificPage.png" , "1" );
135
135
136
- Assert .assertEquals (1 , FileUtil .listFilesInDirectory (destinationFolder , true ).length );
137
- Assert .assertTrue (FileUtil .fileExists (destinationFolder + "specificPage.png" ));
136
+ Assert .assertEquals (1 , FileUtil .listFilesInDirectory (DESTINATION_FOLDER , true ).length );
137
+ Assert .assertTrue (FileUtil .fileExists (DESTINATION_FOLDER + "specificPage.png" ));
138
138
}
139
139
140
140
@ Test
141
141
public void runGhostScriptTestForSeveralSpecificPages () throws IOException , InterruptedException {
142
- String inputPdf = sourceFolder + "imageHandlerUtilTest.pdf" ;
142
+ String inputPdf = SOURCE_FOLDER + "imageHandlerUtilTest.pdf" ;
143
143
144
144
GhostscriptHelper ghostscriptHelper = new GhostscriptHelper ();
145
145
String imageFileName = new File (inputPdf ).getName () + "_severalSpecificPages-%03d.png" ;
146
- ghostscriptHelper .runGhostScriptImageGeneration (inputPdf , destinationFolder ,
146
+ ghostscriptHelper .runGhostScriptImageGeneration (inputPdf , DESTINATION_FOLDER ,
147
147
imageFileName , "1,3" );
148
148
149
- Assert .assertEquals (2 , FileUtil .listFilesInDirectory (destinationFolder , true ).length );
150
- Assert .assertTrue (FileUtil .fileExists (destinationFolder + "imageHandlerUtilTest.pdf_severalSpecificPages-001.png" ));
151
- Assert .assertTrue (FileUtil .fileExists (destinationFolder + "imageHandlerUtilTest.pdf_severalSpecificPages-002.png" ));
149
+ Assert .assertEquals (2 , FileUtil .listFilesInDirectory (DESTINATION_FOLDER , true ).length );
150
+ Assert .assertTrue (FileUtil .fileExists (DESTINATION_FOLDER + "imageHandlerUtilTest.pdf_severalSpecificPages-001.png" ));
151
+ Assert .assertTrue (FileUtil .fileExists (DESTINATION_FOLDER + "imageHandlerUtilTest.pdf_severalSpecificPages-002.png" ));
152
152
}
153
153
154
154
@ Test
155
155
public void runGhostScriptTestForAllPages () throws IOException , InterruptedException {
156
- String inputPdf = sourceFolder + "imageHandlerUtilTest.pdf" ;
156
+ String inputPdf = SOURCE_FOLDER + "imageHandlerUtilTest.pdf" ;
157
157
158
158
GhostscriptHelper ghostscriptHelper = new GhostscriptHelper ();
159
159
String imageFileName = new File (inputPdf ).getName () + "_allPages-%03d.png" ;
160
- ghostscriptHelper .runGhostScriptImageGeneration (inputPdf , destinationFolder , imageFileName );
160
+ ghostscriptHelper .runGhostScriptImageGeneration (inputPdf , DESTINATION_FOLDER , imageFileName );
161
161
162
- Assert .assertEquals (3 , FileUtil .listFilesInDirectory (destinationFolder , true ).length );
163
- Assert .assertTrue (FileUtil .fileExists (destinationFolder + "imageHandlerUtilTest.pdf_allPages-001.png" ));
164
- Assert .assertTrue (FileUtil .fileExists (destinationFolder + "imageHandlerUtilTest.pdf_allPages-002.png" ));
165
- Assert .assertTrue (FileUtil .fileExists (destinationFolder + "imageHandlerUtilTest.pdf_allPages-003.png" ));
162
+ Assert .assertEquals (3 , FileUtil .listFilesInDirectory (DESTINATION_FOLDER , true ).length );
163
+ Assert .assertTrue (FileUtil .fileExists (DESTINATION_FOLDER + "imageHandlerUtilTest.pdf_allPages-001.png" ));
164
+ Assert .assertTrue (FileUtil .fileExists (DESTINATION_FOLDER + "imageHandlerUtilTest.pdf_allPages-002.png" ));
165
+ Assert .assertTrue (FileUtil .fileExists (DESTINATION_FOLDER + "imageHandlerUtilTest.pdf_allPages-003.png" ));
166
166
}
167
167
168
168
@ Test
169
169
public void dSaferParamInGhostScriptHelperTest () throws IOException , InterruptedException {
170
- String input = sourceFolder + "unsafePostScript.ps" ;
170
+ String input = SOURCE_FOLDER + "unsafePostScript.ps" ;
171
171
String outputName = "unsafePostScript.png" ;
172
- String maliciousResult1 = destinationFolder + "output1.txt" ;
173
- String maliciousResult2 = destinationFolder + "output2.txt" ;
172
+ String maliciousResult1 = DESTINATION_FOLDER + "output1.txt" ;
173
+ String maliciousResult2 = DESTINATION_FOLDER + "output2.txt" ;
174
174
try {
175
175
GhostscriptHelper ghostscriptHelper = new GhostscriptHelper ();
176
- ghostscriptHelper .runGhostScriptImageGeneration (input , destinationFolder , outputName );
176
+ ghostscriptHelper .runGhostScriptImageGeneration (input , DESTINATION_FOLDER , outputName );
177
177
} catch (GhostscriptHelper .GhostscriptExecutionException e ) {
178
178
System .out .println ("Error code was returned on processing of malicious script with -dSAFER option enabled. "
179
179
+ "This is expected for some environments and ghostscript versions. "
@@ -186,13 +186,13 @@ public void dSaferParamInGhostScriptHelperTest() throws IOException, Interrupted
186
186
@ Test
187
187
public void ghostScriptImageGenerationTest () throws IOException , InterruptedException {
188
188
String filename = "resultantImage.png" ;
189
- String psFile = sourceFolder + "simple.ps" ;
190
- String resultantImage = destinationFolder + filename ;
191
- String cmpResultantImage = sourceFolder + "cmp_" + filename ;
192
- String diff = destinationFolder + "diff_" + filename ;
189
+ String psFile = SOURCE_FOLDER + "simple.ps" ;
190
+ String resultantImage = DESTINATION_FOLDER + filename ;
191
+ String cmpResultantImage = SOURCE_FOLDER + "cmp_" + filename ;
192
+ String diff = DESTINATION_FOLDER + "diff_" + filename ;
193
193
194
194
GhostscriptHelper ghostscriptHelper = new GhostscriptHelper ();
195
- ghostscriptHelper .runGhostScriptImageGeneration (psFile , destinationFolder , filename );
195
+ ghostscriptHelper .runGhostScriptImageGeneration (psFile , DESTINATION_FOLDER , filename );
196
196
Assert .assertTrue (FileUtil .fileExists (resultantImage ));
197
197
198
198
ImageMagickHelper imageMagickHelper = new ImageMagickHelper ();
0 commit comments