Skip to content

Commit aa8949c

Browse files
author
David Motsonashvili
committed
add serialization tests
1 parent d8ec7cc commit aa8949c

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

firebase-ai/src/test/java/com/google/firebase/ai/SerializationTests.kt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.google.firebase.ai
1818

19+
import com.google.firebase.ai.common.TemplateGenerateContentRequest
20+
import com.google.firebase.ai.common.TemplateGenerateImageRequest
1921
import com.google.firebase.ai.common.util.descriptorToJson
2022
import com.google.firebase.ai.type.Candidate
2123
import com.google.firebase.ai.type.CountTokensResponse
@@ -512,6 +514,56 @@ internal class SerializationTests {
512514
expectedJsonAsString shouldEqualJson actualJson.toString()
513515
}
514516

517+
@Test
518+
fun `test template request serialization as Json`() {
519+
val expectedJsonAsString =
520+
"""
521+
{
522+
"id": "TemplateGenerateContentRequest",
523+
"type": "object",
524+
"properties": {
525+
"inputs": {
526+
"type": "object",
527+
"additionalProperties": {
528+
"${"$"}ref": "JsonElement"
529+
}
530+
},
531+
"history": {
532+
"type": "array",
533+
"items": {
534+
"${"$"}ref": "Content"
535+
}
536+
}
537+
}
538+
}
539+
"""
540+
.trimIndent()
541+
val actualJson = descriptorToJson(TemplateGenerateContentRequest.serializer().descriptor)
542+
expectedJsonAsString shouldEqualJson actualJson.toString()
543+
}
544+
545+
@Test
546+
fun `test template imagen request serialization as Json`() {
547+
val expectedJsonAsString =
548+
"""
549+
{
550+
"id": "TemplateGenerateImageRequest",
551+
"type": "object",
552+
"properties": {
553+
"inputs": {
554+
"type": "object",
555+
"additionalProperties": {
556+
"${"$"}ref": "JsonElement"
557+
}
558+
}
559+
}
560+
}
561+
"""
562+
.trimIndent()
563+
val actualJson = descriptorToJson(TemplateGenerateImageRequest.serializer().descriptor)
564+
expectedJsonAsString shouldEqualJson actualJson.toString()
565+
}
566+
515567
@Test
516568
fun `test GoogleSearch serialization as Json`() {
517569
val expectedJsonAsString =

0 commit comments

Comments
 (0)