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
.Cache
;
17 import be
.nikiroo
.utils
.Downloader
;
18 import be
.nikiroo
.utils
.IOUtils
;
19 import be
.nikiroo
.utils
.test
.TestCase
;
22 * Base class for {@link BasicSupport}s testing.
24 * It will use the paths:
26 * <li><tt>test/???/source</tt>: the html source files</li>
27 * <li><tt>test/???/expected</tt>: the expected output</li>
28 * <li><tt>test/???/actual</tt>: the actual output of the last test</li>
33 abstract class TestBase
extends TestCase
{
34 private BasicSupport support
;
36 private Downloader downloader
;
38 public TestBase(BasicSupport support
, String
[] args
) {
39 super(support
.getType().toString());
40 this.support
= support
;
42 cache
= new Cache(new File("test/source/" + support
.getType()), -1,
44 downloader
= new Downloader("gofetch", cache
);
45 } catch (IOException e
) {
46 throw new RuntimeException(e
);
50 protected InputStream
download(URL url
) throws IOException
{
51 return downloader
.open(url
);
54 static protected InputStream
doOpen(BasicSupport support
,
55 Map
<URL
, File
> map
, URL url
) throws IOException
{
56 File file
= map
.get(url
);
58 throw new FileNotFoundException("Test file not found for URL: "
62 return new FileInputStream("test/source/" + support
.getType() + "/"
68 public void test() throws Exception
{
69 File expected
= new File("test/expected/" + support
.getType());
70 File actual
= new File("test/result/" + support
.getType());
72 IOUtils
.deltree(actual
);
76 Output gopher
= new Gopher(support
.getType(), "", "", 70);
77 Output html
= new Html(support
.getType(), "", "", 80);
79 for (Story story
: support
.list()) {
81 IOUtils
.writeSmallFile(new File(actual
, story
.getId() + ".header"),
82 gopher
.exportHeader(story
));
83 IOUtils
.writeSmallFile(new File(actual
, story
.getId() + ""),
84 gopher
.export(story
));
85 IOUtils
.writeSmallFile(new File(actual
, story
.getId()
86 + ".header.html"), html
.exportHeader(story
));
87 IOUtils
.writeSmallFile(new File(actual
, story
.getId() + ".html"),
91 assertEquals(expected
, actual
);