@Test public void testWriteNoItemsWithSession() throws Exception { writer = new Neo4jItemWriter<>(); writer.setSessionFactory(this.sessionFactory); writer.afterPropertiesSet(); when(this.sessionFactory.openSession()).thenReturn(this.session); writer.write(new ArrayList<>()); verifyZeroInteractions(this.session); }
@Test public void testWriteNullWithSession() throws Exception { writer = new Neo4jItemWriter<>(); writer.setSessionFactory(this.sessionFactory); writer.afterPropertiesSet(); when(this.sessionFactory.openSession()).thenReturn(this.session); writer.write(null); verifyZeroInteractions(this.session); }
@Test public void testWriteItemsWithSession() throws Exception { writer = new Neo4jItemWriter<>(); writer.setSessionFactory(this.sessionFactory); writer.afterPropertiesSet(); List<String> items = new ArrayList<>(); items.add("foo"); items.add("bar"); when(this.sessionFactory.openSession()).thenReturn(this.session); writer.write(items); verify(this.session).save("foo"); verify(this.session).save("bar"); }
@Test public void testAfterPropertiesSet() throws Exception{ writer = new Neo4jItemWriter<>(); try { writer.afterPropertiesSet(); fail("SessionFactory was not set but exception was not thrown."); } catch (IllegalStateException iae) { assertEquals("A SessionFactory is required", iae.getMessage()); } catch (Throwable t) { fail("Wrong exception was thrown."); } writer.setSessionFactory(this.sessionFactory); writer.afterPropertiesSet(); writer = new Neo4jItemWriter<>(); writer.setSessionFactory(this.sessionFactory); writer.afterPropertiesSet(); }
@Test public void testDeleteItemsWithSession() throws Exception { writer = new Neo4jItemWriter<>(); writer.setSessionFactory(this.sessionFactory); writer.afterPropertiesSet(); List<String> items = new ArrayList<>(); items.add("foo"); items.add("bar"); writer.setDelete(true); when(this.sessionFactory.openSession()).thenReturn(this.session); writer.write(items); verify(this.session).delete("foo"); verify(this.session).delete("bar"); } }
@Test public void testWriteNullSession() throws Exception { writer = new Neo4jItemWriter<>(); writer.setSessionFactory(this.sessionFactory); writer.afterPropertiesSet(); writer.write(null); verifyZeroInteractions(this.session); }