@@ -24,10 +24,13 @@ import com.google.firebase.vertexai.common.shared.Content
24
24
import com.google.firebase.vertexai.common.shared.TextPart
25
25
import com.google.firebase.vertexai.common.util.doBlocking
26
26
import com.google.firebase.vertexai.type.RequestOptions
27
+ import com.google.firebase.vertexai.type.ServerException
27
28
import com.google.firebase.vertexai.type.content
28
29
import io.kotest.assertions.json.shouldContainJsonKey
29
30
import io.kotest.assertions.json.shouldContainJsonKeyValue
31
+ import io.kotest.assertions.throwables.shouldThrow
30
32
import io.kotest.matchers.collections.shouldNotBeEmpty
33
+ import io.kotest.matchers.string.shouldContain
31
34
import io.kotest.matchers.types.shouldBeInstanceOf
32
35
import io.ktor.client.engine.mock.MockEngine
33
36
import io.ktor.client.engine.mock.respond
@@ -44,7 +47,7 @@ internal class GenerativeModelTesting {
44
47
private val TEST_CLIENT_ID = " test"
45
48
46
49
@Test
47
- fun addition () = doBlocking {
50
+ fun `system calling in request` () = doBlocking {
48
51
val mockEngine = MockEngine {
49
52
respond(
50
53
generateContentResponseAsJsonString(" text response" ),
@@ -84,6 +87,46 @@ internal class GenerativeModelTesting {
84
87
}
85
88
}
86
89
90
+ @Test
91
+ fun `exception thrown when using invalid location` () = doBlocking {
92
+ val mockEngine = MockEngine {
93
+ respond(
94
+ """ <!DOCTYPE html>
95
+ <html lang=en>
96
+ <title>Error 404 (Not Found)!!1</title>
97
+ """
98
+ .trimIndent(),
99
+ HttpStatusCode .NotFound ,
100
+ headersOf(HttpHeaders .ContentType , " text/html; charset=utf-8" )
101
+ )
102
+ }
103
+
104
+ val apiController =
105
+ APIController (
106
+ " super_cool_test_key" ,
107
+ " gemini-1.5-flash" ,
108
+ RequestOptions (),
109
+ mockEngine,
110
+ TEST_CLIENT_ID ,
111
+ null ,
112
+ )
113
+
114
+ // Creating the
115
+ val generativeModel =
116
+ GenerativeModel (
117
+ " projects/PROJECTID/locations/INVALID_LOCATION/publishers/google/models/gemini-1.5-flash" ,
118
+ controller = apiController
119
+ )
120
+
121
+ val exception =
122
+ shouldThrow<ServerException > {
123
+ withTimeout(5 .seconds) { generativeModel.generateContent(" my test prompt" ) }
124
+ }
125
+
126
+ // Let's not be too strict on the wording to avoid breaking the test unnecessarily.
127
+ exception.message shouldContain " location"
128
+ }
129
+
87
130
private fun generateContentResponseAsJsonString (text : String ): String {
88
131
return JSON .encodeToString(
89
132
GenerateContentResponse (listOf (Candidate (Content (parts = listOf (TextPart (text))))))
0 commit comments