@@ -505,4 +505,125 @@ private StubMapping setupServerStubForBasicAuth() {
505505 .withStatus (200 )
506506 .withBody (readTestFile (SAMPLES_FOLDER + "HttpResult.json" ))));
507507 }
508+
509+ @ Test
510+ void shouldSetIgnoreStatusCodeCompletionStateForIgnoredStatusCodes ()
511+ throws ConfigurationException {
512+ // GIVEN - Configure client with ignored status codes (404, 503)
513+ configuration .setString (SOURCE_LOOKUP_HTTP_IGNORED_RESPONSE_CODES , "404,503" );
514+ configuration .setString (SOURCE_LOOKUP_HTTP_SUCCESS_CODES , "200" );
515+ configuration .setString (
516+ HttpLookupConnectorOptions .SOURCE_LOOKUP_HTTP_RETRY_CODES .key (), "" );
517+
518+ // Set up WireMock to return 404
519+ this .stubMapping =
520+ wireMockServer .stubFor (
521+ get (urlEqualTo (ENDPOINT + "?id=1&uuid=2" ))
522+ .withHeader ("Content-Type" , equalTo ("application/json" ))
523+ .willReturn (aResponse ().withStatus (404 ).withBody ("Not Found" )));
524+
525+ JavaNetHttpPollingClient pollingClient = setUpPollingClient ();
526+
527+ // WHEN - Pull data with a lookup row
528+ HttpRowDataWrapper result = pollingClient .pull (lookupRowData );
529+
530+ // THEN - Verify completion state is IGNORE_STATUS_CODE
531+ assertThat (result .getHttpCompletionState ())
532+ .isEqualTo (HttpCompletionState .IGNORE_STATUS_CODE );
533+ assertThat (result .getData ()).isEmpty ();
534+ assertThat (result .getHttpStatusCode ()).isEqualTo (404 );
535+ }
536+
537+ @ Test
538+ void shouldSetIgnoreStatusCodeForMultipleIgnoredCodes () throws ConfigurationException {
539+ // GIVEN - Configure client with multiple ignored status codes
540+ configuration .setString (SOURCE_LOOKUP_HTTP_IGNORED_RESPONSE_CODES , "404,503,429" );
541+ configuration .setString (SOURCE_LOOKUP_HTTP_SUCCESS_CODES , "200" );
542+ configuration .setString (
543+ HttpLookupConnectorOptions .SOURCE_LOOKUP_HTTP_RETRY_CODES .key (), "" );
544+
545+ // Set up WireMock to return 503
546+ this .stubMapping =
547+ wireMockServer .stubFor (
548+ get (urlEqualTo (ENDPOINT + "?id=1&uuid=2" ))
549+ .withHeader ("Content-Type" , equalTo ("application/json" ))
550+ .willReturn (
551+ aResponse ()
552+ .withStatus (503 )
553+ .withBody ("Service Unavailable" )));
554+
555+ JavaNetHttpPollingClient pollingClient = setUpPollingClient ();
556+
557+ // WHEN
558+ HttpRowDataWrapper result = pollingClient .pull (lookupRowData );
559+
560+ // THEN - Verify 503 is also treated as ignored
561+ assertThat (result .getHttpCompletionState ())
562+ .isEqualTo (HttpCompletionState .IGNORE_STATUS_CODE );
563+ assertThat (result .getData ()).isEmpty ();
564+ assertThat (result .getHttpStatusCode ()).isEqualTo (503 );
565+ }
566+
567+ @ Test
568+ void shouldNotSetIgnoreStatusCodeForNonIgnoredCodes () throws ConfigurationException {
569+ // GIVEN - Configure client with ignored status codes (404, 503)
570+ configuration .setString (SOURCE_LOOKUP_HTTP_IGNORED_RESPONSE_CODES , "404,503" );
571+ configuration .setString (SOURCE_LOOKUP_HTTP_SUCCESS_CODES , "200" );
572+ configuration .setString (
573+ HttpLookupConnectorOptions .SOURCE_LOOKUP_HTTP_RETRY_CODES .key (), "" );
574+
575+ // Set up WireMock to return 200 (success, not ignored)
576+ this .stubMapping = setUpServerStub (200 );
577+
578+ JavaNetHttpPollingClient pollingClient = setUpPollingClient ();
579+
580+ // WHEN
581+ HttpRowDataWrapper result = pollingClient .pull (lookupRowData );
582+
583+ // THEN - Verify completion state is SUCCESS, not IGNORE_STATUS_CODE
584+ assertThat (result .getHttpCompletionState ()).isEqualTo (HttpCompletionState .SUCCESS );
585+ assertThat (result .getData ()).isNotEmpty ();
586+ assertThat (result .getHttpStatusCode ()).isEqualTo (200 );
587+ }
588+
589+ @ Test
590+ void shouldReturnMetadataForIgnoredStatusCode () throws ConfigurationException {
591+ // GIVEN - Configure client with ignored status codes (404)
592+ configuration .setString (SOURCE_LOOKUP_HTTP_IGNORED_RESPONSE_CODES , "404" );
593+ configuration .setString (SOURCE_LOOKUP_HTTP_SUCCESS_CODES , "200" );
594+ configuration .setString (
595+ HttpLookupConnectorOptions .SOURCE_LOOKUP_HTTP_RETRY_CODES .key (), "" );
596+
597+ // Set up WireMock to return 404 with custom headers
598+ this .stubMapping =
599+ wireMockServer .stubFor (
600+ get (urlEqualTo (ENDPOINT + "?id=1&uuid=2" ))
601+ .withHeader ("Content-Type" , equalTo ("application/json" ))
602+ .willReturn (
603+ aResponse ()
604+ .withStatus (404 )
605+ .withBody ("Not Found" )
606+ .withHeader ("X-Request-Id" , "12345" )
607+ .withHeader ("X-Custom-Header" , "custom-value" )));
608+
609+ JavaNetHttpPollingClient pollingClient = setUpPollingClient ();
610+
611+ // WHEN - Pull data with a lookup row
612+ HttpRowDataWrapper result = pollingClient .pull (lookupRowData );
613+
614+ // THEN - Verify completion state is IGNORE_STATUS_CODE
615+ assertThat (result .getHttpCompletionState ())
616+ .isEqualTo (HttpCompletionState .IGNORE_STATUS_CODE );
617+ // Verify data is empty (no body content)
618+ assertThat (result .getData ()).isEmpty ();
619+ // Verify metadata is present - status code
620+ assertThat (result .getHttpStatusCode ()).isEqualTo (404 );
621+ // Verify metadata is present - headers
622+ assertThat (result .getHttpHeadersMap ()).isNotNull ();
623+ assertThat (result .getHttpHeadersMap ()).containsKey ("X-Request-Id" );
624+ assertThat (result .getHttpHeadersMap ().get ("X-Request-Id" )).containsExactly ("12345" );
625+ assertThat (result .getHttpHeadersMap ()).containsKey ("X-Custom-Header" );
626+ assertThat (result .getHttpHeadersMap ().get ("X-Custom-Header" ))
627+ .containsExactly ("custom-value" );
628+ }
508629}
0 commit comments