[Httpunit-commit] CVS: httpunit/test/com/meterware/httpunit PseudoServer.java,1.2,1.3 PseudoServerTe
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2000-11-21 20:45:02
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/httpunit In directory slayer.i.sourceforge.net:/tmp/cvs-serv6274/test/com/meterware/httpunit Modified Files: PseudoServer.java PseudoServerTest.java WebFormTest.java WebPageTest.java Log Message: Initial servletunit release Index: PseudoServer.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- PseudoServer.java 2000/11/10 18:48:37 1.2 +++ PseudoServer.java 2000/11/21 20:44:59 1.3 @@ -142,10 +142,10 @@ } sendLine( ps, "" ); sendText( ps, resource.getContents() ); - ps.close(); } } + ps.close(); socket.close(); } Index: PseudoServerTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/PseudoServerTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- PseudoServerTest.java 2000/11/10 18:48:37 1.3 +++ PseudoServerTest.java 2000/11/21 20:44:59 1.4 @@ -51,12 +51,14 @@ int port = ps.getConnectedPort(); WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + "/nothing" ); + WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + "/nothing.htm" ); try { WebResponse response = wc.getResponse( request ); fail( "Should have rejected the request" ); } catch (HttpNotFoundException e) { assertEquals( "Response code", HttpURLConnection.HTTP_NOT_FOUND, e.getResponseCode() ); + } finally { + ps.shutDown(); } } @@ -69,11 +71,15 @@ ps.setResource( resourceName, resourceValue ); int port = ps.getConnectedPort(); - WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + resourceName ); - WebResponse response = wc.getResponse( request ); - assertEquals( "requested resource", resourceValue, response.toString() ); - assertEquals( "content type", "text/html", response.getContentType() ); + try { + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + resourceName ); + WebResponse response = wc.getResponse( request ); + assertEquals( "requested resource", resourceValue, response.toString() ); + assertEquals( "content type", "text/html", response.getContentType() ); + } finally { + ps.shutDown(); + } } @@ -89,12 +95,43 @@ ps.setResource( resourceName, resourceValue ); ps.setResource( redirectName, "" ); ps.addResourceHeader( redirectName, "Location: http://localhost:" + port + '/' + resourceName ); + + try { + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + redirectName ); + WebResponse response = wc.getResponse( request ); + assertEquals( "requested resource", resourceValue, response.toString() ); + assertEquals( "content type", "text/html", response.getContentType() ); + } finally { + ps.shutDown(); + } + } + + - WebConversation wc = new WebConversation(); - WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + redirectName ); - WebResponse response = wc.getResponse( request ); - assertEquals( "requested resource", resourceValue, response.toString() ); - assertEquals( "content type", "text/html", response.getContentType() ); + public void testCookies() throws Exception { + String resourceName = "something/interesting"; + String resourceValue = "the desired content\r\n"; + + PseudoServer ps = new PseudoServer(); + int port = ps.getConnectedPort(); + ps.setResource( resourceName, resourceValue ); + ps.addResourceHeader( resourceName, "Set-Cookie: age=12, name=george" ); + ps.addResourceHeader( resourceName, "Set-Cookie: type=short" ); + + try { + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( "http://localhost:" + port + '/' + resourceName ); + WebResponse response = wc.getResponse( request ); + assertEquals( "requested resource", resourceValue, response.toString() ); + assertEquals( "content type", "text/html", response.getContentType() ); + assertEquals( "number of cookies", 3, wc.getCookieNames().length ); + assertEquals( "cookie 'age' value", "12", wc.getCookieValue( "age" ) ); + assertEquals( "cookie 'name' value", "george", wc.getCookieValue( "name" ) ); + assertEquals( "cookie 'type' value", "short", wc.getCookieValue( "type" ) ); + } finally { + ps.shutDown(); + } } } Index: WebFormTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebFormTest.java,v retrieving revision 1.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- WebFormTest.java 2000/10/31 19:54:15 1.8 +++ WebFormTest.java 2000/11/21 20:44:59 1.9 @@ -61,6 +61,20 @@ } + public void testFindFormByName() throws Exception { + defineWebPage( "Default", "<form name=oneForm method=POST action = \"/servlet/Login\">" + + "<Input name=\"secret\" type=\"hidden\" value=\"surprise\">" + + "<br><Input name=typeless value=nothing>" + + "<B>Enter the name 'master': <Input type=TEXT Name=name></B>" + + "<br><Input type=submit value = \"Log in\">" + + "</form>" ); + + WebResponse page = _wc.getResponse( getHostPath() + "/Default.html" ); + assertNull( "Found nonexistent form", page.getFormWithName( "nobody" ) ); + assertNotNull( "Did not find named form", page.getFormWithName( "oneform" ) ); + } + + public void testFormParameters() throws Exception { WebForm form = _wc.getResponse( getHostPath() + "/OneForm.html" ).getForms()[0]; String[] parameters = form.getParameterNames(); Index: WebPageTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/httpunit/WebPageTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- WebPageTest.java 2000/11/10 18:48:37 1.3 +++ WebPageTest.java 2000/11/21 20:44:59 1.4 @@ -114,5 +114,20 @@ } + public void testNoLocalFile() throws Exception { + File file = new File( "temp.html" ); + file.delete(); + + try { + WebConversation wc = new WebConversation(); + WebRequest request = new GetMethodWebRequest( "file:" + file.getAbsolutePath() ); + WebResponse simplePage = wc.getResponse( request ); + fail( "Should have complained about missing file" ); + } catch (java.io.FileNotFoundException e) { + } + + } + + } |