Polish Spring Batch Infrastructure tests
This commit is contained in:
committed by
Mahmoud Ben Hassine
parent
1e4a23e3eb
commit
e4056b4234
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.batch.repeat;
|
||||
package org.springframework.batch.common;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -23,19 +23,19 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
public abstract class AbstractExceptionTests {
|
||||
|
||||
@Test
|
||||
public void testExceptionString() throws Exception {
|
||||
void testExceptionString() {
|
||||
Exception exception = getException("foo");
|
||||
assertEquals("foo", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExceptionStringThrowable() throws Exception {
|
||||
void testExceptionStringThrowable() {
|
||||
Exception exception = getException("foo", new IllegalStateException());
|
||||
assertEquals("foo", exception.getMessage().substring(0, 3));
|
||||
}
|
||||
|
||||
public abstract Exception getException(String msg) throws Exception;
|
||||
protected abstract Exception getException(String msg);
|
||||
|
||||
public abstract Exception getException(String msg, Throwable t) throws Exception;
|
||||
protected abstract Exception getException(String msg, Throwable t);
|
||||
|
||||
}
|
||||
@@ -26,14 +26,14 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml")
|
||||
public class DatasourceTests {
|
||||
class DatasourceTests {
|
||||
|
||||
@Autowired
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Transactional
|
||||
@Test
|
||||
public void testTemplate() throws Exception {
|
||||
void testTemplate() {
|
||||
System.err.println(System.getProperty("java.class.path"));
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_BARS");
|
||||
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");
|
||||
|
||||
@@ -29,13 +29,13 @@ import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml")
|
||||
public class MessagingTests {
|
||||
class MessagingTests {
|
||||
|
||||
@Autowired
|
||||
private JmsTemplate jmsTemplate;
|
||||
|
||||
@BeforeEach
|
||||
public void onSetUp() throws Exception {
|
||||
void onSetUp() throws Exception {
|
||||
Thread.sleep(100L);
|
||||
getMessages(); // drain queue
|
||||
jmsTemplate.convertAndSend("queue", "foo");
|
||||
@@ -43,7 +43,7 @@ public class MessagingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessaging() throws Exception {
|
||||
void testMessaging() {
|
||||
List<String> list = getMessages();
|
||||
System.err.println(list);
|
||||
assertEquals(2, list.size());
|
||||
|
||||
@@ -48,11 +48,11 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Mahmoud Ben Hassine
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml")
|
||||
@DirtiesContext
|
||||
public class BatchMessageListenerContainerIntegrationTests {
|
||||
class BatchMessageListenerContainerIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private JmsTemplate jmsTemplate;
|
||||
@@ -60,13 +60,13 @@ public class BatchMessageListenerContainerIntegrationTests {
|
||||
@Autowired
|
||||
private BatchMessageListenerContainer container;
|
||||
|
||||
private volatile BlockingQueue<String> recovered = new LinkedBlockingQueue<>();
|
||||
private final BlockingQueue<String> recovered = new LinkedBlockingQueue<>();
|
||||
|
||||
private volatile BlockingQueue<String> processed = new LinkedBlockingQueue<>();
|
||||
private final BlockingQueue<String> processed = new LinkedBlockingQueue<>();
|
||||
|
||||
@AfterEach
|
||||
@BeforeEach
|
||||
public void drainQueue() throws Exception {
|
||||
void drainQueue() {
|
||||
container.stop();
|
||||
while (jmsTemplate.receiveAndConvert("queue") != null) {
|
||||
// do nothing
|
||||
@@ -75,17 +75,17 @@ public class BatchMessageListenerContainerIntegrationTests {
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void giveContainerTimeToStop() throws Exception {
|
||||
static void giveContainerTimeToStop() throws Exception {
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfiguration() throws Exception {
|
||||
void testConfiguration() {
|
||||
assertNotNull(container);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSendAndReceive() throws Exception {
|
||||
void testSendAndReceive() throws Exception {
|
||||
container.setMessageListener(new MessageListener() {
|
||||
@Override
|
||||
public void onMessage(Message msg) {
|
||||
@@ -109,7 +109,7 @@ public class BatchMessageListenerContainerIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailureAndRepresent() throws Exception {
|
||||
void testFailureAndRepresent() throws Exception {
|
||||
container.setMessageListener(new MessageListener() {
|
||||
@Override
|
||||
public void onMessage(Message msg) {
|
||||
@@ -131,7 +131,7 @@ public class BatchMessageListenerContainerIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFailureAndRecovery() throws Exception {
|
||||
void testFailureAndRecovery() throws Exception {
|
||||
final RetryTemplate retryTemplate = new RetryTemplate();
|
||||
retryTemplate.setRetryPolicy(new NeverRetryPolicy());
|
||||
container.setMessageListener(new MessageListener() {
|
||||
|
||||
@@ -35,17 +35,17 @@ import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class BatchMessageListenerContainerTests {
|
||||
class BatchMessageListenerContainerTests {
|
||||
|
||||
BatchMessageListenerContainer container;
|
||||
|
||||
@Test
|
||||
public void testReceiveAndExecuteWithCallback() throws Exception {
|
||||
void testReceiveAndExecuteWithCallback() throws Exception {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
template.setCompletionPolicy(new SimpleCompletionPolicy(2));
|
||||
container = getContainer(template);
|
||||
@@ -71,7 +71,7 @@ public class BatchMessageListenerContainerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReceiveAndExecuteWithCallbackReturningNull() throws Exception {
|
||||
void testReceiveAndExecuteWithCallbackReturningNull() throws Exception {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
template.setCompletionPolicy(new SimpleCompletionPolicy(2));
|
||||
container = getContainer(template);
|
||||
@@ -91,23 +91,18 @@ public class BatchMessageListenerContainerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTransactionalReceiveAndExecuteWithCallbackThrowingException() throws Exception {
|
||||
void testTransactionalReceiveAndExecuteWithCallbackThrowingException() {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
template.setCompletionPolicy(new SimpleCompletionPolicy(2));
|
||||
container = getContainer(template);
|
||||
container.setSessionTransacted(true);
|
||||
try {
|
||||
boolean received = doTestWithException(new IllegalStateException("No way!"), true, 2);
|
||||
assertFalse(received, "Message received");
|
||||
fail("Expected IllegalStateException");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
assertEquals("No way!", e.getMessage());
|
||||
}
|
||||
Exception exception = assertThrows(IllegalStateException.class,
|
||||
() -> doTestWithException(new IllegalStateException("No way!"), true, 2));
|
||||
assertEquals("No way!", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonTransactionalReceiveAndExecuteWithCallbackThrowingException() throws Exception {
|
||||
void testNonTransactionalReceiveAndExecuteWithCallbackThrowingException() throws Exception {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
template.setCompletionPolicy(new SimpleCompletionPolicy(2));
|
||||
container = getContainer(template);
|
||||
@@ -117,19 +112,13 @@ public class BatchMessageListenerContainerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonTransactionalReceiveAndExecuteWithCallbackThrowingError() throws Exception {
|
||||
void testNonTransactionalReceiveAndExecuteWithCallbackThrowingError() throws Exception {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
template.setCompletionPolicy(new SimpleCompletionPolicy(2));
|
||||
container = getContainer(template);
|
||||
container.setSessionTransacted(false);
|
||||
try {
|
||||
boolean received = doTestWithException(new RuntimeException("No way!"), false, 2);
|
||||
assertTrue(received, "Message not received but listener not transactional so this should be true");
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals("No way!", e.getMessage());
|
||||
fail("Unexpected Error - should be swallowed");
|
||||
}
|
||||
boolean received = doTestWithException(new RuntimeException("No way!"), false, 2);
|
||||
assertTrue(received, "Message not received but listener not transactional so this should be true");
|
||||
}
|
||||
|
||||
private BatchMessageListenerContainer getContainer(RepeatTemplate template) {
|
||||
|
||||
@@ -36,7 +36,7 @@ public abstract class AbstractItemReaderTests {
|
||||
protected abstract ItemReader<Foo> getItemReader() throws Exception;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
protected void setUp() throws Exception {
|
||||
tested = getItemReader();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ public abstract class AbstractItemReaderTests {
|
||||
* Regular scenario - read the input and eventually return null.
|
||||
*/
|
||||
@Test
|
||||
public void testRead() throws Exception {
|
||||
void testRead() throws Exception {
|
||||
|
||||
Foo foo1 = tested.read();
|
||||
assertEquals(1, foo1.getValue());
|
||||
@@ -68,7 +68,7 @@ public abstract class AbstractItemReaderTests {
|
||||
* Empty input should be handled gracefully - null is returned on first read.
|
||||
*/
|
||||
@Test
|
||||
public void testEmptyInput() throws Exception {
|
||||
void testEmptyInput() throws Exception {
|
||||
pointToEmptyInput(tested);
|
||||
tested.read();
|
||||
assertNull(tested.read());
|
||||
|
||||
@@ -39,13 +39,13 @@ public abstract class AbstractItemStreamItemReaderTests extends AbstractItemRead
|
||||
|
||||
@Override
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
testedAsStream().open(executionContext);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
protected void tearDown() throws Exception {
|
||||
testedAsStream().close();
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public abstract class AbstractItemStreamItemReaderTests extends AbstractItemRead
|
||||
* finished.
|
||||
*/
|
||||
@Test
|
||||
public void testRestart() throws Exception {
|
||||
protected void testRestart() throws Exception {
|
||||
|
||||
testedAsStream().update(executionContext);
|
||||
|
||||
@@ -84,7 +84,7 @@ public abstract class AbstractItemStreamItemReaderTests extends AbstractItemRead
|
||||
* should continue where the old one finished.
|
||||
*/
|
||||
@Test
|
||||
public void testResetAndRestart() throws Exception {
|
||||
void testResetAndRestart() throws Exception {
|
||||
|
||||
testedAsStream().update(executionContext);
|
||||
|
||||
@@ -111,7 +111,7 @@ public abstract class AbstractItemStreamItemReaderTests extends AbstractItemRead
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReopen() throws Exception {
|
||||
void testReopen() throws Exception {
|
||||
testedAsStream().update(executionContext);
|
||||
|
||||
Foo foo1 = tested.read();
|
||||
|
||||
@@ -18,12 +18,11 @@ package org.springframework.batch.item;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
@@ -32,17 +31,12 @@ import org.springframework.util.SerializationUtils;
|
||||
* @author Mahmoud Ben Hassine
|
||||
*
|
||||
*/
|
||||
public class ExecutionContextTests {
|
||||
class ExecutionContextTests {
|
||||
|
||||
private ExecutionContext context;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
context = new ExecutionContext();
|
||||
}
|
||||
private final ExecutionContext context = new ExecutionContext();
|
||||
|
||||
@Test
|
||||
public void testNormalUsage() {
|
||||
void testNormalUsage() {
|
||||
|
||||
context.putString("1", "testString1");
|
||||
context.putString("2", "testString2");
|
||||
@@ -62,27 +56,20 @@ public class ExecutionContextTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidCast() {
|
||||
|
||||
void testInvalidCast() {
|
||||
context.putLong("1", 1);
|
||||
try {
|
||||
context.getDouble("1");
|
||||
fail();
|
||||
}
|
||||
catch (ClassCastException ex) {
|
||||
// expected
|
||||
}
|
||||
assertThrows(ClassCastException.class, () -> context.getDouble("1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsEmpty() {
|
||||
void testIsEmpty() {
|
||||
assertTrue(context.isEmpty());
|
||||
context.putString("1", "test");
|
||||
assertFalse(context.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDirtyFlag() {
|
||||
void testDirtyFlag() {
|
||||
assertFalse(context.isDirty());
|
||||
context.putString("1", "test");
|
||||
assertTrue(context.isDirty());
|
||||
@@ -91,7 +78,7 @@ public class ExecutionContextTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotDirtyWithDuplicate() {
|
||||
void testNotDirtyWithDuplicate() {
|
||||
context.putString("1", "test");
|
||||
assertTrue(context.isDirty());
|
||||
context.clearDirtyFlag();
|
||||
@@ -100,7 +87,7 @@ public class ExecutionContextTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotDirtyWithRemoveMissing() {
|
||||
void testNotDirtyWithRemoveMissing() {
|
||||
context.putString("1", "test");
|
||||
assertTrue(context.isDirty());
|
||||
context.putString("1", null); // remove an item that was present
|
||||
@@ -110,14 +97,14 @@ public class ExecutionContextTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testContains() {
|
||||
void testContains() {
|
||||
context.putString("1", "testString");
|
||||
assertTrue(context.containsKey("1"));
|
||||
assertTrue(context.containsValue("testString"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals() {
|
||||
void testEquals() {
|
||||
context.putString("1", "testString");
|
||||
ExecutionContext tempContext = new ExecutionContext();
|
||||
assertFalse(tempContext.equals(context));
|
||||
@@ -129,19 +116,19 @@ public class ExecutionContextTests {
|
||||
* Putting null value is equivalent to removing the entry for the given key.
|
||||
*/
|
||||
@Test
|
||||
public void testPutNull() {
|
||||
void testPutNull() {
|
||||
context.put("1", null);
|
||||
assertNull(context.get("1"));
|
||||
assertFalse(context.containsKey("1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNull() {
|
||||
void testGetNull() {
|
||||
assertNull(context.get("does not exist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSerialization() {
|
||||
void testSerialization() {
|
||||
|
||||
TestSerializable s = new TestSerializable();
|
||||
s.value = 7;
|
||||
@@ -160,7 +147,7 @@ public class ExecutionContextTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyConstructor() throws Exception {
|
||||
void testCopyConstructor() {
|
||||
ExecutionContext context = new ExecutionContext();
|
||||
context.put("foo", "bar");
|
||||
ExecutionContext copy = new ExecutionContext(context);
|
||||
@@ -168,7 +155,7 @@ public class ExecutionContextTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCopyConstructorNullInput() throws Exception {
|
||||
void testCopyConstructorNullInput() {
|
||||
ExecutionContext context = new ExecutionContext((ExecutionContext) null);
|
||||
assertTrue(context.isEmpty());
|
||||
}
|
||||
@@ -176,7 +163,6 @@ public class ExecutionContextTests {
|
||||
/**
|
||||
* Value object for testing serialization
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
private static class TestSerializable implements Serializable {
|
||||
|
||||
int value;
|
||||
|
||||
@@ -19,25 +19,15 @@ package org.springframework.batch.item;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.retry.interceptor.MethodInvocationRecoverer;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
public class ItemRecoveryHandlerTests {
|
||||
class ItemRecoveryHandlerTests {
|
||||
|
||||
MethodInvocationRecoverer<String> recoverer = new MethodInvocationRecoverer<String>() {
|
||||
@Override
|
||||
public String recover(Object[] data, Throwable cause) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
private final MethodInvocationRecoverer<String> recoverer = (data, cause) -> null;
|
||||
|
||||
@Test
|
||||
public void testRecover() throws Exception {
|
||||
try {
|
||||
recoverer.recover(new Object[] { "foo" }, null);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("Unexpected Exception");
|
||||
}
|
||||
void testRecover() {
|
||||
assertDoesNotThrow(() -> recoverer.recover(new Object[] { "foo" }, null));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,21 +16,17 @@
|
||||
|
||||
package org.springframework.batch.item;
|
||||
|
||||
import org.springframework.batch.support.AbstractExceptionTests;
|
||||
import org.springframework.batch.common.AbstractExceptionTests;
|
||||
|
||||
public class ItemStreamExceptionTests extends AbstractExceptionTests {
|
||||
class ItemStreamExceptionTests extends AbstractExceptionTests {
|
||||
|
||||
@Override
|
||||
public Exception getException(String msg) throws Exception {
|
||||
protected Exception getException(String msg) {
|
||||
return new ItemStreamException(msg);
|
||||
}
|
||||
|
||||
public Exception getException(Throwable t) throws Exception {
|
||||
return new ItemStreamException(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Exception getException(String msg, Throwable t) throws Exception {
|
||||
protected Exception getException(String msg, Throwable t) {
|
||||
return new ItemStreamException(msg, t);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,17 +16,17 @@
|
||||
|
||||
package org.springframework.batch.item;
|
||||
|
||||
import org.springframework.batch.repeat.AbstractExceptionTests;
|
||||
import org.springframework.batch.common.AbstractExceptionTests;
|
||||
|
||||
public class UnexpectedInputExceptionTests extends AbstractExceptionTests {
|
||||
class UnexpectedInputExceptionTests extends AbstractExceptionTests {
|
||||
|
||||
@Override
|
||||
public Exception getException(String msg) throws Exception {
|
||||
protected Exception getException(String msg) {
|
||||
return new UnexpectedInputException(msg, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Exception getException(String msg, Throwable t) throws Exception {
|
||||
protected Exception getException(String msg, Throwable t) {
|
||||
return new UnexpectedInputException(msg, t);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,33 +19,32 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.batch.item.adapter.AbstractMethodInvokingDelegator.InvocationTargetThrowableWrapper;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* Tests for {@link AbstractMethodInvokingDelegator}
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class AbstractDelegatorTests {
|
||||
class AbstractDelegatorTests {
|
||||
|
||||
private static class ConcreteDelegator extends AbstractMethodInvokingDelegator<Foo> {
|
||||
|
||||
}
|
||||
|
||||
private AbstractMethodInvokingDelegator<Foo> delegator = new ConcreteDelegator();
|
||||
private final AbstractMethodInvokingDelegator<Foo> delegator = new ConcreteDelegator();
|
||||
|
||||
private Foo foo = new Foo("foo", 1);
|
||||
private final Foo foo = new Foo("foo", 1);
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
void setUp() {
|
||||
delegator.setTargetObject(foo);
|
||||
delegator.setArguments(null);
|
||||
}
|
||||
@@ -54,7 +53,7 @@ public class AbstractDelegatorTests {
|
||||
* Regular use - calling methods directly and via delegator leads to same results
|
||||
*/
|
||||
@Test
|
||||
public void testDelegation() throws Exception {
|
||||
void testDelegation() throws Exception {
|
||||
delegator.setTargetMethod("getName");
|
||||
delegator.afterPropertiesSet();
|
||||
|
||||
@@ -65,7 +64,7 @@ public class AbstractDelegatorTests {
|
||||
* Regular use - calling methods directly and via delegator leads to same results
|
||||
*/
|
||||
@Test
|
||||
public void testDelegationWithArgument() throws Exception {
|
||||
void testDelegationWithArgument() throws Exception {
|
||||
delegator.setTargetMethod("setName");
|
||||
final String NEW_FOO_NAME = "newFooName";
|
||||
delegator.afterPropertiesSet();
|
||||
@@ -75,7 +74,7 @@ public class AbstractDelegatorTests {
|
||||
|
||||
// using the arguments setter should work equally well
|
||||
foo.setName("foo");
|
||||
assertTrue(!foo.getName().equals(NEW_FOO_NAME));
|
||||
assertNotEquals(NEW_FOO_NAME, foo.getName());
|
||||
delegator.setArguments(new Object[] { NEW_FOO_NAME });
|
||||
delegator.afterPropertiesSet();
|
||||
delegator.invokeDelegateMethod();
|
||||
@@ -86,7 +85,7 @@ public class AbstractDelegatorTests {
|
||||
* Null argument value doesn't cause trouble when validating method signature.
|
||||
*/
|
||||
@Test
|
||||
public void testDelegationWithCheckedNullArgument() throws Exception {
|
||||
void testDelegationWithCheckedNullArgument() throws Exception {
|
||||
delegator.setTargetMethod("setName");
|
||||
delegator.setArguments(new Object[] { null });
|
||||
delegator.afterPropertiesSet();
|
||||
@@ -98,8 +97,7 @@ public class AbstractDelegatorTests {
|
||||
* Regular use - calling methods directly and via delegator leads to same results
|
||||
*/
|
||||
@Test
|
||||
@Disabled // FIXME
|
||||
public void testDelegationWithMultipleArguments() throws Exception {
|
||||
void testDelegationWithMultipleArguments() throws Exception {
|
||||
FooService fooService = new FooService();
|
||||
delegator.setTargetObject(fooService);
|
||||
delegator.setTargetMethod("processNameValuePair");
|
||||
@@ -118,61 +116,34 @@ public class AbstractDelegatorTests {
|
||||
* Exception scenario - target method is not declared by target object.
|
||||
*/
|
||||
@Test
|
||||
public void testInvalidMethodName() throws Exception {
|
||||
void testInvalidMethodName() {
|
||||
delegator.setTargetMethod("not-existing-method-name");
|
||||
|
||||
try {
|
||||
delegator.afterPropertiesSet();
|
||||
fail("Expected IllegalStateException");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
|
||||
try {
|
||||
delegator.invokeDelegateMethod();
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
assertThrows(IllegalStateException.class, delegator::afterPropertiesSet);
|
||||
assertThrows(IllegalArgumentException.class, delegator::invokeDelegateMethod);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception scenario - target method is called with invalid arguments.
|
||||
*/
|
||||
@Test
|
||||
public void testInvalidArgumentsForExistingMethod() throws Exception {
|
||||
void testInvalidArgumentsForExistingMethod() throws Exception {
|
||||
delegator.setTargetMethod("setName");
|
||||
delegator.afterPropertiesSet();
|
||||
try {
|
||||
delegator.invokeDelegateMethodWithArgument(new Object());
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
assertThrows(IllegalArgumentException.class, () -> delegator.invokeDelegateMethodWithArgument(new Object()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception scenario - target method is called with incorrect number of arguments.
|
||||
*/
|
||||
@Test
|
||||
public void testTooFewArguments() throws Exception {
|
||||
void testTooFewArguments() throws Exception {
|
||||
delegator.setTargetMethod("setName");
|
||||
delegator.afterPropertiesSet();
|
||||
try {
|
||||
// single argument expected but none provided
|
||||
delegator.invokeDelegateMethod();
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
assertThrows(IllegalArgumentException.class, delegator::invokeDelegateMethod);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTooManyArguments() throws Exception {
|
||||
void testTooManyArguments() throws Exception {
|
||||
delegator.setTargetMethod("setName");
|
||||
// single argument expected but two provided
|
||||
delegator.invokeDelegateMethodWithArguments(new Object[] { "name", "anotherName" });
|
||||
@@ -183,28 +154,16 @@ public class AbstractDelegatorTests {
|
||||
* Exception scenario - incorrect static arguments set.
|
||||
*/
|
||||
@Test
|
||||
public void testIncorrectNumberOfStaticArguments() throws Exception {
|
||||
void testIncorrectNumberOfStaticArguments() {
|
||||
delegator.setTargetMethod("setName");
|
||||
|
||||
// incorrect argument count
|
||||
delegator.setArguments(new Object[] { "first", "second" });
|
||||
try {
|
||||
delegator.afterPropertiesSet();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
assertThrows(IllegalStateException.class, delegator::afterPropertiesSet);
|
||||
|
||||
// correct argument count, but invalid argument type
|
||||
delegator.setArguments(new Object[] { new Object() });
|
||||
try {
|
||||
delegator.afterPropertiesSet();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
assertThrows(IllegalStateException.class, delegator::afterPropertiesSet);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -212,17 +171,11 @@ public class AbstractDelegatorTests {
|
||||
* Such 'business' exception should be re-thrown as is (without wrapping).
|
||||
*/
|
||||
@Test
|
||||
public void testDelegateException() throws Exception {
|
||||
void testDelegateException() throws Exception {
|
||||
delegator.setTargetMethod("fail");
|
||||
delegator.afterPropertiesSet();
|
||||
try {
|
||||
delegator.invokeDelegateMethod();
|
||||
fail();
|
||||
}
|
||||
catch (Exception expected) {
|
||||
assertEquals(Foo.FAILURE_MESSAGE, expected.getMessage());
|
||||
}
|
||||
|
||||
Exception expected = assertThrows(Exception.class, delegator::invokeDelegateMethod);
|
||||
assertEquals(Foo.FAILURE_MESSAGE, expected.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,16 +183,11 @@ public class AbstractDelegatorTests {
|
||||
* {@link Throwable} (not an {@link Exception}).
|
||||
*/
|
||||
@Test
|
||||
public void testDelegateThrowable() throws Exception {
|
||||
void testDelegateThrowable() throws Exception {
|
||||
delegator.setTargetMethod("failUgly");
|
||||
delegator.afterPropertiesSet();
|
||||
try {
|
||||
delegator.invokeDelegateMethod();
|
||||
fail();
|
||||
}
|
||||
catch (InvocationTargetThrowableWrapper expected) {
|
||||
assertEquals(Foo.UGLY_FAILURE_MESSAGE, expected.getCause().getMessage());
|
||||
}
|
||||
Exception expected = assertThrows(InvocationTargetThrowableWrapper.class, delegator::invokeDelegateMethod);
|
||||
assertEquals(Foo.UGLY_FAILURE_MESSAGE, expected.getCause().getMessage());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
@@ -23,10 +23,10 @@ import java.util.TreeSet;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class HippyMethodInvokerTests {
|
||||
class HippyMethodInvokerTests {
|
||||
|
||||
@Test
|
||||
public void testVanillaMethodInvoker() throws Exception {
|
||||
void testVanillaMethodInvoker() {
|
||||
TestMethodAdapter adapter = new TestMethodAdapter();
|
||||
adapter.setTargetMethod("handle");
|
||||
adapter.setTargetObject(new PlainPojo());
|
||||
@@ -34,7 +34,7 @@ public class HippyMethodInvokerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyParameters() throws Exception {
|
||||
void testEmptyParameters() {
|
||||
TestMethodAdapter adapter = new TestMethodAdapter();
|
||||
adapter.setTargetMethod("empty");
|
||||
adapter.setTargetObject(new PlainPojo());
|
||||
@@ -42,7 +42,7 @@ public class HippyMethodInvokerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyParametersEmptyArgs() throws Exception {
|
||||
void testEmptyParametersEmptyArgs() {
|
||||
TestMethodAdapter adapter = new TestMethodAdapter();
|
||||
adapter.setTargetMethod("empty");
|
||||
adapter.setTargetObject(new PlainPojo());
|
||||
@@ -50,7 +50,7 @@ public class HippyMethodInvokerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingArgument() throws Exception {
|
||||
void testMissingArgument() {
|
||||
TestMethodAdapter adapter = new TestMethodAdapter();
|
||||
adapter.setTargetMethod("missing");
|
||||
adapter.setTargetObject(new PlainPojo());
|
||||
@@ -58,7 +58,7 @@ public class HippyMethodInvokerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongOrder() throws Exception {
|
||||
void testWrongOrder() {
|
||||
TestMethodAdapter adapter = new TestMethodAdapter();
|
||||
adapter.setTargetMethod("disorder");
|
||||
adapter.setTargetObject(new PlainPojo());
|
||||
@@ -66,7 +66,7 @@ public class HippyMethodInvokerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTwoArgsOfSameTypeWithInexactMatch() throws Exception {
|
||||
void testTwoArgsOfSameTypeWithInexactMatch() throws Exception {
|
||||
HippyMethodInvoker invoker = new HippyMethodInvoker();
|
||||
invoker.setTargetMethod("duplicate");
|
||||
invoker.setTargetObject(new PlainPojo());
|
||||
@@ -76,7 +76,7 @@ public class HippyMethodInvokerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverloadedMethodUsingInputWithoutExactMatch() throws Exception {
|
||||
void testOverloadedMethodUsingInputWithoutExactMatch() throws Exception {
|
||||
|
||||
HippyMethodInvoker invoker = new HippyMethodInvoker();
|
||||
invoker.setTargetMethod("foo");
|
||||
@@ -105,7 +105,7 @@ public class HippyMethodInvokerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverloadedMethodWithTwoArgumentsAndOneExactMatch() throws Exception {
|
||||
void testOverloadedMethodWithTwoArgumentsAndOneExactMatch() throws Exception {
|
||||
|
||||
HippyMethodInvoker invoker = new HippyMethodInvoker();
|
||||
invoker.setTargetMethod("foo");
|
||||
|
||||
@@ -28,13 +28,13 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@SpringJUnitConfig(locations = "delegating-item-processor.xml")
|
||||
public class ItemProcessorAdapterTests {
|
||||
class ItemProcessorAdapterTests {
|
||||
|
||||
@Autowired
|
||||
private ItemProcessorAdapter<Foo, String> processor;
|
||||
|
||||
@Test
|
||||
public void testProcess() throws Exception {
|
||||
void testProcess() throws Exception {
|
||||
Foo item = new Foo(0, "foo", 1);
|
||||
assertEquals("foo", processor.process(item));
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.junit.jupiter.api.Test;
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
@SpringJUnitConfig(locations = "delegating-item-provider.xml")
|
||||
public class ItemReaderAdapterTests {
|
||||
class ItemReaderAdapterTests {
|
||||
|
||||
@Autowired
|
||||
private ItemReaderAdapter<Foo> provider;
|
||||
@@ -45,7 +45,7 @@ public class ItemReaderAdapterTests {
|
||||
* points to.
|
||||
*/
|
||||
@Test
|
||||
public void testNext() throws Exception {
|
||||
void testNext() throws Exception {
|
||||
List<Object> returnedItems = new ArrayList<>();
|
||||
Object item;
|
||||
while ((item = provider.read()) != null) {
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
@SpringJUnitConfig(locations = "delegating-item-writer.xml")
|
||||
public class ItemWriterAdapterTests {
|
||||
class ItemWriterAdapterTests {
|
||||
|
||||
@Autowired
|
||||
private ItemWriter<Foo> processor;
|
||||
@@ -48,7 +48,7 @@ public class ItemWriterAdapterTests {
|
||||
* invoker points to.
|
||||
*/
|
||||
@Test
|
||||
public void testProcess() throws Exception {
|
||||
void testProcess() throws Exception {
|
||||
Foo foo;
|
||||
List<Foo> foos = new ArrayList<>();
|
||||
while ((foo = fooService.generateFoo()) != null) {
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
@SpringJUnitConfig(locations = "pe-delegating-item-writer.xml")
|
||||
public class PropertyExtractingDelegatingItemProcessorIntegrationTests {
|
||||
class PropertyExtractingDelegatingItemProcessorIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private PropertyExtractingDelegatingItemWriter<Foo> processor;
|
||||
@@ -46,7 +46,7 @@ public class PropertyExtractingDelegatingItemProcessorIntegrationTests {
|
||||
* invoker points to.
|
||||
*/
|
||||
@Test
|
||||
public void testProcess() throws Exception {
|
||||
void testProcess() throws Exception {
|
||||
Foo foo;
|
||||
while ((foo = fooService.generateFoo()) != null) {
|
||||
processor.write(Collections.singletonList(foo));
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.amqp.core.Message;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -36,15 +35,15 @@ import static org.junit.jupiter.api.Assertions.fail;
|
||||
* @author Chris Schaefer
|
||||
* @author Will Schipp
|
||||
*/
|
||||
public class AmqpItemReaderTests {
|
||||
class AmqpItemReaderTests {
|
||||
|
||||
@Test
|
||||
public void testNullAmqpTemplate() {
|
||||
void testNullAmqpTemplate() {
|
||||
assertThrows(IllegalArgumentException.class, () -> new AmqpItemReader<String>(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoItemType() {
|
||||
void testNoItemType() {
|
||||
final AmqpTemplate amqpTemplate = mock(AmqpTemplate.class);
|
||||
when(amqpTemplate.receiveAndConvert()).thenReturn("foo");
|
||||
|
||||
@@ -53,7 +52,7 @@ public class AmqpItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonMessageItemType() {
|
||||
void testNonMessageItemType() {
|
||||
final AmqpTemplate amqpTemplate = mock(AmqpTemplate.class);
|
||||
when(amqpTemplate.receiveAndConvert()).thenReturn("foo");
|
||||
|
||||
@@ -65,7 +64,7 @@ public class AmqpItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageItemType() {
|
||||
void testMessageItemType() {
|
||||
final AmqpTemplate amqpTemplate = mock(AmqpTemplate.class);
|
||||
final Message message = mock(Message.class);
|
||||
|
||||
@@ -79,7 +78,7 @@ public class AmqpItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTypeMismatch() {
|
||||
void testTypeMismatch() {
|
||||
final AmqpTemplate amqpTemplate = mock(AmqpTemplate.class);
|
||||
|
||||
when(amqpTemplate.receiveAndConvert()).thenReturn("foo");
|
||||
@@ -87,18 +86,13 @@ public class AmqpItemReaderTests {
|
||||
final AmqpItemReader<Integer> amqpItemReader = new AmqpItemReader<>(amqpTemplate);
|
||||
amqpItemReader.setItemType(Integer.class);
|
||||
|
||||
try {
|
||||
amqpItemReader.read();
|
||||
fail("Expected IllegalStateException");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
assertTrue(e.getMessage().contains("wrong type"));
|
||||
}
|
||||
Exception exception = assertThrows(IllegalStateException.class, amqpItemReader::read);
|
||||
assertTrue(exception.getMessage().contains("wrong type"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullItemType() {
|
||||
void testNullItemType() {
|
||||
final AmqpTemplate amqpTemplate = mock(AmqpTemplate.class);
|
||||
|
||||
final AmqpItemReader<String> amqpItemReader = new AmqpItemReader<>(amqpTemplate);
|
||||
|
||||
@@ -32,15 +32,15 @@ import java.util.Arrays;
|
||||
* @author Chris Schaefer
|
||||
* @author Will Schipp
|
||||
*/
|
||||
public class AmqpItemWriterTests {
|
||||
class AmqpItemWriterTests {
|
||||
|
||||
@Test
|
||||
public void testNullAmqpTemplate() {
|
||||
void testNullAmqpTemplate() {
|
||||
assertThrows(IllegalArgumentException.class, () -> new AmqpItemWriter<String>(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void voidTestWrite() throws Exception {
|
||||
void voidTestWrite() throws Exception {
|
||||
AmqpTemplate amqpTemplate = mock(AmqpTemplate.class);
|
||||
|
||||
amqpTemplate.convertAndSend("foo");
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.amqp.core.Message;
|
||||
import org.springframework.batch.item.amqp.AmqpItemReader;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -33,13 +33,13 @@ import static org.mockito.Mockito.when;
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class AmqpItemReaderBuilderTests {
|
||||
class AmqpItemReaderBuilderTests {
|
||||
|
||||
@Mock
|
||||
AmqpTemplate amqpTemplate;
|
||||
|
||||
@Test
|
||||
public void testNoItemType() {
|
||||
void testNoItemType() {
|
||||
when(this.amqpTemplate.receiveAndConvert()).thenReturn("foo");
|
||||
|
||||
final AmqpItemReader<String> amqpItemReader = new AmqpItemReaderBuilder<String>()
|
||||
@@ -48,7 +48,7 @@ public class AmqpItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonMessageItemType() {
|
||||
void testNonMessageItemType() {
|
||||
when(this.amqpTemplate.receiveAndConvert()).thenReturn("foo");
|
||||
|
||||
final AmqpItemReader<String> amqpItemReader = new AmqpItemReaderBuilder<String>()
|
||||
@@ -58,7 +58,7 @@ public class AmqpItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMessageItemType() {
|
||||
void testMessageItemType() {
|
||||
final Message message = mock(Message.class);
|
||||
|
||||
when(this.amqpTemplate.receive()).thenReturn(message);
|
||||
@@ -70,15 +70,10 @@ public class AmqpItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullAmqpTemplate() {
|
||||
try {
|
||||
new AmqpItemReaderBuilder<Message>().build();
|
||||
fail("IllegalArgumentException should have been thrown");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("amqpTemplate is required.", iae.getMessage(),
|
||||
"IllegalArgumentException message did not match the expected result.");
|
||||
}
|
||||
void testNullAmqpTemplate() {
|
||||
Exception exception = assertThrows(IllegalArgumentException.class,
|
||||
() -> new AmqpItemReaderBuilder<Message>().build());
|
||||
assertEquals("amqpTemplate is required.", exception.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,30 +24,25 @@ import org.springframework.amqp.core.AmqpTemplate;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import org.springframework.batch.item.amqp.AmqpItemWriter;
|
||||
|
||||
import static org.aspectj.bridge.MessageUtil.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
public class AmqpItemWriterBuilderTests {
|
||||
class AmqpItemWriterBuilderTests {
|
||||
|
||||
@Test
|
||||
public void testNullAmqpTemplate() {
|
||||
try {
|
||||
new AmqpItemWriterBuilder<Message>().build();
|
||||
fail("IllegalArgumentException should have been thrown");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("amqpTemplate is required.", iae.getMessage(),
|
||||
"IllegalArgumentException message did not match the expected result.");
|
||||
}
|
||||
void testNullAmqpTemplate() {
|
||||
Exception exception = assertThrows(IllegalArgumentException.class,
|
||||
() -> new AmqpItemWriterBuilder<Message>().build());
|
||||
assertEquals("amqpTemplate is required.", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void voidTestWrite() throws Exception {
|
||||
void voidTestWrite() throws Exception {
|
||||
AmqpTemplate amqpTemplate = mock(AmqpTemplate.class);
|
||||
|
||||
AmqpItemWriter<String> amqpItemWriter = new AmqpItemWriterBuilder<String>().amqpTemplate(amqpTemplate).build();
|
||||
|
||||
@@ -28,10 +28,10 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
/**
|
||||
* @author David Turanski
|
||||
*/
|
||||
public class AvroItemReaderTests extends AvroItemReaderTestSupport {
|
||||
class AvroItemReaderTests extends AvroItemReaderTestSupport {
|
||||
|
||||
@Test
|
||||
public void readGenericRecordsUsingResources() throws Exception {
|
||||
void readGenericRecordsUsingResources() throws Exception {
|
||||
|
||||
AvroItemReader<GenericRecord> itemReader = new AvroItemReader<>(dataResource, schemaResource);
|
||||
itemReader.setName(itemReader.getClass().getSimpleName());
|
||||
@@ -41,7 +41,7 @@ public class AvroItemReaderTests extends AvroItemReaderTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readSpecificUsers() throws Exception {
|
||||
void readSpecificUsers() throws Exception {
|
||||
|
||||
AvroItemReader<User> itemReader = new AvroItemReader<>(dataResource, User.class);
|
||||
itemReader.setEmbeddedSchema(false);
|
||||
@@ -51,7 +51,7 @@ public class AvroItemReaderTests extends AvroItemReaderTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readSpecificUsersWithEmbeddedSchema() throws Exception {
|
||||
void readSpecificUsersWithEmbeddedSchema() throws Exception {
|
||||
|
||||
AvroItemReader<User> itemReader = new AvroItemReader<>(dataResourceWithSchema, User.class);
|
||||
itemReader.setEmbeddedSchema(true);
|
||||
@@ -61,7 +61,7 @@ public class AvroItemReaderTests extends AvroItemReaderTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readPojosWithNoEmbeddedSchema() throws Exception {
|
||||
void readPojosWithNoEmbeddedSchema() throws Exception {
|
||||
|
||||
AvroItemReader<PlainOldUser> itemReader = new AvroItemReader<>(plainOldUserDataResource, PlainOldUser.class);
|
||||
itemReader.setEmbeddedSchema(false);
|
||||
@@ -71,13 +71,13 @@ public class AvroItemReaderTests extends AvroItemReaderTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dataResourceDoesNotExist() {
|
||||
void dataResourceDoesNotExist() {
|
||||
assertThrows(IllegalStateException.class,
|
||||
() -> new AvroItemReader<User>(new ClassPathResource("doesnotexist"), schemaResource));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void schemaResourceDoesNotExist() {
|
||||
void schemaResourceDoesNotExist() {
|
||||
assertThrows(IllegalStateException.class,
|
||||
() -> new AvroItemReader<User>(dataResource, new ClassPathResource("doesnotexist")));
|
||||
}
|
||||
|
||||
@@ -32,14 +32,14 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
* @author David Turanski
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class AvroItemWriterTests extends AvroItemWriterTestSupport {
|
||||
class AvroItemWriterTests extends AvroItemWriterTestSupport {
|
||||
|
||||
private ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048);
|
||||
private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048);
|
||||
|
||||
private WritableResource output = new OutputStreamResource(outputStream);
|
||||
private final WritableResource output = new OutputStreamResource(outputStream);
|
||||
|
||||
@Test
|
||||
public void itemWriterForAvroGeneratedClass() throws Exception {
|
||||
void itemWriterForAvroGeneratedClass() throws Exception {
|
||||
|
||||
AvroItemWriter<User> avroItemWriter = new AvroItemWriter<>(this.output, this.schemaResource, User.class);
|
||||
avroItemWriter.open(new ExecutionContext());
|
||||
@@ -50,7 +50,7 @@ public class AvroItemWriterTests extends AvroItemWriterTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemWriterForGenericRecords() throws Exception {
|
||||
void itemWriterForGenericRecords() throws Exception {
|
||||
|
||||
AvroItemWriter<GenericRecord> avroItemWriter = new AvroItemWriter<>(this.output,
|
||||
this.plainOldUserSchemaResource, GenericRecord.class);
|
||||
@@ -65,7 +65,7 @@ public class AvroItemWriterTests extends AvroItemWriterTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemWriterForPojos() throws Exception {
|
||||
void itemWriterForPojos() throws Exception {
|
||||
|
||||
AvroItemWriter<PlainOldUser> avroItemWriter = new AvroItemWriter<>(this.output, this.plainOldUserSchemaResource,
|
||||
PlainOldUser.class);
|
||||
@@ -78,7 +78,7 @@ public class AvroItemWriterTests extends AvroItemWriterTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemWriterWithNoEmbeddedHeaders() throws Exception {
|
||||
void itemWriterWithNoEmbeddedHeaders() throws Exception {
|
||||
|
||||
AvroItemWriter<PlainOldUser> avroItemWriter = new AvroItemWriter<>(this.output, PlainOldUser.class);
|
||||
avroItemWriter.open(new ExecutionContext());
|
||||
@@ -90,13 +90,13 @@ public class AvroItemWriterTests extends AvroItemWriterTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailWitNoOutput() {
|
||||
void shouldFailWitNoOutput() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new AvroItemWriter<>(null, this.schemaResource, User.class).open(new ExecutionContext()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailWitNoType() {
|
||||
void shouldFailWitNoType() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new AvroItemWriter<>(this.output, this.schemaResource, null).open(new ExecutionContext()));
|
||||
}
|
||||
|
||||
@@ -28,10 +28,10 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
/**
|
||||
* @author David Turanski
|
||||
*/
|
||||
public class AvroItemReaderBuilderTests extends AvroItemReaderTestSupport {
|
||||
class AvroItemReaderBuilderTests extends AvroItemReaderTestSupport {
|
||||
|
||||
@Test
|
||||
public void itemReaderWithSchemaResource() throws Exception {
|
||||
void itemReaderWithSchemaResource() throws Exception {
|
||||
|
||||
AvroItemReader<GenericRecord> avroItemReader = new AvroItemReaderBuilder<GenericRecord>().resource(dataResource)
|
||||
.embeddedSchema(false).schema(schemaResource).build();
|
||||
@@ -40,14 +40,14 @@ public class AvroItemReaderBuilderTests extends AvroItemReaderTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemReaderWithGeneratedData() throws Exception {
|
||||
void itemReaderWithGeneratedData() throws Exception {
|
||||
AvroItemReader<GenericRecord> avroItemReader = new AvroItemReaderBuilder<GenericRecord>()
|
||||
.resource(dataResourceWithSchema).schema(schemaResource).build();
|
||||
verify(avroItemReader, genericAvroGeneratedUsers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemReaderWithSchemaString() throws Exception {
|
||||
void itemReaderWithSchemaString() throws Exception {
|
||||
AvroItemReader<GenericRecord> avroItemReader = new AvroItemReaderBuilder<GenericRecord>()
|
||||
.schema(schemaString(schemaResource)).resource(dataResourceWithSchema).build();
|
||||
|
||||
@@ -55,33 +55,33 @@ public class AvroItemReaderBuilderTests extends AvroItemReaderTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemReaderWithEmbeddedHeader() throws Exception {
|
||||
void itemReaderWithEmbeddedHeader() throws Exception {
|
||||
AvroItemReader<User> avroItemReader = new AvroItemReaderBuilder<User>().resource(dataResourceWithSchema)
|
||||
.type(User.class).build();
|
||||
verify(avroItemReader, avroGeneratedUsers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemReaderForSpecificType() throws Exception {
|
||||
void itemReaderForSpecificType() throws Exception {
|
||||
AvroItemReader<User> avroItemReader = new AvroItemReaderBuilder<User>().type(User.class)
|
||||
.resource(dataResourceWithSchema).build();
|
||||
verify(avroItemReader, avroGeneratedUsers());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemReaderWithNoSchemaStringShouldFail() {
|
||||
void itemReaderWithNoSchemaStringShouldFail() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new AvroItemReaderBuilder<GenericRecord>().schema("").resource(dataResource).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemReaderWithPartialConfigurationShouldFail() {
|
||||
void itemReaderWithPartialConfigurationShouldFail() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new AvroItemReaderBuilder<GenericRecord>().resource(dataResource).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemReaderWithNoInputsShouldFail() {
|
||||
void itemReaderWithNoInputsShouldFail() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new AvroItemReaderBuilder<GenericRecord>().schema(schemaResource).build());
|
||||
}
|
||||
|
||||
@@ -32,14 +32,14 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
/**
|
||||
* @author David Turanski
|
||||
*/
|
||||
public class AvroItemWriterBuilderTests extends AvroItemWriterTestSupport {
|
||||
class AvroItemWriterBuilderTests extends AvroItemWriterTestSupport {
|
||||
|
||||
private ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048);
|
||||
private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(2048);
|
||||
|
||||
private WritableResource output = new OutputStreamResource(outputStream);
|
||||
private final WritableResource output = new OutputStreamResource(outputStream);
|
||||
|
||||
@Test
|
||||
public void itemWriterForAvroGeneratedClass() throws Exception {
|
||||
void itemWriterForAvroGeneratedClass() throws Exception {
|
||||
|
||||
AvroItemWriter<User> avroItemWriter = new AvroItemWriterBuilder<User>().resource(output).schema(schemaResource)
|
||||
.type(User.class).build();
|
||||
@@ -52,7 +52,7 @@ public class AvroItemWriterBuilderTests extends AvroItemWriterTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemWriterForGenericRecords() throws Exception {
|
||||
void itemWriterForGenericRecords() throws Exception {
|
||||
|
||||
AvroItemWriter<GenericRecord> avroItemWriter = new AvroItemWriterBuilder<GenericRecord>()
|
||||
.type(GenericRecord.class).schema(plainOldUserSchemaResource).resource(output).build();
|
||||
@@ -66,7 +66,7 @@ public class AvroItemWriterBuilderTests extends AvroItemWriterTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemWriterForPojos() throws Exception {
|
||||
void itemWriterForPojos() throws Exception {
|
||||
|
||||
AvroItemWriter<PlainOldUser> avroItemWriter = new AvroItemWriterBuilder<PlainOldUser>().resource(output)
|
||||
.schema(plainOldUserSchemaResource).type(PlainOldUser.class).build();
|
||||
@@ -80,7 +80,7 @@ public class AvroItemWriterBuilderTests extends AvroItemWriterTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void itemWriterWithNoEmbeddedSchema() throws Exception {
|
||||
void itemWriterWithNoEmbeddedSchema() throws Exception {
|
||||
|
||||
AvroItemWriter<PlainOldUser> avroItemWriter = new AvroItemWriterBuilder<PlainOldUser>().resource(output)
|
||||
.type(PlainOldUser.class).build();
|
||||
@@ -93,13 +93,13 @@ public class AvroItemWriterBuilderTests extends AvroItemWriterTestSupport {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailWitNoOutput() {
|
||||
void shouldFailWitNoOutput() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new AvroItemWriterBuilder<GenericRecord>().type(GenericRecord.class).build());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailWitNoType() {
|
||||
void shouldFailWitNoType() {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new AvroItemWriterBuilder<>().resource(output).schema(schemaResource).build());
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.batch.item.data;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
|
||||
@@ -32,7 +32,7 @@ import org.springframework.data.gemfire.GemfireTemplate;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class GemfireItemWriterTests {
|
||||
class GemfireItemWriterTests {
|
||||
|
||||
private GemfireItemWriter<String, Foo> writer;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class GemfireItemWriterTests {
|
||||
private GemfireTemplate template;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
void setUp() throws Exception {
|
||||
writer = new GemfireItemWriter<>();
|
||||
writer.setTemplate(template);
|
||||
writer.setItemKeyMapper(new SpELItemKeyMapper<>("bar.val"));
|
||||
@@ -48,30 +48,19 @@ public class GemfireItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterPropertiesSet() throws Exception {
|
||||
void testAfterPropertiesSet() throws Exception {
|
||||
writer = new GemfireItemWriter<>();
|
||||
|
||||
try {
|
||||
writer.afterPropertiesSet();
|
||||
fail("Expected exception was not thrown");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
}
|
||||
assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet);
|
||||
|
||||
writer.setTemplate(template);
|
||||
try {
|
||||
writer.afterPropertiesSet();
|
||||
fail("Expected exception was not thrown");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
}
|
||||
assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet);
|
||||
|
||||
writer.setItemKeyMapper(new SpELItemKeyMapper<>("foo"));
|
||||
writer.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicWrite() throws Exception {
|
||||
void testBasicWrite() throws Exception {
|
||||
List<Foo> items = new ArrayList<Foo>() {
|
||||
{
|
||||
add(new Foo(new Bar("val1")));
|
||||
@@ -86,7 +75,7 @@ public class GemfireItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicDelete() throws Exception {
|
||||
void testBasicDelete() throws Exception {
|
||||
List<Foo> items = new ArrayList<Foo>() {
|
||||
{
|
||||
add(new Foo(new Bar("val1")));
|
||||
@@ -101,7 +90,7 @@ public class GemfireItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteWithCustomItemKeyMapper() throws Exception {
|
||||
void testWriteWithCustomItemKeyMapper() throws Exception {
|
||||
List<Foo> items = new ArrayList<Foo>() {
|
||||
{
|
||||
add(new Foo(new Bar("val1")));
|
||||
@@ -126,7 +115,7 @@ public class GemfireItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteNoTransactionNoItems() throws Exception {
|
||||
void testWriteNoTransactionNoItems() throws Exception {
|
||||
writer.write(null);
|
||||
verifyNoInteractions(template);
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -45,7 +45,7 @@ import static org.mockito.Mockito.when;
|
||||
* @author Parikshit Dutta
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class MongoItemReaderTests {
|
||||
class MongoItemReaderTests {
|
||||
|
||||
private MongoItemReader<String> reader;
|
||||
|
||||
@@ -55,7 +55,7 @@ public class MongoItemReaderTests {
|
||||
private Map<String, Sort.Direction> sortOptions;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
void setUp() throws Exception {
|
||||
reader = new MongoItemReader<>();
|
||||
|
||||
sortOptions = new HashMap<>();
|
||||
@@ -70,66 +70,32 @@ public class MongoItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterPropertiesSetForQueryString() throws Exception {
|
||||
void testAfterPropertiesSetForQueryString() throws Exception {
|
||||
reader = new MongoItemReader<>();
|
||||
|
||||
try {
|
||||
reader.afterPropertiesSet();
|
||||
fail("Template was not set but exception was not thrown.");
|
||||
}
|
||||
catch (IllegalStateException iae) {
|
||||
assertEquals("An implementation of MongoOperations is required.", iae.getMessage());
|
||||
}
|
||||
catch (Throwable t) {
|
||||
fail("Wrong exception was thrown.");
|
||||
}
|
||||
Exception exception = assertThrows(IllegalStateException.class, reader::afterPropertiesSet);
|
||||
assertEquals("An implementation of MongoOperations is required.", exception.getMessage());
|
||||
|
||||
reader.setTemplate(template);
|
||||
|
||||
try {
|
||||
reader.afterPropertiesSet();
|
||||
fail("type was not set but exception was not thrown.");
|
||||
}
|
||||
catch (IllegalStateException iae) {
|
||||
assertEquals("A type to convert the input into is required.", iae.getMessage());
|
||||
}
|
||||
catch (Throwable t) {
|
||||
fail("Wrong exception was thrown.");
|
||||
}
|
||||
exception = assertThrows(IllegalStateException.class, reader::afterPropertiesSet);
|
||||
assertEquals("A type to convert the input into is required.", exception.getMessage());
|
||||
|
||||
reader.setTargetType(String.class);
|
||||
|
||||
try {
|
||||
reader.afterPropertiesSet();
|
||||
fail("Query was not set but exception was not thrown.");
|
||||
}
|
||||
catch (IllegalStateException iae) {
|
||||
assertEquals("A query is required.", iae.getMessage());
|
||||
}
|
||||
catch (Throwable t) {
|
||||
fail("Wrong exception was thrown.");
|
||||
}
|
||||
exception = assertThrows(IllegalStateException.class, reader::afterPropertiesSet);
|
||||
assertEquals("A query is required.", exception.getMessage());
|
||||
|
||||
reader.setQuery("");
|
||||
|
||||
try {
|
||||
reader.afterPropertiesSet();
|
||||
fail("Sort was not set but exception was not thrown.");
|
||||
}
|
||||
catch (IllegalStateException iae) {
|
||||
assertEquals("A sort is required.", iae.getMessage());
|
||||
}
|
||||
catch (Throwable t) {
|
||||
fail("Wrong exception was thrown.");
|
||||
}
|
||||
exception = assertThrows(IllegalStateException.class, reader::afterPropertiesSet);
|
||||
assertEquals("A sort is required.", exception.getMessage());
|
||||
|
||||
reader.setSort(sortOptions);
|
||||
|
||||
reader.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterPropertiesSetForQueryObject() throws Exception {
|
||||
void testAfterPropertiesSetForQueryObject() throws Exception {
|
||||
reader = new MongoItemReader<>();
|
||||
|
||||
reader.setTemplate(template);
|
||||
@@ -142,7 +108,7 @@ public class MongoItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicQueryFirstPage() {
|
||||
void testBasicQueryFirstPage() {
|
||||
ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
|
||||
|
||||
when(template.find(queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
|
||||
@@ -157,7 +123,7 @@ public class MongoItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicQuerySecondPage() {
|
||||
void testBasicQuerySecondPage() {
|
||||
reader.page = 2;
|
||||
ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
|
||||
|
||||
@@ -175,7 +141,7 @@ public class MongoItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryWithFields() {
|
||||
void testQueryWithFields() {
|
||||
reader.setFields("{name : 1, age : 1, _id: 0}");
|
||||
ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
|
||||
|
||||
@@ -194,7 +160,7 @@ public class MongoItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryWithHint() {
|
||||
void testQueryWithHint() {
|
||||
reader.setHint("{ $natural : 1}");
|
||||
ArgumentCaptor<Query> queryContainer = ArgumentCaptor.forClass(Query.class);
|
||||
|
||||
@@ -211,7 +177,7 @@ public class MongoItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryWithParameters() {
|
||||
void testQueryWithParameters() {
|
||||
reader.setParameterValues(Collections.singletonList("foo"));
|
||||
|
||||
reader.setQuery("{ name : ?0 }");
|
||||
@@ -229,7 +195,7 @@ public class MongoItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryWithCollection() {
|
||||
void testQueryWithCollection() {
|
||||
reader.setParameterValues(Collections.singletonList("foo"));
|
||||
|
||||
reader.setQuery("{ name : ?0 }");
|
||||
@@ -251,7 +217,7 @@ public class MongoItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryObject() throws Exception {
|
||||
void testQueryObject() throws Exception {
|
||||
reader = new MongoItemReader<>();
|
||||
reader.setTemplate(template);
|
||||
|
||||
@@ -273,7 +239,7 @@ public class MongoItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryObjectWithIgnoredPageSize() throws Exception {
|
||||
void testQueryObjectWithIgnoredPageSize() throws Exception {
|
||||
reader = new MongoItemReader<>();
|
||||
reader.setTemplate(template);
|
||||
|
||||
@@ -295,7 +261,7 @@ public class MongoItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryObjectWithPageSize() throws Exception {
|
||||
void testQueryObjectWithPageSize() throws Exception {
|
||||
reader = new MongoItemReader<>();
|
||||
reader.setTemplate(template);
|
||||
|
||||
@@ -318,7 +284,7 @@ public class MongoItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryObjectWithoutLimit() throws Exception {
|
||||
void testQueryObjectWithoutLimit() throws Exception {
|
||||
reader = new MongoItemReader<>();
|
||||
reader.setTemplate(template);
|
||||
|
||||
@@ -338,7 +304,7 @@ public class MongoItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryObjectWithoutLimitAndPageSize() throws Exception {
|
||||
void testQueryObjectWithoutLimitAndPageSize() throws Exception {
|
||||
reader = new MongoItemReader<>();
|
||||
reader.setTemplate(template);
|
||||
|
||||
@@ -357,7 +323,7 @@ public class MongoItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryObjectWithCollection() throws Exception {
|
||||
void testQueryObjectWithCollection() throws Exception {
|
||||
reader = new MongoItemReader<>();
|
||||
reader.setTemplate(template);
|
||||
|
||||
@@ -383,7 +349,7 @@ public class MongoItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortThrowsExceptionWhenInvokedWithNull() {
|
||||
void testSortThrowsExceptionWhenInvokedWithNull() {
|
||||
// given
|
||||
reader = new MongoItemReader<>();
|
||||
|
||||
|
||||
@@ -23,10 +23,10 @@ import java.util.List;
|
||||
import org.bson.Document;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
@@ -36,7 +36,8 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.never;
|
||||
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
import org.springframework.batch.support.transaction.ResourcelessTransactionManager;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.mongodb.core.BulkOperations;
|
||||
@@ -53,7 +54,6 @@ import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
@@ -63,8 +63,8 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||
* @author Parikshit Dutta
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class MongoItemWriterTests {
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class MongoItemWriterTests {
|
||||
|
||||
private MongoItemWriter<Object> writer;
|
||||
|
||||
@@ -77,16 +77,16 @@ public class MongoItemWriterTests {
|
||||
@Mock
|
||||
DbRefResolver dbRefResolver;
|
||||
|
||||
private PlatformTransactionManager transactionManager = new ResourcelessTransactionManager();
|
||||
private final PlatformTransactionManager transactionManager = new ResourcelessTransactionManager();
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
lenient().when(this.template.bulkOps(any(), anyString())).thenReturn(this.bulkOperations);
|
||||
lenient().when(this.template.bulkOps(any(), any(Class.class))).thenReturn(this.bulkOperations);
|
||||
void setUp() throws Exception {
|
||||
when(this.template.bulkOps(any(), anyString())).thenReturn(this.bulkOperations);
|
||||
when(this.template.bulkOps(any(), any(Class.class))).thenReturn(this.bulkOperations);
|
||||
|
||||
MappingContext<MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext = new MongoMappingContext();
|
||||
MappingMongoConverter mongoConverter = spy(new MappingMongoConverter(this.dbRefResolver, mappingContext));
|
||||
lenient().when(this.template.getConverter()).thenReturn(mongoConverter);
|
||||
when(this.template.getConverter()).thenReturn(mongoConverter);
|
||||
|
||||
writer = new MongoItemWriter<>();
|
||||
writer.setTemplate(template);
|
||||
@@ -94,22 +94,16 @@ public class MongoItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterPropertiesSet() throws Exception {
|
||||
void testAfterPropertiesSet() throws Exception {
|
||||
writer = new MongoItemWriter<>();
|
||||
|
||||
try {
|
||||
writer.afterPropertiesSet();
|
||||
fail("Expected exception was not thrown");
|
||||
}
|
||||
catch (IllegalStateException ignore) {
|
||||
}
|
||||
assertThrows(IllegalStateException.class, writer::afterPropertiesSet);
|
||||
|
||||
writer.setTemplate(template);
|
||||
writer.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteNoTransactionNoCollection() throws Exception {
|
||||
void testWriteNoTransactionNoCollection() throws Exception {
|
||||
List<Item> items = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
|
||||
writer.write(items);
|
||||
@@ -119,7 +113,7 @@ public class MongoItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteNoTransactionWithCollection() throws Exception {
|
||||
void testWriteNoTransactionWithCollection() throws Exception {
|
||||
List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
|
||||
writer.setCollection("collection");
|
||||
@@ -131,7 +125,7 @@ public class MongoItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteNoTransactionNoItems() throws Exception {
|
||||
void testWriteNoTransactionNoItems() throws Exception {
|
||||
writer.write(null);
|
||||
|
||||
verifyNoInteractions(template);
|
||||
@@ -139,17 +133,11 @@ public class MongoItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteTransactionNoCollection() throws Exception {
|
||||
void testWriteTransactionNoCollection() {
|
||||
final List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
|
||||
new TransactionTemplate(transactionManager).execute((TransactionCallback<Void>) status -> {
|
||||
try {
|
||||
writer.write(items);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An exception was thrown while writing: " + e.getMessage());
|
||||
}
|
||||
|
||||
assertDoesNotThrow(() -> writer.write(items));
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -158,19 +146,13 @@ public class MongoItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteTransactionWithCollection() throws Exception {
|
||||
void testWriteTransactionWithCollection() {
|
||||
final List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
|
||||
writer.setCollection("collection");
|
||||
|
||||
new TransactionTemplate(transactionManager).execute((TransactionCallback<Void>) status -> {
|
||||
try {
|
||||
writer.write(items);
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("An exception was thrown while writing: " + e.getMessage());
|
||||
}
|
||||
|
||||
assertDoesNotThrow(() -> writer.write(items));
|
||||
return null;
|
||||
});
|
||||
|
||||
@@ -179,28 +161,17 @@ public class MongoItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteTransactionFails() throws Exception {
|
||||
void testWriteTransactionFails() {
|
||||
final List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
|
||||
writer.setCollection("collection");
|
||||
|
||||
try {
|
||||
new TransactionTemplate(transactionManager).execute((TransactionCallback<Void>) status -> {
|
||||
try {
|
||||
writer.write(items);
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
fail("unexpected exception thrown");
|
||||
}
|
||||
throw new RuntimeException("force rollback");
|
||||
});
|
||||
}
|
||||
catch (RuntimeException re) {
|
||||
assertEquals(re.getMessage(), "force rollback");
|
||||
}
|
||||
catch (Throwable t) {
|
||||
fail("Unexpected exception was thrown");
|
||||
}
|
||||
Exception exception = assertThrows(RuntimeException.class,
|
||||
() -> new TransactionTemplate(transactionManager).execute((TransactionCallback<Void>) status -> {
|
||||
assertDoesNotThrow(() -> writer.write(items));
|
||||
throw new RuntimeException("force rollback");
|
||||
}));
|
||||
assertEquals(exception.getMessage(), "force rollback");
|
||||
|
||||
verifyNoInteractions(template);
|
||||
verifyNoInteractions(bulkOperations);
|
||||
@@ -211,34 +182,24 @@ public class MongoItemWriterTests {
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public void testWriteTransactionReadOnly() throws Exception {
|
||||
void testWriteTransactionReadOnly() {
|
||||
final List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
|
||||
writer.setCollection("collection");
|
||||
|
||||
try {
|
||||
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
|
||||
transactionTemplate.setReadOnly(true);
|
||||
transactionTemplate.execute((TransactionCallback<Void>) status -> {
|
||||
try {
|
||||
writer.write(items);
|
||||
}
|
||||
catch (Exception ignore) {
|
||||
fail("unexpected exception thrown");
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
catch (Throwable t) {
|
||||
fail("Unexpected exception was thrown");
|
||||
}
|
||||
TransactionTemplate transactionTemplate = new TransactionTemplate(transactionManager);
|
||||
transactionTemplate.setReadOnly(true);
|
||||
transactionTemplate.execute((TransactionCallback<Void>) status -> {
|
||||
assertDoesNotThrow(() -> writer.write(items));
|
||||
return null;
|
||||
});
|
||||
|
||||
verifyNoInteractions(template);
|
||||
verifyNoInteractions(bulkOperations);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveNoObjectIdNoCollection() throws Exception {
|
||||
void testRemoveNoObjectIdNoCollection() throws Exception {
|
||||
writer.setDelete(true);
|
||||
List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
|
||||
@@ -249,7 +210,7 @@ public class MongoItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveNoObjectIdWithCollection() throws Exception {
|
||||
void testRemoveNoObjectIdWithCollection() throws Exception {
|
||||
writer.setDelete(true);
|
||||
List<Object> items = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
|
||||
@@ -261,7 +222,7 @@ public class MongoItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveNoTransactionNoCollection() throws Exception {
|
||||
void testRemoveNoTransactionNoCollection() throws Exception {
|
||||
writer.setDelete(true);
|
||||
List<Object> items = Arrays.asList(new Item(1), new Item(2));
|
||||
|
||||
@@ -272,7 +233,7 @@ public class MongoItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveNoTransactionWithCollection() throws Exception {
|
||||
void testRemoveNoTransactionWithCollection() throws Exception {
|
||||
writer.setDelete(true);
|
||||
List<Object> items = Arrays.asList(new Item(1), new Item(2));
|
||||
|
||||
@@ -286,7 +247,7 @@ public class MongoItemWriterTests {
|
||||
|
||||
// BATCH-2018, test code updated to pass BATCH-3713
|
||||
@Test
|
||||
public void testResourceKeyCollision() throws Exception {
|
||||
void testResourceKeyCollision() {
|
||||
final int limit = 5000;
|
||||
List<MongoItemWriter<String>> writers = new ArrayList<>(limit);
|
||||
final String[] documents = new String[limit];
|
||||
|
||||
@@ -30,14 +30,15 @@ import org.neo4j.ogm.session.SessionFactory;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class Neo4jItemReaderTests {
|
||||
class Neo4jItemReaderTests {
|
||||
|
||||
@Mock
|
||||
private Iterable<String> result;
|
||||
@@ -63,75 +64,34 @@ public class Neo4jItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterPropertiesSet() throws Exception {
|
||||
void testAfterPropertiesSet() throws Exception {
|
||||
|
||||
Neo4jItemReader<String> reader = new Neo4jItemReader<>();
|
||||
|
||||
try {
|
||||
reader.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:" + t);
|
||||
}
|
||||
Exception exception = assertThrows(IllegalStateException.class, reader::afterPropertiesSet);
|
||||
assertEquals("A SessionFactory is required", exception.getMessage());
|
||||
|
||||
reader.setSessionFactory(this.sessionFactory);
|
||||
|
||||
try {
|
||||
reader.afterPropertiesSet();
|
||||
fail("Target Type was not set but exception was not thrown.");
|
||||
}
|
||||
catch (IllegalStateException iae) {
|
||||
assertEquals("The type to be returned is required", iae.getMessage());
|
||||
}
|
||||
catch (Throwable t) {
|
||||
fail("Wrong exception was thrown:" + t);
|
||||
}
|
||||
exception = assertThrows(IllegalStateException.class, reader::afterPropertiesSet);
|
||||
assertEquals("The type to be returned is required", exception.getMessage());
|
||||
|
||||
reader.setTargetType(String.class);
|
||||
|
||||
try {
|
||||
reader.afterPropertiesSet();
|
||||
fail("START was not set but exception was not thrown.");
|
||||
}
|
||||
catch (IllegalStateException iae) {
|
||||
assertEquals("A START statement is required", iae.getMessage());
|
||||
}
|
||||
catch (Throwable t) {
|
||||
fail("Wrong exception was thrown:" + t);
|
||||
}
|
||||
exception = assertThrows(IllegalStateException.class, reader::afterPropertiesSet);
|
||||
assertEquals("A START statement is required", exception.getMessage());
|
||||
|
||||
reader.setStartStatement("n=node(*)");
|
||||
|
||||
try {
|
||||
reader.afterPropertiesSet();
|
||||
fail("RETURN was not set but exception was not thrown.");
|
||||
}
|
||||
catch (IllegalStateException iae) {
|
||||
assertEquals("A RETURN statement is required", iae.getMessage());
|
||||
}
|
||||
catch (Throwable t) {
|
||||
fail("Wrong exception was thrown:" + t);
|
||||
}
|
||||
exception = assertThrows(IllegalStateException.class, reader::afterPropertiesSet);
|
||||
assertEquals("A RETURN statement is required", exception.getMessage());
|
||||
|
||||
reader.setReturnStatement("n.name, n.phone");
|
||||
|
||||
try {
|
||||
reader.afterPropertiesSet();
|
||||
fail("ORDER BY was not set but exception was not thrown.");
|
||||
}
|
||||
catch (IllegalStateException iae) {
|
||||
assertEquals("A ORDER BY statement is required", iae.getMessage());
|
||||
}
|
||||
catch (Throwable t) {
|
||||
fail("Wrong exception was thrown:" + t);
|
||||
}
|
||||
exception = assertThrows(IllegalStateException.class, reader::afterPropertiesSet);
|
||||
assertEquals("A ORDER BY statement is required", exception.getMessage());
|
||||
|
||||
reader.setOrderByStatement("n.age");
|
||||
|
||||
reader.afterPropertiesSet();
|
||||
|
||||
reader = new Neo4jItemReader<>();
|
||||
@@ -144,9 +104,8 @@ public class Neo4jItemReaderTests {
|
||||
reader.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testNullResultsWithSession() throws Exception {
|
||||
void testNullResultsWithSession() throws Exception {
|
||||
|
||||
Neo4jItemReader<String> itemReader = buildSessionBasedReader();
|
||||
|
||||
@@ -159,9 +118,8 @@ public class Neo4jItemReaderTests {
|
||||
assertEquals("START n=node(*) RETURN * ORDER BY n.age SKIP 0 LIMIT 50", query.getValue());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testNoResultsWithSession() throws Exception {
|
||||
void testNoResultsWithSession() throws Exception {
|
||||
Neo4jItemReader<String> itemReader = buildSessionBasedReader();
|
||||
ArgumentCaptor<String> query = ArgumentCaptor.forClass(String.class);
|
||||
|
||||
@@ -173,9 +131,8 @@ public class Neo4jItemReaderTests {
|
||||
assertEquals("START n=node(*) RETURN * ORDER BY n.age SKIP 0 LIMIT 50", query.getValue());
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@Test
|
||||
public void testResultsWithMatchAndWhereWithSession() throws Exception {
|
||||
void testResultsWithMatchAndWhereWithSession() throws Exception {
|
||||
Neo4jItemReader<String> itemReader = buildSessionBasedReader();
|
||||
itemReader.setMatchStatement("n -- m");
|
||||
itemReader.setWhereStatement("has(n.name)");
|
||||
@@ -191,9 +148,8 @@ public class Neo4jItemReaderTests {
|
||||
assertTrue(itemReader.doPageRead().hasNext());
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@Test
|
||||
public void testResultsWithMatchAndWhereWithParametersWithSession() throws Exception {
|
||||
void testResultsWithMatchAndWhereWithParametersWithSession() throws Exception {
|
||||
Neo4jItemReader<String> itemReader = buildSessionBasedReader();
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("foo", "bar");
|
||||
|
||||
@@ -19,21 +19,21 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
import org.neo4j.ogm.session.Session;
|
||||
import org.neo4j.ogm.session.SessionFactory;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class Neo4jItemWriterTests {
|
||||
@SuppressWarnings("deprecation")
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class Neo4jItemWriterTests {
|
||||
|
||||
private Neo4jItemWriter<String> writer;
|
||||
|
||||
@@ -44,20 +44,12 @@ public class Neo4jItemWriterTests {
|
||||
private Session session;
|
||||
|
||||
@Test
|
||||
public void testAfterPropertiesSet() throws Exception {
|
||||
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.");
|
||||
}
|
||||
Exception exception = assertThrows(IllegalStateException.class, writer::afterPropertiesSet);
|
||||
assertEquals("A SessionFactory is required", exception.getMessage());
|
||||
|
||||
writer.setSessionFactory(this.sessionFactory);
|
||||
|
||||
@@ -71,7 +63,7 @@ public class Neo4jItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteNullSession() throws Exception {
|
||||
void testWriteNullSession() throws Exception {
|
||||
|
||||
writer = new Neo4jItemWriter<>();
|
||||
|
||||
@@ -84,33 +76,33 @@ public class Neo4jItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteNullWithSession() throws Exception {
|
||||
void testWriteNullWithSession() throws Exception {
|
||||
writer = new Neo4jItemWriter<>();
|
||||
|
||||
writer.setSessionFactory(this.sessionFactory);
|
||||
writer.afterPropertiesSet();
|
||||
|
||||
lenient().when(this.sessionFactory.openSession()).thenReturn(this.session);
|
||||
when(this.sessionFactory.openSession()).thenReturn(this.session);
|
||||
writer.write(null);
|
||||
|
||||
verifyNoInteractions(this.session);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteNoItemsWithSession() throws Exception {
|
||||
void testWriteNoItemsWithSession() throws Exception {
|
||||
writer = new Neo4jItemWriter<>();
|
||||
|
||||
writer.setSessionFactory(this.sessionFactory);
|
||||
writer.afterPropertiesSet();
|
||||
|
||||
lenient().when(this.sessionFactory.openSession()).thenReturn(this.session);
|
||||
when(this.sessionFactory.openSession()).thenReturn(this.session);
|
||||
writer.write(new ArrayList<>());
|
||||
|
||||
verifyNoInteractions(this.session);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteItemsWithSession() throws Exception {
|
||||
void testWriteItemsWithSession() throws Exception {
|
||||
writer = new Neo4jItemWriter<>();
|
||||
|
||||
writer.setSessionFactory(this.sessionFactory);
|
||||
@@ -128,7 +120,7 @@ public class Neo4jItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteItemsWithSession() throws Exception {
|
||||
void testDeleteItemsWithSession() throws Exception {
|
||||
writer = new Neo4jItemWriter<>();
|
||||
|
||||
writer.setSessionFactory(this.sessionFactory);
|
||||
|
||||
@@ -39,11 +39,11 @@ import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -51,18 +51,17 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class RepositoryItemReaderTests {
|
||||
class RepositoryItemReaderTests {
|
||||
|
||||
private RepositoryItemReader<Object> reader;
|
||||
|
||||
@Mock
|
||||
private PagingAndSortingRepository<Object, Integer> repository;
|
||||
|
||||
private Map<String, Sort.Direction> sorts;
|
||||
private Map<String, Sort.Direction> sorts = Map.of("id", Direction.ASC);
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
sorts = Collections.singletonMap("id", Direction.ASC);
|
||||
void setUp() {
|
||||
reader = new RepositoryItemReader<>();
|
||||
reader.setRepository(repository);
|
||||
reader.setPageSize(1);
|
||||
@@ -71,46 +70,23 @@ public class RepositoryItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterPropertiesSet() throws Exception {
|
||||
try {
|
||||
new RepositoryItemReader<>().afterPropertiesSet();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
void testAfterPropertiesSet() throws Exception {
|
||||
reader = new RepositoryItemReader<>();
|
||||
assertThrows(IllegalStateException.class, reader::afterPropertiesSet);
|
||||
|
||||
try {
|
||||
reader = new RepositoryItemReader<>();
|
||||
reader.setRepository(repository);
|
||||
reader.afterPropertiesSet();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException iae) {
|
||||
// expected
|
||||
}
|
||||
reader = new RepositoryItemReader<>();
|
||||
reader.setRepository(repository);
|
||||
assertThrows(IllegalStateException.class, reader::afterPropertiesSet);
|
||||
|
||||
try {
|
||||
reader = new RepositoryItemReader<>();
|
||||
reader.setRepository(repository);
|
||||
reader.setPageSize(-1);
|
||||
reader.afterPropertiesSet();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException iae) {
|
||||
// expected
|
||||
}
|
||||
reader = new RepositoryItemReader<>();
|
||||
reader.setRepository(repository);
|
||||
reader.setPageSize(-1);
|
||||
assertThrows(IllegalStateException.class, reader::afterPropertiesSet);
|
||||
|
||||
try {
|
||||
reader = new RepositoryItemReader<>();
|
||||
reader.setRepository(repository);
|
||||
reader.setPageSize(1);
|
||||
reader.afterPropertiesSet();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException iae) {
|
||||
// expected
|
||||
}
|
||||
reader = new RepositoryItemReader<>();
|
||||
reader.setRepository(repository);
|
||||
reader.setPageSize(1);
|
||||
assertThrows(IllegalStateException.class, reader::afterPropertiesSet);
|
||||
|
||||
reader = new RepositoryItemReader<>();
|
||||
reader.setRepository(repository);
|
||||
@@ -120,7 +96,7 @@ public class RepositoryItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoReadFirstReadNoResults() throws Exception {
|
||||
void testDoReadFirstReadNoResults() throws Exception {
|
||||
ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
|
||||
|
||||
when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(new ArrayList<>()));
|
||||
@@ -135,7 +111,7 @@ public class RepositoryItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoReadFirstReadResults() throws Exception {
|
||||
void testDoReadFirstReadResults() throws Exception {
|
||||
ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
|
||||
final Object result = new Object();
|
||||
|
||||
@@ -151,13 +127,13 @@ public class RepositoryItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoReadFirstReadSecondPage() throws Exception {
|
||||
void testDoReadFirstReadSecondPage() throws Exception {
|
||||
ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
|
||||
final Object result = new Object();
|
||||
when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(singletonList(new Object())))
|
||||
.thenReturn(new PageImpl<>(singletonList(result)));
|
||||
|
||||
assertFalse(reader.doRead() == result);
|
||||
assertNotSame(result, reader.doRead());
|
||||
assertEquals(result, reader.doRead());
|
||||
|
||||
Pageable pageRequest = pageRequestContainer.getValue();
|
||||
@@ -168,13 +144,13 @@ public class RepositoryItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoReadFirstReadExhausted() throws Exception {
|
||||
void testDoReadFirstReadExhausted() throws Exception {
|
||||
ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
|
||||
final Object result = new Object();
|
||||
when(repository.findAll(pageRequestContainer.capture())).thenReturn(new PageImpl<>(singletonList(new Object())))
|
||||
.thenReturn(new PageImpl<>(singletonList(result))).thenReturn(new PageImpl<>(new ArrayList<>()));
|
||||
|
||||
assertFalse(reader.doRead() == result);
|
||||
assertNotSame(result, reader.doRead());
|
||||
assertEquals(result, reader.doRead());
|
||||
assertNull(reader.doRead());
|
||||
|
||||
@@ -186,7 +162,7 @@ public class RepositoryItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJumpToItem() throws Exception {
|
||||
void testJumpToItem() throws Exception {
|
||||
reader.setPageSize(100);
|
||||
final List<Object> objectList = fillWithNewObjects(100);
|
||||
ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
|
||||
@@ -198,7 +174,7 @@ public class RepositoryItemReaderTests {
|
||||
|
||||
// the page must only actually be fetched on the next "doRead()" call
|
||||
final Object o = reader.doRead();
|
||||
assertSame(o, objectList.get(85), "Fetched object should be at index 85 in the current page");
|
||||
assertSame(objectList.get(85), o, "Fetched object should be at index 85 in the current page");
|
||||
|
||||
Pageable pageRequest = pageRequestContainer.getValue();
|
||||
assertEquals(400, pageRequest.getOffset());
|
||||
@@ -208,7 +184,7 @@ public class RepositoryItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJumpToItemFirstItemOnPage() throws Exception {
|
||||
void testJumpToItemFirstItemOnPage() throws Exception {
|
||||
reader.setPageSize(50);
|
||||
final List<Object> objectList = fillWithNewObjects(50);
|
||||
ArgumentCaptor<PageRequest> pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
|
||||
@@ -234,20 +210,15 @@ public class RepositoryItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidMethodName() throws Exception {
|
||||
void testInvalidMethodName() {
|
||||
reader.setMethodName("thisMethodDoesNotExist");
|
||||
|
||||
try {
|
||||
reader.doPageRead();
|
||||
fail();
|
||||
}
|
||||
catch (DynamicMethodInvocationException dmie) {
|
||||
assertTrue(dmie.getCause() instanceof NoSuchMethodException);
|
||||
}
|
||||
Exception exception = assertThrows(DynamicMethodInvocationException.class, reader::doPageRead);
|
||||
assertTrue(exception.getCause() instanceof NoSuchMethodException);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDifferentTypes() throws Exception {
|
||||
void testDifferentTypes() throws Exception {
|
||||
TestRepository differentRepository = mock(TestRepository.class);
|
||||
RepositoryItemReader<String> reader = new RepositoryItemReader<>();
|
||||
sorts = Collections.singletonMap("id", Direction.ASC);
|
||||
@@ -270,7 +241,7 @@ public class RepositoryItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSettingCurrentItemCountExplicitly() throws Exception {
|
||||
void testSettingCurrentItemCountExplicitly() throws Exception {
|
||||
// Dataset : ("1" "2") | "3" "4" | "5" "6"
|
||||
reader.setCurrentItemCount(3); // item as index 3 is : "4"
|
||||
reader.setPageSize(2);
|
||||
@@ -291,7 +262,7 @@ public class RepositoryItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSettingCurrentItemCountRestart() throws Exception {
|
||||
void testSettingCurrentItemCountRestart() throws Exception {
|
||||
reader.setCurrentItemCount(3); // item as index 3 is : "4"
|
||||
reader.setPageSize(2);
|
||||
|
||||
@@ -316,7 +287,7 @@ public class RepositoryItemReaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResetOfPage() throws Exception {
|
||||
void testResetOfPage() throws Exception {
|
||||
reader.setPageSize(2);
|
||||
|
||||
PageRequest request = PageRequest.of(0, 2, Sort.by(Direction.ASC, "id"));
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
package org.springframework.batch.item.data;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
@@ -34,7 +34,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class RepositoryItemWriterTests {
|
||||
class RepositoryItemWriterTests {
|
||||
|
||||
@Mock
|
||||
private CrudRepository<String, Serializable> repository;
|
||||
@@ -42,41 +42,28 @@ public class RepositoryItemWriterTests {
|
||||
private RepositoryItemWriter<String> writer;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
void setUp() {
|
||||
writer = new RepositoryItemWriter<>();
|
||||
writer.setMethodName("save");
|
||||
writer.setRepository(repository);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterPropertiesSet() throws Exception {
|
||||
void testAfterPropertiesSet() throws Exception {
|
||||
writer.afterPropertiesSet();
|
||||
|
||||
writer.setRepository(null);
|
||||
|
||||
try {
|
||||
writer.afterPropertiesSet();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
}
|
||||
assertThrows(IllegalStateException.class, writer::afterPropertiesSet);
|
||||
|
||||
writer.setRepository(repository);
|
||||
writer.setMethodName("");
|
||||
|
||||
try {
|
||||
writer.afterPropertiesSet();
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
assertEquals("methodName must not be empty.", e.getMessage(),
|
||||
"Wrong message for exception: " + e.getMessage());
|
||||
}
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet);
|
||||
assertEquals("methodName must not be empty.", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteNoItems() throws Exception {
|
||||
void testWriteNoItems() throws Exception {
|
||||
writer.write(null);
|
||||
|
||||
writer.write(new ArrayList<>());
|
||||
@@ -85,7 +72,7 @@ public class RepositoryItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteItems() throws Exception {
|
||||
void testWriteItems() throws Exception {
|
||||
List<String> items = Collections.singletonList("foo");
|
||||
|
||||
writer.write(items);
|
||||
@@ -95,7 +82,7 @@ public class RepositoryItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteItemsWithDefaultMethodName() throws Exception {
|
||||
void testWriteItemsWithDefaultMethodName() throws Exception {
|
||||
List<String> items = Collections.singletonList("foo");
|
||||
|
||||
writer.setMethodName(null);
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.springframework.batch.item.data.GemfireItemWriter;
|
||||
import org.springframework.data.gemfire.GemfireTemplate;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -37,7 +37,7 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class GemfireItemWriterBuilderTests {
|
||||
class GemfireItemWriterBuilderTests {
|
||||
|
||||
@Mock
|
||||
private GemfireTemplate template;
|
||||
@@ -47,14 +47,14 @@ public class GemfireItemWriterBuilderTests {
|
||||
private List<GemfireItemWriterBuilderTests.Foo> items;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
void setUp() {
|
||||
this.items = Arrays.asList(new GemfireItemWriterBuilderTests.Foo(new GemfireItemWriterBuilderTests.Bar("val1")),
|
||||
new GemfireItemWriterBuilderTests.Foo(new GemfireItemWriterBuilderTests.Bar("val2")));
|
||||
this.itemKeyMapper = new SpELItemKeyMapper<>("bar.val");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicWrite() throws Exception {
|
||||
void testBasicWrite() throws Exception {
|
||||
GemfireItemWriter<String, GemfireItemWriterBuilderTests.Foo> writer = new GemfireItemWriterBuilder<String, GemfireItemWriterBuilderTests.Foo>()
|
||||
.template(this.template).itemKeyMapper(this.itemKeyMapper).build();
|
||||
|
||||
@@ -67,7 +67,7 @@ public class GemfireItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicDelete() throws Exception {
|
||||
void testBasicDelete() throws Exception {
|
||||
GemfireItemWriter<String, GemfireItemWriterBuilderTests.Foo> writer = new GemfireItemWriterBuilder<String, GemfireItemWriterBuilderTests.Foo>()
|
||||
.template(this.template).delete(true).itemKeyMapper(this.itemKeyMapper).build();
|
||||
|
||||
@@ -80,28 +80,18 @@ public class GemfireItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullTemplate() {
|
||||
try {
|
||||
new GemfireItemWriterBuilder<String, GemfireItemWriterBuilderTests.Foo>().itemKeyMapper(this.itemKeyMapper)
|
||||
.build();
|
||||
fail("IllegalArgumentException should have been thrown");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("template is required.", iae.getMessage(),
|
||||
"IllegalArgumentException message did not match the expected result.");
|
||||
}
|
||||
void testNullTemplate() {
|
||||
var builder = new GemfireItemWriterBuilder<String, GemfireItemWriterBuilderTests.Foo>()
|
||||
.itemKeyMapper(this.itemKeyMapper);
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("template is required.", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullItemKeyMapper() {
|
||||
try {
|
||||
new GemfireItemWriterBuilder<String, GemfireItemWriterBuilderTests.Foo>().template(this.template).build();
|
||||
fail("IllegalArgumentException should have been thrown");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("itemKeyMapper is required.", iae.getMessage(),
|
||||
"IllegalArgumentException message did not match the expected result.");
|
||||
}
|
||||
void testNullItemKeyMapper() {
|
||||
var builder = new GemfireItemWriterBuilder<String, GemfireItemWriterBuilderTests.Foo>().template(this.template);
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("itemKeyMapper is required.", exception.getMessage());
|
||||
}
|
||||
|
||||
static class Foo {
|
||||
|
||||
@@ -34,7 +34,8 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.data.mongodb.core.query.Criteria.where;
|
||||
@@ -47,7 +48,7 @@ import static org.springframework.data.mongodb.core.query.Query.query;
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class MongoItemReaderBuilderTests {
|
||||
class MongoItemReaderBuilderTests {
|
||||
|
||||
@Mock
|
||||
private MongoOperations template;
|
||||
@@ -57,14 +58,14 @@ public class MongoItemReaderBuilderTests {
|
||||
private ArgumentCaptor<Query> queryContainer;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
void setUp() {
|
||||
this.sortOptions = new HashMap<>();
|
||||
this.sortOptions.put("name", Sort.Direction.DESC);
|
||||
this.queryContainer = ArgumentCaptor.forClass(Query.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasic() throws Exception {
|
||||
void testBasic() throws Exception {
|
||||
MongoItemReader<String> reader = getBasicBuilder().build();
|
||||
|
||||
when(template.find(this.queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
|
||||
@@ -79,7 +80,7 @@ public class MongoItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFields() throws Exception {
|
||||
void testFields() throws Exception {
|
||||
MongoItemReader<String> reader = getBasicBuilder().fields("{name : 1, age : 1, _id: 0}").build();
|
||||
|
||||
when(this.template.find(this.queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
|
||||
@@ -93,7 +94,7 @@ public class MongoItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHint() throws Exception {
|
||||
void testHint() throws Exception {
|
||||
MongoItemReader<String> reader = getBasicBuilder().hint("{ $natural : 1}").build();
|
||||
|
||||
when(this.template.find(this.queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>());
|
||||
@@ -105,7 +106,7 @@ public class MongoItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollection() throws Exception {
|
||||
void testCollection() throws Exception {
|
||||
MongoItemReader<String> reader = getBasicBuilder().parameterValues(Collections.singletonList("foo"))
|
||||
.jsonQuery("{ name : ?0 }").collection("collection").build();
|
||||
|
||||
@@ -123,7 +124,7 @@ public class MongoItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarargs() throws Exception {
|
||||
void testVarargs() throws Exception {
|
||||
MongoItemReader<String> reader = getBasicBuilder().parameterValues("foo").jsonQuery("{ name : ?0 }")
|
||||
.collection("collection").build();
|
||||
|
||||
@@ -141,7 +142,7 @@ public class MongoItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithoutQueryLimit() throws Exception {
|
||||
void testWithoutQueryLimit() throws Exception {
|
||||
MongoItemReader<String> reader = new MongoItemReaderBuilder<String>().template(this.template)
|
||||
.targetType(String.class).query(new Query()).sorts(this.sortOptions).name("mongoReaderTest")
|
||||
.pageSize(50).build();
|
||||
@@ -155,7 +156,7 @@ public class MongoItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithoutQueryLimitAndPageSize() throws Exception {
|
||||
void testWithoutQueryLimitAndPageSize() throws Exception {
|
||||
MongoItemReader<String> reader = new MongoItemReaderBuilder<String>().template(this.template)
|
||||
.targetType(String.class).query(new Query()).sorts(this.sortOptions).name("mongoReaderTest").build();
|
||||
|
||||
@@ -168,31 +169,31 @@ public class MongoItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullTemplate() {
|
||||
void testNullTemplate() {
|
||||
validateExceptionMessage(new MongoItemReaderBuilder<String>().targetType(String.class).jsonQuery("{ }")
|
||||
.sorts(this.sortOptions).name("mongoReaderTest").pageSize(50), "template is required.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullTargetType() {
|
||||
void testNullTargetType() {
|
||||
validateExceptionMessage(new MongoItemReaderBuilder<String>().template(this.template).jsonQuery("{ }")
|
||||
.sorts(this.sortOptions).name("mongoReaderTest").pageSize(50), "targetType is required.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullQuery() {
|
||||
void testNullQuery() {
|
||||
validateExceptionMessage(new MongoItemReaderBuilder<String>().template(this.template).targetType(String.class)
|
||||
.sorts(this.sortOptions).name("mongoReaderTest").pageSize(50), "A query is required");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullSortsWithQueryString() {
|
||||
void testNullSortsWithQueryString() {
|
||||
validateExceptionMessage(new MongoItemReaderBuilder<String>().template(this.template).targetType(String.class)
|
||||
.jsonQuery("{ }").name("mongoReaderTest").pageSize(50), "sorts map is required.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullSortsWithQuery() {
|
||||
void testNullSortsWithQuery() {
|
||||
validateExceptionMessage(
|
||||
new MongoItemReaderBuilder<String>().template(this.template).targetType(String.class)
|
||||
.query(query(where("_id").is("10"))).name("mongoReaderTest").pageSize(50),
|
||||
@@ -200,24 +201,16 @@ public class MongoItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullName() {
|
||||
void testNullName() {
|
||||
validateExceptionMessage(new MongoItemReaderBuilder<String>().template(this.template).targetType(String.class)
|
||||
.jsonQuery("{ }").sorts(this.sortOptions).pageSize(50),
|
||||
"A name is required when saveState is set to true");
|
||||
}
|
||||
|
||||
private void validateExceptionMessage(MongoItemReaderBuilder<String> builder, String message) {
|
||||
try {
|
||||
builder.build();
|
||||
fail("Exception should have been thrown");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals(message, iae.getMessage(),
|
||||
"IllegalArgumentException message did not match the expected result.");
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
assertEquals(message, ise.getMessage(), "IllegalStateException message did not match the expected result.");
|
||||
}
|
||||
Exception exception = assertThrows(RuntimeException.class, builder::build);
|
||||
assertTrue(exception instanceof IllegalArgumentException || exception instanceof IllegalStateException);
|
||||
assertEquals(message, exception.getMessage());
|
||||
}
|
||||
|
||||
private MongoItemReaderBuilder<String> getBasicBuilder() {
|
||||
|
||||
@@ -22,15 +22,15 @@ import java.util.List;
|
||||
import org.bson.Document;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import static org.mockito.Mockito.when;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
import org.springframework.batch.item.data.MongoItemWriter;
|
||||
import org.springframework.data.mapping.context.MappingContext;
|
||||
import org.springframework.data.mongodb.core.BulkOperations;
|
||||
@@ -44,7 +44,7 @@ import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
|
||||
import org.springframework.data.mongodb.core.query.Query;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
@@ -54,8 +54,8 @@ import static org.mockito.ArgumentMatchers.eq;
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @author Parikshit Dutta
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class MongoItemWriterBuilderTests {
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class MongoItemWriterBuilderTests {
|
||||
|
||||
@Mock
|
||||
private MongoOperations template;
|
||||
@@ -73,20 +73,20 @@ public class MongoItemWriterBuilderTests {
|
||||
private List<Item> removeItems;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
lenient().when(this.template.bulkOps(any(), anyString())).thenReturn(this.bulkOperations);
|
||||
lenient().when(this.template.bulkOps(any(), any(Class.class))).thenReturn(this.bulkOperations);
|
||||
void setUp() {
|
||||
when(this.template.bulkOps(any(), anyString())).thenReturn(this.bulkOperations);
|
||||
when(this.template.bulkOps(any(), any(Class.class))).thenReturn(this.bulkOperations);
|
||||
|
||||
MappingContext<MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext = new MongoMappingContext();
|
||||
mongoConverter = spy(new MappingMongoConverter(this.dbRefResolver, mappingContext));
|
||||
lenient().when(this.template.getConverter()).thenReturn(mongoConverter);
|
||||
when(this.template.getConverter()).thenReturn(mongoConverter);
|
||||
|
||||
this.saveItems = Arrays.asList(new Item("Foo"), new Item("Bar"));
|
||||
this.removeItems = Arrays.asList(new Item(1), new Item(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicWrite() throws Exception {
|
||||
void testBasicWrite() throws Exception {
|
||||
MongoItemWriter<Item> writer = new MongoItemWriterBuilder<Item>().template(this.template).build();
|
||||
writer.write(this.saveItems);
|
||||
|
||||
@@ -98,7 +98,7 @@ public class MongoItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteToCollection() throws Exception {
|
||||
void testWriteToCollection() throws Exception {
|
||||
MongoItemWriter<Item> writer = new MongoItemWriterBuilder<Item>().collection("collection")
|
||||
.template(this.template).build();
|
||||
|
||||
@@ -112,7 +112,7 @@ public class MongoItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDelete() throws Exception {
|
||||
void testDelete() throws Exception {
|
||||
MongoItemWriter<Item> writer = new MongoItemWriterBuilder<Item>().template(this.template).delete(true).build();
|
||||
|
||||
writer.write(this.removeItems);
|
||||
@@ -122,15 +122,10 @@ public class MongoItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullTemplate() {
|
||||
try {
|
||||
new MongoItemWriterBuilder<>().build();
|
||||
fail("IllegalArgumentException should have been thrown");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("template is required.", iae.getMessage(),
|
||||
"IllegalArgumentException message did not match the expected result.");
|
||||
}
|
||||
void testNullTemplate() {
|
||||
Exception exception = assertThrows(IllegalArgumentException.class,
|
||||
() -> new MongoItemWriterBuilder<>().build());
|
||||
assertEquals("template is required.", exception.getMessage());
|
||||
}
|
||||
|
||||
static class Item {
|
||||
|
||||
@@ -31,14 +31,15 @@ import org.springframework.batch.item.data.Neo4jItemReader;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class Neo4jItemReaderBuilderTests {
|
||||
class Neo4jItemReaderBuilderTests {
|
||||
|
||||
@Mock
|
||||
private Iterable<String> result;
|
||||
@@ -50,7 +51,7 @@ public class Neo4jItemReaderBuilderTests {
|
||||
private Session session;
|
||||
|
||||
@Test
|
||||
public void testFullyQualifiedItemReader() throws Exception {
|
||||
void testFullyQualifiedItemReader() throws Exception {
|
||||
Neo4jItemReader<String> itemReader = new Neo4jItemReaderBuilder<String>().sessionFactory(this.sessionFactory)
|
||||
.targetType(String.class).startStatement("n=node(*)").orderByStatement("n.age").pageSize(50).name("bar")
|
||||
.matchStatement("n -- m").whereStatement("has(n.name)").returnStatement("m").build();
|
||||
@@ -67,7 +68,7 @@ public class Neo4jItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrentSize() throws Exception {
|
||||
void testCurrentSize() throws Exception {
|
||||
Neo4jItemReader<String> itemReader = new Neo4jItemReaderBuilder<String>().sessionFactory(this.sessionFactory)
|
||||
.targetType(String.class).startStatement("n=node(*)").orderByStatement("n.age").pageSize(50).name("bar")
|
||||
.returnStatement("m").currentItemCount(0).maxItemCount(1).build();
|
||||
@@ -82,7 +83,7 @@ public class Neo4jItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResultsWithMatchAndWhereWithParametersWithSession() throws Exception {
|
||||
void testResultsWithMatchAndWhereWithParametersWithSession() throws Exception {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("foo", "bar");
|
||||
Neo4jItemReader<String> itemReader = new Neo4jItemReaderBuilder<String>().sessionFactory(this.sessionFactory)
|
||||
@@ -100,21 +101,15 @@ public class Neo4jItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSessionFactory() {
|
||||
try {
|
||||
new Neo4jItemReaderBuilder<String>().targetType(String.class).startStatement("n=node(*)")
|
||||
.returnStatement("*").orderByStatement("n.age").pageSize(50).name("bar").build();
|
||||
|
||||
fail("IllegalArgumentException should have been thrown");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("sessionFactory is required.", iae.getMessage(),
|
||||
"IllegalArgumentException message did not match the expected result.");
|
||||
}
|
||||
void testNoSessionFactory() {
|
||||
var builder = new Neo4jItemReaderBuilder<String>().targetType(String.class).startStatement("n=node(*)")
|
||||
.returnStatement("*").orderByStatement("n.age").pageSize(50).name("bar");
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("sessionFactory is required.", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZeroPageSize() {
|
||||
void testZeroPageSize() {
|
||||
validateExceptionMessage(
|
||||
new Neo4jItemReaderBuilder<String>().sessionFactory(this.sessionFactory).targetType(String.class)
|
||||
.startStatement("n=node(*)").returnStatement("*").orderByStatement("n.age").pageSize(0)
|
||||
@@ -123,7 +118,7 @@ public class Neo4jItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZeroMaxItemCount() {
|
||||
void testZeroMaxItemCount() {
|
||||
validateExceptionMessage(new Neo4jItemReaderBuilder<String>().sessionFactory(this.sessionFactory)
|
||||
.targetType(String.class).startStatement("n=node(*)").returnStatement("*").orderByStatement("n.age")
|
||||
.pageSize(5).maxItemCount(0).name("foo").matchStatement("n -- m").whereStatement("has(n.name)")
|
||||
@@ -131,7 +126,7 @@ public class Neo4jItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrentItemCountGreaterThanMaxItemCount() {
|
||||
void testCurrentItemCountGreaterThanMaxItemCount() {
|
||||
validateExceptionMessage(
|
||||
new Neo4jItemReaderBuilder<String>().sessionFactory(this.sessionFactory).targetType(String.class)
|
||||
.startStatement("n=node(*)").returnStatement("*").orderByStatement("n.age").pageSize(5)
|
||||
@@ -141,7 +136,7 @@ public class Neo4jItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullName() {
|
||||
void testNullName() {
|
||||
validateExceptionMessage(
|
||||
new Neo4jItemReaderBuilder<String>().sessionFactory(this.sessionFactory).targetType(String.class)
|
||||
.startStatement("n=node(*)").returnStatement("*").orderByStatement("n.age").pageSize(50),
|
||||
@@ -154,7 +149,7 @@ public class Neo4jItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullTargetType() {
|
||||
void testNullTargetType() {
|
||||
validateExceptionMessage(
|
||||
new Neo4jItemReaderBuilder<String>().sessionFactory(this.sessionFactory).startStatement("n=node(*)")
|
||||
.returnStatement("*").orderByStatement("n.age").pageSize(50).name("bar")
|
||||
@@ -163,7 +158,7 @@ public class Neo4jItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullStartStatement() {
|
||||
void testNullStartStatement() {
|
||||
validateExceptionMessage(
|
||||
new Neo4jItemReaderBuilder<String>().sessionFactory(this.sessionFactory).targetType(String.class)
|
||||
.returnStatement("*").orderByStatement("n.age").pageSize(50).name("bar")
|
||||
@@ -172,14 +167,14 @@ public class Neo4jItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullReturnStatement() {
|
||||
void testNullReturnStatement() {
|
||||
validateExceptionMessage(new Neo4jItemReaderBuilder<String>().sessionFactory(this.sessionFactory)
|
||||
.targetType(String.class).startStatement("n=node(*)").orderByStatement("n.age").pageSize(50).name("bar")
|
||||
.matchStatement("n -- m").whereStatement("has(n.name)"), "returnStatement is required.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullOrderByStatement() {
|
||||
void testNullOrderByStatement() {
|
||||
validateExceptionMessage(
|
||||
new Neo4jItemReaderBuilder<String>().sessionFactory(this.sessionFactory).targetType(String.class)
|
||||
.startStatement("n=node(*)").returnStatement("*").pageSize(50).name("bar")
|
||||
@@ -188,14 +183,8 @@ public class Neo4jItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
private void validateExceptionMessage(Neo4jItemReaderBuilder<?> builder, String message) {
|
||||
try {
|
||||
builder.build();
|
||||
fail("IllegalArgumentException should have been thrown");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals(message, iae.getMessage(),
|
||||
"IllegalArgumentException message did not match the expected result.");
|
||||
}
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals(message, exception.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.neo4j.ogm.session.SessionFactory;
|
||||
import org.springframework.batch.item.data.Neo4jItemWriter;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -37,8 +37,9 @@ import static org.mockito.Mockito.when;
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class Neo4jItemWriterBuilderTests {
|
||||
class Neo4jItemWriterBuilderTests {
|
||||
|
||||
@Mock
|
||||
private SessionFactory sessionFactory;
|
||||
@@ -47,7 +48,7 @@ public class Neo4jItemWriterBuilderTests {
|
||||
private Session session;
|
||||
|
||||
@Test
|
||||
public void testBasicWriter() throws Exception {
|
||||
void testBasicWriter() throws Exception {
|
||||
Neo4jItemWriter<String> writer = new Neo4jItemWriterBuilder<String>().sessionFactory(this.sessionFactory)
|
||||
.build();
|
||||
List<String> items = new ArrayList<>();
|
||||
@@ -64,7 +65,7 @@ public class Neo4jItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicDelete() throws Exception {
|
||||
void testBasicDelete() throws Exception {
|
||||
Neo4jItemWriter<String> writer = new Neo4jItemWriterBuilder<String>().delete(true)
|
||||
.sessionFactory(this.sessionFactory).build();
|
||||
List<String> items = new ArrayList<>();
|
||||
@@ -81,14 +82,10 @@ public class Neo4jItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSessionFactory() {
|
||||
try {
|
||||
new Neo4jItemWriterBuilder<String>().build();
|
||||
fail("SessionFactory was not set but exception was not thrown.");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("sessionFactory is required.", iae.getMessage());
|
||||
}
|
||||
void testNoSessionFactory() {
|
||||
Exception exception = assertThrows(IllegalArgumentException.class,
|
||||
() -> new Neo4jItemWriterBuilder<String>().build());
|
||||
assertEquals("sessionFactory is required.", exception.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,10 +23,10 @@ import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
import org.springframework.batch.item.data.RepositoryItemReader;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
@@ -35,8 +35,7 @@ import org.springframework.data.repository.PagingAndSortingRepository;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
@@ -44,8 +43,8 @@ import static org.mockito.Mockito.when;
|
||||
* @author Drummond Dawson
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class RepositoryItemReaderBuilderTests {
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class RepositoryItemReaderBuilderTests {
|
||||
|
||||
private static final String ARG1 = "foo";
|
||||
|
||||
@@ -66,20 +65,20 @@ public class RepositoryItemReaderBuilderTests {
|
||||
private ArgumentCaptor<PageRequest> pageRequestContainer;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
void setUp() {
|
||||
this.sorts = new HashMap<>();
|
||||
this.sorts.put("id", Sort.Direction.ASC);
|
||||
this.pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class);
|
||||
|
||||
List<String> testResult = new ArrayList<>();
|
||||
testResult.add(TEST_CONTENT);
|
||||
lenient().when(page.getContent()).thenReturn(testResult);
|
||||
lenient().when(page.getSize()).thenReturn(5);
|
||||
lenient().when(this.repository.foo(this.pageRequestContainer.capture())).thenReturn(this.page);
|
||||
when(page.getContent()).thenReturn(testResult);
|
||||
when(page.getSize()).thenReturn(5);
|
||||
when(this.repository.foo(this.pageRequestContainer.capture())).thenReturn(this.page);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicRead() throws Exception {
|
||||
void testBasicRead() throws Exception {
|
||||
RepositoryItemReader<Object> reader = new RepositoryItemReaderBuilder<>().repository(this.repository)
|
||||
.sorts(this.sorts).maxItemCount(5).methodName("foo").name("bar").build();
|
||||
String result = (String) reader.read();
|
||||
@@ -88,14 +87,14 @@ public class RepositoryItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrentItemCount() throws Exception {
|
||||
void testCurrentItemCount() throws Exception {
|
||||
RepositoryItemReader<Object> reader = new RepositoryItemReaderBuilder<>().repository(this.repository)
|
||||
.sorts(this.sorts).currentItemCount(6).maxItemCount(5).methodName("foo").name("bar").build();
|
||||
assertNull(reader.read(), "Result returned from reader was not null.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPageSize() throws Exception {
|
||||
void testPageSize() throws Exception {
|
||||
RepositoryItemReader<Object> reader = new RepositoryItemReaderBuilder<>().repository(this.repository)
|
||||
.sorts(this.sorts).maxItemCount(5).methodName("foo").name("bar").pageSize(2).build();
|
||||
reader.read();
|
||||
@@ -103,40 +102,25 @@ public class RepositoryItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoMethodName() throws Exception {
|
||||
try {
|
||||
new RepositoryItemReaderBuilder<>().repository(this.repository).sorts(this.sorts).maxItemCount(10).build();
|
||||
void testNoMethodName() {
|
||||
var builder = new RepositoryItemReaderBuilder<>().repository(this.repository).sorts(this.sorts)
|
||||
.maxItemCount(10);
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("methodName is required.", exception.getMessage());
|
||||
|
||||
fail("IllegalArgumentException should have been thrown");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("methodName is required.", iae.getMessage(),
|
||||
"IllegalArgumentException message did not match the expected result.");
|
||||
}
|
||||
try {
|
||||
new RepositoryItemReaderBuilder<>().repository(this.repository).sorts(this.sorts).methodName("")
|
||||
.maxItemCount(5).build();
|
||||
|
||||
fail("IllegalArgumentException should have been thrown");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("methodName is required.", iae.getMessage(),
|
||||
"IllegalArgumentException message did not match the expected result.");
|
||||
}
|
||||
builder = new RepositoryItemReaderBuilder<>().repository(this.repository).sorts(this.sorts).methodName("")
|
||||
.maxItemCount(5);
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("methodName is required.", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveState() throws Exception {
|
||||
try {
|
||||
new RepositoryItemReaderBuilder<>().repository(repository).methodName("foo").sorts(sorts).maxItemCount(5)
|
||||
.build();
|
||||
void testSaveState() {
|
||||
var builder = new RepositoryItemReaderBuilder<>().repository(repository).methodName("foo").sorts(sorts)
|
||||
.maxItemCount(5);
|
||||
Exception exception = assertThrows(IllegalStateException.class, builder::build);
|
||||
assertEquals("A name is required when saveState is set to true.", exception.getMessage());
|
||||
|
||||
fail("IllegalArgumentException should have been thrown");
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
assertEquals("A name is required when saveState is set to true.", ise.getMessage(),
|
||||
"IllegalStateException name was not set when saveState was true.");
|
||||
}
|
||||
// No IllegalStateException for a name that is not set, should not be thrown since
|
||||
// saveState was false.
|
||||
new RepositoryItemReaderBuilder<>().repository(repository).saveState(false).methodName("foo").sorts(sorts)
|
||||
@@ -144,33 +128,21 @@ public class RepositoryItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullSort() throws Exception {
|
||||
try {
|
||||
new RepositoryItemReaderBuilder<>().repository(repository).methodName("foo").maxItemCount(5).build();
|
||||
|
||||
fail("IllegalArgumentException should have been thrown");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("sorts map is required.", iae.getMessage(),
|
||||
"IllegalArgumentException sorts did not match the expected result.");
|
||||
}
|
||||
void testNullSort() {
|
||||
var builder = new RepositoryItemReaderBuilder<>().repository(repository).methodName("foo").maxItemCount(5);
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("sorts map is required.", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRepository() throws Exception {
|
||||
try {
|
||||
new RepositoryItemReaderBuilder<>().sorts(this.sorts).maxItemCount(10).methodName("foo").build();
|
||||
|
||||
fail("IllegalArgumentException should have been thrown");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("repository is required.", iae.getMessage(),
|
||||
"IllegalArgumentException message did not match the expected result.");
|
||||
}
|
||||
void testNoRepository() {
|
||||
var builder = new RepositoryItemReaderBuilder<>().sorts(this.sorts).maxItemCount(10).methodName("foo");
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("repository is required.", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArguments() throws Exception {
|
||||
void testArguments() throws Exception {
|
||||
List<String> args = new ArrayList<>(3);
|
||||
args.add(ARG1);
|
||||
args.add(ARG2);
|
||||
@@ -189,7 +161,7 @@ public class RepositoryItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVarargArguments() throws Exception {
|
||||
void testVarargArguments() throws Exception {
|
||||
ArgumentCaptor<String> arg1Captor = ArgumentCaptor.forClass(String.class);
|
||||
ArgumentCaptor<String> arg2Captor = ArgumentCaptor.forClass(String.class);
|
||||
ArgumentCaptor<String> arg3Captor = ArgumentCaptor.forClass(String.class);
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.batch.item.data.RepositoryItemWriter;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
@@ -36,39 +36,27 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class RepositoryItemWriterBuilderTests {
|
||||
class RepositoryItemWriterBuilderTests {
|
||||
|
||||
@Mock
|
||||
private TestRepository repository;
|
||||
|
||||
@Test
|
||||
public void testNullRepository() throws Exception {
|
||||
try {
|
||||
new RepositoryItemWriterBuilder<String>().methodName("save").build();
|
||||
|
||||
fail("IllegalArgumentException should have been thrown");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("repository is required.", iae.getMessage(),
|
||||
"IllegalArgumentException message did not match the expected result.");
|
||||
}
|
||||
void testNullRepository() {
|
||||
var builder = new RepositoryItemWriterBuilder<String>().methodName("save");
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("repository is required.", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmptyMethodName() {
|
||||
try {
|
||||
new RepositoryItemWriterBuilder<String>().repository(this.repository).methodName("").build();
|
||||
|
||||
fail("IllegalArgumentException should have been thrown");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("methodName must not be empty.", iae.getMessage(),
|
||||
"IllegalArgumentException message did not match the expected result.");
|
||||
}
|
||||
void testEmptyMethodName() {
|
||||
var builder = new RepositoryItemWriterBuilder<String>().repository(this.repository).methodName("");
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("methodName must not be empty.", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteItems() throws Exception {
|
||||
void testWriteItems() throws Exception {
|
||||
RepositoryItemWriter<String> writer = new RepositoryItemWriterBuilder<String>().methodName("save")
|
||||
.repository(this.repository).build();
|
||||
|
||||
@@ -80,7 +68,7 @@ public class RepositoryItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteItemsTestRepository() throws Exception {
|
||||
void testWriteItemsTestRepository() throws Exception {
|
||||
RepositoryItemWriter<String> writer = new RepositoryItemWriterBuilder<String>().methodName("foo")
|
||||
.repository(this.repository).build();
|
||||
|
||||
@@ -92,7 +80,7 @@ public class RepositoryItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteItemsTestRepositoryMethodIs() throws Exception {
|
||||
void testWriteItemsTestRepositoryMethodIs() throws Exception {
|
||||
RepositoryItemWriterBuilder.RepositoryMethodReference<TestRepository> repositoryMethodReference = new RepositoryItemWriterBuilder.RepositoryMethodReference<>(
|
||||
this.repository);
|
||||
repositoryMethodReference.methodIs().foo(null);
|
||||
|
||||
@@ -31,9 +31,9 @@ import org.springframework.test.context.transaction.AfterTransaction;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* Common scenarios for testing {@link ItemReader} implementations which read data from
|
||||
@@ -63,13 +63,13 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
protected abstract ItemReader<Foo> createItemReader() throws Exception;
|
||||
|
||||
@BeforeEach
|
||||
public void onSetUpInTransaction() throws Exception {
|
||||
void onSetUpInTransaction() throws Exception {
|
||||
reader = createItemReader();
|
||||
executionContext = new ExecutionContext();
|
||||
}
|
||||
|
||||
@AfterTransaction
|
||||
public void onTearDownAfterTransaction() throws Exception {
|
||||
public void onTearDownAfterTransaction() {
|
||||
getAsItemStream(reader).close();
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
@Test
|
||||
@Transactional
|
||||
@DirtiesContext
|
||||
public void testNormalProcessing() throws Exception {
|
||||
void testNormalProcessing() throws Exception {
|
||||
getAsInitializingBean(reader).afterPropertiesSet();
|
||||
getAsItemStream(reader).open(executionContext);
|
||||
|
||||
@@ -109,7 +109,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
@Test
|
||||
@Transactional
|
||||
@DirtiesContext
|
||||
public void testRestart() throws Exception {
|
||||
void testRestart() throws Exception {
|
||||
|
||||
getAsItemStream(reader).open(executionContext);
|
||||
|
||||
@@ -140,7 +140,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
@Test
|
||||
@Transactional
|
||||
@DirtiesContext
|
||||
public void testRestartOnSecondPage() throws Exception {
|
||||
void testRestartOnSecondPage() throws Exception {
|
||||
|
||||
getAsItemStream(reader).open(executionContext);
|
||||
|
||||
@@ -174,7 +174,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
@Test
|
||||
@Transactional
|
||||
@DirtiesContext
|
||||
public void testInvalidRestore() throws Exception {
|
||||
void testInvalidRestore() throws Exception {
|
||||
|
||||
getAsItemStream(reader).open(executionContext);
|
||||
|
||||
@@ -195,13 +195,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
Foo foo = reader.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
|
||||
try {
|
||||
getAsItemStream(reader).open(executionContext);
|
||||
fail();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
// expected
|
||||
}
|
||||
assertThrows(Exception.class, () -> getAsItemStream(reader).open(executionContext));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -210,7 +204,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
@Test
|
||||
@Transactional
|
||||
@DirtiesContext
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
void testRestoreFromEmptyData() throws Exception {
|
||||
getAsItemStream(reader).open(executionContext);
|
||||
|
||||
Foo foo = reader.read();
|
||||
@@ -223,7 +217,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
@Test
|
||||
@Transactional
|
||||
@DirtiesContext
|
||||
public void testRollbackAndRestart() throws Exception {
|
||||
void testRollbackAndRestart() throws Exception {
|
||||
|
||||
getAsItemStream(reader).open(executionContext);
|
||||
|
||||
@@ -232,10 +226,10 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
getAsItemStream(reader).update(executionContext);
|
||||
|
||||
Foo foo2 = reader.read();
|
||||
assertTrue(!foo2.equals(foo1));
|
||||
assertNotEquals(foo2, foo1);
|
||||
|
||||
Foo foo3 = reader.read();
|
||||
assertTrue(!foo2.equals(foo3));
|
||||
assertNotEquals(foo2, foo3);
|
||||
|
||||
getAsItemStream(reader).close();
|
||||
|
||||
@@ -254,17 +248,17 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
@Test
|
||||
@Transactional
|
||||
@DirtiesContext
|
||||
public void testRollbackOnFirstChunkAndRestart() throws Exception {
|
||||
void testRollbackOnFirstChunkAndRestart() throws Exception {
|
||||
|
||||
getAsItemStream(reader).open(executionContext);
|
||||
|
||||
Foo foo1 = reader.read();
|
||||
|
||||
Foo foo2 = reader.read();
|
||||
assertTrue(!foo2.equals(foo1));
|
||||
assertNotEquals(foo2, foo1);
|
||||
|
||||
Foo foo3 = reader.read();
|
||||
assertTrue(!foo2.equals(foo3));
|
||||
assertNotEquals(foo2, foo3);
|
||||
|
||||
getAsItemStream(reader).close();
|
||||
|
||||
@@ -280,7 +274,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
@Test
|
||||
@Transactional
|
||||
@DirtiesContext
|
||||
public void testMultipleRestarts() throws Exception {
|
||||
void testMultipleRestarts() throws Exception {
|
||||
|
||||
getAsItemStream(reader).open(executionContext);
|
||||
|
||||
@@ -289,10 +283,10 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
getAsItemStream(reader).update(executionContext);
|
||||
|
||||
Foo foo2 = reader.read();
|
||||
assertTrue(!foo2.equals(foo1));
|
||||
assertNotEquals(foo2, foo1);
|
||||
|
||||
Foo foo3 = reader.read();
|
||||
assertTrue(!foo2.equals(foo3));
|
||||
assertNotEquals(foo2, foo3);
|
||||
|
||||
getAsItemStream(reader).close();
|
||||
|
||||
@@ -322,7 +316,7 @@ public abstract class AbstractDataSourceItemReaderIntegrationTests {
|
||||
// set transaction to false and make sure the tests work
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testTransacted() throws Exception {
|
||||
void testTransacted() throws Exception {
|
||||
if (reader instanceof JpaPagingItemReader) {
|
||||
((JpaPagingItemReader<Foo>) reader).setTransacted(false);
|
||||
this.testNormalProcessing();
|
||||
|
||||
@@ -36,14 +36,14 @@ public abstract class AbstractDatabaseItemStreamItemReaderTests extends Abstract
|
||||
|
||||
@Override
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
protected void setUp() throws Exception {
|
||||
initializeContext();
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
@AfterEach
|
||||
public void tearDown() throws Exception {
|
||||
protected void tearDown() throws Exception {
|
||||
super.tearDown();
|
||||
ctx.close();
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public abstract class AbstractDatabaseItemStreamItemReaderTests extends Abstract
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadToExhaustion() throws Exception {
|
||||
void testReadToExhaustion() throws Exception {
|
||||
ItemReader<Foo> reader = getItemReader();
|
||||
((ItemStream) reader).open(new ExecutionContext());
|
||||
// pointToEmptyInput(reader);
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
* @author Thomas Risberg
|
||||
*/
|
||||
@SpringJUnitConfig(locations = "data-source-context.xml")
|
||||
public abstract class AbstractGenericDataSourceItemReaderIntegrationTests
|
||||
abstract class AbstractGenericDataSourceItemReaderIntegrationTests
|
||||
extends AbstractDataSourceItemReaderIntegrationTests {
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.batch.item.database;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@@ -60,14 +60,14 @@ public abstract class AbstractJdbcItemReaderIntegrationTests {
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void onSetUp() throws Exception {
|
||||
void onSetUp() throws Exception {
|
||||
itemReader = createItemReader();
|
||||
getAsInitializingBean(itemReader).afterPropertiesSet();
|
||||
executionContext = new ExecutionContext();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void onTearDown() throws Exception {
|
||||
void onTearDown() throws Exception {
|
||||
getAsDisposableBean(itemReader).destroy();
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests {
|
||||
*/
|
||||
@Transactional
|
||||
@Test
|
||||
public void testNormalProcessing() throws Exception {
|
||||
void testNormalProcessing() throws Exception {
|
||||
getAsInitializingBean(itemReader).afterPropertiesSet();
|
||||
getAsItemStream(itemReader).open(executionContext);
|
||||
|
||||
@@ -103,7 +103,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests {
|
||||
*/
|
||||
@Transactional
|
||||
@Test
|
||||
public void testRestart() throws Exception {
|
||||
void testRestart() throws Exception {
|
||||
getAsItemStream(itemReader).open(executionContext);
|
||||
Foo foo1 = itemReader.read();
|
||||
assertEquals(1, foo1.getValue());
|
||||
@@ -126,7 +126,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests {
|
||||
*/
|
||||
@Transactional
|
||||
@Test
|
||||
public void testInvalidRestore() throws Exception {
|
||||
void testInvalidRestore() throws Exception {
|
||||
|
||||
getAsItemStream(itemReader).open(executionContext);
|
||||
Foo foo1 = itemReader.read();
|
||||
@@ -144,13 +144,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests {
|
||||
Foo foo = itemReader.read();
|
||||
assertEquals(1, foo.getValue());
|
||||
|
||||
try {
|
||||
getAsItemStream(itemReader).open(executionContext);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
// expected
|
||||
}
|
||||
assertThrows(IllegalStateException.class, () -> getAsItemStream(itemReader).open(executionContext));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -158,7 +152,7 @@ public abstract class AbstractJdbcItemReaderIntegrationTests {
|
||||
*/
|
||||
@Transactional
|
||||
@Test
|
||||
public void testRestoreFromEmptyData() throws Exception {
|
||||
void testRestoreFromEmptyData() throws Exception {
|
||||
ExecutionContext streamContext = new ExecutionContext();
|
||||
getAsItemStream(itemReader).open(streamContext);
|
||||
Foo foo = itemReader.read();
|
||||
|
||||
@@ -22,11 +22,11 @@ import org.junit.jupiter.api.Test;
|
||||
/**
|
||||
* @author Jimmy Praet
|
||||
*/
|
||||
public abstract class AbstractJdbcPagingItemReaderParameterTests extends AbstractPagingItemReaderParameterTests {
|
||||
abstract class AbstractJdbcPagingItemReaderParameterTests extends AbstractPagingItemReaderParameterTests {
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testReadAfterJumpSecondPage() throws Exception {
|
||||
void testReadAfterJumpSecondPage() throws Exception {
|
||||
executionContext.put(getName() + ".start.after", Collections.<String, Object>singletonMap("ID", 4));
|
||||
super.testReadAfterJumpSecondPage();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.batch.item.database;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
@@ -26,11 +25,14 @@ import org.springframework.batch.item.ItemStream;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
/**
|
||||
* @author Thomas Risberg
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public abstract class AbstractPagingItemReaderParameterTests {
|
||||
abstract class AbstractPagingItemReaderParameterTests {
|
||||
|
||||
protected AbstractPagingItemReader<Foo> tested;
|
||||
|
||||
@@ -40,63 +42,63 @@ public abstract class AbstractPagingItemReaderParameterTests {
|
||||
protected DataSource dataSource;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
void setUp() throws Exception {
|
||||
tested = getItemReader();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
void tearDown() {
|
||||
((ItemStream) tested).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRead() throws Exception {
|
||||
void testRead() throws Exception {
|
||||
|
||||
((ItemStream) tested).open(executionContext);
|
||||
|
||||
Foo foo2 = tested.read();
|
||||
Assertions.assertEquals(2, foo2.getValue());
|
||||
assertEquals(2, foo2.getValue());
|
||||
|
||||
Foo foo3 = tested.read();
|
||||
Assertions.assertEquals(3, foo3.getValue());
|
||||
assertEquals(3, foo3.getValue());
|
||||
|
||||
Foo foo4 = tested.read();
|
||||
Assertions.assertEquals(4, foo4.getValue());
|
||||
assertEquals(4, foo4.getValue());
|
||||
|
||||
Foo foo5 = tested.read();
|
||||
Assertions.assertEquals(5, foo5.getValue());
|
||||
assertEquals(5, foo5.getValue());
|
||||
|
||||
Object o = tested.read();
|
||||
Assertions.assertNull(o);
|
||||
assertNull(o);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadAfterJumpFirstPage() throws Exception {
|
||||
void testReadAfterJumpFirstPage() throws Exception {
|
||||
|
||||
executionContext.putInt(getName() + ".read.count", 2);
|
||||
((ItemStream) tested).open(executionContext);
|
||||
|
||||
Foo foo4 = tested.read();
|
||||
Assertions.assertEquals(4, foo4.getValue());
|
||||
assertEquals(4, foo4.getValue());
|
||||
|
||||
Foo foo5 = tested.read();
|
||||
Assertions.assertEquals(5, foo5.getValue());
|
||||
assertEquals(5, foo5.getValue());
|
||||
|
||||
Object o = tested.read();
|
||||
Assertions.assertNull(o);
|
||||
assertNull(o);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadAfterJumpSecondPage() throws Exception {
|
||||
void testReadAfterJumpSecondPage() throws Exception {
|
||||
|
||||
executionContext.putInt(getName() + ".read.count", 3);
|
||||
((ItemStream) tested).open(executionContext);
|
||||
|
||||
Foo foo5 = tested.read();
|
||||
Assertions.assertEquals(5, foo5.getValue());
|
||||
assertEquals(5, foo5.getValue());
|
||||
|
||||
Object o = tested.read();
|
||||
Assertions.assertNull(o);
|
||||
assertNull(o);
|
||||
}
|
||||
|
||||
protected String getName() {
|
||||
|
||||
@@ -23,7 +23,6 @@ import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.Connection;
|
||||
@@ -46,10 +45,10 @@ import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
public class ExtendedConnectionDataSourceProxyTests {
|
||||
class ExtendedConnectionDataSourceProxyTests {
|
||||
|
||||
@Test
|
||||
public void testOperationWithDataSourceUtils() throws SQLException {
|
||||
void testOperationWithDataSourceUtils() throws SQLException {
|
||||
Connection con = mock(Connection.class);
|
||||
DataSource ds = mock(DataSource.class);
|
||||
|
||||
@@ -77,13 +76,13 @@ public class ExtendedConnectionDataSourceProxyTests {
|
||||
Connection con3 = csds.getConnection();
|
||||
csds.startCloseSuppression(con3);
|
||||
Connection con3_1 = csds.getConnection();
|
||||
assertSame(con3_1, con3, "should be same connection");
|
||||
assertSame(con3, con3_1, "should be same connection");
|
||||
assertFalse(csds.shouldClose(con3), "should not be able to close connection");
|
||||
con3_1.close(); // no mock call for this - should be suppressed
|
||||
Connection con3_2 = csds.getConnection();
|
||||
assertSame(con3_2, con3, "should be same connection");
|
||||
assertSame(con3, con3_2, "should be same connection");
|
||||
Connection con4 = csds.getConnection();
|
||||
assertNotSame(con4, con3, "shouldn't be same connection");
|
||||
assertNotSame(con3, con4, "shouldn't be same connection");
|
||||
csds.stopCloseSuppression(con3);
|
||||
assertTrue(csds.shouldClose(con3), "should be able to close connection");
|
||||
con3_1 = null;
|
||||
@@ -95,7 +94,7 @@ public class ExtendedConnectionDataSourceProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOperationWithDirectCloseCall() throws SQLException {
|
||||
void testOperationWithDirectCloseCall() throws SQLException {
|
||||
Connection con = mock(Connection.class);
|
||||
DataSource ds = mock(DataSource.class);
|
||||
|
||||
@@ -109,12 +108,12 @@ public class ExtendedConnectionDataSourceProxyTests {
|
||||
Connection con1 = csds.getConnection();
|
||||
csds.startCloseSuppression(con1);
|
||||
Connection con1_1 = csds.getConnection();
|
||||
assertSame(con1_1, con1, "should be same connection");
|
||||
assertSame(con1, con1_1, "should be same connection");
|
||||
con1_1.close(); // no mock call for this - should be suppressed
|
||||
Connection con1_2 = csds.getConnection();
|
||||
assertSame(con1_2, con1, "should be same connection");
|
||||
assertSame(con1, con1_2, "should be same connection");
|
||||
Connection con2 = csds.getConnection();
|
||||
assertNotSame(con2, con1, "shouldn't be same connection");
|
||||
assertNotSame(con1, con2, "shouldn't be same connection");
|
||||
csds.stopCloseSuppression(con1);
|
||||
assertTrue(csds.shouldClose(con1), "should be able to close connection");
|
||||
con1_1 = null;
|
||||
@@ -126,7 +125,7 @@ public class ExtendedConnectionDataSourceProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSuppressOfCloseWithJdbcTemplate() throws Exception {
|
||||
void testSuppressOfCloseWithJdbcTemplate() throws Exception {
|
||||
|
||||
Connection con = mock(Connection.class);
|
||||
DataSource ds = mock(DataSource.class);
|
||||
@@ -229,32 +228,25 @@ public class ExtendedConnectionDataSourceProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delegateIsRequired() {
|
||||
void delegateIsRequired() {
|
||||
|
||||
ExtendedConnectionDataSourceProxy tested = new ExtendedConnectionDataSourceProxy(null);
|
||||
assertThrows(IllegalArgumentException.class, tested::afterPropertiesSet);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unwrapForUnsupportedInterface() throws Exception {
|
||||
void unwrapForUnsupportedInterface() throws Exception {
|
||||
|
||||
ExtendedConnectionDataSourceProxy tested = new ExtendedConnectionDataSourceProxy(new DataSourceStub());
|
||||
|
||||
assertFalse(tested.isWrapperFor(Unsupported.class));
|
||||
|
||||
try {
|
||||
tested.unwrap(Unsupported.class);
|
||||
fail();
|
||||
}
|
||||
catch (SQLException expected) {
|
||||
// this would be the correct behavior in a Java6-only recursive implementation
|
||||
// assertEquals(DataSourceStub.UNWRAP_ERROR_MESSAGE, expected.getMessage());
|
||||
assertEquals("Unsupported class " + Unsupported.class.getSimpleName(), expected.getMessage());
|
||||
}
|
||||
Exception expected = assertThrows(SQLException.class, () -> tested.unwrap(Unsupported.class));
|
||||
assertEquals("Unsupported class " + Unsupported.class.getSimpleName(), expected.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unwrapForSupportedInterface() throws Exception {
|
||||
void unwrapForSupportedInterface() throws Exception {
|
||||
|
||||
DataSourceStub ds = new DataSourceStub();
|
||||
ExtendedConnectionDataSourceProxy tested = new ExtendedConnectionDataSourceProxy(ds);
|
||||
@@ -264,7 +256,7 @@ public class ExtendedConnectionDataSourceProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unwrapForSmartDataSource() throws Exception {
|
||||
void unwrapForSmartDataSource() throws Exception {
|
||||
|
||||
ExtendedConnectionDataSourceProxy tested = new ExtendedConnectionDataSourceProxy(new DataSourceStub());
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.batch.item.database;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.hibernate.StatelessSession;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -27,7 +27,7 @@ import org.springframework.batch.item.sample.Foo;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class HibernateCursorItemReaderIntegrationTests extends AbstractHibernateCursorItemReaderIntegrationTests {
|
||||
class HibernateCursorItemReaderIntegrationTests extends AbstractHibernateCursorItemReaderIntegrationTests {
|
||||
|
||||
/**
|
||||
* Exception scenario.
|
||||
@@ -36,18 +36,12 @@ public class HibernateCursorItemReaderIntegrationTests extends AbstractHibernate
|
||||
* only in uninitialized state.
|
||||
*/
|
||||
@Test
|
||||
public void testSetUseStatelessSession() {
|
||||
void testSetUseStatelessSession() {
|
||||
HibernateCursorItemReader<Foo> inputSource = (HibernateCursorItemReader<Foo>) reader;
|
||||
|
||||
// initialize and call setter => error
|
||||
inputSource.open(new ExecutionContext());
|
||||
try {
|
||||
inputSource.setUseStatelessSession(false);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
assertThrows(IllegalStateException.class, () -> inputSource.setUseStatelessSession(false));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ import static org.mockito.Mockito.when;
|
||||
* @author Robert Kasanicky
|
||||
* @author Will Schipp
|
||||
*/
|
||||
public class HibernateCursorItemReaderStatefulIntegrationTests
|
||||
extends AbstractHibernateCursorItemReaderIntegrationTests {
|
||||
class HibernateCursorItemReaderStatefulIntegrationTests extends AbstractHibernateCursorItemReaderIntegrationTests {
|
||||
|
||||
@Override
|
||||
protected boolean isUseStatelessSession() {
|
||||
@@ -43,7 +42,7 @@ public class HibernateCursorItemReaderStatefulIntegrationTests
|
||||
// Ensure close is called on the stateful session correctly.
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testStatefulClose() {
|
||||
void testStatefulClose() {
|
||||
|
||||
SessionFactory sessionFactory = mock(SessionFactory.class);
|
||||
Session session = mock(Session.class);
|
||||
|
||||
@@ -29,8 +29,7 @@ import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* Tests for {@link HibernateCursorItemReader} using {@link StatelessSession}.
|
||||
@@ -38,7 +37,7 @@ import static org.junit.jupiter.api.Assertions.fail;
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
@SpringJUnitConfig(locations = "data-source-context.xml")
|
||||
public class HibernateCursorProjectionItemReaderIntegrationTests {
|
||||
class HibernateCursorProjectionItemReaderIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
@@ -61,7 +60,7 @@ public class HibernateCursorProjectionItemReaderIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleItemsInProjection() throws Exception {
|
||||
void testMultipleItemsInProjection() throws Exception {
|
||||
HibernateCursorItemReader<Object[]> reader = new HibernateCursorItemReader<>();
|
||||
initializeItemReader(reader, "select f.value, f.name from Foo f");
|
||||
Object[] foo1 = reader.read();
|
||||
@@ -69,7 +68,7 @@ public class HibernateCursorProjectionItemReaderIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleItemInProjection() throws Exception {
|
||||
void testSingleItemInProjection() throws Exception {
|
||||
HibernateCursorItemReader<Object> reader = new HibernateCursorItemReader<>();
|
||||
initializeItemReader(reader, "select f.value from Foo f");
|
||||
Object foo1 = reader.read();
|
||||
@@ -77,17 +76,12 @@ public class HibernateCursorProjectionItemReaderIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleItemInProjectionWithArrayType() throws Exception {
|
||||
void testSingleItemInProjectionWithArrayType() throws Exception {
|
||||
HibernateCursorItemReader<Object[]> reader = new HibernateCursorItemReader<>();
|
||||
initializeItemReader(reader, "select f.value from Foo f");
|
||||
try {
|
||||
assertThrows(ClassCastException.class, () -> {
|
||||
Object[] foo1 = reader.read();
|
||||
assertNotNull(foo1);
|
||||
fail("Expected ClassCastException");
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
// expected
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,14 +32,14 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
* @author Will Schipp
|
||||
*
|
||||
*/
|
||||
public class HibernateItemReaderHelperTests {
|
||||
class HibernateItemReaderHelperTests {
|
||||
|
||||
private HibernateItemReaderHelper<String> helper = new HibernateItemReaderHelper<>();
|
||||
private final HibernateItemReaderHelper<String> helper = new HibernateItemReaderHelper<>();
|
||||
|
||||
private SessionFactory sessionFactory = mock(SessionFactory.class);
|
||||
private final SessionFactory sessionFactory = mock(SessionFactory.class);
|
||||
|
||||
@Test
|
||||
public void testOneSessionForAllPages() throws Exception {
|
||||
void testOneSessionForAllPages() {
|
||||
|
||||
StatelessSession session = mock(StatelessSession.class);
|
||||
when(sessionFactory.openStatelessSession()).thenReturn(session);
|
||||
@@ -53,7 +53,7 @@ public class HibernateItemReaderHelperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSessionReset() throws Exception {
|
||||
void testSessionReset() {
|
||||
|
||||
StatelessSession session = mock(StatelessSession.class);
|
||||
when(sessionFactory.openStatelessSession()).thenReturn(session);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.batch.item.database;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.Session;
|
||||
@@ -25,8 +24,8 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -37,7 +36,7 @@ import static org.mockito.Mockito.when;
|
||||
* @author Will Schipp
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class HibernateItemWriterTests {
|
||||
class HibernateItemWriterTests {
|
||||
|
||||
HibernateItemWriter<Object> writer;
|
||||
|
||||
@@ -46,7 +45,7 @@ public class HibernateItemWriterTests {
|
||||
Session currentSession;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
void setUp() {
|
||||
writer = new HibernateItemWriter<>();
|
||||
factory = mock(SessionFactory.class);
|
||||
currentSession = mock(Session.class);
|
||||
@@ -57,34 +56,27 @@ public class HibernateItemWriterTests {
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.database.HibernateItemWriter#afterPropertiesSet()}
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testAfterPropertiesSet() throws Exception {
|
||||
void testAfterPropertiesSet() {
|
||||
writer = new HibernateItemWriter<>();
|
||||
try {
|
||||
writer.afterPropertiesSet();
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
// expected
|
||||
assertTrue(e.getMessage().contains("SessionFactory"), "Wrong message for exception: " + e.getMessage());
|
||||
}
|
||||
Exception exception = assertThrows(IllegalStateException.class, writer::afterPropertiesSet);
|
||||
String message = exception.getMessage();
|
||||
assertTrue(message.contains("SessionFactory"), "Wrong message for exception: " + message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.database.HibernateItemWriter#afterPropertiesSet()}
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testAfterPropertiesSetWithDelegate() throws Exception {
|
||||
void testAfterPropertiesSetWithDelegate() {
|
||||
writer.setSessionFactory(this.factory);
|
||||
writer.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteAndFlushSunnyDayHibernate3() throws Exception {
|
||||
void testWriteAndFlushSunnyDayHibernate3() {
|
||||
this.writer.setSessionFactory(this.factory);
|
||||
when(this.currentSession.contains("foo")).thenReturn(true);
|
||||
when(this.currentSession.contains("bar")).thenReturn(false);
|
||||
@@ -98,23 +90,17 @@ public class HibernateItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteAndFlushWithFailureHibernate3() throws Exception {
|
||||
void testWriteAndFlushWithFailureHibernate3() {
|
||||
this.writer.setSessionFactory(this.factory);
|
||||
final RuntimeException ex = new RuntimeException("ERROR");
|
||||
when(this.currentSession.contains("foo")).thenThrow(ex);
|
||||
|
||||
try {
|
||||
writer.write(Collections.singletonList("foo"));
|
||||
fail("Expected RuntimeException");
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals("ERROR", e.getMessage());
|
||||
}
|
||||
|
||||
Exception exception = assertThrows(RuntimeException.class, () -> writer.write(List.of("foo")));
|
||||
assertEquals("ERROR", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteAndFlushSunnyDayHibernate4() throws Exception {
|
||||
void testWriteAndFlushSunnyDayHibernate4() {
|
||||
writer.setSessionFactory(factory);
|
||||
when(factory.getCurrentSession()).thenReturn(currentSession);
|
||||
when(currentSession.contains("foo")).thenReturn(true);
|
||||
@@ -128,20 +114,15 @@ public class HibernateItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteAndFlushWithFailureHibernate4() throws Exception {
|
||||
void testWriteAndFlushWithFailureHibernate4() {
|
||||
writer.setSessionFactory(factory);
|
||||
final RuntimeException ex = new RuntimeException("ERROR");
|
||||
|
||||
when(factory.getCurrentSession()).thenReturn(currentSession);
|
||||
when(currentSession.contains("foo")).thenThrow(ex);
|
||||
|
||||
try {
|
||||
writer.write(Collections.singletonList("foo"));
|
||||
fail("Expected RuntimeException");
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals("ERROR", e.getMessage());
|
||||
}
|
||||
Exception exception = assertThrows(RuntimeException.class, () -> writer.write(List.of("foo")));
|
||||
assertEquals("ERROR", exception.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
* @author Thomas Risberg
|
||||
* @author Will Schipp
|
||||
*/
|
||||
public class JdbcBatchItemWriterClassicTests {
|
||||
class JdbcBatchItemWriterClassicTests {
|
||||
|
||||
private JdbcBatchItemWriter<String> writer = new JdbcBatchItemWriter<>();
|
||||
|
||||
@@ -50,7 +50,7 @@ public class JdbcBatchItemWriterClassicTests {
|
||||
private PreparedStatement ps;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
void setUp() {
|
||||
ps = mock(PreparedStatement.class);
|
||||
jdbcTemplate = new JdbcTemplate() {
|
||||
@Override
|
||||
@@ -78,54 +78,31 @@ public class JdbcBatchItemWriterClassicTests {
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.item.database.JdbcBatchItemWriter#afterPropertiesSet()}
|
||||
* .
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testAfterPropertiesSet() throws Exception {
|
||||
void testAfterPropertiesSet() {
|
||||
writer = new JdbcBatchItemWriter<>();
|
||||
try {
|
||||
writer.afterPropertiesSet();
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
String message = e.getMessage();
|
||||
assertTrue(message.contains("NamedParameterJdbcTemplate"),
|
||||
"Message does not contain ' NamedParameterJdbcTemplate'.");
|
||||
}
|
||||
writer.setJdbcTemplate(new NamedParameterJdbcTemplate(jdbcTemplate));
|
||||
try {
|
||||
writer.afterPropertiesSet();
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
String message = e.getMessage().toLowerCase();
|
||||
assertTrue(message.contains("sql"), "Message does not contain 'sql'.");
|
||||
}
|
||||
writer.setSql("select * from foo where id = ?");
|
||||
try {
|
||||
writer.afterPropertiesSet();
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
String message = e.getMessage();
|
||||
assertTrue(message.contains("ItemPreparedStatementSetter"),
|
||||
"Message does not contain 'ItemPreparedStatementSetter'.");
|
||||
}
|
||||
writer.setItemPreparedStatementSetter(new ItemPreparedStatementSetter<String>() {
|
||||
@Override
|
||||
public void setValues(String item, PreparedStatement ps) throws SQLException {
|
||||
}
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet);
|
||||
assertTrue(exception.getMessage().contains("NamedParameterJdbcTemplate"),
|
||||
"Message does not contain ' NamedParameterJdbcTemplate'.");
|
||||
|
||||
writer.setJdbcTemplate(new NamedParameterJdbcTemplate(jdbcTemplate));
|
||||
exception = assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet);
|
||||
String message = exception.getMessage();
|
||||
assertTrue(message.toLowerCase().contains("sql"), "Message does not contain 'sql'.");
|
||||
|
||||
writer.setSql("select * from foo where id = ?");
|
||||
exception = assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet);
|
||||
assertTrue(exception.getMessage().contains("ItemPreparedStatementSetter"),
|
||||
"Message does not contain 'ItemPreparedStatementSetter'.");
|
||||
|
||||
writer.setItemPreparedStatementSetter((item, ps) -> {
|
||||
});
|
||||
writer.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteAndFlush() throws Exception {
|
||||
void testWriteAndFlush() throws Exception {
|
||||
ps.addBatch();
|
||||
when(ps.executeBatch()).thenReturn(new int[] { 123 });
|
||||
writer.write(Collections.singletonList("bar"));
|
||||
@@ -134,24 +111,18 @@ public class JdbcBatchItemWriterClassicTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteAndFlushWithEmptyUpdate() throws Exception {
|
||||
void testWriteAndFlushWithEmptyUpdate() throws Exception {
|
||||
ps.addBatch();
|
||||
when(ps.executeBatch()).thenReturn(new int[] { 0 });
|
||||
try {
|
||||
writer.write(Collections.singletonList("bar"));
|
||||
fail("Expected EmptyResultDataAccessException");
|
||||
}
|
||||
catch (EmptyResultDataAccessException e) {
|
||||
// expected
|
||||
String message = e.getMessage();
|
||||
assertTrue(message.contains("did not update"), "Wrong message: " + message);
|
||||
}
|
||||
Exception exception = assertThrows(EmptyResultDataAccessException.class, () -> writer.write(List.of("bar")));
|
||||
String message = exception.getMessage();
|
||||
assertTrue(message.contains("did not update"), "Wrong message: " + message);
|
||||
assertEquals(2, list.size());
|
||||
assertTrue(list.contains("SQL"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteAndFlushWithFailure() throws Exception {
|
||||
void testWriteAndFlushWithFailure() throws Exception {
|
||||
final RuntimeException ex = new RuntimeException("bar");
|
||||
writer.setItemPreparedStatementSetter(new ItemPreparedStatementSetter<String>() {
|
||||
@Override
|
||||
@@ -162,13 +133,8 @@ public class JdbcBatchItemWriterClassicTests {
|
||||
});
|
||||
ps.addBatch();
|
||||
when(ps.executeBatch()).thenReturn(new int[] { 123 });
|
||||
try {
|
||||
writer.write(Collections.singletonList("foo"));
|
||||
fail("Expected RuntimeException");
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals("bar", e.getMessage());
|
||||
}
|
||||
Exception exception = assertThrows(RuntimeException.class, () -> writer.write(List.of("foo")));
|
||||
assertEquals("bar", exception.getMessage());
|
||||
assertEquals(2, list.size());
|
||||
writer.setItemPreparedStatementSetter(new ItemPreparedStatementSetter<String>() {
|
||||
@Override
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.batch.item.database;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hamcrest.BaseMatcher;
|
||||
@@ -31,8 +31,8 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -50,7 +50,7 @@ public class JdbcBatchItemWriterNamedParameterTests {
|
||||
|
||||
private NamedParameterJdbcOperations namedParameterJdbcOperations;
|
||||
|
||||
private String sql = "update foo set bar = :bar where id = :id";
|
||||
private final String sql = "update foo set bar = :bar where id = :id";
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private class Foo {
|
||||
@@ -83,7 +83,7 @@ public class JdbcBatchItemWriterNamedParameterTests {
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
void setUp() {
|
||||
namedParameterJdbcOperations = mock(NamedParameterJdbcOperations.class);
|
||||
writer.setSql(sql);
|
||||
writer.setJdbcTemplate(namedParameterJdbcOperations);
|
||||
@@ -97,45 +97,34 @@ public class JdbcBatchItemWriterNamedParameterTests {
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testAfterPropertiesSet() throws Exception {
|
||||
void testAfterPropertiesSet() {
|
||||
writer = new JdbcBatchItemWriter<>();
|
||||
try {
|
||||
writer.afterPropertiesSet();
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
String message = e.getMessage();
|
||||
assertTrue(message.contains("NamedParameterJdbcTemplate"),
|
||||
"Message does not contain 'NamedParameterJdbcTemplate'.");
|
||||
}
|
||||
writer.setJdbcTemplate(namedParameterJdbcOperations);
|
||||
try {
|
||||
writer.afterPropertiesSet();
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
String message = e.getMessage().toLowerCase();
|
||||
assertTrue(message.contains("sql"), "Message does not contain 'sql'.");
|
||||
}
|
||||
writer.setSql("select * from foo where id = :id");
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet);
|
||||
String message = exception.getMessage();
|
||||
assertTrue(message.contains("NamedParameterJdbcTemplate"),
|
||||
"Message does not contain 'NamedParameterJdbcTemplate'.");
|
||||
|
||||
writer.setJdbcTemplate(namedParameterJdbcOperations);
|
||||
exception = assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet);
|
||||
message = exception.getMessage().toLowerCase();
|
||||
assertTrue(message.contains("sql"), "Message does not contain 'sql'.");
|
||||
|
||||
writer.setSql("select * from foo where id = :id");
|
||||
writer.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteAndFlush() throws Exception {
|
||||
void testWriteAndFlush() throws Exception {
|
||||
when(namedParameterJdbcOperations.batchUpdate(eq(sql),
|
||||
eqSqlParameterSourceArray(
|
||||
new SqlParameterSource[] { new BeanPropertySqlParameterSource(new Foo("bar")) })))
|
||||
.thenReturn(new int[] { 1 });
|
||||
writer.write(Collections.singletonList(new Foo("bar")));
|
||||
writer.write(List.of(new Foo("bar")));
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void testWriteAndFlushMap() throws Exception {
|
||||
void testWriteAndFlushMap() throws Exception {
|
||||
JdbcBatchItemWriter<Map<String, Object>> mapWriter = new JdbcBatchItemWriter<>();
|
||||
|
||||
mapWriter.setSql(sql);
|
||||
@@ -145,7 +134,7 @@ public class JdbcBatchItemWriterNamedParameterTests {
|
||||
ArgumentCaptor<Map[]> captor = ArgumentCaptor.forClass(Map[].class);
|
||||
|
||||
when(namedParameterJdbcOperations.batchUpdate(eq(sql), captor.capture())).thenReturn(new int[] { 1 });
|
||||
mapWriter.write(Collections.singletonList(Collections.singletonMap("foo", "bar")));
|
||||
mapWriter.write(List.of(Map.of("foo", "bar")));
|
||||
|
||||
assertEquals(1, captor.getValue().length);
|
||||
Map<String, Object> results = captor.getValue()[0];
|
||||
@@ -153,7 +142,7 @@ public class JdbcBatchItemWriterNamedParameterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteAndFlushMapWithItemSqlParameterSourceProvider() throws Exception {
|
||||
void testWriteAndFlushMapWithItemSqlParameterSourceProvider() throws Exception {
|
||||
JdbcBatchItemWriter<Map<String, Object>> mapWriter = new JdbcBatchItemWriter<>();
|
||||
|
||||
mapWriter.setSql(sql);
|
||||
@@ -169,7 +158,7 @@ public class JdbcBatchItemWriterNamedParameterTests {
|
||||
ArgumentCaptor<SqlParameterSource[]> captor = ArgumentCaptor.forClass(SqlParameterSource[].class);
|
||||
|
||||
when(namedParameterJdbcOperations.batchUpdate(any(String.class), captor.capture())).thenReturn(new int[] { 1 });
|
||||
mapWriter.write(Collections.singletonList(Collections.singletonMap("foo", "bar")));
|
||||
mapWriter.write(List.of(Map.of("foo", "bar")));
|
||||
|
||||
assertEquals(1, captor.getValue().length);
|
||||
SqlParameterSource results = captor.getValue()[0];
|
||||
@@ -177,36 +166,26 @@ public class JdbcBatchItemWriterNamedParameterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteAndFlushWithEmptyUpdate() throws Exception {
|
||||
void testWriteAndFlushWithEmptyUpdate() {
|
||||
when(namedParameterJdbcOperations.batchUpdate(eq(sql),
|
||||
eqSqlParameterSourceArray(
|
||||
new SqlParameterSource[] { new BeanPropertySqlParameterSource(new Foo("bar")) })))
|
||||
.thenReturn(new int[] { 0 });
|
||||
try {
|
||||
writer.write(Collections.singletonList(new Foo("bar")));
|
||||
fail("Expected EmptyResultDataAccessException");
|
||||
}
|
||||
catch (EmptyResultDataAccessException e) {
|
||||
// expected
|
||||
String message = e.getMessage();
|
||||
assertTrue(message.contains("did not update"), "Wrong message: " + message);
|
||||
}
|
||||
Exception exception = assertThrows(EmptyResultDataAccessException.class,
|
||||
() -> writer.write(List.of(new Foo("bar"))));
|
||||
String message = exception.getMessage();
|
||||
assertTrue(message.contains("did not update"), "Wrong message: " + message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteAndFlushWithFailure() throws Exception {
|
||||
void testWriteAndFlushWithFailure() {
|
||||
final RuntimeException ex = new RuntimeException("ERROR");
|
||||
when(namedParameterJdbcOperations.batchUpdate(eq(sql),
|
||||
eqSqlParameterSourceArray(
|
||||
new SqlParameterSource[] { new BeanPropertySqlParameterSource(new Foo("bar")) })))
|
||||
.thenThrow(ex);
|
||||
try {
|
||||
writer.write(Collections.singletonList(new Foo("bar")));
|
||||
fail("Expected RuntimeException");
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals("ERROR", e.getMessage());
|
||||
}
|
||||
Exception exception = assertThrows(RuntimeException.class, () -> writer.write(List.of(new Foo("bar"))));
|
||||
assertEquals("ERROR", exception.getMessage());
|
||||
}
|
||||
|
||||
public static SqlParameterSource[] eqSqlParameterSourceArray(SqlParameterSource[] in) {
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.batch.item.sample.Foo;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class JdbcCursorItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests {
|
||||
class JdbcCursorItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests {
|
||||
|
||||
@Override
|
||||
protected ItemReader<Foo> getItemReader() throws Exception {
|
||||
@@ -45,7 +45,7 @@ public class JdbcCursorItemReaderCommonTests extends AbstractDatabaseItemStreamI
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestartWithDriverSupportsAbsolute() throws Exception {
|
||||
void testRestartWithDriverSupportsAbsolute() throws Exception {
|
||||
tested = getItemReader();
|
||||
((JdbcCursorItemReader<Foo>) tested).setDriverSupportsAbsolute(true);
|
||||
testedAsStream().open(executionContext);
|
||||
@@ -63,7 +63,7 @@ public class JdbcCursorItemReaderCommonTests extends AbstractDatabaseItemStreamI
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadBeforeOpen() throws Exception {
|
||||
void testReadBeforeOpen() throws Exception {
|
||||
tested = getItemReader();
|
||||
assertThrows(ReaderNotOpenException.class, tested::read);
|
||||
}
|
||||
|
||||
@@ -37,13 +37,13 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class JdbcCursorItemReaderConfigTests {
|
||||
class JdbcCursorItemReaderConfigTests {
|
||||
|
||||
/*
|
||||
* Should fail if trying to call getConnection() twice
|
||||
*/
|
||||
@Test
|
||||
public void testUsesCurrentTransaction() throws Exception {
|
||||
void testUsesCurrentTransaction() throws Exception {
|
||||
DataSource ds = mock(DataSource.class);
|
||||
Connection con = mock(Connection.class);
|
||||
when(con.getAutoCommit()).thenReturn(false);
|
||||
@@ -74,7 +74,7 @@ public class JdbcCursorItemReaderConfigTests {
|
||||
* Should fail if trying to call getConnection() twice
|
||||
*/
|
||||
@Test
|
||||
public void testUsesItsOwnTransaction() throws Exception {
|
||||
void testUsesItsOwnTransaction() throws Exception {
|
||||
|
||||
DataSource ds = mock(DataSource.class);
|
||||
Connection con = mock(Connection.class);
|
||||
@@ -102,7 +102,7 @@ public class JdbcCursorItemReaderConfigTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOverrideConnectionAutoCommit() throws Exception {
|
||||
void testOverrideConnectionAutoCommit() throws Exception {
|
||||
boolean initialAutoCommit = false;
|
||||
boolean neededAutoCommit = true;
|
||||
|
||||
|
||||
@@ -23,10 +23,10 @@ import org.springframework.batch.item.sample.Foo;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
public class JdbcCursorItemReaderIntegrationTests extends AbstractGenericDataSourceItemReaderIntegrationTests {
|
||||
class JdbcCursorItemReaderIntegrationTests extends AbstractGenericDataSourceItemReaderIntegrationTests {
|
||||
|
||||
@Override
|
||||
protected ItemReader<Foo> createItemReader() throws Exception {
|
||||
protected ItemReader<Foo> createItemReader() {
|
||||
JdbcCursorItemReader<Foo> result = new JdbcCursorItemReader<>();
|
||||
result.setDataSource(dataSource);
|
||||
result.setSql("select ID, NAME, VALUE from T_FOOS");
|
||||
|
||||
@@ -50,7 +50,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
@SpringJUnitConfig(locations = "JdbcPagingItemReaderCommonTests-context.xml")
|
||||
public class JdbcPagingItemReaderAsyncTests {
|
||||
class JdbcPagingItemReaderAsyncTests {
|
||||
|
||||
/**
|
||||
* The page size
|
||||
@@ -67,7 +67,7 @@ public class JdbcPagingItemReaderAsyncTests {
|
||||
*/
|
||||
private static final int THREAD_COUNT = 3;
|
||||
|
||||
private static Log logger = LogFactory.getLog(JdbcPagingItemReaderAsyncTests.class);
|
||||
private static final Log logger = LogFactory.getLog(JdbcPagingItemReaderAsyncTests.class);
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
@@ -75,7 +75,7 @@ public class JdbcPagingItemReaderAsyncTests {
|
||||
private int maxId;
|
||||
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
void init() {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
Integer maxIdResult = jdbcTemplate.queryForObject("SELECT MAX(ID) from T_FOOS", Integer.class);
|
||||
maxId = maxIdResult == null ? 0 : maxIdResult;
|
||||
@@ -86,13 +86,13 @@ public class JdbcPagingItemReaderAsyncTests {
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void destroy() {
|
||||
void destroy() {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsyncReader() throws Throwable {
|
||||
void testAsyncReader() {
|
||||
List<Throwable> throwables = new ArrayList<>();
|
||||
int max = 10;
|
||||
for (int i = 0; i < max; i++) {
|
||||
|
||||
@@ -37,7 +37,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
*/
|
||||
@SpringJUnitConfig(
|
||||
locations = "/org/springframework/batch/item/database/JdbcPagingItemReaderParameterTests-context.xml")
|
||||
public class JdbcPagingItemReaderClassicParameterTests extends AbstractJdbcPagingItemReaderParameterTests {
|
||||
class JdbcPagingItemReaderClassicParameterTests extends AbstractJdbcPagingItemReaderParameterTests {
|
||||
|
||||
// force jumpToItemQuery in JdbcPagingItemReader.doJumpToPage(int)
|
||||
private static boolean forceJumpToItemQuery = false;
|
||||
@@ -82,7 +82,7 @@ public class JdbcPagingItemReaderClassicParameterTests extends AbstractJdbcPagin
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadAfterJumpSecondPageWithJumpToItemQuery() throws Exception {
|
||||
void testReadAfterJumpSecondPageWithJumpToItemQuery() throws Exception {
|
||||
try {
|
||||
forceJumpToItemQuery = true;
|
||||
super.testReadAfterJumpSecondPage();
|
||||
|
||||
@@ -27,13 +27,13 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
@SpringJUnitConfig
|
||||
public class JdbcPagingItemReaderConfigTests {
|
||||
class JdbcPagingItemReaderConfigTests {
|
||||
|
||||
@Autowired
|
||||
private JdbcPagingItemReader<Object> jdbcPagingItemReader;
|
||||
|
||||
@Test
|
||||
public void testConfig() {
|
||||
void testConfig() {
|
||||
assertNotNull(jdbcPagingItemReader);
|
||||
NamedParameterJdbcTemplate namedParameterJdbcTemplate = (NamedParameterJdbcTemplate) ReflectionTestUtils
|
||||
.getField(jdbcPagingItemReader, "namedParameterJdbcTemplate");
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.jdbc.core.SingleColumnRowMapper;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
@SpringJUnitConfig(locations = "JdbcPagingItemReaderCommonTests-context.xml")
|
||||
public class JdbcPagingItemReaderEmptyResultSetTests {
|
||||
class JdbcPagingItemReaderEmptyResultSetTests {
|
||||
|
||||
private static final int PAGE_SIZE = 2;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class JdbcPagingItemReaderEmptyResultSetTests {
|
||||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void testMultiplePageReadsOnEmptyResultSet() throws Exception {
|
||||
void testMultiplePageReadsOnEmptyResultSet() throws Exception {
|
||||
final ItemReader<Long> reader = getItemReader();
|
||||
for (int i = 0; i < EMPTY_READS; i++) {
|
||||
assertNull(reader.read());
|
||||
|
||||
@@ -41,7 +41,7 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
// independent of
|
||||
// other
|
||||
// tests
|
||||
public class JdbcPagingItemReaderNamedParameterTests extends AbstractJdbcPagingItemReaderParameterTests {
|
||||
class JdbcPagingItemReaderNamedParameterTests extends AbstractJdbcPagingItemReaderParameterTests {
|
||||
|
||||
// force jumpToItemQuery in JdbcPagingItemReader.doJumpToPage(int)
|
||||
private static boolean forceJumpToItemQuery = false;
|
||||
@@ -86,7 +86,7 @@ public class JdbcPagingItemReaderNamedParameterTests extends AbstractJdbcPagingI
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadAfterJumpSecondPageWithJumpToItemQuery() throws Exception {
|
||||
void testReadAfterJumpSecondPageWithJumpToItemQuery() throws Exception {
|
||||
try {
|
||||
forceJumpToItemQuery = true;
|
||||
super.testReadAfterJumpSecondPage();
|
||||
|
||||
@@ -50,9 +50,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
*/
|
||||
@SpringJUnitConfig(locations = "JdbcPagingItemReaderCommonTests-context.xml")
|
||||
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
|
||||
public class JdbcPagingQueryIntegrationTests {
|
||||
class JdbcPagingQueryIntegrationTests {
|
||||
|
||||
private static Log logger = LogFactory.getLog(JdbcPagingQueryIntegrationTests.class);
|
||||
private static final Log logger = LogFactory.getLog(JdbcPagingQueryIntegrationTests.class);
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
@@ -61,12 +61,10 @@ public class JdbcPagingQueryIntegrationTests {
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
private int itemCount = 9;
|
||||
|
||||
private int pageSize = 2;
|
||||
private final int pageSize = 2;
|
||||
|
||||
@BeforeEach
|
||||
public void testInit() {
|
||||
void testInit() {
|
||||
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
String[] names = { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" };
|
||||
String[] codes = { "A", "B", "A", "B", "B", "B", "A", "B", "A" };
|
||||
@@ -76,16 +74,16 @@ public class JdbcPagingQueryIntegrationTests {
|
||||
codes[i], i);
|
||||
maxId++;
|
||||
}
|
||||
assertEquals(itemCount, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
|
||||
assertEquals(9, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS"));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void destroy() {
|
||||
void destroy() {
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_FOOS");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryFromStart() throws Exception {
|
||||
void testQueryFromStart() throws Exception {
|
||||
|
||||
PagingQueryProvider queryProvider = getPagingQueryProvider();
|
||||
|
||||
@@ -123,7 +121,7 @@ public class JdbcPagingQueryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryFromStartWithGroupBy() throws Exception {
|
||||
void testQueryFromStartWithGroupBy() throws Exception {
|
||||
AbstractSqlPagingQueryProvider queryProvider = (AbstractSqlPagingQueryProvider) getPagingQueryProvider();
|
||||
Map<String, Order> sortKeys = new LinkedHashMap<>();
|
||||
sortKeys.put("NAME", Order.ASCENDING);
|
||||
@@ -169,7 +167,7 @@ public class JdbcPagingQueryIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJumpToItem() throws Exception {
|
||||
void testJumpToItem() throws Exception {
|
||||
|
||||
PagingQueryProvider queryProvider = getPagingQueryProvider();
|
||||
|
||||
|
||||
@@ -52,9 +52,9 @@ import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
* @since 2.1
|
||||
*/
|
||||
@SpringJUnitConfig(locations = "JdbcPagingItemReaderCommonTests-context.xml")
|
||||
public class JdbcPagingRestartIntegrationTests {
|
||||
class JdbcPagingRestartIntegrationTests {
|
||||
|
||||
private static Log logger = LogFactory.getLog(JdbcPagingRestartIntegrationTests.class);
|
||||
private static final Log logger = LogFactory.getLog(JdbcPagingRestartIntegrationTests.class);
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
@@ -63,12 +63,12 @@ public class JdbcPagingRestartIntegrationTests {
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
private int itemCount = 9;
|
||||
private final int itemCount = 9;
|
||||
|
||||
private int pageSize = 2;
|
||||
private final int pageSize = 2;
|
||||
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
void init() {
|
||||
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
maxId = jdbcTemplate.queryForObject("SELECT MAX(ID) from T_FOOS", Integer.class);
|
||||
for (int i = itemCount; i > maxId; i--) {
|
||||
@@ -79,13 +79,13 @@ public class JdbcPagingRestartIntegrationTests {
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void destroy() {
|
||||
void destroy() {
|
||||
jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // FIXME
|
||||
public void testReaderFromStart() throws Exception {
|
||||
void testReaderFromStart() throws Exception {
|
||||
|
||||
ItemReader<Foo> reader = getItemReader();
|
||||
|
||||
@@ -108,7 +108,7 @@ public class JdbcPagingRestartIntegrationTests {
|
||||
|
||||
@Test
|
||||
@Disabled // FIXME
|
||||
public void testReaderOnRestart() throws Exception {
|
||||
void testReaderOnRestart() throws Exception {
|
||||
|
||||
ItemReader<Foo> reader = getItemReader();
|
||||
|
||||
|
||||
@@ -25,10 +25,10 @@ import java.util.ArrayList;
|
||||
/**
|
||||
* @author Thomas Risberg
|
||||
*/
|
||||
public class JdbcParameterUtilsTests {
|
||||
class JdbcParameterUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testCountParameterPlaceholders() {
|
||||
void testCountParameterPlaceholders() {
|
||||
assertEquals(0, JdbcParameterUtils.countParameterPlaceholders(null, null));
|
||||
assertEquals(0, JdbcParameterUtils.countParameterPlaceholders("", null));
|
||||
assertEquals(1, JdbcParameterUtils.countParameterPlaceholders("?", null));
|
||||
|
||||
@@ -47,7 +47,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@SpringJUnitConfig(classes = JpaItemWriterIntegrationTests.JpaConfiguration.class)
|
||||
@Transactional
|
||||
@DirtiesContext
|
||||
public class JpaItemWriterIntegrationTests {
|
||||
class JpaItemWriterIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
@@ -56,17 +56,17 @@ public class JpaItemWriterIntegrationTests {
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
void init() {
|
||||
this.jdbcTemplate.update("create table person (id int not null primary key, name varchar(32))");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void destroy() {
|
||||
void destroy() {
|
||||
JdbcTestUtils.dropTables(this.jdbcTemplate, "person");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMerge() throws Exception {
|
||||
void testMerge() throws Exception {
|
||||
// given
|
||||
JpaItemWriter<Person> writer = new JpaItemWriter<>();
|
||||
writer.setEntityManagerFactory(this.entityManagerFactory);
|
||||
@@ -81,7 +81,7 @@ public class JpaItemWriterIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersist() throws Exception {
|
||||
void testPersist() throws Exception {
|
||||
// given
|
||||
JpaItemWriter<Person> writer = new JpaItemWriter<>();
|
||||
writer.setEntityManagerFactory(this.entityManagerFactory);
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
package org.springframework.batch.item.database;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -40,14 +40,14 @@ import org.springframework.transaction.support.TransactionSynchronizationManager
|
||||
* @author Chris Cranford
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class JpaItemWriterTests {
|
||||
class JpaItemWriterTests {
|
||||
|
||||
EntityManagerFactory emf;
|
||||
|
||||
JpaItemWriter<Object> writer;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
void setUp() {
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
TransactionSynchronizationManager.clearSynchronization();
|
||||
}
|
||||
@@ -57,21 +57,15 @@ public class JpaItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAfterPropertiesSet() throws Exception {
|
||||
void testAfterPropertiesSet() {
|
||||
writer = new JpaItemWriter<>();
|
||||
try {
|
||||
writer.afterPropertiesSet();
|
||||
fail("Expected IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
assertTrue(e.getMessage().contains("EntityManagerFactory"),
|
||||
"Wrong message for exception: " + e.getMessage());
|
||||
}
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, writer::afterPropertiesSet);
|
||||
String message = exception.getMessage();
|
||||
assertTrue(message.contains("EntityManagerFactory"), "Wrong message for exception: " + message);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteAndFlushSunnyDay() throws Exception {
|
||||
void testWriteAndFlushSunnyDay() {
|
||||
EntityManager em = mock(EntityManager.class, "em");
|
||||
em.contains("foo");
|
||||
em.contains("bar");
|
||||
@@ -87,7 +81,7 @@ public class JpaItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersist() throws Exception {
|
||||
void testPersist() {
|
||||
writer.setUsePersist(true);
|
||||
EntityManager em = mock(EntityManager.class, "em");
|
||||
TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em));
|
||||
@@ -99,7 +93,7 @@ public class JpaItemWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWriteAndFlushWithFailure() throws Exception {
|
||||
void testWriteAndFlushWithFailure() {
|
||||
final RuntimeException ex = new RuntimeException("ERROR");
|
||||
EntityManager em = mock(EntityManager.class, "em");
|
||||
em.contains("foo");
|
||||
@@ -107,15 +101,9 @@ public class JpaItemWriterTests {
|
||||
em.merge("bar");
|
||||
when(em).thenThrow(ex);
|
||||
TransactionSynchronizationManager.bindResource(emf, new EntityManagerHolder(em));
|
||||
List<String> items = Arrays.asList(new String[] { "foo", "bar" });
|
||||
|
||||
try {
|
||||
writer.write(items);
|
||||
fail("Expected RuntimeException");
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertEquals("ERROR", e.getMessage());
|
||||
}
|
||||
Exception exception = assertThrows(RuntimeException.class, () -> writer.write(List.of("foo", "bar")));
|
||||
assertEquals("ERROR", exception.getMessage());
|
||||
|
||||
TransactionSynchronizationManager.unbindResource(emf);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class JpaNativeQueryProviderIntegrationTests {
|
||||
@Autowired
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
private JpaNativeQueryProvider<Foo> jpaQueryProvider;
|
||||
private final JpaNativeQueryProvider<Foo> jpaQueryProvider;
|
||||
|
||||
public JpaNativeQueryProviderIntegrationTests() {
|
||||
jpaQueryProvider = new JpaNativeQueryProvider<>();
|
||||
@@ -51,7 +51,7 @@ public class JpaNativeQueryProviderIntegrationTests {
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void shouldRetrieveAndMapAllFoos() throws Exception {
|
||||
void shouldRetrieveAndMapAllFoos() throws Exception {
|
||||
|
||||
String sqlQuery = "select * from T_FOOS";
|
||||
jpaQueryProvider.setSqlQuery(sqlQuery);
|
||||
@@ -76,7 +76,7 @@ public class JpaNativeQueryProviderIntegrationTests {
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void shouldExecuteParameterizedQuery() throws Exception {
|
||||
void shouldExecuteParameterizedQuery() throws Exception {
|
||||
|
||||
String sqlQuery = "select * from T_FOOS where value >= :limit";
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.test.jdbc.JdbcTestUtils;
|
||||
|
||||
@SpringJUnitConfig(locations = "JpaPagingItemReaderCommonTests-context.xml")
|
||||
public class JpaPagingItemReaderAsyncTests {
|
||||
class JpaPagingItemReaderAsyncTests {
|
||||
|
||||
/**
|
||||
* The number of items to read
|
||||
@@ -56,7 +56,7 @@ public class JpaPagingItemReaderAsyncTests {
|
||||
*/
|
||||
private static final int THREAD_COUNT = 3;
|
||||
|
||||
private static Log logger = LogFactory.getLog(JpaPagingItemReaderAsyncTests.class);
|
||||
private static final Log logger = LogFactory.getLog(JpaPagingItemReaderAsyncTests.class);
|
||||
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
@@ -67,7 +67,7 @@ public class JpaPagingItemReaderAsyncTests {
|
||||
private int maxId;
|
||||
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
void init() {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
maxId = jdbcTemplate.queryForObject("SELECT MAX(ID) from T_FOOS", Integer.class);
|
||||
for (int i = maxId + 1; i <= ITEM_COUNT; i++) {
|
||||
@@ -77,13 +77,13 @@ public class JpaPagingItemReaderAsyncTests {
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void destroy() {
|
||||
void destroy() {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAsyncReader() throws Throwable {
|
||||
void testAsyncReader() {
|
||||
List<Throwable> throwables = new ArrayList<>();
|
||||
int max = 10;
|
||||
for (int i = 0; i < max; i++) {
|
||||
|
||||
@@ -33,7 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@SpringJUnitConfig(locations = "RepositoryItemReaderCommonTests-context.xml")
|
||||
@Transactional
|
||||
public class RepositoryItemReaderIntegrationTests {
|
||||
class RepositoryItemReaderIntegrationTests {
|
||||
|
||||
private static final String CONTEXT_KEY = "RepositoryItemReader.read.count";
|
||||
|
||||
@@ -41,12 +41,12 @@ public class RepositoryItemReaderIntegrationTests {
|
||||
private RepositoryItemReader<Author> reader;
|
||||
|
||||
@AfterEach
|
||||
public void reinitializeReader() {
|
||||
void reinitializeReader() {
|
||||
reader.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadFromFirstPos() throws Exception {
|
||||
void testReadFromFirstPos() throws Exception {
|
||||
reader.open(new ExecutionContext());
|
||||
|
||||
Author author = reader.read();
|
||||
@@ -59,7 +59,7 @@ public class RepositoryItemReaderIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadFromWithinPage() throws Exception {
|
||||
void testReadFromWithinPage() throws Exception {
|
||||
reader.setCurrentItemCount(1);
|
||||
reader.open(new ExecutionContext());
|
||||
|
||||
@@ -73,7 +73,7 @@ public class RepositoryItemReaderIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadFromNewPage() throws Exception {
|
||||
void testReadFromNewPage() throws Exception {
|
||||
reader.setPageSize(2);
|
||||
reader.setCurrentItemCount(2); // 3rd item = 1rst of page 2
|
||||
reader.open(new ExecutionContext());
|
||||
@@ -88,7 +88,7 @@ public class RepositoryItemReaderIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadFromWithinPage_Restart() throws Exception {
|
||||
void testReadFromWithinPage_Restart() throws Exception {
|
||||
final ExecutionContext executionContext = new ExecutionContext();
|
||||
executionContext.putInt(CONTEXT_KEY, 1);
|
||||
reader.open(executionContext);
|
||||
@@ -103,7 +103,7 @@ public class RepositoryItemReaderIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadFromNewPage_Restart() throws Exception {
|
||||
void testReadFromNewPage_Restart() throws Exception {
|
||||
reader.setPageSize(2);
|
||||
final ExecutionContext executionContext = new ExecutionContext();
|
||||
executionContext.putInt(CONTEXT_KEY, 2);
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.jdbc.core.SqlParameter;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class StoredProcedureItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests {
|
||||
class StoredProcedureItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests {
|
||||
|
||||
@Override
|
||||
protected ItemReader<Foo> getItemReader() throws Exception {
|
||||
@@ -44,13 +44,13 @@ public class StoredProcedureItemReaderCommonTests extends AbstractDatabaseItemSt
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initializeContext() throws Exception {
|
||||
protected void initializeContext() {
|
||||
ctx = new ClassPathXmlApplicationContext(
|
||||
"org/springframework/batch/item/database/stored-procedure-context.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestartWithDriverSupportsAbsolute() throws Exception {
|
||||
void testRestartWithDriverSupportsAbsolute() throws Exception {
|
||||
testedAsStream().close();
|
||||
tested = getItemReader();
|
||||
((StoredProcedureItemReader<Foo>) tested).setDriverSupportsAbsolute(true);
|
||||
@@ -82,7 +82,7 @@ public class StoredProcedureItemReaderCommonTests extends AbstractDatabaseItemSt
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadBeforeOpen() throws Exception {
|
||||
void testReadBeforeOpen() throws Exception {
|
||||
testedAsStream().close();
|
||||
tested = getItemReader();
|
||||
assertThrows(ReaderNotOpenException.class, tested::read);
|
||||
|
||||
@@ -38,13 +38,13 @@ import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.support.TransactionCallback;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
public class StoredprocedureItemReaderConfigTests {
|
||||
class StoredprocedureItemReaderConfigTests {
|
||||
|
||||
/*
|
||||
* Should fail if trying to call getConnection() twice
|
||||
*/
|
||||
@Test
|
||||
public void testUsesCurrentTransaction() throws Exception {
|
||||
void testUsesCurrentTransaction() throws Exception {
|
||||
DataSource ds = mock(DataSource.class);
|
||||
DatabaseMetaData dmd = mock(DatabaseMetaData.class);
|
||||
when(dmd.getDatabaseProductName()).thenReturn("Oracle");
|
||||
@@ -79,7 +79,7 @@ public class StoredprocedureItemReaderConfigTests {
|
||||
* Should fail if trying to call getConnection() twice
|
||||
*/
|
||||
@Test
|
||||
public void testUsesItsOwnTransaction() throws Exception {
|
||||
void testUsesItsOwnTransaction() throws Exception {
|
||||
|
||||
DataSource ds = mock(DataSource.class);
|
||||
DatabaseMetaData dmd = mock(DatabaseMetaData.class);
|
||||
@@ -114,7 +114,7 @@ public class StoredprocedureItemReaderConfigTests {
|
||||
* Should fail if trying to call getConnection() twice
|
||||
*/
|
||||
@Test
|
||||
public void testHandlesRefCursorPosition() throws Exception {
|
||||
void testHandlesRefCursorPosition() throws Exception {
|
||||
|
||||
DataSource ds = mock(DataSource.class);
|
||||
DatabaseMetaData dmd = mock(DatabaseMetaData.class);
|
||||
|
||||
@@ -41,32 +41,32 @@ import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class HibernateCursorItemReaderBuilderTests {
|
||||
class HibernateCursorItemReaderBuilderTests {
|
||||
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
void setUp() {
|
||||
this.context = new AnnotationConfigApplicationContext(TestDataSourceConfiguration.class);
|
||||
this.sessionFactory = (SessionFactory) context.getBean("sessionFactory");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
void tearDown() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfiguration() throws Exception {
|
||||
void testConfiguration() throws Exception {
|
||||
HibernateCursorItemReader<Foo> reader = new HibernateCursorItemReaderBuilder<Foo>().name("fooReader")
|
||||
.sessionFactory(this.sessionFactory).fetchSize(2).currentItemCount(2).maxItemCount(4)
|
||||
.queryName("allFoos").useStatelessSession(true).build();
|
||||
@@ -93,7 +93,7 @@ public class HibernateCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationNoSaveState() throws Exception {
|
||||
void testConfigurationNoSaveState() throws Exception {
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("value", 2);
|
||||
|
||||
@@ -120,7 +120,7 @@ public class HibernateCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationQueryProvider() throws Exception {
|
||||
void testConfigurationQueryProvider() throws Exception {
|
||||
|
||||
HibernateNativeQueryProvider<Foo> provider = new HibernateNativeQueryProvider<>();
|
||||
provider.setEntityClass(Foo.class);
|
||||
@@ -148,7 +148,7 @@ public class HibernateCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationNativeQuery() throws Exception {
|
||||
void testConfigurationNativeQuery() throws Exception {
|
||||
HibernateCursorItemReader<Foo> reader = new HibernateCursorItemReaderBuilder<Foo>().name("fooReader")
|
||||
.sessionFactory(this.sessionFactory).nativeQuery("select * from T_FOOS").entityClass(Foo.class).build();
|
||||
|
||||
@@ -170,41 +170,23 @@ public class HibernateCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidation() {
|
||||
try {
|
||||
new HibernateCursorItemReaderBuilder<Foo>().fetchSize(-2).build();
|
||||
fail("fetch size must be >= 0");
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
assertEquals("fetchSize must not be negative", ise.getMessage());
|
||||
}
|
||||
void testValidation() {
|
||||
Exception exception = assertThrows(IllegalStateException.class,
|
||||
() -> new HibernateCursorItemReaderBuilder<Foo>().fetchSize(-2).build());
|
||||
assertEquals("fetchSize must not be negative", exception.getMessage());
|
||||
|
||||
try {
|
||||
new HibernateCursorItemReaderBuilder<Foo>().build();
|
||||
fail("sessionFactory is required");
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
assertEquals("A SessionFactory must be provided", ise.getMessage());
|
||||
}
|
||||
exception = assertThrows(IllegalStateException.class,
|
||||
() -> new HibernateCursorItemReaderBuilder<Foo>().build());
|
||||
assertEquals("A SessionFactory must be provided", exception.getMessage());
|
||||
|
||||
try {
|
||||
new HibernateCursorItemReaderBuilder<Foo>().sessionFactory(this.sessionFactory).saveState(true).build();
|
||||
fail("name is required when saveState is true");
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
assertEquals("A name is required when saveState is set to true.", ise.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
new HibernateCursorItemReaderBuilder<Foo>().sessionFactory(this.sessionFactory).saveState(false).build();
|
||||
fail("A HibernateQueryProvider, queryName, queryString, "
|
||||
+ "or both the nativeQuery and entityClass must be configured");
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
assertEquals("A HibernateQueryProvider, queryName, queryString, "
|
||||
+ "or both the nativeQuery and entityClass must be configured", ise.getMessage());
|
||||
}
|
||||
exception = assertThrows(IllegalStateException.class, () -> new HibernateCursorItemReaderBuilder<Foo>()
|
||||
.sessionFactory(this.sessionFactory).saveState(true).build());
|
||||
assertEquals("A name is required when saveState is set to true.", exception.getMessage());
|
||||
|
||||
exception = assertThrows(IllegalStateException.class, () -> new HibernateCursorItemReaderBuilder<Foo>()
|
||||
.sessionFactory(this.sessionFactory).saveState(false).build());
|
||||
assertEquals("A HibernateQueryProvider, queryName, queryString, "
|
||||
+ "or both the nativeQuery and entityClass must be configured", exception.getMessage());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -22,23 +22,23 @@ import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.junit.jupiter.MockitoSettings;
|
||||
import org.mockito.quality.Strictness;
|
||||
import org.springframework.batch.item.database.HibernateItemWriter;
|
||||
import org.springframework.batch.item.sample.Foo;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class HibernateItemWriterBuilderTests {
|
||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||
class HibernateItemWriterBuilderTests {
|
||||
|
||||
@Mock
|
||||
private SessionFactory sessionFactory;
|
||||
@@ -47,12 +47,12 @@ public class HibernateItemWriterBuilderTests {
|
||||
private Session session;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
lenient().when(this.sessionFactory.getCurrentSession()).thenReturn(this.session);
|
||||
void setUp() {
|
||||
when(this.sessionFactory.getCurrentSession()).thenReturn(this.session);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfiguration() {
|
||||
void testConfiguration() {
|
||||
HibernateItemWriter<Foo> itemWriter = new HibernateItemWriterBuilder<Foo>().sessionFactory(this.sessionFactory)
|
||||
.build();
|
||||
|
||||
@@ -68,7 +68,7 @@ public class HibernateItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationClearSession() {
|
||||
void testConfigurationClearSession() {
|
||||
HibernateItemWriter<Foo> itemWriter = new HibernateItemWriterBuilder<Foo>().sessionFactory(this.sessionFactory)
|
||||
.clearSession(false).build();
|
||||
|
||||
@@ -85,14 +85,10 @@ public class HibernateItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidation() {
|
||||
try {
|
||||
new HibernateItemWriterBuilder<Foo>().build();
|
||||
fail("sessionFactory is required");
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
assertEquals("SessionFactory must be provided", ise.getMessage(), "Incorrect message");
|
||||
}
|
||||
void testValidation() {
|
||||
Exception exception = assertThrows(IllegalStateException.class,
|
||||
() -> new HibernateItemWriterBuilder<Foo>().build());
|
||||
assertEquals("SessionFactory must be provided", exception.getMessage());
|
||||
}
|
||||
|
||||
private List<Foo> getFoos() {
|
||||
|
||||
@@ -43,27 +43,27 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class HibernatePagingItemReaderBuilderTests {
|
||||
class HibernatePagingItemReaderBuilderTests {
|
||||
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
void setUp() {
|
||||
this.context = new AnnotationConfigApplicationContext(
|
||||
HibernatePagingItemReaderBuilderTests.TestDataSourceConfiguration.class);
|
||||
this.sessionFactory = (SessionFactory) context.getBean("sessionFactory");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
void tearDown() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
@@ -71,7 +71,7 @@ public class HibernatePagingItemReaderBuilderTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testConfiguration() throws Exception {
|
||||
void testConfiguration() throws Exception {
|
||||
HibernatePagingItemReader<Foo> reader = new HibernatePagingItemReaderBuilder<Foo>().name("fooReader")
|
||||
.sessionFactory(this.sessionFactory).fetchSize(2).currentItemCount(2).maxItemCount(4).pageSize(5)
|
||||
.queryName("allFoos").useStatelessSession(false).build();
|
||||
@@ -103,7 +103,7 @@ public class HibernatePagingItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationNoSaveState() throws Exception {
|
||||
void testConfigurationNoSaveState() throws Exception {
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("value", 2);
|
||||
|
||||
@@ -130,7 +130,7 @@ public class HibernatePagingItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationQueryProvider() throws Exception {
|
||||
void testConfigurationQueryProvider() throws Exception {
|
||||
|
||||
HibernateNativeQueryProvider<Foo> provider = new HibernateNativeQueryProvider<>();
|
||||
provider.setEntityClass(Foo.class);
|
||||
@@ -158,39 +158,23 @@ public class HibernatePagingItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidation() {
|
||||
try {
|
||||
new HibernatePagingItemReaderBuilder<Foo>().sessionFactory(this.sessionFactory).fetchSize(-2).build();
|
||||
fail("fetch size must be >= 0");
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
assertEquals("fetchSize must not be negative", ise.getMessage());
|
||||
}
|
||||
void testValidation() {
|
||||
Exception exception = assertThrows(IllegalStateException.class,
|
||||
() -> new HibernatePagingItemReaderBuilder<Foo>().sessionFactory(this.sessionFactory).fetchSize(-2)
|
||||
.build());
|
||||
assertEquals("fetchSize must not be negative", exception.getMessage());
|
||||
|
||||
try {
|
||||
new HibernatePagingItemReaderBuilder<Foo>().build();
|
||||
fail("A SessionFactory must be provided");
|
||||
}
|
||||
catch (IllegalArgumentException ise) {
|
||||
assertEquals("A SessionFactory must be provided", ise.getMessage());
|
||||
}
|
||||
exception = assertThrows(IllegalArgumentException.class,
|
||||
() -> new HibernatePagingItemReaderBuilder<Foo>().build());
|
||||
assertEquals("A SessionFactory must be provided", exception.getMessage());
|
||||
|
||||
try {
|
||||
new HibernatePagingItemReaderBuilder<Foo>().sessionFactory(this.sessionFactory).saveState(true).build();
|
||||
fail("name is required when saveState is set to true");
|
||||
}
|
||||
catch (IllegalArgumentException ise) {
|
||||
assertEquals("A name is required when saveState is set to true", ise.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
new HibernatePagingItemReaderBuilder<Foo>().sessionFactory(this.sessionFactory).saveState(false).build();
|
||||
fail("queryString or queryName must be set");
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
assertEquals("queryString or queryName must be set", ise.getMessage());
|
||||
}
|
||||
exception = assertThrows(IllegalArgumentException.class, () -> new HibernatePagingItemReaderBuilder<Foo>()
|
||||
.sessionFactory(this.sessionFactory).saveState(true).build());
|
||||
assertEquals("A name is required when saveState is set to true", exception.getMessage());
|
||||
|
||||
exception = assertThrows(IllegalStateException.class, () -> new HibernatePagingItemReaderBuilder<Foo>()
|
||||
.sessionFactory(this.sessionFactory).saveState(false).build());
|
||||
assertEquals("queryString or queryName must be set", exception.getMessage());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -44,34 +44,33 @@ import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class JdbcBatchItemWriterBuilderTests {
|
||||
class JdbcBatchItemWriterBuilderTests {
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
void setUp() {
|
||||
this.context = new AnnotationConfigApplicationContext(TestDataSourceConfiguration.class);
|
||||
this.dataSource = (DataSource) context.getBean("dataSource");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
void tearDown() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicMap() throws Exception {
|
||||
void testBasicMap() throws Exception {
|
||||
JdbcBatchItemWriter<Map<String, Object>> writer = new JdbcBatchItemWriterBuilder<Map<String, Object>>()
|
||||
.columnMapped().dataSource(this.dataSource)
|
||||
.sql("INSERT INTO FOO (first, second, third) VALUES (:first, :second, :third)").build();
|
||||
@@ -85,7 +84,7 @@ public class JdbcBatchItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomJdbcTemplate() throws Exception {
|
||||
void testCustomJdbcTemplate() throws Exception {
|
||||
NamedParameterJdbcOperations template = new NamedParameterJdbcTemplate(this.dataSource);
|
||||
|
||||
JdbcBatchItemWriter<Map<String, Object>> writer = new JdbcBatchItemWriterBuilder<Map<String, Object>>()
|
||||
@@ -100,11 +99,11 @@ public class JdbcBatchItemWriterBuilderTests {
|
||||
verifyWrite();
|
||||
|
||||
Object usedTemplate = ReflectionTestUtils.getField(writer, "namedParameterJdbcTemplate");
|
||||
assertTrue(template == usedTemplate);
|
||||
assertSame(template, usedTemplate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicPojo() throws Exception {
|
||||
void testBasicPojo() throws Exception {
|
||||
JdbcBatchItemWriter<Foo> writer = new JdbcBatchItemWriterBuilder<Foo>().beanMapped().dataSource(this.dataSource)
|
||||
.sql("INSERT INTO FOO (first, second, third) VALUES (:first, :second, :third)").build();
|
||||
|
||||
@@ -122,7 +121,7 @@ public class JdbcBatchItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssertUpdates() {
|
||||
void testAssertUpdates() {
|
||||
JdbcBatchItemWriter<Foo> writer = new JdbcBatchItemWriterBuilder<Foo>().beanMapped().dataSource(this.dataSource)
|
||||
.sql("UPDATE FOO SET second = :second, third = :third WHERE first = :first").assertUpdates(true)
|
||||
.build();
|
||||
@@ -137,7 +136,7 @@ public class JdbcBatchItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomPreparedStatementSetter() throws Exception {
|
||||
void testCustomPreparedStatementSetter() throws Exception {
|
||||
JdbcBatchItemWriter<Map<String, Object>> writer = new JdbcBatchItemWriterBuilder<Map<String, Object>>()
|
||||
.itemPreparedStatementSetter((item, ps) -> {
|
||||
ps.setInt(0, (int) item.get("first"));
|
||||
@@ -155,7 +154,7 @@ public class JdbcBatchItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomPSqlParameterSourceProvider() throws Exception {
|
||||
void testCustomPSqlParameterSourceProvider() throws Exception {
|
||||
JdbcBatchItemWriter<Map<String, Object>> writer = new JdbcBatchItemWriterBuilder<Map<String, Object>>()
|
||||
.itemSqlParameterSourceProvider(MapSqlParameterSource::new).dataSource(this.dataSource)
|
||||
.sql("INSERT INTO FOO (first, second, third) VALUES (:first, :second, :third)").build();
|
||||
@@ -169,40 +168,22 @@ public class JdbcBatchItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBuildAssertions() {
|
||||
try {
|
||||
new JdbcBatchItemWriterBuilder<Map<String, Object>>()
|
||||
.itemSqlParameterSourceProvider(MapSqlParameterSource::new).build();
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
assertEquals("Either a DataSource or a NamedParameterJdbcTemplate is required", ise.getMessage());
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("Incorrect exception was thrown when missing DataSource and JdbcTemplate: " + e.getMessage());
|
||||
}
|
||||
void testBuildAssertions() {
|
||||
var builder = new JdbcBatchItemWriterBuilder<Map<String, Object>>()
|
||||
.itemSqlParameterSourceProvider(MapSqlParameterSource::new);
|
||||
Exception exception = assertThrows(IllegalStateException.class, builder::build);
|
||||
assertEquals("Either a DataSource or a NamedParameterJdbcTemplate is required", exception.getMessage());
|
||||
|
||||
try {
|
||||
new JdbcBatchItemWriterBuilder<Map<String, Object>>()
|
||||
.itemSqlParameterSourceProvider(MapSqlParameterSource::new).dataSource(this.dataSource).build();
|
||||
}
|
||||
catch (IllegalArgumentException ise) {
|
||||
assertEquals("A SQL statement is required", ise.getMessage());
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("Incorrect exception was thrown when testing missing SQL: " + e);
|
||||
}
|
||||
builder = new JdbcBatchItemWriterBuilder<Map<String, Object>>()
|
||||
.itemSqlParameterSourceProvider(MapSqlParameterSource::new).dataSource(this.dataSource);
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("A SQL statement is required", exception.getMessage());
|
||||
|
||||
try {
|
||||
new JdbcBatchItemWriterBuilder<Map<String, Object>>().dataSource(this.dataSource)
|
||||
.sql("INSERT INTO FOO VALUES (?, ?, ?)").columnMapped().beanMapped().build();
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
assertEquals("Either an item can be mapped via db column or via bean spec, can't be both",
|
||||
ise.getMessage());
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail("Incorrect exception was thrown both mapping types are used" + e.getMessage());
|
||||
}
|
||||
builder = new JdbcBatchItemWriterBuilder<Map<String, Object>>().dataSource(this.dataSource)
|
||||
.sql("INSERT INTO FOO VALUES (?, ?, ?)").columnMapped().beanMapped();
|
||||
exception = assertThrows(IllegalStateException.class, builder::build);
|
||||
assertEquals("Either an item can be mapped via db column or via bean spec, can't be both",
|
||||
exception.getMessage());
|
||||
}
|
||||
|
||||
private void verifyWrite() {
|
||||
|
||||
@@ -41,8 +41,8 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
@@ -50,27 +50,27 @@ import static org.junit.jupiter.api.Assertions.fail;
|
||||
* @author Ankur Trapasiya
|
||||
* @author Parikshit Dutta
|
||||
*/
|
||||
public class JdbcCursorItemReaderBuilderTests {
|
||||
class JdbcCursorItemReaderBuilderTests {
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
void setUp() {
|
||||
this.context = new AnnotationConfigApplicationContext(TestDataSourceConfiguration.class);
|
||||
this.dataSource = (DataSource) context.getBean("dataSource");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
void tearDown() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleScenario() throws Exception {
|
||||
void testSimpleScenario() throws Exception {
|
||||
JdbcCursorItemReader<Foo> reader = new JdbcCursorItemReaderBuilder<Foo>().dataSource(this.dataSource)
|
||||
.name("fooReader").sql("SELECT * FROM FOO ORDER BY FIRST").rowMapper((rs, rowNum) -> {
|
||||
Foo foo = new Foo();
|
||||
@@ -93,7 +93,7 @@ public class JdbcCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxRows() throws Exception {
|
||||
void testMaxRows() throws Exception {
|
||||
JdbcCursorItemReader<Foo> reader = new JdbcCursorItemReaderBuilder<Foo>().dataSource(this.dataSource)
|
||||
.name("fooReader").sql("SELECT * FROM FOO ORDER BY FIRST").maxRows(2).saveState(false)
|
||||
.rowMapper((rs, rowNum) -> {
|
||||
@@ -118,7 +118,7 @@ public class JdbcCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryArgumentsList() throws Exception {
|
||||
void testQueryArgumentsList() throws Exception {
|
||||
JdbcCursorItemReader<Foo> reader = new JdbcCursorItemReaderBuilder<Foo>().dataSource(this.dataSource)
|
||||
.name("fooReader").sql("SELECT * FROM FOO WHERE FIRST > ? ORDER BY FIRST")
|
||||
.queryArguments(Arrays.asList(3)).rowMapper((rs, rowNum) -> {
|
||||
@@ -141,7 +141,7 @@ public class JdbcCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryArgumentsArray() throws Exception {
|
||||
void testQueryArgumentsArray() throws Exception {
|
||||
JdbcCursorItemReader<Foo> reader = new JdbcCursorItemReaderBuilder<Foo>().dataSource(this.dataSource)
|
||||
.name("fooReader").sql("SELECT * FROM FOO WHERE FIRST > ? ORDER BY FIRST").queryArguments(3)
|
||||
.rowMapper((rs, rowNum) -> {
|
||||
@@ -164,7 +164,7 @@ public class JdbcCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryArgumentsTypedArray() throws Exception {
|
||||
void testQueryArgumentsTypedArray() throws Exception {
|
||||
JdbcCursorItemReader<Foo> reader = new JdbcCursorItemReaderBuilder<Foo>().dataSource(this.dataSource)
|
||||
.name("fooReader").sql("SELECT * FROM FOO WHERE FIRST > ? ORDER BY FIRST")
|
||||
.queryArguments(new Integer[] { 3 }, new int[] { Types.BIGINT }).rowMapper((rs, rowNum) -> {
|
||||
@@ -187,7 +187,7 @@ public class JdbcCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPreparedStatementSetter() throws Exception {
|
||||
void testPreparedStatementSetter() throws Exception {
|
||||
JdbcCursorItemReader<Foo> reader = new JdbcCursorItemReaderBuilder<Foo>().dataSource(this.dataSource)
|
||||
.name("fooReader").sql("SELECT * FROM FOO WHERE FIRST > ? ORDER BY FIRST")
|
||||
.preparedStatementSetter(new PreparedStatementSetter() {
|
||||
@@ -215,7 +215,7 @@ public class JdbcCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxItemCount() throws Exception {
|
||||
void testMaxItemCount() throws Exception {
|
||||
JdbcCursorItemReader<Foo> reader = new JdbcCursorItemReaderBuilder<Foo>().dataSource(this.dataSource)
|
||||
.name("fooReader").sql("SELECT * FROM FOO ORDER BY FIRST").maxItemCount(2).rowMapper((rs, rowNum) -> {
|
||||
Foo foo = new Foo();
|
||||
@@ -237,7 +237,7 @@ public class JdbcCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrentItemCount() throws Exception {
|
||||
void testCurrentItemCount() throws Exception {
|
||||
JdbcCursorItemReader<Foo> reader = new JdbcCursorItemReaderBuilder<Foo>().dataSource(this.dataSource)
|
||||
.name("fooReader").sql("SELECT * FROM FOO ORDER BY FIRST").currentItemCount(1)
|
||||
.rowMapper((rs, rowNum) -> {
|
||||
@@ -260,7 +260,7 @@ public class JdbcCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOtherProperties() {
|
||||
void testOtherProperties() {
|
||||
JdbcCursorItemReader<Foo> reader = new JdbcCursorItemReaderBuilder<Foo>().dataSource(this.dataSource)
|
||||
.name("fooReader").sql("SELECT * FROM FOO ORDER BY FIRST").fetchSize(1).queryTimeout(2)
|
||||
.ignoreWarnings(true).driverSupportsAbsolute(true).useSharedExtendedConnection(true)
|
||||
@@ -274,53 +274,29 @@ public class JdbcCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVerifyCursorPositionDefaultToTrue() {
|
||||
void testVerifyCursorPositionDefaultToTrue() {
|
||||
JdbcCursorItemReader<Foo> reader = new JdbcCursorItemReaderBuilder<Foo>().dataSource(this.dataSource)
|
||||
.name("fooReader").sql("SELECT * FROM FOO ORDER BY FIRST").beanRowMapper(Foo.class).build();
|
||||
assertTrue((boolean) ReflectionTestUtils.getField(reader, "verifyCursorPosition"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidation() {
|
||||
try {
|
||||
new JdbcCursorItemReaderBuilder<Foo>().saveState(true).build();
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("A name is required when saveState is set to true", iae.getMessage());
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail();
|
||||
}
|
||||
void testValidation() {
|
||||
var builder = new JdbcCursorItemReaderBuilder<Foo>().saveState(true);
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("A name is required when saveState is set to true", exception.getMessage());
|
||||
|
||||
try {
|
||||
new JdbcCursorItemReaderBuilder<Foo>().saveState(false).build();
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("A query is required", iae.getMessage());
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail();
|
||||
}
|
||||
builder = new JdbcCursorItemReaderBuilder<Foo>().saveState(false);
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("A query is required", exception.getMessage());
|
||||
|
||||
try {
|
||||
new JdbcCursorItemReaderBuilder<Foo>().saveState(false).sql("select 1").build();
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("A datasource is required", iae.getMessage());
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail();
|
||||
}
|
||||
builder = new JdbcCursorItemReaderBuilder<Foo>().saveState(false).sql("select 1");
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("A datasource is required", exception.getMessage());
|
||||
|
||||
try {
|
||||
new JdbcCursorItemReaderBuilder<Foo>().saveState(false).sql("select 1").dataSource(this.dataSource).build();
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("A rowmapper is required", iae.getMessage());
|
||||
}
|
||||
catch (Exception e) {
|
||||
fail();
|
||||
}
|
||||
builder = new JdbcCursorItemReaderBuilder<Foo>().saveState(false).sql("select 1").dataSource(this.dataSource);
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("A rowmapper is required", exception.getMessage());
|
||||
}
|
||||
|
||||
private void validateFoo(Foo item, int first, String second, String third) {
|
||||
|
||||
@@ -41,34 +41,33 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
* @author Drummond Dawson
|
||||
*/
|
||||
public class JdbcPagingItemReaderBuilderTests {
|
||||
class JdbcPagingItemReaderBuilderTests {
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
void setUp() {
|
||||
this.context = new AnnotationConfigApplicationContext(TestDataSourceConfiguration.class);
|
||||
this.dataSource = (DataSource) context.getBean("dataSource");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
void tearDown() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicConfigurationQueryProvider() throws Exception {
|
||||
void testBasicConfigurationQueryProvider() throws Exception {
|
||||
Map<String, Order> sortKeys = new HashMap<>(1);
|
||||
sortKeys.put("ID", Order.DESCENDING);
|
||||
|
||||
@@ -95,13 +94,13 @@ public class JdbcPagingItemReaderBuilderTests {
|
||||
assertEquals(10, item1.getFirst());
|
||||
assertEquals("11", item1.getSecond());
|
||||
assertEquals("12", item1.getThird());
|
||||
assertTrue((int) ReflectionTestUtils.getField(reader, "fetchSize") == 2);
|
||||
assertEquals(2, (int) ReflectionTestUtils.getField(reader, "fetchSize"));
|
||||
|
||||
assertEquals(2, executionContext.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicConfiguration() throws Exception {
|
||||
void testBasicConfiguration() throws Exception {
|
||||
Map<String, Order> sortKeys = new HashMap<>(1);
|
||||
sortKeys.put("ID", Order.DESCENDING);
|
||||
|
||||
@@ -124,7 +123,7 @@ public class JdbcPagingItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPageSize() throws Exception {
|
||||
void testPageSize() throws Exception {
|
||||
Map<String, Order> sortKeys = new HashMap<>(1);
|
||||
sortKeys.put("ID", Order.DESCENDING);
|
||||
|
||||
@@ -153,7 +152,7 @@ public class JdbcPagingItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveState() throws Exception {
|
||||
void testSaveState() throws Exception {
|
||||
Map<String, Order> sortKeys = new HashMap<>(1);
|
||||
sortKeys.put("ID", Order.DESCENDING);
|
||||
|
||||
@@ -187,7 +186,7 @@ public class JdbcPagingItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameters() throws Exception {
|
||||
void testParameters() throws Exception {
|
||||
Map<String, Order> sortKeys = new HashMap<>(1);
|
||||
sortKeys.put("ID", Order.DESCENDING);
|
||||
|
||||
@@ -215,7 +214,7 @@ public class JdbcPagingItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanRowMapper() throws Exception {
|
||||
void testBeanRowMapper() throws Exception {
|
||||
Map<String, Order> sortKeys = new HashMap<>(1);
|
||||
sortKeys.put("ID", Order.DESCENDING);
|
||||
|
||||
@@ -236,65 +235,36 @@ public class JdbcPagingItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidation() {
|
||||
void testValidation() {
|
||||
var builder = new JdbcPagingItemReaderBuilder<Foo>();
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("dataSource is required", exception.getMessage());
|
||||
|
||||
try {
|
||||
new JdbcPagingItemReaderBuilder<Foo>().build();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("dataSource is required", iae.getMessage());
|
||||
}
|
||||
builder = new JdbcPagingItemReaderBuilder<Foo>().pageSize(-2);
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("pageSize must be greater than zero", exception.getMessage());
|
||||
|
||||
try {
|
||||
new JdbcPagingItemReaderBuilder<Foo>().pageSize(-2).build();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("pageSize must be greater than zero", iae.getMessage());
|
||||
}
|
||||
builder = new JdbcPagingItemReaderBuilder<Foo>().pageSize(2);
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("dataSource is required", exception.getMessage());
|
||||
|
||||
try {
|
||||
new JdbcPagingItemReaderBuilder<Foo>().pageSize(2).build();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException ise) {
|
||||
assertEquals("dataSource is required", ise.getMessage());
|
||||
}
|
||||
builder = new JdbcPagingItemReaderBuilder<Foo>().pageSize(2).dataSource(this.dataSource);
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("A name is required when saveState is set to true", exception.getMessage());
|
||||
|
||||
try {
|
||||
new JdbcPagingItemReaderBuilder<Foo>().pageSize(2).dataSource(this.dataSource).build();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException ise) {
|
||||
assertEquals("A name is required when saveState is set to true", ise.getMessage());
|
||||
}
|
||||
builder = new JdbcPagingItemReaderBuilder<Foo>().saveState(false).pageSize(2).dataSource(this.dataSource);
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("selectClause is required when not providing a PagingQueryProvider", exception.getMessage());
|
||||
|
||||
try {
|
||||
new JdbcPagingItemReaderBuilder<Foo>().saveState(false).pageSize(2).dataSource(this.dataSource).build();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException ise) {
|
||||
assertEquals("selectClause is required when not providing a PagingQueryProvider", ise.getMessage());
|
||||
}
|
||||
builder = new JdbcPagingItemReaderBuilder<Foo>().name("fooReader").pageSize(2).dataSource(this.dataSource)
|
||||
.selectClause("SELECT *");
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("fromClause is required when not providing a PagingQueryProvider", exception.getMessage());
|
||||
|
||||
try {
|
||||
new JdbcPagingItemReaderBuilder<Foo>().name("fooReader").pageSize(2).dataSource(this.dataSource)
|
||||
.selectClause("SELECT *").build();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException ise) {
|
||||
assertEquals("fromClause is required when not providing a PagingQueryProvider", ise.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
new JdbcPagingItemReaderBuilder<Foo>().saveState(false).pageSize(2).dataSource(this.dataSource)
|
||||
.selectClause("SELECT *").fromClause("FOO").build();
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException ise) {
|
||||
assertEquals("sortKeys are required when not providing a PagingQueryProvider", ise.getMessage());
|
||||
}
|
||||
builder = new JdbcPagingItemReaderBuilder<Foo>().saveState(false).pageSize(2).dataSource(this.dataSource)
|
||||
.selectClause("SELECT *").fromClause("FOO");
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("sortKeys are required when not providing a PagingQueryProvider", exception.getMessage());
|
||||
}
|
||||
|
||||
public static class Foo {
|
||||
|
||||
@@ -46,33 +46,33 @@ import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class JpaCursorItemReaderBuilderTests {
|
||||
class JpaCursorItemReaderBuilderTests {
|
||||
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
void setUp() {
|
||||
this.context = new AnnotationConfigApplicationContext(
|
||||
JpaCursorItemReaderBuilderTests.TestDataSourceConfiguration.class);
|
||||
this.entityManagerFactory = (EntityManagerFactory) context.getBean("entityManagerFactory");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
void tearDown() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfiguration() throws Exception {
|
||||
void testConfiguration() throws Exception {
|
||||
JpaCursorItemReader<Foo> reader = new JpaCursorItemReaderBuilder<Foo>().name("fooReader")
|
||||
.entityManagerFactory(this.entityManagerFactory).currentItemCount(2).maxItemCount(4)
|
||||
.queryString("select f from Foo f ").build();
|
||||
@@ -99,7 +99,7 @@ public class JpaCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationNoSaveState() throws Exception {
|
||||
void testConfigurationNoSaveState() throws Exception {
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("value", 2);
|
||||
|
||||
@@ -126,7 +126,7 @@ public class JpaCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationNamedQueryProvider() throws Exception {
|
||||
void testConfigurationNamedQueryProvider() throws Exception {
|
||||
JpaNamedQueryProvider<Foo> namedQueryProvider = new JpaNamedQueryProvider<>();
|
||||
namedQueryProvider.setNamedQuery("allFoos");
|
||||
namedQueryProvider.setEntityClass(Foo.class);
|
||||
@@ -157,7 +157,7 @@ public class JpaCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationNativeQueryProvider() throws Exception {
|
||||
void testConfigurationNativeQueryProvider() throws Exception {
|
||||
|
||||
JpaNativeQueryProvider<Foo> provider = new JpaNativeQueryProvider<>();
|
||||
provider.setEntityClass(Foo.class);
|
||||
@@ -185,32 +185,19 @@ public class JpaCursorItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidation() {
|
||||
try {
|
||||
new JpaCursorItemReaderBuilder<Foo>().build();
|
||||
fail("An EntityManagerFactory is required");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("An EntityManagerFactory is required", iae.getMessage());
|
||||
}
|
||||
void testValidation() {
|
||||
var builder = new JpaCursorItemReaderBuilder<Foo>();
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("An EntityManagerFactory is required", exception.getMessage());
|
||||
|
||||
try {
|
||||
new JpaCursorItemReaderBuilder<Foo>().entityManagerFactory(this.entityManagerFactory).saveState(true)
|
||||
.build();
|
||||
fail("A name is required when saveState is set to true");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("A name is required when saveState is set to true", iae.getMessage());
|
||||
}
|
||||
builder = new JpaCursorItemReaderBuilder<Foo>().entityManagerFactory(this.entityManagerFactory).saveState(true);
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("A name is required when saveState is set to true", exception.getMessage());
|
||||
|
||||
try {
|
||||
new JpaCursorItemReaderBuilder<Foo>().entityManagerFactory(this.entityManagerFactory).saveState(false)
|
||||
.build();
|
||||
fail("Query string is required when queryProvider is null");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("Query string is required when queryProvider is null", iae.getMessage());
|
||||
}
|
||||
builder = new JpaCursorItemReaderBuilder<Foo>().entityManagerFactory(this.entityManagerFactory)
|
||||
.saveState(false);
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("Query string is required when queryProvider is null", exception.getMessage());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -31,14 +31,14 @@ import org.springframework.orm.jpa.EntityManagerHolder;
|
||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class JpaItemWriterBuilderTests {
|
||||
class JpaItemWriterBuilderTests {
|
||||
|
||||
@Mock
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
@@ -47,18 +47,18 @@ public class JpaItemWriterBuilderTests {
|
||||
private EntityManager entityManager;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
void setUp() {
|
||||
TransactionSynchronizationManager.bindResource(this.entityManagerFactory,
|
||||
new EntityManagerHolder(this.entityManager));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
void tearDown() {
|
||||
TransactionSynchronizationManager.unbindResource(this.entityManagerFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfiguration() throws Exception {
|
||||
void testConfiguration() throws Exception {
|
||||
JpaItemWriter<String> itemWriter = new JpaItemWriterBuilder<String>()
|
||||
.entityManagerFactory(this.entityManagerFactory).build();
|
||||
|
||||
@@ -73,18 +73,14 @@ public class JpaItemWriterBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidation() {
|
||||
try {
|
||||
new JpaItemWriterBuilder<String>().build();
|
||||
fail("Should fail if no EntityManagerFactory is provided");
|
||||
}
|
||||
catch (IllegalStateException ise) {
|
||||
assertEquals("EntityManagerFactory must be provided", ise.getMessage(), "Incorrect message");
|
||||
}
|
||||
void testValidation() {
|
||||
Exception exception = assertThrows(IllegalStateException.class,
|
||||
() -> new JpaItemWriterBuilder<String>().build());
|
||||
assertEquals("EntityManagerFactory must be provided", exception.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersist() throws Exception {
|
||||
void testPersist() throws Exception {
|
||||
JpaItemWriter<String> itemWriter = new JpaItemWriterBuilder<String>()
|
||||
.entityManagerFactory(this.entityManagerFactory).usePersist(true).build();
|
||||
|
||||
|
||||
@@ -47,35 +47,35 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
* @author Parikshit Dutta
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class JpaPagingItemReaderBuilderTests {
|
||||
class JpaPagingItemReaderBuilderTests {
|
||||
|
||||
private EntityManagerFactory entityManagerFactory;
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
void setUp() {
|
||||
this.context = new AnnotationConfigApplicationContext(
|
||||
JpaPagingItemReaderBuilderTests.TestDataSourceConfiguration.class);
|
||||
this.entityManagerFactory = (EntityManagerFactory) context.getBean("entityManagerFactory");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
void tearDown() {
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfiguration() throws Exception {
|
||||
void testConfiguration() throws Exception {
|
||||
JpaPagingItemReader<Foo> reader = new JpaPagingItemReaderBuilder<Foo>().name("fooReader")
|
||||
.entityManagerFactory(this.entityManagerFactory).currentItemCount(2).maxItemCount(4).pageSize(5)
|
||||
.transacted(false).queryString("select f from Foo f ").build();
|
||||
@@ -104,7 +104,7 @@ public class JpaPagingItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationNoSaveState() throws Exception {
|
||||
void testConfigurationNoSaveState() throws Exception {
|
||||
Map<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("value", 2);
|
||||
|
||||
@@ -131,7 +131,7 @@ public class JpaPagingItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationNamedQueryProvider() throws Exception {
|
||||
void testConfigurationNamedQueryProvider() throws Exception {
|
||||
JpaNamedQueryProvider<Foo> namedQueryProvider = new JpaNamedQueryProvider<>();
|
||||
namedQueryProvider.setNamedQuery("allFoos");
|
||||
namedQueryProvider.setEntityClass(Foo.class);
|
||||
@@ -162,7 +162,7 @@ public class JpaPagingItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfigurationNativeQueryProvider() throws Exception {
|
||||
void testConfigurationNativeQueryProvider() throws Exception {
|
||||
|
||||
JpaNativeQueryProvider<Foo> provider = new JpaNativeQueryProvider<>();
|
||||
provider.setEntityClass(Foo.class);
|
||||
@@ -190,40 +190,24 @@ public class JpaPagingItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidation() {
|
||||
try {
|
||||
new JpaPagingItemReaderBuilder<Foo>().entityManagerFactory(this.entityManagerFactory).pageSize(-2).build();
|
||||
fail("pageSize must be >= 0");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("pageSize must be greater than zero", iae.getMessage());
|
||||
}
|
||||
void testValidation() {
|
||||
var builder = new JpaPagingItemReaderBuilder<Foo>().entityManagerFactory(this.entityManagerFactory)
|
||||
.pageSize(-2);
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("pageSize must be greater than zero", exception.getMessage());
|
||||
|
||||
try {
|
||||
new JpaPagingItemReaderBuilder<Foo>().build();
|
||||
fail("An EntityManagerFactory is required");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("An EntityManagerFactory is required", iae.getMessage());
|
||||
}
|
||||
builder = new JpaPagingItemReaderBuilder<Foo>();
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("An EntityManagerFactory is required", exception.getMessage());
|
||||
|
||||
try {
|
||||
new JpaPagingItemReaderBuilder<Foo>().entityManagerFactory(this.entityManagerFactory).saveState(true)
|
||||
.build();
|
||||
fail("A name is required when saveState is set to true");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("A name is required when saveState is set to true", iae.getMessage());
|
||||
}
|
||||
builder = new JpaPagingItemReaderBuilder<Foo>().entityManagerFactory(this.entityManagerFactory).saveState(true);
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("A name is required when saveState is set to true", exception.getMessage());
|
||||
|
||||
try {
|
||||
new JpaPagingItemReaderBuilder<Foo>().entityManagerFactory(this.entityManagerFactory).saveState(false)
|
||||
.build();
|
||||
fail("Query string is required when queryProvider is null");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("Query string is required when queryProvider is null", iae.getMessage());
|
||||
}
|
||||
builder = new JpaPagingItemReaderBuilder<Foo>().entityManagerFactory(this.entityManagerFactory)
|
||||
.saveState(false);
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("Query string is required when queryProvider is null", exception.getMessage());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -41,32 +41,32 @@ import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* @author Michael Minella
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class StoredProcedureItemReaderBuilderTests {
|
||||
class StoredProcedureItemReaderBuilderTests {
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
void setUp() {
|
||||
this.context = new AnnotationConfigApplicationContext(TestDataSourceConfiguration.class);
|
||||
this.dataSource = (DataSource) this.context.getBean("dataSource");
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void tearDown() {
|
||||
void tearDown() {
|
||||
this.context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSunnyScenario() throws Exception {
|
||||
void testSunnyScenario() throws Exception {
|
||||
StoredProcedureItemReader<Foo> reader = new StoredProcedureItemReaderBuilder<Foo>().name("foo_reader")
|
||||
.dataSource(this.dataSource).procedureName("read_foos").rowMapper(new FooRowMapper())
|
||||
.verifyCursorPosition(false).build();
|
||||
@@ -82,7 +82,7 @@ public class StoredProcedureItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfiguration() {
|
||||
void testConfiguration() {
|
||||
ArgumentPreparedStatementSetter preparedStatementSetter = new ArgumentPreparedStatementSetter(null);
|
||||
|
||||
SqlParameter[] parameters = new SqlParameter[0];
|
||||
@@ -109,7 +109,7 @@ public class StoredProcedureItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSaveState() throws Exception {
|
||||
void testNoSaveState() throws Exception {
|
||||
StoredProcedureItemReader<Foo> reader = new StoredProcedureItemReaderBuilder<Foo>().dataSource(this.dataSource)
|
||||
.procedureName("read_foos").rowMapper(new FooRowMapper()).verifyCursorPosition(false).saveState(false)
|
||||
.build();
|
||||
@@ -128,43 +128,23 @@ public class StoredProcedureItemReaderBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidation() {
|
||||
try {
|
||||
new StoredProcedureItemReaderBuilder<Foo>().build();
|
||||
void testValidation() {
|
||||
var builder = new StoredProcedureItemReaderBuilder<Foo>();
|
||||
Exception exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("A name is required when saveSate is set to true", exception.getMessage());
|
||||
|
||||
fail("Exception was not thrown for missing the name");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("A name is required when saveSate is set to true", iae.getMessage());
|
||||
}
|
||||
builder = new StoredProcedureItemReaderBuilder<Foo>().saveState(false);
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("The name of the stored procedure must be provided", exception.getMessage());
|
||||
|
||||
try {
|
||||
new StoredProcedureItemReaderBuilder<Foo>().saveState(false).build();
|
||||
builder = new StoredProcedureItemReaderBuilder<Foo>().saveState(false).procedureName("read_foos");
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("A datasource is required", exception.getMessage());
|
||||
|
||||
fail("Exception was not thrown for missing the stored procedure name");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("The name of the stored procedure must be provided", iae.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
new StoredProcedureItemReaderBuilder<Foo>().saveState(false).procedureName("read_foos").build();
|
||||
|
||||
fail("Exception was not thrown for missing the DataSource");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("A datasource is required", iae.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
new StoredProcedureItemReaderBuilder<Foo>().saveState(false).procedureName("read_foos")
|
||||
.dataSource(this.dataSource).build();
|
||||
|
||||
fail("Exception was not thrown for missing the RowMapper");
|
||||
}
|
||||
catch (IllegalArgumentException iae) {
|
||||
assertEquals("A rowmapper is required", iae.getMessage());
|
||||
}
|
||||
builder = new StoredProcedureItemReaderBuilder<Foo>().saveState(false).procedureName("read_foos")
|
||||
.dataSource(this.dataSource);
|
||||
exception = assertThrows(IllegalArgumentException.class, builder::build);
|
||||
assertEquals("A rowmapper is required", exception.getMessage());
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -36,10 +36,10 @@ import org.springframework.util.Assert;
|
||||
* @author Parikshit Dutta
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class JpaNamedQueryProviderTests {
|
||||
class JpaNamedQueryProviderTests {
|
||||
|
||||
@Test
|
||||
public void testJpaNamedQueryProviderNamedQueryIsProvided() {
|
||||
void testJpaNamedQueryProviderNamedQueryIsProvided() {
|
||||
JpaNamedQueryProvider<Foo> jpaNamedQueryProvider = new JpaNamedQueryProvider<>();
|
||||
jpaNamedQueryProvider.setEntityClass(Foo.class);
|
||||
|
||||
@@ -52,7 +52,7 @@ public class JpaNamedQueryProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJpaNamedQueryProviderEntityClassIsProvided() {
|
||||
void testJpaNamedQueryProviderEntityClassIsProvided() {
|
||||
JpaNamedQueryProvider<Foo> jpaNamedQueryProvider = new JpaNamedQueryProvider<>();
|
||||
jpaNamedQueryProvider.setNamedQuery("allFoos");
|
||||
|
||||
@@ -65,7 +65,8 @@ public class JpaNamedQueryProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNamedQueryCreation() throws Exception {
|
||||
@SuppressWarnings("unchecked")
|
||||
void testNamedQueryCreation() throws Exception {
|
||||
// given
|
||||
String namedQuery = "allFoos";
|
||||
TypedQuery<Foo> query = mock(TypedQuery.class);
|
||||
|
||||
@@ -30,14 +30,14 @@ import org.springframework.batch.item.database.Order;
|
||||
* @author Michael Minella
|
||||
* @author Benjamin Hetz
|
||||
*/
|
||||
public abstract class AbstractSqlPagingQueryProviderTests {
|
||||
abstract class AbstractSqlPagingQueryProviderTests {
|
||||
|
||||
protected AbstractSqlPagingQueryProvider pagingQueryProvider;
|
||||
|
||||
protected int pageSize;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
void setUp() {
|
||||
if (pagingQueryProvider == null) {
|
||||
throw new IllegalArgumentException("pagingQueryProvider can't be null");
|
||||
}
|
||||
@@ -53,20 +53,20 @@ public abstract class AbstractSqlPagingQueryProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryContainsSortKey() {
|
||||
void testQueryContainsSortKey() {
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize).toLowerCase();
|
||||
assertTrue(s.contains("id asc"), "Wrong query: " + s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryContainsSortKeyDesc() {
|
||||
void testQueryContainsSortKeyDesc() {
|
||||
pagingQueryProvider.getSortKeys().put("id", Order.DESCENDING);
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize).toLowerCase();
|
||||
assertTrue(s.contains("id desc"), "Wrong query: " + s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateFirstPageQueryWithMultipleSortKeys() {
|
||||
void testGenerateFirstPageQueryWithMultipleSortKeys() {
|
||||
Map<String, Order> sortKeys = new LinkedHashMap<>();
|
||||
sortKeys.put("name", Order.ASCENDING);
|
||||
sortKeys.put("id", Order.DESCENDING);
|
||||
@@ -76,7 +76,7 @@ public abstract class AbstractSqlPagingQueryProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateRemainingPagesQueryWithMultipleSortKeys() {
|
||||
void testGenerateRemainingPagesQueryWithMultipleSortKeys() {
|
||||
Map<String, Order> sortKeys = new LinkedHashMap<>();
|
||||
sortKeys.put("name", Order.ASCENDING);
|
||||
sortKeys.put("id", Order.DESCENDING);
|
||||
@@ -86,7 +86,7 @@ public abstract class AbstractSqlPagingQueryProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateJumpToItemQueryWithMultipleSortKeys() {
|
||||
void testGenerateJumpToItemQueryWithMultipleSortKeys() {
|
||||
Map<String, Order> sortKeys = new LinkedHashMap<>();
|
||||
sortKeys.put("name", Order.ASCENDING);
|
||||
sortKeys.put("id", Order.DESCENDING);
|
||||
@@ -96,7 +96,7 @@ public abstract class AbstractSqlPagingQueryProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
void testGenerateJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
Map<String, Order> sortKeys = new LinkedHashMap<>();
|
||||
sortKeys.put("name", Order.ASCENDING);
|
||||
sortKeys.put("id", Order.DESCENDING);
|
||||
@@ -106,7 +106,7 @@ public abstract class AbstractSqlPagingQueryProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveKeyWordsFollowedBySpaceChar() {
|
||||
void testRemoveKeyWordsFollowedBySpaceChar() {
|
||||
String selectClause = "SELECT id, 'yes', false";
|
||||
String fromClause = "FROM test.verification_table";
|
||||
String whereClause = "WHERE TRUE";
|
||||
@@ -120,7 +120,7 @@ public abstract class AbstractSqlPagingQueryProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveKeyWordsFollowedByTabChar() {
|
||||
void testRemoveKeyWordsFollowedByTabChar() {
|
||||
String selectClause = "SELECT\tid, 'yes', false";
|
||||
String fromClause = "FROM\ttest.verification_table";
|
||||
String whereClause = "WHERE\tTRUE";
|
||||
@@ -134,7 +134,7 @@ public abstract class AbstractSqlPagingQueryProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveKeyWordsFollowedByNewLineChar() {
|
||||
void testRemoveKeyWordsFollowedByNewLineChar() {
|
||||
String selectClause = "SELECT\nid, 'yes', false";
|
||||
String fromClause = "FROM\ntest.verification_table";
|
||||
String whereClause = "WHERE\nTRUE";
|
||||
@@ -148,35 +148,35 @@ public abstract class AbstractSqlPagingQueryProviderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public abstract void testGenerateFirstPageQuery();
|
||||
abstract void testGenerateFirstPageQuery();
|
||||
|
||||
@Test
|
||||
public abstract void testGenerateRemainingPagesQuery();
|
||||
abstract void testGenerateRemainingPagesQuery();
|
||||
|
||||
@Test
|
||||
public abstract void testGenerateJumpToItemQuery();
|
||||
abstract void testGenerateJumpToItemQuery();
|
||||
|
||||
@Test
|
||||
public abstract void testGenerateJumpToItemQueryForFirstPage();
|
||||
abstract void testGenerateJumpToItemQueryForFirstPage();
|
||||
|
||||
@Test
|
||||
public abstract void testGenerateFirstPageQueryWithGroupBy();
|
||||
abstract void testGenerateFirstPageQueryWithGroupBy();
|
||||
|
||||
@Test
|
||||
public abstract void testGenerateRemainingPagesQueryWithGroupBy();
|
||||
abstract void testGenerateRemainingPagesQueryWithGroupBy();
|
||||
|
||||
@Test
|
||||
public abstract void testGenerateJumpToItemQueryWithGroupBy();
|
||||
abstract void testGenerateJumpToItemQueryWithGroupBy();
|
||||
|
||||
@Test
|
||||
public abstract void testGenerateJumpToItemQueryForFirstPageWithGroupBy();
|
||||
abstract void testGenerateJumpToItemQueryForFirstPageWithGroupBy();
|
||||
|
||||
public abstract String getFirstPageSqlWithMultipleSortKeys();
|
||||
abstract String getFirstPageSqlWithMultipleSortKeys();
|
||||
|
||||
public abstract String getRemainingSqlWithMultipleSortKeys();
|
||||
abstract String getRemainingSqlWithMultipleSortKeys();
|
||||
|
||||
public abstract String getJumpToItemQueryWithMultipleSortKeys();
|
||||
abstract String getJumpToItemQueryWithMultipleSortKeys();
|
||||
|
||||
public abstract String getJumpToItemQueryForFirstPageWithMultipleSortKeys();
|
||||
abstract String getJumpToItemQueryForFirstPageWithMultipleSortKeys();
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test;
|
||||
* @author Lucas Ward
|
||||
* @author Will Schipp
|
||||
*/
|
||||
public class ColumnMapExecutionContextRowMapperTests {
|
||||
class ColumnMapExecutionContextRowMapperTests {
|
||||
|
||||
private ColumnMapItemPreparedStatementSetter mapper;
|
||||
|
||||
@@ -37,7 +37,7 @@ public class ColumnMapExecutionContextRowMapperTests {
|
||||
private PreparedStatement ps;
|
||||
|
||||
@BeforeEach
|
||||
protected void setUp() throws Exception {
|
||||
void setUp() {
|
||||
ps = mock(PreparedStatement.class);
|
||||
mapper = new ColumnMapItemPreparedStatementSetter();
|
||||
|
||||
@@ -47,13 +47,13 @@ public class ColumnMapExecutionContextRowMapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateExecutionContextFromEmptyKeys() throws Exception {
|
||||
void testCreateExecutionContextFromEmptyKeys() throws Exception {
|
||||
|
||||
mapper.setValues(new HashMap<>(), ps);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateSetter() throws Exception {
|
||||
void testCreateSetter() throws Exception {
|
||||
|
||||
ps.setObject(1, Integer.valueOf(1));
|
||||
ps.setObject(2, Integer.valueOf(2));
|
||||
|
||||
@@ -23,15 +23,15 @@ import org.junit.jupiter.api.Test;
|
||||
* @author Thomas Risberg
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class Db2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
class Db2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
|
||||
public Db2PagingQueryProviderTests() {
|
||||
Db2PagingQueryProviderTests() {
|
||||
pagingQueryProvider = new Db2PagingQueryProvider();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateFirstPageQuery() {
|
||||
void testGenerateFirstPageQuery() {
|
||||
String sql = "SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY id ASC FETCH FIRST 100 ROWS ONLY";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -39,7 +39,7 @@ public class Db2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderT
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateRemainingPagesQuery() {
|
||||
void testGenerateRemainingPagesQuery() {
|
||||
String sql = "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) ORDER BY id ASC FETCH FIRST 100 ROWS ONLY";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -47,7 +47,7 @@ public class Db2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderT
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQuery() {
|
||||
void testGenerateJumpToItemQuery() {
|
||||
String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -55,7 +55,7 @@ public class Db2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderT
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQueryForFirstPage() {
|
||||
void testGenerateJumpToItemQueryForFirstPage() {
|
||||
String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -63,7 +63,7 @@ public class Db2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderT
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateFirstPageQueryWithGroupBy() {
|
||||
void testGenerateFirstPageQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC FETCH FIRST 100 ROWS ONLY";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
@@ -72,7 +72,7 @@ public class Db2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderT
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep) AS MAIN_QRY WHERE ((id > ?)) ORDER BY id ASC FETCH FIRST 100 ROWS ONLY";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
@@ -81,7 +81,7 @@ public class Db2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderT
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
@@ -90,7 +90,7 @@ public class Db2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderT
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
@@ -98,22 +98,22 @@ public class Db2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderT
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirstPageSqlWithMultipleSortKeys() {
|
||||
String getFirstPageSqlWithMultipleSortKeys() {
|
||||
return "SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC FETCH FIRST 100 ROWS ONLY";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemainingSqlWithMultipleSortKeys() {
|
||||
String getRemainingSqlWithMultipleSortKeys() {
|
||||
return "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC FETCH FIRST 100 ROWS ONLY";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY name ASC, id DESC";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY name ASC, id DESC";
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@ package org.springframework.batch.item.database.support;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -40,18 +40,18 @@ import org.springframework.jdbc.support.incrementer.SybaseMaxValueIncrementer;
|
||||
* @author Drummond Dawson
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class DefaultDataFieldMaxValueIncrementerFactoryTests {
|
||||
class DefaultDataFieldMaxValueIncrementerFactoryTests {
|
||||
|
||||
private DefaultDataFieldMaxValueIncrementerFactory factory;
|
||||
|
||||
@BeforeEach
|
||||
protected void setUp() throws Exception {
|
||||
void setUp() {
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
factory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSupportedDatabaseType() {
|
||||
void testSupportedDatabaseType() {
|
||||
assertTrue(factory.isSupportedIncrementerType("db2"));
|
||||
assertTrue(factory.isSupportedIncrementerType("db2zos"));
|
||||
assertTrue(factory.isSupportedIncrementerType("mysql"));
|
||||
@@ -66,85 +66,73 @@ public class DefaultDataFieldMaxValueIncrementerFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnsupportedDatabaseType() {
|
||||
void testUnsupportedDatabaseType() {
|
||||
assertFalse(factory.isSupportedIncrementerType("invalidtype"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidDatabaseType() {
|
||||
try {
|
||||
factory.getIncrementer("invalidtype", "NAME");
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
void testInvalidDatabaseType() {
|
||||
assertThrows(IllegalArgumentException.class, () -> factory.getIncrementer("invalidtype", "NAME"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullIncrementerName() {
|
||||
try {
|
||||
factory.getIncrementer("db2", null);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
void testNullIncrementerName() {
|
||||
assertThrows(IllegalArgumentException.class, () -> factory.getIncrementer("db2", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDb2() {
|
||||
void testDb2() {
|
||||
assertTrue(factory.getIncrementer("db2", "NAME") instanceof Db2LuwMaxValueIncrementer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDb2zos() {
|
||||
void testDb2zos() {
|
||||
assertTrue(factory.getIncrementer("db2zos", "NAME") instanceof Db2MainframeMaxValueIncrementer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMysql() {
|
||||
void testMysql() {
|
||||
assertTrue(factory.getIncrementer("mysql", "NAME") instanceof MySQLMaxValueIncrementer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOracle() {
|
||||
void testOracle() {
|
||||
factory.setIncrementerColumnName("ID");
|
||||
assertTrue(factory.getIncrementer("oracle", "NAME") instanceof OracleSequenceMaxValueIncrementer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDerby() {
|
||||
void testDerby() {
|
||||
assertTrue(factory.getIncrementer("derby", "NAME") instanceof DerbyMaxValueIncrementer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHsql() {
|
||||
void testHsql() {
|
||||
assertTrue(factory.getIncrementer("hsql", "NAME") instanceof HsqlMaxValueIncrementer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostgres() {
|
||||
void testPostgres() {
|
||||
assertTrue(factory.getIncrementer("postgres", "NAME") instanceof PostgresSequenceMaxValueIncrementer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMsSqlServer() {
|
||||
void testMsSqlServer() {
|
||||
assertTrue(factory.getIncrementer("sqlserver", "NAME") instanceof SqlServerSequenceMaxValueIncrementer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSybase() {
|
||||
void testSybase() {
|
||||
assertTrue(factory.getIncrementer("sybase", "NAME") instanceof SybaseMaxValueIncrementer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSqlite() {
|
||||
void testSqlite() {
|
||||
assertTrue(factory.getIncrementer("sqlite", "NAME") instanceof SqliteMaxValueIncrementer);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHana() {
|
||||
void testHana() {
|
||||
assertTrue(factory.getIncrementer("hana", "NAME") instanceof HanaSequenceMaxValueIncrementer);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,18 +15,17 @@
|
||||
*/
|
||||
package org.springframework.batch.item.database.support;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.item.database.Order;
|
||||
import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
||||
@@ -36,14 +35,14 @@ import org.springframework.dao.InvalidDataAccessResourceUsageException;
|
||||
* @author Michael Minella
|
||||
* @author Will Schipp
|
||||
*/
|
||||
public class DerbyPagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
class DerbyPagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
|
||||
public DerbyPagingQueryProviderTests() {
|
||||
DerbyPagingQueryProviderTests() {
|
||||
pagingQueryProvider = new DerbyPagingQueryProvider();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInit() throws Exception {
|
||||
void testInit() throws Exception {
|
||||
DataSource ds = mock(DataSource.class);
|
||||
Connection con = mock(Connection.class);
|
||||
DatabaseMetaData dmd = mock(DatabaseMetaData.class);
|
||||
@@ -54,7 +53,7 @@ public class DerbyPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitWithRecentVersion() throws Exception {
|
||||
void testInitWithRecentVersion() throws Exception {
|
||||
DataSource ds = mock(DataSource.class);
|
||||
Connection con = mock(Connection.class);
|
||||
DatabaseMetaData dmd = mock(DatabaseMetaData.class);
|
||||
@@ -65,52 +64,46 @@ public class DerbyPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInitWithUnsupportedVersion() throws Exception {
|
||||
void testInitWithUnsupportedVersion() throws Exception {
|
||||
DataSource ds = mock(DataSource.class);
|
||||
Connection con = mock(Connection.class);
|
||||
DatabaseMetaData dmd = mock(DatabaseMetaData.class);
|
||||
when(dmd.getDatabaseProductVersion()).thenReturn("10.2.9.9");
|
||||
when(con.getMetaData()).thenReturn(dmd);
|
||||
when(ds.getConnection()).thenReturn(con);
|
||||
try {
|
||||
pagingQueryProvider.init(ds);
|
||||
fail();
|
||||
}
|
||||
catch (InvalidDataAccessResourceUsageException e) {
|
||||
// expected
|
||||
}
|
||||
assertThrows(InvalidDataAccessResourceUsageException.class, () -> pagingQueryProvider.init(ds));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateFirstPageQuery() {
|
||||
void testGenerateFirstPageQuery() {
|
||||
String sql = "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
Assertions.assertEquals(sql, s);
|
||||
assertEquals(sql, s);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateRemainingPagesQuery() {
|
||||
void testGenerateRemainingPagesQuery() {
|
||||
String sql = "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((id > ?)) ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
Assertions.assertEquals(sql, s);
|
||||
assertEquals(sql, s);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQuery() {
|
||||
void testGenerateJumpToItemQuery() {
|
||||
String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
Assertions.assertEquals(sql, s);
|
||||
assertEquals(sql, s);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQueryForFirstPage() {
|
||||
void testGenerateJumpToItemQueryForFirstPage() {
|
||||
String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
Assertions.assertEquals(sql, s);
|
||||
assertEquals(sql, s);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,7 +112,7 @@ public class DerbyPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
*/
|
||||
@Test
|
||||
@Override
|
||||
public void testQueryContainsSortKey() {
|
||||
void testQueryContainsSortKey() {
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize).toLowerCase();
|
||||
assertTrue(s.contains("id asc"), "Wrong query: " + s);
|
||||
}
|
||||
@@ -130,7 +123,7 @@ public class DerbyPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
*/
|
||||
@Test
|
||||
@Override
|
||||
public void testQueryContainsSortKeyDesc() {
|
||||
void testQueryContainsSortKeyDesc() {
|
||||
pagingQueryProvider.getSortKeys().put("id", Order.DESCENDING);
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize).toLowerCase();
|
||||
assertTrue(s.contains("id desc"), "Wrong query: " + s);
|
||||
@@ -138,7 +131,7 @@ public class DerbyPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateFirstPageQueryWithGroupBy() {
|
||||
void testGenerateFirstPageQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
@@ -147,7 +140,7 @@ public class DerbyPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((id > ?)) ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
@@ -156,7 +149,7 @@ public class DerbyPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
@@ -165,7 +158,7 @@ public class DerbyPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
@@ -173,22 +166,22 @@ public class DerbyPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirstPageSqlWithMultipleSortKeys() {
|
||||
String getFirstPageSqlWithMultipleSortKeys() {
|
||||
return "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 ORDER BY name ASC, id DESC";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemainingSqlWithMultipleSortKeys() {
|
||||
String getRemainingSqlWithMultipleSortKeys() {
|
||||
return "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY name ASC, id DESC";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY name ASC, id DESC";
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
* @author Henning Pöttker
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class H2PagingQueryProviderIntegrationTests {
|
||||
class H2PagingQueryProviderIntegrationTests {
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(ModeEnum.class)
|
||||
|
||||
@@ -25,15 +25,15 @@ import org.junit.jupiter.api.Test;
|
||||
* @author Michael Minella
|
||||
* @author Henning Pöttker
|
||||
*/
|
||||
public class H2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
class H2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
|
||||
public H2PagingQueryProviderTests() {
|
||||
H2PagingQueryProviderTests() {
|
||||
pagingQueryProvider = new H2PagingQueryProvider();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateFirstPageQuery() {
|
||||
void testGenerateFirstPageQuery() {
|
||||
String sql = "SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY id ASC FETCH NEXT 100 ROWS ONLY";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -41,7 +41,7 @@ public class H2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderTe
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateRemainingPagesQuery() {
|
||||
void testGenerateRemainingPagesQuery() {
|
||||
String sql = "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) "
|
||||
+ "ORDER BY id ASC FETCH NEXT 100 ROWS ONLY";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
@@ -50,7 +50,7 @@ public class H2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderTe
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQuery() {
|
||||
void testGenerateJumpToItemQuery() {
|
||||
String sql = "SELECT id FROM foo WHERE bar = 1 ORDER BY id ASC OFFSET 99 ROWS FETCH NEXT 1 ROWS ONLY";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -58,7 +58,7 @@ public class H2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderTe
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQueryForFirstPage() {
|
||||
void testGenerateJumpToItemQueryForFirstPage() {
|
||||
String sql = "SELECT id FROM foo WHERE bar = 1 ORDER BY id ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -66,7 +66,7 @@ public class H2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderTe
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateFirstPageQueryWithGroupBy() {
|
||||
void testGenerateFirstPageQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC FETCH NEXT 100 ROWS ONLY";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
@@ -75,7 +75,7 @@ public class H2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderTe
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) GROUP BY dep "
|
||||
+ "ORDER BY id ASC FETCH NEXT 100 ROWS ONLY";
|
||||
@@ -85,7 +85,7 @@ public class H2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderTe
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC OFFSET 99 ROWS FETCH NEXT 1 ROWS ONLY";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
@@ -94,7 +94,7 @@ public class H2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderTe
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
@@ -102,23 +102,23 @@ public class H2PagingQueryProviderTests extends AbstractSqlPagingQueryProviderTe
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirstPageSqlWithMultipleSortKeys() {
|
||||
String getFirstPageSqlWithMultipleSortKeys() {
|
||||
return "SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC FETCH NEXT 100 ROWS ONLY";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemainingSqlWithMultipleSortKeys() {
|
||||
String getRemainingSqlWithMultipleSortKeys() {
|
||||
return "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((name > ?) OR (name = ? AND id < ?)) "
|
||||
+ "ORDER BY name ASC, id DESC FETCH NEXT 100 ROWS ONLY";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
return "SELECT name, id FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC OFFSET 99 ROWS FETCH NEXT 1 ROWS ONLY";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
return "SELECT name, id FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY";
|
||||
}
|
||||
|
||||
|
||||
@@ -28,15 +28,15 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
* @author Jonathan Bregler
|
||||
* @since 5.0
|
||||
*/
|
||||
public class HanaPagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
class HanaPagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
|
||||
public HanaPagingQueryProviderTests() {
|
||||
HanaPagingQueryProviderTests() {
|
||||
pagingQueryProvider = new HanaPagingQueryProvider();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateFirstPageQuery() {
|
||||
void testGenerateFirstPageQuery() {
|
||||
String sql = "SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY id ASC LIMIT 100";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -44,7 +44,7 @@ public class HanaPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateRemainingPagesQuery() {
|
||||
void testGenerateRemainingPagesQuery() {
|
||||
String sql = "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) ORDER BY id ASC LIMIT 100";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -52,7 +52,7 @@ public class HanaPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQuery() {
|
||||
void testGenerateJumpToItemQuery() {
|
||||
String sql = "SELECT id FROM foo WHERE bar = 1 ORDER BY id ASC LIMIT 1 OFFSET 99";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -60,7 +60,7 @@ public class HanaPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQueryForFirstPage() {
|
||||
void testGenerateJumpToItemQueryForFirstPage() {
|
||||
String sql = "SELECT id FROM foo WHERE bar = 1 ORDER BY id ASC LIMIT 1 OFFSET 0";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -68,7 +68,7 @@ public class HanaPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateFirstPageQueryWithGroupBy() {
|
||||
void testGenerateFirstPageQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC LIMIT 100";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
@@ -77,7 +77,7 @@ public class HanaPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep) AS MAIN_QRY WHERE ((id > ?)) ORDER BY id ASC LIMIT 100";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
@@ -86,7 +86,7 @@ public class HanaPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC LIMIT 1 OFFSET 99";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
@@ -95,7 +95,7 @@ public class HanaPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC LIMIT 1 OFFSET 0";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
@@ -103,7 +103,7 @@ public class HanaPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFirstPageSqlWithAliases() {
|
||||
void testFirstPageSqlWithAliases() {
|
||||
Map<String, Order> sorts = new HashMap<>();
|
||||
sorts.put("owner.id", Order.ASCENDING);
|
||||
|
||||
@@ -128,22 +128,22 @@ public class HanaPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirstPageSqlWithMultipleSortKeys() {
|
||||
String getFirstPageSqlWithMultipleSortKeys() {
|
||||
return "SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC LIMIT 100";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemainingSqlWithMultipleSortKeys() {
|
||||
String getRemainingSqlWithMultipleSortKeys() {
|
||||
return "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC LIMIT 100";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
return "SELECT name, id FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC LIMIT 1 OFFSET 99";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
return "SELECT name, id FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC LIMIT 1 OFFSET 0";
|
||||
}
|
||||
|
||||
|
||||
@@ -41,26 +41,22 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@SpringJUnitConfig(locations = "../data-source-context.xml")
|
||||
public class HibernateNativeQueryProviderIntegrationTests {
|
||||
class HibernateNativeQueryProviderIntegrationTests {
|
||||
|
||||
protected DataSource dataSource;
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
protected HibernateNativeQueryProvider<Foo> hibernateQueryProvider;
|
||||
private final HibernateNativeQueryProvider<Foo> hibernateQueryProvider;
|
||||
|
||||
private SessionFactory sessionFactory;
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
this.dataSource = dataSource;
|
||||
}
|
||||
|
||||
public HibernateNativeQueryProviderIntegrationTests() {
|
||||
HibernateNativeQueryProviderIntegrationTests() {
|
||||
hibernateQueryProvider = new HibernateNativeQueryProvider<>();
|
||||
hibernateQueryProvider.setEntityClass(Foo.class);
|
||||
}
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() throws Exception {
|
||||
void setUp() throws Exception {
|
||||
|
||||
LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean();
|
||||
factoryBean.setDataSource(dataSource);
|
||||
@@ -73,7 +69,7 @@ public class HibernateNativeQueryProviderIntegrationTests {
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void shouldRetrieveAndMapAllFoos() throws Exception {
|
||||
void shouldRetrieveAndMapAllFoos() throws Exception {
|
||||
|
||||
String nativeQuery = "select * from T_FOOS";
|
||||
|
||||
@@ -91,7 +87,6 @@ public class HibernateNativeQueryProviderIntegrationTests {
|
||||
expectedFoos.add(new Foo(4, "bar4", 4));
|
||||
expectedFoos.add(new Foo(5, "bar5", 5));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Foo> actualFoos = query.list();
|
||||
|
||||
assertEquals(actualFoos, expectedFoos);
|
||||
|
||||
@@ -32,18 +32,18 @@ import static org.mockito.Mockito.when;
|
||||
* @author Dave Syer
|
||||
* @author Will Schipp
|
||||
*/
|
||||
public class HibernateNativeQueryProviderTests {
|
||||
class HibernateNativeQueryProviderTests {
|
||||
|
||||
protected HibernateNativeQueryProvider<Foo> hibernateQueryProvider;
|
||||
private final HibernateNativeQueryProvider<Foo> hibernateQueryProvider;
|
||||
|
||||
public HibernateNativeQueryProviderTests() {
|
||||
HibernateNativeQueryProviderTests() {
|
||||
hibernateQueryProvider = new HibernateNativeQueryProvider<>();
|
||||
hibernateQueryProvider.setEntityClass(Foo.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testCreateQueryWithStatelessSession() {
|
||||
void testCreateQueryWithStatelessSession() {
|
||||
String sqlQuery = "select * from T_FOOS";
|
||||
hibernateQueryProvider.setSqlQuery(sqlQuery);
|
||||
|
||||
@@ -60,7 +60,7 @@ public class HibernateNativeQueryProviderTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void shouldCreateQueryWithStatefulSession() {
|
||||
void shouldCreateQueryWithStatefulSession() {
|
||||
String sqlQuery = "select * from T_FOOS";
|
||||
hibernateQueryProvider.setSqlQuery(sqlQuery);
|
||||
|
||||
|
||||
@@ -23,15 +23,15 @@ import org.junit.jupiter.api.Test;
|
||||
* @author Thomas Risberg
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class HsqlPagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
class HsqlPagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
|
||||
public HsqlPagingQueryProviderTests() {
|
||||
HsqlPagingQueryProviderTests() {
|
||||
pagingQueryProvider = new HsqlPagingQueryProvider();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateFirstPageQuery() {
|
||||
void testGenerateFirstPageQuery() {
|
||||
String sql = "SELECT TOP 100 id, name, age FROM foo WHERE bar = 1 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -39,7 +39,7 @@ public class HsqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateRemainingPagesQuery() {
|
||||
void testGenerateRemainingPagesQuery() {
|
||||
String sql = "SELECT TOP 100 id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -47,7 +47,7 @@ public class HsqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQuery() {
|
||||
void testGenerateJumpToItemQuery() {
|
||||
String sql = "SELECT LIMIT 99 1 id FROM foo WHERE bar = 1 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -55,7 +55,7 @@ public class HsqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQueryForFirstPage() {
|
||||
void testGenerateJumpToItemQueryForFirstPage() {
|
||||
String sql = "SELECT LIMIT 0 1 id FROM foo WHERE bar = 1 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -63,7 +63,7 @@ public class HsqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateFirstPageQueryWithGroupBy() {
|
||||
void testGenerateFirstPageQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT TOP 100 id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
@@ -72,7 +72,7 @@ public class HsqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT TOP 100 * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep) AS MAIN_QRY WHERE ((id > ?)) ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
@@ -81,7 +81,7 @@ public class HsqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT LIMIT 99 1 id FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
@@ -90,7 +90,7 @@ public class HsqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT LIMIT 0 1 id FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
@@ -98,22 +98,22 @@ public class HsqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvider
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirstPageSqlWithMultipleSortKeys() {
|
||||
String getFirstPageSqlWithMultipleSortKeys() {
|
||||
return "SELECT TOP 100 id, name, age FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemainingSqlWithMultipleSortKeys() {
|
||||
String getRemainingSqlWithMultipleSortKeys() {
|
||||
return "SELECT TOP 100 id, name, age FROM foo WHERE (bar = 1) AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
return "SELECT LIMIT 99 1 name, id FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
return "SELECT LIMIT 0 1 name, id FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC";
|
||||
}
|
||||
|
||||
|
||||
@@ -34,17 +34,17 @@ import static org.mockito.Mockito.when;
|
||||
* @author Will Schipp
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class JpaNativeQueryProviderTests {
|
||||
class JpaNativeQueryProviderTests {
|
||||
|
||||
private JpaNativeQueryProvider<Foo> jpaQueryProvider;
|
||||
private final JpaNativeQueryProvider<Foo> jpaQueryProvider;
|
||||
|
||||
public JpaNativeQueryProviderTests() {
|
||||
JpaNativeQueryProviderTests() {
|
||||
jpaQueryProvider = new JpaNativeQueryProvider<>();
|
||||
jpaQueryProvider.setEntityClass(Foo.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateQuery() {
|
||||
void testCreateQuery() {
|
||||
|
||||
String sqlQuery = "select * from T_FOOS where value >= :limit";
|
||||
jpaQueryProvider.setSqlQuery(sqlQuery);
|
||||
|
||||
@@ -28,15 +28,15 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
* @author Thomas Risberg
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class MySqlPagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
class MySqlPagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
|
||||
public MySqlPagingQueryProviderTests() {
|
||||
MySqlPagingQueryProviderTests() {
|
||||
pagingQueryProvider = new MySqlPagingQueryProvider();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateFirstPageQuery() {
|
||||
void testGenerateFirstPageQuery() {
|
||||
String sql = "SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY id ASC LIMIT 100";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -44,7 +44,7 @@ public class MySqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateRemainingPagesQuery() {
|
||||
void testGenerateRemainingPagesQuery() {
|
||||
String sql = "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) ORDER BY id ASC LIMIT 100";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -52,7 +52,7 @@ public class MySqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQuery() {
|
||||
void testGenerateJumpToItemQuery() {
|
||||
String sql = "SELECT id FROM foo WHERE bar = 1 ORDER BY id ASC LIMIT 99, 1";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -60,7 +60,7 @@ public class MySqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQueryForFirstPage() {
|
||||
void testGenerateJumpToItemQueryForFirstPage() {
|
||||
String sql = "SELECT id FROM foo WHERE bar = 1 ORDER BY id ASC LIMIT 0, 1";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -68,7 +68,7 @@ public class MySqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateFirstPageQueryWithGroupBy() {
|
||||
void testGenerateFirstPageQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC LIMIT 100";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
@@ -77,7 +77,7 @@ public class MySqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep) AS MAIN_QRY WHERE ((id > ?)) ORDER BY id ASC LIMIT 100";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
@@ -86,7 +86,7 @@ public class MySqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC LIMIT 99, 1";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
@@ -95,7 +95,7 @@ public class MySqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC LIMIT 0, 1";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
@@ -103,7 +103,7 @@ public class MySqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFirstPageSqlWithAliases() {
|
||||
void testFirstPageSqlWithAliases() {
|
||||
Map<String, Order> sorts = new HashMap<>();
|
||||
sorts.put("owner.id", Order.ASCENDING);
|
||||
|
||||
@@ -128,22 +128,22 @@ public class MySqlPagingQueryProviderTests extends AbstractSqlPagingQueryProvide
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirstPageSqlWithMultipleSortKeys() {
|
||||
String getFirstPageSqlWithMultipleSortKeys() {
|
||||
return "SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC LIMIT 100";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemainingSqlWithMultipleSortKeys() {
|
||||
String getRemainingSqlWithMultipleSortKeys() {
|
||||
return "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC LIMIT 100";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
return "SELECT name, id FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC LIMIT 99, 1";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
return "SELECT name, id FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC LIMIT 0, 1";
|
||||
}
|
||||
|
||||
|
||||
@@ -23,15 +23,15 @@ import org.junit.jupiter.api.Test;
|
||||
* @author Thomas Risberg
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class OraclePagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
class OraclePagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
|
||||
public OraclePagingQueryProviderTests() {
|
||||
OraclePagingQueryProviderTests() {
|
||||
pagingQueryProvider = new OraclePagingQueryProvider();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateFirstPageQuery() {
|
||||
void testGenerateFirstPageQuery() {
|
||||
String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY id ASC) WHERE ROWNUM <= 100";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -43,7 +43,7 @@ public class OraclePagingQueryProviderTests extends AbstractSqlPagingQueryProvid
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateRemainingPagesQuery() {
|
||||
void testGenerateRemainingPagesQuery() {
|
||||
String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY id ASC) WHERE ROWNUM <= 100 AND ((id > ?))";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -51,7 +51,7 @@ public class OraclePagingQueryProviderTests extends AbstractSqlPagingQueryProvid
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQuery() {
|
||||
void testGenerateJumpToItemQuery() {
|
||||
String sql = "SELECT id FROM (SELECT id, ROWNUM as TMP_ROW_NUM FROM (SELECT id FROM foo WHERE bar = 1 ORDER BY id ASC)) WHERE TMP_ROW_NUM = 100";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -59,7 +59,7 @@ public class OraclePagingQueryProviderTests extends AbstractSqlPagingQueryProvid
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQueryForFirstPage() {
|
||||
void testGenerateJumpToItemQueryForFirstPage() {
|
||||
String sql = "SELECT id FROM (SELECT id, ROWNUM as TMP_ROW_NUM FROM (SELECT id FROM foo WHERE bar = 1 ORDER BY id ASC)) WHERE TMP_ROW_NUM = 1";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -67,7 +67,7 @@ public class OraclePagingQueryProviderTests extends AbstractSqlPagingQueryProvid
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateFirstPageQueryWithGroupBy() {
|
||||
void testGenerateFirstPageQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC) WHERE ROWNUM <= 100";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
@@ -76,7 +76,7 @@ public class OraclePagingQueryProviderTests extends AbstractSqlPagingQueryProvid
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC) WHERE ROWNUM <= 100 AND ((id > ?))";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
@@ -85,7 +85,7 @@ public class OraclePagingQueryProviderTests extends AbstractSqlPagingQueryProvid
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id FROM (SELECT id, MIN(ROWNUM) as TMP_ROW_NUM FROM (SELECT id FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC)) WHERE TMP_ROW_NUM = 100";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
@@ -94,7 +94,7 @@ public class OraclePagingQueryProviderTests extends AbstractSqlPagingQueryProvid
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id FROM (SELECT id, MIN(ROWNUM) as TMP_ROW_NUM FROM (SELECT id FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC)) WHERE TMP_ROW_NUM = 1";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
@@ -102,22 +102,22 @@ public class OraclePagingQueryProviderTests extends AbstractSqlPagingQueryProvid
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirstPageSqlWithMultipleSortKeys() {
|
||||
String getFirstPageSqlWithMultipleSortKeys() {
|
||||
return "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC) WHERE ROWNUM <= 100";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemainingSqlWithMultipleSortKeys() {
|
||||
String getRemainingSqlWithMultipleSortKeys() {
|
||||
return "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC) WHERE ROWNUM <= 100 AND ((name > ?) OR (name = ? AND id < ?))";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
return "SELECT name, id FROM (SELECT name, id, ROWNUM as TMP_ROW_NUM FROM (SELECT name, id FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC)) WHERE TMP_ROW_NUM = 100";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
return "SELECT name, id FROM (SELECT name, id, ROWNUM as TMP_ROW_NUM FROM (SELECT name, id FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC)) WHERE TMP_ROW_NUM = 1";
|
||||
}
|
||||
|
||||
|
||||
@@ -23,15 +23,15 @@ import org.junit.jupiter.api.Test;
|
||||
* @author Thomas Risberg
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class PostgresPagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
class PostgresPagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
|
||||
public PostgresPagingQueryProviderTests() {
|
||||
PostgresPagingQueryProviderTests() {
|
||||
pagingQueryProvider = new PostgresPagingQueryProvider();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateFirstPageQuery() {
|
||||
void testGenerateFirstPageQuery() {
|
||||
String sql = "SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY id ASC LIMIT 100";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -39,7 +39,7 @@ public class PostgresPagingQueryProviderTests extends AbstractSqlPagingQueryProv
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateRemainingPagesQuery() {
|
||||
void testGenerateRemainingPagesQuery() {
|
||||
String sql = "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) ORDER BY id ASC LIMIT 100";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -47,7 +47,7 @@ public class PostgresPagingQueryProviderTests extends AbstractSqlPagingQueryProv
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQuery() {
|
||||
void testGenerateJumpToItemQuery() {
|
||||
String sql = "SELECT id FROM foo WHERE bar = 1 ORDER BY id ASC LIMIT 1 OFFSET 99";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
assertEquals(sql, s, "Wrong SQL for jump to");
|
||||
@@ -55,7 +55,7 @@ public class PostgresPagingQueryProviderTests extends AbstractSqlPagingQueryProv
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQueryForFirstPage() {
|
||||
void testGenerateJumpToItemQueryForFirstPage() {
|
||||
String sql = "SELECT id FROM foo WHERE bar = 1 ORDER BY id ASC LIMIT 1 OFFSET 0";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
assertEquals(sql, s, "Wrong SQL for first page");
|
||||
@@ -63,7 +63,7 @@ public class PostgresPagingQueryProviderTests extends AbstractSqlPagingQueryProv
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateFirstPageQueryWithGroupBy() {
|
||||
void testGenerateFirstPageQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("id, dep");
|
||||
String sql = "SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY id, dep ORDER BY id ASC LIMIT 100";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
@@ -72,7 +72,7 @@ public class PostgresPagingQueryProviderTests extends AbstractSqlPagingQueryProv
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("id, dep");
|
||||
String sql = "SELECT * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY id, dep) AS MAIN_QRY WHERE ((id > ?)) ORDER BY id ASC LIMIT 100";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
@@ -81,7 +81,7 @@ public class PostgresPagingQueryProviderTests extends AbstractSqlPagingQueryProv
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("id, dep");
|
||||
String sql = "SELECT id FROM foo WHERE bar = 1 GROUP BY id, dep ORDER BY id ASC LIMIT 1 OFFSET 99";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
@@ -90,7 +90,7 @@ public class PostgresPagingQueryProviderTests extends AbstractSqlPagingQueryProv
|
||||
|
||||
@Override
|
||||
@Test
|
||||
public void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("id, dep");
|
||||
String sql = "SELECT id FROM foo WHERE bar = 1 GROUP BY id, dep ORDER BY id ASC LIMIT 1 OFFSET 0";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
@@ -98,22 +98,22 @@ public class PostgresPagingQueryProviderTests extends AbstractSqlPagingQueryProv
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirstPageSqlWithMultipleSortKeys() {
|
||||
String getFirstPageSqlWithMultipleSortKeys() {
|
||||
return "SELECT id, name, age FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC LIMIT 100";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemainingSqlWithMultipleSortKeys() {
|
||||
String getRemainingSqlWithMultipleSortKeys() {
|
||||
return "SELECT id, name, age FROM foo WHERE (bar = 1) AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC LIMIT 100";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
return "SELECT name, id FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC LIMIT 1 OFFSET 99";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
return "SELECT name, id FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC LIMIT 1 OFFSET 0";
|
||||
}
|
||||
|
||||
|
||||
@@ -36,11 +36,11 @@ import org.springframework.jdbc.support.MetaDataAccessException;
|
||||
* @author Dave Syer
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class SqlPagingQueryProviderFactoryBeanTests {
|
||||
class SqlPagingQueryProviderFactoryBeanTests {
|
||||
|
||||
private SqlPagingQueryProviderFactoryBean factory = new SqlPagingQueryProviderFactoryBean();
|
||||
private final SqlPagingQueryProviderFactoryBean factory = new SqlPagingQueryProviderFactoryBean();
|
||||
|
||||
public SqlPagingQueryProviderFactoryBeanTests() throws Exception {
|
||||
SqlPagingQueryProviderFactoryBeanTests() throws Exception {
|
||||
factory.setSelectClause("id, name, age");
|
||||
factory.setFromClause("foo");
|
||||
factory.setWhereClause("bar = 1");
|
||||
@@ -52,35 +52,35 @@ public class SqlPagingQueryProviderFactoryBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFactory() throws Exception {
|
||||
void testFactory() throws Exception {
|
||||
PagingQueryProvider provider = factory.getObject();
|
||||
assertNotNull(provider);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testType() throws Exception {
|
||||
void testType() {
|
||||
assertEquals(PagingQueryProvider.class, factory.getObjectType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleton() throws Exception {
|
||||
assertEquals(true, factory.isSingleton());
|
||||
void testSingleton() {
|
||||
assertTrue(factory.isSingleton());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoDataSource() {
|
||||
void testNoDataSource() {
|
||||
factory.setDataSource(null);
|
||||
assertThrows(IllegalArgumentException.class, factory::getObject);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoSortKey() {
|
||||
void testNoSortKey() {
|
||||
factory.setSortKeys(null);
|
||||
assertThrows(IllegalArgumentException.class, factory::getObject);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWhereClause() throws Exception {
|
||||
void testWhereClause() throws Exception {
|
||||
factory.setWhereClause("x=y");
|
||||
PagingQueryProvider provider = factory.getObject();
|
||||
String query = provider.generateFirstPageQuery(100);
|
||||
@@ -88,26 +88,26 @@ public class SqlPagingQueryProviderFactoryBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAscending() throws Exception {
|
||||
void testAscending() throws Exception {
|
||||
PagingQueryProvider provider = factory.getObject();
|
||||
String query = provider.generateFirstPageQuery(100);
|
||||
assertTrue(query.contains("ASC"), "Wrong query: " + query);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongDatabaseType() {
|
||||
void testWrongDatabaseType() {
|
||||
factory.setDatabaseType("NoSuchDb");
|
||||
assertThrows(IllegalArgumentException.class, factory::getObject);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingMetaData() throws Exception {
|
||||
void testMissingMetaData() throws Exception {
|
||||
factory.setDataSource(DatabaseTypeTestUtils.getMockDataSource(new MetaDataAccessException("foo")));
|
||||
assertThrows(IllegalArgumentException.class, factory::getObject);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllDatabaseTypes() throws Exception {
|
||||
void testAllDatabaseTypes() throws Exception {
|
||||
for (DatabaseType type : DatabaseType.values()) {
|
||||
factory.setDatabaseType(type.name());
|
||||
PagingQueryProvider provider = factory.getObject();
|
||||
|
||||
@@ -22,7 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.batch.item.database.Order;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -33,18 +32,12 @@ import org.springframework.util.StringUtils;
|
||||
* @author Michael Minella
|
||||
* @since 2.0
|
||||
*/
|
||||
public class SqlPagingQueryUtilsTests {
|
||||
class SqlPagingQueryUtilsTests {
|
||||
|
||||
private Map<String, Order> sortKeys;
|
||||
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
sortKeys = new LinkedHashMap<>();
|
||||
sortKeys.put("ID", Order.ASCENDING);
|
||||
}
|
||||
private final Map<String, Order> sortKeys = new LinkedHashMap<>(Map.of("ID", Order.ASCENDING));
|
||||
|
||||
@Test
|
||||
public void testGenerateLimitSqlQuery() {
|
||||
void testGenerateLimitSqlQuery() {
|
||||
AbstractSqlPagingQueryProvider qp = new TestSqlPagingQueryProvider("FOO", "BAR", sortKeys);
|
||||
assertEquals("SELECT FOO FROM BAR ORDER BY ID ASC LIMIT 100",
|
||||
SqlPagingQueryUtils.generateLimitSqlQuery(qp, false, "LIMIT 100"));
|
||||
@@ -58,7 +51,7 @@ public class SqlPagingQueryUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTopSqlQuery() {
|
||||
void testGenerateTopSqlQuery() {
|
||||
AbstractSqlPagingQueryProvider qp = new TestSqlPagingQueryProvider("FOO", "BAR", sortKeys);
|
||||
assertEquals("SELECT TOP 100 FOO FROM BAR ORDER BY ID ASC",
|
||||
SqlPagingQueryUtils.generateTopSqlQuery(qp, false, "TOP 100"));
|
||||
@@ -72,7 +65,7 @@ public class SqlPagingQueryUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateRowNumSqlQuery() {
|
||||
void testGenerateRowNumSqlQuery() {
|
||||
AbstractSqlPagingQueryProvider qp = new TestSqlPagingQueryProvider("FOO", "BAR", sortKeys);
|
||||
assertEquals("SELECT * FROM (SELECT FOO FROM BAR ORDER BY ID ASC) WHERE ROWNUMBER <= 100",
|
||||
SqlPagingQueryUtils.generateRowNumSqlQuery(qp, false, "ROWNUMBER <= 100"));
|
||||
@@ -87,7 +80,7 @@ public class SqlPagingQueryUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateRowNumSqlQueryWithNesting() {
|
||||
void testGenerateRowNumSqlQueryWithNesting() {
|
||||
AbstractSqlPagingQueryProvider qp = new TestSqlPagingQueryProvider("FOO", "BAR", sortKeys);
|
||||
assertEquals(
|
||||
"SELECT FOO FROM (SELECT FOO, ROWNUM as TMP_ROW_NUM FROM (SELECT FOO FROM BAR ORDER BY ID ASC)) WHERE ROWNUMBER <= 100",
|
||||
@@ -95,7 +88,7 @@ public class SqlPagingQueryUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTopSqlQueryDescending() {
|
||||
void testGenerateTopSqlQueryDescending() {
|
||||
sortKeys.put("ID", Order.DESCENDING);
|
||||
AbstractSqlPagingQueryProvider qp = new TestSqlPagingQueryProvider("FOO", "BAR", sortKeys);
|
||||
assertEquals("SELECT TOP 100 FOO FROM BAR ORDER BY ID DESC",
|
||||
@@ -110,7 +103,7 @@ public class SqlPagingQueryUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateRowNumSqlQueryDescending() {
|
||||
void testGenerateRowNumSqlQueryDescending() {
|
||||
sortKeys.put("ID", Order.DESCENDING);
|
||||
AbstractSqlPagingQueryProvider qp = new TestSqlPagingQueryProvider("FOO", "BAR", sortKeys);
|
||||
assertEquals("SELECT * FROM (SELECT FOO FROM BAR ORDER BY ID DESC) WHERE ROWNUMBER <= 100",
|
||||
@@ -127,7 +120,7 @@ public class SqlPagingQueryUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateLimitJumpToQuery() {
|
||||
void testGenerateLimitJumpToQuery() {
|
||||
AbstractSqlPagingQueryProvider qp = new TestSqlPagingQueryProvider("FOO", "BAR", sortKeys);
|
||||
assertEquals("SELECT ID FROM BAR ORDER BY ID ASC LIMIT 100, 1",
|
||||
SqlPagingQueryUtils.generateLimitJumpToQuery(qp, "LIMIT 100, 1"));
|
||||
@@ -137,7 +130,7 @@ public class SqlPagingQueryUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTopJumpToQuery() {
|
||||
void testGenerateTopJumpToQuery() {
|
||||
AbstractSqlPagingQueryProvider qp = new TestSqlPagingQueryProvider("FOO", "BAR", sortKeys);
|
||||
assertEquals("SELECT TOP 100, 1 ID FROM BAR ORDER BY ID ASC",
|
||||
SqlPagingQueryUtils.generateTopJumpToQuery(qp, "TOP 100, 1"));
|
||||
@@ -147,7 +140,7 @@ public class SqlPagingQueryUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateTopJumpQueryDescending() {
|
||||
void testGenerateTopJumpQueryDescending() {
|
||||
sortKeys.put("ID", Order.DESCENDING);
|
||||
AbstractSqlPagingQueryProvider qp = new TestSqlPagingQueryProvider("FOO", "BAR", sortKeys);
|
||||
String query = SqlPagingQueryUtils.generateTopJumpToQuery(qp, "TOP 100, 1");
|
||||
@@ -159,7 +152,7 @@ public class SqlPagingQueryUtilsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateLimitJumpQueryDescending() {
|
||||
void testGenerateLimitJumpQueryDescending() {
|
||||
sortKeys.put("ID", Order.DESCENDING);
|
||||
AbstractSqlPagingQueryProvider qp = new TestSqlPagingQueryProvider("FOO", "BAR", sortKeys);
|
||||
String query = SqlPagingQueryUtils.generateLimitJumpToQuery(qp, "LIMIT 100, 1");
|
||||
|
||||
@@ -23,15 +23,15 @@ import org.junit.jupiter.api.Test;
|
||||
* @author Thomas Risberg
|
||||
* @author Michael Minella
|
||||
*/
|
||||
public class SqlServerPagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
class SqlServerPagingQueryProviderTests extends AbstractSqlPagingQueryProviderTests {
|
||||
|
||||
public SqlServerPagingQueryProviderTests() {
|
||||
SqlServerPagingQueryProviderTests() {
|
||||
pagingQueryProvider = new SqlServerPagingQueryProvider();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateFirstPageQuery() {
|
||||
void testGenerateFirstPageQuery() {
|
||||
String sql = "SELECT TOP 100 id, name, age FROM foo WHERE bar = 1 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -39,7 +39,7 @@ public class SqlServerPagingQueryProviderTests extends AbstractSqlPagingQueryPro
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateRemainingPagesQuery() {
|
||||
void testGenerateRemainingPagesQuery() {
|
||||
String sql = "SELECT TOP 100 id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -47,7 +47,7 @@ public class SqlServerPagingQueryProviderTests extends AbstractSqlPagingQueryPro
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQuery() {
|
||||
void testGenerateJumpToItemQuery() {
|
||||
String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -55,7 +55,7 @@ public class SqlServerPagingQueryProviderTests extends AbstractSqlPagingQueryPro
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQueryForFirstPage() {
|
||||
void testGenerateJumpToItemQueryForFirstPage() {
|
||||
String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
assertEquals(sql, s);
|
||||
@@ -63,7 +63,7 @@ public class SqlServerPagingQueryProviderTests extends AbstractSqlPagingQueryPro
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateFirstPageQueryWithGroupBy() {
|
||||
void testGenerateFirstPageQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT TOP 100 id, name, age FROM foo WHERE bar = 1 GROUP BY dep ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateFirstPageQuery(pageSize);
|
||||
@@ -72,7 +72,7 @@ public class SqlServerPagingQueryProviderTests extends AbstractSqlPagingQueryPro
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
void testGenerateRemainingPagesQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT TOP 100 * FROM (SELECT id, name, age FROM foo WHERE bar = 1 GROUP BY dep) AS MAIN_QRY WHERE ((id > ?)) ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize);
|
||||
@@ -81,7 +81,7 @@ public class SqlServerPagingQueryProviderTests extends AbstractSqlPagingQueryPro
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize);
|
||||
@@ -90,7 +90,7 @@ public class SqlServerPagingQueryProviderTests extends AbstractSqlPagingQueryPro
|
||||
|
||||
@Test
|
||||
@Override
|
||||
public void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
void testGenerateJumpToItemQueryForFirstPageWithGroupBy() {
|
||||
pagingQueryProvider.setGroupClause("dep");
|
||||
String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1 GROUP BY dep) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY id ASC";
|
||||
String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize);
|
||||
@@ -98,22 +98,22 @@ public class SqlServerPagingQueryProviderTests extends AbstractSqlPagingQueryPro
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFirstPageSqlWithMultipleSortKeys() {
|
||||
String getFirstPageSqlWithMultipleSortKeys() {
|
||||
return "SELECT TOP 100 id, name, age FROM foo WHERE bar = 1 ORDER BY name ASC, id DESC";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRemainingSqlWithMultipleSortKeys() {
|
||||
String getRemainingSqlWithMultipleSortKeys() {
|
||||
return "SELECT TOP 100 id, name, age FROM foo WHERE (bar = 1) AND ((name > ?) OR (name = ? AND id < ?)) ORDER BY name ASC, id DESC";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryWithMultipleSortKeys() {
|
||||
return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY name ASC, id DESC";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
String getJumpToItemQueryForFirstPageWithMultipleSortKeys() {
|
||||
return "SELECT name, id FROM ( SELECT name, id, ROW_NUMBER() OVER ( ORDER BY name ASC, id DESC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY name ASC, id DESC";
|
||||
}
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user