Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #232 from vmotolyzhenko/extend-test-user-operations
Browse files Browse the repository at this point in the history
Added new endpoint 'getTestUsers' to TestUserOperations api
  • Loading branch information
habuma authored Oct 24, 2017
2 parents 24f4722 + 31b5f0d commit eadda43
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.social.facebook.api;

import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonProperty;

/**
* @author vmotolyzhenko
*/
public class TestUserList extends FacebookObject {
@JsonProperty("data")
private List<TestUser> testUsers = new ArrayList<>();

public List<TestUser> getTestUsers() {
return testUsers;
}

public void setTestUsers(List<TestUser> testUsers) {
this.testUsers = testUsers;
}

@Override
@JsonAnySetter
protected void add(String key, Object value) {
super.add(key, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
*/
package org.springframework.social.facebook.api;

import java.util.List;

public interface TestUserOperations {

TestUser createTestUser(boolean installed, String permissions);

TestUser createTestUser(boolean installed, String permissions, String name);

List<TestUser> getTestUsers();

void sendConfirmFriends(TestUser user1, TestUser user2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@
*/
package org.springframework.social.facebook.api.impl;

import java.util.Collections;
import java.util.List;
import java.util.Optional;

import org.springframework.social.facebook.api.GraphApi;
import org.springframework.social.facebook.api.TestUser;
import org.springframework.social.facebook.api.TestUserList;
import org.springframework.social.facebook.api.TestUserOperations;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
Expand Down Expand Up @@ -65,6 +70,12 @@ public TestUser createTestUser(boolean installed, String permissions, String nam

return restTemplate.postForObject(graphApi.getBaseGraphApiUrl() + "{appId}/accounts/test-users", request, TestUser.class, appId);
}

@Override
public List<TestUser> getTestUsers() {
TestUserList users = restTemplate.getForObject(graphApi.getBaseGraphApiUrl() + "{appId}/accounts/test-users", TestUserList.class, appId);
return Optional.ofNullable(users).map(TestUserList::getTestUsers).orElse(Collections.emptyList());
}

public void sendConfirmFriends(TestUser testUser1, TestUser testUser2) {
RestOperations userRest = new FacebookTemplate(testUser1.getAccessToken()).restOperations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@
*/
package org.springframework.social.facebook.api;

import static org.junit.Assert.*;
import static org.springframework.http.HttpMethod.*;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.*;
import static org.springframework.test.web.client.response.MockRestResponseCreators.*;
import java.util.List;

import org.junit.Test;
import org.springframework.http.MediaType;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.springframework.http.HttpMethod.GET;
import static org.springframework.http.HttpMethod.POST;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.content;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.header;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;

/**
* @author Craig Walls
*/
Expand All @@ -47,6 +54,22 @@ public void post_message() throws Exception {
}

// id, email, password, access_token, login_url


@Test
public void get_test_user_list() throws Exception {
String responseBody = "{\"data\":[{\"id\":\"101234413904069\",\"login_url\":\"LOGIN_URL\",\"access_token\":\"ACCESS_TOKEN\"}],\"paging\":{\"cursors\":{\"before\":\"MTAxMjM0NDEzOTA0MDY5\",\"after\":\"MTA1MDE2MjcwMTg3ODMz\"}}}";
mockServer.expect(requestTo(fbUrl("APP_ID/accounts/test-users")))
.andExpect(method(GET))
.andExpect(header("Authorization", "OAuth someAccessToken"))
.andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));

List<TestUser> testUserList = facebook.testUserOperations().getTestUsers();
assertTrue(testUserList.size() == 1);
TestUser testUser= testUserList.get(0);
assertEquals("101234413904069", testUser.getId());
assertEquals("ACCESS_TOKEN", testUser.getAccessToken());
assertEquals("LOGIN_URL", testUser.getLoginUrl());
mockServer.verify();
}

}

0 comments on commit eadda43

Please sign in to comment.