65074ca7b577f9de79ca384225f863a75acbe239
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
;
20 * Base class for {@link BasicSupport}s testing.
22 * It will use the paths:
24 * <li><tt>test/XXX/source</tt>: the html source files</li>
25 * <li><tt>test/XXX/expected</tt>: the expected output</li>
26 * <li><tt>test/XXX/actual</tt>: the actual output of the last test</li>
31 abstract class TestBase
extends TestCase
{
32 private BasicSupport support
;
34 public TestBase(BasicSupport support
, String
[] args
) {
35 super(support
.getType().toString());
36 this.support
= support
;
39 static protected InputStream
doOpen(BasicSupport support
,
40 Map
<URL
, File
> map
, URL url
) throws IOException
{
41 File file
= map
.get(url
);
43 throw new FileNotFoundException("Test file not found for URL: "
47 return new FileInputStream("test/source/" + support
.getType() + "/"
53 public void test() throws Exception
{
54 File expected
= new File("test/expected/" + support
.getType());
55 File actual
= new File("test/result/" + support
.getType());
57 IOUtils
.deltree(actual
);
61 Output gopher
= new Gopher(support
.getType(), "", "", 70);
62 Output html
= new Html(support
.getType(), "", "", 80);
64 for (Story story
: support
.list()) {
66 IOUtils
.writeSmallFile(new File(actual
, story
.getId() + ".header"),
67 gopher
.exportHeader(story
));
68 IOUtils
.writeSmallFile(new File(actual
, story
.getId() + ""),
69 gopher
.export(story
));
70 IOUtils
.writeSmallFile(new File(actual
, story
.getId()
71 + ".header.html"), html
.exportHeader(story
));
72 IOUtils
.writeSmallFile(new File(actual
, story
.getId() + ".html"),
76 assertEquals(expected
, actual
);