Skip to content

Commit 966c33b

Browse files
committed
fix test
1 parent f7aa456 commit 966c33b

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2022 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+
package com.amplifyframework.auth.cognito
17+
18+
import androidx.test.ext.junit.runners.AndroidJUnit4
19+
import androidx.test.platform.app.InstrumentationRegistry
20+
import com.amplifyframework.auth.cognito.data.AWSCognitoAuthCredentialStore
21+
import com.amplifyframework.auth.cognito.testutils.AuthConfigurationProvider
22+
import com.amplifyframework.auth.cognito.testutils.CredentialStoreUtil
23+
import com.google.gson.Gson
24+
import junit.framework.TestCase.assertEquals
25+
import org.json.JSONObject
26+
import org.junit.Before
27+
import org.junit.Test
28+
import org.junit.runner.RunWith
29+
30+
@RunWith(AndroidJUnit4::class)
31+
class CredentialStoreStateMachineInstrumentationTest {
32+
private val context = InstrumentationRegistry.getInstrumentation().context
33+
34+
private val configuration = AuthConfigurationProvider.getAuthConfigurationObject()
35+
private val userPoolId = configuration.userPool.userPool.PoolId
36+
private val identityPoolId = configuration.credentials.cognitoIdentity.identityData.PoolId
37+
private val userPoolAppClientId = configuration.userPool.userPool.AppClientId
38+
39+
private val credential = CredentialStoreUtil.getDefaultCredential()
40+
41+
@Before
42+
fun setup() {
43+
CredentialStoreUtil.setupLegacyStore(context, userPoolAppClientId, userPoolId, identityPoolId)
44+
}
45+
46+
private val authConfigJson = JSONObject(Gson().toJson(configuration))
47+
48+
@Test
49+
fun test_CredentialStore_Migration_Succeeds_On_Plugin_Configuration() {
50+
val plugin = AWSCognitoAuthPlugin()
51+
plugin.configure(authConfigJson, context)
52+
plugin.initialize(context)
53+
54+
val receivedCredentials = AWSCognitoAuthCredentialStore(
55+
context,
56+
AuthConfiguration.fromJson(authConfigJson)
57+
).retrieveCredential()
58+
59+
assertEquals(credential, receivedCredentials)
60+
}
61+
}

0 commit comments

Comments
 (0)