Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ public class ConsumerDiagnosticsService {
private final ConsumerDiagnosticsProvider diagnosticsProvider;

public ConsumerStackTraceVO getConsumerStack(String groupName, String clientId) {
if (!StringUtils.hasText(groupName)) {
throw new BusinessException(HttpStatus.BAD_REQUEST.value(), "groupName is required");
}
if (!StringUtils.hasText(clientId)) {
throw new BusinessException(HttpStatus.BAD_REQUEST.value(), "clientId is required");
String normalizedGroupName = normalizeRequired(groupName, "groupName");
String normalizedClientId = normalizeRequired(clientId, "clientId");
return diagnosticsProvider.getConsumerStack(normalizedGroupName, normalizedClientId);
}

private String normalizeRequired(String value, String fieldName) {
if (!StringUtils.hasText(value)) {
throw new BusinessException(HttpStatus.BAD_REQUEST.value(), fieldName + " is required");
}
return diagnosticsProvider.getConsumerStack(groupName, clientId);
return value.trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,24 @@ void getConsumerStackShouldDelegateToProvider() {
verify(diagnosticsProvider).getConsumerStack("cg-orders", "client-1");
}

@Test
void getConsumerStackShouldTrimInputsBeforeDelegatingToProvider() {
ConsumerStackTraceVO stackTrace = ConsumerStackTraceVO.builder()
.groupName("cg-orders")
.clientId("client-1")
.capturedAt(LocalDateTime.now())
.threadCount(0)
.threads(List.of())
.build();
when(diagnosticsProvider.getConsumerStack("cg-orders", "client-1")).thenReturn(stackTrace);

ConsumerStackTraceVO result = diagnosticsService.getConsumerStack(" cg-orders ", " client-1 ");

assertThat(result.getGroupName()).isEqualTo("cg-orders");
assertThat(result.getClientId()).isEqualTo("client-1");
verify(diagnosticsProvider).getConsumerStack("cg-orders", "client-1");
}

@Test
void getConsumerStackShouldRejectBlankGroupName() {
assertThatThrownBy(() -> diagnosticsService.getConsumerStack(" ", "client-1"))
Expand Down
Loading