Search in sources :

Example 1 with DevicesHandler

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler in project aws-sdk-android by aws-amplify.

the class CognitoIdentityProviderDevicesTest method listDevicesInCurrentThread.

@Test
public void listDevicesInCurrentThread() {
    // 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.listDevices(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);
        }
    });
}
Also used : DevicesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler) ArgumentCaptor(org.mockito.ArgumentCaptor) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) ListDevicesRequest(com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest) Test(org.junit.Test)

Example 2 with DevicesHandler

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler 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);
        }
    });
}
Also used : DevicesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler) ArgumentCaptor(org.mockito.ArgumentCaptor) CognitoDevice(com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice) ListDevicesRequest(com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest) Test(org.junit.Test)

Example 3 with DevicesHandler

use of com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler in project aws-sdk-android by aws-amplify.

the class CognitoUser method listDevicesInBackground.

/**
 * Fetches the list of all remembered devices for this user.
 *
 * @param limit REQUIRED: Maximum number of devices to be returned in this
 *            call, defaults to 10.
 * @param paginationToken REQUIRED: Token to continue an earlier search.
 * @param callback REQUIRED: {@link DevicesHandler} callback.
 */
public void listDevicesInBackground(final int limit, final String paginationToken, final DevicesHandler callback) {
    if (callback == null) {
        throw new CognitoParameterInvalidException("callback is null");
    }
    final CognitoUser user = this;
    new Thread(new Runnable() {

        @Override
        public void run() {
            final Handler handler = new Handler(context.getMainLooper());
            Runnable returnCallback;
            try {
                final ListDevicesResult listDevicesResult = listDevicesInternal(user.getCachedSession(), limit, paginationToken);
                final List<CognitoDevice> devicesList = new ArrayList<CognitoDevice>();
                for (final DeviceType device : listDevicesResult.getDevices()) {
                    devicesList.add(new CognitoDevice(device, user, context));
                }
                returnCallback = new Runnable() {

                    @Override
                    public void run() {
                        callback.onSuccess(devicesList);
                    }
                };
            } catch (final Exception e) {
                returnCallback = new Runnable() {

                    @Override
                    public void run() {
                        callback.onFailure(e);
                    }
                };
            }
            handler.post(returnCallback);
        }
    }).start();
}
Also used : ListDevicesResult(com.amazonaws.services.cognitoidentityprovider.model.ListDevicesResult) DeviceType(com.amazonaws.services.cognitoidentityprovider.model.DeviceType) CognitoParameterInvalidException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException) ArrayList(java.util.ArrayList) Handler(android.os.Handler) GetDetailsHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler) AuthenticationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler) GenericHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler) VerificationHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.VerificationHandler) UpdateAttributesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler) ForgotPasswordHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.ForgotPasswordHandler) RegisterMfaHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.RegisterMfaHandler) DevicesHandler(com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CognitoInternalErrorException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoInternalErrorException) UserNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.UserNotFoundException) CognitoParameterInvalidException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException) NotAuthorizedException(com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException) ResourceNotFoundException(com.amazonaws.services.cognitoidentityprovider.model.ResourceNotFoundException) InvalidParameterException(com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException) CognitoNotAuthorizedException(com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)

Aggregations

DevicesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.DevicesHandler)3 CognitoDevice (com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoDevice)2 ListDevicesRequest (com.amazonaws.services.cognitoidentityprovider.model.ListDevicesRequest)2 Test (org.junit.Test)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 Handler (android.os.Handler)1 CognitoInternalErrorException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoInternalErrorException)1 CognitoNotAuthorizedException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoNotAuthorizedException)1 CognitoParameterInvalidException (com.amazonaws.mobileconnectors.cognitoidentityprovider.exceptions.CognitoParameterInvalidException)1 AuthenticationHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.AuthenticationHandler)1 ForgotPasswordHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.ForgotPasswordHandler)1 GenericHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GenericHandler)1 GetDetailsHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.GetDetailsHandler)1 RegisterMfaHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.RegisterMfaHandler)1 UpdateAttributesHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.UpdateAttributesHandler)1 VerificationHandler (com.amazonaws.mobileconnectors.cognitoidentityprovider.handlers.VerificationHandler)1 DeviceType (com.amazonaws.services.cognitoidentityprovider.model.DeviceType)1 InvalidParameterException (com.amazonaws.services.cognitoidentityprovider.model.InvalidParameterException)1 ListDevicesResult (com.amazonaws.services.cognitoidentityprovider.model.ListDevicesResult)1 NotAuthorizedException (com.amazonaws.services.cognitoidentityprovider.model.NotAuthorizedException)1