@Test public void testGetUserByIdReturnsNotFoundForNonExistingId() throws Exception { String testUserId = "non-existing-id"; UserByIdQuery testQuery = new UserByIdQuery(new UserId(testUserId)); when(queryGateway.query(eq(testQuery), any(InstanceResponseType.class))) .thenReturn(completedFuture(null)); CompletableFuture<ResponseEntity<UserView>> result = testSubject.getUserById(testUserId); assertTrue(result.isDone()); ResponseEntity<UserView> responseEntity = result.get(); assertSame(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); assertNull(responseEntity.getBody()); verify(queryGateway).query(eq(testQuery), any(InstanceResponseType.class)); }
@GetMapping("/user/{userId}") public CompletableFuture<ResponseEntity<UserView>> getUserById(@PathVariable String userId) { return queryGateway.query(new UserByIdQuery(new UserId(userId)), ResponseTypes.instanceOf(UserView.class)) .thenApply(this::wrapResult); }
QueryController { @GetMapping("/user/{userId}") public CompletableFuture<ResponseEntity<UserView>> getUserById(@PathVariable String userId) { return queryGateway.query(new UserByIdQuery(new UserId(userId)), ResponseTypes.instanceOf(UserView.class)) .thenApply(this::wrapResult); } }
QueryController { @GetMapping("/user/{userId}") public CompletableFuture<ResponseEntity<UserView>> getUserById(@PathVariable String userId) { return queryGateway.query(new UserByIdQuery(new UserId(userId)), ResponseTypes.instanceOf(UserView.class)) .thenApply(this::wrapResult); } QueryController(QueryGateway queryGateway); }
QueryController { @GetMapping("/user/{userId}") public CompletableFuture<ResponseEntity<UserView>> getUserById(@PathVariable String userId) { return queryGateway.query(new UserByIdQuery(new UserId(userId)), ResponseTypes.instanceOf(UserView.class)) .thenApply(this::wrapResult); } QueryController(QueryGateway queryGateway); @GetMapping("/company/{companyId}") CompletableFuture<ResponseEntity<CompanyView>> getCompanyById(@PathVariable String companyId); @GetMapping("/company") CompletableFuture<ResponseEntity<List<CompanyView>>> findAllCompanies(
            @RequestParam(value = "page", defaultValue = "0") int page,
            @RequestParam(value = "pageSize", defaultValue = "100") int pageSize); @GetMapping("/order-book/{orderBookId}") CompletableFuture<ResponseEntity<OrderBookView>> getOrderBookById(@PathVariable String orderBookId); @GetMapping("/order-book/by-company/{companyId}") CompletableFuture<ResponseEntity<List<OrderBookView>>> getOrderBooksByCompanyId(
            @PathVariable String companyId); @GetMapping("/transaction/{transactionId}") CompletableFuture<ResponseEntity<TransactionView>> getTransactionById(@PathVariable String transactionId); @GetMapping("/transaction/by-portfolio/{portfolioId}") CompletableFuture<ResponseEntity<List<TransactionView>>> getTransactionsByPortfolioId(
            @PathVariable String portfolioId); @GetMapping("/executed-trades/{orderBookId}") CompletableFuture<ResponseEntity<List<TradeExecutedView>>> getExecutedTradesByOrderBookId(
            @PathVariable String orderBookId); @GetMapping("/portfolio/{portfolioId}") CompletableFuture<ResponseEntity<PortfolioView>> getPortfolioById(@PathVariable String portfolioId); @GetMapping("/portfolio/by-user/{userId}") CompletableFuture<ResponseEntity<PortfolioView>> getPortfolioByUserId(@PathVariable String userId); @GetMapping("/user/{userId}") CompletableFuture<ResponseEntity<UserView>> getUserById(@PathVariable String userId); @GetMapping("/user") CompletableFuture<ResponseEntity<List<UserView>>> findAllUsers(
            @RequestParam(value = "page", defaultValue = "0") int page,
            @RequestParam(value = "pageSize", defaultValue = "100") int pageSize); @GetMapping("/subscribe/order-book/{orderBookId}") Flux<ServerSentEvent<OrderBookView>> subscribeToOrderBook(@PathVariable String orderBookId); }
QueryController { @GetMapping("/user/{userId}") public CompletableFuture<ResponseEntity<UserView>> getUserById(@PathVariable String userId) { return queryGateway.query(new UserByIdQuery(new UserId(userId)), ResponseTypes.instanceOf(UserView.class)) .thenApply(this::wrapResult); } QueryController(QueryGateway queryGateway); @GetMapping("/company/{companyId}") CompletableFuture<ResponseEntity<CompanyView>> getCompanyById(@PathVariable String companyId); @GetMapping("/company") CompletableFuture<ResponseEntity<List<CompanyView>>> findAllCompanies(
            @RequestParam(value = "page", defaultValue = "0") int page,
            @RequestParam(value = "pageSize", defaultValue = "100") int pageSize); @GetMapping("/order-book/{orderBookId}") CompletableFuture<ResponseEntity<OrderBookView>> getOrderBookById(@PathVariable String orderBookId); @GetMapping("/order-book/by-company/{companyId}") CompletableFuture<ResponseEntity<List<OrderBookView>>> getOrderBooksByCompanyId(
            @PathVariable String companyId); @GetMapping("/transaction/{transactionId}") CompletableFuture<ResponseEntity<TransactionView>> getTransactionById(@PathVariable String transactionId); @GetMapping("/transaction/by-portfolio/{portfolioId}") CompletableFuture<ResponseEntity<List<TransactionView>>> getTransactionsByPortfolioId(
            @PathVariable String portfolioId); @GetMapping("/executed-trades/{orderBookId}") CompletableFuture<ResponseEntity<List<TradeExecutedView>>> getExecutedTradesByOrderBookId(
            @PathVariable String orderBookId); @GetMapping("/portfolio/{portfolioId}") CompletableFuture<ResponseEntity<PortfolioView>> getPortfolioById(@PathVariable String portfolioId); @GetMapping("/portfolio/by-user/{userId}") CompletableFuture<ResponseEntity<PortfolioView>> getPortfolioByUserId(@PathVariable String userId); @GetMapping("/user/{userId}") CompletableFuture<ResponseEntity<UserView>> getUserById(@PathVariable String userId); @GetMapping("/user") CompletableFuture<ResponseEntity<List<UserView>>> findAllUsers(
            @RequestParam(value = "page", defaultValue = "0") int page,
            @RequestParam(value = "pageSize", defaultValue = "100") int pageSize); @GetMapping("/subscribe/order-book/{orderBookId}") Flux<ServerSentEvent<OrderBookView>> subscribeToOrderBook(@PathVariable String orderBookId);  }