package org.scribe.model; import static org.junit.Assert.*; import java.nio.charset.Charset; import org.junit.Assume; import org.junit.Test; public class TestRequest { @Test public void testValidConstructor() { String url = "http://www.facebook.com/"; Verb verb = Verb.GET; OAuthRequest req = new OAuthRequest(verb, url); assertTrue(req.getUrl().equals(url)); assertTrue(req.getVerb().equals(verb)); } @Test public void testAddHeader() { String url = "http://www.google.com/"; Verb verb = Verb.POST; // little variation here ... Request req = new Request(verb, url); String key = "Header23"; String value = "HeaderValue23"; try { req.addHeader(key, value); } catch (Exception e) { Assume.assumeNoException(e); } assertTrue(req.getHeaders().containsKey(key)); assertTrue(req.getHeaders().containsValue(value)); } @Test public void testAddBodyParameter() { String url = "http://www.twitter.com"; Verb verb = Verb.PUT; // little variation here ... Request req = new Request(verb, url); String key = "BodyParam53"; String value = "BodyValue64"; try { req.addBodyParameter(key, value); } catch (Exception e) { Assume.assumeNoException(e); } Parameter param = new Parameter(key, value); assertTrue(req.getBodyParams().contains(param)); } @Test public void testCharset() { String url = "http://www.bing.com"; Verb verb = Verb.HEAD; // little variation here ... Request req = new Request(verb, url); String charset = "whatSoEver"; req.setCharset(charset); assert (req.getCharset().equals(charset)); } @Test public void testEmptyCharset() { String url = "http://www.bing.com"; Verb verb = Verb.PATCH; // little variation here ... Request req = new Request(verb, url); String charset = null; req.setCharset(charset); assert (req.getCharset().equals(Charset.defaultCharset().name())); } }