use of com.microsoft.identity.common.internal.dto.AccessTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class CacheKeyValueDelegateTest method accessTokenCreateCacheValue.
@Test
public void accessTokenCreateCacheValue() throws JSONException {
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setCredentialType(CredentialType.AccessToken.name().toLowerCase(Locale.US));
accessToken.setClientId(CLIENT_ID);
accessToken.setRealm(REALM);
accessToken.setTarget(TARGET);
final String serializedValue = mDelegate.generateCacheValue(accessToken);
// Turn the serialized value into a JSONObject and start testing field equality.
final JSONObject jsonObject = new JSONObject(serializedValue);
assertEquals(HOME_ACCOUNT_ID, jsonObject.getString(Credential.SerializedNames.HOME_ACCOUNT_ID));
assertEquals(ENVIRONMENT, jsonObject.getString(Credential.SerializedNames.ENVIRONMENT));
assertEquals(CredentialType.AccessToken.name().toLowerCase(Locale.US), jsonObject.getString("credential_type"));
assertEquals(CLIENT_ID, jsonObject.getString(Credential.SerializedNames.CLIENT_ID));
assertEquals(REALM, jsonObject.getString(AccessTokenRecord.SerializedNames.REALM));
assertEquals(TARGET, jsonObject.getString(AccessTokenRecord.SerializedNames.TARGET));
}
use of com.microsoft.identity.common.internal.dto.AccessTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class CacheKeyValueDelegateTest method testAccessTokenTypeProperty.
@Test
public void testAccessTokenTypeProperty() {
// Test to verify that "token_type" is correctly serialized into token_type property
final String authScheme = "Bearer";
final String jsonStr = "{\"token_type\": \"" + authScheme + "\"}";
final AccessTokenRecord record = mDelegate.fromCacheValue(jsonStr, AccessTokenRecord.class);
assertEquals(authScheme, record.getAccessTokenType());
}
use of com.microsoft.identity.common.internal.dto.AccessTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class CacheKeyValueDelegateTest method accessTokenCreateCacheKeyNoTarget.
@Test
public void accessTokenCreateCacheKeyNoTarget() {
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setCredentialType(CredentialType.AccessToken.name());
accessToken.setClientId(CLIENT_ID);
accessToken.setRealm(REALM);
final String expectedKey = // just for formatting
"" + HOME_ACCOUNT_ID + CACHE_VALUE_SEPARATOR + ENVIRONMENT + CACHE_VALUE_SEPARATOR + CREDENTIAL_TYPE_ACCESS_TOKEN + CACHE_VALUE_SEPARATOR + CLIENT_ID + CACHE_VALUE_SEPARATOR + REALM + CACHE_VALUE_SEPARATOR;
assertEquals(expectedKey, mDelegate.generateCacheKey(accessToken));
}
use of com.microsoft.identity.common.internal.dto.AccessTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class CacheKeyValueDelegateTest method accessTokenCreateCacheKeyNoRealm.
@Test
public void accessTokenCreateCacheKeyNoRealm() {
final AccessTokenRecord accessToken = new AccessTokenRecord();
accessToken.setHomeAccountId(HOME_ACCOUNT_ID);
accessToken.setEnvironment(ENVIRONMENT);
accessToken.setCredentialType(CredentialType.AccessToken.name());
accessToken.setClientId(CLIENT_ID);
accessToken.setTarget(TARGET);
final String expectedKey = // just for formatting
"" + HOME_ACCOUNT_ID + CACHE_VALUE_SEPARATOR + ENVIRONMENT + CACHE_VALUE_SEPARATOR + CREDENTIAL_TYPE_ACCESS_TOKEN + CACHE_VALUE_SEPARATOR + CLIENT_ID + CACHE_VALUE_SEPARATOR + CACHE_VALUE_SEPARATOR + TARGET;
assertEquals(expectedKey, mDelegate.generateCacheKey(accessToken));
}
use of com.microsoft.identity.common.internal.dto.AccessTokenRecord in project microsoft-authentication-library-common-for-android by AzureAD.
the class CacheKeyValueDelegateTest method testAccessTokenTypePropertyRename.
@Test
public void testAccessTokenTypePropertyRename() {
// Test to verify that "access_token_type" is correctly serialized into token_type property
final String authScheme = "Bearer";
final String jsonStr = "{\"access_token_type\": \"" + authScheme + "\"}";
final AccessTokenRecord record = mDelegate.fromCacheValue(jsonStr, AccessTokenRecord.class);
assertEquals(authScheme, record.getAccessTokenType());
}
Aggregations