Replaced snapshot versions and addressed deprications
This commit moves all SNAPSHOT dependencies to the latest available released versions. It also addresses a number of deprications in the Spring Data realm. Specifically around the deprication of the Neo4JOperations and the package reorganization within Hibernate.
This commit is contained in:
14
build.gradle
14
build.gradle
@@ -48,16 +48,16 @@ allprojects {
|
||||
|
||||
environmentProperty = project.hasProperty('environment') ? getProperty('environment') : 'hsql'
|
||||
|
||||
springVersionDefault = '5.0.0.BUILD-SNAPSHOT'
|
||||
springVersionDefault = '5.0.0.M4'
|
||||
springVersion = project.hasProperty('springVersion') ? getProperty('springVersion') : springVersionDefault
|
||||
springRetryVersion = '1.1.3.RELEASE'
|
||||
springAmqpVersion = '1.5.6.RELEASE'
|
||||
springDataCommonsVersion = '2.0.0.BUILD-SNAPSHOT'
|
||||
springDataGemfireVersion = '2.0.0.BUILD-SNAPSHOT'
|
||||
springDataJpaVersion = '2.0.0.BUILD-SNAPSHOT'
|
||||
springDataMongodbVersion = '2.0.0.BUILD-SNAPSHOT'
|
||||
springDataNeo4jVersion = '5.0.0.BUILD-SNAPSHOT'
|
||||
springIntegrationVersion = '5.0.0.BUILD-SNAPSHOT'
|
||||
springDataCommonsVersion = '2.0.0.M1'
|
||||
springDataGemfireVersion = '2.0.0.M1'
|
||||
springDataJpaVersion = '2.0.0.M1'
|
||||
springDataMongodbVersion = '2.0.0.M1'
|
||||
springDataNeo4jVersion = '5.0.0.M1'
|
||||
springIntegrationVersion = '5.0.0.M1'
|
||||
springLdapVersion = '2.0.4.RELEASE'
|
||||
|
||||
activemqVersion = '5.13.2'
|
||||
|
||||
@@ -15,17 +15,14 @@
|
||||
*/
|
||||
package org.springframework.batch.core.resource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
import org.springframework.batch.item.database.JdbcCursorItemReader;
|
||||
import org.springframework.batch.item.database.support.ListPreparedStatementSetter;
|
||||
@@ -34,6 +31,9 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = "/org/springframework/batch/core/repository/dao/data-source-context.xml")
|
||||
public class JdbcCursorItemReaderPreparedStatementIntegrationTests {
|
||||
@@ -50,7 +50,7 @@ public class JdbcCursorItemReaderPreparedStatementIntegrationTests {
|
||||
@Before
|
||||
public void onSetUpInTransaction() throws Exception {
|
||||
|
||||
itemReader = new JdbcCursorItemReader<Foo>();
|
||||
itemReader = new JdbcCursorItemReader<>();
|
||||
itemReader.setDataSource(dataSource);
|
||||
itemReader.setSql("select ID, NAME, VALUE from T_FOOS where ID > ? and ID < ?");
|
||||
itemReader.setIgnoreWarnings(true);
|
||||
@@ -61,12 +61,11 @@ public class JdbcCursorItemReaderPreparedStatementIntegrationTests {
|
||||
itemReader.setMaxRows(100);
|
||||
itemReader.setQueryTimeout(1000);
|
||||
itemReader.setSaveState(true);
|
||||
ListPreparedStatementSetter pss = new ListPreparedStatementSetter();
|
||||
List<Long> parameters = new ArrayList<Long>();
|
||||
List<Long> parameters = new ArrayList<>();
|
||||
parameters.add(1L);
|
||||
parameters.add(4L);
|
||||
pss.setParameters(parameters);
|
||||
|
||||
ListPreparedStatementSetter pss = new ListPreparedStatementSetter(parameters);
|
||||
|
||||
itemReader.setPreparedStatementSetter(pss);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,11 +75,10 @@ public class ListPreparedStatementSetterTests {
|
||||
@Before
|
||||
public void onSetUpInTransaction() throws Exception {
|
||||
|
||||
pss = new ListPreparedStatementSetter();
|
||||
List<Long> parameters = new ArrayList<Long>();
|
||||
parameters.add(1L);
|
||||
parameters.add(4L);
|
||||
pss.setParameters(parameters);
|
||||
pss = new ListPreparedStatementSetter(parameters);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -103,7 +102,7 @@ public class ListPreparedStatementSetterTests {
|
||||
@Transactional
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testAfterPropertiesSet() throws Exception {
|
||||
pss.setParameters(null);
|
||||
pss = new ListPreparedStatementSetter(null);
|
||||
pss.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@@ -133,7 +132,7 @@ public class ListPreparedStatementSetterTests {
|
||||
}
|
||||
|
||||
public static class FooStoringItemWriter implements ItemWriter<Foo> {
|
||||
private List<Foo> foos = new ArrayList<Foo>();
|
||||
private List<Foo> foos = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public void write(List<? extends Foo> items) throws Exception {
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.util.Map;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.neo4j.ogm.session.SessionFactory;
|
||||
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
@@ -63,6 +64,7 @@ public abstract class AbstractNeo4jItemReader<T> extends
|
||||
protected Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private Neo4jOperations template;
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
private String startStatement;
|
||||
private String returnStatement;
|
||||
@@ -143,16 +145,31 @@ public abstract class AbstractNeo4jItemReader<T> extends
|
||||
this.orderByStatement = orderByStatement;
|
||||
}
|
||||
|
||||
protected SessionFactory getSessionFactory() {
|
||||
return sessionFactory;
|
||||
}
|
||||
|
||||
public void setSessionFactory(SessionFactory sessionFactory) {
|
||||
this.sessionFactory = sessionFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to perform operations against the Neo4J database.
|
||||
*
|
||||
* @param template the Neo4jOperations instance to use
|
||||
* @see Neo4jOperations
|
||||
* @deprecated Use {@link #setSessionFactory(SessionFactory)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setTemplate(Neo4jOperations template) {
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link Neo4jOperations}
|
||||
* @deprecated Use {@link #getSessionFactory()}
|
||||
*/
|
||||
@Deprecated
|
||||
protected final Neo4jOperations getTemplate() {
|
||||
return this.template;
|
||||
}
|
||||
@@ -197,7 +214,8 @@ public abstract class AbstractNeo4jItemReader<T> extends
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.state(template != null, "A Neo4JOperations implementation is required");
|
||||
Assert.state(template != null || sessionFactory != null,
|
||||
"A Neo4JOperations implementation or SessionFactory is required");
|
||||
Assert.state(targetType != null, "The type to be returned is required");
|
||||
Assert.state(StringUtils.hasText(startStatement), "A START statement is required");
|
||||
Assert.state(StringUtils.hasText(returnStatement), "A RETURN statement is required");
|
||||
|
||||
@@ -18,6 +18,9 @@ package org.springframework.batch.item.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.neo4j.ogm.session.Session;
|
||||
import org.neo4j.ogm.session.SessionFactory;
|
||||
//
|
||||
//import org.springframework.data.neo4j.conversion.ResultConverter;
|
||||
|
||||
@@ -32,8 +35,22 @@ public class Neo4jItemReader<T> extends AbstractNeo4jItemReader {
|
||||
|
||||
@Override
|
||||
protected Iterator<T> doPageRead() {
|
||||
Iterable queryResults = getTemplate().queryForObjects(
|
||||
getTargetType(), generateLimitCypherQuery(), getParameterValues());
|
||||
SessionFactory factory = getSessionFactory();
|
||||
|
||||
Iterable<T> queryResults;
|
||||
|
||||
if(factory != null) {
|
||||
Session session = factory.openSession();
|
||||
|
||||
queryResults = session.query(getTargetType(),
|
||||
generateLimitCypherQuery(),
|
||||
getParameterValues());
|
||||
}
|
||||
else {
|
||||
queryResults = getTemplate().queryForObjects(
|
||||
getTargetType(), generateLimitCypherQuery(), getParameterValues());
|
||||
|
||||
}
|
||||
|
||||
if(queryResults != null) {
|
||||
return queryResults.iterator();
|
||||
|
||||
@@ -20,6 +20,9 @@ import java.util.List;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.neo4j.ogm.session.Session;
|
||||
import org.neo4j.ogm.session.SessionFactory;
|
||||
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.data.neo4j.template.Neo4jOperations;
|
||||
@@ -28,8 +31,7 @@ import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* A {@link ItemWriter} implementation that writes to a Neo4j database using an
|
||||
* implementation of Spring Data's {@link Neo4jOperations}.
|
||||
* A {@link ItemWriter} implementation that writes to a Neo4j database.
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
@@ -49,6 +51,10 @@ public class Neo4jItemWriter<T> implements ItemWriter<T>, InitializingBean {
|
||||
|
||||
private Neo4jOperations template;
|
||||
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
private boolean useSession = false;
|
||||
|
||||
public void setDelete(boolean delete) {
|
||||
this.delete = delete;
|
||||
}
|
||||
@@ -57,11 +63,17 @@ public class Neo4jItemWriter<T> implements ItemWriter<T>, InitializingBean {
|
||||
* Set the {@link Neo4jOperations} to be used to save items
|
||||
*
|
||||
* @param template the template implementation to be used
|
||||
* @deprecated Use {@link #setSessionFactory(SessionFactory)}
|
||||
*/
|
||||
@Deprecated
|
||||
public void setTemplate(Neo4jOperations template) {
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
public void setSessionFactory(SessionFactory sessionFactory) {
|
||||
this.sessionFactory = sessionFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks mandatory properties
|
||||
*
|
||||
@@ -69,7 +81,10 @@ public class Neo4jItemWriter<T> implements ItemWriter<T>, InitializingBean {
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
Assert.state(template != null, "A Neo4JOperations implementation is required");
|
||||
Assert.state(template != null || this.sessionFactory != null,
|
||||
"A Neo4JOperations implementation or a SessionFactory is required");
|
||||
|
||||
this.useSession = this.sessionFactory != null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,13 +107,35 @@ public class Neo4jItemWriter<T> implements ItemWriter<T>, InitializingBean {
|
||||
*/
|
||||
protected void doWrite(List<? extends T> items) {
|
||||
if(delete) {
|
||||
for (T t : items) {
|
||||
template.delete(t);
|
||||
}
|
||||
delete(items);
|
||||
}
|
||||
else {
|
||||
for (T t : items) {
|
||||
template.save(t);
|
||||
save(items);
|
||||
}
|
||||
}
|
||||
|
||||
private void delete(List<? extends T> items) {
|
||||
if(this.useSession) {
|
||||
Session session = this.sessionFactory.openSession();
|
||||
|
||||
items.forEach(session::delete);
|
||||
}
|
||||
else {
|
||||
for (T item : items) {
|
||||
this.template.delete(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void save(List<? extends T> items) {
|
||||
if(this.useSession) {
|
||||
Session session = this.sessionFactory.openSession();
|
||||
|
||||
items.forEach(session::save);
|
||||
}
|
||||
else {
|
||||
for (T item : items) {
|
||||
this.template.save(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,12 +20,13 @@ import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.ScrollMode;
|
||||
import org.hibernate.ScrollableResults;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.StatelessSession;
|
||||
|
||||
import org.springframework.batch.item.database.orm.HibernateQueryProvider;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.batch.item.database.orm;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.StatelessSession;
|
||||
|
||||
|
||||
@@ -16,8 +16,9 @@
|
||||
|
||||
package org.springframework.batch.item.database.orm;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.SQLQuery;
|
||||
import org.hibernate.query.NativeQuery;
|
||||
import org.hibernate.query.Query;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -40,12 +41,12 @@ public class HibernateNativeQueryProvider<E> extends AbstractHibernateQueryProvi
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Create an {@link SQLQuery} from the session provided (preferring
|
||||
* Create an {@link NativeQuery} from the session provided (preferring
|
||||
* stateless if both are available).
|
||||
* </p>
|
||||
*/
|
||||
@Override
|
||||
public SQLQuery createQuery() {
|
||||
public NativeQuery createQuery() {
|
||||
|
||||
if (isStatelessSession()) {
|
||||
return getStatelessSession().createNativeQuery(sqlQuery).addEntity(entityClass);
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.batch.item.database.orm;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.StatelessSession;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
|
||||
@@ -25,6 +25,8 @@ import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.neo4j.ogm.session.Session;
|
||||
import org.neo4j.ogm.session.SessionFactory;
|
||||
|
||||
import org.springframework.data.neo4j.template.Neo4jOperations;
|
||||
|
||||
@@ -38,17 +40,22 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
public class Neo4jItemReaderTests {
|
||||
|
||||
private Neo4jItemReader<String> reader;
|
||||
@Mock
|
||||
private Neo4jOperations template;
|
||||
@Mock
|
||||
private Iterable<String> result;
|
||||
@Mock
|
||||
private SessionFactory sessionFactory;
|
||||
@Mock
|
||||
private Session session;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
reader = new Neo4jItemReader<String>();
|
||||
|
||||
MockitoAnnotations.initMocks(this);
|
||||
}
|
||||
|
||||
private Neo4jItemReader<String> buildTemplateBasedReader() throws Exception {
|
||||
Neo4jItemReader<String> reader = new Neo4jItemReader<>();
|
||||
|
||||
reader.setTemplate(template);
|
||||
reader.setTargetType(String.class);
|
||||
@@ -57,17 +64,33 @@ public class Neo4jItemReaderTests {
|
||||
reader.setOrderByStatement("n.age");
|
||||
reader.setPageSize(50);
|
||||
reader.afterPropertiesSet();
|
||||
|
||||
return reader;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterPropertiesSet() throws Exception {
|
||||
reader = new Neo4jItemReader<>();
|
||||
Neo4jItemReader<String> reader = new Neo4jItemReader<>();
|
||||
|
||||
try {
|
||||
reader.afterPropertiesSet();
|
||||
fail("Template was not set but exception was not thrown.");
|
||||
} catch (IllegalStateException iae) {
|
||||
assertEquals("A Neo4JOperations implementation is required", iae.getMessage());
|
||||
assertEquals("A Neo4JOperations implementation or SessionFactory is required", iae.getMessage());
|
||||
} catch (Throwable t) {
|
||||
fail("Wrong exception was thrown:" + t);
|
||||
}
|
||||
@@ -119,57 +142,134 @@ public class Neo4jItemReaderTests {
|
||||
reader.setOrderByStatement("n.age");
|
||||
|
||||
reader.afterPropertiesSet();
|
||||
|
||||
reader = new Neo4jItemReader<>();
|
||||
reader.setSessionFactory(this.sessionFactory);
|
||||
reader.setTargetType(String.class);
|
||||
reader.setStartStatement("n=node(*)");
|
||||
reader.setReturnStatement("n.name, n.phone");
|
||||
reader.setOrderByStatement("n.age");
|
||||
|
||||
reader.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testNullResults() {
|
||||
public void testNullResults() throws Exception {
|
||||
Neo4jItemReader<String> itemReader = buildTemplateBasedReader();
|
||||
|
||||
ArgumentCaptor<String> query = ArgumentCaptor.forClass(String.class);
|
||||
|
||||
when(template.queryForObjects(eq(String.class), query.capture(), (Map<String, Object>) isNull())).thenReturn(null);
|
||||
|
||||
assertFalse(reader.doPageRead().hasNext());
|
||||
assertFalse(itemReader.doPageRead().hasNext());
|
||||
assertEquals("START n=node(*) RETURN * ORDER BY n.age SKIP 0 LIMIT 50", query.getValue());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testNoResults() {
|
||||
public void testNullResultsWithSession() throws Exception {
|
||||
Neo4jItemReader<String> itemReader = buildSessionBasedReader();
|
||||
|
||||
ArgumentCaptor<String> query = ArgumentCaptor.forClass(String.class);
|
||||
|
||||
when(this.sessionFactory.openSession()).thenReturn(this.session);
|
||||
when(this.session.query(eq(String.class), query.capture(), (Map<String, Object>) isNull())).thenReturn(null);
|
||||
|
||||
assertFalse(itemReader.doPageRead().hasNext());
|
||||
assertEquals("START n=node(*) RETURN * ORDER BY n.age SKIP 0 LIMIT 50", query.getValue());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testNoResults() throws Exception {
|
||||
Neo4jItemReader<String> itemReader = buildTemplateBasedReader();
|
||||
ArgumentCaptor<String> query = ArgumentCaptor.forClass(String.class);
|
||||
|
||||
when(template.queryForObjects(eq(String.class), query.capture(), (Map<String, Object>) isNull())).thenReturn(result);
|
||||
when(result.iterator()).thenReturn(Collections.<String>emptyIterator());
|
||||
|
||||
assertFalse(reader.doPageRead().hasNext());
|
||||
assertFalse(itemReader.doPageRead().hasNext());
|
||||
assertEquals("START n=node(*) RETURN * ORDER BY n.age SKIP 0 LIMIT 50", query.getValue());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testNoResultsWithSession() throws Exception {
|
||||
Neo4jItemReader<String> itemReader = buildSessionBasedReader();
|
||||
ArgumentCaptor<String> query = ArgumentCaptor.forClass(String.class);
|
||||
|
||||
when(this.sessionFactory.openSession()).thenReturn(this.session);
|
||||
when(this.session.query(eq(String.class), query.capture(), (Map<String, Object>) isNull())).thenReturn(result);
|
||||
when(result.iterator()).thenReturn(Collections.emptyIterator());
|
||||
|
||||
assertFalse(itemReader.doPageRead().hasNext());
|
||||
assertEquals("START n=node(*) RETURN * ORDER BY n.age SKIP 0 LIMIT 50", query.getValue());
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@Test
|
||||
public void testResultsWithMatchAndWhere() throws Exception {
|
||||
reader.setMatchStatement("n -- m");
|
||||
reader.setWhereStatement("has(n.name)");
|
||||
reader.setReturnStatement("m");
|
||||
reader.afterPropertiesSet();
|
||||
Neo4jItemReader<String> itemReader = buildTemplateBasedReader();
|
||||
itemReader.setMatchStatement("n -- m");
|
||||
itemReader.setWhereStatement("has(n.name)");
|
||||
itemReader.setReturnStatement("m");
|
||||
itemReader.afterPropertiesSet();
|
||||
when(template.queryForObjects(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(reader.doPageRead().hasNext());
|
||||
assertTrue(itemReader.doPageRead().hasNext());
|
||||
}
|
||||
|
||||
@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 testResultsWithMatchAndWhereWithParameters() throws Exception {
|
||||
Neo4jItemReader<String> itemReader = buildTemplateBasedReader();
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("foo", "bar");
|
||||
reader.setParameterValues(params);
|
||||
reader.setMatchStatement("n -- m");
|
||||
reader.setWhereStatement("has(n.name)");
|
||||
reader.setReturnStatement("m");
|
||||
reader.afterPropertiesSet();
|
||||
itemReader.setParameterValues(params);
|
||||
itemReader.setMatchStatement("n -- m");
|
||||
itemReader.setWhereStatement("has(n.name)");
|
||||
itemReader.setReturnStatement("m");
|
||||
itemReader.afterPropertiesSet();
|
||||
when(template.queryForObjects(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(reader.doPageRead().hasNext());
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,11 +15,6 @@
|
||||
*/
|
||||
package org.springframework.batch.item.data;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -27,31 +22,41 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.neo4j.ogm.session.Session;
|
||||
import org.neo4j.ogm.session.SessionFactory;
|
||||
|
||||
import org.springframework.data.neo4j.template.Neo4jOperations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class Neo4jItemWriterTests {
|
||||
|
||||
private Neo4jItemWriter<String> writer;
|
||||
@Mock
|
||||
private Neo4jOperations template;
|
||||
@Mock
|
||||
private SessionFactory sessionFactory;
|
||||
@Mock
|
||||
private Session session;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
writer = new Neo4jItemWriter<String>();
|
||||
|
||||
writer.setTemplate(template);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterPropertiesSet() throws Exception{
|
||||
writer = new Neo4jItemWriter<String>();
|
||||
writer = new Neo4jItemWriter<>();
|
||||
|
||||
try {
|
||||
writer.afterPropertiesSet();
|
||||
fail("Template was not set but exception was not thrown.");
|
||||
} catch (IllegalStateException iae) {
|
||||
assertEquals("A Neo4JOperations implementation is required", iae.getMessage());
|
||||
assertEquals("A Neo4JOperations implementation or a SessionFactory is required", iae.getMessage());
|
||||
} catch (Throwable t) {
|
||||
fail("Wrong exception was thrown.");
|
||||
}
|
||||
@@ -59,25 +64,76 @@ public class Neo4jItemWriterTests {
|
||||
writer.setTemplate(template);
|
||||
|
||||
writer.afterPropertiesSet();
|
||||
|
||||
writer = new Neo4jItemWriter<>();
|
||||
|
||||
writer.setSessionFactory(this.sessionFactory);
|
||||
|
||||
writer.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteNull() throws Exception {
|
||||
writer = new Neo4jItemWriter<>();
|
||||
|
||||
writer.setTemplate(template);
|
||||
writer.afterPropertiesSet();
|
||||
|
||||
writer.write(null);
|
||||
|
||||
verifyZeroInteractions(template);
|
||||
verifyZeroInteractions(this.session);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteNoItems() throws Exception {
|
||||
writer.write(new ArrayList<String>());
|
||||
writer = new Neo4jItemWriter<>();
|
||||
|
||||
writer.setTemplate(template);
|
||||
writer.afterPropertiesSet();
|
||||
|
||||
writer.write(new ArrayList<>());
|
||||
|
||||
verifyZeroInteractions(template);
|
||||
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(template);
|
||||
verifyZeroInteractions(this.session);
|
||||
}
|
||||
|
||||
@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(template);
|
||||
verifyZeroInteractions(this.session);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteItems() throws Exception {
|
||||
List<String> items = new ArrayList<String>();
|
||||
writer = new Neo4jItemWriter<>();
|
||||
|
||||
writer.setTemplate(template);
|
||||
writer.afterPropertiesSet();
|
||||
|
||||
List<String> items = new ArrayList<>();
|
||||
items.add("foo");
|
||||
items.add("bar");
|
||||
|
||||
@@ -85,11 +141,37 @@ public class Neo4jItemWriterTests {
|
||||
|
||||
verify(template).save("foo");
|
||||
verify(template).save("bar");
|
||||
verifyZeroInteractions(this.session);
|
||||
verifyZeroInteractions(this.sessionFactory);
|
||||
}
|
||||
|
||||
@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");
|
||||
verifyZeroInteractions(template);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteItems() throws Exception {
|
||||
List<String> items = new ArrayList<String>();
|
||||
writer = new Neo4jItemWriter<>();
|
||||
|
||||
writer.setTemplate(template);
|
||||
writer.afterPropertiesSet();
|
||||
|
||||
List<String> items = new ArrayList<>();
|
||||
items.add("foo");
|
||||
items.add("bar");
|
||||
|
||||
@@ -99,5 +181,28 @@ public class Neo4jItemWriterTests {
|
||||
|
||||
verify(template).delete("foo");
|
||||
verify(template).delete("bar");
|
||||
verifyZeroInteractions(this.session);
|
||||
verifyZeroInteractions(this.sessionFactory);
|
||||
}
|
||||
|
||||
@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");
|
||||
verifyZeroInteractions(template);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.query.Query;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -86,7 +86,7 @@ public class HibernateNativeQueryProviderIntegrationTests {
|
||||
|
||||
Query query = hibernateQueryProvider.createQuery();
|
||||
|
||||
List<Foo> expectedFoos = new ArrayList<Foo>();
|
||||
List<Foo> expectedFoos = new ArrayList<>();
|
||||
|
||||
expectedFoos.add(new Foo(1, "bar1", 1));
|
||||
expectedFoos.add(new Foo(2, "bar2", 2));
|
||||
|
||||
@@ -66,7 +66,7 @@ public class AggregateItem<T> {
|
||||
private boolean header = false;
|
||||
|
||||
/**
|
||||
* @param item
|
||||
* @param item the item to wrap
|
||||
*/
|
||||
public AggregateItem(T item) {
|
||||
super();
|
||||
|
||||
@@ -48,8 +48,7 @@ public class AggregateItemReader<T> implements ItemReader<List<T>> {
|
||||
|
||||
/**
|
||||
* Get the next list of records.
|
||||
* @throws Exception
|
||||
*
|
||||
*
|
||||
* @see org.springframework.batch.item.ItemReader#read()
|
||||
*/
|
||||
@Override
|
||||
|
||||
@@ -56,7 +56,6 @@ public class OrderItemReader implements ItemReader<Order> {
|
||||
private ItemReader<FieldSet> fieldSetReader;
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @see org.springframework.batch.item.ItemReader#read()
|
||||
*/
|
||||
@Override
|
||||
|
||||
@@ -55,7 +55,8 @@ public class OrderLineAggregator implements LineAggregator<Order> {
|
||||
/**
|
||||
* Set aggregators for all types of lines in the output file
|
||||
*
|
||||
* @param aggregators
|
||||
* @param aggregators Map of LineAggregators used to map the various record types for
|
||||
* each order
|
||||
*/
|
||||
public void setAggregators(Map<String, LineAggregator<Object>> aggregators) {
|
||||
this.aggregators = aggregators;
|
||||
|
||||
@@ -75,8 +75,8 @@ public class CompositeCustomerUpdateLineTokenizer extends StepExecutionListenerS
|
||||
/**
|
||||
* Set the {@link LineTokenizer} that will be used to tokenize any lines that begin with
|
||||
* A, U, or D, and are thus a customer operation.
|
||||
*
|
||||
* @param customerTokenizer
|
||||
*
|
||||
* @param customerTokenizer tokenizer to delegate to for customer operation records
|
||||
*/
|
||||
public void setCustomerTokenizer(LineTokenizer customerTokenizer) {
|
||||
this.customerTokenizer = customerTokenizer;
|
||||
@@ -86,7 +86,7 @@ public class CompositeCustomerUpdateLineTokenizer extends StepExecutionListenerS
|
||||
* Set the {@link LineTokenizer} that will be used to tokenize any lines that being with
|
||||
* F and is thus a footer record.
|
||||
*
|
||||
* @param footerTokenizer
|
||||
* @param footerTokenizer tokenizer to delegate to for footer records
|
||||
*/
|
||||
public void setFooterTokenizer(LineTokenizer footerTokenizer) {
|
||||
this.footerTokenizer = footerTokenizer;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class Trade implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
* @param id id of the trade
|
||||
*/
|
||||
public Trade(long id) {
|
||||
this.id = id;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class LimitDecider implements JobExecutionDecider {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param limit
|
||||
* @param limit number of times to return "CONTINUE"
|
||||
*/
|
||||
public void setLimit(int limit) {
|
||||
this.limit = limit;
|
||||
|
||||
@@ -67,6 +67,7 @@ import org.springframework.context.ApplicationContextAware;
|
||||
*
|
||||
* @deprecated (from 2.1) use {@link JobLauncherTestUtils} instead
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract class AbstractJobTests implements ApplicationContextAware {
|
||||
|
||||
/** Logger */
|
||||
|
||||
Reference in New Issue
Block a user