Skip to content
Merged
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 @@ -28,6 +28,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.hypertrace.config.service.v1.ConfigServiceGrpc.ConfigServiceImplBase;
Expand Down Expand Up @@ -178,6 +179,46 @@ public MockGenericConfigService mockGetAll() {
return this;
}

public MockGenericConfigService mockGetAllWithFilter(
Predicate<ContextSpecificConfig> filterPredicate) {

Mockito.doAnswer(
invocation -> {
StreamObserver<GetAllConfigsResponse> responseObserver =
invocation.getArgument(1, StreamObserver.class);
GetAllConfigsRequest request = invocation.getArgument(0, GetAllConfigsRequest.class);

List<ContextSpecificConfig> matchingConfigs =
currentValues
.row(
ResourceType.of(
request.getResourceNamespace(), request.getResourceName()))
.values()
.stream()
.filter(
config -> {
if (request.hasFilter()) {
return filterPredicate.test(config);
}
return true;
})
.collect(Collectors.toList());

GetAllConfigsResponse response =
GetAllConfigsResponse.newBuilder()
.addAllContextSpecificConfigs(matchingConfigs)
.build();

responseObserver.onNext(response);
responseObserver.onCompleted();
return null;
})
.when(this.mockConfigService)
.getAllConfigs(ArgumentMatchers.any(), ArgumentMatchers.any());

return this;
}

@SuppressWarnings("unchecked")
public MockGenericConfigService mockDelete() {
Mockito.doAnswer(
Expand Down
Loading