Re: Bitte um Hilfe: HttpUnit Problem (Asking for help with a HttpUnit problem)

"Wolfgang Fahl" <[email protected]> Thu, 20 Aug 2009 10:48:27 +0200
Newsgroups gmane.comp.web.httpunit.devel
Organization BITPlan GmbH
Message-ID <[email protected]>
Hello Oliver,

WebResponse.getBytes is now available to directly access 
the bytes. The internal String represenation is 
different and the conversion would be somewhat awkward.

See
http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1043

for the modifications

I'm copying the mailinglist with your original mail and 
will try to translate the content as:
"I have integrated my Testcase in the File 
MessageBodyRequestTest.java". Based on the test i found 
a Workaround. Please look at the two lines that were 
commented by me. Based on this I am not sure whether 
this is a bug or not. But i'm sure it's less effort now 
to find this our"

Yes indeed - it was simple to check that this is a small 
Change Request. Hopefully WebRespons.getBytes might be 
useful for others.

Thanks for your comment!

Wolfgang

From:           	Oliver Wahlen <[email protected]>
To:             	[email protected]
Subject:        	Re: Bitte um Hilfe: HttpUnit Problem

> Hallo Wolfgang,
> Ich habe meinen Testcase in die Datei MessageBodyRequestTest.java 
> integriert.
> Basierend auf diesem Test habe ich zunächst einen Workaround gefunden.
> Schau Dir bitte mal unten die beiden von mir kommentierten Zeilen an.
> Ich bin mir basierend darauf nicht mehr sicher, ob das nun ein Bug ist 
> oder nicht.
> Aber das bekommst Du sicher jetzt mit wenig Aufwand raus :-)
> 
> Mein Code:
> ---------- Schnipp ----------
> public void testDownloadRequestUsingGetText() throws Exception {
>  defineResource( "ReportData", new BodyEcho() );
>  byte[] binaryData = new byte[256];
>  for(int i=0;i<=255;i++) {
>  binaryData[i] = (byte)i;
>  }
> 
>  InputStream source = new ByteArrayInputStream( binaryData );
> 
>  WebConversation wc = new WebConversation();
>  WebRequest wr = new PutMethodWebRequest( getHostPath() + "/ReportData", 
> source, "application/random" );
>  WebResponse response = wc.getResponse( wr );
>  // currently the following line does not work:
>  byte[] download = response.getText().getBytes();
>  // currently the following line works:
>  //byte[] download = getDownload( response );
>  assertEquals( "Body response", binaryData, download );
>  }
> ---------- Schnapp ----------
> 
> Zur Info:
> Im Test habt Ihr die Methode getDownload implementiert.
> Sie sieht wie folgt aus:
> ---------- Schnipp ----------
>  private byte[] getDownload( WebResponse response ) throws IOException {
>  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
>  InputStream inputStream = response.getInputStream();
> 
>  byte[] buffer = new byte[8 * 1024];
>  int count = 0;
>  do {
>  outputStream.write( buffer, 0, count );
>  count = inputStream.read( buffer, 0, buffer.length );
>  } while (count != -1);
> 
>  inputStream.close();
>  return outputStream.toByteArray();
>  }
> ---------- Schnapp ----------
> 
> mit freundlichen Grüßen,
> Oliver
> 
> 



BITPlan - smart solutions
Pater-Delp-Str. 1, D-47877 Willich Schiefbahn
Tel. +49 2154 811-480, Fax +49 2154 811-481
Web: http://www.bitplan.de
bitplan GmbH, Willich - HRB 6820 Krefeld, VAT-ID: 10258040548, 
Geschäftsführer: Wolfgang Fahl

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july

_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop