Updates after review

This commit is contained in:
Sara Aspery
2023-01-13 15:38:22 +00:00
parent 3dc637df12
commit c32487a922

View File

@@ -295,7 +295,6 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
*/ */
public boolean isContentInSearchResults(String userQuery, String contentToFind, boolean expectedInResults) { public boolean isContentInSearchResults(String userQuery, String contentToFind, boolean expectedInResults) {
String expectedStatusCode = HttpStatus.OK.toString();
String contentName = (contentToFind == null) ? "" : contentToFind; String contentName = (contentToFind == null) ? "" : contentToFind;
SearchRequest searchRequest = createQuery(userQuery); SearchRequest searchRequest = createQuery(userQuery);
@@ -305,34 +304,36 @@ public abstract class AbstractE2EFunctionalTest extends AbstractTestNGSpringCont
{ {
try try
{ {
SearchResponse response = query(searchRequest); if (expectedInResults == isContentFoundWithRequest(searchRequest, contentName))
if (restClient.getStatusCode().matches(expectedStatusCode))
{ {
boolean found = isContentInSearchResponse(response, contentName); return true;
}
// Exit loop if result is as expected. // Wait for the solr indexing (eventual consistency).
if (expectedInResults == found) Utility.waitToLoopTime(properties.getSolrWaitTimeInSeconds(), "Wait For Indexing. Retry Attempt: " + (searchCount + 1));
{
return true;
}
// Wait for the solr indexing (eventual consistency).
Utility.waitToLoopTime(properties.getSolrWaitTimeInSeconds(), "Wait For Indexing. Retry Attempt: " + (searchCount + 1));
}
else
{
throw new RuntimeException("API returned status code:" + restClient.getStatusCode() + " Expected: " + expectedStatusCode + "; Response body: " + response);
}
} }
catch (EmptyJsonResponseException e) catch (EmptyJsonResponseException ignore)
{ {
// Ignore the empty JSON response and try again
} }
} }
return false; return false;
} }
private boolean isContentFoundWithRequest(SearchRequest searchRequest, String contentName)
{
SearchResponse response = query(searchRequest);
if (restClient.getStatusCode().matches(HttpStatus.OK.toString()))
{
return isContentInSearchResponse(response, contentName);
}
else
{
throw new RuntimeException("API returned status code:" + restClient.getStatusCode() + " Expected: " + HttpStatus.OK + "; Response body: " + response);
}
}
/** /**
* Method to check if the contentName is returned in the SearchResponse. * Method to check if the contentName is returned in the SearchResponse.
* *