@Test public void shouldGetMessagesUsingDefaults() throws Exception { MessageFilter filter = new MessageFilter(); when(messageRepository.findByDateBetweenAndDirectionIn( notNull(), notNull(), directionsCaptor.capture(), pageableCaptor.capture()) ).thenReturn(singleResult()); assertHasSingleResult(sut.getMessagesMatchingFilter(filter)); assertPagingMatches(0, 25); assertDirectionMatches(Message.Direction.INBOUND, Message.Direction.OUTBOUND); }
public List<Message> getMessagesMatchingFilter(MessageFilter filter) { Date calcFromDate = Optional.ofNullable(filter.getFromDate()).orElse(startOfDay()); Date calcToDate = Optional.ofNullable(filter.getFromDate()).orElse(endOfDay()); Integer calcPage = Optional.ofNullable(filter.getPageNumber()).orElse(0); Integer calcSize = Optional.ofNullable(filter.getPageSize()).orElse(25); boolean includeInbound = Optional.ofNullable(filter.getDirectionInbound()).orElse(true); boolean includeOutbound = Optional.ofNullable(filter.getDirectionOutbound()).orElse(true); Collection<Message.Direction> includeDirections = new TreeSet<>(); if (includeInbound) { includeDirections.add(Message.Direction.INBOUND); } if (includeOutbound) { includeDirections.add(Message.Direction.OUTBOUND); } Pageable pageable = new PageRequest(calcPage, calcSize, Sort.Direction.DESC, "date"); if (StringUtils.isNotEmpty(filter.getContainingText())) { return messageRepository.findByDateBetweenAndDirectionInAndPayloadContainingIgnoreCase(calcFromDate, calcToDate, includeDirections, filter.getContainingText(), pageable); } else { return messageRepository.findByDateBetweenAndDirectionIn(calcFromDate, calcToDate, includeDirections, pageable); } }
MessageService { public List<Message> getMessagesMatchingFilter(MessageFilter filter) { Date calcFromDate = Optional.ofNullable(filter.getFromDate()).orElse(startOfDay()); Date calcToDate = Optional.ofNullable(filter.getFromDate()).orElse(endOfDay()); Integer calcPage = Optional.ofNullable(filter.getPageNumber()).orElse(0); Integer calcSize = Optional.ofNullable(filter.getPageSize()).orElse(25); boolean includeInbound = Optional.ofNullable(filter.getDirectionInbound()).orElse(true); boolean includeOutbound = Optional.ofNullable(filter.getDirectionOutbound()).orElse(true); Collection<Message.Direction> includeDirections = new TreeSet<>(); if (includeInbound) { includeDirections.add(Message.Direction.INBOUND); } if (includeOutbound) { includeDirections.add(Message.Direction.OUTBOUND); } Pageable pageable = new PageRequest(calcPage, calcSize, Sort.Direction.DESC, "date"); if (StringUtils.isNotEmpty(filter.getContainingText())) { return messageRepository.findByDateBetweenAndDirectionInAndPayloadContainingIgnoreCase(calcFromDate, calcToDate, includeDirections, filter.getContainingText(), pageable); } else { return messageRepository.findByDateBetweenAndDirectionIn(calcFromDate, calcToDate, includeDirections, pageable); } } }
MessageService { public List<Message> getMessagesMatchingFilter(MessageFilter filter) { Date calcFromDate = Optional.ofNullable(filter.getFromDate()).orElse(startOfDay()); Date calcToDate = Optional.ofNullable(filter.getFromDate()).orElse(endOfDay()); Integer calcPage = Optional.ofNullable(filter.getPageNumber()).orElse(0); Integer calcSize = Optional.ofNullable(filter.getPageSize()).orElse(25); boolean includeInbound = Optional.ofNullable(filter.getDirectionInbound()).orElse(true); boolean includeOutbound = Optional.ofNullable(filter.getDirectionOutbound()).orElse(true); Collection<Message.Direction> includeDirections = new TreeSet<>(); if (includeInbound) { includeDirections.add(Message.Direction.INBOUND); } if (includeOutbound) { includeDirections.add(Message.Direction.OUTBOUND); } Pageable pageable = new PageRequest(calcPage, calcSize, Sort.Direction.DESC, "date"); if (StringUtils.isNotEmpty(filter.getContainingText())) { return messageRepository.findByDateBetweenAndDirectionInAndPayloadContainingIgnoreCase(calcFromDate, calcToDate, includeDirections, filter.getContainingText(), pageable); } else { return messageRepository.findByDateBetweenAndDirectionIn(calcFromDate, calcToDate, includeDirections, pageable); } } @Autowired  MessageService(MessageRepository messageRepository); }
MessageService { public List<Message> getMessagesMatchingFilter(MessageFilter filter) { Date calcFromDate = Optional.ofNullable(filter.getFromDate()).orElse(startOfDay()); Date calcToDate = Optional.ofNullable(filter.getFromDate()).orElse(endOfDay()); Integer calcPage = Optional.ofNullable(filter.getPageNumber()).orElse(0); Integer calcSize = Optional.ofNullable(filter.getPageSize()).orElse(25); boolean includeInbound = Optional.ofNullable(filter.getDirectionInbound()).orElse(true); boolean includeOutbound = Optional.ofNullable(filter.getDirectionOutbound()).orElse(true); Collection<Message.Direction> includeDirections = new TreeSet<>(); if (includeInbound) { includeDirections.add(Message.Direction.INBOUND); } if (includeOutbound) { includeDirections.add(Message.Direction.OUTBOUND); } Pageable pageable = new PageRequest(calcPage, calcSize, Sort.Direction.DESC, "date"); if (StringUtils.isNotEmpty(filter.getContainingText())) { return messageRepository.findByDateBetweenAndDirectionInAndPayloadContainingIgnoreCase(calcFromDate, calcToDate, includeDirections, filter.getContainingText(), pageable); } else { return messageRepository.findByDateBetweenAndDirectionIn(calcFromDate, calcToDate, includeDirections, pageable); } } @Autowired  MessageService(MessageRepository messageRepository); Message saveMessage(Message.Direction direction, String payload, String citrusMessageId, Map<String, Object> headers); Message getMessageById(Long id); List<Message> getMessagesMatchingFilter(MessageFilter filter); void clearMessages(); }
MessageService { public List<Message> getMessagesMatchingFilter(MessageFilter filter) { Date calcFromDate = Optional.ofNullable(filter.getFromDate()).orElse(startOfDay()); Date calcToDate = Optional.ofNullable(filter.getFromDate()).orElse(endOfDay()); Integer calcPage = Optional.ofNullable(filter.getPageNumber()).orElse(0); Integer calcSize = Optional.ofNullable(filter.getPageSize()).orElse(25); boolean includeInbound = Optional.ofNullable(filter.getDirectionInbound()).orElse(true); boolean includeOutbound = Optional.ofNullable(filter.getDirectionOutbound()).orElse(true); Collection<Message.Direction> includeDirections = new TreeSet<>(); if (includeInbound) { includeDirections.add(Message.Direction.INBOUND); } if (includeOutbound) { includeDirections.add(Message.Direction.OUTBOUND); } Pageable pageable = new PageRequest(calcPage, calcSize, Sort.Direction.DESC, "date"); if (StringUtils.isNotEmpty(filter.getContainingText())) { return messageRepository.findByDateBetweenAndDirectionInAndPayloadContainingIgnoreCase(calcFromDate, calcToDate, includeDirections, filter.getContainingText(), pageable); } else { return messageRepository.findByDateBetweenAndDirectionIn(calcFromDate, calcToDate, includeDirections, pageable); } } @Autowired  MessageService(MessageRepository messageRepository); Message saveMessage(Message.Direction direction, String payload, String citrusMessageId, Map<String, Object> headers); Message getMessageById(Long id); List<Message> getMessagesMatchingFilter(MessageFilter filter); void clearMessages();  }