### Question:
RowMutationHelper { public static List<RowMutation> from(Collection<SolrInputDocument> docs, String table) { List<RowMutation> mutations = Lists.newArrayList(); for (SolrInputDocument d : docs) { mutations.add(from(d, table)); } return mutations; }  static List<RowMutation> from(Collection<SolrInputDocument> docs, String table); static RowMutation from(SolrInputDocument doc, String table);  }### Answer:
@Test public void basicOneForOneConversion() { SolrInputDocument parent = new SolrInputDocument(); parent.addField("rowid", "123"); SolrInputDocument child = new SolrInputDocument(); child.addField("recordid", "1"); child.addField("fam.key", "value"); parent.addChildDocument(child); RowMutation mutate = RowMutationHelper.from(parent, "foo"); assertEquals("Should get our rowid back.", "123", mutate.getRowId()); assertEquals("Should get a single record.", 1, mutate.getRecordMutationsSize()); assertEquals("Tablename should be set", "foo", mutate.getTable()); }
@Test public void multivalueFieldsShouldTranslate() { SolrInputDocument doc = new SolrInputDocument(); doc.addField("rowid", "123"); SolrInputDocument child = new SolrInputDocument(); child.addField("recordid", "1"); child.addField("fam.key", "value1"); child.addField("fam.key", "value2"); doc.addChildDocument(child); RowMutation mutate = RowMutationHelper.from(doc, "foo"); List<Object> vals = getRecordValues("key", mutate); assertEquals("Should get both values back.", 2, vals.size()); assertEquals("value1", vals.get(0).toString()); assertEquals("value2", vals.get(1).toString()); }
@Test public void documentWithChildDocumentsShouldBeRowWithRecords() { SolrInputDocument doc = new SolrInputDocument(); doc.addField("rowid", "1"); List<SolrInputDocument> children = Lists.newArrayList(); for (int i = 0; i < 10; i++) { SolrInputDocument child = new SolrInputDocument(); child.addField("recordid", i); child.addField("fam.key", "value" + i); children.add(child); } doc.addChildDocuments(children); RowMutation mutate = RowMutationHelper.from(doc, "foo"); assertEquals("Children should turn into records.", 10, mutate.getRecordMutationsSize()); assertEquals("Should get a simple value back.", "value0", getRecordValue("key", mutate)); assertEquals("Should properly figure our family.", "fam", getFirstRecord(mutate).getFamily()); }
@Test(expected = IllegalArgumentException.class) public void docWithChildrenCantItselfHaveFieldValues() { SolrInputDocument parent = new SolrInputDocument(); parent.addField("id", "1"); parent.addField("fam.key1", "123"); SolrInputDocument child = new SolrInputDocument(); parent.addChildDocument(child); RowMutationHelper.from(parent, "foo"); }
@Test(expected = IllegalArgumentException.class) public void rowsCantDirectlyHaveValues() { SolrInputDocument parent = new SolrInputDocument(); parent.addField("id", "1"); parent.addField("fam.key1", "123"); RowMutationHelper.from(parent, "foo"); }
@Test(expected = IllegalArgumentException.class) public void docsMustUseTheNormalBlurFamilyColumnFormat() { SolrInputDocument parent = new SolrInputDocument(); parent.addField("columnWithoutFamily", "123"); SolrInputDocument child = new SolrInputDocument(); parent.addChildDocument(child); RowMutationHelper.from(parent, "foo"); }