From: <wu...@us...> - 2008-04-07 08:32:30
|
Revision: 109 http://davinspector.svn.sourceforge.net/davinspector/?rev=109&view=rev Author: wuest Date: 2008-04-07 01:32:26 -0700 (Mon, 07 Apr 2008) Log Message: ----------- Added files for unit test. Modified Paths: -------------- trunk/DAVInspector/test/de/dlr/davinspector/http/HTTPTest.java Added Paths: ----------- trunk/DAVInspector/test/de/dlr/davinspector/http/request.txt trunk/DAVInspector/test/de/dlr/davinspector/http/response-multistatus.txt trunk/DAVInspector/test/de/dlr/davinspector/http/response.txt Modified: trunk/DAVInspector/test/de/dlr/davinspector/http/HTTPTest.java =================================================================== --- trunk/DAVInspector/test/de/dlr/davinspector/http/HTTPTest.java 2008-04-06 15:17:09 UTC (rev 108) +++ trunk/DAVInspector/test/de/dlr/davinspector/http/HTTPTest.java 2008-04-07 08:32:26 UTC (rev 109) @@ -1,9 +1,9 @@ /* * HTTPTest.java * - * TODO: wues_ha Enter comment! + * Unit tests for HTTMessageParser. * - * Created: 10.03.2008 wues_ha <email> + * Created: 10.03.2008 Jochen Wuest <joc...@dl...> * Changed: * * $Id$ @@ -26,6 +26,10 @@ package de.dlr.davinspector.http; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; import java.util.Calendar; import java.util.Date; @@ -42,33 +46,34 @@ /** - * TODO: wues_ha: Enter comment! + * Unit tests for HTTMessageParser. + * TODO: Add tests for parser. * * @version $LastChangedRevision$ * @author Jochen Wuest */ public class HTTPTest { - /** Comment for not yet implemented tests. */ - private static final String NOT_YET = "Not yet implemented"; + /** Filename of a http response. */ + private static final String RESPONSE_FILE = "response.txt"; /** */ private static int idCounter = 0; /** */ - private AMessage message; + private AMessage myMessage; /** */ - private Date timestamp; + private Date myTimestamp; /** */ - private Direction direction; + private Direction myDirection; /** */ - private String data; + private String myData = ""; /** - * TODO: wues_ha: Enter comment! + * Once called on class loading. * * @throws Exception Exception */ @@ -78,7 +83,7 @@ } /** - * TODO: wues_ha: Enter comment! + * Once called on class shutdown. * * @throws Exception Exception */ @@ -87,25 +92,28 @@ } /** - * TODO: wues_ha: Enter comment! + * Called before every test. Set's up the environment. * * @throws Exception Exception */ @Before public void setUp() throws Exception { idCounter++; - timestamp = new Date(); - direction = Direction.ClientToServer; - // TODO: Read test data from file. - data = "This is a test"; - message = new Message(); - message.setMessageDirection(direction); - message.setRawData(data); - message.setTimestamp(timestamp); + myTimestamp = new Date(); + myDirection = Direction.ClientToServer; + try { + myData = loadTestDataFromFile("request.txt"); + } catch (IOException ioe) { + System.err.println(ioe.getMessage()); + } + myMessage = new Message(); + myMessage.setDirection(myDirection); + myMessage.setRawData(myData); + myMessage.setTimestamp(myTimestamp); } /** - * TODO: wues_ha: Enter comment! + * Called after every test. Tear's down the environment. * * @throws Exception Exception */ @@ -114,89 +122,85 @@ } /** - * TODO: wues_ha: Enter comment! - * + * Test of the ID-Counter. */ @Test public void testGetId() { - Assert.assertEquals(idCounter, message.getId()); + Assert.assertEquals(idCounter, myMessage.getId()); } /** - * TODO: wues_ha: Enter comment! - * + * Test of the timestamp field. */ @Test public void testGetTimestamp() { - Assert.assertEquals(timestamp, message.getTimestamp()); + Assert.assertEquals(myTimestamp, myMessage.getTimestamp()); } /** - * TODO: wues_ha: Enter comment! - * + * Test of the timestamp field. */ @Test public void testSetTimestamp() { Calendar cal = Calendar.getInstance(); cal.set(1, 1, 1, 1, 1, 1); // ### - timestamp = cal.getTime(); - message.setTimestamp(timestamp); - Assert.assertEquals(timestamp, message.getTimestamp()); + myTimestamp = cal.getTime(); + myMessage.setTimestamp(myTimestamp); + Assert.assertEquals(myTimestamp, myMessage.getTimestamp()); } /** - * TODO: wues_ha: Enter comment! - * + * Test of the message direction field. */ @Test public void testGetMessageDirection() { - Assert.assertEquals(Direction.ClientToServer, message.getMessageDirection()); + Assert.assertEquals(Direction.ClientToServer, myMessage.getDirection()); } /** - * TODO: wues_ha: Enter comment! - * + * Test of the message direction field. */ @Test public void testSetMessageDirection() { - Direction msgDir = message.getMessageDirection(); + Direction msgDir = myMessage.getDirection(); if (msgDir == Direction.ClientToServer) { msgDir = Direction.ServerToClient; } else { msgDir = Direction.ClientToServer; } - message.setMessageDirection(msgDir); - Assert.assertEquals(msgDir, message.getMessageDirection()); + myMessage.setDirection(msgDir); + Assert.assertEquals(msgDir, myMessage.getDirection()); } /** - * TODO: wues_ha: Enter comment! - * + * Test of the size field. */ @Test public void testGetSize() { - Assert.assertEquals(data.length(), message.getSize()); + Assert.assertEquals(myData.length(), myMessage.getSize()); } /** - * TODO: wues_ha: Enter comment! - * + * Test of the raw data field. */ @Test public void testGetRawData() { - Assert.assertEquals(data, message.getRawData()); + Assert.assertEquals(myData, myMessage.getRawData()); } /** - * TODO: wues_ha: Enter comment! - * + * Test of the raw data field. */ @Test public void testSetRawData() { - // TODO: Read test data from file. - String testdata = "Mir lose de Dom in koelle."; - message.setRawData(testdata); - Assert.assertEquals(testdata, message.getRawData()); + String testdata = ""; + try { + testdata = loadTestDataFromFile(RESPONSE_FILE); + } catch (IOException ioe) { + System.err.println(ioe.getMessage()); + } + myMessage.setRawData(testdata); + Assert.assertEquals(testdata, myMessage.getRawData()); } /** @@ -204,17 +208,15 @@ * */ @Test - public void testGetMessageHeader() { - junit.framework.TestCase.fail(NOT_YET); - } - - /** - * TODO: wues_ha: Enter comment! - * - */ - @Test public void testGetRawHeader() { - junit.framework.TestCase.fail(NOT_YET); + String testdata = ""; + try { + testdata = loadTestDataFromFile(RESPONSE_FILE); + } catch (IOException ioe) { + System.err.println(ioe.getMessage()); + } + myMessage.setRawData(testdata); + Assert.assertEquals(testdata, myMessage.getRawData()); } /** @@ -222,17 +224,15 @@ * */ @Test - public void testGetMessageBody() { - junit.framework.TestCase.fail(NOT_YET); - } - - /** - * TODO: wues_ha: Enter comment! - * - */ - @Test public void testGetRawBody() { - junit.framework.TestCase.fail(NOT_YET); + String testdata = ""; + try { + testdata = loadTestDataFromFile(RESPONSE_FILE); + } catch (IOException ioe) { + System.err.println(ioe.getMessage()); + } + myMessage.setRawData(testdata); + Assert.assertEquals(testdata, myMessage.getRawData()); } /** @@ -241,16 +241,52 @@ */ @Test public void testParseMessage() { - junit.framework.TestCase.fail(NOT_YET); + try { + myData = loadTestDataFromFile(RESPONSE_FILE); + } catch (IOException ioe) { + System.err.println(ioe.getMessage()); + } + + HTTPMessageParser message = new HTTPMessageParser(new Message()); + + message.setDirection(myDirection); + message.setRawData(myData); + message.setTimestamp(myTimestamp); + String carry = message.parse(); + + if (carry.equals("")) { + junit.framework.TestCase.assertTrue(message.isComplete()); + } else { + junit.framework.TestCase.fail("Carry not empty."); + } } /** - * TODO: wues_ha: Enter comment! + * Utility method. Returns the content of a file in a string. * + * @param filename String + * @return String + * @throws IOException IOE */ - @Test - public void testIsComplete() { - junit.framework.TestCase.fail(NOT_YET); + private String loadTestDataFromFile(String filename) throws IOException { + String result = ""; + String buffer; + File inputFile; + FileReader filereader; + BufferedReader bufferedreader; + + File userdir = new File(System.getProperty("user.dir")); + inputFile = new File(userdir + "/test/de/dlr/davinspector/http/" + filename); + + filereader = new FileReader(inputFile); + bufferedreader = new BufferedReader(filereader); + buffer = bufferedreader.readLine(); + while (buffer != null) { + result += buffer; + buffer = bufferedreader.readLine(); + } + bufferedreader.close(); + + return result; } - } Added: trunk/DAVInspector/test/de/dlr/davinspector/http/request.txt =================================================================== --- trunk/DAVInspector/test/de/dlr/davinspector/http/request.txt (rev 0) +++ trunk/DAVInspector/test/de/dlr/davinspector/http/request.txt 2008-04-07 08:32:26 UTC (rev 109) @@ -0,0 +1,18 @@ +PROPFIND /slide/files/ HTTP/1.1 +Host: localhost:9999 +Connection: TE +TE: trailers, deflate, gzip, compress +User-Agent: UCI DAV Explorer/0.91 RPT-HTTPClient/0.3-3E +Depth: 0 +Translate: f +Cookie: JSESSIONID=E7480B4CDAC11E7DAF2A90E1CA145A1F +Cookie2: $Version="1" +Accept-Encoding: deflate, gzip, x-gzip, compress, x-compress +Content-type: text/xml +Content-length: 85 +Expect: 100-continue + +<?xml version="1.0"?> +<A:propfind xmlns:A="DAV:"> + <A:allprop/> +</A:propfind> Added: trunk/DAVInspector/test/de/dlr/davinspector/http/response-multistatus.txt =================================================================== --- trunk/DAVInspector/test/de/dlr/davinspector/http/response-multistatus.txt (rev 0) +++ trunk/DAVInspector/test/de/dlr/davinspector/http/response-multistatus.txt 2008-04-07 08:32:26 UTC (rev 109) @@ -0,0 +1,183 @@ +HTTP/1.1 207 Multi-Status +Server: Apache-Coyote/1.1 +Set-Cookie: JSESSIONID=347CA584900DC234AB760FE5DA3FF814; Path=/slide +Content-Type: text/xml;charset=UTF-8 +Transfer-Encoding: chunked +Date: Thu, 27 Mar 2008 15:17:53 GMT + +345 +<?xml version="1.0" encoding="UTF-8"?> +<D:multistatus xmlns:D="DAV:"> +<D:response xmlns:D="DAV:"> + <D:href>/slide/files</D:href> + <D:propstat> + <D:prop> + <D:displayname>files</D:displayname> + <D:resourcetype> + <D:collection /> + </D:resourcetype> + <D:getcontentlength>0</D:getcontentlength> + <D:getlastmodified>Mon, 01 Oct 2007 11:25:47 GMT</D:getlastmodified> + <D:lockdiscovery /> + </D:prop> + <D:status>HTTP/1.1 200 OK</D:status> + </D:propstat> + <D:propstat> + <D:prop> + <D:getcontenttype /> + <D:checked-in /> + <D:checked-out /> + <D:version-name /> + </D:prop> + <D:status>HTTP/1.1 404 Not Found</D:status> + </D:propstat> +</D:response> +35d +<D:response xmlns:D="DAV:"> + <D:href>/slide/files/ntop-overviewrgrg.pdf</D:href> + <D:propstat> + <D:prop> + <D:displayname>ntop-overviewrgrg.pdf</D:displayname> + <D:resourcetype /> + <D:getcontenttype>application/pdf</D:getcontenttype> + <D:getcontentlength>320661</D:getcontentlength> + <D:getlastmodified>Thu, 20 Mar 2008 14:17:45 GMT</D:getlastmodified> + <D:lockdiscovery /> + <D:checked-in> + <D:href>/slide/history/1/1.0</D:href> + </D:checked-in> + </D:prop> + <D:status>HTTP/1.1 200 OK</D:status> + </D:propstat> + <D:propstat> + <D:prop> + <D:checked-out /> + <D:version-name /> + </D:prop> + <D:status>HTTP/1.1 404 Not Found</D:status> + </D:propstat> +</D:response> +2ea +<D:response xmlns:D="DAV:"> + <D:href>/slide/files/gui.java</D:href> + <D:propstat> + <D:prop> + <D:displayname>gui.java</D:displayname> + <D:resourcetype /> + <D:getcontenttype>text/plain</D:getcontenttype> + <D:getcontentlength>7567</D:getcontentlength> + <D:getlastmodified>Tue, 27 Nov 2007 07:57:13 GMT</D:getlastmodified> + <D:lockdiscovery /> + </D:prop> + <D:status>HTTP/1.1 200 OK</D:status> + </D:propstat> + <D:propstat> + <D:prop> + <D:checked-in /> + <D:checked-out /> + <D:version-name /> + </D:prop> + <D:status>HTTP/1.1 404 Not Found</D:status> + </D:propstat> +</D:response> +2f5 +<D:response xmlns:D="DAV:"> + <D:href>/slide/files/netze_logo.gif</D:href> + <D:propstat> + <D:prop> + <D:displayname>netze_logo.gif</D:displayname> + <D:resourcetype /> + <D:getcontenttype>image/gif</D:getcontenttype> + <D:getcontentlength>3633</D:getcontentlength> + <D:getlastmodified>Tue, 02 Oct 2007 06:50:08 GMT</D:getlastmodified> + <D:lockdiscovery /> + </D:prop> + <D:status>HTTP/1.1 200 OK</D:status> + </D:propstat> + <D:propstat> + <D:prop> + <D:checked-in /> + <D:checked-out /> + <D:version-name /> + </D:prop> + <D:status>HTTP/1.1 404 Not Found</D:status> + </D:propstat> +</D:response> +303 +<D:response xmlns:D="DAV:"> + <D:href>/slide/files/test</D:href> + <D:propstat> + <D:prop> + <D:displayname>test</D:displayname> + <D:resourcetype> + <D:collection /> + </D:resourcetype> + <D:getcontentlength>0</D:getcontentlength> + <D:getlastmodified>Tue, 27 Nov 2007 07:46:49 GMT</D:getlastmodified> + <D:lockdiscovery /> + </D:prop> + <D:status>HTTP/1.1 200 OK</D:status> + </D:propstat> + <D:propstat> + <D:prop> + <D:getcontenttype /> + <D:checked-in /> + <D:checked-out /> + <D:version-name /> + </D:prop> + <D:status>HTTP/1.1 404 Not Found</D:status> + </D:propstat> +</D:response> +359 +<D:response xmlns:D="DAV:"> + <D:href>/slide/files/slide-doc.war</D:href> + <D:propstat> + <D:prop> + <D:displayname>slide-doc.war</D:displayname> + <D:resourcetype /> + <D:getcontenttype>application/octet-stream</D:getcontenttype> + <D:getcontentlength>2985562</D:getcontentlength> + <D:getlastmodified>Mon, 01 Oct 2007 11:35:06 GMT</D:getlastmodified> + <D:lockdiscovery /> + <D:checked-in> + <D:href>/slide/history/101/1.0</D:href> + </D:checked-in> + </D:prop> + <D:status>HTTP/1.1 200 OK</D:status> + </D:propstat> + <D:propstat> + <D:prop> + <D:checked-out /> + <D:version-name /> + </D:prop> + <D:status>HTTP/1.1 404 Not Found</D:status> + </D:propstat> +</D:response> +2fd +<D:response xmlns:D="DAV:"> + <D:href>/slide/files/slide.war</D:href> + <D:propstat> + <D:prop> + <D:displayname>slide.war</D:displayname> + <D:resourcetype /> + <D:getcontenttype>application/octet-stream</D:getcontenttype> + <D:getcontentlength>5270059</D:getcontentlength> + <D:getlastmodified>Mon, 01 Oct 2007 11:35:06 GMT</D:getlastmodified> + <D:lockdiscovery /> + </D:prop> + <D:status>HTTP/1.1 200 OK</D:status> + </D:propstat> + <D:propstat> + <D:prop> + <D:checked-in /> + <D:checked-out /> + <D:version-name /> + </D:prop> + <D:status>HTTP/1.1 404 Not Found</D:status> + </D:propstat> +</D:response> +12 + +</D:multistatus> + +0 Added: trunk/DAVInspector/test/de/dlr/davinspector/http/response.txt =================================================================== --- trunk/DAVInspector/test/de/dlr/davinspector/http/response.txt (rev 0) +++ trunk/DAVInspector/test/de/dlr/davinspector/http/response.txt 2008-04-07 08:32:26 UTC (rev 109) @@ -0,0 +1,58 @@ +HTTP/1.1 200 OK +Server: Apache-Coyote/1.1 +ETag: "2a75b88cf715807a122dc95b16e89528" +Content-Language: en +Last-Modified: Tue, 27 Nov 2007 07:47:54 GMT +Content-Type: text/plain +Content-Length: 2645 +Date: Thu, 27 Mar 2008 15:32:04 GMT + +Installation procedure + +The preferred Java version to run DAV Explorer is Java 2 (JDK 1.2 and above.) +DAV Explorer also runs with JDK 1.1.8 and Swing 1.1.1. However, this may +restrict the capabilities of DAV Explorer. + +Note: If not compiling from source, skip steps 1-3 and 5. +If use of SSL is not required, step 4 can also be skipped. + +1. Login to the DAV Explorer Subversion archive with any Subversion client. + The Subversion archive is located at + http://louvre.ics.uci.edu:8080/svn/DAVExplorer/ + NOTE: the archive location may change in the near future, so be sure to check + the DAV Explorer download website http://www.ics.uci.edu/~webdav/download.html + for any changes. + +2. Navigate to your chosen source directory. + +3. Retrieve all DAV Explorer source files from the DAV Explorer Subversion + archive, from the trunk directory, using your favorite Subversion client tool. + The command line format: + svn checkout http://louvre.ics.uci.edu:8080/svn/DAVExplorer/trunk DAVExplorer + +4. If SSL support is required, retrieve the Java Secure Socket Extensions from + http://java.sun.com/products/jsse/ + Install the JSSE files according to the JSSE documentation. + Note that from JDK 1.4 on, JSSE is included in the JDK. + Make sure that the appropriate X.509 certificates are installed at the + Webserver. + +5. Compile all Java source files with Java 2 by running make in the dav_explorer + directory directly below your source directory. This also creates a + DAVExplorer.jar file in the dav_explorer directory. + The DAV Explorer sources do not compile without the JSSE files present. + Note that the Makefile does not work under MS Windows. Instead, running the + make.bat file in the dav_explorer directory achieves the same result. + Under MS Windows, you can also run the DAVjar.bat file from the dav_explorer + directory to create the DAVExplorer.jar file. + Under Unix, the DAVjar.sh shell script serves the same purpose. + We also provide an Eclipse workspace file in the source distribution. + +6. Run the DAV Explorer. + Under MS Windows, run the DAVExplorer.bat file from the dav_explorer directory. + Under Unix, run the DAVExplorer.sh shell script from the dav_explorer directory. + You can also run DAVExplorer by using the command 'java -jar DAVExplorer.jar'. + For SSL support, run DAVExplorerSSL.bat or DAVExplorerSSL.sh, respectively. + Alternatively, the command 'java -jar -Dssl=true DAVExplorer.jar' can be used. + SSL support can also be selected from the Edit menu. + Under MacOS 9, you can use the provided MRJ wrapper DAVExplorer.bin. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |