use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderDevicesTest method forgetDeviceInCurrentThread.
@Test
public void forgetDeviceInCurrentThread() {
CognitoDeviceHelper.cacheDeviceKey(TEST_USER_NAME, TEST_USER_POOL, TEST_DEVICE_KEY, appContext);
testUser = testPool.getUser(TEST_USER_NAME);
// Store tokens in shared preferences
final String testAccessToken = getValidJWT(3600L);
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "idToken", getValidJWT(3600L));
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", testAccessToken);
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
// Set mock result for the change password request API call
doNothing().when(mockCSIClient).forgetDevice(any(ForgetDeviceRequest.class));
final CountDownLatch countDownLatch = new CountDownLatch(1);
CognitoDevice cachedDevice = testUser.thisDevice();
cachedDevice.forgetDevice(new GenericHandler() {
@Override
public void onSuccess() {
ArgumentCaptor<ForgetDeviceRequest> argumentCaptor = ArgumentCaptor.forClass(ForgetDeviceRequest.class);
verify(mockCSIClient).forgetDevice(argumentCaptor.capture());
ForgetDeviceRequest requestSent = argumentCaptor.getValue();
Log.d(TAG, "testAccessToken = " + testAccessToken);
Log.d(TAG, "requestSent.getAccessToken() = " + requestSent.getAccessToken());
assertEquals(testAccessToken, requestSent.getAccessToken());
countDownLatch.countDown();
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
countDownLatch.countDown();
}
});
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderDevicesTest method getDeviceDetailsInCurrentThread.
@Test
public void getDeviceDetailsInCurrentThread() {
CognitoDeviceHelper.cacheDeviceKey(TEST_USER_NAME, TEST_USER_POOL, TEST_DEVICE_KEY, appContext);
testUser = testPool.getUser(TEST_USER_NAME);
// Store tokens in shared preferences
final String testAccessToken = getValidJWT(3600L);
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + ".idToken", getValidJWT(3600L));
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", testAccessToken);
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
// Set mock result for the change password request API call
doReturn(TEST_VALID_GET_DEVICE_RESPONSE).when(mockCSIClient).getDevice(any(GetDeviceRequest.class));
CognitoDevice cachedDevice = testUser.thisDevice();
cachedDevice.getDevice(new GenericHandler() {
@Override
public void onSuccess() {
ArgumentCaptor<GetDeviceRequest> argumentCaptor = ArgumentCaptor.forClass(GetDeviceRequest.class);
verify(mockCSIClient).getDevice(argumentCaptor.capture());
GetDeviceRequest requestSent = argumentCaptor.getValue();
assertEquals(testAccessToken, requestSent.getAccessToken());
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderDevicesTest method listDevicesInBackgroundThread.
@Test
public void listDevicesInBackgroundThread() {
// Set mock result for the change password request API call
doReturn(TEST_VALID_LIST_DEVICES_RESPONSE).when(mockCSIClient).listDevices(any(ListDevicesRequest.class));
// Store tokens in shared preferences
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "idToken", getValidJWT(3600L));
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", getValidJWT(3600L));
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
testUser.listDevicesInBackground(10, "ptoken", new DevicesHandler() {
@Override
public void onSuccess(List<CognitoDevice> devices) {
assertNotNull(devices);
ArgumentCaptor<ListDevicesRequest> argumentCaptor = ArgumentCaptor.forClass(ListDevicesRequest.class);
verify(mockCSIClient).listDevices(argumentCaptor.capture());
ListDevicesRequest requestSent = argumentCaptor.getValue();
assertEquals("ptoken", requestSent.getPaginationToken());
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderDevicesTest method forgetDeviceInBackgroundThread.
@Test
public void forgetDeviceInBackgroundThread() {
CognitoDeviceHelper.cacheDeviceKey(TEST_USER_NAME, TEST_USER_POOL, TEST_DEVICE_KEY, appContext);
testUser = testPool.getUser(TEST_USER_NAME);
// Store tokens in shared preferences
final String testAccessToken = getValidJWT(3600L);
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "idToken", getValidJWT(3600L));
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "accessToken", testAccessToken);
awsKeyValueStorageUtility.put("CognitoIdentityProvider." + TEST_CLIENT_ID + "." + TEST_USER_NAME + "." + "refreshToken", TEST_CACHED_RTOKEN);
// Set mock result for the change password request API call
doNothing().when(mockCSIClient).forgetDevice(any(ForgetDeviceRequest.class));
CognitoDevice cachedDevice = testUser.thisDevice();
cachedDevice.forgetDeviceInBackground(new GenericHandler() {
@Override
public void onSuccess() {
ArgumentCaptor<ForgetDeviceRequest> argumentCaptor = ArgumentCaptor.forClass(ForgetDeviceRequest.class);
verify(mockCSIClient).forgetDevice(argumentCaptor.capture());
ForgetDeviceRequest requestSent = argumentCaptor.getValue();
assertEquals(testAccessToken, requestSent.getAccessToken());
}
@Override
public void onFailure(Exception exception) {
assertNotNull(exception);
}
});
}
use of com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice in project aws-sdk-android by aws-amplify.
the class CognitoIdentityProviderDevicesTest method getDevice.
@Test
public void getDevice() {
CognitoDeviceHelper.cacheDeviceKey(TEST_USER_NAME, TEST_USER_POOL, TEST_DEVICE_KEY, appContext);
testUser = testPool.getUser(TEST_USER_NAME);
CognitoDevice cachedDevice = testUser.thisDevice();
assertNotNull(cachedDevice);
}
Aggregations