SolrUpdateDao implements UpdateDao { @Override public Document update(Document update, Optional<String> rawIndex) throws IOException { Document newVersion = update; Object commentsObj = update.getDocument().get(COMMENTS_FIELD); if ( commentsObj instanceof List && ((List<Object>) commentsObj).size() > 0 && ((List<Object>) commentsObj).get(0) instanceof Map) { newVersion = new Document(update); convertCommentsToRaw(newVersion.getDocument()); } try { SolrInputDocument solrInputDocument = SolrUtilities.toSolrInputDocument(newVersion); Optional<String> index = SolrUtilities .getIndex(config.getIndexSupplier(), newVersion.getSensorType(), rawIndex); if (index.isPresent()) { this.client.add(index.get(), solrInputDocument); this.client.commit(index.get()); } else { throw new IllegalStateException("Index must be specified or inferred."); } } catch (SolrServerException e) { throw new IOException(e); } return newVersion; } SolrUpdateDao(SolrClient client, SolrRetrieveLatestDao retrieveLatestDao, AccessConfig config); @Override Document update(Document update, Optional<String> rawIndex); @Override Map<Document, Optional<String>> batchUpdate(Map<Document, Optional<String>> updates); @Override Document addCommentToAlert(CommentAddRemoveRequest request); @Override Document addCommentToAlert(CommentAddRemoveRequest request, Document latest); @Override Document removeCommentFromAlert(CommentAddRemoveRequest request); @Override Document removeCommentFromAlert(CommentAddRemoveRequest request, Document latest); void convertCommentsToRaw(Map<String,Object> source);  }
@Test public void updateShouldProperlyUpdateDocumentImplicitIndex() throws Exception { Document document = new Document(new HashMap<String, Object>(){{ put("field", "value"); }}, "guid", "bro", 0L); SolrInputDocument solrInputDocument = new SolrInputDocument(); solrInputDocument.addField("field", "value"); solrUpdateDao.update(document, Optional.empty()); verify(client).add(eq("bro"), argThat(new SolrInputDocumentMatcher(solrInputDocument))); }
@Test public void updateShouldProperlyUpdateDocumentExplicitIndex() throws Exception { Document document = new Document(new HashMap<String, Object>(){{ put("field", "value"); }}, "guid", "bro", 0L); SolrInputDocument solrInputDocument = new SolrInputDocument(); solrInputDocument.addField("field", "value"); solrUpdateDao.update(document, Optional.of("bro")); verify(client).add(eq("bro"), argThat(new SolrInputDocumentMatcher(solrInputDocument))); }