Search in sources :

Example 6 with PrimaryRefreshTokenRecord

use of com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.

the class CacheKeyValueDelegateTest method primaryRefreshTokenCreateCacheValue.

@Test
public void primaryRefreshTokenCreateCacheValue() throws JSONException {
    final PrimaryRefreshTokenRecord primaryRefreshToken = new PrimaryRefreshTokenRecord();
    primaryRefreshToken.setHomeAccountId(HOME_ACCOUNT_ID);
    primaryRefreshToken.setEnvironment(ENVIRONMENT);
    primaryRefreshToken.setCredentialType(CredentialType.PrimaryRefreshToken.name().toLowerCase(Locale.US));
    primaryRefreshToken.setClientId(CLIENT_ID);
    primaryRefreshToken.setSessionKey(SESSION_KEY);
    final String serializedValue = mDelegate.generateCacheValue(primaryRefreshToken);
    // Turn the serialized value into a JSONObject and start testing field equality.
    final JSONObject jsonObject = new JSONObject(serializedValue);
    assertEquals(HOME_ACCOUNT_ID, jsonObject.getString(PrimaryRefreshTokenRecord.SerializedNames.HOME_ACCOUNT_ID));
    assertEquals(ENVIRONMENT, jsonObject.getString(PrimaryRefreshTokenRecord.SerializedNames.ENVIRONMENT));
    assertEquals(CredentialType.PrimaryRefreshToken.name().toLowerCase(Locale.US), jsonObject.getString("credential_type"));
    assertEquals(CLIENT_ID, jsonObject.getString(PrimaryRefreshTokenRecord.SerializedNames.CLIENT_ID));
    assertEquals(SESSION_KEY, jsonObject.getString(PrimaryRefreshTokenRecord.SerializedNames.SESSION_KEY));
}
Also used : JSONObject(org.json.JSONObject) PrimaryRefreshTokenRecord(com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord) Test(org.junit.Test)

Aggregations

PrimaryRefreshTokenRecord (com.microsoft.identity.common.internal.dto.PrimaryRefreshTokenRecord)6 Test (org.junit.Test)5 Credential (com.microsoft.identity.common.internal.dto.Credential)3 AccessTokenRecord (com.microsoft.identity.common.internal.dto.AccessTokenRecord)1 IdTokenRecord (com.microsoft.identity.common.internal.dto.IdTokenRecord)1 RefreshTokenRecord (com.microsoft.identity.common.internal.dto.RefreshTokenRecord)1 JSONObject (org.json.JSONObject)1