1   package com.diasparsoftware.htmlunitx.test;
2   
3   import java.io.InputStream;
4   import java.net.URL;
5   import java.util.Collections;
6   
7   import junit.framework.TestCase;
8   
9   import com.diasparsoftware.htmlunitx.*;
10  import com.gargoylesoftware.htmlunit.*;
11  
12  public class TestableWebConnectionTest extends TestCase {
13      public void testEmptyResponse() throws Exception {
14          String contentAsString = "";
15          InputStream contentAsStream = TextUtil
16              .toInputStream(contentAsString);
17  
18          TestableWebConnection connection = new TestableWebConnection(
19              new WebClient());
20  
21          URL url = new URL("http://foo");
22          InputStreamWebResponse inputStreamWebResponse = new InputStreamWebResponse(
23              url, contentAsStream);
24          inputStreamWebResponse.setContentType("text/plain");
25  
26          connection.setResponse(inputStreamWebResponse);
27  
28          WebResponse response = connection.getResponse(url,
29              SubmitMethod.GET, Collections.EMPTY_LIST,
30              Collections.EMPTY_MAP);
31  
32          InputStreamWebResponse expectedResponse = new InputStreamWebResponse(
33              url, contentAsStream);
34          assertEquals(expectedResponse, response);
35      }
36  
37      public void testNonEmptyPlainResponse() throws Exception {
38          String contentAsString = "Come here, Watson; I want you.";
39          InputStream contentAsStream = TextUtil
40              .toInputStream(contentAsString);
41  
42          TestableWebConnection connection = new TestableWebConnection(
43              new WebClient());
44  
45          URL url = new URL("http://foo");
46          InputStreamWebResponse inputStreamWebResponse = new InputStreamWebResponse(
47              url, contentAsStream);
48          inputStreamWebResponse.setContentType("text/plain");
49  
50          connection.setResponse(inputStreamWebResponse);
51  
52          WebResponse response = connection.getResponse(url,
53              SubmitMethod.GET, Collections.EMPTY_LIST,
54              Collections.EMPTY_MAP);
55  
56          InputStreamWebResponse expectedResponse = new InputStreamWebResponse(
57              url, contentAsStream);
58          assertEquals(expectedResponse, response);
59      }
60  }