View Javadoc

1   /*
2    * $Id: SiteGraphTest.java 474191 2006-11-13 08:30:40Z mrdon $
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  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          // use the classloader rather than relying on the
38          // working directory being an assumed value when
39          // running the test:  so let's get this class's parent dir
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  }