|
| 1 | +package org.scribe.builder; |
| 2 | + |
| 3 | +import static org.junit.Assert.*; |
| 4 | + |
| 5 | +import org.junit.*; |
| 6 | +import org.scribe.builder.api.*; |
| 7 | +import org.scribe.model.*; |
| 8 | +import org.scribe.oauth.*; |
| 9 | + |
| 10 | +public class ServiceBuilderTest |
| 11 | +{ |
| 12 | + private ServiceBuilder builder; |
| 13 | + |
| 14 | + @Before |
| 15 | + public void setup() |
| 16 | + { |
| 17 | + builder = new ServiceBuilder(); |
| 18 | + } |
| 19 | + |
| 20 | + @Test |
| 21 | + public void shouldReturnOOBasDefaultCallback() |
| 22 | + { |
| 23 | + builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").build(); |
| 24 | + assertEquals(ApiMock.config.getApiKey(), "key"); |
| 25 | + assertEquals(ApiMock.config.getApiSecret(), "secret"); |
| 26 | + assertEquals(ApiMock.config.getCallback(), OAuthConstants.OUT_OF_BAND); |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + public void shouldAcceptValidCallbackUrl() |
| 31 | + { |
| 32 | + builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").callback("http://example.com").build(); |
| 33 | + assertEquals(ApiMock.config.getApiKey(), "key"); |
| 34 | + assertEquals(ApiMock.config.getApiSecret(), "secret"); |
| 35 | + assertEquals(ApiMock.config.getCallback(), "http://example.com"); |
| 36 | + } |
| 37 | + |
| 38 | + @Test(expected=IllegalArgumentException.class) |
| 39 | + public void shouldNotAcceptAnInvalidUrlAsCallback() |
| 40 | + { |
| 41 | + builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").callback("example.com").build(); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void shouldAcceptAnScope() |
| 46 | + { |
| 47 | + builder.provider(ApiMock.class).apiKey("key").apiSecret("secret").scope("rss-api").build(); |
| 48 | + assertEquals(ApiMock.config.getApiKey(), "key"); |
| 49 | + assertEquals(ApiMock.config.getApiSecret(), "secret"); |
| 50 | + assertEquals(ApiMock.scope, "rss-api"); |
| 51 | + } |
| 52 | + |
| 53 | + public static class ApiMock implements Api |
| 54 | + { |
| 55 | + public static OAuthConfig config; |
| 56 | + public static String scope; |
| 57 | + |
| 58 | + @Override |
| 59 | + public OAuthService createService(OAuthConfig config, String scope) |
| 60 | + { |
| 61 | + ApiMock.config = config; |
| 62 | + ApiMock.scope = scope; |
| 63 | + return null; |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments