Revert json-path & Mockito versions
* Remove `mockito-inline` dependency * Fix deprecations from Spring Security * Fix `SmbSessionFactoryWithCIFSContextTests` for compatibility with latest `JCIFS` * Migrate all the SMB tests to Junit Jupiter
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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.PollableChannel;
|
||||
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 class HttpDslTests {
|
||||
@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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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 java.lang.reflect.Method;
|
||||
|
||||
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 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Markus Spann
|
||||
* @author Gregory Bragg
|
||||
* @author Artem Bilan
|
||||
*/
|
||||
public abstract class AbstractBaseTests {
|
||||
|
||||
@@ -51,19 +51,19 @@ public abstract class AbstractBaseTests {
|
||||
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 abstract class AbstractBaseTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 abstract class AbstractBaseTests {
|
||||
* @param _testClass test class object
|
||||
* @param _methodNames String method names to invoke in order, no parameters expected
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
protected static void runTests(Class<? extends AbstractBaseTests> _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);
|
||||
|
||||
@@ -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 @@ package org.springframework.integration.smb;
|
||||
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());
|
||||
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);
|
||||
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();
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 @@ package org.springframework.integration.smb;
|
||||
|
||||
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 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
*/
|
||||
public class SmbParserInboundTests extends AbstractBaseTests {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void prepare() {
|
||||
ensureExists("test-temp/remote-10");
|
||||
cleanUp();
|
||||
@@ -46,14 +48,14 @@ public class SmbParserInboundTests extends AbstractBaseTests {
|
||||
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");
|
||||
}
|
||||
|
||||
@@ -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.Map;
|
||||
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.inbound.SmbInboundFileSynchronizingMe
|
||||
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 @@ import static org.mockito.Mockito.when;
|
||||
* @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 class SmbInboundChannelAdapterParserTests {
|
||||
|
||||
@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 class SmbInboundChannelAdapterParserTests {
|
||||
assertThat("/").isEqualTo(remoteFileSeparator);
|
||||
}
|
||||
|
||||
@Test(timeout = 10000)
|
||||
@Test
|
||||
public void testSmbInboundChannelAdapterCompleteNoId() {
|
||||
|
||||
Map<String, SourcePollingChannelAdapter> spcas = applicationContext.getBeansOfType(SourcePollingChannelAdapter.class);
|
||||
Map<String, SourcePollingChannelAdapter> 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 SmbInboundChannelAdapterParserTests {
|
||||
return SmbSessionFactory.class;
|
||||
}
|
||||
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 @@ package org.springframework.integration.smb.config;
|
||||
|
||||
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 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @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 class SmbInboundOutboundSample extends AbstractBaseTests {
|
||||
|
||||
}
|
||||
|
||||
@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/";
|
||||
|
||||
@@ -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<MessageHandler> handlers = (Set<MessageHandler>) TestUtils.getPropertyValue(
|
||||
TestUtils.getPropertyValue(channel, "dispatcher"), "handlers");
|
||||
Iterator<MessageHandler> iterator = handlers.iterator();
|
||||
assertThat(TestUtils.getPropertyValue(ac.getBean("smbOutboundChannelAdapter2"), "handler")).isSameAs(iterator.next());
|
||||
assertThat(messageHandler).isSameAs(iterator.next());
|
||||
// verify subscription order
|
||||
@SuppressWarnings("unchecked")
|
||||
Set<MessageHandler> handlers = (Set<MessageHandler>) TestUtils.getPropertyValue(
|
||||
TestUtils.getPropertyValue(channel, "dispatcher"), "handlers");
|
||||
Iterator<MessageHandler> 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());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.ArrayList;
|
||||
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 @@ public class SmbInboundRemoteFileSystemSynchronizerTests extends AbstractBaseTes
|
||||
@Override
|
||||
protected SmbSession createSession() {
|
||||
try {
|
||||
List<SmbFile> smbFiles = new ArrayList<SmbFile>();
|
||||
List<SmbFile> smbFiles = new ArrayList<>();
|
||||
for (String fileName : new File(testRemoteDir).list()) {
|
||||
SmbFile file = smbSession.createSmbFileObject(fileName);
|
||||
smbFiles.add(file);
|
||||
@@ -126,5 +126,7 @@ public class SmbInboundRemoteFileSystemSynchronizerTests extends AbstractBaseTes
|
||||
throw new RuntimeException("Failed to create mock session.", _ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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.InputStream;
|
||||
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 class SmbSendingMessageHandlerTests extends AbstractBaseTests {
|
||||
smbSessionFactory.setShareAndDir("smb-share/");
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void cleanup() {
|
||||
FileSystemUtils.deleteRecursively(new File("remote-target-dir"));
|
||||
}
|
||||
@@ -119,20 +117,17 @@ public class SmbSendingMessageHandlerTests extends AbstractBaseTests {
|
||||
when(smbSession.remove(Mockito.anyString())).thenReturn(true);
|
||||
when(smbSession.list(Mockito.anyString())).thenReturn(new SmbFile[0]);
|
||||
|
||||
doAnswer(new Answer<Object>() {
|
||||
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 class SmbSendingMessageHandlerTests extends AbstractBaseTests {
|
||||
// when(smbSession.write(Mockito.any(byte[].class), Mockito.anyString())).thenReturn(null);
|
||||
// when(smbSession.write(Mockito.any(File.class), Mockito.anyString())).thenReturn(null);
|
||||
|
||||
doAnswer((Answer<Object>) _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)
|
||||
|
||||
@@ -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 java.io.OutputStream;
|
||||
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 class SmbSessionFactoryWithCIFSContextTests extends AbstractBaseTests {
|
||||
smbSessionFactory.setShareAndDir("smb-share/");
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void cleanup() {
|
||||
FileSystemUtils.deleteRecursively(new File("remote-target-dir"));
|
||||
}
|
||||
@@ -88,10 +87,9 @@ public class SmbSessionFactoryWithCIFSContextTests extends AbstractBaseTests {
|
||||
|
||||
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 @@ public class SmbSessionFactoryWithCIFSContextTests extends AbstractBaseTests {
|
||||
// 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<Object>() {
|
||||
|
||||
@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)
|
||||
|
||||
@@ -57,6 +57,7 @@ import org.springframework.messaging.Message;
|
||||
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 class WebFluxDslTests {
|
||||
|
||||
@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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user