GH-2760: use assertThatExceptionOfType in tests
Fixes https://github.com/spring-projects/spring-integration/issues/2760 * The `assertThatExceptionOfType()` is more convenient, than `assertThatThrownBy`, so, replace all the usages accordingly * Fix JavaDoc typo in the `AbstractScriptExecutingMessageProcessor` * Fix Sonar smells for `throws Exception` in `AbstractScriptExecutingMessageProcessor` hierarchy and some code polishing for them
This commit is contained in:
@@ -56,21 +56,6 @@ public abstract class AbstractScriptExecutingMessageProcessor<T>
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Executes the script and returns the result.
|
||||
*/
|
||||
@Override
|
||||
public final T processMessage(Message<?> message) {
|
||||
try {
|
||||
ScriptSource source = this.getScriptSource(message);
|
||||
Map<String, Object> variables = this.scriptVariableGenerator.generateScriptVariables(message);
|
||||
return executeScript(source, variables);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw IntegrationUtils.wrapInHandlingExceptionIfNecessary(message, () -> "Failed to execute script.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
this.beanClassLoader = classLoader;
|
||||
@@ -81,6 +66,21 @@ public abstract class AbstractScriptExecutingMessageProcessor<T>
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the script and returns the result.
|
||||
*/
|
||||
@Override
|
||||
public final T processMessage(Message<?> message) {
|
||||
try {
|
||||
ScriptSource source = getScriptSource(message);
|
||||
Map<String, Object> variables = this.scriptVariableGenerator.generateScriptVariables(message);
|
||||
return executeScript(source, variables);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw IntegrationUtils.wrapInHandlingExceptionIfNecessary(message, () -> "Failed to execute script.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Subclasses must implement this method to create a script source,
|
||||
* optionally using the message to locate or create the script.
|
||||
@@ -92,11 +92,10 @@ public abstract class AbstractScriptExecutingMessageProcessor<T>
|
||||
/**
|
||||
* Subclasses must implement this method. In doing so, the execution context
|
||||
* for the script should be populated with the provided script variables.
|
||||
*78546 @param scriptSource The script source.
|
||||
* @param scriptSource The script source.
|
||||
* @param variables The variables.
|
||||
* @return The result of the execution.
|
||||
* @throws Exception Any Exception.
|
||||
*/
|
||||
protected abstract T executeScript(ScriptSource scriptSource, Map<String, Object> variables) throws Exception;
|
||||
protected abstract T executeScript(ScriptSource scriptSource, Map<String, Object> variables);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -28,6 +28,8 @@ import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author David Turanski
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public class ScriptExecutingMessageProcessor extends AbstractScriptExecutingMessageProcessor<Object> {
|
||||
@@ -40,12 +42,10 @@ public class ScriptExecutingMessageProcessor extends AbstractScriptExecutingMess
|
||||
/**
|
||||
* Create a processor for the {@link ScriptSource} using the provided
|
||||
* {@link ScriptExecutor} using the DefaultScriptVariableGenerator
|
||||
*
|
||||
* @param scriptSource The script source.
|
||||
* @param scriptExecutor The script executor.
|
||||
*/
|
||||
public ScriptExecutingMessageProcessor(ScriptSource scriptSource, ScriptExecutor scriptExecutor) {
|
||||
super();
|
||||
this.scriptSource = scriptSource;
|
||||
this.scriptExecutor = scriptExecutor;
|
||||
}
|
||||
@@ -53,13 +53,13 @@ public class ScriptExecutingMessageProcessor extends AbstractScriptExecutingMess
|
||||
/**
|
||||
* Create a processor for the {@link ScriptSource} using the provided
|
||||
* {@link ScriptExecutor}
|
||||
*
|
||||
* @param scriptSource The script source.
|
||||
* @param scriptVariableGenerator The script variable generator.
|
||||
* @param scriptExecutor The script executor.
|
||||
*/
|
||||
public ScriptExecutingMessageProcessor(ScriptSource scriptSource, ScriptVariableGenerator scriptVariableGenerator,
|
||||
ScriptExecutor scriptExecutor) {
|
||||
|
||||
super(scriptVariableGenerator);
|
||||
this.scriptSource = scriptSource;
|
||||
this.scriptExecutor = scriptExecutor;
|
||||
@@ -68,13 +68,13 @@ public class ScriptExecutingMessageProcessor extends AbstractScriptExecutingMess
|
||||
/**
|
||||
* Create a processor for the {@link ScriptSource} using the provided
|
||||
* {@link ScriptExecutor} using the DefaultScriptVariableGenerator
|
||||
*
|
||||
* @param scriptSource The script source.
|
||||
* @param scriptExecutor The script executor.
|
||||
* @param variables The variables.
|
||||
*/
|
||||
public ScriptExecutingMessageProcessor(ScriptSource scriptSource, ScriptExecutor scriptExecutor,
|
||||
Map<String, Object> variables) {
|
||||
|
||||
super(new DefaultScriptVariableGenerator(variables));
|
||||
this.scriptSource = scriptSource;
|
||||
this.scriptExecutor = scriptExecutor;
|
||||
@@ -87,7 +87,7 @@ public class ScriptExecutingMessageProcessor extends AbstractScriptExecutingMess
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object executeScript(ScriptSource scriptSource, Map<String, Object> variables) throws Exception {
|
||||
protected Object executeScript(ScriptSource scriptSource, Map<String, Object> variables) {
|
||||
Assert.notNull(scriptSource, "scriptSource must not be null");
|
||||
return this.scriptExecutor.executeScript(scriptSource, variables);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user