QueryService extends QueryServiceGrpc.QueryServiceImplBase implements Logging { @Override public void read(Query query, StreamObserver<QueryResponse> responseObserver) { _debug().log("Incoming query: `%s`.", lazy(() -> shortDebugString(query))); TypeUrl type = query.targetType(); BoundedContext context = typeToContextMap.get(type); if (context == null) { handleUnsupported(type, responseObserver); } else { handleQuery(context, query, responseObserver); } } private  QueryService(Map<TypeUrl, BoundedContext> map); static Builder newBuilder(); @Override void read(Query query, StreamObserver<QueryResponse> responseObserver);  }
@Test @DisplayName("execute queries") void executeQueries() { Query query = Given.AQuery.readAllProjects(); service.read(query, responseObserver); checkOkResponse(responseObserver); }
@Test @DisplayName("dispatch queries to proper Bounded Context") void dispatchQueriesToBc() { Query query = Given.AQuery.readAllProjects(); service.read(query, responseObserver); checkOkResponse(responseObserver); }
@Test @MuteLogging @DisplayName("return error if query failed to execute") void returnErrorOnQueryFail() { setUpService(new ThrowingProjectDetailsRepository()); Query query = Given.AQuery.readAllProjects(); service.read(query, responseObserver); checkFailureResponse(responseObserver); }
@Test @MuteLogging @DisplayName("throw an IllegalStateException if the requested entity type is unknown") void failOnUnknownType() { Query query = Given.AQuery.readUnknownType(); service.read(query, responseObserver); Throwable error = responseObserver.getError(); ThrowableSubject assertError = assertThat(error); assertError.isNotNull(); assertError.isInstanceOf(UnknownEntityTypeException.class); String unknownTypeUrl = query.targetType() .value(); assertError.hasMessageThat().contains(unknownTypeUrl); }