assertEquals(0, serviceProvider.getAccessTokenCount());
assertEquals(0, serviceProvider.getResourceAccessCount());
MakeRequestClient client = makeNonSocialClient("owner", "owner", GADGET_URL);
HttpResponse response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL);
assertEquals("", response.getResponseAsString());
assertEquals(1, serviceProvider.getRequestTokenCount());
assertEquals(0, serviceProvider.getAccessTokenCount());
assertEquals(0, serviceProvider.getResourceAccessCount());
client.approveToken("user_data=hello-oauth");
response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL);
assertEquals("User data is hello-oauth", response.getResponseAsString());
assertEquals(1, serviceProvider.getRequestTokenCount());
assertEquals(1, serviceProvider.getAccessTokenCount());
assertEquals(1, serviceProvider.getResourceAccessCount());
response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL + "?cachebust=1");
assertEquals("User data is hello-oauth", response.getResponseAsString());
assertEquals(1, serviceProvider.getRequestTokenCount());
assertEquals(1, serviceProvider.getAccessTokenCount());
assertEquals(2, serviceProvider.getResourceAccessCount());
serviceProvider.setConsumersThrottled(true);
response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL + "?cachebust=2");
assertEquals("", response.getResponseAsString());
Map<String, String> metadata = response.getMetadata();
assertNotNull(metadata);
assertEquals("consumer_key_refused", metadata.get("oauthError"));
checkStringContains("oauthErrorText mismatch", metadata.get("oauthErrorText"),
"Service provider rejected request");
checkStringContains("oauthErrorText missing request entry", metadata.get("oauthErrorText"),
"GET /data?cachebust=2\n");
checkStringContains("oauthErrorText missing request entry", metadata.get("oauthErrorText"),
"GET /data?cachebust=2&oauth_body_hash=2jm");
assertEquals(1, serviceProvider.getRequestTokenCount());
assertEquals(1, serviceProvider.getAccessTokenCount());
assertEquals(3, serviceProvider.getResourceAccessCount());
serviceProvider.setConsumersThrottled(false);
client.clearState();
response = client.sendGet(FakeOAuthServiceProvider.RESOURCE_URL + "?cachebust=3");
assertEquals("User data is hello-oauth", response.getResponseAsString());
assertEquals(1, serviceProvider.getRequestTokenCount());
assertEquals(1, serviceProvider.getAccessTokenCount());
assertEquals(4, serviceProvider.getResourceAccessCount());
}