Tests for WebClient. @author Mike Bowler @author Christian Sell @author Ben Curren @author Marc Guillemot @author David D. Kilzer @author Chris Erskine @author Hans Donner @author Paul King @author Ahmed Ashour @author Daniel Gredler @author Sudhan Moghe @author Ronald Brill @author Carsten
| 76 | * @author Joerg Werner |
| 77 | */ |
| 78 | public class WebClientTest extends SimpleWebTestCase { |
| 79 | |
| 80 | /** |
| 81 | * Test the situation where credentials are required but they haven't been specified. |
| 82 | * |
| 83 | * @throws Exception if something goes wrong |
| 84 | */ |
| 85 | @Test |
| 86 | public void credentialProvider_NoCredentials() throws Exception { |
| 87 | final String htmlContent = DOCTYPE_HTML |
| 88 | + "<html><head><title>foo</title></head><body>\n" |
| 89 | + "No access</body></html>"; |
| 90 | final WebClient client = getWebClient(); |
| 91 | client.getOptions().setPrintContentOnFailingStatusCode(false); |
| 92 | |
| 93 | final MockWebConnection webConnection = new MockWebConnection(); |
| 94 | webConnection.setDefaultResponse(htmlContent, 401, "Credentials missing or just plain wrong", |
| 95 | MimeType.TEXT_PLAIN); |
| 96 | client.setWebConnection(webConnection); |
| 97 | |
| 98 | try { |
| 99 | client.getPage(new WebRequest(URL_FIRST, HttpMethod.POST)); |
| 100 | fail("Expected FailingHttpStatusCodeException"); |
| 101 | } |
| 102 | catch (final FailingHttpStatusCodeException e) { |
| 103 | assertEquals(401, e.getStatusCode()); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Test that the {@link WebWindowEvent#CHANGE} window event gets fired at the |
| 109 | * appropriate time. |
| 110 | * @throws Exception if something goes wrong |
| 111 | */ |
| 112 | @Test |
| 113 | public void htmlWindowEvents_changed() throws Exception { |
| 114 | final String htmlContent = DOCTYPE_HTML |
| 115 | + "<html><head><title>foo</title></head><body>\n" |
| 116 | + "<a href='http://www.foo2.com' id='a2'>link to foo2</a>\n" |
| 117 | + "</body></html>"; |
| 118 | final WebClient client = getWebClient(); |
| 119 | |
| 120 | final List<WebWindowEvent> events = new LinkedList<>(); |
| 121 | client.addWebWindowListener(new WebWindowListener() { |
| 122 | @Override |
| 123 | public void webWindowOpened(final WebWindowEvent event) { |
| 124 | events.add(event); |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public void webWindowContentChanged(final WebWindowEvent event) { |
| 129 | events.add(event); |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public void webWindowClosed(final WebWindowEvent event) { |
| 134 | events.add(event); |
| 135 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…