public
Last active

Java: JUnit test Using Apache HTTPComponents

  • Download Gist
TestStoreForward.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
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();
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.