INT-3321: Remove powermock Dependency

JIRA: https://jira.spring.io/browse/INT-3321

Refactor `StoredProcExecutorTests` just to use Mockito

INT-3321 Polishing

Mock the operations cache loader; remove static method.
This commit is contained in:
Artem Bilan
2014-03-12 19:06:29 +02:00
committed by Gary Russell
parent c73cc40e23
commit dafa765d88
3 changed files with 32 additions and 41 deletions

View File

@@ -92,7 +92,6 @@ subprojects { subproject ->
openJpaVersion = '2.3.0'
pahoMqttClientVersion = '0.4.0'
postgresVersion = '9.1-901-1.jdbc4'
powermockVersion = '1.5.4'
romeVersion = '1.0.0'
saajApiVersion = '1.3.5'
saajImplVersion = '1.3.23'
@@ -342,9 +341,6 @@ project('spring-integration-jdbc') {
testCompile "org.apache.derby:derby:$derbyVersion"
testCompile "org.apache.derby:derbyclient:$derbyVersion"
testCompile "org.powermock:powermock-module-junit4:$powermockVersion"
testCompile "org.powermock:powermock-api-mockito:$powermockVersion"
testCompile "postgresql:postgresql:$postgresVersion"
testCompile "mysql:mysql-connector-java:$mysqlVersion"
testCompile "commons-dbcp:commons-dbcp:$commonsDbcpVersion"

View File

@@ -325,17 +325,7 @@ public class StoredProcExecutor implements BeanFactoryAware, InitializingBean {
SqlParameterSource storedProcedureParameterSource =
sqlParameterSourceFactory.createParameterSource(input);
return StoredProcExecutor.executeStoredProcedure(localSimpleJdbcCall,
storedProcedureParameterSource);
}
private static Map<String, Object> executeStoredProcedure(SimpleJdbcCallOperations simpleJdbcCallOperations,
SqlParameterSource storedProcedureParameterSource) {
Map<String, Object> resultMap = simpleJdbcCallOperations.execute(storedProcedureParameterSource);
return resultMap;
return localSimpleJdbcCall.execute(storedProcedureParameterSource);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -29,26 +29,27 @@ import javax.sql.DataSource;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.expression.Expression;
import org.springframework.integration.config.ExpressionFactoryBean;
import org.springframework.integration.jdbc.storedproc.ProcedureParameter;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.SqlParameter;
import org.springframework.jdbc.core.simple.SimpleJdbcCall;
import org.springframework.jdbc.core.simple.SimpleJdbcCallOperations;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.CacheStats;
@RunWith(PowerMockRunner.class)
@PrepareForTest({StoredProcExecutor.class})
@PowerMockIgnore ({"org.apache.log4j.*"})
/**
* @author Gunnar Hillert
* @author Artem Bilan
* @author Gary Russell
*/
public class StoredProcExecutorTests {
private static final Logger LOGGER = Logger.getLogger(StoredProcExecutorTests.class);
@@ -315,11 +316,6 @@ public class StoredProcExecutorTests {
final DataSource datasource = mock(DataSource.class);
PowerMockito.mockStatic(StoredProcExecutor.class);
PowerMockito.spy(StoredProcExecutor.class);
PowerMockito.doReturn(null).when(StoredProcExecutor.class, "executeStoredProcedure", Mockito.any(), Mockito.any());
final StoredProcExecutor storedProcExecutor = new StoredProcExecutor(datasource);
final ExpressionFactoryBean efb = new ExpressionFactoryBean("headers['stored_procedure_name']");
@@ -331,6 +327,8 @@ public class StoredProcExecutorTests {
storedProcExecutor.afterPropertiesSet();
this.mockTheOperationsCache(storedProcExecutor);
//This should work
storedProcExecutor.executeStoredProcedure(
@@ -345,7 +343,8 @@ public class StoredProcExecutorTests {
MessageBuilder.withPayload("test")
.setHeader("some_other_header", "123")
.build());
} catch (IllegalArgumentException e) {
}
catch (IllegalArgumentException e) {
assertEquals("Unable to resolve Stored Procedure/Function name for the provided Expression 'headers['stored_procedure_name']'.", e.getMessage());
return;
}
@@ -359,11 +358,6 @@ public class StoredProcExecutorTests {
final DataSource datasource = mock(DataSource.class);
PowerMockito.mockStatic(StoredProcExecutor.class);
PowerMockito.spy(StoredProcExecutor.class);
PowerMockito.doReturn(null).when(StoredProcExecutor.class, "executeStoredProcedure", Mockito.any(), Mockito.any());
final StoredProcExecutor storedProcExecutor = new StoredProcExecutor(datasource);
final ExpressionFactoryBean efb = new ExpressionFactoryBean("headers['stored_procedure_name']");
@@ -375,6 +369,8 @@ public class StoredProcExecutorTests {
storedProcExecutor.afterPropertiesSet();
this.mockTheOperationsCache(storedProcExecutor);
for (int i = 1; i <= 3; i++) {
storedProcExecutor.executeStoredProcedure(
MessageBuilder.withPayload("test")
@@ -397,12 +393,8 @@ public class StoredProcExecutorTests {
final DataSource datasource = mock(DataSource.class);
PowerMockito.mockStatic(StoredProcExecutor.class);
PowerMockito.spy(StoredProcExecutor.class);
PowerMockito.doReturn(null).when(StoredProcExecutor.class, "executeStoredProcedure", Mockito.any(), Mockito.any());
final StoredProcExecutor storedProcExecutor = new StoredProcExecutor(datasource);
storedProcExecutor.setJdbcCallOperationsCacheSize(0);
final ExpressionFactoryBean efb = new ExpressionFactoryBean("headers['stored_procedure_name']");
@@ -414,6 +406,8 @@ public class StoredProcExecutorTests {
storedProcExecutor.afterPropertiesSet();
this.mockTheOperationsCache(storedProcExecutor);
for (int i = 1; i <= 10; i++) {
storedProcExecutor.executeStoredProcedure(
MessageBuilder.withPayload("test")
@@ -427,4 +421,15 @@ public class StoredProcExecutorTests {
}
private void mockTheOperationsCache(final StoredProcExecutor storedProcExecutor) {
Object cache = TestUtils.getPropertyValue(storedProcExecutor, "jdbcCallOperationsCache.localCache");
new DirectFieldAccessor(cache)
.setPropertyValue("defaultLoader", new CacheLoader<String, SimpleJdbcCallOperations>() {
@Override
public SimpleJdbcCall load(String storedProcedureName) {
return mock(SimpleJdbcCall.class);
}
});
}
}