Initial commit
This commit is contained in:
commit
bfbe536886
59 files changed
+2540
No files matched your search
@@ -0,0 +1,45 @@
|
||||
package org.scribe.extractors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.*;
|
||||
import org.scribe.exceptions.*;
|
||||
import org.scribe.model.*;
|
||||
import org.scribe.model.Request.*;
|
||||
import org.scribe.test.helpers.*;
|
||||
|
||||
public class BaseStringExtractorTest
|
||||
{
|
||||
|
||||
private BaseStringExtractorImpl extractor;
|
||||
private OAuthRequest request;
|
||||
|
||||
@Before
|
||||
public void setup()
|
||||
{
|
||||
request = ObjectMother.createSampleOAuthRequest();
|
||||
extractor = new BaseStringExtractorImpl();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExtractBaseStringFromOAuthRequest()
|
||||
{
|
||||
String expected = "GET&http%3A%2F%2Fexample.com&oauth_callback%3Dhttp%253A%252F%252Fexample%252Fcallback%26oauth_consumer_key%3DAS%2523%2524%255E*%2540%2526%26oauth_signature%3DOAuth-Signature%26oauth_timestamp%3D123456";
|
||||
String baseString = extractor.extract(request);
|
||||
assertEquals(expected, baseString);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionIfRquestIsNull()
|
||||
{
|
||||
OAuthRequest nullRequest = null;
|
||||
extractor.extract(nullRequest);
|
||||
}
|
||||
|
||||
@Test(expected = OAuthParametersMissingException.class)
|
||||
public void shouldThrowExceptionIfRquestHasNoOAuthParameters()
|
||||
{
|
||||
OAuthRequest request = new OAuthRequest(Verb.GET, "http://example.com");
|
||||
extractor.extract(request);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.scribe.extractors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.*;
|
||||
import org.scribe.exceptions.*;
|
||||
import org.scribe.model.*;
|
||||
import org.scribe.model.Request.*;
|
||||
import org.scribe.test.helpers.*;
|
||||
|
||||
public class HeaderExtractorTest
|
||||
{
|
||||
|
||||
private HeaderExtractorImpl extractor;
|
||||
private OAuthRequest request;
|
||||
|
||||
@Before
|
||||
public void setup()
|
||||
{
|
||||
request = ObjectMother.createSampleOAuthRequest();
|
||||
extractor = new HeaderExtractorImpl();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExtractStandardHeader()
|
||||
{
|
||||
String expected = "OAuth oauth_callback=\"http%3A%2F%2Fexample%2Fcallback\", " + "oauth_signature=\"OAuth-Signature\", "
|
||||
+ "oauth_consumer_key=\"AS%23%24%5E*%40%26\", " + "oauth_timestamp=\"123456\"";
|
||||
String header = extractor.extract(request);
|
||||
assertEquals(expected, header);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldExceptionIfRequestIsNull()
|
||||
{
|
||||
OAuthRequest nullRequest = null;
|
||||
extractor.extract(nullRequest);
|
||||
}
|
||||
|
||||
@Test(expected = OAuthParametersMissingException.class)
|
||||
public void shouldExceptionIfRequestHasNoOAuthParams()
|
||||
{
|
||||
OAuthRequest emptyRequest = new OAuthRequest(Verb.GET, "http://example.com");
|
||||
extractor.extract(emptyRequest);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package org.scribe.extractors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.*;
|
||||
import org.scribe.exceptions.*;
|
||||
import org.scribe.model.*;
|
||||
|
||||
public class TokenExtractorTest
|
||||
{
|
||||
|
||||
private TokenExtractorImpl extractor;
|
||||
|
||||
@Before
|
||||
public void setup()
|
||||
{
|
||||
extractor = new TokenExtractorImpl();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExtractTokenFromOAuthStandardResponse()
|
||||
{
|
||||
String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03";
|
||||
Token extracted = extractor.extract(response);
|
||||
assertEquals("hh5s93j4hdidpola", extracted.getToken());
|
||||
assertEquals("hdhd0244k9j7ao03", extracted.getSecret());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExtractTokenFromResponseWithCallbackConfirmed()
|
||||
{
|
||||
String response = "oauth_token=hh5s93j4hdidpola&oauth_token_secret=hdhd0244k9j7ao03&callback_confirmed=true";
|
||||
Token extracted = extractor.extract(response);
|
||||
assertEquals("hh5s93j4hdidpola", extracted.getToken());
|
||||
assertEquals("hdhd0244k9j7ao03", extracted.getSecret());
|
||||
}
|
||||
|
||||
@Test(expected = OAuthException.class)
|
||||
public void shouldThrowExceptionIfTokenIsAbsent()
|
||||
{
|
||||
String response = "oauth_secret=hh5s93j4hdidpola&callback_confirmed=true";
|
||||
extractor.extract(response);
|
||||
}
|
||||
|
||||
@Test(expected = OAuthException.class)
|
||||
public void shouldThrowExceptionIfSecretIsAbsent()
|
||||
{
|
||||
String response = "oauth_token=hh5s93j4hdidpola&callback_confirmed=true";
|
||||
extractor.extract(response);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionIfResponseIsNull()
|
||||
{
|
||||
String response = null;
|
||||
extractor.extract(response);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void shouldThrowExceptionIfResponseIsEmptyString()
|
||||
{
|
||||
String response = "";
|
||||
extractor.extract(response);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user