Skip to content

Add pagination for long queries in CustomControllerClients#1809

Open
theghost5800 wants to merge 2 commits intomasterfrom
addPagination
Open

Add pagination for long queries in CustomControllerClients#1809
theghost5800 wants to merge 2 commits intomasterfrom
addPagination

Conversation

@theghost5800
Copy link
Copy Markdown
Contributor

JIRA:LMCROSSITXSADEPLOY-3432

Comment on lines +53 to +54
String uri = uriPrefix + batchParamPrefix + String.join(",", batch);
return getListOfResources(responseMapper, uri);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you extract this to a method so the map is cleaner

.toList();
}

List<List<String>> splitIntoBatches(List<String> values, int fixedUriLength) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add access modifier or is it intentionally without one?

Comment on lines +212 to +219
Mockito.when(webClient.get())
.thenReturn(requestHeadersUriSpec);
Mockito.when(requestHeadersUriSpec.uri(Mockito.anyString()))
.thenReturn(requestHeadersSpec);
Mockito.when(requestHeadersSpec.headers(Mockito.any(Consumer.class)))
.thenReturn(requestHeadersSpec);
Mockito.when(requestHeadersSpec.retrieve())
.thenReturn(responseSpec);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is repeated in the methods below. Can you extract is to avoid duplication? The other test classes have similiar duplicatio. Can you do the same?

}

private PaginationV3 addPageOfResources(String uri, ResourcesResponseMapper<?> responseMapper, Object... urlVariables) {
protected <T> List<T> getListOfResourcesInBatches(ResourcesResponseMapper<T> responseMapper, String uriPrefix, String batchParamPrefix,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you decrease the number of params of this method? maybe merge uriPrefix and batchParamPrefix?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have merged them but if we want to keep old behaviour by passing urlVariables to be resolved inside webClient, then count of parameters will be still the same.

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class AppBoundServiceInstanceNamesGetterTest {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this class called this way? I do not understand what is is actually testing from the name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name of the class is the same as original class by adding test suffix in the end. Test method names explains what exactly is testing.

return buildResponseWithIncludedServiceInstancesAndPagination(serviceNames, null);
}

private String buildResponseWithIncludedServiceInstancesAndPagination(List<String> serviceNames, String nextPageHref) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method seems hard to read. can you extrac in some json and replace files or split to smaller readable methods?

return getListOfResources(new ServiceKeysResponseMapper(),
SERVICE_KEYS_BY_METADATA_SELECTOR_URI + uriSuffix,
labelSelector);
String expandedUriPrefix = SERVICE_KEYS_BY_METADATA_SELECTOR_URI.replace("{value}", labelSelector)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is it needed to manually replace this value? is it properly url encoded?

Comment on lines +546 to +553
String nextPage = nextPageHref == null ? "null" : "{\"href\":\"" + nextPageHref + "\"}";
return "{" + "\"resources\":[" + " {" + " \"guid\":\"" + serviceKeyGuid + "\"," + " \"name\":\"" + keyName + "\","
+ " \"type\":\"key\"," + " \"created_at\":\"2024-01-01T00:00:00Z\"," + " \"updated_at\":\"2024-01-01T00:00:00Z\","
+ " \"metadata\":{\"labels\":{},\"annotations\":{}}," + " \"relationships\":{"
+ " \"service_instance\":{\"data\":{\"guid\":\"" + serviceInstanceGuid + "\"}}" + " }" + " }" + "]," + "\"included\":{"
+ " \"service_instances\":[" + " {" + " \"guid\":\"" + serviceInstanceGuid + "\"," + " \"name\":\"" + serviceName
+ "\"," + " \"type\":\"managed\"," + " \"created_at\":\"2024-01-01T00:00:00Z\","
+ " \"updated_at\":\"2024-01-01T00:00:00Z\"," + " \"metadata\":{\"labels\":{},\"annotations\":{}}" + " }" + " ]"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract this in a file

Comment on lines +582 to +585
return "{" + "\"resources\":[" + resources + "]," + "\"included\":{" + " \"service_instances\":[" + " {" + " \"guid\":\""
+ serviceInstanceGuid + "\"," + " \"name\":\"" + serviceName + "\"," + " \"type\":\"managed\","
+ " \"created_at\":\"2024-01-01T00:00:00Z\"," + " \"updated_at\":\"2024-01-01T00:00:00Z\","
+ " \"metadata\":{\"labels\":{},\"annotations\":{}}" + " }" + " ]" + "}," + "\"pagination\":{\"next\":null}" + "}";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, extract in file

Comment on lines +362 to +375
return "{"
+ "\"resources\":["
+ " {"
+ " \"guid\":\"" + UUID.randomUUID() + "\","
+ " \"created_at\":\"2024-01-01T00:00:00Z\","
+ " \"updated_at\":\"2024-01-01T00:00:00Z\","
+ " \"relationships\":{"
+ " \"route\":{\"data\":{\"guid\":\"" + routeGuid + "\"}},"
+ " \"service_instance\":{\"data\":{\"guid\":\"" + serviceInstanceGuid + "\"}}"
+ " }"
+ " }"
+ "],"
+ "\"pagination\":{\"next\":" + nextPage + "}"
+ "}";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, extract in file?

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 6, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants