Initial import!

This commit is contained in:
markpollack
2008-05-30 22:55:02 +00:00
commit c478a783c0
2978 changed files with 510966 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
/*
* 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;
using Quartz.Spi;
using Spring.Scheduling.Quartz;
namespace Spring.Scheduling.Quartz
{
/// <summary>
/// Tests for <see cref="AdaptableJobFactory" />.
/// </summary>
/// <author>Marko Lahma (.NET)</author>
[TestFixture]
public class AdaptableJobFactoryTest
{
private AdaptableJobFactory jobFactory;
[SetUp]
public void SetUp()
{
jobFactory = new AdaptableJobFactory();
}
[Test]
public void TestNewJob_IncompatibleJob()
{
try
{
// 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");
}
catch (ArgumentException)
{
// ok
}
catch (SchedulerException)
{
// ok
}
catch (Exception)
{
Assert.Fail("Got exception that was not instance of SchedulerException or ArgumentException");
}
}
[Test]
public void TestNewJob_ThreadStartJob()
{
// TODO ThreadStart is not the way to go
}
[Test]
public void TestNewJob_NormalIJob()
{
TriggerFiredBundle bundle = TestUtil.CreateMinimalFiredBundleWithTypedJobDetail(typeof(NoOpJob));
IJob job = jobFactory.NewJob(bundle);
Assert.IsNotNull(job, "Returned job was null");
}
}
internal class NoOpThreadStartJob : NoOpJob
{
public void Execute()
{
Execute(null);
}
}
}

View File

@@ -0,0 +1,92 @@
/*
* 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");
}
}
}

View File

@@ -0,0 +1,132 @@
/*
* 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.Group = null;
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();
}
}
}

View File

@@ -0,0 +1,75 @@
/*
* 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);
}
}
}

View File

@@ -0,0 +1,139 @@
/*
* 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; }
}
}
}

View File

@@ -0,0 +1,309 @@
/*
* 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 MockRepository mockery = null;
private SchedulerFactoryObject factory;
[SetUp]
public void SetUp()
{
factory = new SchedulerFactoryObject();
TestSchedulerFactory.Mockery.BackToRecordAll();
}
[Test]
public void TestAfterPropertiesSet_Defaults()
{
factory.AfterPropertiesSet();
TestSchedulerFactory.Mockery.ReplayAll();
}
[Test]
public void TestAfterPropertiesSet_NullJobFactory()
{
factory.JobFactory = null;
factory.AfterPropertiesSet();
TestSchedulerFactory.Mockery.ReplayAll();
}
[Test]
public void TestAfterPropertiesSet_NoAutoStartup()
{
// set expectations
TestSchedulerFactory.MockScheduler.JobFactory = null;
LastCall.IgnoreArguments();
TestSchedulerFactory.Mockery.ReplayAll();
factory.SchedulerFactoryType = typeof(TestSchedulerFactory);
factory.AutoStartup = false;
factory.AfterPropertiesSet();
}
[Test]
public void TestAfterPropertiesSet_AutoStartup()
{
InitForAfterPropertiesSetTest();
TestSchedulerFactory.MockScheduler.Start();
TestSchedulerFactory.Mockery.ReplayAll();
factory.SchedulerFactoryType = typeof (TestSchedulerFactory);
factory.AutoStartup = true;
factory.AfterPropertiesSet();
}
[Test]
public void TestAfterPropertiesSet_AddListeners()
{
mockery = new MockRepository();
InitForAfterPropertiesSetTest();
factory.SchedulerListeners = new ISchedulerListener[] { (ISchedulerListener)mockery.CreateMock(typeof(ISchedulerListener)) };
TestSchedulerFactory.MockScheduler.AddSchedulerListener(null);
LastCall.IgnoreArguments();
factory.GlobalJobListeners = new IJobListener[] { (IJobListener)mockery.CreateMock(typeof(IJobListener)) };
TestSchedulerFactory.MockScheduler.AddGlobalJobListener(null);
LastCall.IgnoreArguments();
factory.JobListeners = new IJobListener[] { (IJobListener)mockery.CreateMock(typeof(IJobListener)) };
TestSchedulerFactory.MockScheduler.AddJobListener(null);
LastCall.IgnoreArguments();
factory.GlobalTriggerListeners = new ITriggerListener[] { (ITriggerListener)mockery.CreateMock(typeof(ITriggerListener)) };
TestSchedulerFactory.MockScheduler.AddGlobalTriggerListener(null);
LastCall.IgnoreArguments();
factory.TriggerListeners = new ITriggerListener[] { (ITriggerListener)mockery.CreateMock(typeof(ITriggerListener)) };
TestSchedulerFactory.MockScheduler.AddTriggerListener(null);
LastCall.IgnoreArguments();
TestSchedulerFactory.Mockery.ReplayAll();
mockery.ReplayAll();
factory.AfterPropertiesSet();
}
[Test]
public void TestAfterPropertiesSet_Calendars()
{
mockery = new MockRepository();
InitForAfterPropertiesSetTest();
const string calendarName = "calendar";
ICalendar cal = (ICalendar) mockery.CreateMock(typeof (ICalendar));
Hashtable calTable = new Hashtable();
calTable[calendarName] = cal;
factory.Calendars = calTable;
TestSchedulerFactory.MockScheduler.AddCalendar(calendarName, cal, true, true);
TestSchedulerFactory.Mockery.ReplayAll();
mockery.ReplayAll();
factory.AfterPropertiesSet();
}
[Test]
public void TestAfterPropertiesSet_Trigger_TriggerExists()
{
mockery = new MockRepository();
InitForAfterPropertiesSetTest();
const string TRIGGER_NAME = "trigName";
const string TRIGGER_GROUP = "trigGroup";
SimpleTrigger trigger = new SimpleTrigger(TRIGGER_NAME, TRIGGER_GROUP);
factory.Triggers = new Trigger[] { trigger };
Expect.Call(TestSchedulerFactory.MockScheduler.GetTrigger(TRIGGER_NAME, TRIGGER_GROUP)).Return(trigger);
TestSchedulerFactory.Mockery.ReplayAll();
mockery.ReplayAll();
factory.AfterPropertiesSet();
}
[Test]
public void TestAfterPropertiesSet_Trigger_TriggerDoesntExist()
{
mockery = new MockRepository();
InitForAfterPropertiesSetTest();
const string TRIGGER_NAME = "trigName";
const string TRIGGER_GROUP = "trigGroup";
SimpleTrigger trigger = new SimpleTrigger(TRIGGER_NAME, TRIGGER_GROUP);
factory.Triggers = new Trigger[] { trigger };
Expect.Call(TestSchedulerFactory.MockScheduler.GetTrigger(TRIGGER_NAME, TRIGGER_GROUP)).Return(null);
TestSchedulerFactory.MockScheduler.ScheduleJob(trigger);
LastCall.IgnoreArguments().Return(DateTime.UtcNow);
TestSchedulerFactory.Mockery.ReplayAll();
mockery.ReplayAll();
factory.AfterPropertiesSet();
}
private void InitForAfterPropertiesSetTest()
{
factory.AutoStartup = false;
// set expectations
factory.SchedulerFactoryType = typeof(TestSchedulerFactory);
TestSchedulerFactory.MockScheduler.JobFactory = null;
LastCall.IgnoreArguments();
}
[Test]
public void TestAfterPropertiesSet_AutoStartup_WithDelay()
{
// set expectations
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 = 2;
factory.AfterPropertiesSet();
Thread.Sleep(TimeSpan.FromSeconds(3));
}
[Test]
public void TestStart()
{
// set expectations
TestSchedulerFactory.MockScheduler.JobFactory = null;
LastCall.IgnoreArguments();
TestSchedulerFactory.MockScheduler.Start();
TestSchedulerFactory.Mockery.ReplayAll();
factory.SchedulerFactoryType = typeof(TestSchedulerFactory);
factory.AutoStartup = false;
factory.AfterPropertiesSet();
factory.Start();
}
[Test]
public void TestStop()
{
// set expectations
TestSchedulerFactory.MockScheduler.JobFactory = null;
LastCall.IgnoreArguments();
TestSchedulerFactory.MockScheduler.Standby();
TestSchedulerFactory.Mockery.ReplayAll();
factory.SchedulerFactoryType = typeof(TestSchedulerFactory);
factory.AutoStartup = false;
factory.AfterPropertiesSet();
factory.Stop();
}
[Test]
public void TestGetObject()
{
factory.AfterPropertiesSet();
TestSchedulerFactory.Mockery.ReplayAll();
IScheduler sched = (IScheduler)factory.GetObject();
Assert.IsNotNull(sched, "scheduler was null");
}
[Test]
[ExpectedException(ExceptionType = typeof(ArgumentException))]
public void TestSchedulerFactoryType_InvalidType()
{
TestSchedulerFactory.Mockery.ReplayAll();
factory.SchedulerFactoryType = typeof(SchedulerFactoryObjectTest);
}
[Test]
public void TestSchedulerFactoryType_ValidType()
{
TestSchedulerFactory.Mockery.ReplayAll();
factory.SchedulerFactoryType = typeof(StdSchedulerFactory);
}
[TearDown]
public void TearDown()
{
TestSchedulerFactory.Mockery.VerifyAll();
if (mockery != null)
{
mockery.VerifyAll();
}
}
}
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(); }
}
}
}

View File

@@ -0,0 +1,97 @@
/*
* 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");
}
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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; }
}
}
}

View File

@@ -0,0 +1,55 @@
/*
* 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;
}
}
}

View File

@@ -0,0 +1,89 @@
/*
* 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");
}
}
}

View File

@@ -0,0 +1,170 @@
<VisualStudioProject>
<CSHARP
ProjectType = "Local"
ProductVersion = "7.10.6030"
SchemaVersion = "2.0"
ProjectGuid = "{ED644EA8-B6AE-457C-BF32-516DAE541FAC}"
>
<Build>
<Settings
ApplicationIcon = ""
AssemblyKeyContainerName = ""
AssemblyName = "Spring.Scheduling.Quartz.Tests"
AssemblyOriginatorKeyFile = ""
DefaultClientScript = "JScript"
DefaultHTMLPageLayout = "Grid"
DefaultTargetSchema = "IE50"
DelaySign = "false"
OutputType = "Library"
PreBuildEvent = ""
PostBuildEvent = ""
RootNamespace = "Spring"
RunPostBuildEvent = "OnBuildSuccess"
StartupObject = ""
>
<Config
Name = "Debug"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "DEBUG;TRACE"
DocumentationFile = ""
DebugSymbols = "true"
FileAlignment = "4096"
IncrementalBuild = "false"
NoStdLib = "false"
NoWarn = ""
Optimize = "false"
OutputPath = "..\..\..\build\VS.NET.2003\Spring.Scheduling.Quartz.Tests\Debug\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
<Config
Name = "Release"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "TRACE"
DocumentationFile = ""
DebugSymbols = "false"
FileAlignment = "4096"
IncrementalBuild = "false"
NoStdLib = "false"
NoWarn = ""
Optimize = "true"
OutputPath = "..\..\..\build\VS.NET.2003\Spring.Scheduling.Quartz.Tests\Release\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
</Settings>
<References>
<Reference
Name = "System"
AssemblyName = "System"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll"
/>
<Reference
Name = "System.Data"
AssemblyName = "System.Data"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll"
/>
<Reference
Name = "System.XML"
AssemblyName = "System.Xml"
HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"
/>
<Reference
Name = "Spring.Scheduling.Quartz.2003"
Project = "{0C0D8C65-90DE-4914-9940-4C684C54971B}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
/>
<Reference
Name = "Spring.Core"
AssemblyName = "Spring.Core"
HintPath = "..\..\..\lib\net\1.1\Spring.Core.dll"
/>
<Reference
Name = "nunit.framework"
AssemblyName = "nunit.framework"
HintPath = "..\..\..\lib\net\1.1\nunit.framework.dll"
/>
<Reference
Name = "Quartz"
AssemblyName = "Quartz"
HintPath = "..\..\..\lib\net\1.1\Quartz.dll"
/>
<Reference
Name = "Nullables"
AssemblyName = "Nullables"
HintPath = "..\..\..\lib\net\1.1\Nullables.dll"
/>
<Reference
Name = "Rhino.Mocks"
AssemblyName = "Rhino.Mocks"
HintPath = "..\..\..\lib\net\1.1\Rhino.Mocks.dll"
/>
</References>
</Build>
<Files>
<Include>
<File
RelPath = "Scheduling\Quartz\AdaptableJobFactoryTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Scheduling\Quartz\CronTriggerObjectTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Scheduling\Quartz\JobDetailObjectTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Scheduling\Quartz\MethodInvokingJobDetailFactoryObjectTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Scheduling\Quartz\MethodInvokingJobTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Scheduling\Quartz\SchedulerFactoryObjectTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Scheduling\Quartz\SimpleTriggerObjectTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Scheduling\Quartz\SpringObjectJobFactoryTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Scheduling\Quartz\TestUtil.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Scheduling\Quartz\TriggerObjectTest.cs"
SubType = "Code"
BuildAction = "Compile"
/>
</Include>
</Files>
</CSHARP>
</VisualStudioProject>

View File

@@ -0,0 +1,82 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{9FE720ED-2BD9-4FB9-89C8-FFFA4A491CB5}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Spring</RootNamespace>
<AssemblyName>Spring.Scheduling.Quartz.Tests</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\..\build\VS.NET.2005\Spring.Scheduling.Quartz.Tests\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;NET_2_0</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\..\build\VS.NET.2005\Spring.Scheduling.Quartz.Tests\Release\</OutputPath>
<DefineConstants>TRACE;NET_2_0</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=2.2.7.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\net\2.0\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="Quartz, Version=0.7.0.15571, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\net\2.0\Quartz.dll</HintPath>
</Reference>
<Reference Include="Rhino.Mocks, Version=2.9.6.40380, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\lib\Net\2.0\Rhino.Mocks.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\Spring\Spring.Core\Spring.Core.2005.csproj">
<Project>{710961A3-0DF4-49E4-A26E-F5B9C044AC84}</Project>
<Name>Spring.Core.2005</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\src\Spring\Spring.Scheduling.Quartz\Spring.Scheduling.Quartz.2005.csproj">
<Project>{E823D54C-CE82-4868-929F-5F95A999F61E}</Project>
<Name>Spring.Scheduling.Quartz.2005</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="Scheduling\Quartz\AdaptableJobFactoryTest.cs" />
<Compile Include="Scheduling\Quartz\SchedulerFactoryObjectTest.cs" />
<Compile Include="Scheduling\Quartz\SpringObjectJobFactoryTest.cs" />
<Compile Include="Scheduling\Quartz\TestUtil.cs" />
<Compile Include="Scheduling\Quartz\TriggerObjectTest.cs" />
<Compile Include="Scheduling\Quartz\SimpleTriggerObjectTest.cs" />
<Compile Include="Scheduling\Quartz\CronTriggerObjectTest.cs" />
<Compile Include="Scheduling\Quartz\JobDetailObjectTest.cs" />
<Compile Include="Scheduling\Quartz\MethodInvokingJobDetailFactoryObjectTest.cs" />
<Compile Include="Scheduling\Quartz\MethodInvokingJobTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Spring.Scheduling.Quartz.Tests.dll.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,60 @@
<?xml version="1.0" ?>
<project name="Spring.Scheduling.Quartz.Tests" default="build" xmlns="http://nant.sf.net/schemas/nant.xsd">
<!--
Required properties:
* current.bin.dir - (path) root level to build to
* build.debug - (true|false) debug build?
* current.build.defines.csc - framework-specific build defines
-->
<target name="build">
<csc target="library" define="${current.build.defines.csc}"
warnaserror="true"
debug="${current.build.debug}"
output="${current.bin.dir}/${project::get-name()}.dll"
doc="${current.bin.dir}/${project::get-name()}.xml">
<nowarn>
<warning number="${nowarn.numbers.test}" />
</nowarn>
<sources failonempty="true">
<include name="**/*.cs" />
<include name="../CommonAssemblyInfo.cs" />
</sources>
<references basedir="${current.bin.dir}">
<include name="*.dll" />
<exclude name="${project::get-name()}.dll" />
</references>
</csc>
<copy todir="${current.bin.dir}">
<fileset basedir="${project::get-name()}/Data">
<include name="**/*.xml" />
<include name="**/*.test" />
</fileset>
</copy>
<copy todir="${current.bin.dir}">
<fileset basedir="${project::get-name()}">
<include name="**/*.config" />
</fileset>
</copy>
</target>
<target name="test" depends="build">
<nunit2>
<formatter type="Plain" />
<formatter type="Xml" usefile="true" extension=".xml"
outputdir="${current.bin.dir}/results" />
<test assemblyname="${current.bin.dir}/${project::get-name()}.dll"
appconfig="${current.bin.dir}/${project::get-name()}.dll.config" />
</nunit2>
</target>
<target name="test-mono-1.0" >
<nunit2>
<formatter type="Plain" />
<formatter type="Xml" usefile="true" extension=".xml"
outputdir="${current.bin.dir}/results" />
<test assemblyname="${bin.dir}/net/1.1/${current.build.config}/${project::get-name()}.dll"
appconfig="${bin.dir}/net/1.1/${current.build.config}/${project::get-name()}.dll.config" />
</nunit2>
</target>
</project>

View File

@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Common.Logging"
publicKeyToken="af08829b84f0328e" />
<!-- Assembly versions can be redirected in application, publisher policy, or machine configuration files. -->
<bindingRedirect oldVersion="1.1.0.0"
newVersion="1.2.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>