Skip to content

@greghelton /TestStoreForward.java
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.