Fix RMI tests to rely on the random local port
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
</int:channel>
|
||||
|
||||
<bean id="port" class="java.lang.Integer">
|
||||
<constructor-arg value="#{T(org.springframework.integration.test.util.SocketUtils).findAvailableServerSocket()}" />
|
||||
<constructor-arg value="#{T(org.springframework.util.SocketUtils).findAvailableTcpPort()}" />
|
||||
</bean>
|
||||
|
||||
<!-- Bad -->
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2019 the original author or authors.
|
||||
* Copyright 2013-2020 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.
|
||||
@@ -21,8 +21,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
@@ -34,7 +33,7 @@ import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.SubscribableChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
|
||||
@@ -45,7 +44,7 @@ import org.springframework.transaction.TransactionDefinition;
|
||||
* @since 3.0
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class BackToBackTests {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -29,13 +29,13 @@ import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.gateway.RequestReplyExchanger;
|
||||
import org.springframework.integration.handler.AbstractReplyProducingMessageHandler;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.messaging.MessagingException;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.remoting.RemoteLookupFailureException;
|
||||
import org.springframework.remoting.rmi.RmiServiceExporter;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -46,22 +46,24 @@ public class RmiOutboundGatewayTests {
|
||||
|
||||
private static final QueueChannel OUTPUT = new QueueChannel(1);
|
||||
|
||||
private static int RMI_PORT;
|
||||
|
||||
private static RmiServiceExporter EXPORTER;
|
||||
|
||||
private static RmiOutboundGateway GATEWAY;
|
||||
|
||||
@BeforeAll
|
||||
static void setup() throws RemoteException {
|
||||
RMI_PORT = SocketUtils.findAvailableTcpPort();
|
||||
|
||||
EXPORTER = new RmiServiceExporter();
|
||||
EXPORTER.setService(new TestExchanger());
|
||||
EXPORTER.setServiceInterface(RequestReplyExchanger.class);
|
||||
EXPORTER.setServiceName("testRemoteHandler");
|
||||
EXPORTER.setRegistryPort(0);
|
||||
EXPORTER.setRegistryPort(RMI_PORT);
|
||||
EXPORTER.afterPropertiesSet();
|
||||
|
||||
Integer localPort = TestUtils.getPropertyValue(EXPORTER, "registry.ref.ref.ep.port", Integer.class);
|
||||
|
||||
GATEWAY = new RmiOutboundGateway("rmi://localhost:" + localPort + "/testRemoteHandler");
|
||||
GATEWAY = new RmiOutboundGateway("rmi://localhost:" + RMI_PORT + "/testRemoteHandler");
|
||||
GATEWAY.setOutputChannel(OUTPUT);
|
||||
}
|
||||
|
||||
@@ -120,7 +122,7 @@ public class RmiOutboundGatewayTests {
|
||||
|
||||
@Test
|
||||
void invalidServiceName() {
|
||||
RmiOutboundGateway gateway = new RmiOutboundGateway("rmi://localhost:1099/noSuchService");
|
||||
RmiOutboundGateway gateway = new RmiOutboundGateway("rmi://localhost:" + RMI_PORT + "/noSuchService");
|
||||
assertThatExceptionOfType(MessageHandlingException.class)
|
||||
.isThrownBy(() -> gateway.handleMessage(new GenericMessage<>("test")))
|
||||
.withCauseInstanceOf(RemoteLookupFailureException.class);
|
||||
@@ -136,7 +138,7 @@ public class RmiOutboundGatewayTests {
|
||||
|
||||
@Test
|
||||
void invalidUrl() {
|
||||
RmiOutboundGateway gateway = new RmiOutboundGateway("invalid");
|
||||
RmiOutboundGateway gateway = new RmiOutboundGateway("https://sample.com/");
|
||||
assertThatExceptionOfType(MessageHandlingException.class)
|
||||
.isThrownBy(() -> gateway.handleMessage(new GenericMessage<>("test")))
|
||||
.withCauseInstanceOf(RemoteLookupFailureException.class);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -18,8 +18,7 @@ package org.springframework.integration.rmi.config;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -30,18 +29,19 @@ import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.util.ErrorHandler;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
*
|
||||
* @since 1.0.3
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class DefaultConfigurationTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -18,8 +18,7 @@ package org.springframework.integration.rmi.config;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -28,7 +27,7 @@ import org.springframework.integration.rmi.RmiInboundGateway;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
/**
|
||||
@@ -36,7 +35,7 @@ import org.springframework.util.SocketUtils;
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class RmiInboundGatewayParserTests {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -21,10 +21,9 @@ import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -41,8 +40,7 @@ import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.remoting.rmi.RmiProxyFactoryBean;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.util.SocketUtils;
|
||||
|
||||
/**
|
||||
@@ -50,8 +48,7 @@ import org.springframework.util.SocketUtils;
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringJUnitConfig
|
||||
@DirtiesContext
|
||||
public class RmiOutboundGatewayParserTests {
|
||||
|
||||
@@ -87,7 +84,7 @@ public class RmiOutboundGatewayParserTests {
|
||||
@Qualifier("advised.handler")
|
||||
RmiOutboundGateway advised;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setupTestInboundGateway() {
|
||||
testChannel.setBeanName("testChannel");
|
||||
rmiInboundGateway.setRequestChannel(testChannel);
|
||||
@@ -97,7 +94,7 @@ public class RmiOutboundGatewayParserTests {
|
||||
rmiInboundGateway.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
@AfterAll
|
||||
public static void destroyInboundGateway() {
|
||||
rmiInboundGateway.destroy();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user