diff --git a/build.gradle b/build.gradle index bbcb308d17f..6063e623499 100644 --- a/build.gradle +++ b/build.gradle @@ -78,7 +78,7 @@ ext { jmsApiVersion = '3.1.0' jpaApiVersion = '3.1.0' jrubyVersion = '9.4.1.0' - jsonpathVersion = '2.8.0' + jsonpathVersion = '2.7.0' junit4Version = '4.13.2' junitJupiterVersion = '5.9.2' jythonVersion = '2.7.3' @@ -89,7 +89,7 @@ ext { mailVersion = '1.0.0' micrometerTracingVersion = '1.1.0-RC1' micrometerVersion = '1.11.0-RC1' - mockitoVersion = '5.3.0' + mockitoVersion = '5.2.0' mongoDriverVersion = '4.9.1' mysqlVersion = '8.0.32' pahoMqttClientVersion = '1.2.5' @@ -452,7 +452,6 @@ project('spring-integration-test-support') { compileOnly 'org.apiguardian:apiguardian-api:1.0.0' api "org.hamcrest:hamcrest-library:$hamcrestVersion" api 'org.mockito:mockito-core' - api 'org.mockito:mockito-inline' api "org.assertj:assertj-core:$assertjVersion" api 'org.springframework:spring-context' api 'org.springframework:spring-messaging' diff --git a/spring-integration-http/src/test/java/org/springframework/integration/http/dsl/HttpDslTests.java b/spring-integration-http/src/test/java/org/springframework/integration/http/dsl/HttpDslTests.java index 386472f41be..465656cf344 100644 --- a/spring-integration-http/src/test/java/org/springframework/integration/http/dsl/HttpDslTests.java +++ b/spring-integration-http/src/test/java/org/springframework/integration/http/dsl/HttpDslTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2022 the original author or authors. + * Copyright 2016-2023 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. @@ -48,8 +48,10 @@ import org.springframework.messaging.support.ErrorMessage; import org.springframework.mock.web.MockPart; import org.springframework.security.authorization.AuthorityAuthorizationManager; +import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.factory.PasswordEncoderFactories; @@ -318,14 +320,13 @@ public UserDetailsService userDetailsService() { @Bean public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { return http - .authorizeHttpRequests() - .requestMatchers(new AntPathRequestMatcher("/service/internal/**")).hasRole("ADMIN") - .anyRequest().permitAll() - .and() - .httpBasic() - .and() - .csrf().disable() - .anonymous().disable() + .authorizeHttpRequests((authorizeHttpRequests) -> + authorizeHttpRequests + .requestMatchers(new AntPathRequestMatcher("/service/internal/**")).hasRole("ADMIN") + .anyRequest().permitAll()) + .httpBasic(Customizer.withDefaults()) + .csrf(AbstractHttpConfigurer::disable) + .anonymous(AbstractHttpConfigurer::disable) .build(); } diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/AbstractBaseTests.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/AbstractBaseTests.java index fd3624b1e99..4ae9d9a3279 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/AbstractBaseTests.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/AbstractBaseTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. @@ -25,10 +25,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.rules.TestName; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestInfo; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.util.FileCopyUtils; @@ -41,6 +40,7 @@ * * @author Markus Spann * @author Gregory Bragg + * @author Artem Bilan */ public abstract class AbstractBaseTests { @@ -51,19 +51,19 @@ protected final Log getLogger() { return logger; } - @Rule - public final TestName testMethodName = new TestName(); + public String testMethodName; private String getTestMethodName() { - return getClass().getSimpleName() + '.' + testMethodName.getMethodName() + "()"; + return getClass().getSimpleName() + '.' + this.testMethodName + "()"; } - @Before - public final void logTestBegin() { + @BeforeEach + public final void logTestBegin(TestInfo testInfo) { + this.testMethodName = testInfo.getDisplayName(); getLogger().info("BGN - Test " + getTestMethodName()); } - @After + @AfterEach public final void logTestEnd() { getLogger().info("END - Test " + getTestMethodName()); } @@ -118,7 +118,7 @@ public static void writeToFile(byte[] _bytes, OutputStream _outputStream) throws } /** - * Writes the specified byte array to the an output file. + * Writes the specified byte array to the output file. * @param _bytes byte array * @param _fileName output file * @throws IOException in case of I/O errors @@ -247,13 +247,13 @@ public static File assertFileExists(String _file) { * @param _testClass test class object * @param _methodNames String method names to invoke in order, no parameters expected */ - @SuppressWarnings("deprecation") protected static void runTests(Class _testClass, String... _methodNames) throws Exception { + AbstractBaseTests test; Method[] methods = new Method[_methodNames.length]; - test = _testClass.newInstance(); + test = _testClass.getDeclaredConstructor().newInstance(); for (int i = 0; i < _methodNames.length; i++) { String methodName = _methodNames[i]; methods[i] = _testClass.getMethod(methodName, (Class[]) null); diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbMessageHistoryTests.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbMessageHistoryTests.java index 05ef5a8710b..643fbe3cd7e 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbMessageHistoryTests.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbMessageHistoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. @@ -19,7 +19,7 @@ import java.net.URI; import java.net.URISyntaxException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.endpoint.SourcePollingChannelAdapter; @@ -37,19 +37,19 @@ public class SmbMessageHistoryTests extends AbstractBaseTests { @Test public void testMessageHistory() throws URISyntaxException { - ClassPathXmlApplicationContext applicationContext = getApplicationContext(); - SourcePollingChannelAdapter adapter = applicationContext - .getBean("smbInboundChannelAdapter", SourcePollingChannelAdapter.class); - assertThat("smbInboundChannelAdapter").isEqualTo(adapter.getComponentName()); - assertThat("smb:inbound-channel-adapter").isEqualTo(adapter.getComponentType()); - - SmbSessionFactory smbSessionFactory = applicationContext.getBean(SmbSessionFactory.class); - - String url = smbSessionFactory.getUrl(); - URI uri = new URI(url); - assertThat("sambagu%40est:sambag%25uest").isEqualTo(uri.getRawUserInfo()); - assertThat("sambagu@est:sambag%uest").isEqualTo(uri.getUserInfo()); - - applicationContext.close(); + try (ClassPathXmlApplicationContext applicationContext = getApplicationContext()) { + SourcePollingChannelAdapter adapter = applicationContext + .getBean("smbInboundChannelAdapter", SourcePollingChannelAdapter.class); + assertThat("smbInboundChannelAdapter").isEqualTo(adapter.getComponentName()); + assertThat("smb:inbound-channel-adapter").isEqualTo(adapter.getComponentType()); + + SmbSessionFactory smbSessionFactory = applicationContext.getBean(SmbSessionFactory.class); + + String url = smbSessionFactory.getUrl(); + URI uri = new URI(url); + assertThat("sambagu%40est:sambag%25uest").isEqualTo(uri.getRawUserInfo()); + assertThat("sambagu@est:sambag%uest").isEqualTo(uri.getUserInfo()); + } } + } diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbParserInboundTests.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbParserInboundTests.java index ea3315bddce..783d80fb39f 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbParserInboundTests.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbParserInboundTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-2023 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,13 +18,15 @@ import java.io.File; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanCreationException; import org.springframework.context.support.ClassPathXmlApplicationContext; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; + /** * @author Markus Spann * @author Prafull Kumar Soni @@ -32,7 +34,7 @@ */ public class SmbParserInboundTests extends AbstractBaseTests { - @Before + @BeforeEach public void prepare() { ensureExists("test-temp/remote-10"); cleanUp(); @@ -46,14 +48,14 @@ public void testLocalFilesAutoCreationTrue() { assertFileNotExists(new File("test-temp/local-6")); } - @Test(expected = BeanCreationException.class) + @Test public void testLocalFilesAutoCreationFalse() { assertFileNotExists(new File("test-temp/local-6")); - new ClassPathXmlApplicationContext(getApplicationContextXmlFile("-fail"), this.getClass()) - .close(); + assertThatExceptionOfType(BeanCreationException.class) + .isThrownBy(() -> new ClassPathXmlApplicationContext(getApplicationContextXmlFile("-fail"), getClass())); } - @After + @AfterEach public void cleanUp() { delete("test-temp/local-10", "test-temp/local-6"); } diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundChannelAdapterParserTests.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundChannelAdapterParserTests.java index 122b70d8949..c8c3f519e0f 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundChannelAdapterParserTests.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. @@ -22,8 +22,7 @@ import java.util.Set; import java.util.concurrent.PriorityBlockingQueue; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.annotation.Autowired; @@ -38,8 +37,7 @@ import org.springframework.integration.smb.session.SmbSession; import org.springframework.integration.smb.session.SmbSessionFactory; import org.springframework.integration.test.util.TestUtils; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -52,22 +50,24 @@ * @author Prafull Kumar Soni * @author Gregory Bragg */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@SpringJUnitConfig public class SmbInboundChannelAdapterParserTests { @Autowired ApplicationContext applicationContext; - @Test(timeout = 100000) + @Test public void testSmbInboundChannelAdapterComplete() { - final SourcePollingChannelAdapter adapter = this.applicationContext.getBean("smbInbound", SourcePollingChannelAdapter.class); - final PriorityBlockingQueue queue = TestUtils.getPropertyValue(adapter, "source.fileSource.toBeReceived", PriorityBlockingQueue.class); + final SourcePollingChannelAdapter adapter = + this.applicationContext.getBean("smbInbound", SourcePollingChannelAdapter.class); + final PriorityBlockingQueue queue = + TestUtils.getPropertyValue(adapter, "source.fileSource.toBeReceived", PriorityBlockingQueue.class); assertThat(queue.comparator()).isNotNull(); assertThat("smbInbound").isEqualTo(adapter.getComponentName()); assertThat("smb:inbound-channel-adapter").isEqualTo(adapter.getComponentType()); - assertThat(applicationContext.getBean("smbChannel")).isEqualTo(TestUtils.getPropertyValue(adapter, "outputChannel")); + assertThat(applicationContext.getBean("smbChannel")) + .isEqualTo(TestUtils.getPropertyValue(adapter, "outputChannel")); SmbInboundFileSynchronizingMessageSource inbound = (SmbInboundFileSynchronizingMessageSource) TestUtils.getPropertyValue(adapter, "source"); @@ -95,8 +95,10 @@ public void testSmbInboundChannelAdapterComplete() { @Test public void testNoCachingSessionFactoryByDefault() { - SourcePollingChannelAdapter adapter = applicationContext.getBean("simpleAdapter", SourcePollingChannelAdapter.class); - Object sessionFactory = TestUtils.getPropertyValue(adapter, "source.synchronizer.remoteFileTemplate.sessionFactory"); + SourcePollingChannelAdapter adapter = + applicationContext.getBean("simpleAdapter", SourcePollingChannelAdapter.class); + Object sessionFactory = + TestUtils.getPropertyValue(adapter, "source.synchronizer.remoteFileTemplate.sessionFactory"); assertThat(sessionFactory).isInstanceOf(SmbSessionFactory.class); SmbInboundFileSynchronizer fisync = TestUtils.getPropertyValue(adapter, "source.synchronizer", SmbInboundFileSynchronizer.class); @@ -105,10 +107,10 @@ public void testNoCachingSessionFactoryByDefault() { assertThat("/").isEqualTo(remoteFileSeparator); } - @Test(timeout = 10000) + @Test public void testSmbInboundChannelAdapterCompleteNoId() { - - Map spcas = applicationContext.getBeansOfType(SourcePollingChannelAdapter.class); + Map spcas = + applicationContext.getBeansOfType(SourcePollingChannelAdapter.class); SourcePollingChannelAdapter adapter = null; for (String key : spcas.keySet()) { if (!key.equals("smbInbound") && !key.equals("simpleAdapter")) { @@ -132,9 +134,6 @@ public Class getObjectType() { return SmbSessionFactory.class; } - public boolean isSingleton() { - return true; - } } } diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundOutboundSample.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundOutboundSample.java index bf86f8c2d7d..9e03332a645 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundOutboundSample.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundOutboundSample.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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,8 @@ import java.io.File; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -46,6 +46,7 @@ * @author Markus Spann * @author Gunnar Hillert * @author Gregory Bragg + * @author Artem Bilan */ public class SmbInboundOutboundSample extends AbstractBaseTests { @@ -53,7 +54,7 @@ public class SmbInboundOutboundSample extends AbstractBaseTests { private static final String OUTBOUND_APPLICATION_CONTEXT_XML = "SmbOutboundChannelAdapterSample-context.xml"; - @Ignore("Actual SMB share must be configured in file [" + INBOUND_APPLICATION_CONTEXT_XML + "].") + @Disabled("Actual SMB share must be configured in file [" + INBOUND_APPLICATION_CONTEXT_XML + "].") @Test public void testSmbInboundChannelAdapter() throws Exception { String testLocalDir = "test-temp/local-4/"; @@ -89,7 +90,7 @@ public void testSmbInboundChannelAdapter() throws Exception { } - @Ignore("Actual SMB share must be configured in file [" + OUTBOUND_APPLICATION_CONTEXT_XML + "].") + @Disabled("Actual SMB share must be configured in file [" + OUTBOUND_APPLICATION_CONTEXT_XML + "].") @Test public void testSmbOutboundChannelAdapter() throws Exception { String testRemoteDir = "test-temp/remote-8/"; diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbOutboundChannelAdapterParserTests.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbOutboundChannelAdapterParserTests.java index 6f8819a3a81..755b7e4da1b 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbOutboundChannelAdapterParserTests.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbOutboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. @@ -17,12 +17,12 @@ package org.springframework.integration.smb.config; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Iterator; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.channel.PublishSubscribeChannel; import org.springframework.integration.endpoint.EventDrivenConsumer; @@ -44,46 +44,54 @@ public class SmbOutboundChannelAdapterParserTests extends AbstractBaseTests { @Test public void testSmbOutboundChannelAdapterComplete() { - ApplicationContext ac = getApplicationContext(); + try (ClassPathXmlApplicationContext ac = getApplicationContext()) { + Object consumer = ac.getBean("smbOutboundChannelAdapter"); + assertThat(consumer).isInstanceOf(EventDrivenConsumer.class); - Object consumer = ac.getBean("smbOutboundChannelAdapter"); - assertThat(consumer).isInstanceOf(EventDrivenConsumer.class); + PublishSubscribeChannel channel = ac.getBean("smbPubSubChannel", PublishSubscribeChannel.class); + assertThat(channel).isEqualTo(TestUtils.getPropertyValue(consumer, "inputChannel")); + assertThat("smbOutboundChannelAdapter").isEqualTo(((EventDrivenConsumer) consumer).getComponentName()); - PublishSubscribeChannel channel = ac.getBean("smbPubSubChannel", PublishSubscribeChannel.class); - assertThat(channel).isEqualTo(TestUtils.getPropertyValue(consumer, "inputChannel")); - assertThat("smbOutboundChannelAdapter").isEqualTo(((EventDrivenConsumer) consumer).getComponentName()); + Object messageHandler = TestUtils.getPropertyValue(consumer, "handler"); + String remoteFileSeparator = + TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.remoteFileSeparator", String.class); + assertThat(remoteFileSeparator).isNotNull(); + assertThat(".working.tmp") + .isEqualTo(TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.temporaryFileSuffix")); + assertThat(".").isEqualTo(remoteFileSeparator); + assertThat(ac.getBean("fileNameGenerator")) + .isEqualTo(TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.fileNameGenerator")); + assertThat(StandardCharsets.UTF_8) + .isEqualTo(TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.charset", Charset.class)); - Object messageHandler = TestUtils.getPropertyValue(consumer, "handler"); - String remoteFileSeparator = (String) TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.remoteFileSeparator"); - assertThat(remoteFileSeparator).isNotNull(); - assertThat(".working.tmp").isEqualTo(TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.temporaryFileSuffix", String.class)); - assertThat(".").isEqualTo(remoteFileSeparator); - assertThat(ac.getBean("fileNameGenerator")).isEqualTo(TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.fileNameGenerator")); - assertThat("UTF-8").isEqualTo(TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.charset", Charset.class).name()); + Object sessionFactoryProp = TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.sessionFactory"); + assertThat(SmbSessionFactory.class).isEqualTo(sessionFactoryProp.getClass()); - Object sessionFactoryProp = TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.sessionFactory"); - assertThat(SmbSessionFactory.class).isEqualTo(sessionFactoryProp.getClass()); + SmbSessionFactory smbSessionFactory = (SmbSessionFactory) sessionFactoryProp; + assertThat("localhost").isEqualTo(TestUtils.getPropertyValue(smbSessionFactory, "host")); + assertThat(0).isEqualTo(TestUtils.getPropertyValue(smbSessionFactory, "port")); + assertThat(23).isEqualTo(TestUtils.getPropertyValue(messageHandler, "order")); - SmbSessionFactory smbSessionFactory = (SmbSessionFactory) sessionFactoryProp; - assertThat("localhost").isEqualTo(TestUtils.getPropertyValue(smbSessionFactory, "host")); - assertThat(0).isEqualTo(TestUtils.getPropertyValue(smbSessionFactory, "port")); - assertThat(23).isEqualTo(TestUtils.getPropertyValue(messageHandler, "order")); - - // verify subscription order - @SuppressWarnings("unchecked") - Set handlers = (Set) TestUtils.getPropertyValue( - TestUtils.getPropertyValue(channel, "dispatcher"), "handlers"); - Iterator iterator = handlers.iterator(); - assertThat(TestUtils.getPropertyValue(ac.getBean("smbOutboundChannelAdapter2"), "handler")).isSameAs(iterator.next()); - assertThat(messageHandler).isSameAs(iterator.next()); + // verify subscription order + @SuppressWarnings("unchecked") + Set handlers = (Set) TestUtils.getPropertyValue( + TestUtils.getPropertyValue(channel, "dispatcher"), "handlers"); + Iterator iterator = handlers.iterator(); + assertThat(TestUtils.getPropertyValue(ac.getBean("smbOutboundChannelAdapter2"), "handler")) + .isSameAs(iterator.next()); + assertThat(messageHandler).isSameAs(iterator.next()); + } } @Test public void noCachingByDefault() { - ApplicationContext ac = new ClassPathXmlApplicationContext(getApplicationContextXmlFile(), this.getClass()); - Object adapter = ac.getBean("simpleAdapter"); - Object sfProperty = TestUtils.getPropertyValue(adapter, "handler.remoteFileTemplate.sessionFactory"); - assertThat(SmbSessionFactory.class).isEqualTo(sfProperty.getClass()); + try (ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext( + getApplicationContextXmlFile(), this.getClass())) { + + Object adapter = ac.getBean("simpleAdapter"); + Object sfProperty = TestUtils.getPropertyValue(adapter, "handler.remoteFileTemplate.sessionFactory"); + assertThat(SmbSessionFactory.class).isEqualTo(sfProperty.getClass()); + } } } diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/inbound/SmbInboundRemoteFileSystemSynchronizerTests.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/inbound/SmbInboundRemoteFileSystemSynchronizerTests.java index 261bb27c22c..9c5b2fefd20 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/inbound/SmbInboundRemoteFileSystemSynchronizerTests.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/inbound/SmbInboundRemoteFileSystemSynchronizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. @@ -22,7 +22,7 @@ import java.util.List; import jcifs.smb.SmbFile; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -49,7 +49,7 @@ public class SmbInboundRemoteFileSystemSynchronizerTests extends AbstractBaseTes private String testRemoteDir = "test-temp/remote-9/"; - @Before + @BeforeEach public void prepare() { delete(testLocalDir); ensureExists(testRemoteDir); @@ -101,7 +101,7 @@ class TestSmbSessionFactory extends SmbSessionFactory { @Override protected SmbSession createSession() { try { - List smbFiles = new ArrayList(); + List smbFiles = new ArrayList<>(); for (String fileName : new File(testRemoteDir).list()) { SmbFile file = smbSession.createSmbFileObject(fileName); smbFiles.add(file); @@ -126,5 +126,7 @@ public Object answer(InvocationOnMock _invocation) throws Throwable { throw new RuntimeException("Failed to create mock session.", _ex); } } + } + } diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/outbound/SmbSendingMessageHandlerTests.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/outbound/SmbSendingMessageHandlerTests.java index 69f721d6e62..18fab87a304 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/outbound/SmbSendingMessageHandlerTests.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/outbound/SmbSendingMessageHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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,12 +21,10 @@ import java.io.OutputStream; import jcifs.smb.SmbFile; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; import org.springframework.beans.factory.BeanFactory; import org.springframework.expression.common.LiteralExpression; @@ -53,7 +51,7 @@ public class SmbSendingMessageHandlerTests extends AbstractBaseTests { private SmbSessionFactory smbSessionFactory; - @Before + @BeforeEach public void prepare() { smbSession = mock(SmbSession.class); smbSessionFactory = new TestSmbSessionFactory(); @@ -65,7 +63,7 @@ public void prepare() { smbSessionFactory.setShareAndDir("smb-share/"); } - @After + @AfterEach public void cleanup() { FileSystemUtils.deleteRecursively(new File("remote-target-dir")); } @@ -119,20 +117,17 @@ protected SmbSession createSession() { when(smbSession.remove(Mockito.anyString())).thenReturn(true); when(smbSession.list(Mockito.anyString())).thenReturn(new SmbFile[0]); - doAnswer(new Answer() { + doAnswer(_invocation -> { - @Override - public Object answer(InvocationOnMock _invocation) throws Throwable { - String path = (String) _invocation.getArguments()[0]; - OutputStream os = (OutputStream) _invocation.getArguments()[1]; - writeToFile((this.getClass().getSimpleName() + " : TEST : " + path).getBytes(), os); - return null; - } + String path = _invocation.getArgument(0); + OutputStream os = _invocation.getArgument(1); + writeToFile((this.getClass().getSimpleName() + " : TEST : " + path).getBytes(), os); + return null; }).when(smbSession).read(Mockito.anyString(), Mockito.any(OutputStream.class)); doAnswer(_invocation -> { - InputStream inputStream = (InputStream) _invocation.getArguments()[0]; - String path = (String) _invocation.getArguments()[1]; + InputStream inputStream = _invocation.getArgument(0); + String path = _invocation.getArgument(1); writeToFile(inputStream, path); return null; }).when(smbSession) @@ -141,14 +136,14 @@ public Object answer(InvocationOnMock _invocation) throws Throwable { // when(smbSession.write(Mockito.any(byte[].class), Mockito.anyString())).thenReturn(null); // when(smbSession.write(Mockito.any(File.class), Mockito.anyString())).thenReturn(null); - doAnswer((Answer) _invocation -> { - String path = (String) _invocation.getArguments()[0]; + doAnswer(_invocation -> { + String path = _invocation.getArgument(0); return new File(path).mkdirs(); }).when(smbSession).mkdir(Mockito.anyString()); doAnswer(_invocation -> { - String pathFrom = (String) _invocation.getArguments()[0]; - String pathTo = (String) _invocation.getArguments()[1]; + String pathFrom = _invocation.getArgument(0); + String pathTo = _invocation.getArgument(1); new File(pathFrom).renameTo(new File(pathTo)); return null; }).when(smbSession) diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/session/SmbSessionFactoryWithCIFSContextTests.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/session/SmbSessionFactoryWithCIFSContextTests.java index a0f91747d61..ef67c6722b8 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/session/SmbSessionFactoryWithCIFSContextTests.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/session/SmbSessionFactoryWithCIFSContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 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. @@ -23,12 +23,11 @@ import jcifs.CIFSContext; import jcifs.context.SingletonContext; import jcifs.smb.SmbFile; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import jcifs.util.Strings; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; import org.springframework.beans.factory.BeanFactory; import org.springframework.expression.common.LiteralExpression; @@ -53,7 +52,7 @@ public class SmbSessionFactoryWithCIFSContextTests extends AbstractBaseTests { private SmbSessionFactory smbSessionFactory; - @Before + @BeforeEach public void prepare() { smbSession = mock(SmbSession.class); @@ -68,7 +67,7 @@ public void prepare() { smbSessionFactory.setShareAndDir("smb-share/"); } - @After + @AfterEach public void cleanup() { FileSystemUtils.deleteRecursively(new File("remote-target-dir")); } @@ -88,10 +87,9 @@ public void testHandleFileContentMessage() { class TestSmbSessionFactory extends SmbSessionFactory { - private CIFSContext context; + private final CIFSContext context; protected TestSmbSessionFactory(CIFSContext _context) { - assertThat(_context).as("CIFSContext object is null.").isNotNull(); this.context = _context; } @@ -101,42 +99,36 @@ protected SmbSession createSession() { // test for a constructor with a CIFSContext SmbShare smbShare = new SmbShare(this, this.context); assertThat(smbShare).as("SmbShare object is null.").isNotNull(); - assertThat(smbShare.toString()).isEqualTo("smb://sambaguest:sambaguest@localhost:445/smb-share/"); + assertThat(smbShare.toString()) + .isEqualTo(Strings.maskSecretValue("smb://sambaguest:sambaguest@localhost:445/smb-share/")); // the rest has been copied from SmbSendingMessageHandlerTests when(smbSession.remove(Mockito.anyString())).thenReturn(true); when(smbSession.list(Mockito.anyString())).thenReturn(new SmbFile[0]); - doAnswer(new Answer() { - - @Override - public Object answer(InvocationOnMock _invocation) throws Throwable { - String path = (String) _invocation.getArguments()[0]; - OutputStream os = (OutputStream) _invocation.getArguments()[1]; - writeToFile((this.getClass().getSimpleName() + " : TEST : " + path).getBytes(), os); - return null; - } + doAnswer(_invocation -> { + String path = _invocation.getArgument(0); + OutputStream os = (OutputStream) _invocation.getArguments()[1]; + writeToFile((this.getClass().getSimpleName() + " : TEST : " + path).getBytes(), os); + return null; }).when(smbSession).read(Mockito.anyString(), Mockito.any(OutputStream.class)); doAnswer(_invocation -> { - InputStream inputStream = (InputStream) _invocation.getArguments()[0]; - String path = (String) _invocation.getArguments()[1]; + InputStream inputStream = _invocation.getArgument(0); + String path = _invocation.getArgument(1); writeToFile(inputStream, path); return null; }).when(smbSession) .write(Mockito.any(InputStream.class), Mockito.anyString()); - // when(smbSession.write(Mockito.any(byte[].class), Mockito.anyString())).thenReturn(null); - // when(smbSession.write(Mockito.any(File.class), Mockito.anyString())).thenReturn(null); - doAnswer(_invocation -> { - String path = (String) _invocation.getArguments()[0]; + String path = _invocation.getArgument(0); return new File(path).mkdirs(); }).when(smbSession).mkdir(Mockito.anyString()); doAnswer(_invocation -> { - String pathFrom = (String) _invocation.getArguments()[0]; - String pathTo = (String) _invocation.getArguments()[1]; + String pathFrom = _invocation.getArgument(0); + String pathTo = _invocation.getArgument(1); new File(pathFrom).renameTo(new File(pathTo)); return null; }).when(smbSession) diff --git a/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/dsl/WebFluxDslTests.java b/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/dsl/WebFluxDslTests.java index 18aa16b9f93..bb8456c74f6 100644 --- a/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/dsl/WebFluxDslTests.java +++ b/spring-integration-webflux/src/test/java/org/springframework/integration/webflux/dsl/WebFluxDslTests.java @@ -57,6 +57,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.messaging.PollableChannel; import org.springframework.messaging.support.ErrorMessage; +import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity; import org.springframework.security.config.web.server.ServerHttpSecurity; @@ -384,12 +385,9 @@ public ReactiveUserDetailsService reactiveUserDetailsService() { @Bean public SecurityWebFilterChain reactiveSpringSecurityFilterChain(ServerHttpSecurity http) { - return http.authorizeExchange() - .anyExchange().hasRole("ADMIN") - .and() - .httpBasic() - .and() - .csrf().disable() + return http.authorizeExchange(authorizeExchangeSpec -> authorizeExchangeSpec.anyExchange().hasRole("ADMIN")) + .httpBasic(Customizer.withDefaults()) + .csrf(ServerHttpSecurity.CsrfSpec::disable) .build(); }