33import com .github .tomakehurst .wiremock .junit5 .WireMockRuntimeInfo ;
44import com .github .tomakehurst .wiremock .junit5 .WireMockTest ;
55import com .godaddy .ans .sdk .auth .JwtCredentialsProvider ;
6+ import com .godaddy .ans .sdk .config .AnsConfiguration ;
67import com .godaddy .ans .sdk .config .Environment ;
78import com .godaddy .ans .sdk .model .generated .AgentDetails ;
89import com .godaddy .ans .sdk .model .generated .AgentLifecycleStatus ;
@@ -71,6 +72,7 @@ void shouldBuildClientWithCustomBaseUrl(WireMockRuntimeInfo wmRuntimeInfo) {
7172 String baseUrl = wmRuntimeInfo .getHttpBaseUrl ();
7273
7374 DiscoveryClient client = DiscoveryClient .builder ()
75+ .environment (Environment .OTE )
7476 .baseUrl (baseUrl )
7577 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
7678 .build ();
@@ -115,6 +117,24 @@ void shouldThrowExceptionWhenCredentialsProviderIsNull() {
115117 .isInstanceOf (NullPointerException .class );
116118 }
117119
120+ @ Test
121+ @ DisplayName ("Should build client with pre-built configuration" )
122+ void shouldBuildClientWithPreBuiltConfiguration () {
123+ AnsConfiguration prebuilt = AnsConfiguration .builder ()
124+ .environment (Environment .PROD )
125+ .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
126+ .baseUrl ("https://custom.example.com" )
127+ .build ();
128+
129+ DiscoveryClient client = DiscoveryClient .builder ()
130+ .environment (Environment .OTE )
131+ .configuration (prebuilt )
132+ .build ();
133+
134+ assertThat (client .getConfiguration ()).isSameAs (prebuilt );
135+ assertThat (client .getConfiguration ().getBaseUrl ()).isEqualTo ("https://custom.example.com" );
136+ }
137+
118138 // ==================== Resolution Success Tests ====================
119139
120140 @ Test
@@ -137,6 +157,7 @@ void shouldResolveAgentSuccessfully(WireMockRuntimeInfo wmRuntimeInfo) {
137157 .withBody (agentDetailsResponse ())));
138158
139159 DiscoveryClient client = DiscoveryClient .builder ()
160+ .environment (Environment .OTE )
140161 .baseUrl (baseUrl )
141162 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
142163 .build ();
@@ -196,6 +217,7 @@ void shouldResolveAgentWithoutVersion(WireMockRuntimeInfo wmRuntimeInfo) {
196217 .withBody (agentDetailsResponse ())));
197218
198219 DiscoveryClient client = DiscoveryClient .builder ()
220+ .environment (Environment .OTE )
199221 .baseUrl (baseUrl )
200222 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
201223 .build ();
@@ -228,6 +250,7 @@ void shouldResolveAgentAsync(WireMockRuntimeInfo wmRuntimeInfo) throws Exception
228250 .withBody (agentDetailsResponse ())));
229251
230252 DiscoveryClient client = DiscoveryClient .builder ()
253+ .environment (Environment .OTE )
231254 .baseUrl (baseUrl )
232255 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
233256 .build ();
@@ -253,6 +276,7 @@ void shouldThrowNotFoundExceptionWhen404(WireMockRuntimeInfo wmRuntimeInfo) {
253276 .withBody ("{\" status\" :\" error\" ,\" code\" :\" NOT_FOUND\" ,\" message\" :\" Agent not found\" }" )));
254277
255278 DiscoveryClient client = DiscoveryClient .builder ()
279+ .environment (Environment .OTE )
256280 .baseUrl (baseUrl )
257281 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
258282 .build ();
@@ -274,6 +298,7 @@ void shouldThrowAuthExceptionWhen401(WireMockRuntimeInfo wmRuntimeInfo) {
274298 .withBody ("{\" status\" :\" error\" ,\" code\" :\" UNAUTHORIZED\" ,\" message\" :\" Invalid credentials\" }" )));
275299
276300 DiscoveryClient client = DiscoveryClient .builder ()
301+ .environment (Environment .OTE )
277302 .baseUrl (baseUrl )
278303 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
279304 .build ();
@@ -295,6 +320,7 @@ void shouldThrowAuthExceptionWhen403(WireMockRuntimeInfo wmRuntimeInfo) {
295320 .withBody ("{\" status\" :\" error\" ,\" code\" :\" FORBIDDEN\" ,\" message\" :\" Access denied\" }" )));
296321
297322 DiscoveryClient client = DiscoveryClient .builder ()
323+ .environment (Environment .OTE )
298324 .baseUrl (baseUrl )
299325 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
300326 .build ();
@@ -317,6 +343,7 @@ void shouldThrowValidationExceptionWhen422(WireMockRuntimeInfo wmRuntimeInfo) {
317343 + "\" message\" :\" Invalid version format\" }" )));
318344
319345 DiscoveryClient client = DiscoveryClient .builder ()
346+ .environment (Environment .OTE )
320347 .baseUrl (baseUrl )
321348 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
322349 .build ();
@@ -338,6 +365,7 @@ void shouldThrowServerExceptionWhen500(WireMockRuntimeInfo wmRuntimeInfo) {
338365 .withBody ("{\" status\" :\" error\" ,\" code\" :\" INTERNAL_ERROR\" ,\" message\" :\" Internal server error\" }" )));
339366
340367 DiscoveryClient client = DiscoveryClient .builder ()
368+ .environment (Environment .OTE )
341369 .baseUrl (baseUrl )
342370 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
343371 .build ();
@@ -360,6 +388,7 @@ void shouldThrowServerExceptionWhenLinkMissing(WireMockRuntimeInfo wmRuntimeInfo
360388 .withBody ("{\" ansName\" :\" ans://v1.0.0.booking-agent.example.com\" ,\" links\" :[]}" )));
361389
362390 DiscoveryClient client = DiscoveryClient .builder ()
391+ .environment (Environment .OTE )
363392 .baseUrl (baseUrl )
364393 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
365394 .build ();
@@ -381,6 +410,7 @@ void shouldWrapExceptionInAsync(WireMockRuntimeInfo wmRuntimeInfo) {
381410 .withBody ("{\" status\" :\" error\" ,\" code\" :\" NOT_FOUND\" ,\" message\" :\" Agent not found\" }" )));
382411
383412 DiscoveryClient client = DiscoveryClient .builder ()
413+ .environment (Environment .OTE )
384414 .baseUrl (baseUrl )
385415 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
386416 .build ();
@@ -406,6 +436,7 @@ void shouldGetAgentByIdSuccessfully(WireMockRuntimeInfo wmRuntimeInfo) {
406436 .withBody (agentDetailsResponse ())));
407437
408438 DiscoveryClient client = DiscoveryClient .builder ()
439+ .environment (Environment .OTE )
409440 .baseUrl (baseUrl )
410441 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
411442 .build ();
@@ -433,6 +464,7 @@ void shouldThrowNotFoundWhenGettingNonExistentAgent(WireMockRuntimeInfo wmRuntim
433464 .withBody ("{\" status\" :\" error\" ,\" code\" :\" NOT_FOUND\" ,\" message\" :\" Agent not found\" }" )));
434465
435466 DiscoveryClient client = DiscoveryClient .builder ()
467+ .environment (Environment .OTE )
436468 .baseUrl (baseUrl )
437469 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
438470 .build ();
@@ -454,6 +486,7 @@ void shouldThrowAuthExceptionWhenUnauthorizedToGetAgent(WireMockRuntimeInfo wmRu
454486 .withBody ("{\" status\" :\" error\" ,\" code\" :\" UNAUTHORIZED\" ,\" message\" :\" Invalid token\" }" )));
455487
456488 DiscoveryClient client = DiscoveryClient .builder ()
489+ .environment (Environment .OTE )
457490 .baseUrl (baseUrl )
458491 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
459492 .build ();
@@ -475,6 +508,7 @@ void shouldGetAgentAsync(WireMockRuntimeInfo wmRuntimeInfo) throws Exception {
475508 .withBody (agentDetailsResponse ())));
476509
477510 DiscoveryClient client = DiscoveryClient .builder ()
511+ .environment (Environment .OTE )
478512 .baseUrl (baseUrl )
479513 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
480514 .build ();
@@ -498,6 +532,7 @@ void shouldWrapExceptionInAsyncGetAgent(WireMockRuntimeInfo wmRuntimeInfo) {
498532 .withBody ("{\" status\" :\" error\" ,\" code\" :\" NOT_FOUND\" ,\" message\" :\" Agent not found\" }" )));
499533
500534 DiscoveryClient client = DiscoveryClient .builder ()
535+ .environment (Environment .OTE )
501536 .baseUrl (baseUrl )
502537 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
503538 .build ();
@@ -540,6 +575,7 @@ void shouldHandleRelativeHrefInResolutionResponse(WireMockRuntimeInfo wmRuntimeI
540575 .withBody (agentDetailsResponse ())));
541576
542577 DiscoveryClient client = DiscoveryClient .builder ()
578+ .environment (Environment .OTE )
543579 .baseUrl (baseUrl )
544580 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
545581 .build ();
@@ -562,6 +598,7 @@ void shouldThrowServerExceptionForMalformedResolutionJson(WireMockRuntimeInfo wm
562598 .withBody ("{ invalid json }" )));
563599
564600 DiscoveryClient client = DiscoveryClient .builder ()
601+ .environment (Environment .OTE )
565602 .baseUrl (baseUrl )
566603 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
567604 .build ();
@@ -589,6 +626,7 @@ void shouldThrowServerExceptionForMalformedAgentDetailsJson(WireMockRuntimeInfo
589626 .withBody ("{ not valid json }" )));
590627
591628 DiscoveryClient client = DiscoveryClient .builder ()
629+ .environment (Environment .OTE )
592630 .baseUrl (baseUrl )
593631 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
594632 .build ();
@@ -610,6 +648,7 @@ void shouldThrowServerExceptionForUnexpected4xxError(WireMockRuntimeInfo wmRunti
610648 .withBody ("{\" status\" :\" error\" ,\" message\" :\" Bad request\" }" )));
611649
612650 DiscoveryClient client = DiscoveryClient .builder ()
651+ .environment (Environment .OTE )
613652 .baseUrl (baseUrl )
614653 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
615654 .build ();
@@ -637,6 +676,7 @@ void shouldHandleNullVersionInResolve(WireMockRuntimeInfo wmRuntimeInfo) {
637676 .withBody (agentDetailsResponse ())));
638677
639678 DiscoveryClient client = DiscoveryClient .builder ()
679+ .environment (Environment .OTE )
640680 .baseUrl (baseUrl )
641681 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
642682 .build ();
@@ -668,6 +708,7 @@ void shouldHandleEmptyVersionStringInResolve(WireMockRuntimeInfo wmRuntimeInfo)
668708 .withBody (agentDetailsResponse ())));
669709
670710 DiscoveryClient client = DiscoveryClient .builder ()
711+ .environment (Environment .OTE )
671712 .baseUrl (baseUrl )
672713 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
673714 .build ();
@@ -695,6 +736,7 @@ void shouldIncludeRequestIdInErrorResponse(WireMockRuntimeInfo wmRuntimeInfo) {
695736 .withBody ("{\" status\" :\" error\" ,\" message\" :\" Internal error\" }" )));
696737
697738 DiscoveryClient client = DiscoveryClient .builder ()
739+ .environment (Environment .OTE )
698740 .baseUrl (baseUrl )
699741 .credentialsProvider (new JwtCredentialsProvider (TEST_JWT_TOKEN ))
700742 .build ();
0 commit comments