1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.sitegraph;
22
23 import java.io.File;
24 import java.io.InputStream;
25 import java.io.StringWriter;
26 import java.net.URL;
27
28 import org.apache.struts2.StrutsTestCase;
29 import org.apache.struts2.dispatcher.Dispatcher;
30
31 import com.opensymphony.xwork2.util.ClassLoaderUtil;
32
33 /***
34 */
35 public class SiteGraphTest extends StrutsTestCase {
36 public void testWebFlow() throws Exception {
37
38
39
40 URL url = ClassLoaderUtil.getResource("org/apache/struts2/sitegraph/struts.xml", SiteGraphTest.class);
41 File file = new File(url.toString().substring(5));
42 String dir = file.getParent();
43
44 SiteGraph siteGraph = new SiteGraph(dir, dir, dir, "");
45 StringWriter writer = new StringWriter();
46 siteGraph.setWriter(writer);
47 siteGraph.prepare();
48
49 URL compare = SiteGraphTest.class.getResource("out.txt");
50 StringBuffer buffer = new StringBuffer(128);
51 InputStream in = compare.openStream();
52 byte[] buf = new byte[4096];
53 int nbytes;
54
55 while ((nbytes = in.read(buf)) > 0) {
56 buffer.append(new String(buf, 0, nbytes));
57 }
58
59 in.close();
60 assertEquals(buffer.toString().replaceAll("\r\n", "\n"), writer.toString().replaceAll("\r\n", "\n"));
61 }
62 }