From 54b2eb0b2e6b5faa8aae6ff91c4dfbab6c0428dc Mon Sep 17 00:00:00 2001 From: lahma Date: Tue, 13 Jul 2010 09:24:36 +0000 Subject: [PATCH] SPRNET-1340 MethodInvokingJobDetailFactoryObject does not set the result in JobContext --- .../Scheduling/Quartz/MethodInvokingJob.cs | 2 +- .../Quartz/MethodInvokingJobTest.cs | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/Spring/Spring.Scheduling.Quartz/Scheduling/Quartz/MethodInvokingJob.cs b/src/Spring/Spring.Scheduling.Quartz/Scheduling/Quartz/MethodInvokingJob.cs index 7a97176c..861d0dc3 100644 --- a/src/Spring/Spring.Scheduling.Quartz/Scheduling/Quartz/MethodInvokingJob.cs +++ b/src/Spring/Spring.Scheduling.Quartz/Scheduling/Quartz/MethodInvokingJob.cs @@ -66,7 +66,7 @@ namespace Spring.Scheduling.Quartz } try { - methodInvoker.Invoke(); + context.Result = methodInvoker.Invoke(); } catch (TargetInvocationException ex) { diff --git a/test/Spring/Spring.Scheduling.Quartz.Tests/Scheduling/Quartz/MethodInvokingJobTest.cs b/test/Spring/Spring.Scheduling.Quartz.Tests/Scheduling/Quartz/MethodInvokingJobTest.cs index 94d3cfc2..ce0bb97e 100644 --- a/test/Spring/Spring.Scheduling.Quartz.Tests/Scheduling/Quartz/MethodInvokingJobTest.cs +++ b/test/Spring/Spring.Scheduling.Quartz.Tests/Scheduling/Quartz/MethodInvokingJobTest.cs @@ -83,6 +83,24 @@ namespace Spring.Scheduling.Quartz Assert.AreEqual(1, job.CounterValue, "Job was not invoked once"); } + /// + /// Test that invocation result is set to execution context (SPRNET-1340). + /// + [Test] + public void TestMethodInvoker_ShouldSetResultToExecutionContext() + { + InvocationCountingJob job = new InvocationCountingJob(); + MethodInvoker mi = new MethodInvoker(); + mi.TargetObject = job; + mi.TargetMethod = "InvokeWithReturnValue"; + mi.Prepare(); + methodInvokingJob.MethodInvoker = mi; + JobExecutionContext context = CreateMinimalJobExecutionContext(); + methodInvokingJob.Execute(context); + + Assert.AreEqual(InvocationCountingJob.DefaultReturnValue, context.Result, "result value was not set to context"); + } + /// /// Test method invoke via execute. /// @@ -147,6 +165,7 @@ namespace Spring.Scheduling.Quartz public class InvocationCountingJob { private int counter; + internal const string DefaultReturnValue = "return value"; /// /// Increments method invoke counter. @@ -169,6 +188,14 @@ namespace Spring.Scheduling.Quartz { } + /// + /// Returns as return value. + /// + public string InvokeWithReturnValue() + { + return DefaultReturnValue; + } + /// /// Invocation count. ///