@Test public void search_SingleWord_ShouldCreateConditionAndReturnDocuments() { List<TodoDocument> expected = new ArrayList<TodoDocument>(); Page expectedPage = new PageImpl(expected); when(solrTemplateMock.queryForPage(any(Query.class), eq(TodoDocument.class))).thenReturn(expectedPage); List<TodoDocument> actual = repository.search(SEARCH_TERM_SINGLE_WORD); ArgumentCaptor<SimpleQuery> queryArgument = ArgumentCaptor.forClass(SimpleQuery.class); verify(solrTemplateMock, times(1)).queryForPage(queryArgument.capture(), eq(TodoDocument.class)); verifyNoMoreInteractions(solrTemplateMock); SimpleQuery executedQuery = queryArgument.getValue(); Sort sort = executedQuery.getSort(); assertEquals(Sort.Direction.DESC, sort.getOrderFor(TodoDocument.FIELD_ID).getDirection()); Criteria executedCriteria = executedQuery.getCriteria(); List<Criteria> criteriaChain = executedCriteria.getCriteriaChain(); assertEquals(2, criteriaChain.size()); for (Criteria criteria: criteriaChain) { Field field = criteria.getField(); assertTrue(field.getName().equals(TodoDocument.FIELD_TITLE) || field.getName().equals(TodoDocument.FIELD_DESCRIPTION)); Set<Criteria.CriteriaEntry> entries = criteria.getCriteriaEntries(); assertEquals(1, entries.size()); Criteria.CriteriaEntry entry = entries.iterator().next(); assertEquals(Criteria.OperationKey.CONTAINS.getKey(), entry.getKey()); assertEquals(SEARCH_TERM_SINGLE_WORD, entry.getValue()); } assertEquals(expected, actual); }
@Override public List<TodoDocument> search(String searchTerm) { LOGGER.debug("Building a criteria query with search term: {}", searchTerm); String[] words = searchTerm.split(" "); Criteria conditions = createSearchConditions(words); SimpleQuery search = new SimpleQuery(conditions); search.addSort(sortByIdDesc()); Page results = solrTemplate.queryForPage(search, TodoDocument.class); return results.getContent(); }
TodoDocumentRepositoryImpl implements CustomTodoDocumentRepository { @Override public List<TodoDocument> search(String searchTerm) { LOGGER.debug("Building a criteria query with search term: {}", searchTerm); String[] words = searchTerm.split(" "); Criteria conditions = createSearchConditions(words); SimpleQuery search = new SimpleQuery(conditions); search.addSort(sortByIdDesc()); Page results = solrTemplate.queryForPage(search, TodoDocument.class); return results.getContent(); } }
TodoDocumentRepositoryImpl implements CustomTodoDocumentRepository { @Override public List<TodoDocument> search(String searchTerm) { LOGGER.debug("Building a criteria query with search term: {}", searchTerm); String[] words = searchTerm.split(" "); Criteria conditions = createSearchConditions(words); SimpleQuery search = new SimpleQuery(conditions); search.addSort(sortByIdDesc()); Page results = solrTemplate.queryForPage(search, TodoDocument.class); return results.getContent(); }  }
TodoDocumentRepositoryImpl implements CustomTodoDocumentRepository { @Override public List<TodoDocument> search(String searchTerm) { LOGGER.debug("Building a criteria query with search term: {}", searchTerm); String[] words = searchTerm.split(" "); Criteria conditions = createSearchConditions(words); SimpleQuery search = new SimpleQuery(conditions); search.addSort(sortByIdDesc()); Page results = solrTemplate.queryForPage(search, TodoDocument.class); return results.getContent(); }  @Override List<TodoDocument> search(String searchTerm); @Override void update(Todo todoEntry); }
TodoDocumentRepositoryImpl implements CustomTodoDocumentRepository { @Override public List<TodoDocument> search(String searchTerm) { LOGGER.debug("Building a criteria query with search term: {}", searchTerm); String[] words = searchTerm.split(" "); Criteria conditions = createSearchConditions(words); SimpleQuery search = new SimpleQuery(conditions); search.addSort(sortByIdDesc()); Page results = solrTemplate.queryForPage(search, TodoDocument.class); return results.getContent(); }  @Override List<TodoDocument> search(String searchTerm); @Override void update(Todo todoEntry);  }