Skip to content

Commit 7fa1161

Browse files
committed
Fix tests according new test events model in SF
https://build.spring.io/browse/INT-MASTER-1479 The `MicrometerCustomMetricsTests` and `MicrometerMetricsTests` close an application explicitly in the test, so we can't handle test events properly any more. Therefore use only `DependencyInjectionTestExecutionListener` excluding all others together with the `EventPublishingTestExecutionListener` The `TcpConfigInboundGatewayTests` don't need to use a static holder for the application context at all and, therefore, there is nothing to close in the `@After` any more There is reason to close an application context in the `StoredProcOutboundChannelAdapterWithinChainTests`. Other tests must take care about clean embedded DB before their start
1 parent 7b3dd2b commit 7fa1161

File tree

4 files changed

+25
-43
lines changed

4 files changed

+25
-43
lines changed

spring-integration-core/src/test/java/org/springframework/integration/support/management/micrometer/MicrometerCustomMetricsTests.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,23 @@
3131
import org.springframework.integration.config.EnableIntegrationManagement;
3232
import org.springframework.integration.support.management.metrics.MetricsCaptor;
3333
import org.springframework.messaging.support.GenericMessage;
34+
import org.springframework.test.context.TestExecutionListeners;
3435
import org.springframework.test.context.junit4.SpringRunner;
36+
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
3537

3638
import io.micrometer.core.instrument.MeterRegistry;
3739
import io.micrometer.core.instrument.search.MeterNotFoundException;
3840
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
3941

4042
/**
4143
* @author Gary Russell
44+
* @author Artem Bilan
4245
*
4346
* @since 5.1
4447
*
4548
*/
4649
@RunWith(SpringRunner.class)
50+
@TestExecutionListeners(DependencyInjectionTestExecutionListener.class)
4751
public class MicrometerCustomMetricsTests {
4852

4953
@Autowired
@@ -56,7 +60,7 @@ public class MicrometerCustomMetricsTests {
5660
private QueueChannel queue;
5761

5862
@Test
59-
public void testSend() throws Exception {
63+
public void testSend() {
6064
GenericMessage<String> message = new GenericMessage<>("foo");
6165
this.queue.send(message);
6266
this.queue.receive();
@@ -112,6 +116,7 @@ public QueueChannel queue() {
112116
public MetricsCaptor captor() {
113117
return new CustomMetricsCaptor(meterRegistry());
114118
}
119+
115120
}
116121

117122
static class CustomMetricsCaptor extends MicrometerMetricsCaptor {

spring-integration-core/src/test/java/org/springframework/integration/support/management/micrometer/MicrometerMetricsTests.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,24 @@
4949
import org.springframework.messaging.PollableChannel;
5050
import org.springframework.messaging.support.GenericMessage;
5151
import org.springframework.test.annotation.DirtiesContext;
52+
import org.springframework.test.context.TestExecutionListeners;
5253
import org.springframework.test.context.junit4.SpringRunner;
54+
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
5355

5456
import io.micrometer.core.instrument.MeterRegistry;
5557
import io.micrometer.core.instrument.search.MeterNotFoundException;
5658
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
5759

5860
/**
5961
* @author Gary Russell
62+
* @author Artem Bilan
6063
*
6164
* @since 5.0.2
6265
*
6366
*/
6467
@RunWith(SpringRunner.class)
6568
@DirtiesContext
69+
@TestExecutionListeners(DependencyInjectionTestExecutionListener.class)
6670
public class MicrometerMetricsTests {
6771

6872
@Autowired
@@ -91,7 +95,7 @@ public class MicrometerMetricsTests {
9195

9296
@SuppressWarnings("unchecked")
9397
@Test
94-
public void testSend() throws Exception {
98+
public void testSend() {
9599
GenericMessage<String> message = new GenericMessage<>("foo");
96100
this.channel.send(message);
97101
try {
@@ -186,15 +190,15 @@ public void testSend() throws Exception {
186190

187191
// Test meter removal
188192
registry.get("spring.integration.send")
189-
.tag("name", "newChannel")
190-
.tag("result", "success")
191-
.timer();
192-
newChannel.destroy();
193-
try {
194-
registry.get("spring.integration.send")
195193
.tag("name", "newChannel")
196194
.tag("result", "success")
197195
.timer();
196+
newChannel.destroy();
197+
try {
198+
registry.get("spring.integration.send")
199+
.tag("name", "newChannel")
200+
.tag("result", "success")
201+
.timer();
198202
fail("Expected MeterNotFoundException");
199203
}
200204
catch (MeterNotFoundException e) {

spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/TcpConfigInboundGatewayTests.java

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,27 @@
2525

2626
import javax.net.SocketFactory;
2727

28-
import org.junit.AfterClass;
29-
import org.junit.Before;
3028
import org.junit.Test;
3129
import org.junit.runner.RunWith;
3230

3331
import org.springframework.beans.factory.annotation.Autowired;
3432
import org.springframework.beans.factory.annotation.Qualifier;
35-
import org.springframework.context.support.AbstractApplicationContext;
3633
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
3734
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
3835
import org.springframework.integration.ip.tcp.serializer.ByteArrayStxEtxSerializer;
39-
import org.springframework.test.context.ContextConfiguration;
40-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
36+
import org.springframework.test.annotation.DirtiesContext;
37+
import org.springframework.test.context.junit4.SpringRunner;
4138

4239
/**
4340
* @author Gary Russell
41+
* @author Artem Bilan
42+
*
4443
* @since 2.0
4544
*/
46-
@ContextConfiguration
47-
@RunWith(SpringJUnit4ClassRunner.class)
45+
@RunWith(SpringRunner.class)
46+
@DirtiesContext
4847
public class TcpConfigInboundGatewayTests {
4948

50-
static AbstractApplicationContext staticContext;
51-
52-
@Autowired
53-
AbstractApplicationContext ctx;
54-
5549
@Autowired
5650
@Qualifier("crLfServer")
5751
AbstractServerConnectionFactory crLfServer;
@@ -288,16 +282,4 @@ private void waitListening(TcpInboundGateway gateway) throws Exception {
288282

289283
}
290284

291-
@Before
292-
public void copyContext() {
293-
if (staticContext == null) {
294-
staticContext = ctx;
295-
}
296-
}
297-
298-
@AfterClass
299-
public static void shutDown() {
300-
staticContext.close();
301-
}
302-
303285
}

spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundChannelAdapterWithinChainTests.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,23 @@
2424
import org.junit.runner.RunWith;
2525

2626
import org.springframework.beans.factory.annotation.Autowired;
27-
import org.springframework.context.support.AbstractApplicationContext;
2827
import org.springframework.integration.jdbc.storedproc.User;
2928
import org.springframework.integration.support.MessageBuilder;
3029
import org.springframework.jdbc.core.JdbcTemplate;
3130
import org.springframework.messaging.Message;
3231
import org.springframework.messaging.MessageChannel;
3332
import org.springframework.test.annotation.DirtiesContext;
34-
import org.springframework.test.context.ContextConfiguration;
35-
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
33+
import org.springframework.test.context.junit4.SpringRunner;
3634

3735
/**
3836
* @author Artem Bilan
3937
*
4038
* @since 2.2
4139
*/
42-
@ContextConfiguration
43-
@RunWith(SpringJUnit4ClassRunner.class)
40+
@RunWith(SpringRunner.class)
4441
@DirtiesContext // close at the end after class
4542
public class StoredProcOutboundChannelAdapterWithinChainTests {
4643

47-
@Autowired
48-
private AbstractApplicationContext context;
49-
5044
@Autowired
5145
private JdbcTemplate jdbcTemplate;
5246

@@ -64,9 +58,6 @@ public void test() {
6458
assertThat(map.get("USERNAME")).as("Wrong username").isEqualTo("username");
6559
assertThat(map.get("PASSWORD")).as("Wrong password").isEqualTo("password");
6660
assertThat(map.get("EMAIL")).as("Wrong email").isEqualTo("email");
67-
// embeddedDatabase can be in working state. So other tests with the same embeddedDatabase beanId, type and init scripts
68-
// may be failed with Exception like: object in the DB already exists
69-
this.context.close();
7061
}
7162

7263
}

0 commit comments

Comments
 (0)