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