View Javadoc

1   /*
2    * $Id: SiteGraphTest.java 651946 2008-04-27 13:41:38Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.struts2.sitegraph;
23  
24  import java.io.File;
25  import java.io.InputStream;
26  import java.io.StringWriter;
27  import java.net.URL;
28  
29  import org.apache.struts2.StrutsTestCase;
30  import org.apache.struts2.dispatcher.Dispatcher;
31  
32  import com.opensymphony.xwork2.util.ClassLoaderUtil;
33  
34  /***
35   */
36  public class SiteGraphTest extends StrutsTestCase {
37      public void testWebFlow() throws Exception {
38          // use the classloader rather than relying on the
39          // working directory being an assumed value when
40          // running the test:  so let's get this class's parent dir
41          URL url = ClassLoaderUtil.getResource("org/apache/struts2/sitegraph/struts.xml", SiteGraphTest.class);
42          File file = new File(url.toString().substring(5));
43          String dir = file.getParent();
44  
45          SiteGraph siteGraph = new SiteGraph(dir, dir, dir, "");
46          StringWriter writer = new StringWriter();
47          siteGraph.setWriter(writer);
48          siteGraph.prepare();
49  
50          URL compare = SiteGraphTest.class.getResource("out.txt");
51          StringBuffer buffer = new StringBuffer(128);
52          InputStream in = compare.openStream();
53          byte[] buf = new byte[4096];
54          int nbytes;
55  
56          while ((nbytes = in.read(buf)) > 0) {
57              buffer.append(new String(buf, 0, nbytes));
58          }
59  
60          in.close();
61          assertEquals(buffer.toString().replaceAll("\r\n", "\n"), writer.toString().replaceAll("\r\n", "\n"));
62      }
63  }