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
This commit is contained in:
Artem Bilan
2019-04-08 12:10:52 -04:00
parent 7b3dd2b12a
commit 7fa1161f5b
4 changed files with 25 additions and 43 deletions

View File

@@ -31,7 +31,9 @@ import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.config.EnableIntegrationManagement;
import org.springframework.integration.support.management.metrics.MetricsCaptor;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.search.MeterNotFoundException;
@@ -39,11 +41,13 @@ import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 5.1
*
*/
@RunWith(SpringRunner.class)
@TestExecutionListeners(DependencyInjectionTestExecutionListener.class)
public class MicrometerCustomMetricsTests {
@Autowired
@@ -56,7 +60,7 @@ public class MicrometerCustomMetricsTests {
private QueueChannel queue;
@Test
public void testSend() throws Exception {
public void testSend() {
GenericMessage<String> message = new GenericMessage<>("foo");
this.queue.send(message);
this.queue.receive();
@@ -112,6 +116,7 @@ public class MicrometerCustomMetricsTests {
public MetricsCaptor captor() {
return new CustomMetricsCaptor(meterRegistry());
}
}
static class CustomMetricsCaptor extends MicrometerMetricsCaptor {

View File

@@ -49,7 +49,9 @@ import org.springframework.messaging.MessagingException;
import org.springframework.messaging.PollableChannel;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.support.DependencyInjectionTestExecutionListener;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.search.MeterNotFoundException;
@@ -57,12 +59,14 @@ import io.micrometer.core.instrument.simple.SimpleMeterRegistry;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 5.0.2
*
*/
@RunWith(SpringRunner.class)
@DirtiesContext
@TestExecutionListeners(DependencyInjectionTestExecutionListener.class)
public class MicrometerMetricsTests {
@Autowired
@@ -91,7 +95,7 @@ public class MicrometerMetricsTests {
@SuppressWarnings("unchecked")
@Test
public void testSend() throws Exception {
public void testSend() {
GenericMessage<String> message = new GenericMessage<>("foo");
this.channel.send(message);
try {
@@ -186,15 +190,15 @@ public class MicrometerMetricsTests {
// Test meter removal
registry.get("spring.integration.send")
.tag("name", "newChannel")
.tag("result", "success")
.timer();
newChannel.destroy();
try {
registry.get("spring.integration.send")
.tag("name", "newChannel")
.tag("result", "success")
.timer();
newChannel.destroy();
try {
registry.get("spring.integration.send")
.tag("name", "newChannel")
.tag("result", "success")
.timer();
fail("Expected MeterNotFoundException");
}
catch (MeterNotFoundException e) {

View File

@@ -25,33 +25,27 @@ import java.net.Socket;
import javax.net.SocketFactory;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
import org.springframework.integration.ip.tcp.serializer.ByteArrayStxEtxSerializer;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 2.0
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@DirtiesContext
public class TcpConfigInboundGatewayTests {
static AbstractApplicationContext staticContext;
@Autowired
AbstractApplicationContext ctx;
@Autowired
@Qualifier("crLfServer")
AbstractServerConnectionFactory crLfServer;
@@ -288,16 +282,4 @@ public class TcpConfigInboundGatewayTests {
}
@Before
public void copyContext() {
if (staticContext == null) {
staticContext = ctx;
}
}
@AfterClass
public static void shutDown() {
staticContext.close();
}
}

View File

@@ -24,29 +24,23 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.integration.jdbc.storedproc.User;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit4.SpringRunner;
/**
* @author Artem Bilan
*
* @since 2.2
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@RunWith(SpringRunner.class)
@DirtiesContext // close at the end after class
public class StoredProcOutboundChannelAdapterWithinChainTests {
@Autowired
private AbstractApplicationContext context;
@Autowired
private JdbcTemplate jdbcTemplate;
@@ -64,9 +58,6 @@ public class StoredProcOutboundChannelAdapterWithinChainTests {
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();
}
}