Update of /cvsroot/springnet/Spring.Net.Integration/projects/Spring.Scheduling.Quartz/test/Spring/Spring.Scheduling.Quartz.Tests/Scheduling/Quartz
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv19120/Scheduling/Quartz
Modified Files:
AdaptableJobFactoryTest.cs
Added Files:
CronTriggerObjectTest.cs JobDetailObjectTest.cs
MethodInvokingJobDetailFactoryObjectTest.cs
MethodInvokingJobTest.cs SchedulerFactoryObjectTest.cs
SimpleTriggerObjectTest.cs SpringObjectJobFactoryTest.cs
TestUtil.cs TriggerObjectTest.cs
Log Message:
Added tests, more to be done
--- NEW FILE: SpringObjectJobFactoryTest.cs ---
/*
* Copyright 2002-2005 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System.Collections;
using NUnit.Framework;
using Quartz;
using Quartz.Job;
using Quartz.Spi;
namespace Spring.Scheduling.Quartz
{
/// <summary>
///
/// </summary>
/// <author>Marko Lahma (.NET)</author>
[TestFixture]
public class SpringObjectJobFactoryTest
{
private SpringObjectJobFactory factory;
[SetUp]
public void SetUp()
{
factory = new SpringObjectJobFactory();
}
[Test]
public void TestCreateJobInstance_SimpleDefaults()
{
Trigger trigger = new SimpleTrigger();
TriggerFiredBundle bundle = TestUtil.CreateMinimalFiredBundleWithTypedJobDetail(typeof (NoOpJob), trigger);
IJob job = factory.NewJob(bundle);
Assert.IsNotNull(job, "Created job was null");
}
[Test]
public void TestCreateJobInstance_SchedulerContextGiven()
{
IDictionary items = new Hashtable();
items["foo"] = "bar";
items["number"] = 123;
factory.SchedulerContext = new SchedulerContext(items);
Trigger trigger = new SimpleTrigger();
TriggerFiredBundle bundle = TestUtil.CreateMinimalFiredBundleWithTypedJobDetail(typeof(InjectableJob), trigger);
InjectableJob job = (InjectableJob) factory.NewJob(bundle);
Assert.IsNotNull(job, "Created job was null");
Assert.AreEqual("bar", job.Foo, "string injection failed");
Assert.AreEqual(123, job.Number, "integer injection failed");
}
[Test]
public void TestCreateJobInstance_IgnoredProperties()
{
factory.IgnoredUnknownProperties = new string[] {"foo", "baz"};
Trigger trigger = new SimpleTrigger();
trigger.JobDataMap["foo"] = "should not be injected";
trigger.JobDataMap["number"] = 123;
TriggerFiredBundle bundle = TestUtil.CreateMinimalFiredBundleWithTypedJobDetail(typeof(InjectableJob), trigger);
InjectableJob job = (InjectableJob)factory.NewJob(bundle);
Assert.IsNotNull(job, "Created job was null");
Assert.AreEqual(123, job.Number, "integer injection failed");
Assert.IsNull(job.Foo, "foo was injected when it was not supposed to ");
}
}
public class InjectableJob : NoOpJob
{
private int number;
private string foo;
public int Number
{
get { return number; }
set { number = value; }
}
public string Foo
{
get { return foo; }
set { foo = value; }
}
}
}
--- NEW FILE: TestUtil.cs ---
/*
* Copyright 2002-2005 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using Quartz;
using Quartz.Spi;
namespace Spring.Scheduling.Quartz
{
/// <summary>
/// Quartz.NET integration testing helpers.
/// </summary>
/// <author>Marko Lahma (.NET)</author>
public class TestUtil
{
/// <summary>
/// Creates the minimal fired bundle with job detail that has
/// given job type.
/// </summary>
/// <param name="jobType">Type of the job.</param>
/// <returns>Minimal TriggerFiredBundle</returns>
public static TriggerFiredBundle CreateMinimalFiredBundleWithTypedJobDetail(Type jobType)
{
return CreateMinimalFiredBundleWithTypedJobDetail(jobType, null);
}
/// <summary>
/// Creates the minimal fired bundle with job detail that has
/// given job type.
/// </summary>
/// <param name="jobType">Type of the job.</param>
/// <param name="trigger">The trigger.</param>
/// <returns>Minimal TriggerFiredBundle</returns>
public static TriggerFiredBundle CreateMinimalFiredBundleWithTypedJobDetail(Type jobType, Trigger trigger)
{
JobDetail jd = new JobDetail("jobName", "jobGroup", jobType);
TriggerFiredBundle bundle = new TriggerFiredBundle(jd, trigger, null, false, null, null, null, null);
return bundle;
}
}
}
--- NEW FILE: MethodInvokingJobTest.cs ---
/*
* Copyright 2002-2005 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Threading;
using NUnit.Framework;
using Quartz;
using Quartz.Job;
using Quartz.Spi;
using Rhino.Mocks;
using Spring.Objects.Support;
namespace Spring.Scheduling.Quartz
{
/// <summary>
///
/// </summary>
/// <author>Marko Lahma (.NET)</author>
[TestFixture]
public class MethodInvokingJobTest
{
private MethodInvokingJob methodInvokingJob;
[SetUp]
public void SetUp()
{
methodInvokingJob = new MethodInvokingJob();
}
[Test]
[ExpectedException(ExceptionType = typeof(ArgumentException))]
public void TestMethodInvoker_SetWithNull()
{
methodInvokingJob.MethodInvoker = null;
}
[Test]
[ExpectedException(ExceptionType = typeof(JobExecutionException))]
public void TestMethodInvocation_NullMethodInvokder()
{
methodInvokingJob.Execute(CreateMinimalJobExecutionContext());
}
[Test]
public void TestMethodInvoker_MethodSetCorrectly()
{
InvocationCountingJob job = new InvocationCountingJob();
MethodInvoker mi = new MethodInvoker();
mi.TargetObject = job;
mi.TargetMethod = "Invoke";
mi.Prepare();
methodInvokingJob.MethodInvoker = mi;
methodInvokingJob.Execute(CreateMinimalJobExecutionContext());
Assert.AreEqual(1, job.CounterValue, "Job was not invoked once");
}
[Test]
public void TestMethodInvoker_MethodSetCorrectlyThrowsException()
{
InvocationCountingJob job = new InvocationCountingJob();
MethodInvoker mi = new MethodInvoker();
mi.TargetObject = job;
mi.TargetMethod = "InvokeAndThrowException";
mi.Prepare();
methodInvokingJob.MethodInvoker = mi;
try
{
methodInvokingJob.Execute(CreateMinimalJobExecutionContext());
Assert.Fail("Successful invoke when method threw exception");
}
catch (JobExecutionException)
{
// ok
}
Assert.AreEqual(1, job.CounterValue, "Job was not invoked once");
}
private static JobExecutionContext CreateMinimalJobExecutionContext()
{
MockRepository repo = new MockRepository();
IScheduler sched = (IScheduler) repo.DynamicMock(typeof (IScheduler));
JobExecutionContext ctx = new JobExecutionContext(sched, ConstructMinimalTriggerFiredBundle(), null);
return ctx;
}
private static TriggerFiredBundle ConstructMinimalTriggerFiredBundle()
{
JobDetail jd = new JobDetail("jobName", "jobGroup", typeof(NoOpJob));
SimpleTrigger trigger = new SimpleTrigger("triggerName", "triggerGroup");
TriggerFiredBundle retValue = new TriggerFiredBundle(jd, trigger, null, false, null, null, null, null);
return retValue;
}
}
/// <summary>
/// Test class for method invoker.
/// </summary>
public class InvocationCountingJob
{
private int counter;
public void Invoke()
{
Interlocked.Increment(ref counter);
}
public void InvokeAndThrowException()
{
Interlocked.Increment(ref counter);
throw new Exception();
}
public int CounterValue
{
get { return counter; }
}
}
}
--- NEW FILE: CronTriggerObjectTest.cs ---
/*
* Copyright 2002-2005 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using NUnit.Framework;
using Quartz;
using Quartz.Job;
namespace Spring.Scheduling.Quartz
{
/// <summary>
/// Tests for <see cref="CronTriggerObject" />.
/// </summary>
/// <author>Marko Lahma (.NET)</author>
[TestFixture]
public class CronTriggerObjectTest : TriggerObjectTest
{
private CronTriggerObject cronTrigger;
[SetUp]
public void SetUp()
{
cronTrigger = new CronTriggerObject();
cronTrigger.ObjectName = TRIGGER_NAME;
Trigger = cronTrigger;
}
/// <summary>
/// Tests all possible misfire instructions for cron trigger
/// from strings to int.
/// </summary>
[Test]
public void TestMisfireInstructionNames()
{
string[] names = new string[] { "DoNothing", "FireOnceNow", "SmartPolicy" };
foreach (string name in names)
{
cronTrigger.MisfireInstructionName = name;
}
}
[Test]
public override void TestAfterPropertiesSet_Defaults()
{
cronTrigger.AfterPropertiesSet();
base.TestAfterPropertiesSet_Defaults();
AssertDateTimesEqualityWithAllowedDelta(DateTime.UtcNow, cronTrigger.StartTimeUtc, 1000);
Assert.AreEqual(TimeZone.CurrentTimeZone, cronTrigger.TimeZone, "trigger time zone mismatch");
}
[Test]
public override void TestAfterPropertiesSet_ValuesGiven()
{
TimeZone TZ = TimeZone.CurrentTimeZone;
cronTrigger.TimeZone = TZ;
cronTrigger.AfterPropertiesSet();
base.TestAfterPropertiesSet_ValuesGiven();
Assert.AreSame(TZ, cronTrigger.TimeZone, "trigger time zone mismatch");
}
[Test]
public override void TestAfterPropertiesSet_JobDetailGiven()
{
const string jobName = "jobName";
const string jobGroup = "jobGroup";
JobDetail jd = new JobDetail(jobName, jobGroup, typeof (NoOpJob));
cronTrigger.JobDetail = jd;
cronTrigger.AfterPropertiesSet();
base.TestAfterPropertiesSet_JobDetailGiven();
Assert.AreSame(jd, cronTrigger.JobDetail, "job details weren't same");
}
}
}
--- NEW FILE: SchedulerFactoryObjectTest.cs ---
/*
* Copyright 2002-2005 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections;
using System.Threading;
using NUnit.Framework;
using Quartz;
using Quartz.Impl;
using Rhino.Mocks;
namespace Spring.Scheduling.Quartz
{
/// <summary>
///
/// </summary>
/// <author>Marko Lahma (.NET)</author>
[TestFixture]
public class SchedulerFactoryObjectTest
{
private SchedulerFactoryObject factory;
[SetUp]
public void SetUp()
{
factory = new SchedulerFactoryObject();
}
[Test]
public void TestAfterPropertiesSet_Defaults()
{
factory.AfterPropertiesSet();
}
[Test]
public void TestAfterPropertiesSet_NullJobFactory()
{
factory.JobFactory = null;
factory.AfterPropertiesSet();
}
[Test]
public void TestAfterPropertiesSet_NoAutoStartup()
{
// set expectations
TestSchedulerFactory.Mockery.BackToRecordAll();
TestSchedulerFactory.MockScheduler.JobFactory = null;
LastCall.IgnoreArguments();
TestSchedulerFactory.Mockery.ReplayAll();
factory.SchedulerFactoryType = typeof(TestSchedulerFactory);
factory.AutoStartup = false;
factory.AfterPropertiesSet();
TestSchedulerFactory.Mockery.VerifyAll();
}
[Test]
public void TestAfterPropertiesSet_AutoStartup()
{
TestSchedulerFactory.Mockery.BackToRecordAll();
// set expectations
TestSchedulerFactory.MockScheduler.JobFactory = null;
LastCall.IgnoreArguments();
TestSchedulerFactory.MockScheduler.Start();
TestSchedulerFactory.Mockery.ReplayAll();
factory.SchedulerFactoryType = typeof (TestSchedulerFactory);
factory.AutoStartup = true;
factory.AfterPropertiesSet();
TestSchedulerFactory.Mockery.VerifyAll();
}
[Test]
public void TestAfterPropertiesSet_AutoStartup_WithDelay()
{
// set expectations
TestSchedulerFactory.Mockery.BackToRecordAll();
TestSchedulerFactory.MockScheduler.JobFactory = null;
LastCall.IgnoreArguments();
Expect.Call(TestSchedulerFactory.MockScheduler.SchedulerName).Return("schedName");
TestSchedulerFactory.MockScheduler.Start();
TestSchedulerFactory.Mockery.ReplayAll();
factory.SchedulerFactoryType = typeof(TestSchedulerFactory);
factory.AutoStartup = true;
factory.StartupDelay = 5;
factory.AfterPropertiesSet();
Thread.Sleep(TimeSpan.FromSeconds(6));
TestSchedulerFactory.Mockery.VerifyAll();
}
[Test]
public void TestStart()
{
// set expectations
TestSchedulerFactory.Mockery.BackToRecordAll();
TestSchedulerFactory.MockScheduler.JobFactory = null;
LastCall.IgnoreArguments();
TestSchedulerFactory.MockScheduler.Start();
TestSchedulerFactory.Mockery.ReplayAll();
factory.SchedulerFactoryType = typeof(TestSchedulerFactory);
factory.AutoStartup = false;
factory.AfterPropertiesSet();
factory.Start();
TestSchedulerFactory.Mockery.VerifyAll();
}
[Test]
public void TestStop()
{
// set expectations
TestSchedulerFactory.Mockery.BackToRecordAll();
TestSchedulerFactory.MockScheduler.JobFactory = null;
LastCall.IgnoreArguments();
TestSchedulerFactory.MockScheduler.Standby();
TestSchedulerFactory.Mockery.ReplayAll();
factory.SchedulerFactoryType = typeof(TestSchedulerFactory);
factory.AutoStartup = false;
factory.AfterPropertiesSet();
factory.Stop();
TestSchedulerFactory.Mockery.VerifyAll();
}
[Test]
public void TestGetObject()
{
factory.AfterPropertiesSet();
IScheduler sched = (IScheduler) factory.GetObject();
Assert.IsNotNull(sched, "scheduler was null");
}
[Test]
[ExpectedException(ExceptionType = typeof(ArgumentException))]
public void TestSchedulerFactoryType_InvalidType()
{
factory.SchedulerFactoryType = typeof (SchedulerFactoryObjectTest);
}
[Test]
public void TestSchedulerFactoryType_ValidType()
{
factory.SchedulerFactoryType = typeof(StdSchedulerFactory);
}
}
public class TestSchedulerFactory : ISchedulerFactory
{
private static readonly MockRepository mockery = new MockRepository();
private static readonly IScheduler mockScheduler;
static TestSchedulerFactory()
{
mockScheduler = (IScheduler) mockery.CreateMock(typeof (IScheduler));
}
public static MockRepository Mockery
{
get { return mockery; }
}
public static IScheduler MockScheduler
{
get { return mockScheduler; }
}
public IScheduler GetScheduler()
{
return mockScheduler;
}
public IScheduler GetScheduler(string schedName)
{
return mockScheduler;
}
public ICollection AllSchedulers
{
get { return new ArrayList(); }
}
}
}
--- NEW FILE: TriggerObjectTest.cs ---
/*
* Copyright 2002-2005 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using NUnit.Framework;
using Quartz;
namespace Spring.Scheduling.Quartz
{
/// <summary>
/// Base class for testing triggers. Contains common functionality.
/// </summary>
[TestFixture]
public abstract class TriggerObjectTest
{
private Trigger trigger;
protected const string TRIGGER_NAME = "trigger";
protected Trigger Trigger
{
set { trigger = value; }
}
[Test]
public virtual void TestAfterPropertiesSet_Defaults()
{
Assert.AreEqual(TRIGGER_NAME, trigger.Name, "trigger name mismatch");
Assert.AreEqual(SchedulerConstants.DEFAULT_GROUP, trigger.Group, "trigger group name mismatch");
AssertDateTimesEqualityWithAllowedDelta(DateTime.UtcNow, trigger.StartTimeUtc, 1000);
Assert.IsNull(trigger.JobName, "trigger job name not null");
Assert.AreEqual(SchedulerConstants.DEFAULT_GROUP, trigger.JobGroup, "trigger job group was not default");
}
[Test]
public virtual void TestAfterPropertiesSet_ValuesGiven()
{
const string NAME = "newName";
const string GROUP = "newGroup";
DateTime START_TIME = new DateTime(10000000);
trigger.Name = NAME;
trigger.Group = GROUP;
trigger.StartTimeUtc = START_TIME;
Assert.AreEqual(NAME, trigger.Name, "trigger name mismatch");
Assert.AreEqual(GROUP, trigger.Group, "trigger group name mismatch");
AssertDateTimesEqualityWithAllowedDelta(START_TIME, trigger.StartTimeUtc, 1000);
}
[Test]
public virtual void TestAfterPropertiesSet_JobDetailGiven()
{
const string jobName = "jobName";
const string jobGroup = "jobGroup";
Assert.AreEqual(jobName, trigger.JobName, "trigger job name was not from job detail");
Assert.AreEqual(jobGroup, trigger.JobGroup, "trigger job group was not from job detail");
}
[Test]
public virtual void TestTriggerListenerNames_Valis()
{
string[] LISTENER_NAMES = new string[] {"Foo", "Bar", "Baz"};
trigger.TriggerListenerNames = LISTENER_NAMES;
CollectionAssert.AreEqual(LISTENER_NAMES, trigger.TriggerListenerNames, "Trigger listeners were not equal");
}
protected static void AssertDateTimesEqualityWithAllowedDelta(DateTime d1, DateTime d2, int allowedDeltaInMilliseconds)
{
int diffInMillis = (int) Math.Abs((d1 - d2).TotalMilliseconds);
Assert.LessOrEqual(diffInMillis, allowedDeltaInMilliseconds, "too much difference in times");
}
}
}
--- NEW FILE: MethodInvokingJobDetailFactoryObjectTest.cs ---
/*
* Copyright 2002-2005 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using NUnit.Framework;
using Quartz;
namespace Spring.Scheduling.Quartz
{
/// <summary>
///
/// </summary>
/// <author>Marko Lahma (.NET)</author>
[TestFixture]
public class MethodInvokingJobDetailFactoryObjectTest
{
private const string FACTORY_NAME = "springObjectFactory";
private MethodInvokingJobDetailFactoryObject factory;
[SetUp]
public void SetUp()
{
factory = new MethodInvokingJobDetailFactoryObject();
factory.ObjectName = FACTORY_NAME;
factory.TargetMethod = "Invoke";
factory.TargetObject = new InvocationCountingJob();
}
[Test]
public void TestGetObject_MinimalDefaults()
{
factory.AfterPropertiesSet();
JobDetail jd = (JobDetail) factory.GetObject();
Assert.IsNotNull(jd, "job detail was null");
Assert.AreEqual(FACTORY_NAME, jd.Name, "job name did not default to factory name");
Assert.AreEqual(jd.JobType, typeof(MethodInvokingJob), "factory did not create method invoking job");
Assert.IsTrue(jd.Durable, "job was not durable");
Assert.IsTrue(jd.Volatile, "job was not volatile");
}
[Test]
public void TestGetObject_ConcurrentJob()
{
factory.Concurrent = false;
factory.AfterPropertiesSet();
JobDetail jd = (JobDetail)factory.GetObject();
Assert.IsNotNull(jd, "job detail was null");
Assert.AreEqual(jd.JobType, typeof(StatefulMethodInvokingJob), "factory did not create stateful method invoking job");
}
[Test]
public void TestGetObject_TriggerListenersSet()
{
string[] LISTENER_NAMES = new string[] {"Foo", "Bar"};
factory.JobListenerNames = LISTENER_NAMES;
factory.AfterPropertiesSet();
JobDetail jd = (JobDetail)factory.GetObject();
CollectionAssert.AreEquivalent(LISTENER_NAMES, jd.JobListenerNames);
}
}
}
--- NEW FILE: SimpleTriggerObjectTest.cs ---
/*
* Copyright 2002-2005 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using NUnit.Framework;
using Quartz;
using Quartz.Job;
namespace Spring.Scheduling.Quartz
{
/// <summary>
/// Tests for <see cref="SimpleTriggerObject" />.
/// </summary>
/// <author>Marko Lahma (.NET)</author>
[TestFixture]
public class SimpleTriggerObjectTest : TriggerObjectTest
{
private SimpleTriggerObject simpleTrigger;
[SetUp]
public void SetUp()
{
simpleTrigger = new SimpleTriggerObject();
simpleTrigger.ObjectName = TRIGGER_NAME;
Trigger = simpleTrigger;
}
/// <summary>
/// Tests all possible misfire instructions for cron trigger
/// from strings to int.
/// </summary>
[Test]
public void TestMisfireInstructionNames()
{
string[] names = new string[] { "FireNow", "RescheduleNextWithExistingCount", "RescheduleNextWithRemainingCount", "RescheduleNowWithExistingRepeatCount", "RescheduleNowWithRemainingRepeatCount", "SmartPolicy" };
foreach (string name in names)
{
simpleTrigger.MisfireInstructionName = name;
}
}
[Test]
public override void TestAfterPropertiesSet_Defaults()
{
simpleTrigger.AfterPropertiesSet();
base.TestAfterPropertiesSet_Defaults();
}
[Test]
public override void TestAfterPropertiesSet_ValuesGiven()
{
simpleTrigger.StartDelay = 100;
simpleTrigger.AfterPropertiesSet();
base.TestAfterPropertiesSet_ValuesGiven();
}
[Test]
public void TestAfterPropertiesSet_StartDelayGiven()
{
const int START_DELAY = 100000;
simpleTrigger.StartDelay = START_DELAY;
DateTime startTime = DateTime.UtcNow;
simpleTrigger.AfterPropertiesSet();
AssertDateTimesEqualityWithAllowedDelta(startTime.AddMilliseconds(START_DELAY), simpleTrigger.StartTimeUtc, 1000);
}
[Test]
public override void TestAfterPropertiesSet_JobDetailGiven()
{
const string jobName = "jobName";
const string jobGroup = "jobGroup";
JobDetail jd = new JobDetail(jobName, jobGroup, typeof(NoOpJob));
simpleTrigger.JobDetail = jd;
simpleTrigger.AfterPropertiesSet();
base.TestAfterPropertiesSet_JobDetailGiven();
Assert.AreSame(jd, simpleTrigger.JobDetail, "job details weren't same");
}
}
}
Index: AdaptableJobFactoryTest.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net.Integration/projects/Spring.Scheduling.Quartz/test/Spring/Spring.Scheduling.Quartz.Tests/Scheduling/Quartz/AdaptableJobFactoryTest.cs,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** AdaptableJobFactoryTest.cs 11 Sep 2007 09:47:52 -0000 1.1
--- AdaptableJobFactoryTest.cs 12 Sep 2007 18:39:33 -0000 1.2
***************
*** 29,33 ****
/// Tests for <see cref="AdaptableJobFactory" />.
/// </summary>
! [TestFixture]
public class AdaptableJobFactoryTest
{
--- 29,34 ----
/// Tests for <see cref="AdaptableJobFactory" />.
/// </summary>
! /// <author>Marko Lahma (.NET)</author>
! [TestFixture]
public class AdaptableJobFactoryTest
{
***************
*** 46,50 ****
{
// this actually fails already in Quartz level
! TriggerFiredBundle bundle = CreateMinimalFiredBundleWithTypedJobDetail(typeof(object));
jobFactory.NewJob(bundle);
Assert.Fail("Created job which was not an IJob");
--- 47,51 ----
{
// this actually fails already in Quartz level
! TriggerFiredBundle bundle = TestUtil.CreateMinimalFiredBundleWithTypedJobDetail(typeof(object));
jobFactory.NewJob(bundle);
Assert.Fail("Created job which was not an IJob");
***************
*** 73,77 ****
public void TestNewJob_NormalIJob()
{
! TriggerFiredBundle bundle = CreateMinimalFiredBundleWithTypedJobDetail(typeof(NoOpJob));
IJob job = jobFactory.NewJob(bundle);
Assert.IsNotNull(job, "Returned job was null");
--- 74,78 ----
public void TestNewJob_NormalIJob()
{
! TriggerFiredBundle bundle = TestUtil.CreateMinimalFiredBundleWithTypedJobDetail(typeof(NoOpJob));
IJob job = jobFactory.NewJob(bundle);
Assert.IsNotNull(job, "Returned job was null");
***************
*** 79,94 ****
! /// <summary>
! /// Creates the minimal fired bundle with job detail that has
! /// given job type.
! /// </summary>
! /// <param name="jobType">Type of the job.</param>
! /// <returns>Minimal TriggerFiredBundle</returns>
! private static TriggerFiredBundle CreateMinimalFiredBundleWithTypedJobDetail(Type jobType)
! {
! JobDetail jd = new JobDetail("jobName", "jobGroup", jobType);
! TriggerFiredBundle bundle = new TriggerFiredBundle(jd, null, null, false, null, null, null, null);
! return bundle;
! }
}
--- 80,84 ----
!
}
--- NEW FILE: JobDetailObjectTest.cs ---
/*
* Copyright 2002-2005 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections;
using NUnit.Framework;
using Quartz;
using Quartz.Job;
using Spring.Context.Support;
namespace Spring.Scheduling.Quartz
{
/// <summary>
/// Tests for <see cref="JobDetailObject" />.
/// </summary>
/// <author>Marko Lahma (.NET)</author>
[TestFixture]
public class JobDetailObjectTest
{
private JobDetailObject jobDetail;
[SetUp]
public void SetUp()
{
jobDetail = new JobDetailObject();
}
[Test]
[ExpectedException(ExceptionType = typeof(ArgumentException))]
public void TestJobType_Null()
{
jobDetail.JobType = null;
}
[Test]
public void TestJobType_NonIJob()
{
jobDetail.JobType = typeof(object);
Assert.AreEqual(typeof(object), jobDetail.JobType, "JobDetail did not create same type as expected");
}
[Test]
public void TestJobType_IJob()
{
Type CORRECT_IJOB = typeof (NoOpJob);
jobDetail.JobType = CORRECT_IJOB;
Assert.AreEqual(jobDetail.JobType, CORRECT_IJOB, "JobDetail did not register correct job type");
}
[Test]
[ExpectedException(ExceptionType = typeof(ArgumentException))]
public void TestJobDataAsMap_Null()
{
jobDetail.JobDataAsMap = null;
}
[Test]
public void TestJobDataAsMap_ProperValues()
{
IDictionary values = new Hashtable();
values["baz"] = "foo";
values["foo"] = 123;
values["bar"] = null;
jobDetail.JobDataAsMap = values;
Assert.AreEqual(values.Count, jobDetail.JobDataMap.Count, "Data of inequal size");
CollectionAssert.AreEqual(values.Keys, jobDetail.JobDataMap.Keys, "JobDataMap values not equal");
}
[Test]
public void TestAfterPropertiesSet_Defaults()
{
const string objectName = "springJobDetailObject";
jobDetail.ObjectName = objectName;
jobDetail.AfterPropertiesSet();
Assert.AreEqual(SchedulerConstants.DEFAULT_GROUP, jobDetail.Group, "Groups differ");
Assert.AreEqual(objectName, jobDetail.Name, "Names differ");
}
[Test]
public void TestAfterPropertiesSet_CustomNameAndGroup()
{
const string objectName = "springJobDetailObject";
const string jobDetailName = "jobDetailName";
const string jobDetailGroup = "jobDetailGroup";
jobDetail.ObjectName = objectName;
jobDetail.Name = jobDetailName;
jobDetail.Group = jobDetailGroup;
jobDetail.AfterPropertiesSet();
Assert.AreEqual(jobDetailGroup, jobDetail.Group, "Groups differ");
Assert.AreEqual(jobDetailName, jobDetail.Name, "Names differ");
}
[Test]
public void TestAfterPropertiesSet_ApplicationContextJobDataKeySetWithApplicationContext()
{
const string objectName = "springJobDetailObject";
jobDetail.ObjectName = objectName;
jobDetail.ApplicationContext = new XmlApplicationContext();
jobDetail.ApplicationContextJobDataKey = "applicationContextJobDataKey";
jobDetail.AfterPropertiesSet();
}
[Test]
[ExpectedException(ExceptionType = typeof(ArgumentException))]
public void TestAfterPropertiesSet_ApplicationContextJobDataKeySetWithoutApplicationContext()
{
const string objectName = "springJobDetailObject";
jobDetail.ObjectName = objectName;
jobDetail.ApplicationContextJobDataKey = "applicationContextJobDataKey";
jobDetail.AfterPropertiesSet();
}
}
}
|