-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FIX: KotlinDataClassComponent.getType() returned invalid raw type
- Loading branch information
1 parent
51c3007
commit d6dd53e
Showing
6 changed files
with
148 additions
and
2 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
15 changes: 15 additions & 0 deletions
15
repository/src/test/java/tech/ydb/yoj/repository/hybrid/ChangeMetadata.java
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,15 @@ | ||
package tech.ydb.yoj.repository.hybrid; | ||
|
||
import java.time.Instant; | ||
|
||
public record ChangeMetadata( | ||
ChangeKind kind, | ||
Instant time, | ||
long version | ||
) { | ||
enum ChangeKind { | ||
CREATE, | ||
UPDATE, | ||
DELETE, | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
repository/src/test/java/tech/ydb/yoj/repository/hybrid/Chronology.java
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,9 @@ | ||
package tech.ydb.yoj.repository.hybrid; | ||
|
||
import java.time.Instant; | ||
|
||
public record Chronology( | ||
Instant createdAt, | ||
Instant updatedAt | ||
) { | ||
} |
28 changes: 28 additions & 0 deletions
28
repository/src/test/kotlin/tech/ydb/yoj/repository/hybrid/Account.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,28 @@ | ||
package tech.ydb.yoj.repository.hybrid | ||
|
||
import tech.ydb.yoj.repository.db.Entity | ||
|
||
data class Account( | ||
private val id: Id, | ||
private val version: Long, | ||
private val chronology: Chronology, | ||
val login: String, | ||
val description: String? = null, | ||
) : Entity<Account> { | ||
override fun getId() = id | ||
|
||
data class Id(val value: String) : Entity.Id<Account> | ||
|
||
data class Snapshot( | ||
private val id: Id, | ||
private val entity: Account?, | ||
val meta: ChangeMetadata, | ||
) : Entity<Snapshot> { | ||
override fun getId() = id | ||
|
||
data class Id( | ||
private val id: Account.Id, | ||
private val version: Long | ||
) : Entity.Id<Snapshot> | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
repository/src/test/kotlin/tech/ydb/yoj/repository/hybrid/HybridSchemaTest.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,45 @@ | ||
package tech.ydb.yoj.repository.hybrid | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Test | ||
import tech.ydb.yoj.repository.db.EntitySchema | ||
import java.time.Instant | ||
|
||
/** | ||
* Test for Schema using both Kotlin data classes and JVM records. | ||
*/ | ||
class HybridSchemaTest { | ||
@Test | ||
fun testIdFlattening() { | ||
val now = Instant.now() | ||
val account = Account( | ||
id = Account.Id("hahaha"), | ||
version = 1L, | ||
chronology = Chronology(now, now), | ||
login = "logIn", | ||
description = null | ||
) | ||
val accountSnapshot = Account.Snapshot( | ||
id = Account.Snapshot.Id(account.id, 1L), | ||
entity = account, | ||
meta = ChangeMetadata(ChangeMetadata.ChangeKind.CREATE, now, 1L) | ||
) | ||
|
||
val schema = EntitySchema.of(Account.Snapshot::class.java) | ||
|
||
val flattened = schema.flatten(accountSnapshot) | ||
assertThat(flattened).isEqualTo(mapOf( | ||
"id_id" to "hahaha", | ||
"id_version" to 1L, | ||
"entity_id" to "hahaha", | ||
"entity_version" to 1L, | ||
"entity_chronology_createdAt" to now, | ||
"entity_chronology_updatedAt" to now, | ||
"entity_login" to "logIn", | ||
"meta_kind" to ChangeMetadata.ChangeKind.CREATE, | ||
"meta_time" to now, | ||
"meta_version" to 1L | ||
)) | ||
assertThat(schema.newInstance(flattened)).isEqualTo(accountSnapshot) | ||
} | ||
} |