Skip to content

Commit

Permalink
Added test for hookHandleSearch to verify behavior when no matching l…
Browse files Browse the repository at this point in the history
…istener is found for a given query parameter.
  • Loading branch information
steniobhz committed Oct 11, 2024
1 parent 2f712c0 commit a0161a2
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -973,4 +973,37 @@ public void testHookHandleSearch_ListenerPathWithValidQueryParam(TestContext con
async.complete();
}

/**
* Test for hookHandleSearch with listener storage path and valid query param but no match found. <br />
* eg. register / unregister: http://localhost:7012/gateleen/server/listenertest/_hooks/listeners/listener/1 <br />
* requestUrl: http://localhost:7012/gateleen/server/listenertest/listener/test?q=nonMatchingQuery
*/
@Test
public void testHookHandleSearch_ListenerPathWithNonMatchingQueryParam(TestContext context) {
Async async = context.async();
delete();
initRoutingRules();

String nonMatchingQueryParam = "nonMatchingQuery";
String listenerPath = "/_hooks/listeners";
String requestUrl = requestUrlBase + listenerPath + "?q=" + nonMatchingQueryParam;

// Register a listener with a different query param
String differentQueryParam = "differentQuery";
TestUtils.registerListener(requestUrlBase + listenerPath + "?q=" + differentQueryParam, targetUrlBase, new String[]{"GET", "POST"}, null);

// Send GET request with non-matching query param
given().queryParam("q", nonMatchingQueryParam)
.when().get(requestUrl)
.then().assertThat().statusCode(404); // Expecting 404 as no listener matches the query

// Validate that the response is not found
checkGETStatusCodeWithAwait(requestUrl, 404);

// Unregister the listener
TestUtils.unregisterListener(requestUrlBase + listenerPath);

async.complete();
}

}

0 comments on commit a0161a2

Please sign in to comment.