Fix JmsMockTests for bad Mockito usage

https://build.spring.io/browse/INTSAMPLES-NIGHTLY-2074

Upgrade to SK-2.0 M1 and SIK-3.0 M1

Fix JPA sample adding `SEQUENCE HIBERNATE_SEQUENCE` DDL
into the `schema.sql`

https://build.spring.io/browse/INTSAMPLES-NIGHTLY-2078/

The latest Hibernate version doesn't create such a DB entity if
we use `hibernate.ddl-auto: none`

Increase timeouts in the JMS and TCP tests
This commit is contained in:
Artem Bilan
2017-04-27 16:19:02 -04:00
parent fdb9ddceeb
commit be0e24aea5
11 changed files with 79 additions and 57 deletions

View File

@@ -18,21 +18,25 @@ package org.springframework.integration.samples.advance.testing.jms;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import javax.jms.JMSException;
import javax.jms.TextMessage;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -62,6 +66,8 @@ public class JmsMockTests {
private static final Logger LOGGER = Logger.getLogger(JmsMockTests.class);
private final AtomicReference<String> testMessageHolder = new AtomicReference<>();
@Autowired
private JmsTemplate mockJmsTemplate;
@@ -80,6 +86,25 @@ public class JmsMockTests {
@Qualifier("invalidMessageChannel")
private SubscribableChannel invalidMessageChannel;
@Before
public void setup() throws JMSException {
TextMessage message = mock(TextMessage.class);
when(this.mockJmsTemplate.getMessageConverter()).thenReturn(new SimpleMessageConverter());
when(this.mockJmsTemplate.receiveSelected(anyString())).thenReturn(message);
given(message.getText())
.willAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return testMessageHolder.get();
}
});
}
/**
* This test verifies that a message received on a polling JMS inbound channel adapter is
* routed to the designated channel and that the message payload is as expected
@@ -92,13 +117,13 @@ public class JmsMockTests {
public void testReceiveMessage() throws JMSException, InterruptedException, IOException {
String msg = "hello";
boolean sent = verifyJmsMessageReceivedOnOutputChannel(msg, outputChannel,new CountDownHandler() {
boolean sent = verifyJmsMessageReceivedOnOutputChannel(msg, outputChannel, new CountDownHandler() {
@Override
protected void verifyMessage(Message<?> message) {
assertEquals("hello",message.getPayload());
}
}
@Override
protected void verifyMessage(Message<?> message) {
assertEquals("hello", message.getPayload());
}
}
);
assertTrue("message not sent to expected output channel", sent);
}
@@ -116,12 +141,12 @@ public class JmsMockTests {
String msg = "whoops";
boolean sent = verifyJmsMessageReceivedOnOutputChannel(msg, invalidMessageChannel, new CountDownHandler() {
@Override
protected void verifyMessage(Message<?> message) {
assertEquals("invalid payload",message.getPayload());
}
@Override
protected void verifyMessage(Message<?> message) {
assertEquals("invalid payload", message.getPayload());
}
}
}
);
assertTrue("message not sent to expected output channel", sent);
}
@@ -168,16 +193,10 @@ public class JmsMockTests {
* is also a mock.
*/
TextMessage message = mock(TextMessage.class);
when(this.mockJmsTemplate.getMessageConverter()).thenReturn(new SimpleMessageConverter());
when(this.mockJmsTemplate.receiveSelected(anyString())).thenReturn(message);
String text = (String) obj;
this.testMessageHolder.set((String) obj);
CountDownLatch latch = new CountDownLatch(1);
handler.setLatch(latch);
doReturn(text).when(message).getText();
expectedOutputChannel.subscribe(handler);
@@ -192,6 +211,7 @@ public class JmsMockTests {
return latchCountedToZero;
}
/*
* A MessageHandler that uses a CountDownLatch to synchronize with the calling thread
*/
@@ -199,7 +219,7 @@ public class JmsMockTests {
CountDownLatch latch;
public final void setLatch(CountDownLatch latch){
public final void setLatch(CountDownLatch latch) {
this.latch = latch;
}
@@ -219,4 +239,4 @@ public class JmsMockTests {
}
}
}

View File

@@ -6,8 +6,6 @@
xmlns:int-stream="http://www.springframework.org/schema/integration/stream"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jms
@@ -15,11 +13,9 @@
http://www.springframework.org/schema/integration/stream
http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd">
<int-stream:stdin-channel-adapter id="stdin" channel="stdinToJmsoutChannel"/>
<int-stream:stdin-channel-adapter id="stdin" channel="stdinToJmsOutChannel"/>
<int:channel id="stdinToJmsoutChannel"/>
<int:chain input-channel="stdinToJmsoutChannel">
<int:chain input-channel="stdinToJmsOutChannel">
<int:header-enricher>
<int:header name="jms_replyTo" ref="replyQueue" />
</int:header-enricher>
@@ -32,7 +28,7 @@
<int:channel id="jmsReplyChannel" />
<int:aggregator input-channel="jmsReplyChannel" output-channel="out"
group-timeout="5000"
group-timeout="20000"
expire-groups-upon-timeout="false"
send-partial-result-on-expiry="true"
discard-channel="logLateArrivers"

View File

@@ -13,10 +13,10 @@
http://www.springframework.org/schema/integration/stream
http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd">
<stream:stdin-channel-adapter id="stdin" channel="stdinToJmsoutChannel"/>
<stream:stdin-channel-adapter id="stdin" channel="stdinToJmsOutChannel"/>
<channel id="stdinToJmsoutChannel"/>
<channel id="stdinToJmsOutChannel"/>
<jms:outbound-channel-adapter id="jmsout" channel="stdinToJmsoutChannel" destination="requestQueue"/>
<jms:outbound-channel-adapter id="jmsout" channel="stdinToJmsOutChannel" destination="requestQueue"/>
</beans:beans>

View File

@@ -15,11 +15,11 @@
http://www.springframework.org/schema/integration/stream
http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd">
<stream:stdin-channel-adapter id="stdin" channel="stdinToJmsoutChannel"/>
<stream:stdin-channel-adapter id="stdin" channel="stdinToJmsOutChannel"/>
<channel id="stdinToJmsoutChannel"/>
<channel id="stdinToJmsOutChannel"/>
<jms:outbound-gateway request-channel="stdinToJmsoutChannel"
<jms:outbound-gateway request-channel="stdinToJmsOutChannel"
request-destination="requestQueue"
reply-channel="jmsReplyChannel"/>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2017 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.jms;
import java.util.List;
@@ -29,6 +30,7 @@ import org.springframework.messaging.MessageChannel;
/**
* @author Gunnar Hillert
* @author Gary Russell
* @author Artem Bilan
*/
public class AggregatorDemoTest {
@@ -44,14 +46,14 @@ public class AggregatorDemoTest {
final GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(configFilesGatewayDemo);
final MessageChannel stdinToJmsoutChannel = applicationContext.getBean("stdinToJmsoutChannel", MessageChannel.class);
final MessageChannel stdinToJmsOutChannel = applicationContext.getBean("stdinToJmsOutChannel", MessageChannel.class);
stdinToJmsoutChannel.send(MessageBuilder.withPayload("jms test").build());
stdinToJmsOutChannel.send(MessageBuilder.withPayload("jms test").build());
final QueueChannel queueChannel = applicationContext.getBean("queueChannel", QueueChannel.class);
@SuppressWarnings("unchecked")
Message<List<String>> reply = (Message<List<String>>) queueChannel.receive(20000);
Message<List<String>> reply = (Message<List<String>>) queueChannel.receive(600000);
Assert.assertNotNull(reply);
List<String> out = reply.getPayload();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.jms;
import org.junit.Assert;
@@ -42,9 +43,9 @@ public class ChannelAdapterDemoTest {
final GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(configFilesChannelAdapterDemo);
final MessageChannel stdinToJmsoutChannel = applicationContext.getBean("stdinToJmsoutChannel", MessageChannel.class);
final MessageChannel stdinToJmsOutChannel = applicationContext.getBean("stdinToJmsOutChannel", MessageChannel.class);
stdinToJmsoutChannel.send(MessageBuilder.withPayload("jms test").build());
stdinToJmsOutChannel.send(MessageBuilder.withPayload("jms test").build());
final QueueChannel queueChannel = applicationContext.getBean("queueChannel", QueueChannel.class);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2017 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.
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.jms;
import org.junit.Assert;
@@ -42,9 +43,9 @@ public class GatewayDemoTest {
final GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext(configFilesGatewayDemo);
final MessageChannel stdinToJmsoutChannel = applicationContext.getBean("stdinToJmsoutChannel", MessageChannel.class);
final MessageChannel stdinToJmsOutChannel = applicationContext.getBean("stdinToJmsOutChannel", MessageChannel.class);
stdinToJmsoutChannel.send(MessageBuilder.withPayload("jms test").build());
stdinToJmsOutChannel.send(MessageBuilder.withPayload("jms test").build());
final QueueChannel queueChannel = applicationContext.getBean("queueChannel", QueueChannel.class);

View File

@@ -1,3 +1 @@
insert into PEOPLE(id, name, CREATED_DATE_TIME) values ('1001', 'Cartman', NOW());
INSERT INTO SEQUENCE(SEQ_NAME, SEQ_COUNT) values ('SEQ_GEN', 0);

View File

@@ -4,6 +4,6 @@ DROP TABLE if EXISTS SEQUENCE;
CREATE TABLE OPENJPA_SEQUENCE_TABLE (ID TINYINT NOT NULL, SEQUENCE_VALUE BIGINT, PRIMARY KEY (ID));
CREATE TABLE SEQUENCE (SEQ_NAME VARCHAR(50), SEQ_COUNT DECIMAL(15));
CREATE TABLE PEOPLE (id BIGINT generated by default as identity, name VARCHAR(255), CREATED_DATE_TIME TIMESTAMP, PRIMARY KEY (id));
CREATE SEQUENCE HIBERNATE_SEQUENCE START WITH 1 INCREMENT BY 1;

View File

@@ -183,16 +183,16 @@ subprojects { subproject ->
commonsPoolVersion = '1.5.4'
c3p0Version = '0.9.1.2'
derbyVersion = '10.10.1.1'
eclipseLinkVersion = '2.6.2'
eclipseLinkVersion = '2.6.4'
hamcrestVersion = '1.3'
hibernateVersion = '5.2.4.Final'
hibernateValidatorVersion = '5.2.4.Final'
hibernateVersion = '5.2.10.Final'
hibernateValidatorVersion = '5.4.1.Final'
ftpServerVersion = '1.1.0'
flexjsonVersion = '2.0'
guavaVersion = '16.0.1'
groovyVersion = '2.3.0'
hsqldbVersion = '2.3.2'
h2Version = '1.3.175'
h2Version = '1.4.194'
jacksonVersion = '2.3.2'
jasyptVersion = '1.7'
javaxInjectVersion = '1'
@@ -215,9 +215,9 @@ subprojects { subproject ->
subethasmtpVersion = '1.2'
slf4jVersion = '1.7.11'
springIntegrationVersion = '5.0.0.BUILD-SNAPSHOT'
springIntegrationKafkaVersion = '3.0.0.BUILD-SNAPSHOT'
springIntegrationKafkaVersion = '3.0.0.M1'
springIntegrationSplunkVersion = '1.1.0.RELEASE'
springKafkaVersion = '2.0.0.BUILD-SNAPSHOT'
springKafkaVersion = '2.0.0.M1'
springVersion = '5.0.0.BUILD-SNAPSHOT'
springSecurityVersion = '4.2.2.RELEASE'
springWebFlowVersion = '2.3.3.RELEASE'

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.tcpclientserver;
import static org.hamcrest.Matchers.containsString;
@@ -53,7 +54,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @since 2.1
*
*/
@ContextConfiguration(loader=CustomTestContextLoader.class, locations={"/META-INF/spring/integration/tcpClientServerDemo-conversion-context.xml"})
@ContextConfiguration(loader = CustomTestContextLoader.class,
locations = { "/META-INF/spring/integration/tcpClientServerDemo-conversion-context.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext
public class TcpClientServerDemoTest {
@@ -84,15 +86,17 @@ public class TcpClientServerDemoTest {
results.add(i);
final int j = i;
executor.execute(new Runnable() {
@Override
public void run() {
String result = gw.send(j + "Hello world!"); // first 3 bytes is correlationid
assertEquals(j + "Hello world!:echo", result);
results.remove(j);
latch.countDown();
}});
}
});
}
assertTrue(latch.await(10, TimeUnit.SECONDS));
assertTrue(latch.await(20, TimeUnit.SECONDS));
assertEquals(0, results.size());
}