Skip to content

Commit

Permalink
add testes to check if parameter is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
steniobhz committed Oct 17, 2024
1 parent 6aeec5c commit 4f7f4ff
Showing 1 changed file with 60 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -945,8 +945,7 @@ private void checkGETBodyWithAwait(final String requestUrl, final String body) {

/**
* Test for hookHandleSearch with listener storage path and valid query param. <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=testQuery
* requestUrl: http://localhost:7012/playground/server/hooks/v1/registrations/listeners/?q=testQuery
*/
@Test
public void testHookHandleSearch_ListenerPathWithValidQueryParam(TestContext context) {
Expand Down Expand Up @@ -976,8 +975,7 @@ public void testHookHandleSearch_ListenerPathWithValidQueryParam(TestContext con

/**
* 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
* requestUrl: http://localhost:7012/playground/server/hooks/v1/registrations/listeners/?q=nonMatchingQuery
*/
@Test
public void testHookHandleSearch_ListenerPathWithNonMatchingQueryParam(TestContext context) {
Expand Down Expand Up @@ -1011,8 +1009,7 @@ public void testHookHandleSearch_ListenerPathWithNonMatchingQueryParam(TestConte

/**
* Test for hookHandleSearch with listener storage path and valid query param but no listeners registered. <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=someQuery
* requestUrl: http://localhost:7012/playground/server/hooks/v1/registrations/listeners/?q=someQuery
*/
@Test
public void testHookHandleSearch_NoListenersRegistered(TestContext context) {
Expand All @@ -1039,4 +1036,61 @@ public void testHookHandleSearch_NoListenersRegistered(TestContext context) {
async.complete();
}


@Test
public void testHookHandleSearch_ListenerPathInvalidParam(TestContext context) {
Async async = context.async();
delete();
initRoutingRules();

String queryParam = "testQuery";
String listenerPath = "/_hooks/listeners";
String requestUrl = requestUrlBase + listenerPath + "?www=" + queryParam;

// Register a listener
TestUtils.registerListener(requestUrlBase + listenerPath, targetUrlBase, new String[]{"GET", "POST"}, null);

// Send GET request
given().queryParam("www", queryParam)
.when().get(requestUrl)
.then().assertThat().statusCode(400);

// Validate the response
checkGETStatusCodeWithAwait(requestUrl, 400);

TestUtils.unregisterListener(requestUrlBase + listenerPath);

async.complete();
}

/**
* Test for hookHandleSearch with listener storage path and no query parameter. <br />
* requestUrl: http://localhost:7012/playground/server/hooks/v1/registrations/listeners/?q=
*/
@Test
public void testHookHandleSearch_NoQueryParameter(TestContext context) {
Async async = context.async();
delete();
initRoutingRules();

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

// Register a listener
TestUtils.registerListener(requestUrlBase + listenerPath, targetUrlBase, new String[]{"GET", "POST"}, null);

// Send GET request
given().queryParam("q", queryParam)
.when().get(requestUrl)
.then().assertThat().statusCode(400);

// Validate the response
checkGETStatusCodeWithAwait(requestUrl, 400);

TestUtils.unregisterListener(requestUrlBase + listenerPath);

async.complete();
}

}

0 comments on commit 4f7f4ff

Please sign in to comment.