Created
December 26, 2011 19:17
-
-
Save greghelton/1521956 to your computer and use it in GitHub Desktop.
Java: JUnit test Using Apache HTTPComponents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package us.greg; | |
import org.junit.Test; | |
import static org.junit.Assert.assertEquals; | |
import static org.junit.Assert.assertTrue; | |
import static org.junit.Assert.fail; | |
import java.io.BufferedReader; | |
import java.io.ByteArrayInputStream; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.io.Reader; | |
import java.io.StringWriter; | |
import java.io.Writer; | |
import java.io.IOException; | |
import org.apache.http.HttpEntity; | |
import org.apache.http.HttpResponse; | |
import org.apache.http.client.HttpClient; | |
import org.apache.http.client.methods.HttpGet; | |
import org.apache.http.impl.client.DefaultHttpClient; | |
import java.net.URLEncoder; | |
public class TestStoreForward { | |
String xmlRequest = URLEncoder.encode( | |
"http://localhost:8080/atm/prefs?customerID=123456789&atm=FG3781", "UTF-8"); | |
/* | |
* this is the test of the servlet and SP call | |
*/ | |
@Test | |
public void sqlErrorTest() { | |
try { | |
HttpGet httpget = new HttpGet(xmlRequest); | |
HttpClient httpclient = new DefaultHttpClient(); | |
HttpResponse response = httpclient.execute(httpget); | |
HttpEntity entity = response.getEntity(); | |
if (entity != null) { | |
InputStream instream = entity.getContent(); | |
String data = StreamReaderHelper.readStream(instream); | |
assertTrue(true); | |
} | |
} catch (Exception e) { | |
fail(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you please tell me where I can find StreamReaderHelper?