-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from SchwarzIT/feature/add-kdoc-comments
Add KDoc comments and ensure deterministic field order
- Loading branch information
Showing
9 changed files
with
101 additions
and
20 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
package kaufland.com.demo.entity | ||
|
||
import com.couchbase.lite.Blob | ||
import kaufland.com.coachbasebinderapi.Comment | ||
import kaufland.com.coachbasebinderapi.Entity | ||
import kaufland.com.coachbasebinderapi.Field | ||
import kaufland.com.coachbasebinderapi.Fields | ||
import kaufland.com.coachbasebinderapi.* | ||
import kaufland.com.coachbasebinderapi.query.Queries | ||
import kaufland.com.coachbasebinderapi.query.Query | ||
|
||
@Entity(database = "mydb_db") | ||
@MapWrapper | ||
@Comment(["Hey, I just met you and this is crazy", "But here's my documentation, so read it maybe"]) | ||
@Fields( | ||
Field(name = "type", type = String::class, defaultValue = "product", readonly = true), | ||
Field(name = "name", type = String::class, comment = ["contains the product name", "and other infos"]), | ||
Field(name = "type", type = String::class, defaultValue = "product", readonly = true, comment = ["Document type"]), | ||
Field(name = "name", type = String::class, comment = ["contains the product name.", "and other infos"]), | ||
Field(name = "comments", type = UserComment::class, list = true), | ||
Field(name = "image", type = Blob::class), | ||
Field(name = "identifiers", type = String::class, list = true) | ||
) | ||
@Queries( | ||
Query(fields = ["type"]) | ||
) | ||
open class Product | ||
open class Product |
53 changes: 53 additions & 0 deletions
53
demo/src/test/java/kaufland/com/demo/entity/ProductWrapperTest.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,53 @@ | ||
package kaufland.com.demo.entity | ||
|
||
import kaufland.com.coachbasebinderapi.PersistenceConfig | ||
import kaufland.com.coachbasebinderapi.TypeConversion | ||
import org.junit.Assert.* | ||
import org.junit.BeforeClass | ||
import org.junit.Test | ||
import kotlin.reflect.KClass | ||
|
||
class ProductWrapperTest { | ||
companion object { | ||
@BeforeClass | ||
@JvmStatic | ||
fun beforeClass() { | ||
PersistenceConfig.configure(object : PersistenceConfig.Connector { | ||
override val typeConversions: Map<KClass<*>, TypeConversion> = mapOf() | ||
|
||
override fun getDocument(id: String, dbName: String): Map<String, Any>? { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun queryDoc(dbName: String, queryParams: Map<String, Any>): List<Map<String, Any>> { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun deleteDocument(id: String, dbName: String) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun upsertDocument(document: MutableMap<String, Any>, id: String?, dbName: String) { | ||
TODO("Not yet implemented") | ||
} | ||
}) | ||
} | ||
} | ||
|
||
@Test | ||
fun `toMap should preserve field order`() { | ||
val product = ProductWrapper.create().builder() | ||
.setName("name") | ||
.setComments(emptyList()) | ||
.setIdentifiers(listOf("1", "2")) | ||
.exit() | ||
|
||
val map = product.toMap() | ||
map.remove(ProductWrapper.TYPE) | ||
assertEquals(mapOf( | ||
ProductWrapper.NAME to "name", | ||
ProductWrapper.COMMENTS to listOf<UserCommentWrapper>(), | ||
ProductWrapper.IDENTIFIERS to listOf("1", "2") | ||
), map) | ||
} | ||
} |