1   package com.diasparsoftware.htmlunitx.test;
2   
3   import java.io.*;
4   import java.net.URL;
5   
6   import com.diasparsoftware.gsbase.StreamUtil;
7   import com.diasparsoftware.htmlunitx.*;
8   
9   public class FileSystemWebResponseTest extends
10      AbstractWebResponseTestCase {
11  
12      private FileInputStream expectedContentAsStream;
13      private InputStreamWebResponse actualWebResponse;
14      private String expectedContentAsString;
15      private byte[] expectedResponseBody;
16  
17      protected void setUp() throws Exception {
18          expectedContentAsStream = new FileInputStream(
19              "test/data/webResponse.html");
20  
21          actualWebResponse = new FileSystemWebResponse(new URL(
22              "http://foo"), new File(
23              "test/data/webResponse.html"));
24  
25          // Need to read from a different stream, otherwise
26          // we have a race condition on who gets to read the
27          // stream first. I'm not sure how to solve this problem.
28  
29          expectedContentAsString = StreamUtil
30              .getContentAsString(new FileInputStream(
31                  "test/data/webResponse.html"));
32  
33          expectedResponseBody = expectedContentAsString
34              .getBytes(actualWebResponse.getContentCharSet());
35  
36          super.setUp();
37      }
38  
39      protected TestableWebResponse makeActualWebResponse()
40          throws Exception {
41  
42          return actualWebResponse;
43      }
44  
45      protected byte[] getExpectedResponseBody() throws Exception {
46          return expectedResponseBody;
47      }
48  
49      protected InputStream getExpectedContentAsStream()
50          throws Exception {
51  
52          return expectedContentAsStream;
53      }
54  
55      protected String getExpectedContentAsString()
56          throws Exception {
57          return expectedContentAsString;
58      }
59  }