@SuppressWarnings("serial") @Test public void testResultsWithMatchAndWhereWithSession() throws Exception { Neo4jItemReader<String> itemReader = buildSessionBasedReader(); itemReader.setMatchStatement("n -- m"); itemReader.setWhereStatement("has(n.name)"); itemReader.setReturnStatement("m"); itemReader.afterPropertiesSet(); when(this.sessionFactory.openSession()).thenReturn(this.session); when(this.session.query(String.class, "START n=node(*) MATCH n -- m WHERE has(n.name) RETURN m ORDER BY n.age SKIP 0 LIMIT 50", null)).thenReturn(result); when(result.iterator()).thenReturn(Arrays.asList("foo", "bar", "baz").iterator()); assertTrue(itemReader.doPageRead().hasNext()); }
@SuppressWarnings("serial") @Test public void testResultsWithMatchAndWhereWithParametersWithSession() throws Exception { Neo4jItemReader<String> itemReader = buildSessionBasedReader(); Map<String, Object> params = new HashMap<>(); params.put("foo", "bar"); itemReader.setParameterValues(params); itemReader.setMatchStatement("n -- m"); itemReader.setWhereStatement("has(n.name)"); itemReader.setReturnStatement("m"); itemReader.afterPropertiesSet(); when(this.sessionFactory.openSession()).thenReturn(this.session); when(this.session.query(String.class, "START n=node(*) MATCH n -- m WHERE has(n.name) RETURN m ORDER BY n.age SKIP 0 LIMIT 50", params)).thenReturn(result); when(result.iterator()).thenReturn(Arrays.asList("foo", "bar", "baz").iterator()); assertTrue(itemReader.doPageRead().hasNext()); } }
reader.afterPropertiesSet(); fail("SessionFactory was not set but exception was not thrown."); } catch (IllegalStateException iae) { reader.afterPropertiesSet(); fail("Target Type was not set but exception was not thrown."); } catch (IllegalStateException iae) { reader.afterPropertiesSet(); fail("START was not set but exception was not thrown."); } catch (IllegalStateException iae) { reader.afterPropertiesSet(); fail("RETURN was not set but exception was not thrown."); } catch (IllegalStateException iae) { reader.afterPropertiesSet(); fail("ORDER BY was not set but exception was not thrown."); } catch (IllegalStateException iae) { reader.afterPropertiesSet(); reader.setOrderByStatement("n.age"); reader.afterPropertiesSet();
private Neo4jItemReader<String> buildSessionBasedReader() throws Exception { Neo4jItemReader<String> reader = new Neo4jItemReader<>(); reader.setSessionFactory(this.sessionFactory); reader.setTargetType(String.class); reader.setStartStatement("n=node(*)"); reader.setReturnStatement("*"); reader.setOrderByStatement("n.age"); reader.setPageSize(50); reader.afterPropertiesSet(); return reader; }