Upgraded Spring Data versions
This commit upgrades the Spring Data versions to the latest snapshots
This commit is contained in:
19
build.gradle
19
build.gradle
@@ -52,11 +52,11 @@ allprojects {
|
|||||||
springVersion = project.hasProperty('springVersion') ? getProperty('springVersion') : springVersionDefault
|
springVersion = project.hasProperty('springVersion') ? getProperty('springVersion') : springVersionDefault
|
||||||
springRetryVersion = '1.2.0.RELEASE'
|
springRetryVersion = '1.2.0.RELEASE'
|
||||||
springAmqpVersion = '1.5.6.RELEASE'
|
springAmqpVersion = '1.5.6.RELEASE'
|
||||||
springDataCommonsVersion = '2.0.0.M1'
|
springDataCommonsVersion = '2.0.0.BUILD-SNAPSHOT'
|
||||||
springDataGemfireVersion = '2.0.0.M1'
|
springDataGemfireVersion = '2.0.0.BUILD-SNAPSHOT'
|
||||||
springDataJpaVersion = '2.0.0.M1'
|
springDataJpaVersion = '2.0.0.BUILD-SNAPSHOT'
|
||||||
springDataMongodbVersion = '2.0.0.M1'
|
springDataMongodbVersion = '2.0.0.BUILD-SNAPSHOT'
|
||||||
springDataNeo4jVersion = '5.0.0.M1'
|
springDataNeo4jVersion = '5.0.0.BUILD-SNAPSHOT'
|
||||||
springIntegrationVersion = '5.0.0.M1'
|
springIntegrationVersion = '5.0.0.M1'
|
||||||
springLdapVersion = '2.0.4.RELEASE'
|
springLdapVersion = '2.0.4.RELEASE'
|
||||||
|
|
||||||
@@ -264,7 +264,6 @@ project('spring-batch-core') {
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile project(":spring-batch-infrastructure")
|
compile project(":spring-batch-infrastructure")
|
||||||
|
|
||||||
compile "com.ibm.jbatch:com.ibm.jbatch-tck-spi:$jbatchTckSpi"
|
|
||||||
compile "com.fasterxml.jackson.core:jackson-databind:${jackson2Version}"
|
compile "com.fasterxml.jackson.core:jackson-databind:${jackson2Version}"
|
||||||
compile ("org.codehaus.jettison:jettison:$jettisonVersion") {
|
compile ("org.codehaus.jettison:jettison:$jettisonVersion") {
|
||||||
exclude group: 'stax', module: 'stax-api'
|
exclude group: 'stax', module: 'stax-api'
|
||||||
@@ -284,6 +283,7 @@ project('spring-batch-core') {
|
|||||||
testCompile "commons-dbcp:commons-dbcp:$commonsDdbcpVersion"
|
testCompile "commons-dbcp:commons-dbcp:$commonsDdbcpVersion"
|
||||||
testCompile "junit:junit:${junitVersion}"
|
testCompile "junit:junit:${junitVersion}"
|
||||||
testCompile "org.hamcrest:hamcrest-library:$hamcrestVersion"
|
testCompile "org.hamcrest:hamcrest-library:$hamcrestVersion"
|
||||||
|
optional "com.ibm.jbatch:com.ibm.jbatch-tck-spi:$jbatchTckSpi"
|
||||||
optional "com.thoughtworks.xstream:xstream:$xstreamVersion"
|
optional "com.thoughtworks.xstream:xstream:$xstreamVersion"
|
||||||
optional "org.aspectj:aspectjrt:$aspectjVersion"
|
optional "org.aspectj:aspectjrt:$aspectjVersion"
|
||||||
optional "org.aspectj:aspectjweaver:$aspectjVersion"
|
optional "org.aspectj:aspectjweaver:$aspectjVersion"
|
||||||
@@ -297,11 +297,8 @@ project('spring-batch-core') {
|
|||||||
|
|
||||||
project('spring-batch-infrastructure') {
|
project('spring-batch-infrastructure') {
|
||||||
description = 'Spring Batch Infrastructure'
|
description = 'Spring Batch Infrastructure'
|
||||||
|
|
||||||
test {
|
test {
|
||||||
// permsize settings not passed down from GRADLE_OPTS nor JAVA_OPTS
|
|
||||||
// when running certain tests causing permgen OOM when using JDK7
|
|
||||||
// compilation is not performed with JDK6 and permgen is removed
|
|
||||||
// starting with JDK8..
|
|
||||||
if (JavaVersion.current().isJava7Compatible()) {
|
if (JavaVersion.current().isJava7Compatible()) {
|
||||||
jvmArgs '-XX:MaxPermSize=256m'
|
jvmArgs '-XX:MaxPermSize=256m'
|
||||||
}
|
}
|
||||||
@@ -493,7 +490,7 @@ project('spring-batch-test') {
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile project(":spring-batch-core")
|
compile project(":spring-batch-core")
|
||||||
|
|
||||||
compile "junit:junit:${junitVersion}"
|
compile "junit:junit:${junitVersion}"
|
||||||
compile "org.hamcrest:hamcrest-library:$hamcrestVersion"
|
compile "org.hamcrest:hamcrest-library:$hamcrestVersion"
|
||||||
compile "org.springframework:spring-test:$springVersion"
|
compile "org.springframework:spring-test:$springVersion"
|
||||||
compile "org.springframework:spring-jdbc:$springVersion"
|
compile "org.springframework:spring-jdbc:$springVersion"
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import org.neo4j.ogm.session.SessionFactory;
|
|||||||
|
|
||||||
import org.springframework.batch.item.ItemReader;
|
import org.springframework.batch.item.ItemReader;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.data.neo4j.template.Neo4jOperations;
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
@@ -63,7 +62,6 @@ public abstract class AbstractNeo4jItemReader<T> extends
|
|||||||
|
|
||||||
protected Log logger = LogFactory.getLog(getClass());
|
protected Log logger = LogFactory.getLog(getClass());
|
||||||
|
|
||||||
private Neo4jOperations template;
|
|
||||||
private SessionFactory sessionFactory;
|
private SessionFactory sessionFactory;
|
||||||
|
|
||||||
private String startStatement;
|
private String startStatement;
|
||||||
@@ -153,27 +151,6 @@ public abstract class AbstractNeo4jItemReader<T> extends
|
|||||||
this.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The object type to be returned from each call to {@link #read()}
|
* The object type to be returned from each call to {@link #read()}
|
||||||
*
|
*
|
||||||
@@ -214,8 +191,7 @@ public abstract class AbstractNeo4jItemReader<T> extends
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
Assert.state(template != null || sessionFactory != null,
|
Assert.state(sessionFactory != null,"A SessionFactory is required");
|
||||||
"A Neo4JOperations implementation or SessionFactory is required");
|
|
||||||
Assert.state(targetType != null, "The type to be returned 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(startStatement), "A START statement is required");
|
||||||
Assert.state(StringUtils.hasText(returnStatement), "A RETURN statement is required");
|
Assert.state(StringUtils.hasText(returnStatement), "A RETURN statement is required");
|
||||||
|
|||||||
@@ -21,8 +21,6 @@ import java.util.Iterator;
|
|||||||
|
|
||||||
import org.neo4j.ogm.session.Session;
|
import org.neo4j.ogm.session.Session;
|
||||||
import org.neo4j.ogm.session.SessionFactory;
|
import org.neo4j.ogm.session.SessionFactory;
|
||||||
//
|
|
||||||
//import org.springframework.data.neo4j.conversion.ResultConverter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
@@ -39,18 +37,11 @@ public class Neo4jItemReader<T> extends AbstractNeo4jItemReader {
|
|||||||
|
|
||||||
Iterable<T> queryResults;
|
Iterable<T> queryResults;
|
||||||
|
|
||||||
if(factory != null) {
|
|
||||||
Session session = factory.openSession();
|
Session session = factory.openSession();
|
||||||
|
|
||||||
queryResults = session.query(getTargetType(),
|
queryResults = session.query(getTargetType(),
|
||||||
generateLimitCypherQuery(),
|
generateLimitCypherQuery(),
|
||||||
getParameterValues());
|
getParameterValues());
|
||||||
}
|
|
||||||
else {
|
|
||||||
queryResults = getTemplate().queryForObjects(
|
|
||||||
getTargetType(), generateLimitCypherQuery(), getParameterValues());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(queryResults != null) {
|
if(queryResults != null) {
|
||||||
return queryResults.iterator();
|
return queryResults.iterator();
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import org.neo4j.ogm.session.SessionFactory;
|
|||||||
|
|
||||||
import org.springframework.batch.item.ItemWriter;
|
import org.springframework.batch.item.ItemWriter;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.data.neo4j.template.Neo4jOperations;
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
@@ -49,27 +48,12 @@ public class Neo4jItemWriter<T> implements ItemWriter<T>, InitializingBean {
|
|||||||
|
|
||||||
private boolean delete = false;
|
private boolean delete = false;
|
||||||
|
|
||||||
private Neo4jOperations template;
|
|
||||||
|
|
||||||
private SessionFactory sessionFactory;
|
private SessionFactory sessionFactory;
|
||||||
|
|
||||||
private boolean useSession = false;
|
|
||||||
|
|
||||||
public void setDelete(boolean delete) {
|
public void setDelete(boolean delete) {
|
||||||
this.delete = delete;
|
this.delete = delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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) {
|
public void setSessionFactory(SessionFactory sessionFactory) {
|
||||||
this.sessionFactory = sessionFactory;
|
this.sessionFactory = sessionFactory;
|
||||||
}
|
}
|
||||||
@@ -81,10 +65,8 @@ public class Neo4jItemWriter<T> implements ItemWriter<T>, InitializingBean {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void afterPropertiesSet() throws Exception {
|
public void afterPropertiesSet() throws Exception {
|
||||||
Assert.state(template != null || this.sessionFactory != null,
|
Assert.state(this.sessionFactory != null,
|
||||||
"A Neo4JOperations implementation or a SessionFactory is required");
|
"A SessionFactory is required");
|
||||||
|
|
||||||
this.useSession = this.sessionFactory != null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -115,28 +97,18 @@ public class Neo4jItemWriter<T> implements ItemWriter<T>, InitializingBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void delete(List<? extends T> items) {
|
private void delete(List<? extends T> items) {
|
||||||
if(this.useSession) {
|
Session session = this.sessionFactory.openSession();
|
||||||
Session session = this.sessionFactory.openSession();
|
|
||||||
|
|
||||||
items.forEach(session::delete);
|
for(T item : items) {
|
||||||
}
|
session.delete(item);
|
||||||
else {
|
|
||||||
for (T item : items) {
|
|
||||||
this.template.delete(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void save(List<? extends T> items) {
|
private void save(List<? extends T> items) {
|
||||||
if(this.useSession) {
|
Session session = this.sessionFactory.openSession();
|
||||||
Session session = this.sessionFactory.openSession();
|
|
||||||
|
|
||||||
items.forEach(session::save);
|
for (T item : items) {
|
||||||
}
|
session.save(item);
|
||||||
else {
|
|
||||||
for (T item : items) {
|
|
||||||
this.template.save(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ import org.mockito.MockitoAnnotations;
|
|||||||
import org.neo4j.ogm.session.Session;
|
import org.neo4j.ogm.session.Session;
|
||||||
import org.neo4j.ogm.session.SessionFactory;
|
import org.neo4j.ogm.session.SessionFactory;
|
||||||
|
|
||||||
import org.springframework.data.neo4j.template.Neo4jOperations;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@@ -40,8 +38,6 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
public class Neo4jItemReaderTests {
|
public class Neo4jItemReaderTests {
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Neo4jOperations template;
|
|
||||||
@Mock
|
@Mock
|
||||||
private Iterable<String> result;
|
private Iterable<String> result;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -54,20 +50,6 @@ public class Neo4jItemReaderTests {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Neo4jItemReader<String> buildTemplateBasedReader() throws Exception {
|
|
||||||
Neo4jItemReader<String> reader = new Neo4jItemReader<>();
|
|
||||||
|
|
||||||
reader.setTemplate(template);
|
|
||||||
reader.setTargetType(String.class);
|
|
||||||
reader.setStartStatement("n=node(*)");
|
|
||||||
reader.setReturnStatement("*");
|
|
||||||
reader.setOrderByStatement("n.age");
|
|
||||||
reader.setPageSize(50);
|
|
||||||
reader.afterPropertiesSet();
|
|
||||||
|
|
||||||
return reader;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Neo4jItemReader<String> buildSessionBasedReader() throws Exception {
|
private Neo4jItemReader<String> buildSessionBasedReader() throws Exception {
|
||||||
Neo4jItemReader<String> reader = new Neo4jItemReader<>();
|
Neo4jItemReader<String> reader = new Neo4jItemReader<>();
|
||||||
|
|
||||||
@@ -84,22 +66,23 @@ public class Neo4jItemReaderTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAfterPropertiesSet() throws Exception {
|
public void testAfterPropertiesSet() throws Exception {
|
||||||
|
|
||||||
Neo4jItemReader<String> reader = new Neo4jItemReader<>();
|
Neo4jItemReader<String> reader = new Neo4jItemReader<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader.afterPropertiesSet();
|
reader.afterPropertiesSet();
|
||||||
fail("Template was not set but exception was not thrown.");
|
fail("SessionFactory was not set but exception was not thrown.");
|
||||||
} catch (IllegalStateException iae) {
|
} catch (IllegalStateException iae) {
|
||||||
assertEquals("A Neo4JOperations implementation or SessionFactory is required", iae.getMessage());
|
assertEquals("A SessionFactory is required", iae.getMessage());
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
fail("Wrong exception was thrown:" + t);
|
fail("Wrong exception was thrown:" + t);
|
||||||
}
|
}
|
||||||
|
|
||||||
reader.setTemplate(template);
|
reader.setSessionFactory(this.sessionFactory);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
reader.afterPropertiesSet();
|
reader.afterPropertiesSet();
|
||||||
fail("type was not set but exception was not thrown.");
|
fail("Target Type was not set but exception was not thrown.");
|
||||||
} catch (IllegalStateException iae) {
|
} catch (IllegalStateException iae) {
|
||||||
assertEquals("The type to be returned is required", iae.getMessage());
|
assertEquals("The type to be returned is required", iae.getMessage());
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
@@ -153,22 +136,10 @@ public class Neo4jItemReaderTests {
|
|||||||
reader.afterPropertiesSet();
|
reader.afterPropertiesSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Test
|
|
||||||
public void testNullResults() throws Exception {
|
|
||||||
Neo4jItemReader<String> itemReader = buildTemplateBasedReader();
|
|
||||||
|
|
||||||
ArgumentCaptor<String> query = ArgumentCaptor.forClass(String.class);
|
|
||||||
|
|
||||||
when(template.queryForObjects(eq(String.class), query.capture(), isNull())).thenReturn(null);
|
|
||||||
|
|
||||||
assertFalse(itemReader.doPageRead().hasNext());
|
|
||||||
assertEquals("START n=node(*) RETURN * ORDER BY n.age SKIP 0 LIMIT 50", query.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testNullResultsWithSession() throws Exception {
|
public void testNullResultsWithSession() throws Exception {
|
||||||
|
|
||||||
Neo4jItemReader<String> itemReader = buildSessionBasedReader();
|
Neo4jItemReader<String> itemReader = buildSessionBasedReader();
|
||||||
|
|
||||||
ArgumentCaptor<String> query = ArgumentCaptor.forClass(String.class);
|
ArgumentCaptor<String> query = ArgumentCaptor.forClass(String.class);
|
||||||
@@ -180,19 +151,6 @@ public class Neo4jItemReaderTests {
|
|||||||
assertEquals("START n=node(*) RETURN * ORDER BY n.age SKIP 0 LIMIT 50", query.getValue());
|
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(), 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("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Test
|
@Test
|
||||||
public void testNoResultsWithSession() throws Exception {
|
public void testNoResultsWithSession() throws Exception {
|
||||||
@@ -207,20 +165,6 @@ public class Neo4jItemReaderTests {
|
|||||||
assertEquals("START n=node(*) RETURN * ORDER BY n.age SKIP 0 LIMIT 50", query.getValue());
|
assertEquals("START n=node(*) RETURN * ORDER BY n.age SKIP 0 LIMIT 50", query.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
@Test
|
|
||||||
public void testResultsWithMatchAndWhere() throws Exception {
|
|
||||||
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(itemReader.doPageRead().hasNext());
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
@Test
|
@Test
|
||||||
public void testResultsWithMatchAndWhereWithSession() throws Exception {
|
public void testResultsWithMatchAndWhereWithSession() throws Exception {
|
||||||
@@ -237,23 +181,6 @@ public class Neo4jItemReaderTests {
|
|||||||
assertTrue(itemReader.doPageRead().hasNext());
|
assertTrue(itemReader.doPageRead().hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
|
||||||
@Test
|
|
||||||
public void testResultsWithMatchAndWhereWithParameters() throws Exception {
|
|
||||||
Neo4jItemReader<String> itemReader = buildTemplateBasedReader();
|
|
||||||
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(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(itemReader.doPageRead().hasNext());
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
@Test
|
@Test
|
||||||
public void testResultsWithMatchAndWhereWithParametersWithSession() throws Exception {
|
public void testResultsWithMatchAndWhereWithParametersWithSession() throws Exception {
|
||||||
|
|||||||
@@ -25,8 +25,6 @@ import org.mockito.MockitoAnnotations;
|
|||||||
import org.neo4j.ogm.session.Session;
|
import org.neo4j.ogm.session.Session;
|
||||||
import org.neo4j.ogm.session.SessionFactory;
|
import org.neo4j.ogm.session.SessionFactory;
|
||||||
|
|
||||||
import org.springframework.data.neo4j.template.Neo4jOperations;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@@ -36,8 +34,7 @@ import static org.mockito.Mockito.when;
|
|||||||
public class Neo4jItemWriterTests {
|
public class Neo4jItemWriterTests {
|
||||||
|
|
||||||
private Neo4jItemWriter<String> writer;
|
private Neo4jItemWriter<String> writer;
|
||||||
@Mock
|
|
||||||
private Neo4jOperations template;
|
|
||||||
@Mock
|
@Mock
|
||||||
private SessionFactory sessionFactory;
|
private SessionFactory sessionFactory;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -50,18 +47,19 @@ public class Neo4jItemWriterTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAfterPropertiesSet() throws Exception{
|
public void testAfterPropertiesSet() throws Exception{
|
||||||
|
|
||||||
writer = new Neo4jItemWriter<>();
|
writer = new Neo4jItemWriter<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
writer.afterPropertiesSet();
|
writer.afterPropertiesSet();
|
||||||
fail("Template was not set but exception was not thrown.");
|
fail("SessionFactory was not set but exception was not thrown.");
|
||||||
} catch (IllegalStateException iae) {
|
} catch (IllegalStateException iae) {
|
||||||
assertEquals("A Neo4JOperations implementation or a SessionFactory is required", iae.getMessage());
|
assertEquals("A SessionFactory is required", iae.getMessage());
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
fail("Wrong exception was thrown.");
|
fail("Wrong exception was thrown.");
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.setTemplate(template);
|
writer.setSessionFactory(this.sessionFactory);
|
||||||
|
|
||||||
writer.afterPropertiesSet();
|
writer.afterPropertiesSet();
|
||||||
|
|
||||||
@@ -73,28 +71,15 @@ public class Neo4jItemWriterTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWriteNull() throws Exception {
|
public void testWriteNullSession() throws Exception {
|
||||||
|
|
||||||
writer = new Neo4jItemWriter<>();
|
writer = new Neo4jItemWriter<>();
|
||||||
|
|
||||||
writer.setTemplate(template);
|
writer.setSessionFactory(this.sessionFactory);
|
||||||
writer.afterPropertiesSet();
|
writer.afterPropertiesSet();
|
||||||
|
|
||||||
writer.write(null);
|
writer.write(null);
|
||||||
|
|
||||||
verifyZeroInteractions(template);
|
|
||||||
verifyZeroInteractions(this.session);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWriteNoItems() throws Exception {
|
|
||||||
writer = new Neo4jItemWriter<>();
|
|
||||||
|
|
||||||
writer.setTemplate(template);
|
|
||||||
writer.afterPropertiesSet();
|
|
||||||
|
|
||||||
writer.write(new ArrayList<>());
|
|
||||||
|
|
||||||
verifyZeroInteractions(template);
|
|
||||||
verifyZeroInteractions(this.session);
|
verifyZeroInteractions(this.session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +93,6 @@ public class Neo4jItemWriterTests {
|
|||||||
when(this.sessionFactory.openSession()).thenReturn(this.session);
|
when(this.sessionFactory.openSession()).thenReturn(this.session);
|
||||||
writer.write(null);
|
writer.write(null);
|
||||||
|
|
||||||
verifyZeroInteractions(template);
|
|
||||||
verifyZeroInteractions(this.session);
|
verifyZeroInteractions(this.session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,29 +106,9 @@ public class Neo4jItemWriterTests {
|
|||||||
when(this.sessionFactory.openSession()).thenReturn(this.session);
|
when(this.sessionFactory.openSession()).thenReturn(this.session);
|
||||||
writer.write(new ArrayList<>());
|
writer.write(new ArrayList<>());
|
||||||
|
|
||||||
verifyZeroInteractions(template);
|
|
||||||
verifyZeroInteractions(this.session);
|
verifyZeroInteractions(this.session);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testWriteItems() throws Exception {
|
|
||||||
writer = new Neo4jItemWriter<>();
|
|
||||||
|
|
||||||
writer.setTemplate(template);
|
|
||||||
writer.afterPropertiesSet();
|
|
||||||
|
|
||||||
List<String> items = new ArrayList<>();
|
|
||||||
items.add("foo");
|
|
||||||
items.add("bar");
|
|
||||||
|
|
||||||
writer.write(items);
|
|
||||||
|
|
||||||
verify(template).save("foo");
|
|
||||||
verify(template).save("bar");
|
|
||||||
verifyZeroInteractions(this.session);
|
|
||||||
verifyZeroInteractions(this.sessionFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWriteItemsWithSession() throws Exception {
|
public void testWriteItemsWithSession() throws Exception {
|
||||||
writer = new Neo4jItemWriter<>();
|
writer = new Neo4jItemWriter<>();
|
||||||
@@ -161,28 +125,6 @@ public class Neo4jItemWriterTests {
|
|||||||
|
|
||||||
verify(this.session).save("foo");
|
verify(this.session).save("foo");
|
||||||
verify(this.session).save("bar");
|
verify(this.session).save("bar");
|
||||||
verifyZeroInteractions(template);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDeleteItems() throws Exception {
|
|
||||||
writer = new Neo4jItemWriter<>();
|
|
||||||
|
|
||||||
writer.setTemplate(template);
|
|
||||||
writer.afterPropertiesSet();
|
|
||||||
|
|
||||||
List<String> items = new ArrayList<>();
|
|
||||||
items.add("foo");
|
|
||||||
items.add("bar");
|
|
||||||
|
|
||||||
writer.setDelete(true);
|
|
||||||
|
|
||||||
writer.write(items);
|
|
||||||
|
|
||||||
verify(template).delete("foo");
|
|
||||||
verify(template).delete("bar");
|
|
||||||
verifyZeroInteractions(this.session);
|
|
||||||
verifyZeroInteractions(this.sessionFactory);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -203,6 +145,5 @@ public class Neo4jItemWriterTests {
|
|||||||
|
|
||||||
verify(this.session).delete("foo");
|
verify(this.session).delete("foo");
|
||||||
verify(this.session).delete("bar");
|
verify(this.session).delete("bar");
|
||||||
verifyZeroInteractions(template);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user