Skip to content

Instantly share code, notes, and snippets.

@greghelton
Created December 26, 2011 19:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greghelton/1521956 to your computer and use it in GitHub Desktop.
Save greghelton/1521956 to your computer and use it in GitHub Desktop.
Java: JUnit test Using Apache HTTPComponents
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();
}
}
}
@codessentials
Copy link

Can you please tell me where I can find StreamReaderHelper?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment