Migrate tests to AssertJ

Mostly thanks to IDEA's plugin: https://plugins.jetbrains.com/plugin/10345-assertions2assertj
There is still a lot of work to do when complex and composite matchers are used.

* Add `awaitility` dependency and deprecate `EventuallyMatcher` in favor
of `awaitility`
* Remove Hamcrest from dependencies and disable JUnit & Hamcrest
static imports to encourage to use only AssertJ
* Migrate JUnit assumptions in rules to AssertJ's assumptions
* Deprecate some custom matchers in favor of existing in Hamcrest
after upgrading the last to version `2.1`
* Replace `ExpectedException` rules with `assertThatThrownBy()`
* Mention `MessagePredicate` in the `testing.adoc`
This commit is contained in:
Artem Bilan
2019-02-20 12:28:44 -05:00
parent b62c2a8fb3
commit 622d42c71a
916 changed files with 19714 additions and 21769 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-2019 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,8 +16,7 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.HashMap;
import java.util.Map;
@@ -72,10 +71,10 @@ public class AggregatorIntegrationTests {
public void testTransactionalAggregatorGroupTimeout() throws InterruptedException {
this.transactionalAggregatorInput.send(new GenericMessage<Integer>(1, stubHeaders(1, 2, 1)));
assertTrue(RollbackTxSync.latch.await(20, TimeUnit.SECONDS));
assertThat(RollbackTxSync.latch.await(20, TimeUnit.SECONDS)).isTrue();
//As far as we have been within TX, the message group should still be in the MessageStore
assertEquals(1, this.messageGroupStore.messageGroupSize(1));
assertThat(this.messageGroupStore.messageGroupSize(1)).isEqualTo(1);
}
private Map<String, Object> stubHeaders(int sequenceNumber, int sequenceSize, int correlationId) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,13 +16,8 @@
package org.springframework.integration.jdbc;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@@ -89,7 +84,7 @@ public class DelayerHandlerRescheduleIntegrationTests {
MessageChannel input = context.getBean("input", MessageChannel.class);
MessageGroupStore messageStore = context.getBean("messageStore", MessageGroupStore.class);
assertEquals(0, messageStore.getMessageGroupCount());
assertThat(messageStore.getMessageGroupCount()).isEqualTo(0);
Message<String> message1 = MessageBuilder.withPayload("test1").build();
input.send(message1);
input.send(MessageBuilder.withPayload("test2").build());
@@ -107,42 +102,43 @@ public class DelayerHandlerRescheduleIntegrationTests {
fail("IllegalStateException expected");
}
catch (Exception e) {
assertTrue(e instanceof IllegalStateException);
assertTrue(e.getMessage().contains("BeanFactory not initialized or already closed - call 'refresh'"));
assertThat(e instanceof IllegalStateException).isTrue();
assertThat(e.getMessage().contains("BeanFactory not initialized or already closed - call 'refresh'"))
.isTrue();
}
String delayerMessageGroupId = UUIDConverter.getUUID(DELAYER_ID + ".messageGroupId").toString();
assertEquals(1, messageStore.getMessageGroupCount());
assertEquals(delayerMessageGroupId, messageStore.iterator().next().getGroupId());
assertEquals(2, messageStore.messageGroupSize(delayerMessageGroupId));
assertEquals(2, messageStore.getMessageCountForAllMessageGroups());
assertThat(messageStore.getMessageGroupCount()).isEqualTo(1);
assertThat(messageStore.iterator().next().getGroupId()).isEqualTo(delayerMessageGroupId);
assertThat(messageStore.messageGroupSize(delayerMessageGroupId)).isEqualTo(2);
assertThat(messageStore.getMessageCountForAllMessageGroups()).isEqualTo(2);
MessageGroup messageGroup = messageStore.getMessageGroup(delayerMessageGroupId);
// Ensure that with the lazyLoadMessageGroups = false the MessageStore doesn't return PersistentMessageGroup
assertThat(messageGroup, instanceOf(SimpleMessageGroup.class));
assertThat(messageGroup).isInstanceOf(SimpleMessageGroup.class);
Message<?> messageInStore = messageGroup.getMessages().iterator().next();
Object payload = messageInStore.getPayload();
//INT-3049
assertTrue(payload instanceof DelayHandler.DelayedMessageWrapper);
assertEquals(message1, ((DelayHandler.DelayedMessageWrapper) payload).getOriginal());
assertThat(payload instanceof DelayHandler.DelayedMessageWrapper).isTrue();
assertThat(((DelayHandler.DelayedMessageWrapper) payload).getOriginal()).isEqualTo(message1);
context.refresh();
PollableChannel output = context.getBean("output", PollableChannel.class);
Message<?> message = output.receive(20000);
assertNotNull(message);
assertThat(message).isNotNull();
Object payload1 = message.getPayload();
message = output.receive(20000);
assertNotNull(message);
assertThat(message).isNotNull();
Object payload2 = message.getPayload();
assertNotSame(payload1, payload2);
assertThat(payload2).isNotSameAs(payload1);
assertEquals(1, messageStore.getMessageGroupCount());
assertEquals(0, messageStore.messageGroupSize(delayerMessageGroupId));
assertThat(messageStore.getMessageGroupCount()).isEqualTo(1);
assertThat(messageStore.messageGroupSize(delayerMessageGroupId)).isEqualTo(0);
context.close();
}
@@ -154,22 +150,22 @@ public class DelayerHandlerRescheduleIntegrationTests {
MessageGroupStore messageStore = context.getBean("messageStore", MessageGroupStore.class);
String delayerMessageGroupId = UUIDConverter.getUUID("transactionalDelayer.messageGroupId").toString();
assertEquals(0, messageStore.messageGroupSize(delayerMessageGroupId));
assertThat(messageStore.messageGroupSize(delayerMessageGroupId)).isEqualTo(0);
input.send(MessageBuilder.withPayload("test").build());
Thread.sleep(1000);
assertEquals(1, messageStore.messageGroupSize(delayerMessageGroupId));
assertThat(messageStore.messageGroupSize(delayerMessageGroupId)).isEqualTo(1);
//To check that 'rescheduling' works in the transaction boundaries too
context.close();
context.refresh();
assertTrue(RollbackTxSync.latch.await(20, TimeUnit.SECONDS));
assertThat(RollbackTxSync.latch.await(20, TimeUnit.SECONDS)).isTrue();
//On transaction rollback the delayed Message should remain in the persistent MessageStore
assertEquals(1, messageStore.messageGroupSize(delayerMessageGroupId));
assertThat(messageStore.messageGroupSize(delayerMessageGroupId)).isEqualTo(1);
context.close();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,8 +16,7 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.sql.Types;
@@ -45,9 +44,9 @@ public class ExpressionEvaluatingSqlParameterSourceFactoryTests {
factory.setBeanFactory(mock(BeanFactory.class));
factory.afterPropertiesSet();
SqlParameterSource source = factory.createParameterSource(null);
assertTrue(source.hasValue("foo"));
assertEquals("bar", source.getValue("foo"));
assertEquals(JdbcUtils.TYPE_UNKNOWN, source.getSqlType("foo"));
assertThat(source.hasValue("foo")).isTrue();
assertThat(source.getValue("foo")).isEqualTo("bar");
assertThat(source.getSqlType("foo")).isEqualTo(JdbcUtils.TYPE_UNKNOWN);
}
@Test
@@ -55,9 +54,9 @@ public class ExpressionEvaluatingSqlParameterSourceFactoryTests {
factory.setBeanFactory(mock(BeanFactory.class));
factory.afterPropertiesSet();
SqlParameterSource source = factory.createParameterSource(Collections.singletonMap("foo", "bar"));
assertTrue(source.hasValue("foo"));
assertEquals("bar", source.getValue("foo"));
assertEquals(JdbcUtils.TYPE_UNKNOWN, source.getSqlType("foo"));
assertThat(source.hasValue("foo")).isTrue();
assertThat(source.getValue("foo")).isEqualTo("bar");
assertThat(source.getSqlType("foo")).isEqualTo(JdbcUtils.TYPE_UNKNOWN);
}
@Test
@@ -67,9 +66,9 @@ public class ExpressionEvaluatingSqlParameterSourceFactoryTests {
SqlParameterSource source = factory.createParameterSource(Arrays.asList(Collections.singletonMap("foo", "bar"),
Collections.singletonMap("foo", "bucket")));
String expression = "foo";
assertTrue(source.hasValue(expression));
assertEquals("[bar, bucket]", source.getValue(expression).toString());
assertEquals(JdbcUtils.TYPE_UNKNOWN, source.getSqlType(expression));
assertThat(source.hasValue(expression)).isTrue();
assertThat(source.getValue(expression).toString()).isEqualTo("[bar, bucket]");
assertThat(source.getSqlType(expression)).isEqualTo(JdbcUtils.TYPE_UNKNOWN);
}
@Test
@@ -78,9 +77,9 @@ public class ExpressionEvaluatingSqlParameterSourceFactoryTests {
factory.afterPropertiesSet();
SqlParameterSource source = factory.createParameterSource(Collections.singletonMap("foo", "bar"));
// This is an illegal parameter name in Spring JDBC so we'd never get this as input
assertTrue(source.hasValue("foo.toUpperCase()"));
assertEquals("BAR", source.getValue("foo.toUpperCase()"));
assertEquals(JdbcUtils.TYPE_UNKNOWN, source.getSqlType("food"));
assertThat(source.hasValue("foo.toUpperCase()")).isTrue();
assertThat(source.getValue("foo.toUpperCase()")).isEqualTo("BAR");
assertThat(source.getSqlType("food")).isEqualTo(JdbcUtils.TYPE_UNKNOWN);
}
@Test
@@ -89,9 +88,9 @@ public class ExpressionEvaluatingSqlParameterSourceFactoryTests {
factory.setBeanFactory(mock(BeanFactory.class));
factory.afterPropertiesSet();
SqlParameterSource source = factory.createParameterSource(Collections.singletonMap("foo", "bar"));
assertTrue(source.hasValue("spam"));
assertEquals("BAR", source.getValue("spam"));
assertEquals(JdbcUtils.TYPE_UNKNOWN, source.getSqlType("spam"));
assertThat(source.hasValue("spam")).isTrue();
assertThat(source.getValue("spam")).isEqualTo("BAR");
assertThat(source.getSqlType("spam")).isEqualTo(JdbcUtils.TYPE_UNKNOWN);
}
@Test
@@ -101,9 +100,9 @@ public class ExpressionEvaluatingSqlParameterSourceFactoryTests {
factory.setBeanFactory(mock(BeanFactory.class));
factory.afterPropertiesSet();
SqlParameterSource source = factory.createParameterSource(Collections.singletonMap("crap", "bucket"));
assertTrue(source.hasValue("spam"));
assertEquals("BAR", source.getValue("spam"));
assertEquals(JdbcUtils.TYPE_UNKNOWN, source.getSqlType("spam"));
assertThat(source.hasValue("spam")).isTrue();
assertThat(source.getValue("spam")).isEqualTo("BAR");
assertThat(source.getSqlType("spam")).isEqualTo(JdbcUtils.TYPE_UNKNOWN);
}
@Test
@@ -114,9 +113,9 @@ public class ExpressionEvaluatingSqlParameterSourceFactoryTests {
SqlParameterSource source = factory.createParameterSource(Arrays.asList(Collections.singletonMap("foo", "bar"),
Collections.singletonMap("foo", "bucket")));
String expression = "spam";
assertTrue(source.hasValue(expression));
assertEquals("[BAR, BUCKET]", source.getValue(expression).toString());
assertEquals(JdbcUtils.TYPE_UNKNOWN, source.getSqlType("foo"));
assertThat(source.hasValue(expression)).isTrue();
assertThat(source.getValue(expression).toString()).isEqualTo("[BAR, BUCKET]");
assertThat(source.getSqlType("foo")).isEqualTo(JdbcUtils.TYPE_UNKNOWN);
}
@Test
@@ -128,9 +127,9 @@ public class ExpressionEvaluatingSqlParameterSourceFactoryTests {
SqlParameterSource source = factory.createParameterSource(Arrays.asList(Collections.singletonMap("foo", "bar"),
Collections.singletonMap("foo", "bucket")));
String expression = "spam";
assertTrue(source.hasValue(expression));
assertEquals("[BAR, BUCKET]", source.getValue(expression).toString());
assertEquals(Types.SQLXML, source.getSqlType("spam"));
assertThat(source.hasValue(expression)).isTrue();
assertThat(source.getValue(expression).toString()).isEqualTo("[BAR, BUCKET]");
assertThat(source.getSqlType("spam")).isEqualTo(Types.SQLXML);
}
@Test
@@ -142,9 +141,9 @@ public class ExpressionEvaluatingSqlParameterSourceFactoryTests {
SqlParameterSource source = factory.createParameterSource(Arrays.asList(Collections.singletonMap("foo", "bar"),
Collections.singletonMap("foo", "bucket")));
String expression = "spam";
assertTrue(source.hasValue(expression));
assertEquals("[BAR, BUCKET]", source.getValue(expression).toString());
assertEquals(JdbcUtils.TYPE_UNKNOWN, source.getSqlType("spam"));
assertThat(source.hasValue(expression)).isTrue();
assertThat(source.getValue(expression).toString()).isEqualTo("[BAR, BUCKET]");
assertThat(source.getSqlType("spam")).isEqualTo(JdbcUtils.TYPE_UNKNOWN);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,8 +16,7 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import java.util.List;
@@ -74,9 +73,9 @@ public class JdbcMessageHandlerIntegrationTests {
Message<String> message = new GenericMessage<>("foo");
handler.handleMessage(message);
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM FOOS WHERE ID=?", 1);
assertEquals("Wrong id", "1", map.get("ID"));
assertEquals("Wrong status", 0, map.get("STATUS"));
assertEquals("Wrong name", "foo", map.get("NAME"));
assertThat(map.get("ID")).as("Wrong id").isEqualTo("1");
assertThat(map.get("STATUS")).as("Wrong status").isEqualTo(0);
assertThat(map.get("NAME")).as("Wrong name").isEqualTo("foo");
}
@Test
@@ -87,7 +86,7 @@ public class JdbcMessageHandlerIntegrationTests {
Message<String> message = new GenericMessage<>("foo");
handler.handleMessage(message);
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM FOOS WHERE ID=?", 1);
assertEquals("Wrong name", "foo", map.get("NAME"));
assertThat(map.get("NAME")).as("Wrong name").isEqualTo("foo");
}
@Test
@@ -101,11 +100,11 @@ public class JdbcMessageHandlerIntegrationTests {
List<Map<String, Object>> foos = jdbcTemplate.queryForList("SELECT * FROM FOOS ORDER BY id");
assertEquals(3, foos.size());
assertThat(foos.size()).isEqualTo(3);
assertEquals("foo1", foos.get(0).get("NAME"));
assertEquals("foo2", foos.get(1).get("NAME"));
assertEquals("foo3", foos.get(2).get("NAME"));
assertThat(foos.get(0).get("NAME")).isEqualTo("foo1");
assertThat(foos.get(1).get("NAME")).isEqualTo("foo2");
assertThat(foos.get(2).get("NAME")).isEqualTo("foo3");
}
@Test
@@ -121,8 +120,8 @@ public class JdbcMessageHandlerIntegrationTests {
Message<String> message = new GenericMessage<>("foo");
handler.handleMessage(message);
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM FOOS WHERE ID=?", 1);
assertEquals("Wrong name", "foo", map.get("NAME"));
assertTrue(setterInvoked.get());
assertThat(map.get("NAME")).as("Wrong name").isEqualTo("foo");
assertThat(setterInvoked.get()).isTrue();
}
@Test
@@ -140,11 +139,11 @@ public class JdbcMessageHandlerIntegrationTests {
List<Map<String, Object>> foos = jdbcTemplate.queryForList("SELECT * FROM FOOS ORDER BY id");
assertEquals(3, foos.size());
assertThat(foos.size()).isEqualTo(3);
assertEquals("foo1", foos.get(0).get("NAME"));
assertEquals("foo2", foos.get(1).get("NAME"));
assertEquals("foo3", foos.get(2).get("NAME"));
assertThat(foos.get(0).get("NAME")).isEqualTo("foo1");
assertThat(foos.get(1).get("NAME")).isEqualTo("foo2");
assertThat(foos.get(2).get("NAME")).isEqualTo("foo3");
}
@Test
@@ -159,8 +158,8 @@ public class JdbcMessageHandlerIntegrationTests {
.build();
handler.handleMessage(message);
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM FOOS WHERE ID=?", id);
assertEquals("Wrong id", id, map.get("ID"));
assertEquals("Wrong name", "foo", map.get("NAME"));
assertThat(map.get("ID")).as("Wrong id").isEqualTo(id);
assertThat(map.get("NAME")).as("Wrong name").isEqualTo("foo");
}
@Test
@@ -172,8 +171,8 @@ public class JdbcMessageHandlerIntegrationTests {
handler.handleMessage(message);
String id = message.getHeaders().get("business.id").toString();
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM FOOS WHERE ID=?", id);
assertEquals("Wrong id", id, map.get("ID"));
assertEquals("Wrong name", "foo", map.get("NAME"));
assertThat(map.get("ID")).as("Wrong id").isEqualTo(id);
assertThat(map.get("NAME")).as("Wrong name").isEqualTo("foo");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,12 +16,11 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -67,7 +66,8 @@ public class JdbcOutboundGatewayTests {
fail("Expected an IllegalArgumentException to be thrown.");
}
catch (IllegalArgumentException e) {
assertEquals("If you want to set 'maxRows', then you must provide a 'selectQuery'.", e.getMessage());
assertThat(e.getMessage())
.isEqualTo("If you want to set 'maxRows', then you must provide a 'selectQuery'.");
}
dataSource.shutdown();
@@ -81,7 +81,7 @@ public class JdbcOutboundGatewayTests {
new JdbcOutboundGateway(jdbcOperations, "select * from DOES_NOT_EXIST");
}
catch (IllegalArgumentException e) {
Assert.assertEquals("'jdbcOperations' must not be null.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("'jdbcOperations' must not be null.");
return;
}
@@ -99,8 +99,8 @@ public class JdbcOutboundGatewayTests {
fail("Expected an IllegalArgumentException to be thrown.");
}
catch (IllegalArgumentException e) {
Assert.assertEquals("The 'updateQuery' and the 'selectQuery' must not both be null or empty.",
e.getMessage());
assertThat(e.getMessage())
.isEqualTo("The 'updateQuery' and the 'selectQuery' must not both be null or empty.");
}
}
@@ -114,7 +114,7 @@ public class JdbcOutboundGatewayTests {
fail("Expected an IllegalArgumentException to be thrown.");
}
catch (IllegalArgumentException e) {
assertEquals("'maxRows' must not be null.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("'maxRows' must not be null.");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,9 +16,7 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.sql.ResultSet;
@@ -78,13 +76,13 @@ public class JdbcPollingChannelAdapterIntegrationTests {
jdbcTemplate.update("insert into item values(1,2)");
Message<Object> message = adapter.receive();
Object payload = message.getPayload();
assertTrue("Wrong payload type", payload instanceof List<?>);
assertThat(payload instanceof List<?>).as("Wrong payload type").isTrue();
List<?> rows = (List<?>) payload;
assertEquals("Wrong number of elements", 1, rows.size());
assertTrue("Returned row not a map", rows.get(0) instanceof Map<?, ?>);
assertThat(rows.size()).as("Wrong number of elements").isEqualTo(1);
assertThat(rows.get(0) instanceof Map<?, ?>).as("Returned row not a map").isTrue();
Map<?, ?> row = (Map<?, ?>) rows.get(0);
assertEquals("Wrong id", 1, row.get("id"));
assertEquals("Wrong status", 2, row.get("status"));
assertThat(row.get("id")).as("Wrong id").isEqualTo(1);
assertThat(row.get("status")).as("Wrong status").isEqualTo(2);
}
@Test
@@ -117,13 +115,13 @@ public class JdbcPollingChannelAdapterIntegrationTests {
jdbcTemplate.update("insert into item values(1,2)");
Message<Object> message = adapter.receive();
Object payload = message.getPayload();
assertTrue("Wrong payload type", payload instanceof List<?>);
assertThat(payload instanceof List<?>).as("Wrong payload type").isTrue();
List<?> rows = (List<?>) payload;
assertEquals("Wrong number of elements", 1, rows.size());
assertTrue("Returned row not a map", rows.get(0) instanceof Map<?, ?>);
assertThat(rows.size()).as("Wrong number of elements").isEqualTo(1);
assertThat(rows.get(0) instanceof Map<?, ?>).as("Returned row not a map").isTrue();
Map<?, ?> row = (Map<?, ?>) rows.get(0);
assertEquals("Wrong id", 1, row.get("id"));
assertEquals("Wrong status", 2, row.get("status"));
assertThat(row.get("id")).as("Wrong id").isEqualTo(1);
assertThat(row.get("status")).as("Wrong status").isEqualTo(2);
}
@Test
@@ -134,11 +132,11 @@ public class JdbcPollingChannelAdapterIntegrationTests {
Message<Object> message = adapter.receive();
Object payload = message.getPayload();
List<?> rows = (List<?>) payload;
assertEquals("Wrong number of elements", 1, rows.size());
assertTrue("Wrong payload type", rows.get(0) instanceof Item);
assertThat(rows.size()).as("Wrong number of elements").isEqualTo(1);
assertThat(rows.get(0) instanceof Item).as("Wrong payload type").isTrue();
Item item = (Item) rows.get(0);
assertEquals("Wrong id", 1, item.getId());
assertEquals("Wrong status", 2, item.getStatus());
assertThat(item.getId()).as("Wrong id").isEqualTo(1);
assertThat(item.getStatus()).as("Wrong status").isEqualTo(2);
}
@Test
@@ -156,17 +154,17 @@ public class JdbcPollingChannelAdapterIntegrationTests {
Message<Object> message = adapter.receive();
Object payload = message.getPayload();
List<?> rows = (List<?>) payload;
assertEquals("Wrong number of elements", 2, rows.size());
assertTrue("Wrong payload type", rows.get(0) instanceof Item);
assertThat(rows.size()).as("Wrong number of elements").isEqualTo(2);
assertThat(rows.get(0) instanceof Item).as("Wrong payload type").isTrue();
Item item = (Item) rows.get(0);
assertEquals("Wrong id", 1, item.getId());
assertEquals("Wrong status", 2, item.getStatus());
assertThat(item.getId()).as("Wrong id").isEqualTo(1);
assertThat(item.getStatus()).as("Wrong status").isEqualTo(2);
int countOfStatusTwo = jdbcTemplate.queryForObject("select count(*) from item where status = 2", Integer.class);
assertEquals("Status not updated incorrect number of rows with status 2", 0, countOfStatusTwo);
assertThat(countOfStatusTwo).as("Status not updated incorrect number of rows with status 2").isEqualTo(0);
int countOfStatusTen = jdbcTemplate.queryForObject("select count(*) from item where status = 10", Integer.class);
assertEquals("Status not updated incorrect number of rows with status 10", 2, countOfStatusTen);
assertThat(countOfStatusTen).as("Status not updated incorrect number of rows with status 10").isEqualTo(2);
}
@Test
@@ -185,17 +183,17 @@ public class JdbcPollingChannelAdapterIntegrationTests {
Message<Object> message = adapter.receive();
Object payload = message.getPayload();
List<?> rows = (List<?>) payload;
assertEquals("Wrong number of elements", 2, rows.size());
assertTrue("Wrong payload type", rows.get(0) instanceof Item);
assertThat(rows.size()).as("Wrong number of elements").isEqualTo(2);
assertThat(rows.get(0) instanceof Item).as("Wrong payload type").isTrue();
Item item = (Item) rows.get(0);
assertEquals("Wrong id", 1, item.getId());
assertEquals("Wrong status", 2, item.getStatus());
assertThat(item.getId()).as("Wrong id").isEqualTo(1);
assertThat(item.getStatus()).as("Wrong status").isEqualTo(2);
int countOfStatusTwo = jdbcTemplate.queryForObject("select count(*) from item where status = 2", Integer.class);
assertEquals("Status not updated incorrect number of rows with status 2", 0, countOfStatusTwo);
assertThat(countOfStatusTwo).as("Status not updated incorrect number of rows with status 2").isEqualTo(0);
int countOfStatusTen = jdbcTemplate.queryForObject("select count(*) from item where status = 10", Integer.class);
assertEquals("Status not updated incorrect number of rows with status 10", 2, countOfStatusTen);
assertThat(countOfStatusTen).as("Status not updated incorrect number of rows with status 10").isEqualTo(2);
}
@Test
@@ -215,17 +213,17 @@ public class JdbcPollingChannelAdapterIntegrationTests {
Message<Object> message = adapter.receive();
Object payload = message.getPayload();
List<?> rows = (List<?>) payload;
assertEquals("Wrong number of elements", 1, rows.size());
assertTrue("Wrong payload type", rows.get(0) instanceof Item);
assertThat(rows.size()).as("Wrong number of elements").isEqualTo(1);
assertThat(rows.get(0) instanceof Item).as("Wrong payload type").isTrue();
Item item = (Item) rows.get(0);
assertEquals("Wrong id", 1, item.getId());
assertEquals("Wrong status", 2, item.getStatus());
assertThat(item.getId()).as("Wrong id").isEqualTo(1);
assertThat(item.getStatus()).as("Wrong status").isEqualTo(2);
int countOfStatusTwo = jdbcTemplate.queryForObject("select count(*) from item where status = 2", Integer.class);
assertEquals("Status not updated incorrect number of rows with status 2", 2, countOfStatusTwo);
assertThat(countOfStatusTwo).as("Status not updated incorrect number of rows with status 2").isEqualTo(2);
int countOfStatusTen = jdbcTemplate.queryForObject("select count(*) from copy where status = 10", Integer.class);
assertEquals("Status not updated incorrect number of rows with status 10", 1, countOfStatusTen);
assertThat(countOfStatusTen).as("Status not updated incorrect number of rows with status 10").isEqualTo(1);
}
@Test
@@ -246,24 +244,24 @@ public class JdbcPollingChannelAdapterIntegrationTests {
Message<Object> message = adapter.receive();
Object payload = message.getPayload();
List<?> rows = (List<?>) payload;
assertEquals("Wrong number of elements", 1, rows.size());
assertTrue("Wrong payload type", rows.get(0) instanceof Item);
assertThat(rows.size()).as("Wrong number of elements").isEqualTo(1);
assertThat(rows.get(0) instanceof Item).as("Wrong payload type").isTrue();
Item item = (Item) rows.get(0);
assertEquals("Wrong id", 2, item.getId());
assertEquals("Wrong status", 2, item.getStatus());
assertThat(item.getId()).as("Wrong id").isEqualTo(2);
assertThat(item.getStatus()).as("Wrong status").isEqualTo(2);
int countOfStatusTwo = jdbcTemplate.queryForObject("select count(*) from item where status = 2", Integer.class);
assertEquals("Status not updated incorrect number of rows with status 2", 0, countOfStatusTwo);
assertThat(countOfStatusTwo).as("Status not updated incorrect number of rows with status 2").isEqualTo(0);
int countOfStatusTen = jdbcTemplate.queryForObject("select count(*) from item where status = 10", Integer.class);
assertEquals("Status not updated incorrect number of rows with status 10", 2, countOfStatusTen);
assertThat(countOfStatusTen).as("Status not updated incorrect number of rows with status 10").isEqualTo(2);
}
@Test
public void testEmptyPoll() {
JdbcPollingChannelAdapter adapter = new JdbcPollingChannelAdapter(embeddedDatabase, "select * from item");
Message<Object> message = adapter.receive();
assertNull("Message received when no rows in table", message);
assertThat(message).as("Message received when no rows in table").isNull();
}
private static class Item {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,11 +16,7 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
@@ -67,7 +63,7 @@ public class MessageGroupQueueTests {
Thread.sleep(1000);
t.interrupt();
Thread.sleep(1000);
assertTrue(exceptionHolder.get() instanceof InterruptedException);
assertThat(exceptionHolder.get() instanceof InterruptedException).isTrue();
}
@Test
@@ -94,7 +90,7 @@ public class MessageGroupQueueTests {
t1.start();
t2.start();
Thread.sleep(1000);
assertTrue(messageHolder.get() instanceof Message);
assertThat(messageHolder.get() instanceof Message).isTrue();
}
@Test
@@ -126,7 +122,7 @@ public class MessageGroupQueueTests {
Thread.sleep(1000);
t2.start();
Thread.sleep(1000);
assertTrue(messageHolder.get().getPayload().equals("Hi"));
assertThat(messageHolder.get().getPayload().equals("Hi")).isTrue();
}
@Test
@@ -176,10 +172,10 @@ public class MessageGroupQueueTests {
Thread.sleep(1000);
t4.start();
Thread.sleep(1000);
assertNotNull(messageHolder1.get());
assertEquals("Hi", messageHolder1.get().getPayload());
assertThat(messageHolder1.get()).isNotNull();
assertThat(messageHolder1.get().getPayload()).isEqualTo("Hi");
Thread.sleep(4000);
assertTrue(messageHolder2.get() == null);
assertThat(messageHolder2.get() == null).isTrue();
}
@Test
@@ -221,9 +217,9 @@ public class MessageGroupQueueTests {
Thread.sleep(100);
t3.start();
Thread.sleep(4000);
assertTrue(booleanHolder1.get());
assertFalse(booleanHolder2.get());
assertFalse(booleanHolder3.get());
assertThat(booleanHolder1.get()).isTrue();
assertThat(booleanHolder2.get()).isFalse();
assertThat(booleanHolder3.get()).isFalse();
}
@Test
@@ -259,8 +255,8 @@ public class MessageGroupQueueTests {
Thread.sleep(1000);
t2.start();
Thread.sleep(1000);
assertTrue(messageHolder.get().getPayload().equals("Hi"));
assertNull(queue.poll(5, TimeUnit.SECONDS));
assertThat(messageHolder.get().getPayload().equals("Hi")).isTrue();
assertThat(queue.poll(5, TimeUnit.SECONDS)).isNull();
}
@Test
@@ -296,7 +292,7 @@ public class MessageGroupQueueTests {
Thread.sleep(1000);
t2.interrupt();
Thread.sleep(1000);
assertTrue(exceptionHolder.get() instanceof InterruptedException);
assertThat(exceptionHolder.get() instanceof InterruptedException).isTrue();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,8 +16,8 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.mock;
import java.util.ArrayList;
@@ -62,7 +62,7 @@ public class StoredProcExecutorTests {
new StoredProcExecutor(null);
}
catch (IllegalArgumentException e) {
assertEquals("dataSource must not be null.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("dataSource must not be null.");
return;
}
@@ -80,8 +80,8 @@ public class StoredProcExecutorTests {
storedProcExecutor.afterPropertiesSet();
}
catch (IllegalArgumentException e) {
assertEquals("You must either provide a "
+ "Stored Procedure Name or a Stored Procedure Name Expression.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("You must either provide a "
+ "Stored Procedure Name or a Stored Procedure Name Expression.");
return;
}
@@ -98,7 +98,7 @@ public class StoredProcExecutorTests {
storedProcExecutor.setStoredProcedureName(" ");
}
catch (IllegalArgumentException e) {
assertEquals("storedProcedureName must not be null and cannot be empty.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("storedProcedureName must not be null and cannot be empty.");
return;
}
@@ -119,7 +119,8 @@ public class StoredProcExecutorTests {
storedProcExecutor.setBeanFactory(mock(BeanFactory.class));
storedProcExecutor.afterPropertiesSet();
assertEquals("headers['stored_procedure_name']", storedProcExecutor.getStoredProcedureNameExpressionAsString());
assertThat(storedProcExecutor.getStoredProcedureNameExpressionAsString())
.isEqualTo("headers['stored_procedure_name']");
}
@Test
@@ -132,8 +133,8 @@ public class StoredProcExecutorTests {
storedProcExecutor.setBeanFactory(mock(BeanFactory.class));
storedProcExecutor.afterPropertiesSet();
assertEquals("123", storedProcExecutor.getStoredProcedureName());
assertEquals("123", storedProcExecutor.getStoredProcedureNameExpressionAsString());
assertThat(storedProcExecutor.getStoredProcedureName()).isEqualTo("123");
assertThat(storedProcExecutor.getStoredProcedureNameExpressionAsString()).isEqualTo("123");
}
@Test
@@ -146,7 +147,7 @@ public class StoredProcExecutorTests {
storedProcExecutor.setReturningResultSetRowMappers(null);
}
catch (IllegalArgumentException e) {
assertEquals("returningResultSetRowMappers must not be null.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("returningResultSetRowMappers must not be null.");
return;
}
@@ -167,7 +168,7 @@ public class StoredProcExecutorTests {
storedProcExecutor.setReturningResultSetRowMappers(rowmappers);
}
catch (IllegalArgumentException e) {
assertEquals("The provided map cannot contain null values.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("The provided map cannot contain null values.");
return;
}
@@ -198,7 +199,7 @@ public class StoredProcExecutorTests {
storedProcExecutor.setSqlParameterSourceFactory(null);
}
catch (IllegalArgumentException e) {
assertEquals("sqlParameterSourceFactory must not be null.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("sqlParameterSourceFactory must not be null.");
return;
}
@@ -219,7 +220,7 @@ public class StoredProcExecutorTests {
storedProcExecutor.setSqlParameters(sqlParameters);
}
catch (IllegalArgumentException e) {
assertEquals("The provided list (sqlParameters) cannot contain null values.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("The provided list (sqlParameters) cannot contain null values.");
return;
}
@@ -239,7 +240,7 @@ public class StoredProcExecutorTests {
storedProcExecutor.setSqlParameters(sqlParameters);
}
catch (IllegalArgumentException e) {
assertEquals("sqlParameters must not be null or empty.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("sqlParameters must not be null or empty.");
return;
}
@@ -257,7 +258,7 @@ public class StoredProcExecutorTests {
storedProcExecutor.setSqlParameters(null);
}
catch (IllegalArgumentException e) {
assertEquals("sqlParameters must not be null or empty.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("sqlParameters must not be null or empty.");
return;
}
@@ -278,7 +279,7 @@ public class StoredProcExecutorTests {
storedProcExecutor.setProcedureParameters(procedureParameters);
}
catch (IllegalArgumentException e) {
assertEquals("The provided list (procedureParameters) cannot contain null values.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("The provided list (procedureParameters) cannot contain null values.");
return;
}
@@ -298,7 +299,7 @@ public class StoredProcExecutorTests {
storedProcExecutor.setProcedureParameters(procedureParameters);
}
catch (IllegalArgumentException e) {
assertEquals("procedureParameters must not be null or empty.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("procedureParameters must not be null or empty.");
return;
}
@@ -316,7 +317,7 @@ public class StoredProcExecutorTests {
storedProcExecutor.setProcedureParameters(null);
}
catch (IllegalArgumentException e) {
assertEquals("procedureParameters must not be null or empty.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("procedureParameters must not be null or empty.");
return;
}
@@ -358,7 +359,9 @@ public class StoredProcExecutorTests {
.build());
}
catch (IllegalArgumentException e) {
assertEquals("Unable to resolve Stored Procedure/Function name for the provided Expression 'headers['stored_procedure_name']'.", e.getMessage());
assertThat(e.getMessage())
.isEqualTo("Unable to resolve Stored Procedure/Function name for the provided Expression " +
"'headers['stored_procedure_name']'.");
return;
}
@@ -395,9 +398,9 @@ public class StoredProcExecutorTests {
LOGGER.info(stats);
LOGGER.info(stats.totalLoadTime() / 1000 / 1000);
assertEquals(stats.hitCount(), 2);
assertEquals(stats.missCount(), 1);
assertEquals(stats.loadCount(), 1);
assertThat(2).isEqualTo(stats.hitCount());
assertThat(1).isEqualTo(stats.missCount());
assertThat(1).isEqualTo(stats.loadCount());
}
@@ -430,7 +433,7 @@ public class StoredProcExecutorTests {
final CacheStats stats = (CacheStats) storedProcExecutor.getJdbcCallOperationsCacheStatistics();
LOGGER.info(stats);
assertEquals("Expected a cache misscount of 10", 10, stats.missCount());
assertThat(stats.missCount()).as("Expected a cache misscount of 10").isEqualTo(10);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2017 the original author or authors.
* Copyright 2015-2019 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,10 +16,7 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.sql.Types;
import java.util.ArrayList;
@@ -29,7 +26,6 @@ import java.util.List;
import javax.sql.DataSource;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -80,16 +76,17 @@ public class StoredProcJavaConfigTests {
@Test
public void test() {
Message<?> received = fooChannel.receive(10000);
assertNotNull(received);
assertThat(received).isNotNull();
Collection<?> primes = (Collection<?>) received.getPayload();
assertThat(primes, Matchers.<Object>contains(2, 3, 5, 7));
assertThat(primes).containsExactly(2, 3, 5, 7);
received = fooChannel.receive(100);
// verify maxMessagesPerPoll == 1
assertNull(received);
assertThat(received).isNull();
MessagingTemplate template = new MessagingTemplate(this.control);
template.convertAndSend("@'storedProcJavaConfigTests.Config.storedProc.inboundChannelAdapter'.stop()");
assertFalse(template.convertSendAndReceive(
"@'storedProcJavaConfigTests.Config.storedProc.inboundChannelAdapter'.isRunning()", Boolean.class));
assertThat(template.convertSendAndReceive(
"@'storedProcJavaConfigTests.Config.storedProc.inboundChannelAdapter'.isRunning()", Boolean.class))
.isFalse();
}
@Configuration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,8 +16,7 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.Collection;
@@ -66,7 +65,7 @@ public class StoredProcJmxManagedBeanTests {
public void testCollectJmxAttributes() throws Exception {
final List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null);
assertEquals(1, servers.size());
assertThat(servers.size()).isEqualTo(1);
final MBeanServer server = servers.iterator().next();
@@ -76,34 +75,34 @@ public class StoredProcJmxManagedBeanTests {
ObjectName.getInstance(
"org.springframework.integration.jdbc.test:name=outboundChannelAdapter.adapter.storedProcExecutor,*"),
null);
assertEquals(1, messageHandlerObjectNames.size());
assertThat(messageHandlerObjectNames.size()).isEqualTo(1);
ObjectName messageHandlerObjectName = messageHandlerObjectNames.iterator().next();
Map<String, Object> messageHandlerCacheStatistics = (Map<String, Object>) server
.getAttribute(messageHandlerObjectName, "JdbcCallOperationsCacheStatisticsAsMap");
assertEquals(11, messageHandlerCacheStatistics.size());
assertThat(messageHandlerCacheStatistics.size()).isEqualTo(11);
assertEquals(0L, messageHandlerCacheStatistics.get("hitCount"));
assertEquals(0L, messageHandlerCacheStatistics.get("loadCount"));
assertEquals(0L, messageHandlerCacheStatistics.get("loadExceptionCount"));
assertEquals(0L, messageHandlerCacheStatistics.get("loadSuccessCount"));
assertEquals(0L, messageHandlerCacheStatistics.get("missCount"));
assertThat(messageHandlerCacheStatistics.get("hitCount")).isEqualTo(0L);
assertThat(messageHandlerCacheStatistics.get("loadCount")).isEqualTo(0L);
assertThat(messageHandlerCacheStatistics.get("loadExceptionCount")).isEqualTo(0L);
assertThat(messageHandlerCacheStatistics.get("loadSuccessCount")).isEqualTo(0L);
assertThat(messageHandlerCacheStatistics.get("missCount")).isEqualTo(0L);
// StoredProcOutboundGateway
final Set<ObjectName> storedProcOutboundGatewayObjectNames = server.queryNames(ObjectName
.getInstance("org.springframework.integration.jdbc.test:name=my gateway.storedProcExecutor,*"), null);
assertEquals(1, storedProcOutboundGatewayObjectNames.size());
assertThat(storedProcOutboundGatewayObjectNames.size()).isEqualTo(1);
ObjectName storedProcOutboundGatewayObjectName = storedProcOutboundGatewayObjectNames.iterator().next();
Map<String, Object> storedProcOutboundGatewayCacheStatistics = (Map<String, Object>) server
.getAttribute(storedProcOutboundGatewayObjectName, "JdbcCallOperationsCacheStatisticsAsMap");
assertEquals(11, messageHandlerCacheStatistics.size());
assertThat(messageHandlerCacheStatistics.size()).isEqualTo(11);
assertEquals(0L, storedProcOutboundGatewayCacheStatistics.get("hitCount"));
assertEquals(0L, storedProcOutboundGatewayCacheStatistics.get("loadCount"));
assertEquals(0L, storedProcOutboundGatewayCacheStatistics.get("loadExceptionCount"));
assertEquals(0L, storedProcOutboundGatewayCacheStatistics.get("loadSuccessCount"));
assertEquals(0L, storedProcOutboundGatewayCacheStatistics.get("missCount"));
assertThat(storedProcOutboundGatewayCacheStatistics.get("hitCount")).isEqualTo(0L);
assertThat(storedProcOutboundGatewayCacheStatistics.get("loadCount")).isEqualTo(0L);
assertThat(storedProcOutboundGatewayCacheStatistics.get("loadExceptionCount")).isEqualTo(0L);
assertThat(storedProcOutboundGatewayCacheStatistics.get("loadSuccessCount")).isEqualTo(0L);
assertThat(storedProcOutboundGatewayCacheStatistics.get("missCount")).isEqualTo(0L);
// StoredProcPollingChannelAdapter
@@ -111,19 +110,19 @@ public class StoredProcJmxManagedBeanTests {
ObjectName.getInstance(
"org.springframework.integration.jdbc.test:name=inbound-channel-adapter.storedProcExecutor,*"),
null);
assertEquals(1, storedProcPollingChannelAdapterObjectNames.size());
assertThat(storedProcPollingChannelAdapterObjectNames.size()).isEqualTo(1);
ObjectName storedProcPollingChannelAdapterObjectName = storedProcPollingChannelAdapterObjectNames.iterator()
.next();
Map<String, Object> storedProcPollingChannelAdapterCacheStatistics = (Map<String, Object>) server
.getAttribute(storedProcPollingChannelAdapterObjectName, "JdbcCallOperationsCacheStatisticsAsMap");
assertEquals(11, storedProcPollingChannelAdapterCacheStatistics.size());
assertThat(storedProcPollingChannelAdapterCacheStatistics.size()).isEqualTo(11);
assertEquals(0L, storedProcPollingChannelAdapterCacheStatistics.get("hitCount"));
assertEquals(0L, storedProcPollingChannelAdapterCacheStatistics.get("loadCount"));
assertEquals(0L, storedProcPollingChannelAdapterCacheStatistics.get("loadExceptionCount"));
assertEquals(0L, storedProcPollingChannelAdapterCacheStatistics.get("loadSuccessCount"));
assertEquals(0L, storedProcPollingChannelAdapterCacheStatistics.get("missCount"));
assertThat(storedProcPollingChannelAdapterCacheStatistics.get("hitCount")).isEqualTo(0L);
assertThat(storedProcPollingChannelAdapterCacheStatistics.get("loadCount")).isEqualTo(0L);
assertThat(storedProcPollingChannelAdapterCacheStatistics.get("loadExceptionCount")).isEqualTo(0L);
assertThat(storedProcPollingChannelAdapterCacheStatistics.get("loadSuccessCount")).isEqualTo(0L);
assertThat(storedProcPollingChannelAdapterCacheStatistics.get("missCount")).isEqualTo(0L);
}
@@ -132,25 +131,25 @@ public class StoredProcJmxManagedBeanTests {
public void testOutboundGateWayJmxAttributes() throws Exception {
final List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null);
assertEquals(1, servers.size());
assertThat(servers.size()).isEqualTo(1);
final MBeanServer server = servers.iterator().next();
final Set<ObjectName> objectNames = server.queryNames(
ObjectName.getInstance("org.springframework.integration.jdbc.test:name=my gateway.storedProcExecutor,*"),
null);
assertEquals(1, objectNames.size());
assertThat(objectNames.size()).isEqualTo(1);
ObjectName name = objectNames.iterator().next();
Map<String, Object> cacheStatistics =
(Map<String, Object>) server.getAttribute(name, "JdbcCallOperationsCacheStatisticsAsMap");
assertEquals(11, cacheStatistics.size());
assertThat(cacheStatistics.size()).isEqualTo(11);
assertEquals(0L, cacheStatistics.get("hitCount"));
assertEquals(0L, cacheStatistics.get("loadCount"));
assertEquals(0L, cacheStatistics.get("loadExceptionCount"));
assertEquals(0L, cacheStatistics.get("loadSuccessCount"));
assertEquals(0L, cacheStatistics.get("missCount"));
assertThat(cacheStatistics.get("hitCount")).isEqualTo(0L);
assertThat(cacheStatistics.get("loadCount")).isEqualTo(0L);
assertThat(cacheStatistics.get("loadExceptionCount")).isEqualTo(0L);
assertThat(cacheStatistics.get("loadSuccessCount")).isEqualTo(0L);
assertThat(cacheStatistics.get("missCount")).isEqualTo(0L);
userService.createUser(new User("myUsername", "myPassword", "myEmail"));
@@ -160,19 +159,19 @@ public class StoredProcJmxManagedBeanTests {
Message<Collection<User>> message = received.get(0);
assertNotNull(message);
assertNotNull(message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isNotNull();
Map<String, Object> cacheStatistics2 =
(Map<String, Object>) server.getAttribute(name, "JdbcCallOperationsCacheStatisticsAsMap");
assertEquals(11, cacheStatistics2.size());
assertThat(cacheStatistics2.size()).isEqualTo(11);
assertEquals(0L, cacheStatistics2.get("hitCount"));
assertEquals(1L, cacheStatistics2.get("loadCount"));
assertEquals(0L, cacheStatistics2.get("loadExceptionCount"));
assertEquals(1L, cacheStatistics2.get("loadSuccessCount"));
assertEquals(1L, cacheStatistics2.get("missCount"));
assertThat(cacheStatistics2.get("hitCount")).isEqualTo(0L);
assertThat(cacheStatistics2.get("loadCount")).isEqualTo(1L);
assertThat(cacheStatistics2.get("loadExceptionCount")).isEqualTo(0L);
assertThat(cacheStatistics2.get("loadSuccessCount")).isEqualTo(1L);
assertThat(cacheStatistics2.get("missCount")).isEqualTo(1L);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,7 +16,7 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import java.sql.SQLException;
@@ -86,9 +86,9 @@ public class StoredProcMessageHandlerDerbyIntegrationTests {
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM USERS WHERE USERNAME=?", "username");
assertEquals("Wrong username", "username", map.get("USERNAME"));
assertEquals("Wrong password", "password", map.get("PASSWORD"));
assertEquals("Wrong email", "email", map.get("EMAIL"));
assertThat(map.get("USERNAME")).as("Wrong username").isEqualTo("username");
assertThat(map.get("PASSWORD")).as("Wrong password").isEqualTo("password");
assertThat(map.get("EMAIL")).as("Wrong email").isEqualTo("email");
}
@Test
@@ -113,9 +113,9 @@ public class StoredProcMessageHandlerDerbyIntegrationTests {
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM USERS WHERE USERNAME=?", "username");
assertEquals("Wrong username", "username", map.get("USERNAME"));
assertEquals("Wrong password", "password", map.get("PASSWORD"));
assertEquals("Wrong email", "email", map.get("EMAIL"));
assertThat(map.get("USERNAME")).as("Wrong username").isEqualTo("username");
assertThat(map.get("PASSWORD")).as("Wrong password").isEqualTo("password");
assertThat(map.get("EMAIL")).as("Wrong email").isEqualTo("email");
}
@Test
@@ -140,9 +140,9 @@ public class StoredProcMessageHandlerDerbyIntegrationTests {
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM USERS WHERE USERNAME=?", "username");
assertEquals("Wrong username", "username", map.get("USERNAME"));
assertEquals("Wrong password", "password", map.get("PASSWORD"));
assertEquals("Wrong email", "email", map.get("EMAIL"));
assertThat(map.get("USERNAME")).as("Wrong username").isEqualTo("username");
assertThat(map.get("PASSWORD")).as("Wrong password").isEqualTo("password");
assertThat(map.get("EMAIL")).as("Wrong email").isEqualTo("email");
}
@Test
@@ -169,9 +169,9 @@ public class StoredProcMessageHandlerDerbyIntegrationTests {
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM USERS WHERE USERNAME=?", "ERIC.CARTMAN");
assertEquals("Wrong username", "ERIC.CARTMAN", map.get("USERNAME"));
assertEquals("Wrong password", "C4RTM4N", map.get("PASSWORD"));
assertEquals("Wrong email", "ERIC@CARTMAN.COM", map.get("EMAIL"));
assertThat(map.get("USERNAME")).as("Wrong username").isEqualTo("ERIC.CARTMAN");
assertThat(map.get("PASSWORD")).as("Wrong password").isEqualTo("C4RTM4N");
assertThat(map.get("EMAIL")).as("Wrong email").isEqualTo("ERIC@CARTMAN.COM");
}
@Test
@@ -199,9 +199,9 @@ public class StoredProcMessageHandlerDerbyIntegrationTests {
Map<String, Object> map = jdbcTemplate.queryForMap("SELECT * FROM USERS WHERE USERNAME=?", "1234_Eric.Cartman");
assertEquals("Wrong username", "1234_Eric.Cartman", map.get("USERNAME"));
assertEquals("Wrong password", "static_password", map.get("PASSWORD"));
assertEquals("Wrong email", "static_email", map.get("EMAIL"));
assertThat(map.get("USERNAME")).as("Wrong username").isEqualTo("1234_Eric.Cartman");
assertThat(map.get("PASSWORD")).as("Wrong password").isEqualTo("static_password");
assertThat(map.get("EMAIL")).as("Wrong email").isEqualTo("static_email");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,7 +16,7 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
@@ -61,9 +61,9 @@ public class StoredProcOutboundChannelAdapterWithinChainTests {
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * FROM USERS WHERE USERNAME=?", "username");
assertEquals("Wrong username", "username", map.get("USERNAME"));
assertEquals("Wrong password", "password", map.get("PASSWORD"));
assertEquals("Wrong email", "email", map.get("EMAIL"));
assertThat(map.get("USERNAME")).as("Wrong username").isEqualTo("username");
assertThat(map.get("PASSWORD")).as("Wrong password").isEqualTo("password");
assertThat(map.get("EMAIL")).as("Wrong email").isEqualTo("email");
// embeddedDatabase can be in working state. So other tests with the same embeddedDatabase beanId, type and init scripts
// may be failed with Exception like: object in the DB already exists
this.context.close();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,9 +16,7 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.Collection;
@@ -85,18 +83,18 @@ public class StoredProcOutboundGatewayWithNamespaceIntegrationTests {
Message<Collection<User>> message = received.get(0);
assertNotNull(message);
assertNotNull(message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isNotNull();
Collection<User> allUsers = message.getPayload();
assertTrue(allUsers.size() == 1);
assertThat(allUsers.size() == 1).isTrue();
User userFromDb = allUsers.iterator().next();
assertEquals("Wrong username", "myUsername", userFromDb.getUsername());
assertEquals("Wrong password", "myPassword", userFromDb.getPassword());
assertEquals("Wrong email", "'myEmail'", userFromDb.getEmail());
assertThat(userFromDb.getUsername()).as("Wrong username").isEqualTo("myUsername");
assertThat(userFromDb.getPassword()).as("Wrong password").isEqualTo("myPassword");
assertThat(userFromDb.getEmail()).as("Wrong email").isEqualTo("'myEmail'");
}
@@ -110,18 +108,18 @@ public class StoredProcOutboundGatewayWithNamespaceIntegrationTests {
@SuppressWarnings("unchecked")
Message<Collection<User>> message = (Message<Collection<User>>) replyChannel.receive();
assertNotNull(message);
assertNotNull(message.getPayload());
assertThat(message).isNotNull();
assertThat(message.getPayload()).isNotNull();
Collection<User> allUsers = message.getPayload();
assertTrue(allUsers.size() == 1);
assertThat(allUsers.size() == 1).isTrue();
User userFromDb = allUsers.iterator().next();
assertEquals("Wrong username", "myUsername", userFromDb.getUsername());
assertEquals("Wrong password", "myPassword", userFromDb.getPassword());
assertEquals("Wrong email", "myEmail", userFromDb.getEmail());
assertThat(userFromDb.getUsername()).as("Wrong username").isEqualTo("myUsername");
assertThat(userFromDb.getPassword()).as("Wrong password").isEqualTo("myPassword");
assertThat(userFromDb.getEmail()).as("Wrong email").isEqualTo("myEmail");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,12 +16,8 @@
package org.springframework.integration.jdbc;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.sql.CallableStatement;
import java.util.Collection;
@@ -30,7 +26,6 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
@@ -115,14 +110,14 @@ public class StoredProcOutboundGatewayWithSpelIntegrationTests {
Message<Collection<User>> message = (Message<Collection<User>>) this.outputChannel.receive(10000);
context.stop();
assertNotNull(message);
assertThat(message).isNotNull();
assertNotNull(message.getPayload());
assertNotNull(message.getPayload() instanceof Collection<?>);
assertThat(message.getPayload()).isNotNull();
assertThat(message.getPayload() instanceof Collection<?>).isNotNull();
Collection<User> allUsers = message.getPayload();
assertTrue(allUsers.size() == 2);
assertThat(allUsers.size() == 2).isTrue();
}
@@ -137,15 +132,15 @@ public class StoredProcOutboundGatewayWithSpelIntegrationTests {
this.channel.send(user1Message);
Message<?> receive = this.startErrorsChannel.receive(10000);
assertNotNull(receive);
assertThat(receive, instanceOf(ErrorMessage.class));
assertThat(receive).isNotNull();
assertThat(receive).isInstanceOf(ErrorMessage.class);
MessageHandlingException exception = (MessageHandlingException) receive.getPayload();
String expectedMessage = "Unable to resolve Stored Procedure/Function name " +
"for the provided Expression 'headers['my_stored_procedure']'.";
String actualMessage = exception.getCause().getMessage();
Assert.assertEquals(expectedMessage, actualMessage);
assertThat(actualMessage).isEqualTo(expectedMessage);
}
@Test
@@ -160,13 +155,13 @@ public class StoredProcOutboundGatewayWithSpelIntegrationTests {
this.getMessageChannel.send(new GenericMessage<String>(messageId));
Message<?> resultMessage = this.output2Channel.receive(10000);
assertNotNull(resultMessage);
assertThat(resultMessage).isNotNull();
Object resultPayload = resultMessage.getPayload();
assertTrue(resultPayload instanceof String);
assertThat(resultPayload instanceof String).isTrue();
Message<?> message = new JsonInboundMessageMapper(String.class, new Jackson2JsonMessageParser())
.toMessage((String) resultPayload);
assertEquals(testMessage.getPayload(), message.getPayload());
assertEquals(testMessage.getHeaders().get("FOO"), message.getHeaders().get("FOO"));
assertThat(message.getPayload()).isEqualTo(testMessage.getPayload());
assertThat(message.getHeaders().get("FOO")).isEqualTo(testMessage.getHeaders().get("FOO"));
Mockito.verify(clobSqlReturnType).getTypeValue(Mockito.any(CallableStatement.class),
Mockito.eq(2), Mockito.eq(JdbcTypesEnum.CLOB.getCode()), Mockito.eq((String) null));
}
@@ -178,7 +173,7 @@ public class StoredProcOutboundGatewayWithSpelIntegrationTests {
fail("ReplyRequiredException expected");
}
catch (Exception e) {
assertThat(e, instanceOf(ReplyRequiredException.class));
assertThat(e).isInstanceOf(ReplyRequiredException.class);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,8 +16,7 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.Collection;
@@ -68,13 +67,13 @@ public class StoredProcOutboundGatewayWithSpringContextIntegrationTests {
Message<Collection<User>> message = received.get(0);
context.stop();
assertNotNull(message);
assertNotNull(message.getPayload());
assertNotNull(message.getPayload() instanceof Collection<?>);
assertThat(message).isNotNull();
assertThat(message.getPayload()).isNotNull();
assertThat(message.getPayload() instanceof Collection<?>).isNotNull();
Collection<User> allUsers = message.getPayload();
assertTrue(allUsers.size() == 1);
assertThat(allUsers.size() == 1).isTrue();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,8 +16,7 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
@@ -60,13 +59,13 @@ public class StoredProcPollingChannelAdapterWithNamespace2IntegrationTests {
Message<List<Integer>> message = received.get(0);
context.stop();
assertNotNull(message);
assertNotNull(message.getPayload());
assertTrue(message.getPayload() instanceof List<?>);
assertThat(message).isNotNull();
assertThat(message.getPayload()).isNotNull();
assertThat(message.getPayload() instanceof List<?>).isTrue();
List<Integer> resultList = message.getPayload();
assertTrue(resultList.size() == 1);
assertThat(resultList.size() == 1).isTrue();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,9 +16,7 @@
package org.springframework.integration.jdbc;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.Collection;
@@ -63,13 +61,13 @@ public class StoredProcPollingChannelAdapterWithNamespaceIntegrationTests {
Message<?> message = received.get(0);
context.stop();
assertNotNull(message);
assertNotNull(message.getPayload());
assertNotNull(message.getPayload() instanceof Collection<?>);
assertThat(message).isNotNull();
assertThat(message.getPayload()).isNotNull();
assertThat(message.getPayload() instanceof Collection<?>).isNotNull();
List<Integer> primeNumbers = (List<Integer>) message.getPayload();
assertThat(primeNumbers, contains(2, 3, 5, 7));
assertThat(primeNumbers).containsExactly(2, 3, 5, 7);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,8 +16,7 @@
package org.springframework.integration.jdbc;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.Collection;
@@ -60,13 +59,13 @@ public class StoredProcPollingChannelAdapterWithSpringContextIntegrationTests {
Message<Collection<Integer>> message = received.get(0);
context.stop();
assertNotNull(message);
assertNotNull(message.getPayload());
assertNotNull(message.getPayload() instanceof Collection<?>);
assertThat(message).isNotNull();
assertThat(message.getPayload()).isNotNull();
assertThat(message.getPayload() instanceof Collection<?>).isNotNull();
Collection<Integer> primeNumbers = message.getPayload();
assertTrue(primeNumbers.size() == 4);
assertThat(primeNumbers.size() == 4).isTrue();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,8 +16,8 @@
package org.springframework.integration.jdbc.config;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import org.junit.Test;
@@ -73,7 +73,10 @@ public class InnerPollerParserTests {
fail("Expected Failure to load ApplicationContext");
}
catch (BeanDefinitionParsingException bdpe) {
assertTrue(bdpe.getMessage().startsWith("Configuration problem: A 'poller' element that provides a 'ref' must have no other attributes."));
assertThat(bdpe.getMessage()
.startsWith("Configuration problem: A 'poller' element that provides a 'ref' must have no other " +
"attributes."))
.isTrue();
}
}
@@ -110,7 +113,9 @@ public class InnerPollerParserTests {
fail("Expected Failure to load ApplicationContext");
}
catch (BeanDefinitionParsingException bdpe) {
assertTrue(bdpe.getMessage().startsWith("Configuration problem: A 'poller' element that provides a 'ref' must have no other attributes."));
assertThat(bdpe.getMessage()
.startsWith("Configuration problem: A 'poller' element that provides a 'ref' must have no other attributes."))
.isTrue();
}
}
@@ -147,7 +152,9 @@ public class InnerPollerParserTests {
fail("Expected Failure to load ApplicationContext");
}
catch (BeanDefinitionParsingException bdpe) {
assertTrue(bdpe.getMessage().startsWith("Configuration problem: A 'poller' element that provides a 'ref' must have no other attributes."));
assertThat(bdpe.getMessage()
.startsWith("Configuration problem: A 'poller' element that provides a 'ref' must have no other attributes."))
.isTrue();
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,8 +16,7 @@
package org.springframework.integration.jdbc.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Collections;
import java.util.List;
@@ -65,11 +64,11 @@ public class JdbcMessageHandlerParserTests {
Message<?> message = MessageBuilder.withPayload("foo").setHeader("business.key", "FOO").build();
channel.send(message);
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
assertEquals("Wrong id", "FOO", map.get("ID"));
assertEquals("Wrong id", "foo", map.get("name"));
assertThat(map.get("ID")).as("Wrong id").isEqualTo("FOO");
assertThat(map.get("name")).as("Wrong id").isEqualTo("foo");
JdbcMessageHandler handler = context.getBean(JdbcMessageHandler.class);
assertEquals(23, TestUtils.getPropertyValue(handler, "order"));
assertEquals(1, adviceCalled);
assertThat(TestUtils.getPropertyValue(handler, "order")).isEqualTo(23);
assertThat(adviceCalled).isEqualTo(1);
}
@Test
@@ -78,19 +77,19 @@ public class JdbcMessageHandlerParserTests {
Message<?> message = MessageBuilder.withPayload("foo").setHeader("$foo_id", "abc").build();
channel.send(message);
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
assertEquals("Wrong id", message.getHeaders().get("$foo_id").toString(), map.get("ID"));
assertEquals("Wrong id", "foo", map.get("name"));
assertThat(map.get("ID")).as("Wrong id").isEqualTo(message.getHeaders().get("$foo_id").toString());
assertThat(map.get("name")).as("Wrong id").isEqualTo("foo");
}
@Test
public void testMapPayloadOutboundChannelAdapter() {
setUp("handlingMapPayloadJdbcOutboundChannelAdapterTest.xml", getClass());
assertTrue(context.containsBean("jdbcAdapter"));
assertThat(context.containsBean("jdbcAdapter")).isTrue();
Message<?> message = MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build();
channel.send(message);
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
assertEquals("Wrong name", "bar", map.get("name"));
assertThat(map.get("ID")).as("Wrong id").isEqualTo(message.getHeaders().getId().toString());
assertThat(map.get("name")).as("Wrong name").isEqualTo("bar");
}
@Test
@@ -99,8 +98,8 @@ public class JdbcMessageHandlerParserTests {
Message<?> message = MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build();
channel.send(message);
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
assertEquals("Wrong name", "bar", map.get("name"));
assertThat(map.get("ID")).as("Wrong id").isEqualTo(message.getHeaders().getId().toString());
assertThat(map.get("name")).as("Wrong name").isEqualTo("bar");
}
@Test
@@ -109,8 +108,8 @@ public class JdbcMessageHandlerParserTests {
Message<?> message = MessageBuilder.withPayload("foo").build();
channel.send(message);
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
assertEquals("Wrong name", "bar", map.get("name"));
assertThat(map.get("ID")).as("Wrong id").isEqualTo(message.getHeaders().getId().toString());
assertThat(map.get("name")).as("Wrong name").isEqualTo("bar");
}
@Test
@@ -127,12 +126,12 @@ public class JdbcMessageHandlerParserTests {
Thread.sleep(100);
result = jdbcTemplate.query("SELECT * from FOOW", new ColumnMapRowMapper());
}
assertTrue(n < 100);
assertThat(n < 100).isTrue();
assertEquals(1, result.size());
assertThat(result.size()).isEqualTo(1);
Map<String, Object> map = result.get(0);
assertEquals("Wrong id", "FOO", map.get("ID"));
assertEquals("Wrong id", "foo", map.get("name"));
assertThat(map.get("ID")).as("Wrong id").isEqualTo("FOO");
assertThat(map.get("name")).as("Wrong id").isEqualTo("foo");
}
@Test
@@ -141,8 +140,8 @@ public class JdbcMessageHandlerParserTests {
Message<?> message = MessageBuilder.withPayload("foo").setHeader("business.key", "FOO").build();
channel.send(message);
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
assertEquals("Wrong id", "FOO", map.get("ID"));
assertEquals("Wrong id", "foo", map.get("name"));
assertThat(map.get("ID")).as("Wrong id").isEqualTo("FOO");
assertThat(map.get("name")).as("Wrong id").isEqualTo("foo");
}
@After

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 the original author or authors.
* Copyright 2016-2019 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,8 +16,7 @@
package org.springframework.integration.jdbc.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.io.InputStream;
@@ -53,14 +52,14 @@ public class JdbcMessageStoreParserTests {
public void testSimpleMessageStoreWithDataSource() {
setUp("defaultJdbcMessageStore.xml", getClass());
MessageStore store = context.getBean("messageStore", MessageStore.class);
assertTrue(store instanceof JdbcMessageStore);
assertThat(store instanceof JdbcMessageStore).isTrue();
}
@Test
public void testSimpleMessageStoreWithTemplate() {
setUp("jdbcOperationsJdbcMessageStore.xml", getClass());
MessageStore store = context.getBean("messageStore", MessageStore.class);
assertTrue(store instanceof JdbcMessageStore);
assertThat(store instanceof JdbcMessageStore).isTrue();
}
@Test
@@ -68,18 +67,18 @@ public class JdbcMessageStoreParserTests {
setUp("serializerJdbcMessageStore.xml", getClass());
MessageStore store = context.getBean("messageStore", MessageStore.class);
Object serializer = TestUtils.getPropertyValue(store, "serializer.serializer");
assertTrue(serializer instanceof EnhancedSerializer);
assertThat(serializer instanceof EnhancedSerializer).isTrue();
Object deserializer = TestUtils.getPropertyValue(store, "deserializer.deserializer");
assertTrue(deserializer instanceof EnhancedSerializer);
assertThat(deserializer instanceof EnhancedSerializer).isTrue();
}
@Test
public void testMessageStoreWithAttributes() {
setUp("soupedUpJdbcMessageStore.xml", getClass());
MessageStore store = context.getBean("messageStore", MessageStore.class);
assertEquals("FOO", ReflectionTestUtils.getField(store, "region"));
assertEquals("BAR_", ReflectionTestUtils.getField(store, "tablePrefix"));
assertEquals(context.getBean(LobHandler.class), ReflectionTestUtils.getField(store, "lobHandler"));
assertThat(ReflectionTestUtils.getField(store, "region")).isEqualTo("FOO");
assertThat(ReflectionTestUtils.getField(store, "tablePrefix")).isEqualTo("BAR_");
assertThat(ReflectionTestUtils.getField(store, "lobHandler")).isEqualTo(context.getBean(LobHandler.class));
}
@After

View File

@@ -16,10 +16,7 @@
package org.springframework.integration.jdbc.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -33,7 +30,6 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.junit.After;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
@@ -77,24 +73,24 @@ public class JdbcOutboundGatewayParserTests {
@Test
public void testMapPayloadMapReply() {
setUp("handlingMapPayloadJdbcOutboundGatewayTest.xml", getClass());
assertTrue(this.context.containsBean("jdbcGateway"));
assertThat(this.context.containsBean("jdbcGateway")).isTrue();
Message<?> message = MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build();
this.channel.send(message);
Message<?> reply = this.messagingTemplate.receive();
assertNotNull(reply);
assertThat(reply).isNotNull();
@SuppressWarnings("unchecked")
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
assertEquals("bar", payload.get("name"));
assertThat(payload.get("name")).isEqualTo("bar");
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
assertEquals("Wrong name", "bar", map.get("name"));
assertThat(map.get("ID")).as("Wrong id").isEqualTo(message.getHeaders().getId().toString());
assertThat(map.get("name")).as("Wrong name").isEqualTo("bar");
JdbcOutboundGateway gateway = context.getBean("jdbcGateway.handler", JdbcOutboundGateway.class);
assertEquals(23, TestUtils.getPropertyValue(gateway, "order"));
Assert.assertTrue(TestUtils.getPropertyValue(gateway, "requiresReply", Boolean.class));
assertEquals(1, adviceCalled);
assertThat(TestUtils.getPropertyValue(gateway, "order")).isEqualTo(23);
assertThat(TestUtils.getPropertyValue(gateway, "requiresReply", Boolean.class)).isTrue();
assertThat(adviceCalled).isEqualTo(1);
}
@Test
@@ -107,15 +103,15 @@ public class JdbcOutboundGatewayParserTests {
this.channel.send(message);
Message<?> reply = this.messagingTemplate.receive();
assertNotNull(reply);
assertThat(reply).isNotNull();
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
Object id = payload.get("ID");
assertNotNull(id);
assertThat(id).isNotNull();
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from BARS");
assertEquals("Wrong id", id, map.get("ID"));
assertEquals("Wrong name", "bar", map.get("name"));
assertThat(map.get("ID")).as("Wrong id").isEqualTo(id);
assertThat(map.get("name")).as("Wrong name").isEqualTo("bar");
this.jdbcTemplate.execute("DELETE FROM BARS");
@@ -133,14 +129,14 @@ public class JdbcOutboundGatewayParserTests {
MessageChannel setterRequest = this.context.getBean("setterRequest", MessageChannel.class);
setterRequest.send(new GenericMessage<>("bar2"));
reply = this.messagingTemplate.receive();
assertNotNull(reply);
assertThat(reply).isNotNull();
payload = (Map<String, ?>) reply.getPayload();
id = payload.get("ID");
assertNotNull(id);
assertThat(id).isNotNull();
map = this.jdbcTemplate.queryForMap("SELECT * from BARS");
assertEquals("Wrong id", id, map.get("ID"));
assertEquals("Wrong name", "bar2", map.get("name"));
assertThat(map.get("ID")).as("Wrong id").isEqualTo(id);
assertThat(map.get("name")).as("Wrong name").isEqualTo("bar2");
verify(logger).debug("Executing prepared SQL statement [insert into bars (status, name) values (0, ?)]");
}
@@ -153,10 +149,10 @@ public class JdbcOutboundGatewayParserTests {
this.channel.send(message);
Message<?> reply = this.messagingTemplate.receive();
assertNotNull(reply);
assertThat(reply).isNotNull();
@SuppressWarnings("unchecked")
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
assertEquals(1, payload.get("updated"));
assertThat(payload.get("updated")).isEqualTo(1);
}
@Test
@@ -180,14 +176,14 @@ public class JdbcOutboundGatewayParserTests {
this.channel.send(message);
Message<?> reply = this.messagingTemplate.receive();
assertNotNull(reply);
assertThat(reply).isNotNull();
@SuppressWarnings("unchecked")
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
assertEquals("bar", payload.get("name"));
assertThat(payload.get("name")).isEqualTo("bar");
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from BAZZ");
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
assertEquals("Wrong name", "bar", map.get("name"));
assertThat(map.get("ID")).as("Wrong id").isEqualTo(message.getHeaders().getId().toString());
assertThat(map.get("name")).as("Wrong name").isEqualTo("bar");
verify(logger).debug("Executing prepared SQL statement [select * from bazz where id=?]");
}
@@ -206,9 +202,9 @@ public class JdbcOutboundGatewayParserTests {
Integer status = (Integer) reply.getPayload().get("status");
String name = (String) reply.getPayload().get("name");
assertEquals("100", id);
assertEquals(Integer.valueOf(3), status);
assertEquals("Cartman", name);
assertThat(id).isEqualTo("100");
assertThat(status).isEqualTo(Integer.valueOf(3));
assertThat(name).isEqualTo("Cartman");
}
@Test
@@ -227,7 +223,7 @@ public class JdbcOutboundGatewayParserTests {
accessor = new DirectFieldAccessor(messagingTemplate);
Long sendTimeout = (Long) accessor.getPropertyValue("sendTimeout");
assertEquals("Wrong sendTimeout", Long.valueOf(444L), sendTimeout);
assertThat(sendTimeout).as("Wrong sendTimeout").isEqualTo(Long.valueOf(444L));
}
@@ -243,7 +239,7 @@ public class JdbcOutboundGatewayParserTests {
source = accessor.getPropertyValue("poller"); //JdbcPollingChannelAdapter
accessor = new DirectFieldAccessor(source);
Integer maxRowsPerPoll = (Integer) accessor.getPropertyValue("maxRows");
assertEquals("maxRowsPerPoll should default to 1", Integer.valueOf(1), maxRowsPerPoll);
assertThat(maxRowsPerPoll).as("maxRowsPerPoll should default to 1").isEqualTo(Integer.valueOf(1));
}
@@ -259,7 +255,7 @@ public class JdbcOutboundGatewayParserTests {
source = accessor.getPropertyValue("poller"); //JdbcPollingChannelAdapter
accessor = new DirectFieldAccessor(source);
Integer maxRowsPerPoll = (Integer) accessor.getPropertyValue("maxRows");
assertEquals("maxRowsPerPoll should default to 10", Integer.valueOf(10), maxRowsPerPoll);
assertThat(maxRowsPerPoll).as("maxRowsPerPoll should default to 10").isEqualTo(Integer.valueOf(10));
}
@Test //INT-1029
@@ -272,16 +268,16 @@ public class JdbcOutboundGatewayParserTests {
MessageChannel channel = this.context.getBean("jdbcOutboundGatewayInsideChain", MessageChannel.class);
assertFalse(TestUtils.getPropertyValue(jdbcMessageHandler, "requiresReply", Boolean.class));
assertThat(TestUtils.getPropertyValue(jdbcMessageHandler, "requiresReply", Boolean.class)).isFalse();
channel.send(MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build());
PollableChannel outbound = this.context.getBean("replyChannel", PollableChannel.class);
Message<?> reply = outbound.receive(10000);
assertNotNull(reply);
assertThat(reply).isNotNull();
@SuppressWarnings("unchecked")
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
assertEquals("bar", payload.get("name"));
assertThat(payload.get("name")).isEqualTo("bar");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,11 +16,7 @@
package org.springframework.integration.jdbc.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import java.util.Map;
@@ -71,7 +67,7 @@ public class JdbcPollingChannelAdapterParserTests {
this.jdbcTemplate.update("insert into item values(1,'',2)");
messagingTemplate.setReceiveTimeout(1);
Message<?> message = messagingTemplate.receive();
assertNull("Message found ", message);
assertThat(message).as("Message found ").isNull();
}
@Test
@@ -79,13 +75,13 @@ public class JdbcPollingChannelAdapterParserTests {
setUp("pollingForMapJdbcInboundChannelAdapterTest.xml", getClass());
this.jdbcTemplate.update("insert into item values(1,'',2)");
Message<?> message = messagingTemplate.receive();
assertNotNull("No message found ", message);
assertTrue("Wrong payload type expected instance of List", message.getPayload() instanceof List<?>);
assertThat(message).as("No message found ").isNotNull();
assertThat(message.getPayload() instanceof List<?>).as("Wrong payload type expected instance of List").isTrue();
MessageHistory history = MessageHistory.read(message);
assertNotNull(history);
assertThat(history).isNotNull();
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "jdbcAdapter", 0);
assertNotNull(componentHistoryRecord);
assertEquals("jdbc:inbound-channel-adapter", componentHistoryRecord.get("type"));
assertThat(componentHistoryRecord).isNotNull();
assertThat(componentHistoryRecord.get("type")).isEqualTo("jdbc:inbound-channel-adapter");
}
@@ -94,10 +90,10 @@ public class JdbcPollingChannelAdapterParserTests {
setUp("pollingForMapJdbcInboundChannelAdapterWithUpdateTest.xml", getClass());
this.jdbcTemplate.update("insert into item values(1,'',2)");
Message<?> message = messagingTemplate.receive();
assertNotNull(message);
assertThat(message).isNotNull();
messagingTemplate.setReceiveTimeout(1);
message = messagingTemplate.receive();
assertNull(message);
assertThat(message).isNull();
}
@Test
@@ -105,10 +101,10 @@ public class JdbcPollingChannelAdapterParserTests {
setUp("pollingForMapJdbcInboundChannelAdapterWithNestedUpdateTest.xml", getClass());
this.jdbcTemplate.update("insert into item values(1,'',2)");
Message<?> message = messagingTemplate.receive();
assertNotNull(message);
assertThat(message).isNotNull();
messagingTemplate.setReceiveTimeout(1);
message = messagingTemplate.receive();
assertNull(message);
assertThat(message).isNull();
}
@Test
@@ -116,7 +112,7 @@ public class JdbcPollingChannelAdapterParserTests {
setUp("pollingWithJdbcOperationsJdbcInboundChannelAdapterTest.xml", getClass());
this.jdbcTemplate.update("insert into item values(1,'',2)");
Message<?> message = messagingTemplate.receive();
assertNotNull(message);
assertThat(message).isNotNull();
}
@Test
@@ -124,10 +120,10 @@ public class JdbcPollingChannelAdapterParserTests {
setUp("pollingWithParameterSourceJdbcInboundChannelAdapterTest.xml", getClass());
this.jdbcTemplate.update("insert into item values(1,'',2)");
Message<?> message = messagingTemplate.receive();
assertNotNull(message);
assertThat(message).isNotNull();
List<Map<String, Object>> list = jdbcTemplate.queryForList("SELECT * FROM item WHERE status=1");
assertEquals(1, list.size());
assertEquals("BAR", list.get(0).get("NAME"));
assertThat(list.size()).isEqualTo(1);
assertThat(list.get(0).get("NAME")).isEqualTo("BAR");
}
@Test
@@ -135,13 +131,13 @@ public class JdbcPollingChannelAdapterParserTests {
setUp("pollingWithSelectParameterSourceJdbcInboundChannelAdapterTest.xml", getClass());
this.jdbcTemplate.update("insert into item values(1,'',42)");
Message<?> message = messagingTemplate.receive();
assertNotNull(message);
assertEquals(42, ((Map<?, ?>) ((List<?>) message.getPayload()).get(0)).get("STATUS"));
assertThat(message).isNotNull();
assertThat(((Map<?, ?>) ((List<?>) message.getPayload()).get(0)).get("STATUS")).isEqualTo(42);
this.jdbcTemplate.update("insert into item values(2,'',84)");
this.appCtx.getBean(Status.class).which = 84;
message = messagingTemplate.receive();
assertNotNull(message);
assertEquals(84, ((Map<?, ?>) ((List<?>) message.getPayload()).get(0)).get("STATUS"));
assertThat(message).isNotNull();
assertThat(((Map<?, ?>) ((List<?>) message.getPayload()).get(0)).get("STATUS")).isEqualTo(84);
}
@Test
@@ -149,7 +145,7 @@ public class JdbcPollingChannelAdapterParserTests {
setUp("pollingWithParametersForMapJdbcInboundChannelAdapterTest.xml", getClass());
this.jdbcTemplate.update("insert into item values(1,'',2)");
Message<?> message = messagingTemplate.receive();
assertNotNull(message);
assertThat(message).isNotNull();
}
@Test
@@ -166,9 +162,9 @@ public class JdbcPollingChannelAdapterParserTests {
while (count < 4) {
@SuppressWarnings("unchecked")
Message<List<?>> message = (Message<List<?>>) messagingTemplate.receive();
assertNotNull(message);
assertThat(message).isNotNull();
int payloadSize = message.getPayload().size();
assertTrue(payloadSize <= 2);
assertThat(payloadSize <= 2).isTrue();
count += payloadSize;
}
}
@@ -178,7 +174,7 @@ public class JdbcPollingChannelAdapterParserTests {
setUp("autoChannelJdbcPollingChannelAdapterParserTests-context.xml", getClass());
MessageChannel autoChannel = appCtx.getBean("autoChannel", MessageChannel.class);
SourcePollingChannelAdapter autoChannelAdapter = appCtx.getBean("autoChannel.adapter", SourcePollingChannelAdapter.class);
assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel"));
assertThat(TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")).isSameAs(autoChannel);
}
@After

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2019 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,10 +16,8 @@
package org.springframework.integration.jdbc.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.sql.Types;
@@ -31,8 +29,8 @@ public class JdbcTypesEnumTests {
public void testGetCode() {
JdbcTypesEnum jdbcTypesEnum = JdbcTypesEnum.convertToJdbcTypesEnum("VARCHAR");
assertNotNull("Expected not null jdbcTypesEnum.", jdbcTypesEnum);
assertEquals(Integer.valueOf(Types.VARCHAR), Integer.valueOf(jdbcTypesEnum.getCode()));
assertThat(jdbcTypesEnum).as("Expected not null jdbcTypesEnum.").isNotNull();
assertThat(Integer.valueOf(jdbcTypesEnum.getCode())).isEqualTo(Integer.valueOf(Types.VARCHAR));
}
@@ -40,7 +38,7 @@ public class JdbcTypesEnumTests {
public void testConvertToJdbcTypesEnumWithInvalidParameter() {
JdbcTypesEnum jdbcTypesEnum = JdbcTypesEnum.convertToJdbcTypesEnum("KENNY4JDBC");
assertNull("Expected null return value.", jdbcTypesEnum);
assertThat(jdbcTypesEnum).as("Expected null return value.").isNull();
}
@@ -51,7 +49,7 @@ public class JdbcTypesEnumTests {
JdbcTypesEnum.convertToJdbcTypesEnum(null);
}
catch (IllegalArgumentException e) {
assertEquals("Parameter sqlTypeAsString, must not be null nor empty", e.getMessage());
assertThat(e.getMessage()).isEqualTo("Parameter sqlTypeAsString, must not be null nor empty");
return;
}
@@ -66,7 +64,7 @@ public class JdbcTypesEnumTests {
JdbcTypesEnum.convertToJdbcTypesEnum(" ");
}
catch (IllegalArgumentException e) {
assertEquals("Parameter sqlTypeAsString, must not be null nor empty", e.getMessage());
assertThat(e.getMessage()).isEqualTo("Parameter sqlTypeAsString, must not be null nor empty");
return;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,8 +16,8 @@
package org.springframework.integration.jdbc.config;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.io.ByteArrayInputStream;
import java.util.Properties;
@@ -45,7 +45,10 @@ public class StoredProcInvalidConfigsTests {
fail("Expected a BeanDefinitionParsingException to be thrown.");
}
catch (BeanDefinitionParsingException e) {
assertTrue(e.getMessage().contains("Exactly one of 'stored-procedure-name' or 'stored-procedure-name-expression' is required"));
assertThat(e.getMessage()
.contains("Exactly one of 'stored-procedure-name' or 'stored-procedure-name-expression' is " +
"required"))
.isTrue();
}
}
@@ -56,7 +59,9 @@ public class StoredProcInvalidConfigsTests {
fail("Expected a BeanDefinitionParsingException to be thrown.");
}
catch (BeanDefinitionParsingException e) {
assertTrue(e.getMessage().contains("'return-type' attribute can't be provided for IN 'sql-parameter-definition' element."));
assertThat(e.getMessage()
.contains("'return-type' attribute can't be provided for IN 'sql-parameter-definition' element."))
.isTrue();
}
}
@@ -67,8 +72,8 @@ public class StoredProcInvalidConfigsTests {
fail("Expected a BeanDefinitionParsingException to be thrown.");
}
catch (BeanDefinitionParsingException e) {
assertTrue(e.getMessage().contains("'type-name' and 'scale' attributes are mutually exclusive " +
"for 'sql-parameter-definition' element."));
assertThat(e.getMessage().contains("'type-name' and 'scale' attributes are mutually exclusive " +
"for 'sql-parameter-definition' element.")).isTrue();
}
}
@@ -79,8 +84,8 @@ public class StoredProcInvalidConfigsTests {
fail("Expected a BeanDefinitionParsingException to be thrown.");
}
catch (BeanDefinitionParsingException e) {
assertTrue(e.getMessage().contains("'returnType' and 'scale' attributes are mutually exclusive " +
"for 'sql-parameter-definition' element."));
assertThat(e.getMessage().contains("'returnType' and 'scale' attributes are mutually exclusive " +
"for 'sql-parameter-definition' element.")).isTrue();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,10 +16,7 @@
package org.springframework.integration.jdbc.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.sql.Types;
import java.util.List;
@@ -68,7 +65,9 @@ public class StoredProcMessageHandlerParserTests {
DirectFieldAccessor executorAccessor = new DirectFieldAccessor(executor);
Expression testProcedure1 = (Expression) executorAccessor.getPropertyValue("storedProcedureNameExpression");
assertEquals("Resolution Required should be 'testProcedure1' but was " + testProcedure1, "testProcedure1", testProcedure1.getValue());
assertThat(testProcedure1.getValue())
.as("Resolution Required should be 'testProcedure1' but was " + testProcedure1)
.isEqualTo("testProcedure1");
}
@SuppressWarnings("unchecked")
@@ -84,32 +83,32 @@ public class StoredProcMessageHandlerParserTests {
DirectFieldAccessor executorAccessor = new DirectFieldAccessor(executor);
Object procedureParameters = executorAccessor.getPropertyValue("procedureParameters");
assertNotNull(procedureParameters);
assertTrue(procedureParameters instanceof List);
assertThat(procedureParameters).isNotNull();
assertThat(procedureParameters instanceof List).isTrue();
List<ProcedureParameter> procedureParametersAsList = (List<ProcedureParameter>) procedureParameters;
assertTrue(procedureParametersAsList.size() == 4);
assertThat(procedureParametersAsList.size() == 4).isTrue();
ProcedureParameter parameter1 = procedureParametersAsList.get(0);
ProcedureParameter parameter2 = procedureParametersAsList.get(1);
ProcedureParameter parameter3 = procedureParametersAsList.get(2);
ProcedureParameter parameter4 = procedureParametersAsList.get(3);
assertEquals("username", parameter1.getName());
assertEquals("description", parameter2.getName());
assertEquals("password", parameter3.getName());
assertEquals("age", parameter4.getName());
assertThat(parameter1.getName()).isEqualTo("username");
assertThat(parameter2.getName()).isEqualTo("description");
assertThat(parameter3.getName()).isEqualTo("password");
assertThat(parameter4.getName()).isEqualTo("age");
assertEquals("kenny", parameter1.getValue());
assertEquals("Who killed Kenny?", parameter2.getValue());
assertNull(parameter3.getValue());
assertEquals(Integer.valueOf(30), parameter4.getValue());
assertThat(parameter1.getValue()).isEqualTo("kenny");
assertThat(parameter2.getValue()).isEqualTo("Who killed Kenny?");
assertThat(parameter3.getValue()).isNull();
assertThat(parameter4.getValue()).isEqualTo(Integer.valueOf(30));
assertNull(parameter1.getExpression());
assertNull(parameter2.getExpression());
assertEquals("payload.username", parameter3.getExpression());
assertNull(parameter4.getExpression());
assertThat(parameter1.getExpression()).isNull();
assertThat(parameter2.getExpression()).isNull();
assertThat(parameter3.getExpression()).isEqualTo("payload.username");
assertThat(parameter4.getExpression()).isNull();
}
@@ -127,37 +126,37 @@ public class StoredProcMessageHandlerParserTests {
Object sqlParameters = executorAccessor.getPropertyValue("sqlParameters");
assertNotNull(sqlParameters);
assertTrue(sqlParameters instanceof List);
assertThat(sqlParameters).isNotNull();
assertThat(sqlParameters instanceof List).isTrue();
List<SqlParameter> sqlParametersAsList = (List<SqlParameter>) sqlParameters;
assertTrue(sqlParametersAsList.size() == 4);
assertThat(sqlParametersAsList.size() == 4).isTrue();
SqlParameter parameter1 = sqlParametersAsList.get(0);
SqlParameter parameter2 = sqlParametersAsList.get(1);
SqlParameter parameter3 = sqlParametersAsList.get(2);
SqlParameter parameter4 = sqlParametersAsList.get(3);
assertEquals("username", parameter1.getName());
assertEquals("password", parameter2.getName());
assertEquals("age", parameter3.getName());
assertEquals("description", parameter4.getName());
assertThat(parameter1.getName()).isEqualTo("username");
assertThat(parameter2.getName()).isEqualTo("password");
assertThat(parameter3.getName()).isEqualTo("age");
assertThat(parameter4.getName()).isEqualTo("description");
assertNull("Expect that the scale is null.", parameter1.getScale());
assertNull("Expect that the scale is null.", parameter2.getScale());
assertEquals("Expect that the scale is 5.", Integer.valueOf(5), parameter3.getScale());
assertNull("Expect that the scale is null.", parameter4.getScale());
assertThat(parameter1.getScale()).as("Expect that the scale is null.").isNull();
assertThat(parameter2.getScale()).as("Expect that the scale is null.").isNull();
assertThat(parameter3.getScale()).as("Expect that the scale is 5.").isEqualTo(Integer.valueOf(5));
assertThat(parameter4.getScale()).as("Expect that the scale is null.").isNull();
assertEquals("SqlType is ", Types.VARCHAR, parameter1.getSqlType());
assertEquals("SqlType is ", Types.VARCHAR, parameter2.getSqlType());
assertEquals("SqlType is ", Types.INTEGER, parameter3.getSqlType());
assertEquals("SqlType is ", Types.VARCHAR, parameter4.getSqlType());
assertThat(parameter1.getSqlType()).as("SqlType is ").isEqualTo(Types.VARCHAR);
assertThat(parameter2.getSqlType()).as("SqlType is ").isEqualTo(Types.VARCHAR);
assertThat(parameter3.getSqlType()).as("SqlType is ").isEqualTo(Types.INTEGER);
assertThat(parameter4.getSqlType()).as("SqlType is ").isEqualTo(Types.VARCHAR);
assertTrue(parameter1 instanceof SqlParameter);
assertTrue(parameter2 instanceof SqlOutParameter);
assertTrue(parameter3 instanceof SqlInOutParameter);
assertTrue(parameter4 instanceof SqlParameter);
assertThat(parameter1 instanceof SqlParameter).isTrue();
assertThat(parameter2 instanceof SqlOutParameter).isTrue();
assertThat(parameter3 instanceof SqlInOutParameter).isTrue();
assertThat(parameter4 instanceof SqlParameter).isTrue();
}
@@ -167,7 +166,7 @@ public class StoredProcMessageHandlerParserTests {
MessageHandler handler = TestUtils.getPropertyValue(this.consumer, "handler", MessageHandler.class);
handler.handleMessage(new GenericMessage<String>("foo"));
assertEquals(1, adviceCalled);
assertThat(adviceCalled).isEqualTo(1);
}
@After

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,11 +16,7 @@
package org.springframework.integration.jdbc.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.sql.Types;
import java.util.List;
@@ -70,11 +66,11 @@ public class StoredProcOutboundGatewayParserTests {
DirectFieldAccessor accessor = new DirectFieldAccessor(this.outboundGateway);
Object source = accessor.getPropertyValue("handler");
accessor = new DirectFieldAccessor(source);
assertEquals(Boolean.TRUE, accessor.getPropertyValue("requiresReply"));
assertThat(accessor.getPropertyValue("requiresReply")).isEqualTo(Boolean.TRUE);
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
Expression storedProcedureName = (Expression) accessor.getPropertyValue("storedProcedureNameExpression");
assertEquals("Wrong stored procedure name", "GET_PRIME_NUMBERS", storedProcedureName.getValue());
assertThat(storedProcedureName.getValue()).as("Wrong stored procedure name").isEqualTo("GET_PRIME_NUMBERS");
}
@Test
@@ -91,7 +87,7 @@ public class StoredProcOutboundGatewayParserTests {
accessor = new DirectFieldAccessor(messagingTemplate);
Long sendTimeout = (Long) accessor.getPropertyValue("sendTimeout");
assertEquals("Wrong sendTimeout", Long.valueOf(555L), sendTimeout);
assertThat(sendTimeout).as("Wrong sendTimeout").isEqualTo(Long.valueOf(555L));
}
@@ -105,7 +101,7 @@ public class StoredProcOutboundGatewayParserTests {
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
boolean skipUndeclaredResults = (Boolean) accessor.getPropertyValue("skipUndeclaredResults");
assertFalse(skipUndeclaredResults);
assertThat(skipUndeclaredResults).isFalse();
}
@Test
@@ -118,7 +114,7 @@ public class StoredProcOutboundGatewayParserTests {
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
boolean returnValueRequired = (Boolean) accessor.getPropertyValue("returnValueRequired");
assertTrue(returnValueRequired);
assertThat(returnValueRequired).isTrue();
}
@Test
@@ -130,7 +126,7 @@ public class StoredProcOutboundGatewayParserTests {
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
boolean isFunction = (Boolean) accessor.getPropertyValue("isFunction");
assertTrue(isFunction);
assertThat(isFunction).isTrue();
}
@Test
@@ -142,7 +138,7 @@ public class StoredProcOutboundGatewayParserTests {
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
boolean isFunction = (Boolean) accessor.getPropertyValue("isFunction");
assertFalse(isFunction);
assertThat(isFunction).isFalse();
}
@Test
@@ -154,7 +150,7 @@ public class StoredProcOutboundGatewayParserTests {
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
boolean ignoreColumnMetaData = (Boolean) accessor.getPropertyValue("ignoreColumnMetaData");
assertFalse(ignoreColumnMetaData);
assertThat(ignoreColumnMetaData).isFalse();
}
@Test
@@ -166,7 +162,7 @@ public class StoredProcOutboundGatewayParserTests {
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
boolean ignoreColumnMetaData = (Boolean) accessor.getPropertyValue("ignoreColumnMetaData");
assertTrue(ignoreColumnMetaData);
assertThat(ignoreColumnMetaData).isTrue();
}
@SuppressWarnings("unchecked")
@@ -180,32 +176,32 @@ public class StoredProcOutboundGatewayParserTests {
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
Object procedureParameters = accessor.getPropertyValue("procedureParameters");
assertNotNull(procedureParameters);
assertTrue(procedureParameters instanceof List);
assertThat(procedureParameters).isNotNull();
assertThat(procedureParameters instanceof List).isTrue();
List<ProcedureParameter> procedureParametersAsList = (List<ProcedureParameter>) procedureParameters;
assertTrue(procedureParametersAsList.size() == 4);
assertThat(procedureParametersAsList.size() == 4).isTrue();
ProcedureParameter parameter1 = procedureParametersAsList.get(0);
ProcedureParameter parameter2 = procedureParametersAsList.get(1);
ProcedureParameter parameter3 = procedureParametersAsList.get(2);
ProcedureParameter parameter4 = procedureParametersAsList.get(3);
assertEquals("username", parameter1.getName());
assertEquals("description", parameter2.getName());
assertEquals("password", parameter3.getName());
assertEquals("age", parameter4.getName());
assertThat(parameter1.getName()).isEqualTo("username");
assertThat(parameter2.getName()).isEqualTo("description");
assertThat(parameter3.getName()).isEqualTo("password");
assertThat(parameter4.getName()).isEqualTo("age");
assertEquals("kenny", parameter1.getValue());
assertEquals("Who killed Kenny?", parameter2.getValue());
assertNull(parameter3.getValue());
assertEquals(30, parameter4.getValue());
assertThat(parameter1.getValue()).isEqualTo("kenny");
assertThat(parameter2.getValue()).isEqualTo("Who killed Kenny?");
assertThat(parameter3.getValue()).isNull();
assertThat(parameter4.getValue()).isEqualTo(30);
assertNull(parameter1.getExpression());
assertNull(parameter2.getExpression());
assertEquals("payload.username", parameter3.getExpression());
assertNull(parameter4.getExpression());
assertThat(parameter1.getExpression()).isNull();
assertThat(parameter2.getExpression()).isNull();
assertThat(parameter3.getExpression()).isEqualTo("payload.username");
assertThat(parameter4.getExpression()).isNull();
}
@@ -220,17 +216,18 @@ public class StoredProcOutboundGatewayParserTests {
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
Object returningResultSetRowMappers = accessor.getPropertyValue("returningResultSetRowMappers");
assertNotNull(returningResultSetRowMappers);
assertTrue(returningResultSetRowMappers instanceof Map);
assertThat(returningResultSetRowMappers).isNotNull();
assertThat(returningResultSetRowMappers instanceof Map).isTrue();
Map<String, RowMapper<?>> returningResultSetRowMappersAsMap = (Map<String, RowMapper<?>>) returningResultSetRowMappers;
assertTrue("The rowmapper was not set. Expected returningResultSetRowMappersAsMap.size() == 1", returningResultSetRowMappersAsMap.size() == 1);
assertThat(returningResultSetRowMappersAsMap.size() == 1)
.as("The rowmapper was not set. Expected returningResultSetRowMappersAsMap.size() == 1").isTrue();
Entry<String, ?> mapEntry1 = returningResultSetRowMappersAsMap.entrySet().iterator().next();
assertEquals("out", mapEntry1.getKey());
assertTrue(mapEntry1.getValue() instanceof PrimeMapper);
assertThat(mapEntry1.getKey()).isEqualTo("out");
assertThat(mapEntry1.getValue() instanceof PrimeMapper).isTrue();
}
@@ -246,35 +243,35 @@ public class StoredProcOutboundGatewayParserTests {
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
Object sqlParameters = accessor.getPropertyValue("sqlParameters");
assertNotNull(sqlParameters);
assertTrue(sqlParameters instanceof List);
assertThat(sqlParameters).isNotNull();
assertThat(sqlParameters instanceof List).isTrue();
List<SqlParameter> sqlParametersAsList = (List<SqlParameter>) sqlParameters;
assertTrue(sqlParametersAsList.size() == 4);
assertThat(sqlParametersAsList.size() == 4).isTrue();
SqlParameter parameter1 = sqlParametersAsList.get(0);
SqlParameter parameter2 = sqlParametersAsList.get(1);
SqlParameter parameter3 = sqlParametersAsList.get(2);
SqlParameter parameter4 = sqlParametersAsList.get(3);
assertEquals("username", parameter1.getName());
assertEquals("password", parameter2.getName());
assertEquals("age", parameter3.getName());
assertEquals("description", parameter4.getName());
assertThat(parameter1.getName()).isEqualTo("username");
assertThat(parameter2.getName()).isEqualTo("password");
assertThat(parameter3.getName()).isEqualTo("age");
assertThat(parameter4.getName()).isEqualTo("description");
assertNull("Expect that the scale is null.", parameter1.getScale());
assertNull("Expect that the scale is null.", parameter2.getScale());
assertEquals("Expect that the scale is 5.", Integer.valueOf(5), parameter3.getScale());
assertNull("Expect that the scale is null.", parameter4.getScale());
assertThat(parameter1.getScale()).as("Expect that the scale is null.").isNull();
assertThat(parameter2.getScale()).as("Expect that the scale is null.").isNull();
assertThat(parameter3.getScale()).as("Expect that the scale is 5.").isEqualTo(Integer.valueOf(5));
assertThat(parameter4.getScale()).as("Expect that the scale is null.").isNull();
assertEquals("SqlType is ", Types.VARCHAR, parameter1.getSqlType());
assertEquals("SqlType is ", Types.VARCHAR, parameter2.getSqlType());
assertEquals("SqlType is ", Types.INTEGER, parameter3.getSqlType());
assertEquals("SqlType is ", Types.VARCHAR, parameter4.getSqlType());
assertThat(parameter1.getSqlType()).as("SqlType is ").isEqualTo(Types.VARCHAR);
assertThat(parameter2.getSqlType()).as("SqlType is ").isEqualTo(Types.VARCHAR);
assertThat(parameter3.getSqlType()).as("SqlType is ").isEqualTo(Types.INTEGER);
assertThat(parameter4.getSqlType()).as("SqlType is ").isEqualTo(Types.VARCHAR);
assertTrue(parameter2 instanceof SqlOutParameter);
assertTrue(parameter3 instanceof SqlInOutParameter);
assertThat(parameter2 instanceof SqlOutParameter).isTrue();
assertThat(parameter3 instanceof SqlInOutParameter).isTrue();
}
@Test
@@ -283,7 +280,7 @@ public class StoredProcOutboundGatewayParserTests {
MessageHandler handler = TestUtils.getPropertyValue(this.outboundGateway, "handler", MessageHandler.class);
handler.handleMessage(new GenericMessage<String>("foo"));
assertEquals(1, adviceCalled);
assertThat(adviceCalled).isEqualTo(1);
}
@After

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,12 +16,7 @@
package org.springframework.integration.jdbc.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.sql.Types;
import java.util.Iterator;
@@ -70,7 +65,7 @@ public class StoredProcPollingChannelAdapterParserTests {
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
Expression storedProcedureName = (Expression) accessor.getPropertyValue("storedProcedureNameExpression");
assertEquals("Wrong stored procedure name", "GET_PRIME_NUMBERS", storedProcedureName.getValue());
assertThat(storedProcedureName.getValue()).as("Wrong stored procedure name").isEqualTo("GET_PRIME_NUMBERS");
}
@Test
@@ -82,8 +77,8 @@ public class StoredProcPollingChannelAdapterParserTests {
"source.executor.storedProcedureNameExpression",
Expression.class);
assertEquals("Wrong stored procedure name", "'GET_PRIME_NUMBERS'",
storedProcedureNameExpression.getExpressionString());
assertThat(storedProcedureNameExpression.getExpressionString()).as("Wrong stored procedure name")
.isEqualTo("'GET_PRIME_NUMBERS'");
}
@Test
@@ -95,8 +90,7 @@ public class StoredProcPollingChannelAdapterParserTests {
"source.executor.jdbcCallOperationsCacheSize",
Integer.class);
assertEquals("Wrong Default JdbcCallOperations Cache Size", Integer.valueOf(10),
cacheSize);
assertThat(cacheSize).as("Wrong Default JdbcCallOperations Cache Size").isEqualTo(Integer.valueOf(10));
}
@@ -108,7 +102,7 @@ public class StoredProcPollingChannelAdapterParserTests {
"source.executor.jdbcCallOperationsCacheSize",
Integer.class);
assertEquals("Wrong JdbcCallOperations Cache Size", Integer.valueOf(77), cacheSize);
assertThat(cacheSize).as("Wrong JdbcCallOperations Cache Size").isEqualTo(Integer.valueOf(77));
}
@Test
@@ -121,7 +115,7 @@ public class StoredProcPollingChannelAdapterParserTests {
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
boolean skipUndeclaredResults = (Boolean) accessor.getPropertyValue("skipUndeclaredResults");
assertTrue("skipUndeclaredResults was not set and should default to 'true'", skipUndeclaredResults);
assertThat(skipUndeclaredResults).as("skipUndeclaredResults was not set and should default to 'true'").isTrue();
}
@Test
@@ -134,7 +128,7 @@ public class StoredProcPollingChannelAdapterParserTests {
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
boolean returnValueRequired = (Boolean) accessor.getPropertyValue("returnValueRequired");
assertTrue(returnValueRequired);
assertThat(returnValueRequired).isTrue();
}
@Test
@@ -146,7 +140,7 @@ public class StoredProcPollingChannelAdapterParserTests {
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
boolean isFunction = (Boolean) accessor.getPropertyValue("isFunction");
assertTrue(isFunction);
assertThat(isFunction).isTrue();
}
@SuppressWarnings("unchecked")
@@ -160,32 +154,32 @@ public class StoredProcPollingChannelAdapterParserTests {
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
Object procedureParameters = accessor.getPropertyValue("procedureParameters");
assertNotNull(procedureParameters);
assertTrue(procedureParameters instanceof List);
assertThat(procedureParameters).isNotNull();
assertThat(procedureParameters instanceof List).isTrue();
List<ProcedureParameter> procedureParametersAsList = (List<ProcedureParameter>) procedureParameters;
assertTrue(procedureParametersAsList.size() == 4);
assertThat(procedureParametersAsList.size() == 4).isTrue();
ProcedureParameter parameter1 = procedureParametersAsList.get(0);
ProcedureParameter parameter2 = procedureParametersAsList.get(1);
ProcedureParameter parameter3 = procedureParametersAsList.get(2);
ProcedureParameter parameter4 = procedureParametersAsList.get(3);
assertEquals("username", parameter1.getName());
assertEquals("description", parameter2.getName());
assertEquals("password", parameter3.getName());
assertEquals("age", parameter4.getName());
assertThat(parameter1.getName()).isEqualTo("username");
assertThat(parameter2.getName()).isEqualTo("description");
assertThat(parameter3.getName()).isEqualTo("password");
assertThat(parameter4.getName()).isEqualTo("age");
assertEquals("kenny", parameter1.getValue());
assertEquals("Who killed Kenny?", parameter2.getValue());
assertNull(parameter3.getValue());
assertEquals(30, parameter4.getValue());
assertThat(parameter1.getValue()).isEqualTo("kenny");
assertThat(parameter2.getValue()).isEqualTo("Who killed Kenny?");
assertThat(parameter3.getValue()).isNull();
assertThat(parameter4.getValue()).isEqualTo(30);
assertNull(parameter1.getExpression());
assertNull(parameter2.getExpression());
assertEquals("payload.username", parameter3.getExpression());
assertNull(parameter4.getExpression());
assertThat(parameter1.getExpression()).isNull();
assertThat(parameter2.getExpression()).isNull();
assertThat(parameter3.getExpression()).isEqualTo("payload.username");
assertThat(parameter4.getExpression()).isNull();
}
@@ -200,24 +194,24 @@ public class StoredProcPollingChannelAdapterParserTests {
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
Object returningResultSetRowMappers = accessor.getPropertyValue("returningResultSetRowMappers");
assertNotNull(returningResultSetRowMappers);
assertTrue(returningResultSetRowMappers instanceof Map);
assertThat(returningResultSetRowMappers).isNotNull();
assertThat(returningResultSetRowMappers instanceof Map).isTrue();
Map<String, RowMapper<?>> returningResultSetRowMappersAsMap =
(Map<String, RowMapper<?>>) returningResultSetRowMappers;
assertTrue("The rowmapper was not set. Expected returningResultSetRowMappersAsMap.size() == 2",
returningResultSetRowMappersAsMap.size() == 2);
assertThat(returningResultSetRowMappersAsMap.size() == 2)
.as("The rowmapper was not set. Expected returningResultSetRowMappersAsMap.size() == 2").isTrue();
Iterator<Entry<String, RowMapper<?>>> iterator = returningResultSetRowMappersAsMap.entrySet().iterator();
Entry<String, ?> mapEntry = iterator.next();
assertEquals("out", mapEntry.getKey());
assertTrue(mapEntry.getValue() instanceof PrimeMapper);
assertThat(mapEntry.getKey()).isEqualTo("out");
assertThat(mapEntry.getValue() instanceof PrimeMapper).isTrue();
mapEntry = iterator.next();
assertEquals("out2", mapEntry.getKey());
assertTrue(mapEntry.getValue() instanceof SingleColumnRowMapper);
assertThat(mapEntry.getKey()).isEqualTo("out2");
assertThat(mapEntry.getValue() instanceof SingleColumnRowMapper).isTrue();
}
@@ -233,35 +227,35 @@ public class StoredProcPollingChannelAdapterParserTests {
source = accessor.getPropertyValue("executor");
accessor = new DirectFieldAccessor(source);
Object sqlParameters = accessor.getPropertyValue("sqlParameters");
assertNotNull(sqlParameters);
assertTrue(sqlParameters instanceof List);
assertThat(sqlParameters).isNotNull();
assertThat(sqlParameters instanceof List).isTrue();
List<SqlParameter> sqlParametersAsList = (List<SqlParameter>) sqlParameters;
assertTrue(sqlParametersAsList.size() == 4);
assertThat(sqlParametersAsList.size() == 4).isTrue();
SqlParameter parameter1 = sqlParametersAsList.get(0);
SqlParameter parameter2 = sqlParametersAsList.get(1);
SqlParameter parameter3 = sqlParametersAsList.get(2);
SqlParameter parameter4 = sqlParametersAsList.get(3);
assertEquals("username", parameter1.getName());
assertEquals("password", parameter2.getName());
assertEquals("age", parameter3.getName());
assertEquals("description", parameter4.getName());
assertThat(parameter1.getName()).isEqualTo("username");
assertThat(parameter2.getName()).isEqualTo("password");
assertThat(parameter3.getName()).isEqualTo("age");
assertThat(parameter4.getName()).isEqualTo("description");
assertNull("Expect that the scale is null.", parameter1.getScale());
assertNull("Expect that the scale is null.", parameter2.getScale());
assertEquals("Expect that the scale is 5.", Integer.valueOf(5), parameter3.getScale());
assertNull("Expect that the scale is null.", parameter4.getScale());
assertThat(parameter1.getScale()).as("Expect that the scale is null.").isNull();
assertThat(parameter2.getScale()).as("Expect that the scale is null.").isNull();
assertThat(parameter3.getScale()).as("Expect that the scale is 5.").isEqualTo(Integer.valueOf(5));
assertThat(parameter4.getScale()).as("Expect that the scale is null.").isNull();
assertEquals("SqlType is ", Types.VARCHAR, parameter1.getSqlType());
assertEquals("SqlType is ", Types.VARCHAR, parameter2.getSqlType());
assertEquals("SqlType is ", Types.INTEGER, parameter3.getSqlType());
assertEquals("SqlType is ", Types.VARCHAR, parameter4.getSqlType());
assertThat(parameter1.getSqlType()).as("SqlType is ").isEqualTo(Types.VARCHAR);
assertThat(parameter2.getSqlType()).as("SqlType is ").isEqualTo(Types.VARCHAR);
assertThat(parameter3.getSqlType()).as("SqlType is ").isEqualTo(Types.INTEGER);
assertThat(parameter4.getSqlType()).as("SqlType is ").isEqualTo(Types.VARCHAR);
assertTrue(parameter2 instanceof SqlOutParameter);
assertTrue(parameter3 instanceof SqlInOutParameter);
assertThat(parameter2 instanceof SqlOutParameter).isTrue();
assertThat(parameter3 instanceof SqlInOutParameter).isTrue();
}
@@ -271,9 +265,11 @@ public class StoredProcPollingChannelAdapterParserTests {
MessageChannel autoChannel = context.getBean("autoChannel", MessageChannel.class);
SourcePollingChannelAdapter autoChannelAdapter =
context.getBean("autoChannel.adapter", SourcePollingChannelAdapter.class);
assertSame(autoChannel, TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel"));
assertFalse(TestUtils.getPropertyValue(autoChannelAdapter, "source.executor.returnValueRequired", Boolean.class));
assertFalse(TestUtils.getPropertyValue(autoChannelAdapter, "source.executor.isFunction", Boolean.class));
assertThat(TestUtils.getPropertyValue(autoChannelAdapter, "outputChannel")).isSameAs(autoChannel);
assertThat(TestUtils.getPropertyValue(autoChannelAdapter, "source.executor.returnValueRequired", Boolean.class))
.isFalse();
assertThat(TestUtils.getPropertyValue(autoChannelAdapter, "source.executor.isFunction", Boolean.class))
.isFalse();
autoChannelAdapter.stop();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 the original author or authors.
* Copyright 2016-2019 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,10 +16,7 @@
package org.springframework.integration.jdbc.leader;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
@@ -83,7 +80,7 @@ public class JdbcLockRegistryLeaderInitiatorTests {
initiator.start();
}
assertThat(granted.await(10, TimeUnit.SECONDS), is(true));
assertThat(granted.await(10, TimeUnit.SECONDS)).isTrue();
LockRegistryLeaderInitiator initiator1 = countingPublisher.initiator;
@@ -96,12 +93,12 @@ public class JdbcLockRegistryLeaderInitiatorTests {
}
}
assertNotNull(initiator2);
assertThat(initiator2).isNotNull();
assertThat(initiator1.getContext().isLeader(), is(true));
assertThat(initiator1.getContext().getRole(), equalTo("bar"));
assertThat(initiator2.getContext().isLeader(), is(false));
assertThat(initiator2.getContext().getRole(), equalTo("bar"));
assertThat(initiator1.getContext().isLeader()).isTrue();
assertThat(initiator1.getContext().getRole()).isEqualTo("bar");
assertThat(initiator2.getContext().isLeader()).isFalse();
assertThat(initiator2.getContext().getRole()).isEqualTo("bar");
final CountDownLatch granted1 = new CountDownLatch(1);
final CountDownLatch granted2 = new CountDownLatch(1);
@@ -116,7 +113,7 @@ public class JdbcLockRegistryLeaderInitiatorTests {
public void publishOnRevoked(Object source, Context context, String role) {
try {
// It's difficult to see round-robin election, so block one initiator until the second is elected.
assertThat(granted2.await(20, TimeUnit.SECONDS), is(true));
assertThat(granted2.await(20, TimeUnit.SECONDS)).isTrue();
}
catch (InterruptedException e) {
// No op
@@ -132,7 +129,7 @@ public class JdbcLockRegistryLeaderInitiatorTests {
public void publishOnRevoked(Object source, Context context, String role) {
try {
// It's difficult to see round-robin election, so block one initiator until the second is elected.
assertThat(granted1.await(20, TimeUnit.SECONDS), is(true));
assertThat(granted1.await(20, TimeUnit.SECONDS)).isTrue();
}
catch (InterruptedException e) {
// No op
@@ -144,17 +141,17 @@ public class JdbcLockRegistryLeaderInitiatorTests {
initiator1.getContext().yield();
assertThat(revoked1.await(20, TimeUnit.SECONDS), is(true));
assertThat(revoked1.await(20, TimeUnit.SECONDS)).isTrue();
assertThat(initiator2.getContext().isLeader(), is(true));
assertThat(initiator1.getContext().isLeader(), is(false));
assertThat(initiator2.getContext().isLeader()).isTrue();
assertThat(initiator1.getContext().isLeader()).isFalse();
initiator2.getContext().yield();
assertThat(revoked2.await(20, TimeUnit.SECONDS), is(true));
assertThat(revoked2.await(20, TimeUnit.SECONDS)).isTrue();
assertThat(initiator1.getContext().isLeader(), is(true));
assertThat(initiator2.getContext().isLeader(), is(false));
assertThat(initiator1.getContext().isLeader()).isTrue();
assertThat(initiator2.getContext().isLeader()).isFalse();
// Stop second initiator, so the first one will be leader even after yield
initiator2.stop();
@@ -164,8 +161,8 @@ public class JdbcLockRegistryLeaderInitiatorTests {
initiator1.getContext().yield();
assertThat(granted11.await(20, TimeUnit.SECONDS), is(true));
assertThat(initiator1.getContext().isLeader(), is(true));
assertThat(granted11.await(20, TimeUnit.SECONDS)).isTrue();
assertThat(initiator1.getContext().isLeader()).isTrue();
initiator1.stop();
}
@@ -182,11 +179,11 @@ public class JdbcLockRegistryLeaderInitiatorTests {
initiator.start();
assertThat(granted.await(10, TimeUnit.SECONDS), is(true));
assertThat(granted.await(10, TimeUnit.SECONDS)).isTrue();
destroy();
assertThat(countingPublisher.revoked.await(10, TimeUnit.SECONDS), is(true));
assertThat(countingPublisher.revoked.await(10, TimeUnit.SECONDS)).isTrue();
granted = new CountDownLatch(1);
countingPublisher = new CountingPublisher(granted);
@@ -194,7 +191,7 @@ public class JdbcLockRegistryLeaderInitiatorTests {
init();
assertThat(granted.await(10, TimeUnit.SECONDS), is(true));
assertThat(granted.await(10, TimeUnit.SECONDS)).isTrue();
initiator.stop();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 the original author or authors.
* Copyright 2016-2019 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,10 +16,7 @@
package org.springframework.integration.jdbc.lock;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
@@ -124,12 +121,12 @@ public class JdbcLockRegistryDifferentClientTests {
latch3.countDown();
}
});
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertFalse(locked.get());
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(locked.get()).isFalse();
lock1.unlock();
latch2.countDown();
assertTrue(latch3.await(10, TimeUnit.SECONDS));
assertTrue(locked.get());
assertThat(latch3.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(locked.get()).isTrue();
}
}
@@ -181,10 +178,10 @@ public class JdbcLockRegistryDifferentClientTests {
}
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
// eventually they both get the lock and release it
assertTrue(locked.contains("1"));
assertTrue(locked.contains("2"));
assertThat(locked.contains("1")).isTrue();
assertThat(locked.contains("2")).isTrue();
pool.shutdownNow();
}
}
@@ -226,9 +223,9 @@ public class JdbcLockRegistryDifferentClientTests {
logger.info("Starting: " + i);
pool.invokeAll(tasks);
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertEquals(1, locked.size());
assertTrue(locked.contains("done"));
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(locked.size()).isEqualTo(1);
assertThat(locked.contains("done")).isTrue();
pool.shutdownNow();
}
}
@@ -265,7 +262,7 @@ public class JdbcLockRegistryDifferentClientTests {
lock2.unlock();
}
});
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
data.add(1);
Thread.sleep(100);
data.add(2);
@@ -274,8 +271,8 @@ public class JdbcLockRegistryDifferentClientTests {
lock1.unlock();
for (int i = 0; i < 6; i++) {
Integer integer = data.poll(10, TimeUnit.SECONDS);
assertNotNull(integer);
assertEquals(i + 1, integer.intValue());
assertThat(integer).isNotNull();
assertThat(integer.intValue()).isEqualTo(i + 1);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 the original author or authors.
* Copyright 2016-2019 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,14 +16,7 @@
package org.springframework.integration.jdbc.lock;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
@@ -75,7 +68,7 @@ public class JdbcLockRegistryTests {
Lock lock = this.registry.obtain("foo");
lock.lock();
try {
assertEquals(1, TestUtils.getPropertyValue(this.registry, "locks", Map.class).size());
assertThat(TestUtils.getPropertyValue(this.registry, "locks", Map.class).size()).isEqualTo(1);
}
finally {
lock.unlock();
@@ -84,7 +77,7 @@ public class JdbcLockRegistryTests {
Thread.sleep(10);
this.registry.expireUnusedOlderThan(0);
assertEquals(0, TestUtils.getPropertyValue(this.registry, "locks", Map.class).size());
assertThat(TestUtils.getPropertyValue(this.registry, "locks", Map.class).size()).isEqualTo(0);
}
@Test
@@ -93,7 +86,7 @@ public class JdbcLockRegistryTests {
Lock lock = this.registry.obtain("foo");
lock.lockInterruptibly();
try {
assertEquals(1, TestUtils.getPropertyValue(this.registry, "locks", Map.class).size());
assertThat(TestUtils.getPropertyValue(this.registry, "locks", Map.class).size()).isEqualTo(1);
}
finally {
lock.unlock();
@@ -108,7 +101,7 @@ public class JdbcLockRegistryTests {
lock1.lock();
try {
Lock lock2 = this.registry.obtain("foo");
assertSame(lock1, lock2);
assertThat(lock2).isSameAs(lock1);
lock2.lock();
lock2.unlock();
}
@@ -125,7 +118,7 @@ public class JdbcLockRegistryTests {
lock1.lockInterruptibly();
try {
Lock lock2 = this.registry.obtain("foo");
assertSame(lock1, lock2);
assertThat(lock2).isSameAs(lock1);
lock2.lockInterruptibly();
lock2.unlock();
}
@@ -142,7 +135,7 @@ public class JdbcLockRegistryTests {
lock1.lockInterruptibly();
try {
Lock lock2 = this.registry.obtain("bar");
assertNotSame(lock1, lock2);
assertThat(lock2).isNotSameAs(lock1);
lock2.lockInterruptibly();
lock2.unlock();
}
@@ -170,12 +163,12 @@ public class JdbcLockRegistryTests {
}
return null;
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertFalse(locked.get());
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(locked.get()).isFalse();
lock1.unlock();
Object ise = result.get(10, TimeUnit.SECONDS);
assertThat(ise, instanceOf(IllegalMonitorStateException.class));
assertThat(((Exception) ise).getMessage(), containsString("You do not own"));
assertThat(ise).isInstanceOf(IllegalMonitorStateException.class);
assertThat(((Exception) ise).getMessage()).contains("You do not own");
}
@Test
@@ -202,12 +195,12 @@ public class JdbcLockRegistryTests {
latch3.countDown();
}
});
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertFalse(locked.get());
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(locked.get()).isFalse();
lock1.unlock();
latch2.countDown();
assertTrue(latch3.await(10, TimeUnit.SECONDS));
assertTrue(locked.get());
assertThat(latch3.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(locked.get()).isTrue();
}
@Test
@@ -238,12 +231,12 @@ public class JdbcLockRegistryTests {
latch3.countDown();
}
});
assertTrue(latch1.await(10, TimeUnit.SECONDS));
assertFalse(locked.get());
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(locked.get()).isFalse();
lock1.unlock();
latch2.countDown();
assertTrue(latch3.await(10, TimeUnit.SECONDS));
assertTrue(locked.get());
assertThat(latch3.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(locked.get()).isTrue();
}
}
@@ -265,12 +258,12 @@ public class JdbcLockRegistryTests {
}
return null;
});
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertFalse(locked.get());
assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(locked.get()).isFalse();
lock.unlock();
Object imse = result.get(10, TimeUnit.SECONDS);
assertThat(imse, instanceOf(IllegalMonitorStateException.class));
assertThat(((Exception) imse).getMessage(), containsString("You do not own"));
assertThat(imse).isInstanceOf(IllegalMonitorStateException.class);
assertThat(((Exception) imse).getMessage()).contains("You do not own");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2017-2019 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,8 +16,7 @@
package org.springframework.integration.jdbc.metadata;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import javax.sql.DataSource;
@@ -62,8 +61,8 @@ public class JdbcMetadataStoreTests {
metadataStore.put("foo2", "bar2");
String bar1 = metadataStore.get("foo");
String bar2 = metadataStore.get("foo2");
assertEquals("bar1", bar1);
assertEquals("bar2", bar2);
assertThat(bar1).isEqualTo("bar1");
assertThat(bar2).isEqualTo("bar2");
}
@Test
@@ -74,8 +73,8 @@ public class JdbcMetadataStoreTests {
String bar = metadataStore.get("foo");
metadataStore.remove("foo2");
String bar2 = metadataStore.get("foo2");
assertNull(bar);
assertNull(bar2);
assertThat(bar).isNull();
assertThat(bar2).isNull();
}
@Test
@@ -83,14 +82,14 @@ public class JdbcMetadataStoreTests {
metadataStore.put("foo", "bar");
metadataStore.putIfAbsent("foo", "bar1");
String bar = metadataStore.get("foo");
assertEquals("bar", bar);
assertThat(bar).isEqualTo("bar");
}
@Test
public void nonExistentKeyIsNotRemoved() {
metadataStore.remove("non-existent");
String ne = metadataStore.get("non-existent");
assertNull(ne);
assertThat(ne).isNull();
}
@Test
@@ -98,7 +97,7 @@ public class JdbcMetadataStoreTests {
metadataStore.put("foo", "bar");
metadataStore.replace("foo", "bar", "bar2");
String bar2 = metadataStore.get("foo");
assertEquals("bar2", bar2);
assertThat(bar2).isEqualTo("bar2");
}
@Test
@@ -106,7 +105,7 @@ public class JdbcMetadataStoreTests {
metadataStore.put("foo", "bar");
metadataStore.replace("foo", "bar1", "bar2");
String bar = metadataStore.get("foo");
assertEquals("bar", bar);
assertThat(bar).isEqualTo("bar");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,8 +16,7 @@
package org.springframework.integration.jdbc.mysql;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.ArrayList;
import java.util.List;
@@ -108,11 +107,13 @@ public class MySqlJdbcMessageStoreMultipleChannelTests {
return null;
});
assertTrue("countDownLatch1 was " + countDownLatch1.getCount(), countDownLatch1.await(10000, TimeUnit.MILLISECONDS));
assertTrue("countDownLatch2 was " + countDownLatch2.getCount(), countDownLatch2.await(10000, TimeUnit.MILLISECONDS));
assertThat(countDownLatch1.await(10000, TimeUnit.MILLISECONDS))
.as("countDownLatch1 was " + countDownLatch1.getCount()).isTrue();
assertThat(countDownLatch2.await(10000, TimeUnit.MILLISECONDS))
.as("countDownLatch2 was " + countDownLatch2.getCount()).isTrue();
assertTrue("Wrong Sequence Number handled.", success.get());
assertNull(errorChannel.receive(0));
assertThat(success.get()).as("Wrong Sequence Number handled.").isTrue();
assertThat(errorChannel.receive(0)).isNull();
}
public static class Splitter {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,14 +16,7 @@
package org.springframework.integration.jdbc.mysql;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.springframework.integration.test.matcher.PayloadAndHeaderMatcher.sameExceptIgnorableHeaders;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.BufferedReader;
import java.io.InputStreamReader;
@@ -48,6 +41,7 @@ import org.springframework.integration.jdbc.store.JdbcMessageStore;
import org.springframework.integration.jdbc.store.JdbcMessageStoreTests;
import org.springframework.integration.store.MessageGroup;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.predicate.MessagePredicate;
import org.springframework.integration.util.UUIDConverter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.messaging.Message;
@@ -118,26 +112,25 @@ public class MySqlJdbcMessageStoreTests {
@Test
@Transactional
public void testGetNonExistent() throws Exception {
public void testGetNonExistent() {
Message<?> result = messageStore.getMessage(UUID.randomUUID());
assertNull(result);
assertThat(result).isNull();
}
@Test
@Transactional
public void testAddAndGet() throws Exception {
public void testAddAndGet() {
Message<String> message = MessageBuilder.withPayload("foo").build();
Message<String> saved = messageStore.addMessage(message);
Message<?> result = messageStore.getMessage(saved.getHeaders().getId());
assertNotNull(result);
assertThat(saved, sameExceptIgnorableHeaders(result));
assertThat(result).isNotNull();
assertThat(saved).matches(new MessagePredicate(result));
}
@Test
@Transactional
public void testWithMessageHistory() throws Exception {
Message<?> message = new GenericMessage<String>("Hello");
public void testWithMessageHistory() {
Message<?> message = new GenericMessage<>("Hello");
DirectChannel fooChannel = new DirectChannel();
fooChannel.setBeanName("fooChannel");
DirectChannel barChannel = new DirectChannel();
@@ -148,128 +141,129 @@ public class MySqlJdbcMessageStoreTests {
messageStore.addMessage(message);
message = messageStore.getMessage(message.getHeaders().getId());
MessageHistory messageHistory = MessageHistory.read(message);
assertNotNull(messageHistory);
assertEquals(2, messageHistory.size());
assertThat(messageHistory).isNotNull();
assertThat(messageHistory.size()).isEqualTo(2);
Properties fooChannelHistory = messageHistory.get(0);
assertEquals("fooChannel", fooChannelHistory.get("name"));
assertEquals("channel", fooChannelHistory.get("type"));
assertThat(fooChannelHistory.get("name")).isEqualTo("fooChannel");
assertThat(fooChannelHistory.get("type")).isEqualTo("channel");
}
@Test
@Transactional
public void testSize() throws Exception {
public void testSize() {
Message<String> message = MessageBuilder.withPayload("foo").build();
messageStore.addMessage(message);
assertEquals(1, messageStore.getMessageCount());
assertThat(messageStore.getMessageCount()).isEqualTo(1);
}
@Test
@Transactional
public void testSerializer() throws Exception {
public void testSerializer() {
// N.B. these serializers are not realistic (just for test purposes)
messageStore.setSerializer((object, outputStream) -> {
outputStream.write(((Message<?>) object).getPayload().toString().getBytes());
outputStream.write(object.getPayload().toString().getBytes());
outputStream.flush();
});
messageStore.setDeserializer(inputStream -> {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
return new GenericMessage<String>(reader.readLine());
return new GenericMessage<>(reader.readLine());
});
Message<String> message = MessageBuilder.withPayload("foo").build();
Message<String> saved = messageStore.addMessage(message);
assertNotNull(messageStore.getMessage(message.getHeaders().getId()));
assertThat(messageStore.getMessage(message.getHeaders().getId())).isNotNull();
Message<?> result = messageStore.getMessage(saved.getHeaders().getId());
assertNotNull(result);
assertEquals("foo", result.getPayload());
assertThat(result).isNotNull();
assertThat(result.getPayload()).isEqualTo("foo");
}
@Test
@Transactional
public void testAddAndGetWithDifferentRegion() throws Exception {
public void testAddAndGetWithDifferentRegion() {
Message<String> message = MessageBuilder.withPayload("foo").build();
Message<String> saved = messageStore.addMessage(message);
messageStore.setRegion("FOO");
Message<?> result = messageStore.getMessage(saved.getHeaders().getId());
assertNull(result);
assertThat(result).isNull();
}
@Test
@Transactional
public void testAddAndUpdate() throws Exception {
public void testAddAndUpdate() {
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId("X").build();
message = messageStore.addMessage(message);
message = MessageBuilder.fromMessage(message).setCorrelationId("Y").build();
message = messageStore.addMessage(message);
assertEquals("Y", new IntegrationMessageHeaderAccessor(messageStore.getMessage(message.getHeaders().getId())).getCorrelationId());
assertThat(new IntegrationMessageHeaderAccessor(messageStore.getMessage(message.getHeaders().getId()))
.getCorrelationId()).isEqualTo("Y");
}
@Test
@Transactional
public void testAddAndUpdateAlreadySaved() throws Exception {
public void testAddAndUpdateAlreadySaved() {
Message<String> message = MessageBuilder.withPayload("foo").build();
message = messageStore.addMessage(message);
Message<String> result = messageStore.addMessage(message);
assertSame(message, result);
assertThat(result).isSameAs(message);
}
@Test
@Transactional
public void testAddAndUpdateAlreadySavedAndCopied() throws Exception {
public void testAddAndUpdateAlreadySavedAndCopied() {
Message<String> message = MessageBuilder.withPayload("foo").build();
Message<String> saved = messageStore.addMessage(message);
Message<String> copy = MessageBuilder.fromMessage(saved).build();
Message<String> result = messageStore.addMessage(copy);
assertEquals(copy, result);
assertEquals(saved, result);
assertNotNull(messageStore.getMessage(saved.getHeaders().getId()));
assertThat(result).isEqualTo(copy);
assertThat(result).isEqualTo(saved);
assertThat(messageStore.getMessage(saved.getHeaders().getId())).isNotNull();
}
@Test
@Transactional
public void testAddAndUpdateWithChange() throws Exception {
public void testAddAndUpdateWithChange() {
Message<String> message = MessageBuilder.withPayload("foo").build();
Message<String> saved = messageStore.addMessage(message);
Message<String> copy = MessageBuilder.fromMessage(saved).setHeader("newHeader", 1).build();
Message<String> result = messageStore.addMessage(copy);
assertNotSame(saved, result);
assertThat(saved, sameExceptIgnorableHeaders(result, "newHeader"));
assertNotNull(messageStore.getMessage(saved.getHeaders().getId()));
assertThat(result).isNotSameAs(saved);
assertThat(saved).matches(new MessagePredicate(result, "newHeader"));
assertThat(messageStore.getMessage(saved.getHeaders().getId())).isNotNull();
}
@Test
@Transactional
public void testAddAndRemoveMessageGroup() throws Exception {
public void testAddAndRemoveMessageGroup() {
Message<String> message = MessageBuilder.withPayload("foo").build();
message = messageStore.addMessage(message);
assertNotNull(messageStore.removeMessage(message.getHeaders().getId()));
assertThat(messageStore.removeMessage(message.getHeaders().getId())).isNotNull();
}
@Test
@Transactional
public void testAddAndGetMessageGroup() throws Exception {
public void testAddAndGetMessageGroup() {
String groupId = "X";
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
long now = System.currentTimeMillis();
messageStore.addMessageToGroup(groupId, message);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(1, group.size());
assertTrue("Timestamp too early: " + group.getTimestamp() + "<" + now, group.getTimestamp() >= now);
assertThat(group.size()).isEqualTo(1);
assertThat(group.getTimestamp() >= now).as("Timestamp too early: " + group.getTimestamp() + "<" + now).isTrue();
}
@Test
@Transactional
public void testAddAndRemoveMessageFromMessageGroup() throws Exception {
public void testAddAndRemoveMessageFromMessageGroup() {
String groupId = "X";
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
messageStore.addMessageToGroup(groupId, message);
messageStore.removeMessagesFromGroup(groupId, message);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
assertThat(group.size()).isEqualTo(0);
}
@Test
@Transactional
public void testRemoveMessageGroup() throws Exception {
public void testRemoveMessageGroup() {
JdbcTemplate template = new JdbcTemplate(dataSource);
template.afterPropertiesSet();
String groupId = "X";
@@ -278,52 +272,52 @@ public class MySqlJdbcMessageStoreTests {
messageStore.addMessageToGroup(groupId, message);
messageStore.removeMessageGroup(groupId);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
assertThat(group.size()).isEqualTo(0);
String uuidGroupId = UUIDConverter.getUUID(groupId).toString();
assertTrue(template.queryForList(
"SELECT * from INT_GROUP_TO_MESSAGE where GROUP_KEY = '" + uuidGroupId + "'").size() == 0);
assertThat(template.queryForList(
"SELECT * from INT_GROUP_TO_MESSAGE where GROUP_KEY = '" + uuidGroupId + "'").size() == 0).isTrue();
}
@Test
@Transactional
public void testCompleteMessageGroup() throws Exception {
public void testCompleteMessageGroup() {
String groupId = "X";
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
messageStore.addMessageToGroup(groupId, message);
messageStore.completeGroup(groupId);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertTrue(group.isComplete());
assertEquals(1, group.size());
assertThat(group.isComplete()).isTrue();
assertThat(group.size()).isEqualTo(1);
}
@Test
@Transactional
public void testUpdateLastReleasedSequence() throws Exception {
public void testUpdateLastReleasedSequence() {
String groupId = "X";
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
messageStore.addMessageToGroup(groupId, message);
messageStore.setLastReleasedSequenceNumberForGroup(groupId, 5);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(5, group.getLastReleasedMessageSequenceNumber());
assertThat(group.getLastReleasedMessageSequenceNumber()).isEqualTo(5);
}
@Test
@Transactional
public void testMessageGroupCount() throws Exception {
public void testMessageGroupCount() {
String groupId = "X";
Message<String> message = MessageBuilder.withPayload("foo").build();
messageStore.addMessageToGroup(groupId, message);
assertEquals(1, messageStore.getMessageGroupCount());
assertThat(messageStore.getMessageGroupCount()).isEqualTo(1);
}
@Test
@Transactional
public void testMessageGroupSizes() throws Exception {
public void testMessageGroupSizes() {
String groupId = "X";
Message<String> message = MessageBuilder.withPayload("foo").build();
messageStore.addMessageToGroup(groupId, message);
assertEquals(1, messageStore.getMessageCountForAllMessageGroups());
assertThat(messageStore.getMessageCountForAllMessageGroups()).isEqualTo(1);
}
@Test
@@ -335,9 +329,9 @@ public class MySqlJdbcMessageStoreTests {
Thread.sleep(1);
messageStore.addMessageToGroup(groupId, MessageBuilder.withPayload("bar").setCorrelationId(groupId).build());
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(2, group.size());
assertEquals("foo", messageStore.pollMessageFromGroup(groupId).getPayload());
assertEquals("bar", messageStore.pollMessageFromGroup(groupId).getPayload());
assertThat(group.size()).isEqualTo(2);
assertThat(messageStore.pollMessageFromGroup(groupId).getPayload()).isEqualTo("foo");
assertThat(messageStore.pollMessageFromGroup(groupId).getPayload()).isEqualTo("bar");
}
@Test
@@ -351,12 +345,12 @@ public class MySqlJdbcMessageStoreTests {
Thread.sleep(1000);
messageStore.expireMessageGroups(2000);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(1, group.size());
assertThat(group.size()).isEqualTo(1);
messageStore.addMessageToGroup(groupId, MessageBuilder.withPayload("bar").setCorrelationId(groupId).build());
Thread.sleep(2001);
messageStore.expireMessageGroups(2000);
group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
assertThat(group.size()).isEqualTo(0);
}
@Test
@@ -371,15 +365,15 @@ public class MySqlJdbcMessageStoreTests {
Thread.sleep(1000);
messageStore.expireMessageGroups(2000);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(1, group.size());
assertThat(group.size()).isEqualTo(1);
Thread.sleep(2000);
messageStore.addMessageToGroup(groupId, MessageBuilder.withPayload("bar").setCorrelationId(groupId).build());
group = messageStore.getMessageGroup(groupId);
assertEquals(2, group.size());
assertThat(group.size()).isEqualTo(2);
Thread.sleep(2000);
messageStore.expireMessageGroups(2000);
group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
assertThat(group.size()).isEqualTo(0);
}
@Test
@@ -399,29 +393,28 @@ public class MySqlJdbcMessageStoreTests {
messageStore.addMessageToGroup("Y", MessageBuilder.withPayload("bazA").setCorrelationId(groupX).build());
Thread.sleep(100);
MessageGroup group = messageStore.getMessageGroup(groupX);
assertEquals(3, group.size());
assertThat(group.size()).isEqualTo(3);
Message<?> message1 = messageStore.pollMessageFromGroup(groupX);
assertNotNull(message1);
assertEquals("foo", message1.getPayload());
assertThat(message1).isNotNull();
assertThat(message1.getPayload()).isEqualTo("foo");
group = messageStore.getMessageGroup(groupX);
assertEquals(2, group.size());
assertThat(group.size()).isEqualTo(2);
Message<?> message2 = messageStore.pollMessageFromGroup(groupX);
assertNotNull(message2);
assertEquals("bar", message2.getPayload());
assertThat(message2).isNotNull();
assertThat(message2.getPayload()).isEqualTo("bar");
group = messageStore.getMessageGroup(groupX);
assertEquals(1, group.size());
assertThat(group.size()).isEqualTo(1);
}
@Test
@Transactional
@Rollback(false)
@Repeat(20)
public void testSameMessageToMultipleGroups() throws Exception {
public void testSameMessageToMultipleGroups() {
final String group1Id = "group1";
final String group2Id = "group2";
@@ -442,14 +435,18 @@ public class MySqlJdbcMessageStoreTests {
final Message<?> messageFromGroup1 = messageStore.pollMessageFromGroup(group1Id);
final Message<?> messageFromGroup2 = messageStore.pollMessageFromGroup(group2Id);
assertNotNull(messageFromGroup1);
assertNotNull(messageFromGroup2);
assertThat(messageFromGroup1).isNotNull();
assertThat(messageFromGroup2).isNotNull();
LOG.info("messageFromGroup1: " + messageFromGroup1.getHeaders().getId() + "; Sequence #: " + new IntegrationMessageHeaderAccessor(messageFromGroup1).getSequenceNumber());
LOG.info("messageFromGroup2: " + messageFromGroup2.getHeaders().getId() + "; Sequence #: " + new IntegrationMessageHeaderAccessor(messageFromGroup2).getSequenceNumber());
LOG.info("messageFromGroup1: " + messageFromGroup1.getHeaders().getId()
+ "; Sequence #: " + new IntegrationMessageHeaderAccessor(messageFromGroup1).getSequenceNumber());
LOG.info("messageFromGroup2: " + messageFromGroup2.getHeaders().getId()
+ "; Sequence #: " + new IntegrationMessageHeaderAccessor(messageFromGroup2).getSequenceNumber());
assertEquals(Integer.valueOf(1), messageFromGroup1.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER));
assertEquals(Integer.valueOf(2), messageFromGroup2.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER));
assertThat(messageFromGroup1.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER))
.isEqualTo(1);
assertThat(messageFromGroup2.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER))
.isEqualTo(2);
}
@@ -457,8 +454,7 @@ public class MySqlJdbcMessageStoreTests {
@Transactional
@Rollback(false)
@Repeat(20)
public void testSameMessageAndGroupToMultipleRegions() throws Exception {
public void testSameMessageAndGroupToMultipleRegions() {
final String groupId = "myGroup";
final String region1 = "region1";
final String region2 = "region2";
@@ -486,15 +482,18 @@ public class MySqlJdbcMessageStoreTests {
final Message<?> messageFromRegion1 = messageStore1.pollMessageFromGroup(groupId);
final Message<?> messageFromRegion2 = messageStore2.pollMessageFromGroup(groupId);
assertNotNull(messageFromRegion1);
assertNotNull(messageFromRegion2);
assertThat(messageFromRegion1).isNotNull();
assertThat(messageFromRegion2).isNotNull();
LOG.info("messageFromRegion1: " + messageFromRegion1.getHeaders().getId() + "; Sequence #: " + new IntegrationMessageHeaderAccessor(messageFromRegion1).getSequenceNumber());
LOG.info("messageFromRegion2: " + messageFromRegion2.getHeaders().getId() + "; Sequence #: " + new IntegrationMessageHeaderAccessor(messageFromRegion2).getSequenceNumber());
assertEquals(Integer.valueOf(1), messageFromRegion1.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER));
assertEquals(Integer.valueOf(2), messageFromRegion2.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER));
LOG.info("messageFromRegion1: " + messageFromRegion1.getHeaders().getId()
+ "; Sequence #: " + new IntegrationMessageHeaderAccessor(messageFromRegion1).getSequenceNumber());
LOG.info("messageFromRegion2: " + messageFromRegion2.getHeaders().getId()
+ "; Sequence #: " + new IntegrationMessageHeaderAccessor(messageFromRegion2).getSequenceNumber());
assertThat(messageFromRegion1.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER))
.isEqualTo(1);
assertThat(messageFromRegion2.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER))
.isEqualTo(2);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,13 +16,8 @@
package org.springframework.integration.jdbc.store;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.io.NotSerializableException;
import java.util.List;
@@ -30,7 +25,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -106,7 +100,7 @@ public class JdbcMessageStoreChannelIntegrationTests {
public void testSendAndActivate() throws Exception {
input.send(new GenericMessage<>("foo"));
Service.await(10000);
assertEquals(1, Service.messages.size());
assertThat(Service.messages.size()).isEqualTo(1);
}
@Test
@@ -114,7 +108,7 @@ public class JdbcMessageStoreChannelIntegrationTests {
Service.fail = true;
input.send(new GenericMessage<>("foo"));
Service.await(10000);
assertThat(Service.messages.size(), Matchers.greaterThanOrEqualTo(1));
assertThat(Service.messages.size()).isGreaterThanOrEqualTo(1);
// After a rollback in the poller the message is still waiting to be delivered
// but unless we use a transaction here there is a chance that the queue will
// appear empty....
@@ -122,8 +116,8 @@ public class JdbcMessageStoreChannelIntegrationTests {
synchronized (storeLock) {
assertEquals(1, input.getQueueSize());
assertNotNull(input.receive(100L));
assertThat(input.getQueueSize()).isEqualTo(1);
assertThat(input.receive(100L)).isNotNull();
}
return null;
@@ -155,7 +149,7 @@ public class JdbcMessageStoreChannelIntegrationTests {
});
assertTrue("Could not send message", result);
assertThat(result).as("Could not send message").isTrue();
waitForMessage();
@@ -170,7 +164,7 @@ public class JdbcMessageStoreChannelIntegrationTests {
}
// If the poll blocks in the RDBMS there is no way for the queue to respect the timeout
assertTrue("Timed out waiting for receive", stopWatch.getTotalTimeMillis() < 10000);
assertThat(stopWatch.getTotalTimeMillis() < 10000).as("Timed out waiting for receive").isTrue();
}
@@ -183,7 +177,7 @@ public class JdbcMessageStoreChannelIntegrationTests {
Thread.sleep(50);
}
assertEquals(1, Service.messages.size());
assertThat(Service.messages.size()).isEqualTo(1);
}
@Test
@@ -213,7 +207,7 @@ public class JdbcMessageStoreChannelIntegrationTests {
try {
stopWatch.start();
assertNotNull(input.receive(100L));
assertThat(input.receive(100L)).isNotNull();
}
finally {
stopWatch.stop();
@@ -225,13 +219,13 @@ public class JdbcMessageStoreChannelIntegrationTests {
});
assertTrue("Could not send message", result);
assertThat(result).as("Could not send message").isTrue();
// So no activation
assertEquals(0, Service.messages.size());
assertThat(Service.messages.size()).isEqualTo(0);
// If the poll blocks in the RDBMS there is no way for the queue to respect the timeout
assertTrue("Timed out waiting for receive", stopWatch.getTotalTimeMillis() < 1000);
assertThat(stopWatch.getTotalTimeMillis() < 1000).as("Timed out waiting for receive").isTrue();
}
@@ -242,11 +236,11 @@ public class JdbcMessageStoreChannelIntegrationTests {
fail("MessageDeliveryException expected");
}
catch (Exception e) {
assertThat(e, instanceOf(MessageDeliveryException.class));
assertThat(e.getCause(), instanceOf(SerializationFailedException.class));
assertThat(e.getCause().getCause(), instanceOf(NotSerializableException.class));
assertThat(e.getMessage(),
containsString("org.springframework.integration.routingslip.ExpressionEvaluatingRoutingSlipRouteStrategy"));
assertThat(e).isInstanceOf(MessageDeliveryException.class);
assertThat(e.getCause()).isInstanceOf(SerializationFailedException.class);
assertThat(e.getCause().getCause()).isInstanceOf(NotSerializableException.class);
assertThat(e.getMessage())
.contains("org.springframework.integration.routingslip.ExpressionEvaluatingRoutingSlipRouteStrategy");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,10 +16,8 @@
package org.springframework.integration.jdbc.store;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -89,8 +87,8 @@ public class JdbcMessageStoreChannelOnePollerIntegrationTests {
@Test
public void testSameTransactionDifferentChannelSendAndReceive() throws Exception {
Service.reset(1);
assertNull(this.durable.receive(100L));
assertNull(this.relay.receive(100L));
assertThat(this.durable.receive(100L)).isNull();
assertThat(this.relay.receive(100L)).isNull();
final StopWatch stopWatch = new StopWatch();
boolean result =
@@ -112,7 +110,7 @@ public class JdbcMessageStoreChannelOnePollerIntegrationTests {
try {
stopWatch.start();
// It hasn't arrive yet because we are still in the sending transaction
assertNull(this.durable.receive(100L));
assertThat(this.durable.receive(100L)).isNull();
}
finally {
stopWatch.stop();
@@ -124,13 +122,13 @@ public class JdbcMessageStoreChannelOnePollerIntegrationTests {
});
assertTrue("Could not send message", result);
assertThat(result).as("Could not send message").isTrue();
// If the poll blocks in the RDBMS there is no way for the queue to respect the timeout
assertTrue("Timed out waiting for receive", stopWatch.getTotalTimeMillis() < 10000);
assertThat(stopWatch.getTotalTimeMillis() < 10000).as("Timed out waiting for receive").isTrue();
Service.await(10000);
// Eventual activation
assertEquals(1, Service.messages.size());
assertThat(Service.messages.size()).isEqualTo(1);
/*
* Without the storeLock:
@@ -157,7 +155,7 @@ public class JdbcMessageStoreChannelOnePollerIntegrationTests {
});
// If the poll blocks in the RDBMS there is no way for the queue to respect the timeout
assertTrue("Timed out waiting for receive", stopWatch.getTotalTimeMillis() < 10000);
assertThat(stopWatch.getTotalTimeMillis() < 10000).as("Timed out waiting for receive").isTrue();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,9 +16,8 @@
package org.springframework.integration.jdbc.store;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -91,9 +90,9 @@ public class JdbcMessageStoreChannelTests {
@Test
public void testSendAndActivate() throws InterruptedException {
this.input.send(new GenericMessage<>("foo"));
assertTrue(this.afterCommitLatch.await(10, TimeUnit.SECONDS));
assertEquals(1, Service.messages.size());
assertEquals(0, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size());
assertThat(this.afterCommitLatch.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(Service.messages.size()).isEqualTo(1);
assertThat(messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size()).isEqualTo(0);
}
@Test
@@ -101,9 +100,9 @@ public class JdbcMessageStoreChannelTests {
Service.fail = true;
input.send(new GenericMessage<>("foo"));
Service.await(10000);
assertEquals(1, Service.messages.size());
assertThat(Service.messages.size()).isEqualTo(1);
// After a rollback in the poller the message is still waiting to be delivered
assertEquals(1, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size());
assertThat(messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size()).isEqualTo(1);
}
@Test
@@ -119,9 +118,9 @@ public class JdbcMessageStoreChannelTests {
// expected
}
// So no activation
assertEquals(0, Service.messages.size());
assertThat(Service.messages.size()).isEqualTo(0);
// But inside the transaction the message is still there
assertEquals(1, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size());
assertThat(messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size()).isEqualTo(1);
}
public static class Service {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,13 +16,13 @@
package org.springframework.integration.jdbc.store;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.util.List;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -84,8 +84,8 @@ public class JdbcMessageStoreRegionTests {
messageStore2.addMessage(MessageBuilder.withPayload("payload1").build());
messageStore2.addMessage(MessageBuilder.withPayload("payload2").build());
assertEquals(2, messageStore1.getMessageCount());
assertEquals(2, messageStore2.getMessageCount());
assertThat(messageStore1.getMessageCount()).isEqualTo(2);
assertThat(messageStore2.getMessageCount()).isEqualTo(2);
}
@@ -96,11 +96,11 @@ public class JdbcMessageStoreRegionTests {
messageStore1.setRegion(null);
}
catch (IllegalArgumentException e) {
Assert.assertEquals("Region must not be null or empty.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("Region must not be null or empty.");
return;
}
Assert.fail("Expected an IllegalArgumentException to be thrown.");
fail("Expected an IllegalArgumentException to be thrown.");
}
@Test
@@ -112,13 +112,13 @@ public class JdbcMessageStoreRegionTests {
messageStore2.addMessageToGroup("group1", MessageBuilder.withPayload("payload1").build());
messageStore2.addMessageToGroup("group2", MessageBuilder.withPayload("payload2").build());
assertEquals(1, messageStore1.getMessageGroup("group1").getMessages().size());
assertEquals(1, messageStore2.getMessageGroup("group1").getMessages().size());
assertEquals(1, messageStore1.getMessageGroup("group2").getMessages().size());
assertEquals(1, messageStore2.getMessageGroup("group2").getMessages().size());
assertThat(messageStore1.getMessageGroup("group1").getMessages().size()).isEqualTo(1);
assertThat(messageStore2.getMessageGroup("group1").getMessages().size()).isEqualTo(1);
assertThat(messageStore1.getMessageGroup("group2").getMessages().size()).isEqualTo(1);
assertThat(messageStore2.getMessageGroup("group2").getMessages().size()).isEqualTo(1);
assertEquals(2, messageStore1.getMessageCount());
assertEquals(2, messageStore2.getMessageCount());
assertThat(messageStore1.getMessageCount()).isEqualTo(2);
assertThat(messageStore2.getMessageCount()).isEqualTo(2);
}
@@ -130,16 +130,16 @@ public class JdbcMessageStoreRegionTests {
List<String> regions = jdbcTemplate.query("Select * from INT_MESSAGE_GROUP where REGION = 'region1'",
(RowMapper<String>) (rs, rowNum) -> rs.getString("REGION"));
assertEquals(1, regions.size());
assertEquals("region1", regions.get(0));
assertThat(regions.size()).isEqualTo(1);
assertThat(regions.get(0)).isEqualTo("region1");
messageStore2.addMessageToGroup("group1", MessageBuilder.withPayload("payload1").build());
List<String> regions2 = jdbcTemplate.query("Select * from INT_MESSAGE_GROUP where REGION = 'region2'",
(RowMapper<String>) (rs, rowNum) -> rs.getString("REGION"));
assertEquals(1, regions2.size());
assertEquals("region2", regions2.get(0));
assertThat(regions2.size()).isEqualTo(1);
assertThat(regions2.get(0)).isEqualTo("region2");
}
@@ -154,8 +154,8 @@ public class JdbcMessageStoreRegionTests {
messageStore1.removeMessageGroup("group1");
assertEquals(1, messageStore1.getMessageGroupCount());
assertEquals(2, messageStore2.getMessageGroupCount());
assertThat(messageStore1.getMessageGroupCount()).isEqualTo(1);
assertThat(messageStore2.getMessageGroupCount()).isEqualTo(2);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2019 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,13 +16,7 @@
package org.springframework.integration.jdbc.store;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.springframework.integration.test.matcher.PayloadAndHeaderMatcher.sameExceptIgnorableHeaders;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.BufferedReader;
import java.io.InputStreamReader;
@@ -46,6 +40,7 @@ import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.history.MessageHistory;
import org.springframework.integration.store.MessageGroup;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.predicate.MessagePredicate;
import org.springframework.integration.util.UUIDConverter;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementSetter;
@@ -82,24 +77,24 @@ public class JdbcMessageStoreTests {
}
@Test
public void testGetNonExistent() throws Exception {
public void testGetNonExistent() {
Message<?> result = messageStore.getMessage(UUID.randomUUID());
assertNull(result);
assertThat(result).isNull();
}
@Test
public void testAddAndGet() throws Exception {
public void testAddAndGet() {
Message<String> message = MessageBuilder.withPayload("foo").build();
Message<String> saved = messageStore.addMessage(message);
Message<?> result = messageStore.getMessage(saved.getHeaders().getId());
assertNotNull(result);
assertThat(saved, sameExceptIgnorableHeaders(result));
assertThat(result).isNotNull();
assertThat(saved).matches(new MessagePredicate(result));
}
@Test
public void testWithMessageHistory() throws Exception {
public void testWithMessageHistory() {
Message<?> message = new GenericMessage<String>("Hello");
Message<?> message = new GenericMessage<>("Hello");
DirectChannel fooChannel = new DirectChannel();
fooChannel.setBeanName("fooChannel");
DirectChannel barChannel = new DirectChannel();
@@ -110,93 +105,93 @@ public class JdbcMessageStoreTests {
messageStore.addMessage(message);
message = messageStore.getMessage(message.getHeaders().getId());
MessageHistory messageHistory = MessageHistory.read(message);
assertNotNull(messageHistory);
assertEquals(2, messageHistory.size());
assertThat(messageHistory).isNotNull();
assertThat(messageHistory.size()).isEqualTo(2);
Properties fooChannelHistory = messageHistory.get(0);
assertEquals("fooChannel", fooChannelHistory.get("name"));
assertEquals("channel", fooChannelHistory.get("type"));
assertThat(fooChannelHistory.get("name")).isEqualTo("fooChannel");
assertThat(fooChannelHistory.get("type")).isEqualTo("channel");
}
@Test
public void testSize() throws Exception {
public void testSize() {
Message<String> message = MessageBuilder.withPayload("foo").build();
messageStore.addMessage(message);
assertEquals(1, messageStore.getMessageCount());
assertThat(messageStore.getMessageCount()).isEqualTo(1);
}
@Test
public void testSerializer() throws Exception {
public void testSerializer() {
// N.B. these serializers are not realistic (just for test purposes)
messageStore.setSerializer((object, outputStream) -> {
outputStream.write(((Message<?>) object).getPayload().toString().getBytes());
outputStream.write(object.getPayload().toString().getBytes());
outputStream.flush();
});
messageStore.setDeserializer(inputStream -> {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
return new GenericMessage<String>(reader.readLine());
return new GenericMessage<>(reader.readLine());
});
Message<String> message = MessageBuilder.withPayload("foo").build();
Message<String> saved = messageStore.addMessage(message);
assertNotNull(messageStore.getMessage(message.getHeaders().getId()));
assertThat(messageStore.getMessage(message.getHeaders().getId())).isNotNull();
Message<?> result = messageStore.getMessage(saved.getHeaders().getId());
assertNotNull(result);
assertEquals("foo", result.getPayload());
assertThat(result).isNotNull();
assertThat(result.getPayload()).isEqualTo("foo");
}
@Test
public void testAddAndGetWithDifferentRegion() throws Exception {
public void testAddAndGetWithDifferentRegion() {
Message<String> message = MessageBuilder.withPayload("foo").build();
Message<String> saved = messageStore.addMessage(message);
messageStore.setRegion("FOO");
Message<?> result = messageStore.getMessage(saved.getHeaders().getId());
assertNull(result);
assertThat(result).isNull();
}
@Test
public void testAddAndUpdate() throws Exception {
public void testAddAndUpdate() {
Message<?> message = MessageBuilder.withPayload("foo").setCorrelationId("X").build();
message = messageStore.addMessage(message);
message = MessageBuilder.fromMessage(message).setCorrelationId("Y").build();
message = messageStore.addMessage(message);
message = messageStore.getMessage(message.getHeaders().getId());
assertEquals("Y", new IntegrationMessageHeaderAccessor(message).getCorrelationId());
assertThat(new IntegrationMessageHeaderAccessor(message).getCorrelationId()).isEqualTo("Y");
}
@Test
public void testAddAndUpdateAlreadySaved() throws Exception {
public void testAddAndUpdateAlreadySaved() {
Message<String> message = MessageBuilder.withPayload("foo").build();
message = messageStore.addMessage(message);
Message<String> result = messageStore.addMessage(message);
assertEquals(message, result);
assertThat(result).isEqualTo(message);
}
@Test
public void testAddAndUpdateAlreadySavedAndCopied() throws Exception {
public void testAddAndUpdateAlreadySavedAndCopied() {
Message<String> message = MessageBuilder.withPayload("foo").build();
Message<String> saved = messageStore.addMessage(message);
Message<String> copy = MessageBuilder.fromMessage(saved).build();
Message<String> result = messageStore.addMessage(copy);
assertEquals(copy, result);
assertEquals(saved, result);
assertNotNull(messageStore.getMessage(saved.getHeaders().getId()));
assertThat(result).isEqualTo(copy);
assertThat(result).isEqualTo(saved);
assertThat(messageStore.getMessage(saved.getHeaders().getId())).isNotNull();
}
@Test
public void testAddAndUpdateWithChange() throws Exception {
public void testAddAndUpdateWithChange() {
Message<String> message = MessageBuilder.withPayload("foo").build();
Message<String> saved = messageStore.addMessage(message);
Message<String> copy = MessageBuilder.fromMessage(saved).setHeader("newHeader", 1).build();
Message<String> result = messageStore.addMessage(copy);
assertNotSame(saved, result);
assertThat(saved, sameExceptIgnorableHeaders(result, "newHeader"));
assertNotNull(messageStore.getMessage(saved.getHeaders().getId()));
assertThat(result).isNotSameAs(saved);
assertThat(saved).matches(new MessagePredicate(result, "newHeader"));
assertThat(messageStore.getMessage(saved.getHeaders().getId())).isNotNull();
}
@Test
public void testAddAndRemoveMessageGroup() throws Exception {
Message<String> message = MessageBuilder.withPayload("foo").build();
message = messageStore.addMessage(message);
assertNotNull(messageStore.removeMessage(message.getHeaders().getId()));
assertThat(messageStore.removeMessage(message.getHeaders().getId())).isNotNull();
}
@Test
@@ -206,8 +201,8 @@ public class JdbcMessageStoreTests {
long now = System.currentTimeMillis();
messageStore.addMessagesToGroup(groupId, message);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(1, group.size());
assertTrue("Timestamp too early: " + group.getTimestamp() + "<" + now, group.getTimestamp() >= now);
assertThat(group.size()).isEqualTo(1);
assertThat(group.getTimestamp() >= now).as("Timestamp too early: " + group.getTimestamp() + "<" + now).isTrue();
}
@Test
@@ -217,7 +212,7 @@ public class JdbcMessageStoreTests {
messageStore.addMessagesToGroup(groupId, message);
messageStore.removeMessagesFromGroup(groupId, message);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
assertThat(group.size()).isEqualTo(0);
}
@Test
@@ -231,10 +226,10 @@ public class JdbcMessageStoreTests {
}
this.messageStore.addMessagesToGroup(groupId, messages.toArray(new Message<?>[messages.size()]));
MessageGroup group = this.messageStore.getMessageGroup(groupId);
assertEquals(25, group.size());
assertThat(group.size()).isEqualTo(25);
this.messageStore.removeMessagesFromGroup(groupId, messages);
group = this.messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
assertThat(group.size()).isEqualTo(0);
}
@Test
@@ -247,11 +242,11 @@ public class JdbcMessageStoreTests {
messageStore.addMessagesToGroup(groupId, message);
messageStore.removeMessageGroup(groupId);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
assertThat(group.size()).isEqualTo(0);
String uuidGroupId = UUIDConverter.getUUID(groupId).toString();
assertTrue(template.queryForList(
"SELECT * from INT_GROUP_TO_MESSAGE where GROUP_KEY = ?", uuidGroupId).size() == 0);
assertThat(template.queryForList(
"SELECT * from INT_GROUP_TO_MESSAGE where GROUP_KEY = ?", uuidGroupId).size() == 0).isTrue();
}
@Test
@@ -261,8 +256,8 @@ public class JdbcMessageStoreTests {
messageStore.addMessagesToGroup(groupId, message);
messageStore.completeGroup(groupId);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertTrue(group.isComplete());
assertEquals(1, group.size());
assertThat(group.isComplete()).isTrue();
assertThat(group.size()).isEqualTo(1);
}
@Test
@@ -272,7 +267,7 @@ public class JdbcMessageStoreTests {
messageStore.addMessagesToGroup(groupId, message);
messageStore.setLastReleasedSequenceNumberForGroup(groupId, 5);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(5, group.getLastReleasedMessageSequenceNumber());
assertThat(group.getLastReleasedMessageSequenceNumber()).isEqualTo(5);
}
@Test
@@ -280,7 +275,7 @@ public class JdbcMessageStoreTests {
String groupId = "X";
Message<String> message = MessageBuilder.withPayload("foo").build();
messageStore.addMessagesToGroup(groupId, message);
assertEquals(1, messageStore.getMessageGroupCount());
assertThat(messageStore.getMessageGroupCount()).isEqualTo(1);
}
@Test
@@ -288,7 +283,7 @@ public class JdbcMessageStoreTests {
String groupId = "X";
Message<String> message = MessageBuilder.withPayload("foo").build();
messageStore.addMessagesToGroup(groupId, message);
assertEquals(1, messageStore.getMessageCountForAllMessageGroups());
assertThat(messageStore.getMessageCountForAllMessageGroups()).isEqualTo(1);
}
@Test
@@ -301,9 +296,9 @@ public class JdbcMessageStoreTests {
this.messageStore.addMessagesToGroup(groupId,
MessageBuilder.withPayload("bar").setCorrelationId(groupId).build());
MessageGroup group = this.messageStore.getMessageGroup(groupId);
assertEquals(2, group.size());
assertEquals("foo", this.messageStore.pollMessageFromGroup(groupId).getPayload());
assertEquals("bar", this.messageStore.pollMessageFromGroup(groupId).getPayload());
assertThat(group.size()).isEqualTo(2);
assertThat(this.messageStore.pollMessageFromGroup(groupId).getPayload()).isEqualTo("foo");
assertThat(this.messageStore.pollMessageFromGroup(groupId).getPayload()).isEqualTo("bar");
}
@Test
@@ -319,7 +314,7 @@ public class JdbcMessageStoreTests {
messageStore.expireMessageGroups(2000);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(1, group.size());
assertThat(group.size()).isEqualTo(1);
messageStore.addMessagesToGroup(groupId, MessageBuilder.withPayload("bar").setCorrelationId(groupId).build());
@@ -336,8 +331,8 @@ public class JdbcMessageStoreTests {
messageStore.expireMessageGroups(2000);
group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
assertTrue(groupRemovalLatch.await(10, TimeUnit.SECONDS));
assertThat(group.size()).isEqualTo(0);
assertThat(groupRemovalLatch.await(10, TimeUnit.SECONDS)).isTrue();
}
@Test
@@ -346,7 +341,8 @@ public class JdbcMessageStoreTests {
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
messageStore.setTimeoutOnIdle(true);
messageStore.addMessagesToGroup(groupId, message);
messageStore.registerMessageGroupExpiryCallback((messageGroupStore, group) -> messageGroupStore.removeMessageGroup(group.getGroupId()));
messageStore.registerMessageGroupExpiryCallback((messageGroupStore, group) -> messageGroupStore
.removeMessageGroup(group.getGroupId()));
JdbcTemplate template = new JdbcTemplate(this.dataSource);
template.afterPropertiesSet();
@@ -355,19 +351,19 @@ public class JdbcMessageStoreTests {
messageStore.expireMessageGroups(2000);
MessageGroup group = messageStore.getMessageGroup(groupId);
assertEquals(1, group.size());
assertThat(group.size()).isEqualTo(1);
updateMessageGroup(template, groupId, 2000);
messageStore.addMessagesToGroup(groupId, MessageBuilder.withPayload("bar").setCorrelationId(groupId).build());
group = messageStore.getMessageGroup(groupId);
assertEquals(2, group.size());
assertThat(group.size()).isEqualTo(2);
updateMessageGroup(template, groupId, 2000);
messageStore.expireMessageGroups(2000);
group = messageStore.getMessageGroup(groupId);
assertEquals(0, group.size());
assertThat(group.size()).isEqualTo(0);
}
private void updateMessageGroup(JdbcTemplate template, final String groupId, final long timeout) {
@@ -394,21 +390,21 @@ public class JdbcMessageStoreTests {
MessageBuilder.withPayload("bazA").setCorrelationId(groupId).build());
MessageGroup group = messageStore.getMessageGroup("X");
assertEquals(3, group.size());
assertThat(group.size()).isEqualTo(3);
Message<?> message1 = messageStore.pollMessageFromGroup("X");
assertNotNull(message1);
assertEquals("foo", message1.getPayload());
assertThat(message1).isNotNull();
assertThat(message1.getPayload()).isEqualTo("foo");
group = messageStore.getMessageGroup("X");
assertEquals(2, group.size());
assertThat(group.size()).isEqualTo(2);
Message<?> message2 = messageStore.pollMessageFromGroup("X");
assertNotNull(message2);
assertEquals("bar", message2.getPayload());
assertThat(message2).isNotNull();
assertThat(message2.getPayload()).isEqualTo("bar");
group = messageStore.getMessageGroup("X");
assertEquals(1, group.size());
assertThat(group.size()).isEqualTo(1);
}
@Test
@@ -434,11 +430,11 @@ public class JdbcMessageStoreTests {
final Message<?> messageFromGroup1 = messageStore.pollMessageFromGroup(group1Id);
final Message<?> messageFromGroup2 = messageStore.pollMessageFromGroup(group2Id);
assertNotNull(messageFromGroup1);
assertNotNull(messageFromGroup2);
assertThat(messageFromGroup1).isNotNull();
assertThat(messageFromGroup2).isNotNull();
assertEquals(1, messageFromGroup1.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER));
assertEquals(2, messageFromGroup2.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER));
assertThat(messageFromGroup1.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER)).isEqualTo(1);
assertThat(messageFromGroup2.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER)).isEqualTo(2);
}
@@ -472,11 +468,11 @@ public class JdbcMessageStoreTests {
final Message<?> messageFromRegion1 = messageStore1.pollMessageFromGroup(groupId);
final Message<?> messageFromRegion2 = messageStore2.pollMessageFromGroup(groupId);
assertNotNull(messageFromRegion1);
assertNotNull(messageFromRegion2);
assertThat(messageFromRegion1).isNotNull();
assertThat(messageFromRegion2).isNotNull();
assertEquals(1, messageFromRegion1.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER));
assertEquals(2, messageFromRegion2.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER));
assertThat(messageFromRegion1.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER)).isEqualTo(1);
assertThat(messageFromRegion2.getHeaders().get(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER)).isEqualTo(2);
}
@@ -510,8 +506,8 @@ public class JdbcMessageStoreTests {
//add to the messageStore
messageStore.addMessagesToGroup(groupId, oneOfTwo, twoOfTwo);
//check that 2 messages are there
assertTrue(messageStore.getMessageGroupCount() == 1);
assertTrue(messageStore.getMessageCount() == 2);
assertThat(messageStore.getMessageGroupCount() == 1).isTrue();
assertThat(messageStore.getMessageCount() == 2).isTrue();
//retrieve the group (like in the aggregator)
MessageGroup messageGroup = messageStore.getMessageGroup(groupId);
//'complete' the group
@@ -523,7 +519,7 @@ public class JdbcMessageStoreTests {
//'add' the other message --> emulated by getting the messageGroup
messageGroup = messageStore.getMessageGroup(groupId);
//should be marked 'complete' --> old behavior it would not
assertTrue(messageGroup.isComplete());
assertThat(messageGroup.isComplete()).isTrue();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,9 +16,7 @@
package org.springframework.integration.jdbc.store.channel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
import java.sql.PreparedStatement;
import java.sql.SQLException;
@@ -81,13 +79,13 @@ public abstract class AbstractJdbcChannelMessageStoreTests {
}
@Test
public void testGetNonExistentMessageFromGroup() throws Exception {
public void testGetNonExistentMessageFromGroup() {
Message<?> result = messageStore.pollMessageFromGroup(TEST_MESSAGE_GROUP);
assertNull(result);
assertThat(result).isNull();
}
@Test
public void testAddAndGet() throws Exception {
public void testAddAndGet() {
final Message<String> message = MessageBuilder.withPayload("Cartman and Kenny")
.setHeader("homeTown", "Southpark")
.build();
@@ -107,8 +105,8 @@ public abstract class AbstractJdbcChannelMessageStoreTests {
Message<?> messageFromDb = messageStore.pollMessageFromGroup(TEST_MESSAGE_GROUP);
assertNotNull(messageFromDb);
assertEquals(message.getHeaders().getId(), messageFromDb.getHeaders().getId());
assertThat(messageFromDb).isNotNull();
assertThat(messageFromDb.getHeaders().getId()).isEqualTo(message.getHeaders().getId());
}
@Test
@@ -129,8 +127,8 @@ public abstract class AbstractJdbcChannelMessageStoreTests {
}
});
Message<?> messageFromDb = messageStore.pollMessageFromGroup(TEST_MESSAGE_GROUP);
assertNotNull(messageFromDb);
assertEquals(message.getHeaders().getId(), messageFromDb.getHeaders().getId());
assertThat(messageFromDb).isNotNull();
assertThat(messageFromDb.getHeaders().getId()).isEqualTo(message.getHeaders().getId());
}
private ChannelMessageStorePreparedStatementSetter getMessageGroupPreparedStatementSetter() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2019 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,10 +16,7 @@
package org.springframework.integration.jdbc.store.channel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import java.util.Map;
@@ -36,8 +33,6 @@ import javax.sql.DataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -118,6 +113,7 @@ public abstract class AbstractTxTimeoutMessageStoreTests {
log.info("Sending message: " + message);
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
inputChannel.send(MessageBuilder.withPayload(message).build());
@@ -129,17 +125,17 @@ public abstract class AbstractTxTimeoutMessageStoreTests {
log.info("Done sending " + maxMessages + " messages.");
Assert.assertTrue(String.format("Countdown latch did not count down from " +
"%s to 0 in %sms.", maxMessages, maxWaitTime), testService.await(maxWaitTime));
assertThat(testService.await(maxWaitTime)).as(String.format("Countdown latch did not count down from " +
"%s to 0 in %sms.", maxMessages, maxWaitTime)).isTrue();
for (int i = 0; i < maxMessages; i++) {
Message<?> afterTxMessage = this.afterTxChannel.receive(10000);
assertNotNull(afterTxMessage);
assertThat(afterTxMessage).isNotNull();
}
Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(jdbcChannelMessageStore.getSizeOfIdCache()));
Assert.assertEquals(Integer.valueOf(maxMessages), Integer.valueOf(testService.getSeenMessages().size()));
Assert.assertEquals(Integer.valueOf(0), Integer.valueOf(testService.getDuplicateMessagesCount()));
assertThat(Integer.valueOf(jdbcChannelMessageStore.getSizeOfIdCache())).isEqualTo(Integer.valueOf(0));
assertThat(Integer.valueOf(testService.getSeenMessages().size())).isEqualTo(Integer.valueOf(maxMessages));
assertThat(Integer.valueOf(testService.getDuplicateMessagesCount())).isEqualTo(Integer.valueOf(0));
}
@Test
@@ -189,11 +185,11 @@ public abstract class AbstractTxTimeoutMessageStoreTests {
}
for (int j = 0; j < concurrency; j++) {
assertTrue(completionService.take().get());
assertThat(completionService.take().get()).isTrue();
}
executorService.shutdown();
assertTrue(executorService.awaitTermination(10, TimeUnit.SECONDS));
assertThat(executorService.awaitTermination(10, TimeUnit.SECONDS)).isTrue();
}
@Test
@@ -202,9 +198,9 @@ public abstract class AbstractTxTimeoutMessageStoreTests {
this.first.send(new GenericMessage<Object>("test"));
}
assertTrue(this.successfulLatch.await(20, TimeUnit.SECONDS));
assertThat(this.successfulLatch.await(20, TimeUnit.SECONDS)).isTrue();
assertEquals(0, errorAtomicInteger.get());
assertThat(errorAtomicInteger.get()).isEqualTo(0);
}
@Test
@@ -218,23 +214,24 @@ public abstract class AbstractTxTimeoutMessageStoreTests {
List<Map<String, Object>> result =
jdbcTemplate.queryForList("SELECT MESSAGE_SEQUENCE FROM INT_CHANNEL_MESSAGE " +
"WHERE GROUP_KEY = ? ORDER BY CREATED_DATE", UUIDConverter.getUUID(messageGroup).toString());
assertEquals(2, result.size());
"WHERE GROUP_KEY = ? ORDER BY CREATED_DATE", UUIDConverter.getUUID(messageGroup).toString());
assertThat(result.size()).isEqualTo(2);
Object messageSequence1 = result.get(0).get("MESSAGE_SEQUENCE");
Object messageSequence2 = result.get(1).get("MESSAGE_SEQUENCE");
assertNotNull(messageSequence1);
assertThat(messageSequence1, Matchers.instanceOf(Number.class));
assertNotNull(messageSequence2);
assertThat(messageSequence2, Matchers.instanceOf(Number.class));
assertThat(messageSequence1).isNotNull();
assertThat(messageSequence1).isInstanceOf(Number.class);
assertThat(messageSequence2).isNotNull();
assertThat(messageSequence2).isInstanceOf(Number.class);
assertThat(((Number) messageSequence1).longValue(), Matchers.lessThan(((Number) messageSequence2).longValue()));
assertThat(((Number) messageSequence1).longValue()).isLessThan(((Number) messageSequence2).longValue());
this.jdbcChannelMessageStore.removeMessageGroup(messageGroup);
}
@Test
public void testPriorityChannel() throws Exception {
Message<String> message = MessageBuilder.withPayload("1").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 1).build();
public void testPriorityChannel() {
Message<String> message = MessageBuilder.withPayload("1")
.setHeader(IntegrationMessageHeaderAccessor.PRIORITY, 1).build();
priorityChannel.send(message);
message = MessageBuilder.withPayload("-1").setHeader(IntegrationMessageHeaderAccessor.PRIORITY, -1).build();
priorityChannel.send(message);
@@ -250,32 +247,32 @@ public abstract class AbstractTxTimeoutMessageStoreTests {
priorityChannel.send(message);
Message<?> receive = priorityChannel.receive(10000);
assertNotNull(receive);
assertEquals("3", receive.getPayload());
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo("3");
receive = priorityChannel.receive(10000);
assertNotNull(receive);
assertEquals("31", receive.getPayload());
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo("31");
receive = priorityChannel.receive(10000);
assertNotNull(receive);
assertEquals("2", receive.getPayload());
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo("2");
receive = priorityChannel.receive(10000);
assertNotNull(receive);
assertEquals("1", receive.getPayload());
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo("1");
receive = priorityChannel.receive(10000);
assertNotNull(receive);
assertEquals("0", receive.getPayload());
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo("0");
receive = priorityChannel.receive(10000);
assertNotNull(receive);
assertEquals("-1", receive.getPayload());
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo("-1");
receive = priorityChannel.receive(10000);
assertNotNull(receive);
assertEquals("none", receive.getPayload());
assertThat(receive).isNotNull();
assertThat(receive.getPayload()).isEqualTo("none");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2019 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.

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2019 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,9 +16,8 @@
package org.springframework.integration.jdbc.storedproc;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import java.util.ArrayList;
import java.util.List;
@@ -35,7 +34,7 @@ public class ProcedureParameterTests {
new ProcedureParameter(null, "value", "expression");
}
catch (IllegalArgumentException e) {
assertEquals("'name' must not be empty.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("'name' must not be empty.");
return;
}
@@ -48,7 +47,7 @@ public class ProcedureParameterTests {
Map<String, String> expressionParameters =
ProcedureParameter.convertExpressions(procedureParameters);
assertTrue("Expected 2 expression parameters.", expressionParameters.size() == 2);
assertThat(expressionParameters.size() == 2).as("Expected 2 expression parameters.").isTrue();
}
@Test
@@ -58,7 +57,7 @@ public class ProcedureParameterTests {
Map<String, Object> staticParameters =
ProcedureParameter.convertStaticParameters(procedureParameters);
assertTrue("Expected 3 static parameters.", staticParameters.size() == 3);
assertThat(staticParameters.size() == 3).as("Expected 3 static parameters.").isTrue();
}
@Test
@@ -71,7 +70,7 @@ public class ProcedureParameterTests {
ProcedureParameter.convertStaticParameters(procedureParameters);
}
catch (IllegalArgumentException e) {
assertEquals("'procedureParameters' must not contain null values.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("'procedureParameters' must not contain null values.");
return;
}
@@ -89,7 +88,7 @@ public class ProcedureParameterTests {
ProcedureParameter.convertExpressions(procedureParameters);
}
catch (IllegalArgumentException e) {
assertEquals("'procedureParameters' must not contain null values.", e.getMessage());
assertThat(e.getMessage()).isEqualTo("'procedureParameters' must not contain null values.");
return;
}