-
Notifications
You must be signed in to change notification settings - Fork 127
feat(data) AppSync Events WebSocket Unit Tests + Integration Tests #3048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
tylerjroach
merged 13 commits into
feat/appsync-events
from
tjroach/appsync-events-tests2
May 9, 2025
Merged
Changes from 8 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6f2b4f2
websocket unit tests
tylerjroach 87de0f4
Make websocket tests deterministic
mattcreaser 6dfbfb5
appsync events rest integration tests
tylerjroach 941a904
appsync events websocket integration tests
tylerjroach 9d1cb59
Merge branch 'tjroach/appsync-events-integration-tests' into tjroach/…
tylerjroach 4fb0da7
lint
tylerjroach 1187945
fix compile issue
tylerjroach 80b74b9
fix test hanging issue
tylerjroach 60afc87
fix custom channel
tylerjroach e75a888
fix test
tylerjroach b75211f
lint
tylerjroach 5024de4
Pr comments and gen2 backend files
tylerjroach 84bd0ff
lint
tylerjroach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
appsync/aws-sdk-appsync-events/src/androidTest/AndroidManifest.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| package="com.amazonaws.sdk.appsync.events.test"> | ||
|
|
||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
| </manifest> |
70 changes: 70 additions & 0 deletions
70
.../src/androidTest/java/com/amazonaws/sdk/appsync/events/EventsRestClientAmplifyIamTests.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
| package com.amazonaws.sdk.appsync.events | ||
|
|
||
| import androidx.test.core.app.ApplicationProvider | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import com.amazonaws.sdk.appsync.amplify.authorizers.AmplifyIamAuthorizer | ||
| import com.amazonaws.sdk.appsync.events.data.PublishResult | ||
| import com.amazonaws.sdk.appsync.events.test.R | ||
| import com.amazonaws.sdk.appsync.events.utils.getEventsConfig | ||
| import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin | ||
| import com.amplifyframework.core.Amplify | ||
| import com.amplifyframework.core.configuration.AmplifyOutputs | ||
| import io.kotest.matchers.shouldBe | ||
| import java.util.UUID | ||
| import kotlinx.coroutines.test.runTest | ||
| import kotlinx.serialization.json.JsonPrimitive | ||
| import org.junit.BeforeClass | ||
| import org.junit.Test | ||
|
|
||
| internal class EventsRestClientAmplifyIamTests { | ||
| private val eventsConfig = getEventsConfig(InstrumentationRegistry.getInstrumentation().targetContext) | ||
| private val iamAuthorizer = AmplifyIamAuthorizer(eventsConfig.awsRegion) | ||
| private val defaultChannel = "default/${UUID.randomUUID()}" | ||
| private val events = Events(eventsConfig.url) | ||
|
|
||
| companion object { | ||
| @BeforeClass | ||
| @JvmStatic | ||
| fun setup() { | ||
| Amplify.addPlugin(AWSCognitoAuthPlugin()) | ||
| Amplify.configure( | ||
| AmplifyOutputs.fromResource(R.raw.amplify_outputs), | ||
| ApplicationProvider.getApplicationContext() | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun testPublishWithIam(): Unit = runTest { | ||
mattcreaser marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Publish the REST message | ||
| val restClient = events.createRestClient(publishAuthorizer = iamAuthorizer) | ||
| val result = restClient.publish( | ||
| channelName = defaultChannel, | ||
| event = JsonPrimitive(true) | ||
| ) | ||
|
|
||
| // Assert expected REST response | ||
| (result is PublishResult.Response) shouldBe true | ||
| (result as PublishResult.Response).apply { | ||
| failedEvents.size shouldBe 0 | ||
| successfulEvents.size shouldBe 1 | ||
| successfulEvents[0].apply { | ||
| index shouldBe 0 | ||
| } | ||
mattcreaser marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } | ||
102 changes: 102 additions & 0 deletions
102
...androidTest/java/com/amazonaws/sdk/appsync/events/EventsRestClientAmplifyUserPoolTests.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| /* | ||
| * Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
| package com.amazonaws.sdk.appsync.events | ||
|
|
||
| import androidx.test.core.app.ApplicationProvider | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import com.amazonaws.sdk.appsync.amplify.authorizers.AmplifyUserPoolAuthorizer | ||
| import com.amazonaws.sdk.appsync.events.data.EventsException | ||
| import com.amazonaws.sdk.appsync.events.data.PublishResult | ||
| import com.amazonaws.sdk.appsync.events.test.R | ||
| import com.amazonaws.sdk.appsync.events.utils.Credentials | ||
| import com.amazonaws.sdk.appsync.events.utils.getEventsConfig | ||
| import com.amplifyframework.auth.AuthException | ||
| import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin | ||
| import com.amplifyframework.core.configuration.AmplifyOutputs | ||
| import com.amplifyframework.kotlin.core.Amplify | ||
| import io.kotest.matchers.shouldBe | ||
| import java.util.UUID | ||
| import kotlinx.coroutines.runBlocking | ||
| import kotlinx.coroutines.test.runTest | ||
| import kotlinx.serialization.json.JsonPrimitive | ||
| import org.junit.After | ||
| import org.junit.BeforeClass | ||
| import org.junit.Test | ||
|
|
||
| internal class EventsRestClientAmplifyUserPoolTests { | ||
| private val eventsConfig = getEventsConfig(InstrumentationRegistry.getInstrumentation().targetContext) | ||
| private val userPoolAuthorizer = AmplifyUserPoolAuthorizer() | ||
| private val defaultChannel = "default/${UUID.randomUUID()}" | ||
| private val events = Events(eventsConfig.url) | ||
|
|
||
| companion object { | ||
| @BeforeClass | ||
| @JvmStatic | ||
| fun setup() { | ||
| Amplify.addPlugin(AWSCognitoAuthPlugin()) | ||
| Amplify.configure( | ||
| AmplifyOutputs.fromResource(R.raw.amplify_outputs), | ||
| ApplicationProvider.getApplicationContext() | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @After | ||
| fun tearDown() { | ||
| runBlocking { Amplify.Auth.signOut() } | ||
| } | ||
|
|
||
| @Test | ||
| fun testFailedPublishWithUnauthenticatedUserPool(): Unit = runTest { | ||
| // Publish the REST message | ||
| val restClient = events.createRestClient(publishAuthorizer = userPoolAuthorizer) | ||
| val result = restClient.publish( | ||
| channelName = defaultChannel, | ||
| event = JsonPrimitive(true) | ||
| ) | ||
|
|
||
| // Assert expected REST response | ||
| (result is PublishResult.Failure) shouldBe true | ||
| (result as PublishResult.Failure).apply { | ||
| error shouldBe EventsException( | ||
| "An unknown error occurred", | ||
| cause = AuthException("Token is null", "Token received but is null. Check if you are signed in") | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun testPublishWithAuthenticatedUserPool(): Unit = runTest { | ||
| val credentials = Credentials.load(InstrumentationRegistry.getInstrumentation().targetContext) | ||
| Amplify.Auth.signIn(credentials.first, credentials.second) | ||
|
|
||
| // Publish the REST message | ||
| val restClient = events.createRestClient(publishAuthorizer = userPoolAuthorizer) | ||
| val result = restClient.publish( | ||
| channelName = defaultChannel, | ||
| event = JsonPrimitive(true) | ||
| ) | ||
|
|
||
| // Assert expected REST response | ||
| (result is PublishResult.Response) shouldBe true | ||
| (result as PublishResult.Response).apply { | ||
| failedEvents.size shouldBe 0 | ||
| successfulEvents.size shouldBe 1 | ||
| successfulEvents[0].apply { | ||
| index shouldBe 0 | ||
| } | ||
| } | ||
| } | ||
| } |
70 changes: 70 additions & 0 deletions
70
...ents/src/androidTest/java/com/amazonaws/sdk/appsync/events/EventsRestClientApiKeyTests.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
| package com.amazonaws.sdk.appsync.events | ||
|
|
||
| import androidx.test.core.app.ApplicationProvider | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import com.amazonaws.sdk.appsync.core.authorizers.ApiKeyAuthorizer | ||
| import com.amazonaws.sdk.appsync.events.data.PublishResult | ||
| import com.amazonaws.sdk.appsync.events.test.R | ||
| import com.amazonaws.sdk.appsync.events.utils.getEventsConfig | ||
| import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin | ||
| import com.amplifyframework.core.Amplify | ||
| import com.amplifyframework.core.configuration.AmplifyOutputs | ||
| import io.kotest.matchers.shouldBe | ||
| import java.util.UUID | ||
| import kotlinx.coroutines.test.runTest | ||
| import kotlinx.serialization.json.JsonPrimitive | ||
| import org.junit.BeforeClass | ||
| import org.junit.Test | ||
|
|
||
| internal class EventsRestClientApiKeyTests { | ||
| private val eventsConfig = getEventsConfig(InstrumentationRegistry.getInstrumentation().targetContext) | ||
| private val apiKeyAuthorizer = ApiKeyAuthorizer(eventsConfig.apiKey) | ||
| private val defaultChannel = "default/${UUID.randomUUID()}" | ||
| private val events = Events(eventsConfig.url) | ||
|
|
||
| companion object { | ||
| @BeforeClass | ||
| @JvmStatic | ||
| fun setup() { | ||
| Amplify.addPlugin(AWSCognitoAuthPlugin()) | ||
| Amplify.configure( | ||
| AmplifyOutputs.fromResource(R.raw.amplify_outputs), | ||
| ApplicationProvider.getApplicationContext() | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| fun testPublishWithApiKey(): Unit = runTest { | ||
| // Publish the REST message | ||
| val restClient = events.createRestClient(publishAuthorizer = apiKeyAuthorizer) | ||
| val result = restClient.publish( | ||
| channelName = defaultChannel, | ||
| event = JsonPrimitive(true) | ||
| ) | ||
|
|
||
| // Assert expected REST response | ||
| (result is PublishResult.Response) shouldBe true | ||
| (result as PublishResult.Response).apply { | ||
| failedEvents.size shouldBe 0 | ||
| successfulEvents.size shouldBe 1 | ||
| successfulEvents[0].apply { | ||
| index shouldBe 0 | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.