@Test public void testDelete() throws Exception { MongoItemWriter<String> writer = new MongoItemWriterBuilder<String>().template(this.template) .delete(true) .build(); writer.write(this.items); verify(this.template).remove(this.items.get(0)); verify(this.template).remove(this.items.get(1)); verify(this.template, never()).save(this.items.get(0)); verify(this.template, never()).save(this.items.get(1)); }
@Test public void testWriteToCollection() throws Exception { MongoItemWriter<String> writer = new MongoItemWriterBuilder<String>().collection("collection") .template(this.template) .build(); writer.write(this.items); verify(this.template).save(this.items.get(0), "collection"); verify(this.template).save(this.items.get(1), "collection"); verify(this.template, never()).remove(this.items.get(0), "collection"); verify(this.template, never()).remove(this.items.get(1), "collection"); }
@Test public void testBasicWrite() throws Exception { MongoItemWriter<String> writer = new MongoItemWriterBuilder<String>().template(this.template).build(); writer.write(this.items); verify(this.template).save(this.items.get(0)); verify(this.template).save(this.items.get(1)); verify(this.template, never()).remove(this.items.get(0)); verify(this.template, never()).remove(this.items.get(1)); }
@Test public void testNullTemplate() { try { new MongoItemWriterBuilder<>().build(); fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { assertEquals("IllegalArgumentException message did not match the expected result.", "template is required.", iae.getMessage()); } } }