Search in sources :

Example 1 with QueryServiceClient

use of org.hypertrace.core.query.service.client.QueryServiceClient in project gateway-service by hypertrace.

the class AbstractServiceTest method createMockQueryServiceClient.

private QueryServiceClient createMockQueryServiceClient(String fileName) throws IOException {
    QueryServiceClient queryServiceClient = mock(QueryServiceClient.class);
    Map<QueryRequest, ResultSetChunk> queryRequestResultSetChunkMap = readExpectedQueryServiceRequestAndResponse(fileName);
    when(queryServiceClient.executeQuery(any(QueryRequest.class), any(HashMap.class), any(Integer.class))).thenAnswer((Answer<Iterator<ResultSetChunk>>) invocation -> {
        QueryRequest queryRequest = (QueryRequest) invocation.getArguments()[0];
        ResultSetChunk resultSetChunk = queryRequestResultSetChunkMap.get(queryRequest);
        if (resultSetChunk == null) {
            Assertions.fail("Unexpected QueryRequest object:\n" + JsonFormat.printer().print(queryRequest));
        }
        return List.of(resultSetChunk).iterator();
    });
    return queryServiceClient;
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Arrays(java.util.Arrays) AttributeMetadata(org.hypertrace.core.attribute.service.v1.AttributeMetadata) AttributeMetadataFilter(org.hypertrace.core.attribute.service.v1.AttributeMetadataFilter) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) ConfigFactory(com.typesafe.config.ConfigFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) AttributeServiceClient(org.hypertrace.core.attribute.service.client.AttributeServiceClient) MethodSource(org.junit.jupiter.params.provider.MethodSource) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ScopeFilterConfigs(org.hypertrace.gateway.service.common.config.ScopeFilterConfigs) Iterator(java.util.Iterator) Config(com.typesafe.config.Config) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) File(java.io.File) QueryServiceClient(org.hypertrace.core.query.service.client.QueryServiceClient) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Stream(java.util.stream.Stream) JsonFormat(com.google.protobuf.util.JsonFormat) QueryRequest(org.hypertrace.core.query.service.api.QueryRequest) Assertions(org.junit.jupiter.api.Assertions) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) ResultSetChunk(org.hypertrace.core.query.service.api.ResultSetChunk) BufferedReader(java.io.BufferedReader) Mockito.mock(org.mockito.Mockito.mock) InputStream(java.io.InputStream) QueryRequest(org.hypertrace.core.query.service.api.QueryRequest) HashMap(java.util.HashMap) Iterator(java.util.Iterator) QueryServiceClient(org.hypertrace.core.query.service.client.QueryServiceClient) ResultSetChunk(org.hypertrace.core.query.service.api.ResultSetChunk)

Example 2 with QueryServiceClient

use of org.hypertrace.core.query.service.client.QueryServiceClient in project gateway-service by hypertrace.

the class AbstractServiceTest method runTest.

@ParameterizedTest
@MethodSource("data")
public void runTest(String fileName) throws IOException {
    QueryServiceClient queryServiceClient = createMockQueryServiceClient(fileName);
    TGatewayServiceRequestType testRequest = readGatewayServiceRequest(fileName);
    TGatewayServiceResponseType actualResponse = executeApi(testRequest, queryServiceClient, attributeMetadataProvider, scopeFilterConfigs);
    TGatewayServiceResponseType expectedResponse = readGatewayServiceResponse(fileName);
    Assertions.assertEquals(expectedResponse, actualResponse);
}
Also used : QueryServiceClient(org.hypertrace.core.query.service.client.QueryServiceClient) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

QueryServiceClient (org.hypertrace.core.query.service.client.QueryServiceClient)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 JsonFormat (com.google.protobuf.util.JsonFormat)1 Config (com.typesafe.config.Config)1 ConfigFactory (com.typesafe.config.ConfigFactory)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1