1da6b48a6a2f7451bb13425bb4a9d4125665f1bc
1 package be
.nikiroo
.gofetch
.test
;
4 import java
.io
.FileInputStream
;
5 import java
.io
.FileNotFoundException
;
6 import java
.io
.IOException
;
7 import java
.io
.InputStream
;
11 import be
.nikiroo
.gofetch
.data
.Story
;
12 import be
.nikiroo
.gofetch
.output
.Gopher
;
13 import be
.nikiroo
.gofetch
.output
.Html
;
14 import be
.nikiroo
.gofetch
.output
.Output
;
15 import be
.nikiroo
.gofetch
.support
.BasicSupport
;
16 import be
.nikiroo
.utils
.IOUtils
;
17 import be
.nikiroo
.utils
.test
.TestCase
;
18 import be
.nikiroo
.utils
.test
.TestLauncher
;
21 * Base class for {@link BasicSupport}s testing.
23 * It will use the paths:
25 * <li><tt>test/XXX/source</tt>: the html source files</li>
26 * <li><tt>test/XXX/expected</tt>: the expected output</li>
27 * <li><tt>test/XXX/actual</tt>: the actual output of the last test</li>
32 abstract class TestBase
extends TestLauncher
{
33 public TestBase(BasicSupport support
, String
[] args
) {
34 super(support
.getType().toString(), args
);
38 static protected InputStream
doOpen(BasicSupport support
,
39 Map
<URL
, File
> map
, URL url
) throws IOException
{
40 File file
= map
.get(url
);
42 throw new FileNotFoundException("Test file not found for URL: "
46 return new FileInputStream("test/source/" + support
.getType() + "/"
51 private void addTest(final BasicSupport support
) {
52 addTest(new TestCase("Processing example data") {
54 public void test() throws Exception
{
55 File expected
= new File("test/expected/" + support
.getType());
56 File actual
= new File("test/result/" + support
.getType());
58 IOUtils
.deltree(actual
);
62 Output gopher
= new Gopher(support
.getType(), "", "", 70);
63 Output html
= new Html(support
.getType(), "", "", 80);
65 for (Story story
: support
.list()) {
67 IOUtils
.writeSmallFile(new File(actual
, story
.getId()
68 + ".header"), gopher
.exportHeader(story
));
69 IOUtils
.writeSmallFile(
70 new File(actual
, story
.getId() + ""),
71 gopher
.export(story
));
72 IOUtils
.writeSmallFile(new File(actual
, story
.getId()
73 + ".header.html"), html
.exportHeader(story
));
74 IOUtils
.writeSmallFile(new File(actual
, story
.getId()
75 + ".html"), html
.export(story
));
78 assertEquals(expected
, actual
);