From 41a47171c2991a7c1df1807a9fd8a38db058c9c0 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 17 Nov 2017 12:31:25 -0500 Subject: [PATCH] Upgrade to Reactor 3.1.2 and some polishing * Fix TCP/IP `ParserUnitTests.testInUdpMulticast()` do not check the port. No guarantee with the OS selection port that it is always going to be `> 5100` * Optimize `RmiInboundGatewayParserTests` to load application context only once - `@RunWith(SpringRunner.class)` --- build.gradle | 4 +- .../ip/config/ParserUnitTests.java | 4 +- ... RmiInboundGatewayParserTests-context.xml} | 0 .../config/RmiInboundGatewayParserTests.java | 84 ++++++++----------- 4 files changed, 41 insertions(+), 51 deletions(-) rename spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/{rmiInboundGatewayParserTests.xml => RmiInboundGatewayParserTests-context.xml} (100%) diff --git a/build.gradle b/build.gradle index 0295a57501..ae4bc64fbe 100644 --- a/build.gradle +++ b/build.gradle @@ -123,8 +123,8 @@ subprojects { subproject -> mysqlVersion = '6.0.6' pahoMqttClientVersion = '1.2.0' postgresVersion = '42.0.0' - reactorNettyVersion = '0.7.1.RELEASE' - reactorVersion = '3.1.1.RELEASE' + reactorNettyVersion = '0.7.2.RELEASE' + reactorVersion = '3.1.2.RELEASE' romeToolsVersion = '1.8.0' servletApiVersion = '3.1.0' slf4jVersion = "1.7.25" diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java index 0bd2d55d1d..e80ce360c1 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/config/ParserUnitTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 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. @@ -84,6 +84,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Gary Russell * @author Oleg Zhurakousky * @author Artem Bilan + * * @since 2.0 */ @ContextConfiguration @@ -301,7 +302,6 @@ public class ParserUnitTests { @Test public void testInUdpMulticast() { DirectFieldAccessor dfa = new DirectFieldAccessor(udpInMulticast); - assertTrue(udpInMulticast.getPort() >= 5100); assertEquals("225.6.7.8", dfa.getPropertyValue("group")); assertEquals(27, dfa.getPropertyValue("poolSize")); assertEquals(29, dfa.getPropertyValue("receiveBufferSize")); diff --git a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/rmiInboundGatewayParserTests.xml b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiInboundGatewayParserTests-context.xml similarity index 100% rename from spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/rmiInboundGatewayParserTests.xml rename to spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiInboundGatewayParserTests-context.xml diff --git a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiInboundGatewayParserTests.java b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiInboundGatewayParserTests.java index 0b5b06a716..322f3ae582 100644 --- a/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiInboundGatewayParserTests.java +++ b/spring-integration-rmi/src/test/java/org/springframework/integration/rmi/config/RmiInboundGatewayParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 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. @@ -16,93 +16,83 @@ package org.springframework.integration.rmi.config; +import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; import org.junit.Test; +import org.junit.runner.RunWith; -import org.springframework.beans.DirectFieldAccessor; -import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.integration.core.MessagingTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.ApplicationContext; 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; /** * @author Mark Fisher * @author Gary Russell + * @author Artem Bilan */ +@RunWith(SpringRunner.class) +@DirtiesContext public class RmiInboundGatewayParserTests { + @Autowired + @Qualifier("testChannel") + private MessageChannel channel; + + @Autowired + private ApplicationContext context; + @Test public void gatewayWithDefaultsAndHistory() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "rmiInboundGatewayParserTests.xml", this.getClass()); - MessageChannel channel = (MessageChannel) context.getBean("testChannel"); - RmiInboundGateway gateway = (RmiInboundGateway) context.getBean("gatewayWithDefaults"); + RmiInboundGateway gateway = (RmiInboundGateway) this.context.getBean("gatewayWithDefaults"); + assertEquals("gatewayWithDefaults", gateway.getComponentName()); assertEquals("rmi:inbound-gateway", gateway.getComponentType()); - DirectFieldAccessor accessor = new DirectFieldAccessor(gateway); - assertEquals(true, accessor.getPropertyValue("expectReply")); - assertEquals(channel, accessor.getPropertyValue("requestChannel")); - MessagingTemplate template = (MessagingTemplate) - accessor.getPropertyValue("messagingTemplate"); - DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template); - assertEquals(1000L, templateAccessor.getPropertyValue("sendTimeout")); - assertEquals(1000L, templateAccessor.getPropertyValue("receiveTimeout")); - context.close(); + assertTrue(TestUtils.getPropertyValue(gateway, "expectReply", Boolean.class)); + assertSame(this.channel, TestUtils.getPropertyValue(gateway, "requestChannel")); + assertEquals(1000L, TestUtils.getPropertyValue(gateway, "messagingTemplate.sendTimeout")); + assertEquals(1000L, TestUtils.getPropertyValue(gateway, "messagingTemplate.receiveTimeout")); } @Test public void gatewayWithCustomProperties() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "rmiInboundGatewayParserTests.xml", this.getClass()); - MessageChannel channel = (MessageChannel) context.getBean("testChannel"); RmiInboundGateway gateway = (RmiInboundGateway) context.getBean("gatewayWithCustomProperties"); - DirectFieldAccessor accessor = new DirectFieldAccessor(gateway); - assertEquals(false, accessor.getPropertyValue("expectReply")); - assertEquals(channel, accessor.getPropertyValue("requestChannel")); - MessagingTemplate template = (MessagingTemplate) - accessor.getPropertyValue("messagingTemplate"); - DirectFieldAccessor templateAccessor = new DirectFieldAccessor(template); - assertEquals(123L, templateAccessor.getPropertyValue("sendTimeout")); - assertEquals(456L, templateAccessor.getPropertyValue("receiveTimeout")); - context.close(); + + assertFalse(TestUtils.getPropertyValue(gateway, "expectReply", Boolean.class)); + assertSame(this.channel, TestUtils.getPropertyValue(gateway, "requestChannel")); + assertEquals(123L, TestUtils.getPropertyValue(gateway, "messagingTemplate.sendTimeout")); + assertEquals(456L, TestUtils.getPropertyValue(gateway, "messagingTemplate.receiveTimeout")); } @Test public void gatewayWithHost() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "rmiInboundGatewayParserTests.xml", this.getClass()); RmiInboundGateway gateway = (RmiInboundGateway) context.getBean("gatewayWithHostAndErrorChannel"); - DirectFieldAccessor accessor = new DirectFieldAccessor(gateway); - assertEquals("localhost", accessor.getPropertyValue("registryHost")); - assertSame(context.getBean("testErrorChannel"), - TestUtils.getPropertyValue(gateway, "errorChannel")); - context.close(); + assertEquals("localhost", TestUtils.getPropertyValue(gateway, "registryHost")); + assertSame(context.getBean("testErrorChannel"), TestUtils.getPropertyValue(gateway, "errorChannel")); } @Test public void gatewayWithPort() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "rmiInboundGatewayParserTests.xml", this.getClass()); RmiInboundGateway gateway = (RmiInboundGateway) context.getBean("gatewayWithPort"); - DirectFieldAccessor accessor = new DirectFieldAccessor(gateway); - assertEquals(1234, accessor.getPropertyValue("registryPort")); - context.close(); + assertEquals(1234, TestUtils.getPropertyValue(gateway, "registryPort")); } @Test public void gatewayWithRemoteInvocationExecutorReference() { - ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( - "rmiInboundGatewayParserTests.xml", this.getClass()); RmiInboundGateway gateway = (RmiInboundGateway) context.getBean("gatewayWithExecutorRef"); - DirectFieldAccessor accessor = new DirectFieldAccessor(gateway); - Object remoteInvocationExecutor = accessor.getPropertyValue("remoteInvocationExecutor"); + Object remoteInvocationExecutor = TestUtils.getPropertyValue(gateway, "remoteInvocationExecutor"); assertNotNull(remoteInvocationExecutor); - assertEquals(StubRemoteInvocationExecutor.class, remoteInvocationExecutor.getClass()); - context.close(); + assertThat(remoteInvocationExecutor, instanceOf(StubRemoteInvocationExecutor.class)); } }