Skip to content

Commit

Permalink
Revert json-path & Mockito versions
Browse files Browse the repository at this point in the history
* Remove `mockito-inline` dependency
* Fix deprecations from Spring Security
* Fix `SmbSessionFactoryWithCIFSContextTests` for compatibility with latest `JCIFS`
* Migrate all the SMB tests to Junit Jupiter
  • Loading branch information
artembilan committed Apr 19, 2023
1 parent dd53de8 commit 934e90a
Show file tree
Hide file tree
Showing 12 changed files with 166 additions and 169 deletions.
5 changes: 2 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -41,6 +40,7 @@
*
* @author Markus Spann
* @author Gregory Bragg
* @author Artem Bilan
*/
public abstract class AbstractBaseTests {

Expand All @@ -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());
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<? 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -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());
}
}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -18,21 +18,23 @@

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
*
*/
public class SmbParserInboundTests extends AbstractBaseTests {

@Before
@BeforeEach
public void prepare() {
ensureExists("test-temp/remote-10");
cleanUp();
Expand All @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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");

Expand Down Expand Up @@ -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);
Expand All @@ -105,10 +107,10 @@ public void testNoCachingSessionFactoryByDefault() {
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")) {
Expand All @@ -132,9 +134,6 @@ public Class<?> getObjectType() {
return SmbSessionFactory.class;
}

public boolean isSingleton() {
return true;
}
}

}
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand All @@ -46,14 +46,15 @@
* @author Markus Spann
* @author Gunnar Hillert
* @author Gregory Bragg
* @author Artem Bilan
*/
public class SmbInboundOutboundSample extends AbstractBaseTests {

private static final String INBOUND_APPLICATION_CONTEXT_XML = "SmbInboundChannelAdapterSample-context.xml";

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/";
Expand Down Expand Up @@ -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/";
Expand Down
Loading

0 comments on commit 934e90a

Please sign in to comment.