-
Notifications
You must be signed in to change notification settings - Fork 127
fix(data): Fix GroupQueryPredicate Serialization for LastSyncMetadata stored syncExpression #3124
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
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5f96c47
Fix QueryPredicateGroup serialization/deserialization
tylerjroach db7a18d
fix serialization
tylerjroach 0f33ef4
pragma_table_info doesn't exist on all versions of sqlite. Use the mo…
tylerjroach 5be7eb4
clear out bad sync expressions
tylerjroach 9304e71
add tests
tylerjroach befc045
lint
tylerjroach e7e83cc
Merge branch 'main' into tjroach/fix-predicate-serialization
tylerjroach 9dc4d7a
lint
tylerjroach af43a64
checkstyle
tylerjroach 0e38cb5
change visibility
tylerjroach 579a587
Merge branch 'main' into tjroach/fix-predicate-serialization
tylerjroach 8631d3b
Rename .java to .kt
tylerjroach 0374b7a
kotlin conversions
tylerjroach a45ddb4
pr comments
tylerjroach 73bd2cb
pr comments
tylerjroach c64bcd5
lint
tylerjroach c7c9ee9
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
106 changes: 106 additions & 0 deletions
106
...c/test/java/com/amplifyframework/core/model/query/predicate/GsonPredicateAdaptersTests.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,106 @@ | ||
| /* | ||
| * 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.amplifyframework.core.model.query.predicate | ||
|
|
||
| import com.amplifyframework.testmodels.todo.Todo | ||
| import com.google.gson.Gson | ||
| import io.kotest.matchers.shouldBe | ||
| import org.junit.Test | ||
|
|
||
| class GsonPredicateAdaptersTests { | ||
|
|
||
| private val gson = Gson().newBuilder().apply { | ||
| GsonPredicateAdapters.register(this) | ||
| }.create() | ||
|
|
||
| @Test | ||
| fun `serialize and deserialize single predicate`() { | ||
| val queryPredicate = Todo.ID.eq("123") | ||
| val queryPredicateString = gson.toJson(queryPredicate) | ||
| val expectedString = """ | ||
| {"field":"id","operator":{"value":"123","type":"EQUAL"},"_type":"OPERATION"} | ||
| """.replace("\\s".toRegex(), "") | ||
| queryPredicateString shouldBe expectedString | ||
| val deserializedPredicate = gson.fromJson(queryPredicateString, QueryPredicate::class.java) | ||
| deserializedPredicate shouldBe queryPredicate | ||
| } | ||
|
|
||
| @Test | ||
| fun `serialize and deserialize group predicate`() { | ||
| val queryPredicate = Todo.TITLE.eq("Title").and(Todo.ID.eq("123")) | ||
| val queryPredicateString = gson.toJson(queryPredicate) | ||
| val expectedString = """ | ||
| { | ||
| "type":"AND", | ||
| "predicates":[ | ||
| {"field":"title","operator":{"value":"Title","type":"EQUAL"},"_type":"OPERATION"}, | ||
| {"field":"id","operator":{"value":"123","type":"EQUAL"},"_type":"OPERATION"} | ||
| ], | ||
| "_type":"GROUP" | ||
| } | ||
| """.replace("\\s".toRegex(), "") | ||
| queryPredicateString shouldBe expectedString | ||
| val deserializedPredicate = gson.fromJson(queryPredicateString, QueryPredicate::class.java) | ||
| deserializedPredicate shouldBe queryPredicate | ||
| } | ||
|
|
||
| @Test | ||
| fun `serialize and deserialize nested group predicates`() { | ||
| val queryPredicate = Todo.TITLE.eq("Title") | ||
| .and(Todo.ID.eq("123").or(Todo.ID.eq("456"))) | ||
| val queryPredicateString = gson.toJson(queryPredicate) | ||
| val expectedString = """ | ||
| { | ||
| "type": "AND", | ||
| "predicates": [ | ||
| { | ||
| "field": "title", | ||
| "operator": { | ||
| "value": "Title", | ||
| "type": "EQUAL" | ||
| }, | ||
| "_type": "OPERATION" | ||
| }, | ||
| { | ||
| "type": "OR", | ||
| "predicates": [ | ||
| { | ||
| "field": "id", | ||
| "operator": { | ||
| "value": "123", | ||
| "type": "EQUAL" | ||
| }, | ||
| "_type": "OPERATION" | ||
| }, | ||
| { | ||
| "field": "id", | ||
| "operator": { | ||
| "value": "456", | ||
| "type": "EQUAL" | ||
| }, | ||
| "_type": "OPERATION" | ||
| } | ||
| ], | ||
| "_type": "GROUP" | ||
| } | ||
| ], | ||
| "_type": "GROUP" | ||
| } | ||
| """.replace("\\s".toRegex(), "") | ||
| queryPredicateString shouldBe expectedString | ||
| val deserializedPredicate = gson.fromJson(queryPredicateString, QueryPredicate::class.java) | ||
| deserializedPredicate shouldBe queryPredicate | ||
| } | ||
| } |
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
82 changes: 82 additions & 0 deletions
82
...Test/java/com/amplifyframework/datastore/storage/sqlite/SQLiteStorageAdapterCreateTest.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,82 @@ | ||
| /* | ||
| * 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.amplifyframework.datastore.storage.sqlite | ||
|
|
||
| import android.content.Context | ||
| import android.database.sqlite.SQLiteDatabase | ||
| import androidx.test.core.app.ApplicationProvider | ||
| import com.amplifyframework.datastore.storage.SynchronousStorageAdapter | ||
| import com.amplifyframework.datastore.syncengine.MigrationFlagsTable | ||
| import com.amplifyframework.testmodels.commentsblog.AmplifyModelProvider | ||
| import io.kotest.assertions.withClue | ||
| import io.kotest.matchers.ints.shouldBePositive | ||
| import org.junit.After | ||
| import org.junit.Before | ||
| import org.junit.Test | ||
|
|
||
| /** | ||
| * Test the creation functionality of [SQLiteStorageAdapter] operations. | ||
| */ | ||
| class SQLiteStorageAdapterCreateTest { | ||
| private lateinit var adapter: SynchronousStorageAdapter | ||
|
|
||
| /** | ||
| * Remove any old database files, and then re-provision a new storage adapter, | ||
| * that is able to store the Comment-Blog family of models. | ||
| */ | ||
| @Before | ||
| fun setup() { | ||
| TestStorageAdapter.cleanup() | ||
| this.adapter = TestStorageAdapter.create(AmplifyModelProvider.getInstance()) | ||
| } | ||
|
|
||
| /** | ||
| * Close the open database, and cleanup any database files that it left. | ||
| */ | ||
| @After | ||
| fun teardown() { | ||
| TestStorageAdapter.cleanup(adapter) | ||
| } | ||
|
|
||
| /** | ||
| * Test that initial creation creates migration flags table with initial entries. | ||
| */ | ||
| @Test | ||
| fun verifyMigrationFlagsTableExistsAndContainsRecordsOnCreate() { | ||
| // Verify migration flags table exists and has initial entries | ||
| val dbPath = ApplicationProvider.getApplicationContext<Context>() | ||
| .getDatabasePath(SQLiteStorageAdapter.DEFAULT_DATABASE_NAME).absolutePath | ||
| val database = SQLiteDatabase.openDatabase( | ||
| dbPath, | ||
| null, | ||
| SQLiteDatabase.OPEN_READONLY | ||
| ) | ||
| try { | ||
| database.rawQuery( | ||
| "SELECT 1 FROM " + MigrationFlagsTable.TABLE_NAME + | ||
| " WHERE " + MigrationFlagsTable.COLUMN_FLAG_NAME + " = ?", | ||
| arrayOf( | ||
| MigrationFlagsTable.CLEARED_V2_30_0_AND_BELOW_GROUP_SYNC_EXPRESSIONS | ||
| ) | ||
| ).use { cursor -> | ||
| withClue("Migration flag row was not created") { | ||
| cursor.count.shouldBePositive() | ||
| } | ||
| } | ||
| } finally { | ||
| database.close() | ||
| } | ||
| } | ||
| } |
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.