-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
899f19f
commit 4e446a6
Showing
10 changed files
with
224 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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 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 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
10 changes: 10 additions & 0 deletions
10
tempest2/src/main/kotlin/app/cash/tempest2/TableNameResolver.kt
This file contains 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,10 @@ | ||
package app.cash.tempest2 | ||
|
||
/** | ||
* Resolves the table name for a given [LogicalTable] class. | ||
* | ||
* This allows table names to be overridden at runtime. | ||
*/ | ||
interface TableNameResolver { | ||
fun resolveTableName(clazz: Class<*>, tableNameFromAnnotation: String?): String | ||
} |
This file contains 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 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 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
64 changes: 64 additions & 0 deletions
64
tempest2/src/test/kotlin/app/cash/tempest2/DynamoDbAsyncTableNameResolverTest.kt
This file contains 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,64 @@ | ||
/* | ||
* Copyright 2021 Square Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License 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 app.cash.tempest2 | ||
|
||
import app.cash.tempest2.musiclibrary.AlbumInfo | ||
import app.cash.tempest2.musiclibrary.AsyncMusicDb | ||
import app.cash.tempest2.musiclibrary.AsyncMusicTable | ||
import app.cash.tempest2.musiclibrary.testDb | ||
import app.cash.tempest2.testing.asyncLogicalDb | ||
import java.time.LocalDate | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.RegisterExtension | ||
|
||
class DynamoDbAsyncTableNameResolverTest { | ||
|
||
@RegisterExtension | ||
@JvmField | ||
val db = testDb("custom_table_name") | ||
|
||
private object TestTableNameResolver : TableNameResolver { | ||
override fun resolveTableName(clazz: Class<*>, tableNameFromAnnotation: String?): String { | ||
check(clazz == AsyncMusicTable::class.java) | ||
|
||
return "custom_table_name" | ||
} | ||
} | ||
|
||
private val musicTable = db.asyncLogicalDb<AsyncMusicDb>(extensions = listOf(), TestTableNameResolver).music | ||
|
||
@Test | ||
fun loadAfterSave() = runBlockingTest { | ||
val albumInfo = AlbumInfo( | ||
"ALBUM_1", | ||
"after hours - EP", | ||
"53 Thieves", | ||
LocalDate.of(2020, 2, 21), | ||
"Contemporary R&B" | ||
) | ||
musicTable.albumInfo.save(albumInfo) | ||
|
||
// Query the movies created. | ||
val loadedAlbumInfo = musicTable.albumInfo.load(albumInfo.key)!! | ||
|
||
assertThat(loadedAlbumInfo.album_token).isEqualTo(albumInfo.album_token) | ||
assertThat(loadedAlbumInfo.artist_name).isEqualTo(albumInfo.artist_name) | ||
assertThat(loadedAlbumInfo.release_date).isEqualTo(albumInfo.release_date) | ||
assertThat(loadedAlbumInfo.genre_name).isEqualTo(albumInfo.genre_name) | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
tempest2/src/test/kotlin/app/cash/tempest2/DynamoDbTableNameResolverTest.kt
This file contains 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,64 @@ | ||
/* | ||
* Copyright 2021 Square Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License 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 app.cash.tempest2 | ||
|
||
import app.cash.tempest2.musiclibrary.AlbumInfo | ||
import app.cash.tempest2.musiclibrary.MusicDb | ||
import app.cash.tempest2.musiclibrary.MusicTable | ||
import app.cash.tempest2.musiclibrary.testDb | ||
import app.cash.tempest2.testing.logicalDb | ||
import java.time.LocalDate | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.RegisterExtension | ||
|
||
class DynamoDbTableNameResolverTest { | ||
|
||
@RegisterExtension | ||
@JvmField | ||
val db = testDb("custom_table_name") | ||
|
||
private object TestTableNameResolver : TableNameResolver { | ||
override fun resolveTableName(clazz: Class<*>, tableNameFromAnnotation: String?): String { | ||
check(clazz == MusicTable::class.java) | ||
|
||
return "custom_table_name" | ||
} | ||
} | ||
|
||
private val musicTable by lazy { db.logicalDb<MusicDb>(extensions = listOf(), TestTableNameResolver).music } | ||
|
||
@Test | ||
fun loadAfterSave() { | ||
val albumInfo = AlbumInfo( | ||
"ALBUM_1", | ||
"after hours - EP", | ||
"53 Thieves", | ||
LocalDate.of(2020, 2, 21), | ||
"Contemporary R&B" | ||
) | ||
musicTable.albumInfo.save(albumInfo) | ||
|
||
// Query the movies created. | ||
val loadedAlbumInfo = musicTable.albumInfo.load(albumInfo.key)!! | ||
|
||
assertThat(loadedAlbumInfo.album_token).isEqualTo(albumInfo.album_token) | ||
assertThat(loadedAlbumInfo.artist_name).isEqualTo(albumInfo.artist_name) | ||
assertThat(loadedAlbumInfo.release_date).isEqualTo(albumInfo.release_date) | ||
assertThat(loadedAlbumInfo.genre_name).isEqualTo(albumInfo.genre_name) | ||
} | ||
} |
Oops, something went wrong.