|
| 1 | +/* |
| 2 | + * Copyright 2020-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"). |
| 5 | + * You may not use this file except in compliance with the License. |
| 6 | + * A copy of the License is located at |
| 7 | + * |
| 8 | + * http://aws.amazon.com/apache2.0 |
| 9 | + * |
| 10 | + * or in the "license" file accompanying this file. This file is distributed |
| 11 | + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
| 12 | + * express or implied. See the License for the specific language governing |
| 13 | + * permissions and limitations under the License. |
| 14 | + */ |
| 15 | + |
| 16 | +import android.content.Context; |
| 17 | + |
| 18 | +import com.amazonaws.mobileconnectors.cognitoidentityprovider.CognitoUserPool; |
| 19 | +import com.amazonaws.services.cognitoidentityprovider.AmazonCognitoIdentityProvider; |
| 20 | +import com.amazonaws.services.cognitoidentityprovider.AmazonCognitoIdentityProviderClient; |
| 21 | + |
| 22 | +import org.junit.Before; |
| 23 | +import org.junit.Test; |
| 24 | +import org.mockito.Mock; |
| 25 | +import org.mockito.MockitoAnnotations; |
| 26 | + |
| 27 | +import static org.mockito.Mockito.verify; |
| 28 | +import static org.mockito.Mockito.verifyZeroInteractions; |
| 29 | + |
| 30 | +/** |
| 31 | + * Unit test cases for checking the custom end points for Cognito User Identity Pool |
| 32 | + */ |
| 33 | +public class CognitoIdentityProviderCustomEndPointTest { |
| 34 | + |
| 35 | + private CognitoUserPool testPool; |
| 36 | + public static final String TEST_USER_POOL = "DummyUserPool"; |
| 37 | + public static final String TEST_CLIENT_ID = "DummyClientId"; |
| 38 | + public static final String TEST_CLIENT_SECRET = "DummyClientSecret"; |
| 39 | + public static final String TEST_PINPOINT_APP_ID = "DummyPinpointAppId"; |
| 40 | + public static final String DUMMY_CUSTOM_ENDPOINT = "my-custom-endpoint.amazon.com"; |
| 41 | + |
| 42 | + @Mock |
| 43 | + private AmazonCognitoIdentityProviderClient mockCustomEndpointClient; |
| 44 | + |
| 45 | + @Mock |
| 46 | + private Context appContext; |
| 47 | + |
| 48 | + @Before |
| 49 | + public void init() { |
| 50 | + MockitoAnnotations.initMocks(this); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * Test that end point is set for the {@link AmazonCognitoIdentityProviderClient } with correct value |
| 55 | + * when {@link CognitoUserPool#CognitoUserPool(Context, String, String, String, AmazonCognitoIdentityProvider, String, String)} is called |
| 56 | + * with a valid endpoint |
| 57 | + */ |
| 58 | + @Test |
| 59 | + public void testForCustomEndpoint() { |
| 60 | + testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCustomEndpointClient, TEST_PINPOINT_APP_ID, DUMMY_CUSTOM_ENDPOINT); |
| 61 | + verify(mockCustomEndpointClient).setEndpoint(DUMMY_CUSTOM_ENDPOINT); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * Test that end point is not set for the {@link AmazonCognitoIdentityProviderClient } |
| 66 | + * when {@link CognitoUserPool#CognitoUserPool(Context, String, String, String, AmazonCognitoIdentityProvider, String, String)} is called |
| 67 | + * with a null endpoint |
| 68 | + */ |
| 69 | + @Test |
| 70 | + public void testForCustomEndpointWhenNull() { |
| 71 | + testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCustomEndpointClient, TEST_PINPOINT_APP_ID, null); |
| 72 | + verifyZeroInteractions(mockCustomEndpointClient); |
| 73 | + } |
| 74 | + |
| 75 | + /** |
| 76 | + * Test that end point is not set for the {@link AmazonCognitoIdentityProviderClient } |
| 77 | + * when {@link CognitoUserPool#CognitoUserPool(Context, String, String, String, AmazonCognitoIdentityProvider, String, String)} is called |
| 78 | + * with an empty endpoint |
| 79 | + */ |
| 80 | + @Test |
| 81 | + public void testForCustomEndpointWhenEmpty() { |
| 82 | + testPool = new CognitoUserPool(appContext, TEST_USER_POOL, TEST_CLIENT_ID, TEST_CLIENT_SECRET, mockCustomEndpointClient, TEST_PINPOINT_APP_ID, ""); |
| 83 | + verifyZeroInteractions(mockCustomEndpointClient); |
| 84 | + } |
| 85 | + |
| 86 | + |
| 87 | +} |
0 commit comments