Skip to content

Commit

Permalink
Make sure map export tests are run
Browse files Browse the repository at this point in the history
  • Loading branch information
tsauerwein committed Feb 7, 2017
1 parent e155e5b commit f7a5537
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 11 deletions.
35 changes: 26 additions & 9 deletions examples/src/test/java/org/mapfish/print/ExamplesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.util.StatusPrinter;

import com.google.common.base.Strings;
import com.google.common.collect.Maps;
import com.google.common.io.Files;

import org.apache.commons.lang.ArrayUtils;
import org.json.JSONObject;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -31,6 +34,7 @@
import java.nio.charset.Charset;
import java.util.Map;
import java.util.regex.Pattern;

import javax.imageio.ImageIO;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -70,7 +74,8 @@ public class ExamplesTest {
* will run all examples starting with verbose.
*/
private static final String FILTER_PROPERTY = "examples.filter";
private static final Pattern MATCH_ALL = Pattern.compile(".*");
private static final Pattern REQUEST_MATCH_ALL = Pattern.compile(".*");
private static final Pattern EXAMPLE_MATCH_ALL = Pattern.compile(".*");
@Autowired
MapPrinter mapPrinter;

Expand Down Expand Up @@ -99,15 +104,16 @@ public static void setUp() throws Exception {
String[] parts = filterProperty.split("/", 2);

if (parts.length == 1) {
requestFilter = MATCH_ALL;
requestFilter = REQUEST_MATCH_ALL;
} else {
requestFilter = Pattern.compile(parts[1]);
}

exampleFilter = Pattern.compile(parts[0]);

} else {
requestFilter = exampleFilter = MATCH_ALL;
requestFilter = REQUEST_MATCH_ALL;
exampleFilter = EXAMPLE_MATCH_ALL;
}
}

Expand Down Expand Up @@ -186,7 +192,11 @@ private int runExample(File example, Map<String, Throwable> errors) {
}

testsRan++;
jsonSpec.getInternalObj().put("outputFormat", "png");
String outputFormat = jsonSpec.getInternalObj().getString("outputFormat");
if (!ArrayUtils.contains(new String[]{"png", "jpg", "tiff"}, outputFormat)) {
jsonSpec.getInternalObj().put("outputFormat", "png");
outputFormat = "png";
}
ByteArrayOutputStream out = new ByteArrayOutputStream();

JSONObject headers = new JSONObject();
Expand All @@ -207,12 +217,19 @@ private int runExample(File example, Map<String, Throwable> errors) {

BufferedImage image = ImageIO.read(new ByteArrayInputStream(out.toByteArray()));

// File outDir = new File("/tmp/examples_test", example.getName()+"/expected_output");
// File outDir = new File("/tmp/examples_test", example.getName()+ "/expected_output");
// outDir.mkdirs();
// ImageIO.write(image, "png", new File(outDir, requestFile.getName().replace(".json", ".png")));
// ImageIO.write(image, outputFormat, new File(outDir, requestFile.getName().replace(".json", "." + outputFormat)));

File expectedOutputDir = new File(example, "expected_output");
File expectedOutput = getExpecteOutput(requestFile, expectedOutputDir);
File expectedOutput = getExpectedOutput(outputFormat, requestFile, expectedOutputDir);
if (!expectedOutput.exists()) {
errors.put(
example.getName() + " (" + requestFile.getName() + ")",
new Exception("File not found: " + expectedOutput.toString()));
continue;
}

int similarity = 50;
File file = new File(expectedOutputDir, "image-similarity.txt");
if (file.isFile()) {
Expand All @@ -232,7 +249,7 @@ private int runExample(File example, Map<String, Throwable> errors) {
return testsRan;
}

private File getExpecteOutput(File requestFile, File expectedOutputDir) {
private File getExpectedOutput(String outputFormat, File requestFile, File expectedOutputDir) {
File platformSpecificDir;
if (System.getProperty("os.name").toLowerCase().contains("win")) {
platformSpecificDir = new File(expectedOutputDir, "win");
Expand All @@ -242,7 +259,7 @@ private File getExpecteOutput(File requestFile, File expectedOutputDir) {
platformSpecificDir = new File(expectedOutputDir, "linux");
}

final String imageName = requestFile.getName().replace(".json", ".png");
final String imageName = requestFile.getName().replace(".json", "." + outputFormat);
if (new File(platformSpecificDir, imageName).exists()) {
return new File(platformSpecificDir, imageName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@
"scale": 100000
}
},
"layout": "A4 landscape"
"layout": "A4 landscape",
"outputFormat": "pdf"
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
"rotation": 0,
"scale": 25000
}},
"layout": "A4 landscape"
"layout": "A4 landscape",
"outputFormat": "pdf"
}

0 comments on commit f7a5537

Please sign in to comment.