コード例 #1
0
  private void finishAuthWithTestAccount(TestAccount testAccount) {
    testAccountId = testAccount.getId();

    AccessToken accessToken =
        AccessToken.createFromString(
            testAccount.getAccessToken(), requestedPermissions, AccessTokenSource.TEST_USER);
    finishAuthOrReauth(accessToken, null);
  }
コード例 #2
0
  private static synchronized TestAccount findTestAccountMatchingIdentifier(String identifier) {
    retrieveTestAccountsForAppIfNeeded();

    for (TestAccount testAccount : appTestAccounts.values()) {
      if (testAccount.getName().contains(identifier)) {
        return testAccount;
      }
    }
    return null;
  }
コード例 #3
0
  private static synchronized void populateTestAccounts(
      Collection<TestAccount> testAccounts, Collection<UserAccount> userAccounts) {
    // We get different sets of data from each of these queries. We want to combine them into a
    // single data
    // structure. We have added a Name property to the TestAccount interface, even though we don't
    // really get
    // a name back from the service from that query. We stick the Name from the corresponding
    // UserAccount in it.
    for (TestAccount testAccount : testAccounts) {
      storeTestAccount(testAccount);
    }

    for (UserAccount userAccount : userAccounts) {
      TestAccount testAccount = appTestAccounts.get(userAccount.getUid());
      if (testAccount != null) {
        testAccount.setName(userAccount.getName());
      }
    }
  }
コード例 #4
0
  private TestAccount createTestAccountAndFinishAuth() {
    Bundle parameters = new Bundle();
    parameters.putString("installed", "true");
    parameters.putString("permissions", getPermissionsString());
    parameters.putString("access_token", getAppAccessToken());

    // If we're in shared mode, we want to rename this user to encode its permissions, so we can
    // find it later
    // in another shared session. If we're in private mode, don't bother renaming it since we're
    // just going to
    // delete it at the end of the session.
    if (mode == Mode.SHARED) {
      parameters.putString(
          "name", String.format("Shared %s Testuser", getSharedTestAccountIdentifier()));
    }

    String graphPath = String.format("%s/accounts/test-users", testApplicationId);
    Request createUserRequest = new Request(null, graphPath, parameters, HttpMethod.POST);
    Response response = createUserRequest.executeAndWait();

    FacebookRequestError error = response.getError();
    TestAccount testAccount = response.getGraphObjectAs(TestAccount.class);
    if (error != null) {
      finishAuthOrReauth(null, error.getException());
      return null;
    } else {
      assert testAccount != null;

      // If we are in shared mode, store this new account in the dictionary so we can re-use it
      // later.
      if (mode == Mode.SHARED) {
        // Remember the new name we gave it, since we didn't get it back in the results of the
        // create request.
        testAccount.setName(parameters.getString("name"));
        storeTestAccount(testAccount);
      }

      finishAuthWithTestAccount(testAccount);

      return testAccount;
    }
  }
コード例 #5
0
 private static synchronized void storeTestAccount(TestAccount testAccount) {
   appTestAccounts.put(testAccount.getId(), testAccount);
 }