@@ -159,6 +159,122 @@ void testInvalidResponseErrorHandler() {
159159 .hasMessageContaining ("responseErrorHandler cannot be null" );
160160 }
161161
162+ @ Test
163+ void testBuilderWithAllCustomPaths () {
164+ OpenAiApi api = OpenAiApi .builder ()
165+ .apiKey (TEST_API_KEY )
166+ .baseUrl (TEST_BASE_URL )
167+ .completionsPath ("/custom/completions" )
168+ .embeddingsPath ("/custom/embeddings" )
169+ .build ();
170+
171+ assertThat (api ).isNotNull ();
172+ }
173+
174+ @ Test
175+ void testBuilderImmutability () {
176+ OpenAiApi .Builder builder = OpenAiApi .builder ().apiKey (TEST_API_KEY ).baseUrl (TEST_BASE_URL );
177+
178+ OpenAiApi api1 = builder .build ();
179+ OpenAiApi api2 = builder .build ();
180+
181+ assertThat (api1 ).isNotNull ();
182+ assertThat (api2 ).isNotNull ();
183+ assertThat (api1 ).isNotSameAs (api2 );
184+ }
185+
186+ @ Test
187+ void testNullApiKeyValue () {
188+ assertThatThrownBy (() -> OpenAiApi .builder ().apiKey ((ApiKey ) null ).build ())
189+ .isInstanceOf (IllegalArgumentException .class )
190+ .hasMessageContaining ("apiKey cannot be null" );
191+ }
192+
193+ @ Test
194+ void testBuilderMethodChaining () {
195+ MultiValueMap <String , String > headers = new LinkedMultiValueMap <>();
196+ headers .add ("Test-Header" , "test-value" );
197+
198+ OpenAiApi api = OpenAiApi .builder ()
199+ .apiKey (TEST_API_KEY )
200+ .baseUrl (TEST_BASE_URL )
201+ .completionsPath (TEST_COMPLETIONS_PATH )
202+ .embeddingsPath (TEST_EMBEDDINGS_PATH )
203+ .headers (headers )
204+ .restClientBuilder (RestClient .builder ())
205+ .webClientBuilder (WebClient .builder ())
206+ .responseErrorHandler (mock (ResponseErrorHandler .class ))
207+ .build ();
208+
209+ assertThat (api ).isNotNull ();
210+ }
211+
212+ @ Test
213+ void testCustomHeadersPreservation () {
214+ MultiValueMap <String , String > customHeaders = new LinkedMultiValueMap <>();
215+ customHeaders .add ("X-Custom-Header" , "custom-value" );
216+ customHeaders .add ("X-Organization" , "org-123" );
217+ customHeaders .add ("User-Agent" , "Custom-Client/1.0" );
218+
219+ OpenAiApi api = OpenAiApi .builder ().apiKey (TEST_API_KEY ).headers (customHeaders ).build ();
220+
221+ assertThat (api ).isNotNull ();
222+ }
223+
224+ @ Test
225+ void testComplexMultiValueHeaders () {
226+ MultiValueMap <String , String > multiHeaders = new LinkedMultiValueMap <>();
227+ multiHeaders .add ("Accept" , "application/json" );
228+ multiHeaders .add ("Accept" , "text/plain" );
229+ multiHeaders .add ("Cache-Control" , "no-cache" );
230+ multiHeaders .add ("Cache-Control" , "no-store" );
231+
232+ OpenAiApi api = OpenAiApi .builder ().apiKey (TEST_API_KEY ).headers (multiHeaders ).build ();
233+
234+ assertThat (api ).isNotNull ();
235+ }
236+
237+ @ Test
238+ void testPathValidationWithSlashes () {
239+ OpenAiApi api1 = OpenAiApi .builder ()
240+ .apiKey (TEST_API_KEY )
241+ .completionsPath ("/v1/completions" )
242+ .embeddingsPath ("/v1/embeddings" )
243+ .build ();
244+
245+ OpenAiApi api2 = OpenAiApi .builder ()
246+ .apiKey (TEST_API_KEY )
247+ .completionsPath ("v1/completions" )
248+ .embeddingsPath ("v1/embeddings" )
249+ .build ();
250+
251+ assertThat (api1 ).isNotNull ();
252+ assertThat (api2 ).isNotNull ();
253+ }
254+
255+ @ Test
256+ void testInvalidPathsWithSpecialCharacters () {
257+ assertThatThrownBy (() -> OpenAiApi .builder ().apiKey (TEST_API_KEY ).completionsPath (" " ).build ())
258+ .isInstanceOf (IllegalArgumentException .class );
259+ }
260+
261+ @ Test
262+ void testBuilderWithOnlyRequiredFields () {
263+ OpenAiApi api = OpenAiApi .builder ().apiKey (TEST_API_KEY ).build ();
264+
265+ assertThat (api ).isNotNull ();
266+ }
267+
268+ @ Test
269+ void testDifferentApiKeyTypes () {
270+ SimpleApiKey simpleKey = new SimpleApiKey ("simple-key" );
271+ OpenAiApi api1 = OpenAiApi .builder ().apiKey (simpleKey ).build ();
272+ assertThat (api1 ).isNotNull ();
273+
274+ OpenAiApi api2 = OpenAiApi .builder ().apiKey (() -> "supplier-key" ).build ();
275+ assertThat (api2 ).isNotNull ();
276+ }
277+
162278 @ Nested
163279 class MockRequests {
164280
@@ -425,120 +541,4 @@ void dynamicApiKeyRestClientEmbeddings() throws InterruptedException {
425541
426542 }
427543
428- @ Test
429- void testBuilderWithAllCustomPaths () {
430- OpenAiApi api = OpenAiApi .builder ()
431- .apiKey (TEST_API_KEY )
432- .baseUrl (TEST_BASE_URL )
433- .completionsPath ("/custom/completions" )
434- .embeddingsPath ("/custom/embeddings" )
435- .build ();
436-
437- assertThat (api ).isNotNull ();
438- }
439-
440- @ Test
441- void testBuilderImmutability () {
442- OpenAiApi .Builder builder = OpenAiApi .builder ().apiKey (TEST_API_KEY ).baseUrl (TEST_BASE_URL );
443-
444- OpenAiApi api1 = builder .build ();
445- OpenAiApi api2 = builder .build ();
446-
447- assertThat (api1 ).isNotNull ();
448- assertThat (api2 ).isNotNull ();
449- assertThat (api1 ).isNotSameAs (api2 );
450- }
451-
452- @ Test
453- void testNullApiKeyValue () {
454- assertThatThrownBy (() -> OpenAiApi .builder ().apiKey ((ApiKey ) null ).build ())
455- .isInstanceOf (IllegalArgumentException .class )
456- .hasMessageContaining ("apiKey cannot be null" );
457- }
458-
459- @ Test
460- void testBuilderMethodChaining () {
461- MultiValueMap <String , String > headers = new LinkedMultiValueMap <>();
462- headers .add ("Test-Header" , "test-value" );
463-
464- OpenAiApi api = OpenAiApi .builder ()
465- .apiKey (TEST_API_KEY )
466- .baseUrl (TEST_BASE_URL )
467- .completionsPath (TEST_COMPLETIONS_PATH )
468- .embeddingsPath (TEST_EMBEDDINGS_PATH )
469- .headers (headers )
470- .restClientBuilder (RestClient .builder ())
471- .webClientBuilder (WebClient .builder ())
472- .responseErrorHandler (mock (ResponseErrorHandler .class ))
473- .build ();
474-
475- assertThat (api ).isNotNull ();
476- }
477-
478- @ Test
479- void testCustomHeadersPreservation () {
480- MultiValueMap <String , String > customHeaders = new LinkedMultiValueMap <>();
481- customHeaders .add ("X-Custom-Header" , "custom-value" );
482- customHeaders .add ("X-Organization" , "org-123" );
483- customHeaders .add ("User-Agent" , "Custom-Client/1.0" );
484-
485- OpenAiApi api = OpenAiApi .builder ().apiKey (TEST_API_KEY ).headers (customHeaders ).build ();
486-
487- assertThat (api ).isNotNull ();
488- }
489-
490- @ Test
491- void testComplexMultiValueHeaders () {
492- MultiValueMap <String , String > multiHeaders = new LinkedMultiValueMap <>();
493- multiHeaders .add ("Accept" , "application/json" );
494- multiHeaders .add ("Accept" , "text/plain" );
495- multiHeaders .add ("Cache-Control" , "no-cache" );
496- multiHeaders .add ("Cache-Control" , "no-store" );
497-
498- OpenAiApi api = OpenAiApi .builder ().apiKey (TEST_API_KEY ).headers (multiHeaders ).build ();
499-
500- assertThat (api ).isNotNull ();
501- }
502-
503- @ Test
504- void testPathValidationWithSlashes () {
505- OpenAiApi api1 = OpenAiApi .builder ()
506- .apiKey (TEST_API_KEY )
507- .completionsPath ("/v1/completions" )
508- .embeddingsPath ("/v1/embeddings" )
509- .build ();
510-
511- OpenAiApi api2 = OpenAiApi .builder ()
512- .apiKey (TEST_API_KEY )
513- .completionsPath ("v1/completions" )
514- .embeddingsPath ("v1/embeddings" )
515- .build ();
516-
517- assertThat (api1 ).isNotNull ();
518- assertThat (api2 ).isNotNull ();
519- }
520-
521- @ Test
522- void testInvalidPathsWithSpecialCharacters () {
523- assertThatThrownBy (() -> OpenAiApi .builder ().apiKey (TEST_API_KEY ).completionsPath (" " ).build ())
524- .isInstanceOf (IllegalArgumentException .class );
525- }
526-
527- @ Test
528- void testBuilderWithOnlyRequiredFields () {
529- OpenAiApi api = OpenAiApi .builder ().apiKey (TEST_API_KEY ).build ();
530-
531- assertThat (api ).isNotNull ();
532- }
533-
534- @ Test
535- void testDifferentApiKeyTypes () {
536- SimpleApiKey simpleKey = new SimpleApiKey ("simple-key" );
537- OpenAiApi api1 = OpenAiApi .builder ().apiKey (simpleKey ).build ();
538- assertThat (api1 ).isNotNull ();
539-
540- OpenAiApi api2 = OpenAiApi .builder ().apiKey (() -> "supplier-key" ).build ();
541- assertThat (api2 ).isNotNull ();
542- }
543-
544544}
0 commit comments